__verify_pcpu_ptr function in Linux Kernel - What does it do? -


#define __verify_pcpu_ptr(ptr)                       {                                     const void __percpu *__vpp_verify = (typeof((ptr) + 0))null;     (void)__vpp_verify;                      } while (0)  #define verify_percpu_ptr(__p)                       ({                                   __verify_pcpu_ptr(__p);                      (typeof(*(__p)) __kernel __force *)(__p);            }) 

what these 2 functions do? used for? how work?

thanks.

this part of scheme used per_cpu_ptr support pointer gets different value each cpu. there 2 motives here:

  1. ensure accesses per-cpu data structure made via per_cpu_ptr macro.
  2. ensure argument given macro of correct type.

restating, ensures (a) don't accidentally access per-cpu pointer without macro (which reference first of n members), , (b) don't inadvertently use macro cast pointer not of correct declared type 1 is.

by using these macros, support of compiler in type-checking without runtime overhead. compiler smart enough recognize of these complex machinations result in no observable state change, yet type-checking have been performed. benefit of type-checking, no actual executable code have been emitted compiler.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -