为系统调用编写glibc api [英] writing a glibc api for a system call
问题描述
可能重复:
需要有关glibc源的帮助
Possible Duplicate:
Need help with glibc source
我了解如何在linux内核中实现我们自己的系统调用.我知道我们可以在c程序中使用syscall()
或_asm()
来调用它.
I understand how to implement our own system calls in linux kernel. I know we can call this with syscall()
or with _asm()
in a c program.
-
但是我想了解如何为这个新的系统调用编写glibc api?.
But I want to understand how to write glibc api for this new system call?.
open()
和read()
glibc函数如何调用映射到内核中的系统调用?
How the open()
and read()
glibc function calls mapping into system call in kernel?.
char message[ ] = "Hello!\n";
int main( void )
{
write( 1, message, 7 );
exit( 0 );
}
当我将上述程序转换为汇编程序时,它给出了
When I convert the above program into assembly it is giving
main:
leal 4(%esp), %ecx
andl $-16, %esp
pushl -4(%ecx)
pushl %ebp
movl %esp, %ebp
pushl %ecx
subl $20, %esp
movl $7, 8(%esp)
movl $message, 4(%esp)
movl $1, (%esp)
call write
movl $0, (%esp)
call exit
.size main, .-main
.ident "GCC: (Debian 4.3.2-1.1) 4.3.2"
.section .note.GNU-stack,"",@progbits
〜
3,在调用写"中,我认为写是glibc在这里调用吗?之后会发生什么?如何将glibc调用映射到系统调用?
3, In "call write" I think write is glibc call here ?. what happens after that? how it maps the glibc call to system call?
推荐答案
参见例如此答案和该答案类似的问题.另请阅读有关
See e.g. this answer and that answer to similar questions. Read also more about syscalls, the linux kernel, an overview of linux syscalls, and the assembly howto
glibc中的write
函数不是真正的syscall.它是一个包装器(可以通过sysenter
机器指令进行sycall,也许使用 VDSO ,然后设置errno
).
您可以使用strace
了解某些程序执行的系统调用.
The write
function from glibc is not the true syscall. It is a wrapper (doing the sycall thru e.g. sysenter
machine instruction, perhaps with the VDSO, and setting errno
).
You can use strace
to understand the system calls done by some program.
例如, MUSL libc 具有此
For example, the MUSL libc has this write.c implementation for write
. For GNU libc, look at its write.c.
这篇关于为系统调用编写glibc api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!