【问题标题】:Why "sys_clone" is defined in "./arch/h8300/kernel/process.c"?为什么“./arch/h8300/kernel/process.c”中定义了“sys_clone”?
【发布时间】:2018-04-03 09:58:00
【问题描述】:

我正在破解 linux-4.13.4,我从书中学习了clone 系统调用

Linux 内核开发第三版

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

这是我唯一能找到函数定义的地方。

在我看来,clone系统调用的文件夹路径非常不一致。 clone首先在架构h8300中实现,所以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

【问题讨论】:

    标签: c linux linux-kernel


    【解决方案1】:

    这不是历史原因,而是因为某些克隆的实现依赖于架构。像 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 的情况下,有一个特定于架构的 sys_clone,这是需要的,因为在 h8300 的情况下,参数从调用进程传递到分叉进程的方式必须通过寄存器传递所有参数(而不是寄存器和堆栈的混合)并且因为克隆会击败寄存器,所以它需要 cpu 特定的处理。

    【讨论】:

      猜你喜欢
      • 2016-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-12
      • 2017-03-05
      • 2012-05-07
      • 2019-12-05
      • 1970-01-01
      相关资源
      最近更新 更多