* [musl] clone(),sys_clone() arguments
@ 2020-06-27 12:36 erny hombre
2020-06-27 19:58 ` Rich Felker
0 siblings, 1 reply; 2+ messages in thread
From: erny hombre @ 2020-06-27 12:36 UTC (permalink / raw)
To: musl
Hello,
I am writing an operating system for an ARM processor (Cortex-A9). For the user programs I want to use musl libc.
I am adding a layer between musl and my os to translate linux system calls into native system calls.
For pthread_create the syscall sys_clone is used. This syscall is not called directly. The library
function clone() is used instead. The arguments of clone() and the raw system call sys_clone differ:
int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...
/* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
long sys_clone(unsigned long flags, void *child_stack, void *ptid, void *ctid, struct pt_regs *regs);
Musl uses __clone to reorder clone() arguments to the arguments expected by sys_clone:
/musl-1.2.0/src/thread/arm/clone.s:
__clone:
stmfd sp!,{r4,r5,r6,r7}
mov r7,#120
mov r6,r3
mov r5,r0
mov r0,r2
and r1,r1,#-16
ldr r2,[sp,#16]
ldr r3,[sp,#20]
ldr r4,[sp,#24]
svc 0 ; sys_clone system call
...
I think that the last two arguments for sys_clone (r3..ctid, r4..regs) are taken in the wrong
order from the clone parameters ([sp,#20]..tls, [sp,#24]..ctid).
Do I miss something or is this a bug ?
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [musl] clone(),sys_clone() arguments
2020-06-27 12:36 [musl] clone(),sys_clone() arguments erny hombre
@ 2020-06-27 19:58 ` Rich Felker
0 siblings, 0 replies; 2+ messages in thread
From: Rich Felker @ 2020-06-27 19:58 UTC (permalink / raw)
To: erny hombre; +Cc: musl
On Sat, Jun 27, 2020 at 02:36:20PM +0200, erny hombre wrote:
> Hello,
>
> I am writing an operating system for an ARM processor (Cortex-A9). For the user programs I want to use musl libc.
> I am adding a layer between musl and my os to translate linux system calls into native system calls.
> For pthread_create the syscall sys_clone is used. This syscall is not called directly. The library
> function clone() is used instead. The arguments of clone() and the raw system call sys_clone differ:
> int clone(int (*fn)(void *), void *child_stack, int flags, void *arg, ...
> /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
> long sys_clone(unsigned long flags, void *child_stack, void *ptid, void *ctid, struct pt_regs *regs);
>
> Musl uses __clone to reorder clone() arguments to the arguments expected by sys_clone:
> /musl-1.2.0/src/thread/arm/clone.s:
> __clone:
> stmfd sp!,{r4,r5,r6,r7}
> mov r7,#120
> mov r6,r3
> mov r5,r0
> mov r0,r2
> and r1,r1,#-16
> ldr r2,[sp,#16]
> ldr r3,[sp,#20]
> ldr r4,[sp,#24]
> svc 0 ; sys_clone system call
> ...
>
> I think that the last two arguments for sys_clone (r3..ctid, r4..regs) are taken in the wrong
> order from the clone parameters ([sp,#20]..tls, [sp,#24]..ctid).
> Do I miss something or is this a bug ?
Linux's arch/arm/Kconfig defines CLONE_BACKWARDS, which means the
argument order is (flags, sp, ptid, tp, ctid) -- see kernel/fork.c. I
don't know where you're getting the pt_regs argument from. That's not
part of the syscall interface ever; it is or was a kernel-internal
thing in some kernel versions.
Rich
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2020-06-27 19:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-27 12:36 [musl] clone(),sys_clone() arguments erny hombre
2020-06-27 19:58 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).