Implement makecontext.
This commit is contained in:
parent
fc2fca74d8
commit
9f5a511863
@ -1,5 +1,6 @@
|
||||
# $FreeBSD$
|
||||
|
||||
SRCS+= _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c fpgetround.c \
|
||||
fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c frexp.c \
|
||||
infinity.c isinf.c ldexp.c modf.S setjmp.S sigsetjmp.S
|
||||
SRCS+= _ctx_start.S _setjmp.S fabs.S fixunsdfsi.S flt_rounds.c fpgetmask.c \
|
||||
fpgetround.c fpgetsticky.c fpsetmask.c fpsetround.c fpsetsticky.c \
|
||||
frexp.c infinity.c isinf.c ldexp.c makecontext.c modf.S setjmp.S \
|
||||
sigsetjmp.S
|
||||
|
36
lib/libc/sparc64/gen/_ctx_start.S
Normal file
36
lib/libc/sparc64/gen/_ctx_start.S
Normal file
@ -0,0 +1,36 @@
|
||||
/*-
|
||||
* Copyright (c) 2003 Jake Burkholder.
|
||||
* 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 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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <machine/asm.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
ENTRY(_ctx_start)
|
||||
call %g1
|
||||
mov %g2, %l0
|
||||
call _ctx_done
|
||||
mov %l0, %o0
|
||||
illtrap
|
||||
END(_ctx_start)
|
89
lib/libc/sparc64/gen/makecontext.c
Normal file
89
lib/libc/sparc64/gen/makecontext.c
Normal file
@ -0,0 +1,89 @@
|
||||
/*-
|
||||
* Copyright (c) 2003 Jake Burkholder.
|
||||
* 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 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 AUTHOR 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.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/signal.h>
|
||||
#include <sys/ucontext.h>
|
||||
|
||||
#include <machine/frame.h>
|
||||
#include <machine/tstate.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
||||
__weak_reference(__makecontext, makecontext);
|
||||
|
||||
void _ctx_done(ucontext_t *ucp);
|
||||
void _ctx_start(void);
|
||||
|
||||
void
|
||||
__makecontext(ucontext_t *ucp, void (*start)(void), int argc, ...)
|
||||
{
|
||||
mcontext_t *mc;
|
||||
uint64_t sp;
|
||||
va_list ap;
|
||||
int i;
|
||||
|
||||
mc = &ucp->uc_mcontext;
|
||||
if (ucp == NULL ||
|
||||
(mc->mc_flags & ((1L << _MC_VERSION_BITS) - 1)) != _MC_VERSION)
|
||||
return;
|
||||
if ((argc < 0) || (argc > 6) ||
|
||||
(ucp->uc_stack.ss_sp == NULL) ||
|
||||
(ucp->uc_stack.ss_size < MINSIGSTKSZ)) {
|
||||
mc->mc_flags = 0;
|
||||
return;
|
||||
}
|
||||
mc = &ucp->uc_mcontext;
|
||||
sp = (uint64_t)ucp->uc_stack.ss_sp + ucp->uc_stack.ss_size;
|
||||
va_start(ap, argc);
|
||||
for (i = 0; i < argc; i++)
|
||||
mc->mc_out[i] = va_arg(ap, uint64_t);
|
||||
va_end(ap);
|
||||
mc->mc_global[1] = (uint64_t)start;
|
||||
mc->mc_global[2] = (uint64_t)ucp;
|
||||
mc->mc_out[6] = sp - SPOFF - sizeof(struct frame);
|
||||
mc->mc_tnpc = (uint64_t)_ctx_start + 4;
|
||||
mc->mc_tpc = (uint64_t)_ctx_start;
|
||||
}
|
||||
|
||||
void
|
||||
_ctx_done(ucontext_t *ucp)
|
||||
{
|
||||
|
||||
if (ucp->uc_link == NULL)
|
||||
exit(0);
|
||||
else {
|
||||
ucp->uc_mcontext.mc_flags = 0;
|
||||
setcontext((const ucontext_t *)ucp->uc_link);
|
||||
abort();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user