summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/libc/arch/alpha/sys/tfork_thread.S57
-rw-r--r--lib/libc/arch/amd64/sys/tfork_thread.S94
-rw-r--r--lib/libc/arch/arm/sys/tfork_thread.S48
-rw-r--r--lib/libc/arch/hppa/sys/tfork_thread.S65
-rw-r--r--lib/libc/arch/i386/sys/tfork_thread.S122
-rw-r--r--lib/libc/arch/m68k/sys/tfork_thread.S70
-rw-r--r--lib/libc/arch/m88k/sys/tfork_thread.S55
-rw-r--r--lib/libc/arch/mips64/sys/tfork_thread.S80
-rw-r--r--lib/libc/arch/powerpc/sys/tfork_thread.S53
-rw-r--r--lib/libc/arch/sh/sys/tfork_thread.S61
-rw-r--r--lib/libc/arch/sparc/sys/tfork_thread.S74
-rw-r--r--lib/libc/arch/sparc64/sys/tfork_thread.S73
-rw-r--r--lib/libc/arch/vax/sys/tfork_thread.S69
-rw-r--r--lib/libc/sys/Makefile.inc4
-rw-r--r--lib/librthread/Makefile4
15 files changed, 925 insertions, 4 deletions
diff --git a/lib/libc/arch/alpha/sys/tfork_thread.S b/lib/libc/arch/alpha/sys/tfork_thread.S
new file mode 100644
index 00000000000..10fac103287
--- /dev/null
+++ b/lib/libc/arch/alpha/sys/tfork_thread.S
@@ -0,0 +1,57 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+LEAF(__tfork_thread,0)
+ /* a0 = flags, a1 = stack, a2 = func, a3 = arg */
+ mov a3, a5
+ CALLSYS_ERROR(__tfork)
+
+ beq v0, 1f
+
+ /*
+ * In parent process: just return.
+ */
+ RET
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+ mov a1, sp /* stack */
+ mov a5, a0 /* arg */
+ mov a2, pv /* func */
+ jsr ra, (pv)
+
+ mov zero, a0
+ CALLSYS_NOERROR(__threxit)
+
+END(__tfork_thread)
diff --git a/lib/libc/arch/amd64/sys/tfork_thread.S b/lib/libc/arch/amd64/sys/tfork_thread.S
new file mode 100644
index 00000000000..41a42d79972
--- /dev/null
+++ b/lib/libc/arch/amd64/sys/tfork_thread.S
@@ -0,0 +1,94 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+/*-
+ * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
+ * Copyright (c) 2003 Alan L. Cox <alc@cs.rice.edu>
+ * 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 <machine/asm.h>
+#if 0
+__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/amd64/gen/rfork_thread.S,v 1.1 2003/10/13 20:32:33 alc Exp $");
+#endif
+
+/*
+ * With thanks to John Dyson for the original version of this.
+ */
+
+#include "SYS.h"
+
+/*
+ * %rdi %rsi %rdx %rcx
+ * __tfork_thread(param, stack_addr, start_fnc, start_arg);
+ *
+ * param: Argument to pass to the actual kernel call.
+ * stack_addr: Top of stack for thread.
+ * start_fnc: Address of thread function to call in child.
+ * start_arg: Argument to pass to the thread function in child.
+ */
+
+ENTRY(__tfork_thread)
+ movq %rdx, %r8
+ movq %rcx, %r9
+
+ /*
+ * Prepare and execute the thread creation syscall
+ */
+ movl $SYS___tfork, %eax
+ syscall
+ jb 2f
+
+ /*
+ * Check to see if we are in the parent or child
+ */
+ cmpl $0, %edx
+ jnz 1f
+ ret
+
+ /*
+ * If we are in the child (new thread), then
+ * set-up the call to the internal subroutine. If it
+ * returns, then call __threxit.
+ */
+1:
+ movq %rsi, %rsp
+ movq %r9, %rdi
+ call *%r8
+
+ /*
+ * Thread exit system call
+ */
+ movl $SYS___threxit, %eax
+ xorl %edi, %edi
+ syscall
+
+ /*
+ * Branch here if the thread creation fails:
+ */
+2:
+#ifdef PIC
+ movq PIC_GOT(CERROR), %rcx
+ jmp *%rcx
+#else
+ jmp CERROR
+#endif
diff --git a/lib/libc/arch/arm/sys/tfork_thread.S b/lib/libc/arch/arm/sys/tfork_thread.S
new file mode 100644
index 00000000000..0ece8d15d2a
--- /dev/null
+++ b/lib/libc/arch/arm/sys/tfork_thread.S
@@ -0,0 +1,48 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+/*
+ * Copyright (c) 2005 Dale Rahn <drahn@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+#include <sys/syscall.h>
+#include <machine/asm.h>
+#include "SYS.h"
+
+/*
+ * r0 r1 r2 r3
+ * __tfork_thread(param, stack_addr, start_fnc, start_arg);
+ */
+
+ENTRY(__tfork_thread)
+ stmdb sp!, {r4}
+ mov r4, r1
+
+
+ SYSTRAP(__tfork)
+ bcs 1f
+
+ /* check if we are parent or child */
+ cmp r0, #0
+ ldmneia sp!, {r4}
+ movne pc, lr
+
+ /* child */
+ mov sp, r4
+ mov r0, r3
+ mov lr, pc
+ mov pc, r2
+ nop
+ SYSTRAP(__threxit)
+1:
+ ldmia sp!, {r4}
+ b PIC_SYM(CERROR, PLT)
diff --git a/lib/libc/arch/hppa/sys/tfork_thread.S b/lib/libc/arch/hppa/sys/tfork_thread.S
new file mode 100644
index 00000000000..5a77bd3bbea
--- /dev/null
+++ b/lib/libc/arch/hppa/sys/tfork_thread.S
@@ -0,0 +1,65 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread, 0)
+ SYSCALL(__tfork)
+ comb,<> r0, ret0, 1f
+ nop
+
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+
+ /*
+ * PIC code expects 32 bytes of room available below sp.
+ * Then the regular procedure invocation requires us to allocate
+ * 64 bytes as well.
+ */
+ copy arg1, sp
+ ldo 0(sp), r3
+ stw,ma r0, HPPA_FRAME_SIZE(sp)
+ stw r0, HPPA_FRAME_CRP(sp)
+ stw r0, HPPA_FRAME_PSP(sp)
+
+ copy arg3, arg0 /* arg */
+ copy arg2, t1
+ bl $$dyncall, r31
+ copy r31, rp
+
+ copy r0, arg0
+ SYSCALL(__threxit)
+
+1:
+ bv r0(rp)
+ nop
+
+EXIT(__tfork_thread)
diff --git a/lib/libc/arch/i386/sys/tfork_thread.S b/lib/libc/arch/i386/sys/tfork_thread.S
new file mode 100644
index 00000000000..bc4feddc3ce
--- /dev/null
+++ b/lib/libc/arch/i386/sys/tfork_thread.S
@@ -0,0 +1,122 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+/*-
+ * Copyright (c) 2000 Peter Wemm <peter@FreeBSD.org>
+ * 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 <machine/asm.h>
+#if 0
+__FBSDID("$FreeBSD: /repoman/r/ncvs/src/lib/libc/i386/gen/rfork_thread.S,v 1.5 2003/05/07 17:23:25 jhb Exp $");
+#endif
+
+/*
+ * With thanks to John Dyson for the original version of this.
+ */
+
+#include "SYS.h"
+
+/*
+ * 8 12 16 20
+ * __tfork_thread(param, stack_addr, start_fnc, start_arg);
+ *
+ * param: Arguments to actual system call.
+ * stack_addr: Top of stack for thread.
+ * start_fnc: Address of thread function to call in child.
+ * start_arg: Argument to pass to the thread function in child.
+ */
+
+ENTRY(__tfork_thread)
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %esi
+
+ /*
+ * Push thread info onto the new thread's stack
+ */
+ movl 12(%ebp), %esi # get stack addr
+
+ subl $4, %esi
+ movl 20(%ebp), %eax # get start argument
+ movl %eax, (%esi)
+
+ subl $4, %esi
+ movl 16(%ebp), %eax # get start thread address
+ movl %eax, (%esi)
+
+ /*
+ * Prepare and execute the thread creation syscall
+ */
+ pushl 8(%ebp)
+ pushl $0
+ movl $SYS___tfork, %eax
+ int $0x80
+ jb 2f
+
+ /*
+ * Check to see if we are in the parent or child
+ */
+ cmpl $0, %edx
+ jnz 1f
+ addl $8, %esp
+ popl %esi
+ movl %ebp, %esp
+ popl %ebp
+ ret
+ .p2align 2
+
+ /*
+ * If we are in the child (new thread), then
+ * set-up the call to the internal subroutine. If it
+ * returns, then call __exit.
+ */
+1:
+ movl %esi,%esp
+ popl %eax
+ call *%eax
+ addl $4, %esp
+
+ /*
+ * Exit system call
+ */
+ pushl %eax
+ pushl $0
+ movl $SYS___threxit, %eax
+ int $0x80
+
+ /*
+ * Branch here if the thread creation fails:
+ */
+2:
+ addl $8, %esp
+ popl %esi
+ movl %ebp, %esp
+ popl %ebp
+#ifdef PIC
+ PIC_PROLOGUE
+ movl PIC_GOT(CERROR), %ecx
+ PIC_EPILOGUE
+ jmp *%ecx
+#else
+ jmp CERROR
+#endif
diff --git a/lib/libc/arch/m68k/sys/tfork_thread.S b/lib/libc/arch/m68k/sys/tfork_thread.S
new file mode 100644
index 00000000000..2d6d791ae42
--- /dev/null
+++ b/lib/libc/arch/m68k/sys/tfork_thread.S
@@ -0,0 +1,70 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread)
+ /*
+ * Set up the new thread's stack.
+ */
+ movl sp@(8), a0 /* stack */
+ movl sp@(16), a0@- /* arg */
+ movl sp@(12), a1 /* func */
+
+ /*
+ * We did not create a frame, so the stack is ready for an immediate
+ * system call invocation.
+ */
+ __DO_SYSCALL(__tfork)
+ jcs 9f
+
+ tstl d0
+ jeq 1f
+
+ /*
+ * parent process: just return.
+ */
+ rts
+
+1:
+ /*
+ * child process: switch stacks, invoke function, then exit.
+ */
+ movl a0, sp /* stack with arg pushed on it */
+ jsr a1@ /* func */
+ addq #4, sp
+
+ __DO_SYSCALL(__threxit)
+
+9:
+ /*
+ * system call failure.
+ */
+ jra __cerror
diff --git a/lib/libc/arch/m88k/sys/tfork_thread.S b/lib/libc/arch/m88k/sys/tfork_thread.S
new file mode 100644
index 00000000000..351d93151da
--- /dev/null
+++ b/lib/libc/arch/m88k/sys/tfork_thread.S
@@ -0,0 +1,55 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread)
+ or r6, r3, r0 /* save stack */
+ or r13, r0, __SYSCALLNAME(SYS_,__tfork)
+ tb0 0, r0, 128 /* corrupts r2 and r3 in the child */
+ br __cerror
+
+ bcnd eq0, r2, 1f
+
+ /*
+ * In parent process: just return.
+ */
+ jmp r1
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+ or r31, r6, r0 /* stack */
+ jsr.n r4 /* func */
+ or r2, r5, r0 /* arg */
+
+ or r13, r0, __SYSCALLNAME(SYS_,__threxit)
+ tb0 0, r0, 128
diff --git a/lib/libc/arch/mips64/sys/tfork_thread.S b/lib/libc/arch/mips64/sys/tfork_thread.S
new file mode 100644
index 00000000000..aaedba7df17
--- /dev/null
+++ b/lib/libc/arch/mips64/sys/tfork_thread.S
@@ -0,0 +1,80 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:55 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+FRAMESZ=4*REGSZ
+GPOFF=FRAMESZ-2*REGSZ
+LEAF(__tfork_thread, FRAMESZ)
+ /* a0 = param, a1 = stack, a2 = func, a3 = arg */
+ PTR_SUBU sp, FRAMESZ
+ SETUP_GP64(GPOFF, _C_LABEL(__tfork_thread))
+ .set reorder
+
+ move t0, a1 /* stack */
+ move t1, a3 /* arg */
+
+ __DO_SYSCALL(__tfork)
+ bnez a3, 9f
+
+ RESTORE_GP64
+ PTR_ADDU sp, FRAMESZ
+
+ beqz v0, 1f
+
+ /*
+ * In parent process: just return.
+ */
+ j ra
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+
+ move sp, t0 /* stack */
+ move t9, a2 /* func */
+ move a0, t1 /* arg */
+ move v0, zero
+ jal ra, t9
+
+ move a0, zero
+ __DO_SYSCALL(__threxit)
+
+9:
+ /*
+ * System call failure.
+ */
+ LA t9, CERROR
+
+ RESTORE_GP64
+ PTR_ADDU sp, FRAMESZ
+ jr t9
+END(__tfork_thread)
diff --git a/lib/libc/arch/powerpc/sys/tfork_thread.S b/lib/libc/arch/powerpc/sys/tfork_thread.S
new file mode 100644
index 00000000000..2e9a46a7664
--- /dev/null
+++ b/lib/libc/arch/powerpc/sys/tfork_thread.S
@@ -0,0 +1,53 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:56 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005 Tim Wiess <tim@nop.cx>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <sys/syscall.h>
+#include <machine/asm.h>
+
+ENTRY(__tfork_thread)
+ /* sanity check */
+ cmpwi %r4, 0
+ beq 1f
+ cmpwi %r5, 0
+ beq 1f
+
+ mr %r7,%r4
+
+ /* call __tfork */
+ li %r0, SYS___tfork
+ sc
+ cmpwi %r0, 0
+ bne 2f
+
+ /* check if we are parent or child */
+ cmpwi %r3, 0
+ bnelr
+
+ /* child */
+ mtlr %r5 /* fp */
+ mr %r3, %r6 /* arg */
+ subi %r1, %r7, 16 /* fixup sp to get headroom */
+ blrl
+
+ /* child returned, call _exit */
+ li %r0, SYS___threxit
+ sc
+1:
+ li %r3, -1
+2:
+ b PIC_PLT(_C_LABEL(__cerror))
diff --git a/lib/libc/arch/sh/sys/tfork_thread.S b/lib/libc/arch/sh/sys/tfork_thread.S
new file mode 100644
index 00000000000..bfca155e1d0
--- /dev/null
+++ b/lib/libc/arch/sh/sys/tfork_thread.S
@@ -0,0 +1,61 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:56 guenther Exp $ */
+
+/*
+ * Copyright (c) 2007 Miodrag Vallat.
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice, this permission notice, and the disclaimer below
+ * appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ * r4 r5 r6 r7
+ */
+ENTRY(__tfork_thread)
+ mov.l .LSYS___tfork, r0
+ .word 0xc380 /* trapa #0x80 */
+ bf 9f
+
+ tst r0, r0
+ bt 1f
+
+ /*
+ * In parent process: just return.
+ */
+ rts
+ nop
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+ mov r5, sp
+ jsr @r6
+ mov r7, r4
+
+ mov.l .LSYS___threxit, r0
+ .word 0xc380 /* trapa #0x80 */
+
+9:
+ /*
+ * System call failure.
+ */
+ JUMP_CERROR
+
+ .align 2
+.LSYS___tfork: .long SYS___tfork
+.LSYS___threxit: .long SYS___threxit
+
+ SET_ENTRY_SIZE(__tfork_thread)
diff --git a/lib/libc/arch/sparc/sys/tfork_thread.S b/lib/libc/arch/sparc/sys/tfork_thread.S
new file mode 100644
index 00000000000..882a07f7234
--- /dev/null
+++ b/lib/libc/arch/sparc/sys/tfork_thread.S
@@ -0,0 +1,74 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:56 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread)
+ mov %o1, %o4 /* save stack */
+
+ /*
+ * We can not invoke __tfork as a G2-style system call since we want
+ * different return paths.
+ */
+ mov SYS___tfork, %g1
+ t ST_SYSCALL
+ bcs 9f
+ nop
+
+ cmp %o0, 0
+ be 1f
+ nop
+
+ /*
+ * In parent process: just return.
+ */
+ retl
+ nop
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ * Don't forget to allocate room for a window save on the new
+ * stack!
+ */
+ sub %g0, %g0, %fp
+ sub %o4, 96, %sp /* stack */
+ call %o2 /* func */
+ mov %o3, %o0 /* arg */
+
+ mov SYS___threxit, %g1
+ clr %o0
+ t ST_SYSCALL /* will not return */
+
+9:
+ /*
+ * System call failure.
+ */
+ ERROR()
diff --git a/lib/libc/arch/sparc64/sys/tfork_thread.S b/lib/libc/arch/sparc64/sys/tfork_thread.S
new file mode 100644
index 00000000000..d22aba43a55
--- /dev/null
+++ b/lib/libc/arch/sparc64/sys/tfork_thread.S
@@ -0,0 +1,73 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:56 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread)
+ mov %o1, %o4 /* save stack */
+
+ /*
+ * We can not invoke __tfork as a G2-style system call since we want
+ * different return paths.
+ */
+ mov SYS___tfork, %g1
+ t ST_SYSCALL
+ bcs 9f
+ nop
+
+ cmp %o0, 0
+ be 1f
+ nop
+
+ /*
+ * In parent process: just return.
+ */
+ retl
+ nop
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ */
+
+ mov %g0, %fp /* clear frame pointer */
+ sub %o4, (BIAS + CC64FSZ), %sp /* stack */
+ call %o2 /* func */
+ mov %o3, %o0 /* arg */
+
+ mov SYS___threxit, %g1
+ clr %o0
+ t ST_SYSCALL /* will not return */
+
+9:
+ /*
+ * System call failure.
+ */
+ ERROR()
diff --git a/lib/libc/arch/vax/sys/tfork_thread.S b/lib/libc/arch/vax/sys/tfork_thread.S
new file mode 100644
index 00000000000..1d22f1e924b
--- /dev/null
+++ b/lib/libc/arch/vax/sys/tfork_thread.S
@@ -0,0 +1,69 @@
+/* $OpenBSD: tfork_thread.S,v 1.1 2012/03/22 00:44:56 guenther Exp $ */
+
+/*
+ * Copyright (c) 2005, Miodrag Vallat
+ *
+ * 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 ``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 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 "SYS.h"
+
+/*
+ * int __tfork_thread(const struct __tfork *param, void *stack, void (*func)(void *), void *arg);
+ */
+ENTRY(__tfork_thread, R2|R3|R4)
+ /*
+ * Save thread creation arguments into registers.
+ */
+ movl 8(ap), r2 /* stack */
+ movl 12(ap), r3 /* func */
+ movl 16(ap), r4 /* arg */
+
+ __DO_SYSCALL(__tfork)
+ jcs 9f
+
+ cmpl r0, $0
+ beql 1f
+
+ /*
+ * In parent process: just return.
+ */
+ ret
+
+1:
+ /*
+ * In child process: switch stack, invoke function, then exit.
+ * Note that since we can not pass a register to calls, we need
+ * to waste 4 bytes of stack in every thread.
+ */
+ movl r2, sp /* stack */
+ pushl r3 /* func */
+ pushl r4 /* arg */
+ calls $1, *4(sp) /* func */
+
+ __DO_SYSCALL(__threxit)
+
+9:
+ /*
+ * system call failed.
+ */
+ jmp _C_LABEL(_cerror)
diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc
index dcf2d4cb688..838d63cca31 100644
--- a/lib/libc/sys/Makefile.inc
+++ b/lib/libc/sys/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.98 2012/03/13 15:55:46 guenther Exp $
+# $OpenBSD: Makefile.inc,v 1.99 2012/03/22 00:44:55 guenther Exp $
# $NetBSD: Makefile.inc,v 1.35 1995/10/16 23:49:07 jtc Exp $
# @(#)Makefile.inc 8.1 (Berkeley) 6/17/93
@@ -8,7 +8,7 @@
# modules with non-default implementations on at least one architecture:
SRCS+= Ovfork.S brk.S cerror.S exect.S fork.S rfork.S \
sbrk.S sigpending.S sigprocmask.S sigreturn.S \
- sigsuspend.S syscall.S
+ sigsuspend.S syscall.S tfork_thread.S
LSRCS+= Lint_Ovfork.c Lint_brk.c Lint_exect.c Lint_fork.c \
Lint_rfork.c Lint_sbrk.c \
diff --git a/lib/librthread/Makefile b/lib/librthread/Makefile
index 40823f7fe5d..90147ff39c7 100644
--- a/lib/librthread/Makefile
+++ b/lib/librthread/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.27 2012/02/23 04:43:06 guenther Exp $
+# $OpenBSD: Makefile,v 1.28 2012/03/22 00:44:55 guenther Exp $
# For ``COMPILER_VERSION''
.include <bsd.own.mk>
@@ -40,7 +40,7 @@ SRCS= rthread.c \
rthread_tls.c \
sched_prio.c
-OBJS+= _atomic_lock.o rfork_thread.o cerror.o
+OBJS+= _atomic_lock.o cerror.o
MAN+= __tfork_thread.3
MLINKS+=__tfork_thread.3 __tfork.2