Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../usr/man/man3c/./makecontext.3c
Real path: /usr/share/man/man3c/makecontext.3c
Zurück
'\" te .\" Copyright (c) 1989, AT&T. All rights reserved. .\" Portions Copyright (c) 1992, The X/Open Company Ltd. All rights reserved. .\" Copyright (c) 2004, 2017, Oracle and/or its affiliates. All rights reserved. .\" Oracle gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation. Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation. In the following statement, the phrase "this text" refers to portions of the system documentation. Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html. This notice shall appear on any product containing this material. .TH makecontext 3C "27 Nov 2017" "Oracle Solaris 11.4" "Standard C Library Functions" .SH NAME makecontext, swapcontext \- manipulate user contexts .SH SYNOPSIS .LP .nf #include <ucontext.h> \fBvoid\fR \fBmakecontext\fR(\fBucontext_t *\fR\fIucp\fR, \fBvoid (*\fR\fIfunc\fR)(), \fBint\fR \fIargc\fR...); .fi .LP .nf \fBint\fR \fBswapcontext\fR(\fBucontext_t *restrict\fR \fIoucp\fR, \fBconst ucontext_t *restrict\fR \fIucp\fR); .fi .SH DESCRIPTION .sp .LP The \fBmakecontext()\fR function modifies the context specified by \fIucp\fR, which has been initialized using \fBgetcontext\fR(2). When this context is resumed using \fBswapcontext()\fR or \fBsetcontext\fR(2), execution continues by calling the function \fIfunc\fR, passing it the arguments that follow \fIargc\fR in the \fBmakecontext()\fR call. The value of \fIargc\fR must match the number of pointer-sized integer arguments passed to \fIfunc\fR, otherwise the behavior is undefined. .sp .LP Before a call is made to \fBmakecontext()\fR, the context being modified should have a stack allocated for it. The stack is assigned to the context by initializing the \fBuc_stack\fR member. .sp .LP The \fBuc_link\fR member is used to determine the context that will be resumed when the context being modified by \fBmakecontext()\fR returns. The \fBuc_link\fR member should be initialized prior to the call to \fBmakecontext()\fR. If the \fBuc_link\fR member is initialized to \fINULL\fR, the thread executing \fIfunc\fR will exit when \fIfunc\fR returns. See \fBpthread_exit\fR(3C). .sp .LP The \fBswapcontext()\fR function saves the current context in the context structure pointed to by \fIoucp\fR and sets the context to the context structure pointed to by \fIucp\fR. .sp .LP If the \fIucp\fR or \fIoucp\fR argument points to an invalid address, the behavior is undefined and \fBerrno\fR may be set to \fBEFAULT\fR. .SH RETURN VALUES .sp .LP On successful completion, \fBswapcontext()\fR returns \fB0\fR. Otherwise, \fB\(mi1\fR is returned and \fBerrno\fR is set to indicate the error. .SH ERRORS .sp .LP The \fBswapcontext()\fR function will fail if: .sp .ne 2 .mk .na \fB\fBENOMEM\fR\fR .ad .RS 10n .rt The \fIucp\fR argument does not have enough stack left to complete the operation. .RE .sp .LP The \fBswapcontext()\fR function may fail if: .sp .ne 2 .mk .na \fB\fBEFAULT\fR\fR .ad .RS 10n .rt The \fIucp\fR or \fIoucp\fR argument points to an invalid address. .RE .SH EXAMPLES .LP \fBExample 1\fR Alternate execution context on a stack whose memory was allocated using \fBmmap()\fR. .sp .in +2 .nf #include <stdio.h> #include <ucontext.h> #include <sys/mman.h> void assign(long a, int *b) { *b = (int)a; } int main(int argc, char **argv) { ucontext_t uc, back; size_t sz = 0x10000; int value = 0; getcontext(&uc); uc.uc_stack.ss_sp = mmap(0, sz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); uc.uc_stack.ss_size = sz; uc.uc_stack.ss_flags = 0; uc.uc_link = &back; makecontext(&uc, assign, 2, 100L, &value); swapcontext(&back, &uc); printf("done %d\en", value); return (0); } .fi .in -2 .sp .SH USAGE .sp .LP These functions are useful for implementing user-level context switching between multiple threads of control within a process (co-processing). More effective multiple threads of control can be obtained by using native support for multithreading. See \fBthreads\fR(7). .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ Interface Stability Committed _ MT-Level MT-Safe _ Standard See \fBstandards\fR(7). .TE .sp .SH SEE ALSO .sp .LP \fBgetcontext\fR(2), \fBmmap\fR(2), \fBsigaction\fR(2), \fBsigprocmask\fR(2), \fBpthread_exit\fR(3C), \fBucontext.h\fR(3HEAD), \fBattributes\fR(7), \fBstandards\fR(7), \fBthreads\fR(7) .SH NOTES .sp .LP The semantics of the \fBuc_stack\fR member of the \fBucontext_t\fR structure have changed as they apply to inputs to \fBmakecontext()\fR. Prior to Solaris 10, the \fBss_sp\fR member of the \fBuc_stack\fR structure represented the high memory address of the area reserved for the stack. The \fBss_sp\fR member now represents the base (low memory address), in keeping with other uses of \fBss_sp\fR. .sp .LP This change in the meaning of \fBss_sp\fR is now the default behavior. The \fB-D__MAKECONTEXT_V2_SOURCE\fR compilation flag used in Solaris 9 update releases to access this behavior is obsolete. .sp .LP Binary compatibility has been preserved with releases prior to Solaris 10. Before recompiling, applications that use \fBmakecontext()\fR must be updated to reflect this behavior change. The example below demonstrates a typical change that must be applied: .sp .in +2 .nf --- example1_s9.c Thu Oct 3 11:58:17 2002 +++ example1.c Thu Jun 27 13:28:16 2002 @@ -27,12 +27,9 @@ uc.uc_stack.ss_sp = mmap(0, sz, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANON, -1, 0); - uc.uc_stack.ss_sp = (char *)uc.uc_stack.ss_sp + sz - 8; uc.uc_stack.ss_size = sz; uc.uc_stack.ss_flags = 0; uc.uc_link = &back makecontext(&uc, assign, 2, 100L, &value); .fi .in -2 .sp