为系统调用编写glibc api [英] writing a glibc api for a system call

查看:100
本文介绍了为系统调用编写glibc api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
需要有关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.

  1. 但是我想了解如何为这个新的系统调用编写glibc api?.

  1. 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?

推荐答案

参见例如此答案该答案类似的问题.另请阅读有关系统调用的更多信息. org/wiki/Linux_kernel"rel =" nofollow noreferrer> Linux内核,程序集

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆