[klibc] a little help w/ sys_clone
H. Peter Anvin
hpa at zytor.com
Mon Sep 20 19:16:24 PDT 2004
christophe varoqui wrote:
>
> How does it impact the correctness of the following snippet on IA64 ?
>
sys_clone doesn't exist, you'd need to use sys_clone2. In general you
probably should use the libc wrapper: the _syscall*() macros are broken on
about half of all platforms. IIRC sys_clone2 takes a stack size as well as a
stack pointer.
> #include <sched.h>
> #include <linux/unistd.h>
>
> #define __NR_sys_clone __NR_clone
>
> static inline _syscall2(int,sys_clone, int,flag, void*,stack);
>
> int main(void)
> {
> int pid;
>
> pid = sys_clone(CLONE_NEWNS, 0);
> if (pid < 0)
> exit(1);
> if (pid > 0)
> exit(0);
> /* in child */
> return 0;
> }
>
>
>>Note: klibc is not multithreaded.
>
> Yes, not that annoying : only the multipah daemon is threaded and it
> doesn't need to run early.
If useful, I could add the clone wrapper to klibc, but it would have some
singificant limitations: CLONE_VM would definitely not work (except for with
CLONE_VFORK) and CLONE_SIGHAND would be cantankerous at best.
However, there are definitely clone flags which would work just fine --
CLONE_NEWNS and CLONE_PARENT.
-hpa
More information about the klibc
mailing list