Add API for obtaining extended machine context states that cannot be
fit into existing mcontext_t. On i386 and amd64 do return the extended FPU states using getcontextx(3). For other architectures, getcontextx(3) returns the same information as getcontext(2). Tested by: pho MFC after: 1 month
This commit is contained in:
parent
3572bdc783
commit
8c121450bc
@ -2,7 +2,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= _setjmp.S _set_tp.c rfork_thread.S setjmp.S sigsetjmp.S \
|
||||
fabs.S \
|
||||
fabs.S getcontextx.c \
|
||||
infinity.c ldexp.c makecontext.c signalcontext.c \
|
||||
flt_rounds.c fpgetmask.c fpsetmask.c fpgetprec.c fpsetprec.c \
|
||||
fpgetround.c fpsetround.c fpgetsticky.c
|
||||
|
101
lib/libc/amd64/gen/getcontextx.c
Normal file
101
lib/libc/amd64/gen/getcontextx.c
Normal file
@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <machine/cpufunc.h>
|
||||
#include <machine/fpu.h>
|
||||
#include <machine/specialreg.h>
|
||||
#include <machine/sysarch.h>
|
||||
|
||||
static int xstate_sz = -1;
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
u_int p[4];
|
||||
|
||||
if (xstate_sz == -1) {
|
||||
do_cpuid(1, p);
|
||||
if ((p[2] & CPUID2_OSXSAVE) != 0) {
|
||||
cpuid_count(0xd, 0x0, p);
|
||||
xstate_sz = p[1] - sizeof(struct savefpu);
|
||||
} else
|
||||
xstate_sz = 0;
|
||||
}
|
||||
|
||||
return (sizeof(ucontext_t) + xstate_sz);
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
struct amd64_get_xfpustate xfpu;
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
if (getcontext(ucp) == -1)
|
||||
return (-1);
|
||||
if (xstate_sz != 0) {
|
||||
xfpu.addr = (char *)(ucp + 1);
|
||||
xfpu.len = xstate_sz;
|
||||
if (sysarch(AMD64_GET_XFPUSTATE, &xfpu) == -1)
|
||||
return (-1);
|
||||
ucp->uc_mcontext.mc_xfpustate = (__register_t)xfpu.addr;
|
||||
ucp->uc_mcontext.mc_xfpustate_len = xstate_sz;
|
||||
ucp->uc_mcontext.mc_flags |= _MC_HASFPXSTATE;
|
||||
} else {
|
||||
ucp->uc_mcontext.mc_xfpustate = 0;
|
||||
ucp->uc_mcontext.mc_xfpustate_len = 0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -2,5 +2,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= _ctx_start.S _setjmp.S _set_tp.c alloca.S fabs.c \
|
||||
infinity.c ldexp.c makecontext.c \
|
||||
getcontextx.c infinity.c ldexp.c makecontext.c \
|
||||
setjmp.S signalcontext.c sigsetjmp.S divsi3.S flt_rounds.c
|
||||
|
69
lib/libc/arm/gen/getcontextx.c
Normal file
69
lib/libc/arm/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -384,6 +384,7 @@ FBSD_1.2 {
|
||||
FBSD_1.3 {
|
||||
fdlopen;
|
||||
__FreeBSD_libc_enter_restricted_mode;
|
||||
getcontextx;
|
||||
};
|
||||
|
||||
FBSDprivate_1.0 {
|
||||
@ -507,4 +508,6 @@ FBSDprivate_1.0 {
|
||||
|
||||
__elf_aux_vector;
|
||||
__pthread_map_stacks_exec;
|
||||
__fillcontextx;
|
||||
__getcontextx_size;
|
||||
};
|
||||
|
@ -35,11 +35,11 @@
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd September 10, 2002
|
||||
.Dd December 26, 2011
|
||||
.Dt GETCONTEXT 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm getcontext , setcontext
|
||||
.Nm getcontext , getcontextx , setcontext
|
||||
.Nd get and set user thread context
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
@ -59,6 +59,20 @@ This saved context may then later be restored by calling
|
||||
.Fn setcontext .
|
||||
.Pp
|
||||
The
|
||||
.Fn getcontextx
|
||||
function saves the current execution context in the newly allocated structure
|
||||
.Vt ucontext_t ,
|
||||
which is returned on success.
|
||||
If architecture defines additional CPU states that can be stored in extended
|
||||
blocks referenced from the
|
||||
.Vt ucontext_t ,
|
||||
the memory for them may be allocated and their context also stored.
|
||||
Memory returned by
|
||||
.Fn getcontextx
|
||||
function shall be freed using
|
||||
.Fn free 3 .
|
||||
.Pp
|
||||
The
|
||||
.Fn setcontext
|
||||
function
|
||||
makes a previously saved thread context the current thread context, i.e.,
|
||||
@ -109,11 +123,24 @@ If successful,
|
||||
returns zero and
|
||||
.Fn setcontext
|
||||
does not return; otherwise \-1 is returned.
|
||||
The
|
||||
.Fn getcontextx
|
||||
returns pointer to the allocated and initialized context on success, and
|
||||
.Va NULL
|
||||
on failure.
|
||||
.Sh ERRORS
|
||||
No errors are defined for
|
||||
.Fn getcontext
|
||||
or
|
||||
.Fn setcontext .
|
||||
The
|
||||
.Fn getcontextx
|
||||
may return the following errors in
|
||||
.Va errno :
|
||||
.Bl -tag -width Er
|
||||
.It Bq Er ENOMEM
|
||||
No memory was available to allocate for the context or some extended state.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr sigaction 2 ,
|
||||
.Xr sigaltstack 2 ,
|
||||
|
@ -92,6 +92,9 @@ structures:
|
||||
.Ft int
|
||||
.Fn getcontext "ucontext_t *" ;
|
||||
.It
|
||||
.Ft "ucontext_t *"
|
||||
.Fn getcontextx "void" ;
|
||||
.It
|
||||
.Ft int
|
||||
.Fn setcontext "const ucontext_t *" ;
|
||||
.It
|
||||
@ -104,4 +107,5 @@ structures:
|
||||
.Sh SEE ALSO
|
||||
.Xr sigaltstack 2 ,
|
||||
.Xr getcontext 3 ,
|
||||
.Xr getcontextx 3 ,
|
||||
.Xr makecontext 3
|
||||
|
@ -2,5 +2,5 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= _ctx_start.S _setjmp.S _set_tp.c fabs.S \
|
||||
flt_rounds.c infinity.c ldexp.c makecontext.c \
|
||||
flt_rounds.c getcontextx.c infinity.c ldexp.c makecontext.c \
|
||||
rfork_thread.S setjmp.S signalcontext.c sigsetjmp.S
|
||||
|
133
lib/libc/i386/gen/getcontextx.c
Normal file
133
lib/libc/i386/gen/getcontextx.c
Normal file
@ -0,0 +1,133 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <machine/npx.h>
|
||||
#include <machine/specialreg.h>
|
||||
#include <machine/sysarch.h>
|
||||
|
||||
static int xstate_sz = -1;
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
u_int p[4];
|
||||
int cpuid_supported;
|
||||
|
||||
if (xstate_sz == -1) {
|
||||
__asm __volatile(
|
||||
" pushfl\n"
|
||||
" popl %%eax\n"
|
||||
" movl %%eax,%%ecx\n"
|
||||
" xorl $0x200000,%%eax\n"
|
||||
" pushl %%eax\n"
|
||||
" popfl\n"
|
||||
" pushfl\n"
|
||||
" popl %%eax\n"
|
||||
" xorl %%eax,%%ecx\n"
|
||||
" je 1f\n"
|
||||
" movl $1,%0\n"
|
||||
" jmp 2f\n"
|
||||
"1: movl $0,%0\n"
|
||||
"2:\n"
|
||||
: "=r" (cpuid_supported) : : "eax", "ecx");
|
||||
if (cpuid_supported) {
|
||||
__asm __volatile(
|
||||
" pushl %%ebx\n"
|
||||
" cpuid\n"
|
||||
" movl %%ebx,%1\n"
|
||||
" popl %%ebx\n"
|
||||
: "=a" (p[0]), "=r" (p[1]), "=c" (p[2]), "=d" (p[3])
|
||||
: "0" (0x0));
|
||||
if ((p[2] & CPUID2_OSXSAVE) != 0) {
|
||||
__asm __volatile(
|
||||
" pushl %%ebx\n"
|
||||
" cpuid\n"
|
||||
" movl %%ebx,%1\n"
|
||||
" popl %%ebx\n"
|
||||
: "=a" (p[0]), "=r" (p[1]), "=c" (p[2]),
|
||||
"=d" (p[3])
|
||||
: "0" (0xd), "2" (0x0));
|
||||
xstate_sz = p[1] - sizeof(struct savexmm);
|
||||
} else
|
||||
xstate_sz = 0;
|
||||
} else
|
||||
xstate_sz = 0;
|
||||
}
|
||||
|
||||
return (sizeof(ucontext_t) + xstate_sz);
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
struct i386_get_xfpustate xfpu;
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
if (getcontext(ucp) == -1)
|
||||
return (-1);
|
||||
if (xstate_sz != 0) {
|
||||
xfpu.addr = (char *)(ucp + 1);
|
||||
xfpu.len = xstate_sz;
|
||||
if (sysarch(I386_GET_XFPUSTATE, &xfpu) == -1)
|
||||
return (-1);
|
||||
ucp->uc_mcontext.mc_xfpustate = (__register_t)xfpu.addr;
|
||||
ucp->uc_mcontext.mc_xfpustate_len = xstate_sz;
|
||||
ucp->uc_mcontext.mc_flags |= _MC_HASFPXSTATE;
|
||||
} else {
|
||||
ucp->uc_mcontext.mc_xfpustate = 0;
|
||||
ucp->uc_mcontext.mc_xfpustate_len = 0;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
SRCS+= __divdf3.S __divdi3.S __divsf3.S __divsi3.S __moddi3.S __modsi3.S \
|
||||
__udivdi3.S __udivsi3.S __umoddi3.S __umodsi3.S _mcount.S _set_tp.c \
|
||||
_setjmp.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c fpsetmask.c \
|
||||
fpsetround.c infinity.c ldexp.c makecontext.c setjmp.S \
|
||||
fpsetround.c getcontextx.c infinity.c ldexp.c makecontext.c setjmp.S \
|
||||
signalcontext.c sigsetjmp.S
|
||||
|
||||
# The following may go away if function _Unwind_FindTableEntry()
|
||||
|
69
lib/libc/ia64/gen/getcontextx.c
Normal file
69
lib/libc/ia64/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -6,4 +6,5 @@ SRCS+= infinity.c fabs.c ldexp.c
|
||||
# SRCS+= flt_rounds.c fpgetmask.c fpgetround.c fpgetsticky.c fpsetmask.c \
|
||||
# fpsetround.c fpsetsticky.c
|
||||
|
||||
SRCS+= _ctx_start.S _set_tp.c _setjmp.S makecontext.c setjmp.S signalcontext.c sigsetjmp.S
|
||||
SRCS+= _ctx_start.S _set_tp.c _setjmp.S getcontextx.c makecontext.c \
|
||||
setjmp.S signalcontext.c sigsetjmp.S
|
||||
|
69
lib/libc/mips/gen/getcontextx.c
Normal file
69
lib/libc/mips/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
|
||||
fpgetsticky.c fpsetmask.c fpsetround.c \
|
||||
fpgetsticky.c fpsetmask.c fpsetround.c getcontextx.c \
|
||||
infinity.c ldexp.c makecontext.c _setjmp.S \
|
||||
setjmp.S sigsetjmp.S signalcontext.c syncicache.c \
|
||||
_set_tp.c
|
||||
|
69
lib/libc/powerpc/gen/getcontextx.c
Normal file
69
lib/libc/powerpc/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS += _ctx_start.S fabs.S flt_rounds.c fpgetmask.c fpgetround.c \
|
||||
fpgetsticky.c fpsetmask.c fpsetround.c \
|
||||
fpgetsticky.c fpsetmask.c fpsetround.c getcontextx.c \
|
||||
infinity.c ldexp.c makecontext.c _setjmp.S \
|
||||
setjmp.S sigsetjmp.S signalcontext.c syncicache.c \
|
||||
_set_tp.c
|
||||
|
69
lib/libc/powerpc64/gen/getcontextx.c
Normal file
69
lib/libc/powerpc64/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -2,5 +2,5 @@
|
||||
|
||||
SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \
|
||||
fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c \
|
||||
infinity.c ldexp.c makecontext.c \
|
||||
getcontextx.c infinity.c ldexp.c makecontext.c \
|
||||
signalcontext.c setjmp.S sigsetjmp.S _set_tp.c
|
||||
|
69
lib/libc/sparc64/gen/getcontextx.c
Normal file
69
lib/libc/sparc64/gen/getcontextx.c
Normal file
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2011 Konstantin Belousov <kib@FreeBSD.org>
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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 AUTHOR ``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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/ucontext.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
size_t
|
||||
__getcontextx_size(void)
|
||||
{
|
||||
|
||||
return (sizeof(ucontext_t));
|
||||
}
|
||||
|
||||
int
|
||||
__fillcontextx(char *ctx)
|
||||
{
|
||||
ucontext_t *ucp;
|
||||
|
||||
ucp = (ucontext_t *)ctx;
|
||||
return (getcontext(ucp));
|
||||
}
|
||||
|
||||
__weak_reference(__getcontextx, getcontextx);
|
||||
|
||||
ucontext_t *
|
||||
__getcontextx(void)
|
||||
{
|
||||
char *ctx;
|
||||
int error;
|
||||
|
||||
ctx = malloc(__getcontextx_size());
|
||||
if (ctx == NULL)
|
||||
return (NULL);
|
||||
if (__fillcontextx(ctx) == -1) {
|
||||
error = errno;
|
||||
free(ctx);
|
||||
errno = error;
|
||||
return (NULL);
|
||||
}
|
||||
return ((ucontext_t *)ctx);
|
||||
}
|
@ -72,11 +72,17 @@ struct ucontext4 {
|
||||
__BEGIN_DECLS
|
||||
|
||||
int getcontext(ucontext_t *);
|
||||
ucontext_t *getcontextx(void);
|
||||
int setcontext(const ucontext_t *);
|
||||
void makecontext(ucontext_t *, void (*)(void), int, ...);
|
||||
int signalcontext(ucontext_t *, int, __sighandler_t *);
|
||||
int swapcontext(ucontext_t *, const ucontext_t *);
|
||||
|
||||
#if __BSD_VISIBLE
|
||||
size_t __getcontextx_size(void);
|
||||
int __fillcontextx(char *ctx);
|
||||
#endif
|
||||
|
||||
__END_DECLS
|
||||
|
||||
#else /* _KERNEL */
|
||||
|
Loading…
Reference in New Issue
Block a user