From 9f5a511863d54c3ad81a1a3a7106da655dbe21a8 Mon Sep 17 00:00:00 2001 From: Jake Burkholder Date: Tue, 1 Apr 2003 23:28:50 +0000 Subject: [PATCH] Implement makecontext. --- lib/libc/sparc64/gen/Makefile.inc | 7 ++- lib/libc/sparc64/gen/_ctx_start.S | 36 ++++++++++++ lib/libc/sparc64/gen/makecontext.c | 89 ++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+), 3 deletions(-) create mode 100644 lib/libc/sparc64/gen/_ctx_start.S create mode 100644 lib/libc/sparc64/gen/makecontext.c diff --git a/lib/libc/sparc64/gen/Makefile.inc b/lib/libc/sparc64/gen/Makefile.inc index 9024d28fbca5..85ecfbd5fcf9 100644 --- a/lib/libc/sparc64/gen/Makefile.inc +++ b/lib/libc/sparc64/gen/Makefile.inc @@ -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 diff --git a/lib/libc/sparc64/gen/_ctx_start.S b/lib/libc/sparc64/gen/_ctx_start.S new file mode 100644 index 000000000000..4ba3fd80624b --- /dev/null +++ b/lib/libc/sparc64/gen/_ctx_start.S @@ -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 +__FBSDID("$FreeBSD$"); + +ENTRY(_ctx_start) + call %g1 + mov %g2, %l0 + call _ctx_done + mov %l0, %o0 + illtrap +END(_ctx_start) diff --git a/lib/libc/sparc64/gen/makecontext.c b/lib/libc/sparc64/gen/makecontext.c new file mode 100644 index 000000000000..95795de992cf --- /dev/null +++ b/lib/libc/sparc64/gen/makecontext.c @@ -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 +__FBSDID("$FreeBSD$"); + +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +__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(); + } +}