Skip to contentSkip to conversation

User mode emulation's clone does not seem to work with glibc >= 2.4's fork

Qemu-devel Lubomir Kundrak 4 participants 5 messages Apr 29, 2008 – Jun 30, 2008

lore
Share & tools
lore
#0 lore raw

I tried to run SH4 binaries linked with glibc-2.8 with qemu-sh4. fork() system call was always returning with "Invalid argument".

Post glibc 2.3 fork() on Linux seems to call clone():

glibc-2.4/nptl/sysdeps/unix/sysv/linux/sh/fork.c:
24 /* TLS pointer argument is passed as the 5-th argument. */ 25 #define ARCH_FORK() \
26 INLINE_SYSCALL (clone, 5, \
27 CLONE_CHILD_SETTID | CLONE_CHILD_CLEARTID | SIGCHLD, 0, \
28 NULL, &THREAD_SELF->tid, NULL)

qemu/linux-user/syscall.c:

2713 int do_fork(CPUState *env, unsigned int flags, abi_ulong newsp)
...
2720 if (flags & CLONE_VM) {
...
2794 } else {
2795 /* if no CLONE_VM, we consider it is a fork */
2796 if ((flags & ~CSIGNAL) != 0)
2797 return -EINVAL;
2798 ret = fork();
2799 }
2800 return ret;

Here CLONE_CHILD_SETTID and CLONE_CHILD_CLEARTID being set cause the ~CSIGNAL conditional to fail. If the test is omited, some assertion fail in glibc's fork() implementation is triggered.

Signature · 1 line
Lubomir Kundrak (Red Hat Security Response Team)
#1 lore raw
Quoted 2 lines · Lubomir Kundrak

I tried to run SH4 binaries linked with glibc-2.8 with qemu-sh4. fork() system call was always returning with "Invalid argument".

qemu doesn't currently support NPTL. I'm working on it.

Paul

#2 lore raw

Hi,

Quoted 10 lines · Paul Brook
Quoted 2 lines · Lubomir Kundrak

I tried to run SH4 binaries linked with glibc-2.8 with qemu-sh4. fork() system call was always returning with "Invalid argument".

qemu doesn't currently support NPTL. I'm working on it.

Paul

I'm working on sh4 to provide an NPTL support. I just force the
NPTL support of sh4 in the configuration and add the cpu_set_tls
using the env->gbr. I have sh: ../nptl/sysdeps/unix/sysv/linux/sh/../fork.c:138: __libc_fork: Assertion `(self->tid) != ppid this assertion in tforhe libc code. The child_tidptr is nil, so I can't set the tid for the child. I don't want to fix this issue but just understand what happen.

Regards Michael

#3 lore raw
In reply to Paul Brook

Hi,

Quoted 10 lines · Paul Brook
Quoted 2 lines · Lubomir Kundrak

I tried to run SH4 binaries linked with glibc-2.8 with qemu-sh4. fork() system call was always returning with "Invalid argument".

qemu doesn't currently support NPTL. I'm working on it.

Paul

I'm working on sh4 to provide an NPTL support. I just force the NPTL support of sh4 in the configuration and add the cpu_set_tls using the env->gbr. I have sh:
../nptl/sysdeps/unix/sysv/linux/sh/../fork.c:138: __libc_fork: Assertion `(self->tid) != ppid this assertion in tforhe libc code. The child_tidptr is nil, so I can't set the tid for the child. I don't want to fix this issue but just understand what happen.

Regards Michael

#4 lore raw
In reply to Paul Brook

Hi,

Quoted 10 lines · Paul Brook
Quoted 2 lines · Lubomir Kundrak

I tried to run SH4 binaries linked with glibc-2.8 with qemu-sh4. fork() system call was always returning with "Invalid argument".

qemu doesn't currently support NPTL. I'm working on it.

Paul

I'm working on sh4 to provide an NPTL support. I just force the NPTL support of sh4 in the configuration and add the cpu_set_tls using the env->gbr. I have sh:
../nptl/sysdeps/unix/sysv/linux/sh/../fork.c:138: __libc_fork: Assertion `(self->tid) != ppid this assertion in tforhe libc code. The child_tidptr is nil, so I can't set the tid for the child. I change the code of the fork like this:

#if !defined(TARGET_SH4)
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg4, arg5));
#else
        ret = get_errno(do_fork(cpu_env, arg1, arg2, arg3, arg5, arg4));

#endif

An know seem to work the sh4 target. I think that is not the only change. Is it right?

Regards Michael