summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormini <mini@FreeBSD.org>2002-09-16 19:23:35 +0000
committermini <mini@FreeBSD.org>2002-09-16 19:23:35 +0000
commit1fe838905f946528b59f70ab7069f09b1cbe7ddf (patch)
tree2f584b9bb7764091a75bb599ec028bf34ccd43bf /lib
parent0bd2d50e9f175b6911e183858f780a01cb55f4f6 (diff)
downloadFreeBSD-src-1fe838905f946528b59f70ab7069f09b1cbe7ddf.zip
FreeBSD-src-1fe838905f946528b59f70ab7069f09b1cbe7ddf.tar.gz
Add signalcontext(), which lays down a signal frame onto a ucontext_t.
Reviewed by: deischen, julian Approved by: -arch
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/gen/swapcontext.c27
1 files changed, 15 insertions, 12 deletions
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 <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <sys/param.h>
+#include <sys/signal.h>
+#include <sys/ucontext.h>
+
#include <errno.h>
-#include <signal.h>
#include <stddef.h>
-#include <ucontext.h>
__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);
}
OpenPOWER on IntegriCloud