From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 13692 invoked from network); 27 Jun 2020 19:58:44 -0000 Received: from mother.openwall.net (195.42.179.200) by inbox.vuxu.org with ESMTPUTF8; 27 Jun 2020 19:58:44 -0000 Received: (qmail 19593 invoked by uid 550); 27 Jun 2020 19:58:38 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 19575 invoked from network); 27 Jun 2020 19:58:37 -0000 Date: Sat, 27 Jun 2020 15:58:25 -0400 From: Rich Felker To: erny hombre Cc: musl@lists.openwall.com Message-ID: <20200627195824.GB6430@brightrain.aerifal.cx> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] 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