以下链接解释了UNIX(BSD风格)和Linux的x86-32系统调用约定:
但是UNIX和Linux上的x86-64系统调用约定是什么?
我研究Linux内核并发现,对于int 0x80体系结构,中断syscall不能用于调用系统调用.
问题是:在int 0x80架构的情况下什么是更可取的int 0x80或syscall为什么?
编辑:我使用内核3.4
我们如何在x86 Linux中直接使用sysenter/syscall实现系统调用?有人可以提供帮助吗?如果您还可以显示amd64平台的代码,那就更好了.
我知道在x86中,我们可以使用
__asm__(
" movl $1, %eax \n"
" movl $0, %ebx \n"
" call *%gs:0x10 \n"
);
Run Code Online (Sandbox Code Playgroud)
间接路由到sysenter.
但是我们如何使用sysenter/syscall直接编码来发出系统调用呢?
我找到了一些材料http://damocles.blogbus.com/tag/sysenter/.但仍然难以弄明白.
我的理解是,一般来说,如果从信号处理程序调用非异步信号安全函数,行为是不确定的,但我听说linux允许你安全地调用任何系统调用.这是真的?此外,SIGSEGV处理程序的唯一可移植行为是中止或退出,但我知道如果你返回,linux实际上会恢复执行,是吗?
有谁知道在汇编语言中为Linux系统调用找到汇总表或备忘单的位置?我通过int 0x80指令调用Linux系统调用,我需要不时地引用哪个寄存器包含什么值.
谢谢.
在Ubuntu上 - 内核2.6.32.2
如何在没有任何库帮助的情况下直接从用户代码调用已有的系统调用?我读书和在互联网上解决这个问题,然后写下面的代码但仍然出错.请帮忙
想要找出当前进程的进程ID
#include <stdio.h>
#include<linux/unistd.h> // for __NR_getpid
_syscall0(int, getpid)
int main() {
printf("Current Process ID : %d\n",getpid());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
编译时出错:
root@Omkant:~/os# gcc -Wall getpid.c -o getpid
getpid.c:5:16: error: expected declaration specifiers or ‘...’ before ‘getpid’
getpid.c:5:1: warning: data definition has no type or storage class
getpid.c:5:1: warning: type defaults to ‘int’ in declaration of ‘_syscall0’
getpid.c: In function ‘main’:
getpid.c:8:2: warning: implicit declaration of function ‘getpid’
Run Code Online (Sandbox Code Playgroud)
代码中的问题是什么?请帮忙...
所以这就是我正在关注的场景:
我有3个库 - A,B和C.
foo()并将其公开为API.foo()调用POSIX write()调用来写入一些数据.write()使用linker -wrap选项将包装器写入glibc调用.write()库C所做的任何调用都会被包装库B拦截.但是,我的问题是,如果库C调用foo(),write()foo()内的调用是否会被B拦截?
我有一个包含#include <dos.h>标题的C程序.它显示编译时错误.我知道dos.h头文件在Linux中无效.
dos.h在Linux中是否还有其他等效标头?
如果用户应用程序进行系统调用,则会触发软件中断/异常.如何查看生成软件中断的源代码?
我需要在 Android NDK 内部使用 syscall 来防止挂钩包装函数。在 Linux 中有像 SYSCALL_INLINE 这样的宏,它允许在没有包装函数的情况下使用系统调用。因此宏将系统调用汇编代码直接嵌入到项目中。
我在 Android NDK 中找不到类似的宏。
也许我可以像这样编写自己的函数;https://git.busybox.net/uClibc/tree/libc/sysdeps/linux/arm/syscall.c
但我需要有相同功能的 arm、arm_64、x86 和 x86_64 版本。
你能帮助我吗?我怎样才能找到解决办法?
linux ×8
c ×5
system-calls ×5
assembly ×4
posix ×2
x86 ×2
x86-64 ×2
abi ×1
android ×1
android-ndk ×1
gcc ×1
header-files ×1
ld ×1
linker ×1
linux-kernel ×1
signals ×1
unix ×1