From 1fe838905f946528b59f70ab7069f09b1cbe7ddf Mon Sep 17 00:00:00 2001 From: mini Date: Mon, 16 Sep 2002 19:23:35 +0000 Subject: Add signalcontext(), which lays down a signal frame onto a ucontext_t. Reviewed by: deischen, julian Approved by: -arch --- lib/libc/gen/swapcontext.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/swapcontext.c b/lib/libc/gen/swapcontext.c index d58ae6d..eeb2f78 100644 --- a/lib/libc/gen/swapcontext.c +++ b/lib/libc/gen/swapcontext.c @@ -27,29 +27,32 @@ #include __FBSDID("$FreeBSD$"); +#include +#include +#include + #include -#include #include -#include __weak_reference(__swapcontext, swapcontext); int __swapcontext(ucontext_t *oucp, const ucontext_t *ucp) { - volatile int swapping; int ret; - if (oucp == NULL || ucp == NULL) { + if ((oucp == NULL) || + (oucp->uc_mcontext.mc_len != sizeof(mcontext_t)) || + (ucp == NULL) || + (ucp->uc_mcontext.mc_len != sizeof(mcontext_t))) { errno = EINVAL; - ret = -1; - } else { - swapping = 0; - ret = getcontext(oucp); - if (ret == 0 && swapping == 0) { - swapping = 1; - ret = setcontext(ucp); - } + return (-1); + } + oucp->uc_flags &= ~UCF_SWAPPED; + ret = getcontext(oucp); + if ((ret == 0) && !(oucp->uc_flags & UCF_SWAPPED)) { + oucp->uc_flags |= UCF_SWAPPED; + ret = setcontext(ucp); } return (ret); } -- cgit v1.1