哪里操作系统店的argv和ARGC当执行一个子进程? [英] Where does the OS store argv and argc when a child process is executed?

查看:207
本文介绍了哪里操作系统店的argv和ARGC当执行一个子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些困难,了解操作系统是如何从一个父进程到一个子进程的地址空间中的地址空间将数据传递。也就是说,在一个C程序,其中argc和argv存储在被送入主?

I'm having some difficulty understanding how the OS passes data from the address space of a parent process to the address space of a child process. Namely, in a C program, where is argc and argv stored upon being passed into main?

我了解的argv本质上是一个双指针。什么我不明白是什么操作系统它们加载到内核后,用这些值一样。子进程创建地址空间后,它的新空间推进栈这些价值?我们显然不希望在指针传递给另一个地址空间。

I understand how argv is essentially a double pointer. What I'm not understanding is what the OS does with those values after loading them into the kernel. After creating an address space for the child process does it push these values on the stack of the new space? We obviously don't want to pass in pointers to another address space.

有关记录,我与MIPS32架构的工作。

For the record, I'm working with the MIPS32 architecture.

推荐答案

在Linux上,至少在我合作过的架构,流程与%ESP 启动指向是这样的:

On Linux, at least on the architectures I've played with, the process starts with %esp pointing to something like:

argc | argv[0] | argv[1] | ... argv[argc - 1] | argv[argc] == NULL | envp[0] | envp[1] ... envp[?] == NULL

调用的第一个功能是传统命名为 _start ,它的工作是计算(ARGC =%ESP,argv的=((字符*) %ESP)+ 1,envp =((字符*)%ESP)+ ARGC + 2),然后调用用适当的调用约定

The first function called is traditionally named _start, and its job is to calculate (argc = %esp, argv = ((char *)%esp) + 1, envp = ((char *)%esp) + argc + 2), then call main with the appropriate calling convention.

在x86上,论证获得通过在堆栈中。

On x86, the arguments get passed on the stack.

在AMD64,他们在寄存器中获得通过%RDI %RSI %的RDX

On amd64, they get passed in registers %rdi, %rsi, and %rdx.

在MIPS,谷歌告诉我,有在使用几种不同的调用约定 - 包括O32,N32,N64 - 但它们都使用 $ A0 $ A1 $ A2 第一。

On mips, Google tells me there are several different calling conventions in use - including O32, N32, N64 - but all of them use $a0, $a1, $a2 first.

这篇关于哪里操作系统店的argv和ARGC当执行一个子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆