📄 getcontext.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title>getcontext</title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4><a name = "tag_000_005_479"> </a>NAME</h4><blockquote>getcontext, setcontext - get and set current user context</blockquote><h4><a name = "tag_000_005_480"> </a>SYNOPSIS</h4><blockquote><pre><code>#include <<a href="ucontext.h.html">ucontext.h</a>>int getcontext(ucontext_t *<i>ucp</i>);int setcontext(const ucontext_t *<i>ucp</i>);</code></pre></blockquote><h4><a name = "tag_000_005_481"> </a>DESCRIPTION</h4><blockquote>The<i>getcontext()</i>function initialises the structure pointed to by <i>ucp</i> to the current usercontext of the calling thread. The<b>ucontext_t</b>type that <i>ucp</i>points to defines the user context and includes the contents of the callingthread's machine registers, the signal mask, and the current execution stack.<p>The<i><a href="setcontext.html">setcontext()</a></i>function restores the user context pointed to by <i>ucp</i>. A successfulcall to<i><a href="setcontext.html">setcontext()</a></i>does not return; program execution resumes at the pointspecified by the <i>ucp</i> argument passed to<i><a href="setcontext.html">setcontext()</a></i>.The <i>ucp</i> argument should be created either by a prior call to<i>getcontext()</i>or<i><a href="makecontext.html">makecontext()</a></i>,or by being passed as an argument to a signal handler.If the <i>ucp</i> argument was created with<i>getcontext()</i>,program execution continues as if the corresponding call of<i>getcontext()</i>had just returned. If the <i>ucp</i> argument was created with<i><a href="makecontext.html">makecontext()</a></i>,program execution continues with the function passed to<i><a href="makecontext.html">makecontext()</a></i>.When that function returns, the thread continues as if after a call to<i><a href="setcontext.html">setcontext()</a></i>with the <i>ucp</i> argument that was input to<i><a href="makecontext.html">makecontext()</a></i>.If the <b>uc_link</b> member of the<b>ucontext_t</b>structure pointed to by the <i>ucp</i>argument is equal to 0, then this context is the main context, and the threadwill exit when this context returns. The effects of passing a <i>ucp</i>argument obtained from any other source are unspecified.</blockquote><h4><a name = "tag_000_005_482"> </a>RETURN VALUE</h4><blockquote>On successful completion,<i><a href="setcontext.html">setcontext()</a></i>does not return and<i>getcontext()</i>returns 0.Otherwise, a valueof -1 is returned.</blockquote><h4><a name = "tag_000_005_483"> </a>ERRORS</h4><blockquote>No errors are defined.</blockquote><h4><a name = "tag_000_005_484"> </a>EXAMPLES</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_485"> </a>APPLICATION USAGE</h4><blockquote>When a signal handler is executed, the current user context is saved and a newcontext is created. If the thread leaves the signal handler via<i><a href="longjmp.html">longjmp()</a></i>,then it is unspecified whether the context at the time of the corresponding<i><a href="setjmp.html">setjmp()</a></i>call is restored and thus whether future calls to<i>getcontext()</i>will provide an accurate representation of the current context, since thecontext restored by<i><a href="longjmp.html">longjmp()</a></i>does not necessarily contain all the information that<i><a href="setcontext.html">setcontext()</a></i>requires. Signal handlers should use<i><a href="siglongjmp.html">siglongjmp()</a></i>or<i><a href="setcontext.html">setcontext()</a></i>instead.<p>Portable applications should not modify or access the <b>uc_mcontext</b>member of <b>ucontext_t</b>. A portable application cannot assume that contextincludes any process-wide static data, possibly including<i>errno</i>.Users manipulating contexts should take care to handle these explicitly whenrequired.<p>Use of contexts to create alternate stacks is not defined by thisspecification.</blockquote><h4><a name = "tag_000_005_486"> </a>FUTURE DIRECTIONS</h4><blockquote>None.</blockquote><h4><a name = "tag_000_005_487"> </a>SEE ALSO</h4><blockquote><i><a href="bsd_signal.html">bsd_signal()</a></i>,<i><a href="makecontext.html">makecontext()</a></i>,<i><a href="setjmp.html">setjmp()</a></i>,<i><a href="sigaction.html">sigaction()</a></i>,<i><a href="sigaltstack.html">sigaltstack()</a></i>,<i><a href="sigprocmask.html">sigprocmask()</a></i>,<i><a href="sigsetjmp.html">sigsetjmp()</a></i>,<i><a href="ucontext.h.html"><ucontext.h></a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -