在雪豹上使用 32 位应用程序和内核从系统调用中获取 getpid
我成功地从程序集中调用了退出系统调用,但我很难调用 _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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那是因为 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?