Browse Source

clone: make clone a wrapper around __clone

The architecture-specific assembly versions of clone did not set errno on
failure, which is inconsistent with glibc.  __clone still returns the error
via its return value, and clone is now a wrapper that sets errno as needed.
The public clone has also been moved to src/linux, as it's not directly
related to the pthreads API.

__clone is called by pthread_create, which does not report errors via
errno.  Though not strictly necessary, it's nice to avoid clobbering errno
here.
rs-1.0
Bobby Bingham 12 years ago
parent
commit
fdf5f1b131
  1. 19
      src/linux/clone.c
  2. 3
      src/thread/arm/clone.s
  3. 7
      src/thread/clone.c
  4. 3
      src/thread/i386/clone.s
  5. 5
      src/thread/microblaze/clone.s
  6. 3
      src/thread/x86_64/clone.s

19
src/linux/clone.c

@ -0,0 +1,19 @@
#include <stdarg.h>
#include <unistd.h>
#include "pthread_impl.h"
#include "syscall.h"
int clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
{
va_list ap;
pid_t *ptid, *ctid;
void *tls;
va_start(ap, arg);
ptid = va_arg(ap, pid_t *);
tls = va_arg(ap, void *);
ctid = va_arg(ap, pid_t *);
va_end(ap);
return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid));
}

3
src/thread/arm/clone.s

@ -1,10 +1,7 @@
.text .text
.global __clone .global __clone
.weak clone
.type __clone,%function .type __clone,%function
.type clone,%function
__clone: __clone:
clone:
stmfd sp!,{r4,r5,r6,r7} stmfd sp!,{r4,r5,r6,r7}
mov r7,#120 mov r7,#120
mov r6,r3 mov r6,r3

7
src/thread/clone.c

@ -1,10 +1,7 @@
#include <errno.h> #include <errno.h>
#include "libc.h" #include "pthread_impl.h"
int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...) int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
{ {
errno = ENOSYS; return -ENOSYS;
return -1;
} }
weak_alias(__clone, clone);

3
src/thread/i386/clone.s

@ -1,10 +1,7 @@
.text .text
.global __clone .global __clone
.weak clone
.type __clone,@function .type __clone,@function
.type clone,@function
__clone: __clone:
clone:
push %ebp push %ebp
mov %esp,%ebp mov %esp,%ebp
push %ebx push %ebx

5
src/thread/microblaze/clone.s

@ -1,14 +1,11 @@
.global __clone .global __clone
.weak clone
.type __clone,@function .type __clone,@function
.type clone,@function
# r5, r6, r7, r8, r9, r10, stack # r5, r6, r7, r8, r9, r10, stack
# fn, st, fl, ar, pt, tl, ct # fn, st, fl, ar, pt, tl, ct
# fl, st, __, pt, ct, tl # fl, st, __, pt, ct, tl
__clone: __clone:
clone:
andi r6, r6, -16 andi r6, r6, -16
addi r6, r6, -16 addi r6, r6, -16
swi r5, r6, 0 swi r5, r6, 0
@ -23,7 +20,7 @@ clone:
beqi r3, 1f beqi r3, 1f
rtsd r15, 8 rtsd r15, 8
nop nop
1: lwi r3, r1, 0 1: lwi r3, r1, 0
lwi r5, r1, 4 lwi r5, r1, 4
brald r15, r3 brald r15, r3

3
src/thread/x86_64/clone.s

@ -1,10 +1,7 @@
.text .text
.global __clone .global __clone
.weak clone
.type __clone,@function .type __clone,@function
.type clone,@function
__clone: __clone:
clone:
xor %eax,%eax xor %eax,%eax
mov $56,%al mov $56,%al
mov %rdi,%r11 mov %rdi,%r11

Loading…
Cancel
Save