aboutsummaryrefslogtreecommitdiff
path: root/src/libthread/386-ucontext.c
diff options
context:
space:
mode:
authorPetter Rodhelind <petter.rodhelind@gmail.com>2020-02-11 13:40:11 +0100
committerPetter Rodhelind <petter.rodhelind@gmail.com>2020-02-11 13:40:11 +0100
commit9c79e48c93c0c4d14aabcb490fab048d68934cb2 (patch)
tree1d57d3fd193621a2357473bb65b92190914c5736 /src/libthread/386-ucontext.c
parent02d7aa8915f9c3a3288dab01f321eb94ba219e3b (diff)
parent0237dec768a4ee36ae9e18ce8566d2c999d78410 (diff)
downloadplan9port-9c79e48c93c0c4d14aabcb490fab048d68934cb2.tar.gz
plan9port-9c79e48c93c0c4d14aabcb490fab048d68934cb2.tar.bz2
plan9port-9c79e48c93c0c4d14aabcb490fab048d68934cb2.zip
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'src/libthread/386-ucontext.c')
-rw-r--r--src/libthread/386-ucontext.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libthread/386-ucontext.c b/src/libthread/386-ucontext.c
new file mode 100644
index 00000000..3afa9513
--- /dev/null
+++ b/src/libthread/386-ucontext.c
@@ -0,0 +1,22 @@
+#include "threadimpl.h"
+
+void
+makecontext(ucontext_t *ucp, void (*func)(void), int argc, ...)
+{
+ int *sp;
+
+ sp = USPALIGN(ucp, 4);
+ sp -= argc;
+ memmove(sp, &argc+1, argc*sizeof(int));
+ *--sp = 0; /* return address */
+ ucp->uc_mcontext.mc_eip = (long)func;
+ ucp->uc_mcontext.mc_esp = (int)sp;
+}
+
+int
+swapcontext(ucontext_t *oucp, ucontext_t *ucp)
+{
+ if(getcontext(oucp) == 0)
+ setcontext(ucp);
+ return 0;
+}