Linux macro

  

First take a look at the __user macro definition:

#ifdef __CHECKER__ # define __user __attribute__((noderef, address_space(1))) can be seen from the macro definition, in the configuration _ Under the condition of the _CHECKER__ macro, the __user macro definition is valid, and it is obvious that the macro __CHECKER__ appears as an inspection mechanism, so we can infer that the macro __user should be used to check for error use.

And in fact it is, it is to use the make C=1 option to compile the kernel/module, open the static syntax checking tool sparse to detect possible errors. At the same time, it can be seen that it has no effect on the generation of the file, only to check the grammatical correctness.

Further research found that sparse is a static C syntax checking tool. When compiling a kernel or compiling a module under Linux, you can call the sparse check code by appending C=1.

In addition, the sparse definition A few memory spaces, sparse defines several address spaces for the Linux kernel, the kernel space is the default, the user space is 1, and the io interval is 2. This can check if there is a problem with the code of the access address. Including address_space(1) refers to user space.

For example, in driver writing, size_t hello_read(struct file *file, char __user *buff, size_t count, loff_t *offp) { return 0; }

Copyright © Windows knowledge All Rights Reserved