NetBSD/share/man/man2/ucontext.2

138 lines
4.2 KiB
Groff

.\" $NetBSD: ucontext.2,v 1.10 2018/02/27 10:09:42 uwe Exp $
.\"
.\" Copyright (c) 2001 The NetBSD Foundation, Inc.
.\" All rights reserved.
.\"
.\" This code is derived from software contributed to The NetBSD Foundation
.\" by Klaus Klein.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd February 25, 2018
.Dt UCONTEXT 2
.Os
.Sh NAME
.Nm ucontext
.Nd user context
.Sh SYNOPSIS
.In ucontext.h
.Fn _UC_MACHINE_SP "&uc"
.Fn _UC_MACHINE_FP "&uc"
.Fn _UC_MACHINE_PC "&uc"
.Fn _UC_MACHINE_INTRV "&uc"
.Fn _UC_MACHINE_SET_PC "&uc"
.Sh DESCRIPTION
The
.Vt ucontext_t
is a structure type which is used to describe the context of a
thread of control within the execution of a process.
A thread's context includes its stack, saved registers, and list of
blocked signals.
.Pp
The
.Vt ucontext_t
structure includes the following members:
.Bd -literal -offset indent
ucontext_t *uc_link
sigset_t uc_sigmask
stack_t uc_stack
mcontext_t uc_mcontext
.Ed
.Pp
The
.Fa uc_link
member points to the context that will be resumed after the function
specified when modifying a context using
.Xr makecontext 3
has returned.
If
.Fa uc_link
is a
.Dv NULL
pointer, then the context is the main context,
and the process will exit with an exit status of 0 upon return.
.Pp
The
.Fa uc_sigmask
member is the set of signals that are blocked when the context is
activated.
Further information can be found in
.Xr sigprocmask 2 .
.Pp
The
.Fa uc_stack
member defines the stack used by the context.
Further information can be found in
.Xr sigaltstack 2 .
.Pp
The
.Fa uc_mcontext
member defines the machine state associated with the context;
it may consist of general registers, floating point registers
and other machine-specific information.
Its description is beyond the scope of this manual page;
portable applications should not access this structure member.
.Pp
The following auxiliary macros are available to access some of that
machine-specific information:
.Bl -tag -width ".Fn _UC_MACHINE_SET_PC" -offset indent
.It Fn _UC_MACHINE_SP
\(em read stack pointer,
.It Fn _UC_MACHINE_FP
\(em read frame pointer (base pointer),
.It Fn _UC_MACHINE_PC
\(em read program counter,
.It Fn _UC_MACHINE_INTRV
\(em read integer return value,
.It Fn _UC_MACHINE_SET_PC
\(em write program counter.
.El
.Pp
The frame pointer macro does not guarantee to retrieve a reliable value
and should not be used in a code unless no other debugging format is
easily accessible.
A compiler might optimize the frame pointer register in a function,
reusing it as a general purpose register storage
.Fl ( fomit-frame-pointer )
or emit function prologues only before parts that need them
.Fl ( fshrink-wrap ) .
.Sh SEE ALSO
.Xr _exit 2 ,
.Xr getcontext 2 ,
.Xr setcontext 2 ,
.Xr sigaltstack 2 ,
.Xr sigprocmask 2 ,
.Xr makecontext 3 ,
.Xr swapcontext 3
.Sh STANDARDS
The
.Vt ucontext_t
type conforms to
.St -xsh5
and
.St -p1003.1-2001 .
The
.St -p1003.1-2008
revision removed the
.Vt ucontext_t
from the specification.