|
Message-ID: <20200627195824.GB6430@brightrain.aerifal.cx> Date: Sat, 27 Jun 2020 15:58:25 -0400 From: Rich Felker <dalias@...c.org> To: erny hombre <hombre67@....at> Cc: musl@...ts.openwall.com Subject: Re: clone(),sys_clone() arguments 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
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.