繁体   English   中英

为什么在“ ./arch/h8300/kernel/process.c”中定义“ sys_clone”?

[英]Why “sys_clone” is defined in “./arch/h8300/kernel/process.c”?

我正在入侵linux-4.13.4,并且从书中学习了clone系统调用

Linux内核开发第三版

我很好奇为什么sys_clone是在“ ./arch/h8300/kernel/process.c”中定义的?

这是我可以找到函数定义的唯一位置。

在我看来, clone系统调用的文件夹路径非常不一致。 是否首先在架构h8300实现clone是历史原因,所以Linus Torvalds将clone放在/arch/h8300/吗?

参考:

https://www.classes.cs.uchicago.edu/archive/2006/winter/23000-1/docs/h8300.pdf

https://en.wikipedia.org/wiki/H8_Family

这不是出于历史原因,而是因为克隆的某些实现取决于体系结构。 诸如h8300之类的某些CPU在寄存器中传递的参数要比在kernel/fork.c找到的通用sys_clone包装器传递更多的参数。使用SYSCALL_DEFINE*宏对其进行定义:

在4.13.5中,它位于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

在h8300的情况下,有一个特定于arch的sys_clone,这是必需的,因为在h8300的情况下,参数必须从调用过程传递到派生过程,所有参数必须通过寄存器传递(而不是混合使用寄存器)和堆栈),因为克隆会删除寄存器,因此需要cpu特定的处理。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM