【问题标题】:getpid from syscall with 32 bit app and kernel on snow leopard来自系统调用的 getpid 与雪豹上的 32 位应用程序和内核
【发布时间】:2010-05-14 12:47:58
【问题描述】:

我成功地从程序集中调用了退出系统调用,但我正在努力调用 _getpid 系统调用并使用它的返回值。这是我正在使用的代码

.text
.globl _getpiddirect

_getpiddirect:
    pushl %ebp
    movl %esp, %ebp
    subl $8, %esp
    movl $39, %eax
    int $0x80
    addl $8, %esp
    popl %ebp
    ret

#include <stdio.h>
#include <unistd.h>

extern unsigned long getpiddirect();

int main(int argc, const char *argv[])
{
   printf("%lu\n", getpiddirect());
   printf("%lu\n", (unsigned long) getpid());
   return 0;
}

getpiddirect 不断返回 4056。

【问题讨论】:

    标签: macos kernel system-calls


    【解决方案1】:

    那是因为 39 是 getppid 的代码 - 获取 parent 进程 ID,这就是您得到的 4056。getpid 代码是 20,但请查看 /usr/include/sys /syscall.h 用于 SYS_getpid 的值作为您系统上使用的精确常量。

    我也不确定为什么要在通过中断调用 getpid 之前在堆栈上保留 8 个字节。它不影响任何东西,只是没用,不是吗?

    【讨论】:

    • 谢谢你的回答是正确的。我把 getppid 和 getpid 弄错了。额外的 8 个字节是保持堆栈按照 mac os ABI 要求对齐所必需的。
    猜你喜欢
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-26
    • 1970-01-01
    • 2015-11-05
    • 2014-07-05
    相关资源
    最近更新 更多