I am hacking linux-4.13.4, and I learn clone
system call from book
Linux Kernel Development 3rd Edition
I am curious about why sys_clone
is defined in "./arch/h8300/kernel/process.c" ?
This is the only place I can find the function definition.
In my opinion, the folder path of clone
system call is very inconsistent. Is it a historical reason that clone
is firstly implemented in architecture h8300
, so Linus Torvalds put clone
in /arch/h8300/
?
Reference:
https://www.classes.cs.uchicago.edu/archive/2006/winter/23000-1/docs/h8300.pdf
It's not for historical reasons, it's because some implementation of clone depends on the architecture. Some CPUs like the h8300 pass more parameters in the register than the generic sys_clone
wrapper found in kernel/fork.c
... There it's defined using the SYSCALL_DEFINE*
macros:
In 4.13.5 it's around line 2133.
#ifdef __ARCH_WANT_SYS_CLONE
#ifdef CONFIG_CLONE_BACKWARDS
SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
int __user *, parent_tidptr,
unsigned long, tls,
int __user *, child_tidptr)
#elif defined(CONFIG_CLONE_BACKWARDS2)
SYSCALL_DEFINE5(clone, unsigned long, newsp, unsigned long, clone_flags,
int __user *, parent_tidptr,
int __user *, child_tidptr,
unsigned long, tls)
#elif defined(CONFIG_CLONE_BACKWARDS3)
SYSCALL_DEFINE6(clone, unsigned long, clone_flags, unsigned long, newsp,
int, stack_size,
int __user *, parent_tidptr,
int __user *, child_tidptr,
unsigned long, tls)
#else
SYSCALL_DEFINE5(clone, unsigned long, clone_flags, unsigned long, newsp,
int __user *, parent_tidptr,
int __user *, child_tidptr,
unsigned long, tls)
#endif
{
return _do_fork(clone_flags, newsp, 0, parent_tidptr, child_tidptr, tls);
}
#endif
In case of h8300 there is an arch specific sys_clone, which is needed because of the way parameters are passed from the calling process to a forking process in case of h8300 all the params have to be passed through the registers (rather than a mix of registers and stack) and because clone will trounce the registers it requires cpu specific handling.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.