Linux Kernel asmlinkage macro

Source: Internet
Author: User
Asmlinkage is a macro used to keep parameters in the stack.

Take a look at the definitions in/usr/include/ASM/linkage. h:
# Define asmlinkage cpp_asmlinkage _ attribute _ (regparm (0 )))

Among them, _ attribute _ is the keyword, which is the C language extension of GCC.

The _ attribute _ mechanism is a major feature of gnu c. It can be used to set function attributes, variable attributes, and type attributes. They can be used to provide more data to the compiler and help the compiler perform optimization.
_ Attribute _ (regparm (0): tells the GCC compiler that this function does not need to pass parameters through any registers, but only through stacks.
_ Attribute _ (regparm (3): tells the GCC compiler that this function can pass up to three parameters through registers, the three registers are eax, EDX, and ECx in sequence. More parameters are passed through the stack. In this way, some inbound and outbound stack operations can be reduced, so calling is faster.

Generally, asmlinkage is used in system calls. In some cases, it is necessary to clearly inform the compiler that we use stack to pass parameters. For example, in x86 system calls, the parameter is first pushed to the stack and then the Sys _ * function is called, so all sys _ * functions have asmlinkage to tell the compiler not to use registers for compilation,

The asmlinkage tag is one other thing that we shoshould observe about this simple function. this is a # define for some GCC magic that tells the compiler that the function shocould not perform CT 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 callare 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 CILS. and, because you'll be seeing asmlinkage in front of your other functions, I Thought You shoshould know what it was about.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.