Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Sat, 27 Jun 2020 14:36:20 +0200
From: erny hombre <>
Subject: clone(),sys_clone() arguments


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:
	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 ?

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.