Index: lib/libc/i386/sys/Makefile.inc =================================================================== --- lib/libc/i386/sys/Makefile.inc (revision 249580) +++ lib/libc/i386/sys/Makefile.inc (working copy) @@ -9,7 +9,7 @@ __vdso_gettc.c MDASM= Ovfork.S brk.S cerror.S exect.S getcontext.S pipe.S ptrace.S \ - reboot.S sbrk.S setlogin.S sigreturn.S syscall.S + reboot.S sbrk.S setlogin.S sigreturn.S syscall.S swapcontext.S # Don't generate default code for these syscalls: NOASM= break.o exit.o getlogin.o openbsd_poll.o sstk.o vfork.o yield.o @@ -25,3 +25,13 @@ MLINKS+=i386_get_ioperm.2 i386_set_ioperm.2 MLINKS+=i386_get_ldt.2 i386_set_ldt.2 MLINKS+=i386_set_watch.3 i386_clr_watch.3 + + +# This rule stops ./assym.s in .depend from causing problems. +./assym.s: assym.s + +assym.s: ${.CURDIR}/../../sys/kern/genassym.sh genassym.o + NM='${NM}' sh ${.CURDIR}/../../sys/kern/genassym.sh genassym.o > ${.TARGET} + +genassym.o: ${.CURDIR}/${LIBC_ARCH}/sys/genassym.c + ${CC} -c ${CFLAGS:N-fno-common} ${.CURDIR}/${LIBC_ARCH}/sys/genassym.c Index: lib/libc/i386/sys/genassym.c =================================================================== --- lib/libc/i386/sys/genassym.c (revision 0) +++ lib/libc/i386/sys/genassym.c (working copy) @@ -0,0 +1,6 @@ +#include +#include +#include + +ASSYM(UC_ESP, offsetof(struct __ucontext, uc_mcontext.mc_esp)); +ASSYM(UC_EIP, offsetof(struct __ucontext, uc_mcontext.mc_eip)); Index: lib/libc/i386/sys/swapcontext.S =================================================================== --- lib/libc/i386/sys/swapcontext.S (revision 0) +++ lib/libc/i386/sys/swapcontext.S (working copy) @@ -0,0 +1,62 @@ +/*- + * Copyright (c) 2013 David Xu + * 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 "../../assym.s" + + .weak _swapcontext + .set _swapcontext,__sys_swapcontext + .weak swapcontext + .set swapcontext,__sys__swapcontext + +ENTRY(__sys_swapcontext) + mov $SYS_getcontext,%eax + KERNCALL + jb HIDENAME(cerror) + movl 4(%esp),%eax /* get oucp, see manual */ + movl (%esp),%ecx /* get return address */ + leal 4(%esp),%edx /* the %esp needs to be restored */ + movl %ecx,UC_EIP(%eax) + movl %edx,UC_ESP(%eax) + movl 8(%esp),%ecx /* get ucp */ +#ifdef PIC + PIC_PROLOGUE + pushl %ecx + call PIC_PLT(CNAME(_setcontext)) + addl $4, %esp + PIC_EPILOGUE +#else + pushl %ecx + call CNAME(_setcontext) + addl $4, %esp +#endif + ret +END(__sys_swapcontext) + + .section .note.GNU-stack,"",%progbits