Introduction to Macro __user Linux

Source: Internet
Author: User

First look at the macro definition of __user:

#ifdef __checker__# define __user __attribute__ (Noderef, Address_space (1))

As you can see from the macro definition, the __user macro definition is valid under the condition that you configure the __CHECKER__ macro, and it is obvious that the macro __checker__ appears as a checking mechanism, so we can infer that the macro __user should be used to check for error usage.

In fact, it is in order to compile the kernel/module with the Make C=1 option, open the static grammar checking tool sparse, to detect possible errors. You can also see that it has no effect on the generation of the file, just to check the syntax correctness.

Further research has found that sparse is a static C-grammar checker, Linux to compile the kernel or compile module, you can attach c=1 to invoke sparse check code.

In addition, sparse defines several memory spaces, sparse defines a few address spaces for the Linux kernel, kernel space is default, the user space is 1, and the IO interval is 2. This allows you to check if there is a problem with the code that accesses the address. including Address_space (1) refers to user space.

For example, in driver authoring, size_t hello_read (struct file *file, char __user *buff, size_t count, loff_t *OFFP)

{

return 0;

}

More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/OS/Linux/

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.