⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 swapcontext.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>makecontext</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="makecontext"></a> <a name="tag_03_356"></a><!-- makecontext --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_03_356_01"></a>NAME</h4><blockquote>makecontext, swapcontext - manipulate user contexts</blockquote><h4><a name="tag_03_356_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><div class="box"><code><tt><sup>[<a href="javascript:open_code('XSI')">XSI</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> #include &lt;<a href="../basedefs/ucontext.h.html">ucontext.h</a>&gt;<br><br> void makecontext(ucontext_t *</tt><i>ucp</i><tt>, void (*</tt><i>func</i><tt>)(void),<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int</tt> <i>argc</i><tt>, ...);<br> int swapcontext(ucontext_t *restrict</tt> <i>oucp</i><tt>,<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; const ucontext_t *restrict</tt> <i>ucp</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_356_03"></a>DESCRIPTION</h4><blockquote><p>The <i>makecontext</i>() function shall modify the context specified by <i>ucp</i>, which has been initialized using <a href="../functions/getcontext.html"><i>getcontext</i>()</a>. When this context is resumed using <i>swapcontext</i>() or <a href="../functions/setcontext.html"><i>setcontext</i>()</a>, program execution shall continue by calling <i>func</i>, passing it thearguments that follow <i>argc</i> in the <i>makecontext</i>() call.</p><p>Before a call is made to <i>makecontext</i>(), the application shall ensure that the context being modified has a stackallocated for it. The application shall ensure that the value of <i>argc</i> matches the number of arguments of type <b>int</b>passed to <i>func</i>; otherwise, the behavior is undefined.</p><p>The <i>uc_link</i> member is used to determine the context that shall be resumed when the context being modified by<i>makecontext</i>() returns. The application shall ensure that the <i>uc_link</i> member is initialized prior to the call to<i>makecontext</i>().</p><p>The <i>swapcontext</i>() function shall save the current context in the context structure pointed to by <i>oucp</i> and shallset the context to the context structure pointed to by <i>ucp</i>.</p></blockquote><h4><a name="tag_03_356_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, <i>swapcontext</i>() shall return 0. Otherwise, -1 shall be returned and <i>errno</i> set toindicate the error.</p></blockquote><h4><a name="tag_03_356_05"></a>ERRORS</h4><blockquote><p>The <i>swapcontext</i>() function shall fail if:</p><dl compact><dt>[ENOMEM]</dt><dd>The <i>ucp</i> argument does not have enough stack left to complete the operation.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_356_06"></a>EXAMPLES</h4><blockquote><p>The following example illustrates the use of <i>makecontext</i>():</p><pre><tt>#include &lt;stdio.h&gt;#include &lt;ucontext.h&gt;<br>static ucontext_t ctx[3];<br>static voidf1 (void){    puts("start f1");    swapcontext(&amp;ctx[1], &amp;ctx[2]);    puts("finish f1");}<br>static voidf2 (void){    puts("start f2");    swapcontext(&amp;ctx[2], &amp;ctx[1]);    puts("finish f2");}<br>intmain (void){    char st1[8192];    char st2[8192];<br>    getcontext(&amp;ctx[1]);    ctx[1].uc_stack.ss_sp = st1;    ctx[1].uc_stack.ss_size = sizeof st1;    ctx[1].uc_link = &amp;ctx[0];    makecontext(&amp;ctx[1], f1, 0);<br>    getcontext(&amp;ctx[2]);    ctx[2].uc_stack.ss_sp = st2;    ctx[2].uc_stack.ss_size = sizeof st2;    ctx[2].uc_link = &amp;ctx[1];    makecontext(&amp;ctx[2], f2, 0);<br>    swapcontext(&amp;ctx[0], &amp;ctx[2]);    return 0;}</tt></pre></blockquote><h4><a name="tag_03_356_07"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_356_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_356_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_356_10"></a>SEE ALSO</h4><blockquote><p><a href="exit.html"><i>exit</i>()</a> , <a href="getcontext.html"><i>getcontext</i>()</a> , <a href="sigaction.html"><i>sigaction</i>()</a> , <a href="sigprocmask.html"><i>sigprocmask</i>()</a> , the Base Definitions volume ofIEEE&nbsp;Std&nbsp;1003.1-2001, <a href="../basedefs/ucontext.h.html"><i>&lt;ucontext.h&gt;</i></a></p></blockquote><h4><a name="tag_03_356_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 4, Version 2.</p></blockquote><h4><a name="tag_03_356_12"></a>Issue 5</h4><blockquote><p>Moved from X/OPEN UNIX extension to BASE.</p><p>In the ERRORS section, the description of [ENOMEM] is changed to apply to <i>swapcontext</i>() only.</p></blockquote><h4><a name="tag_03_356_13"></a>Issue 6</h4><blockquote><p>The DESCRIPTION is updated to avoid use of the term &quot;must&quot; for application requirements.</p><p>The <b>restrict</b> keyword is added to the <i>swapcontext</i>() prototype for alignment with the ISO/IEC&nbsp;9899:1999standard.</p><p>IEEE&nbsp;Std 1003.1-2001/Cor&nbsp;1-2002, item XSH/TC1/D6/33 is applied, clarifying that the arguments passed to <i>func</i>are of type <b>int</b>.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX &reg; is a registered Trademark of The Open Group.<br>POSIX &reg; is a registered Trademark of The IEEE.<br>[ <a href="../mindex.html">Main Index</a> | <a href="../basedefs/contents.html">XBD</a> | <a href="../utilities/contents.html">XCU</a> | <a href="../functions/contents.html">XSH</a> | <a href="../xrat/contents.html">XRAT</a>]</font></center><!--footer end--><hr size="2" noshade></body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -