提交 fdf5f1b1 编写于 作者: B Bobby Bingham

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.
上级 7ee48f7b
#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));
}
.text
.global __clone
.weak clone
.type __clone,%function
.type clone,%function
__clone:
clone:
stmfd sp!,{r4,r5,r6,r7}
mov r7,#120
mov r6,r3
......
#include <errno.h>
#include "libc.h"
#include "pthread_impl.h"
int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...)
{
errno = ENOSYS;
return -1;
return -ENOSYS;
}
weak_alias(__clone, clone);
.text
.global __clone
.weak clone
.type __clone,@function
.type clone,@function
__clone:
clone:
push %ebp
mov %esp,%ebp
push %ebx
......
.global __clone
.weak clone
.type __clone,@function
.type clone,@function
# r5, r6, r7, r8, r9, r10, stack
# fn, st, fl, ar, pt, tl, ct
# fl, st, __, pt, ct, tl
__clone:
clone:
andi r6, r6, -16
addi r6, r6, -16
swi r5, r6, 0
......
.text
.global __clone
.weak clone
.type __clone,@function
.type clone,@function
__clone:
clone:
xor %eax,%eax
mov $56,%al
mov %rdi,%r11
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册