gpt4 book ai didi

c - sparc_do_fork() 究竟做了什么?

转载 作者:太空宇宙 更新时间:2023-11-04 11:00:26 24 4
gpt4 key购买 nike

我试图找出这个函数的功能,但我找不到。它在 Linux/arch/sparc/kernel/process_32.c 中定义,谢谢

asmlinkage int sparc_do_fork(unsigned long clone_flags,
unsigned long stack_start,
struct pt_regs *regs,
unsigned long stack_size)
{
unsigned long parent_tid_ptr, child_tid_ptr;
unsigned long orig_i1 = regs->u_regs[UREG_I1];
long ret;

parent_tid_ptr = regs->u_regs[UREG_I2];
child_tid_ptr = regs->u_regs[UREG_I4];

ret = do_fork(clone_flags, stack_start, stack_size,
(int __user *) parent_tid_ptr,
(int __user *) child_tid_ptr);

/* If we get an error and potentially restart the system
* call, we're screwed because copy_thread() clobbered
* the parent's %o1. So detect that case and restore it
* here.
*/
if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK)
regs->u_regs[UREG_I1] = orig_i1;

return ret;
}

最佳答案

它似乎就在源代码中。

它是常规 Linux do_fork() 调用的包装器,用于保存和恢复数据(具体来说,regs->u_regs[UREG_I1],等同于SPARC 输出寄存器 1),否则在某些情况下会损坏:

/* If we get an error and potentially restart the system
* call, we're screwed because copy_thread() clobbered
* the parent's %o1. So detect that case and restore it
* here.
*/

它用:

unsigned long orig_i1 = regs->u_regs[UREG_I1];      // Save it.

ret = do_fork(...);

if ((unsigned long)ret >= -ERESTART_RESTARTBLOCK) // It may be corrupt
regs->u_regs[UREG_I1] = orig_i1; // so restore it.

关于c - sparc_do_fork() 究竟做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27183230/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com