200 lines
6.4 KiB
HTML
200 lines
6.4 KiB
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 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-2001<br>
|
|
Copyright © 2001 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 <<a href="../basedefs/ucontext.h.html">ucontext.h</a>><br>
|
|
<br>
|
|
void makecontext(ucontext_t *</tt><i>ucp</i><tt>, void (*</tt><i>func</i><tt>)(void),<br>
|
|
int</tt> <i>argc</i><tt>, ...);<br>
|
|
int swapcontext(ucontext_t *restrict</tt> <i>oucp</i><tt>,<br>
|
|
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 the
|
|
arguments 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 stack
|
|
allocated for it. The application shall ensure that the value of <i>argc</i> matches the number of integer arguments 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 shall
|
|
set 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 to
|
|
indicate 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 <stdio.h>
|
|
#include <ucontext.h>
|
|
<br>
|
|
static ucontext_t ctx[3];
|
|
<br>
|
|
static void
|
|
f1 (void)
|
|
{
|
|
puts("start f1");
|
|
swapcontext(&ctx[1], &ctx[2]);
|
|
puts("finish f1");
|
|
}
|
|
<br>
|
|
static void
|
|
f2 (void)
|
|
{
|
|
puts("start f2");
|
|
swapcontext(&ctx[2], &ctx[1]);
|
|
puts("finish f2");
|
|
}
|
|
<br>
|
|
int
|
|
main (void)
|
|
{
|
|
char st1[8192];
|
|
char st2[8192];
|
|
<br>
|
|
getcontext(&ctx[1]);
|
|
ctx[1].uc_stack.ss_sp = st1;
|
|
ctx[1].uc_stack.ss_size = sizeof st1;
|
|
ctx[1].uc_link = &ctx[0];
|
|
makecontext(&ctx[1], f1, 0);
|
|
<br>
|
|
getcontext(&ctx[2]);
|
|
ctx[2].uc_stack.ss_sp = st2;
|
|
ctx[2].uc_stack.ss_size = sizeof st2;
|
|
ctx[2].uc_link = &ctx[1];
|
|
makecontext(&ctx[2], f2, 0);
|
|
<br>
|
|
swapcontext(&ctx[0], &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 of
|
|
IEEE Std 1003.1-2001, <a href="../basedefs/ucontext.h.html"><i><ucontext.h></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 "must" for application requirements.</p>
|
|
|
|
<p>The <b>restrict</b> keyword is added to the <i>swapcontext</i>() prototype for alignment with the ISO/IEC 9899:1999
|
|
standard.</p>
|
|
</blockquote>
|
|
|
|
<div class="box"><em>End of informative text.</em></div>
|
|
|
|
<hr>
|
|
<hr size="2" noshade>
|
|
<center><font size="2"><!--footer start-->
|
|
UNIX ® is a registered Trademark of The Open Group.<br>
|
|
POSIX ® 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>
|
|
|