.\" -*- coding: UTF-8 -*- .\" Copyright (C) 2001 Andries Brouwer (aeb@cwi.nl) .\" and Copyright (C) 2006 Michael Kerrisk .\" .\" %%%LICENSE_START(VERBATIM) .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one. .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" %%%LICENSE_END .\" .\" 2006-08-02, mtk, Added example program .\" .\"******************************************************************* .\" .\" This file was generated with po4a. Translate the source file. .\" .\"******************************************************************* .TH MAKECONTEXT 3 "21 Diciembre 2020" GNU "Manual del Programador de Linux" .SH NOMBRE makecontext, swapcontext \- manipulan el contexto de usuario .SH SINOPSIS \fB#include \fP .PP \fBvoid makecontext(ucontext_t *\fP\fIucp\fP\fB, void (*\fP\fIfunc\fP\fB)(),\fP \fBint \fP\fIargc\fP\fB, ...);\fP .PP \fBint swapcontext(ucontext_t *\fP\fIoucp\fP\fB, const ucontext_t *\fP\fIucp\fP\fB);\fP .SH DESCRIPCIÓN In a System V\-like environment, one has the type \fIucontext_t\fP (defined in \fI\fP and described in \fBgetcontext\fP(3)) and the four functions \fBgetcontext\fP(3), \fBsetcontext\fP(3), \fBmakecontext\fP(), and \fBswapcontext\fP() that allow user\-level context switching between multiple threads of control within a process. .PP The \fBmakecontext\fP() function modifies the context pointed to by \fIucp\fP (which was obtained from a call to \fBgetcontext\fP(3)). Before invoking \fBmakecontext\fP(), the caller must allocate a new stack for this context and assign its address to \fIucp\->uc_stack\fP, and define a successor context and assign its address to \fIucp\->uc_link\fP. .PP When this context is later activated (using \fBsetcontext\fP(3) or \fBswapcontext\fP()) the function \fIfunc\fP is called, and passed the series of integer (\fIint\fP) arguments that follow \fIargc\fP; the caller must specify the number of these arguments in \fIargc\fP. When this function returns, the successor context is activated. If the successor context pointer is NULL, the thread exits. .PP La función \fBswapcontext\fP() salva el contexto actual en la estructura apuntada por \fIoucp\fP, y activa el contexto apuntado por \fIucp\fP. .SH "VALOR DEVUELTO" When successful, \fBswapcontext\fP() does not return. (But we may return later, in case \fIoucp\fP is activated, in which case it looks like \fBswapcontext\fP() returns 0.) On error, \fBswapcontext\fP() returns \-1 and sets \fIerrno\fP appropriately. .SH ERRORES .TP \fBENOMEM\fP No queda suficiente espacio en la pila. .SH VERSIONES \fBmakecontext\fP() and \fBswapcontext\fP() are provided in glibc since version 2.1. .SH ATRIBUTOS Para obtener una explicación de los términos usados en esta sección, véase \fBattributes\fP(7). .TS allbox; lb lb lb l l l. Interfaz Atributo Valor T{ \fBmakecontext\fP() T} Seguridad del hilo MT\-Safe race:ucp T{ \fBswapcontext\fP() T} Seguridad del hilo MT\-Safe race:oucp race:ucp .TE .SH "CONFORME A" SUSv2, POSIX.1\-2001. POSIX.1\-2008 removes the specifications of \fBmakecontext\fP() and \fBswapcontext\fP(), citing portability issues, and recommending that applications be rewritten to use POSIX threads instead. .SH NOTAS La interpretación de \fIucp\->uc_stack\fP es como en \fBsigaltstack\fP(2), a saber, esta estructura contiene el comienzo y la longitud de un área de memoria a ser usada como pila, sea cual sea la dirección de crecimiento de la pila. Por lo tanto, no es necesario que los programas de usuario se preocupen por esta dirección. .PP On architectures where \fIint\fP and pointer types are the same size (e.g., x86\-32, where both types are 32 bits), you may be able to get away with passing pointers as arguments to \fBmakecontext\fP() following \fIargc\fP. However, doing this is not guaranteed to be portable, is undefined according to the standards, and won't work on architectures where pointers are larger than \fIint\fPs. Nevertheless, starting with version 2.8, glibc makes some changes to \fBmakecontext\fP(), to permit this on some 64\-bit architectures (e.g., x86\-64). .SH EJEMPLOS The example program below demonstrates the use of \fBgetcontext\fP(3), \fBmakecontext\fP(), and \fBswapcontext\fP(). Running the program produces the following output: .PP .in +4n .EX $\fB ./a.out\fP main: swapcontext(&uctx_main, &uctx_func2) func2: started func2: swapcontext(&uctx_func2, &uctx_func1) func1: started func1: swapcontext(&uctx_func1, &uctx_func2) func2: returning func1: returning main: exiting .EE .in .SS "Program source" \& .EX #include #include #include static ucontext_t uctx_main, uctx_func1, uctx_func2; #define handle_error(msg) \e do { perror(msg); exit(EXIT_FAILURE); } while (0) static void func1(void) { printf("func1: started\en"); printf("func1: swapcontext(&uctx_func1, &uctx_func2)\en"); if (swapcontext(&uctx_func1, &uctx_func2) == \-1) handle_error("swapcontext"); printf("func1: returning\en"); } static void func2(void) { printf("func2: started\en"); printf("func2: swapcontext(&uctx_func2, &uctx_func1)\en"); if (swapcontext(&uctx_func2, &uctx_func1) == \-1) handle_error("swapcontext"); printf("func2: returning\en"); } int main(int argc, char *argv[]) { char func1_stack[16384]; char func2_stack[16384]; if (getcontext(&uctx_func1) == \-1) handle_error("getcontext"); uctx_func1.uc_stack.ss_sp = func1_stack; uctx_func1.uc_stack.ss_size = sizeof(func1_stack); uctx_func1.uc_link = &uctx_main; makecontext(&uctx_func1, func1, 0); if (getcontext(&uctx_func2) == \-1) handle_error("getcontext"); uctx_func2.uc_stack.ss_sp = func2_stack; uctx_func2.uc_stack.ss_size = sizeof(func2_stack); /* Successor context is f1(), unless argc > 1 */ uctx_func2.uc_link = (argc > 1) ? NULL : &uctx_func1; makecontext(&uctx_func2, func2, 0); printf("main: swapcontext(&uctx_main, &uctx_func2)\en"); if (swapcontext(&uctx_main, &uctx_func2) == \-1) handle_error("swapcontext"); printf("main: exiting\en"); exit(EXIT_SUCCESS); } .EE .SH "VÉASE TAMBIÉN" \fBsigaction\fP(2), \fBsigaltstack\fP(2), \fBsigprocmask\fP(2), \fBgetcontext\fP(3), \fBsigsetjmp\fP(3) .SH COLOFÓN Esta página es parte de la versión 5.10 del proyecto Linux \fIman\-pages\fP. Puede encontrar una descripción del proyecto, información sobre cómo informar errores y la última versión de esta página en \%https://www.kernel.org/doc/man\-pages/. .SH TRADUCCIÓN La traducción al español de esta página del manual fue creada por Miguel Pérez Ibars . Esta traducción es documentación libre; lea la .UR https://www.gnu.org/licenses/gpl-3.0.html GNU General Public License Version 3 .UE o posterior con respecto a las condiciones de copyright. No existe NINGUNA RESPONSABILIDAD. Si encuentra algún error en la traducción de esta página del manual, envíe un correo electrónico a .MT debian-l10n-spanish@lists.debian.org>. .ME .