在雪豹上使用 32 位应用程序和内核从系统调用中获取 getpid

发布于 2024-09-02 05:19:01 字数 556 浏览 4 评论 0原文

我成功地从程序集中调用了退出系统调用,但我很难调用 _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。

I successfully called the exit syscall from assembly but I'm strugling to call the _getpid syscall and use it's return value. Here is the code I'm using

.text
.globl _getpiddirect

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

and

#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 keeps returning 4056.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

牵你手 2024-09-09 05:19:01

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

另外我不确定为什么在通过中断调用 getpid 之前你需要在堆栈上有 8 个字节。它不会影响任何事情,只是没用,不是吗?

Thats because 39 is a code for getppid - get parent process id and that is what you're getting as 4056. The getpid code is 20, but please look at /usr/include/sys/syscall.h for the value of SYS_getpid as exact constant used on your system.

Also i'm not sure why you want 8 bytes on the stack prior to calling getpid through interrupt. It doesn't affect anything and is just useless, no?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文