yuyulvxian 发表于 2005-9-8 13:43:11

linux内核中开头带有asmlinkage的函数表示什么

linux内核中开头带有 asmlinkage 的函数表示什么

pinper 发表于 2005-9-12 19:37:36

强制通过堆栈传递参数,不要用寄存器传递

yuyulvxian 发表于 2005-9-13 08:51:21

这样做是为了节约寄存器资源提高效率 还是其他的原因

pinper 发表于 2005-9-13 21:09:14

跟这没关系,仔细看一下有asmlinkage的地方通常是系统调用的函数,因为在系统调用中,寄存器从用户空间传过来后SAVE_ALL压入堆栈,接着调用相应的系统调用函数,这样系统调用函数一定要保证是通过堆栈传递参数的

转贴一段:
The asmlinkage tag is one other thing that we should observe about this simple function. This is a #define for some gcc magic that tells the compiler that the function should not expect to find any of its arguments in registers (a common optimization), but only on the CPU's stack. Recall our earlier assertion that system_call consumes its first argument, the system call number, and allows up to four more arguments that are passed along to the real system call. system_call achieves this feat simply by leaving its other arguments (which were passed to it in registers) on the stack. All system calls are marked with the asmlinkage tag, so they all look to the stack for arguments. Of course, in sys_ni_syscall's case, this doesn't make any difference, because sys_ni_syscall doesn't take any arguments, but it's an issue for most other system calls. And, because you'll be seeing asmlinkage in front of many other functions, I thought you should know what it was about.

yuyulvxian 发表于 2005-9-14 09:02:23

明白了 谢谢啊

yuyulvxian 发表于 2005-9-14 10:53:02

那对于参数小于5的系统调用是不是就不用了

pinper 发表于 2005-9-14 19:53:03

不是,跟这没关系的,具体可以研究一下arch/i386/kernel/entry.S

yuyulvxian 发表于 2005-9-15 08:33:46

是不是为了保护寄存器内容不受更改 才用堆栈传递参数 以便以后能RESTORE--ALL

pinper 发表于 2005-9-15 08:49:27

系统调用把参数存放在寄存器中然后进入内核空间,其实就和正常的函数调用一样,在内核中通过SAVE_ALL构造一个函数调用的栈帧环境,然后调用相应的系统调用函数而已

yuyulvxian 发表于 2005-9-15 12:35:06

这里使用的堆栈就是原来SAVE--ALL的寄存器的内容吧

pinper 发表于 2005-9-15 18:54:23

对的

ENTRY(system_call)
        pushl %eax                        # save orig_eax
        SAVE_ALL
        GET_THREAD_INFO(%ebp)
                                        # system call tracing in operation
        /* Note, _TIF_SECCOMP is bit number 8, and so it needs testw and not testb */
        testw $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT|_TIF_SECCOMP),TI_flags(%ebp)
        jnz syscall_trace_entry
        cmpl $(nr_syscalls), %eax
        jae syscall_badsys
syscall_call:
        call *sys_call_table(,%eax,4)
        movl %eax,EAX(%esp)                # store the return value
页: [1]
查看完整版本: linux内核中开头带有asmlinkage的函数表示什么