Inline Macro issue

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"current" in kernel is a global macro, that always point to the "struct task_struct * " of the currently executing task (for details on task_struct, ref Robert Love, pg 24-27).

 Now I have a macro called push root which has the following purpose-
"to push  root user and group to current context so to set current uid and gid to 0."

 Now in kernel 3.8.3, I would do something like

struct cred *new1;
new1 =prepare_creds();
new1->uid = 0;  
new1->gid = 0;
commit_creds(new1);

So macro definition of push root, according to what I have proposed above, should be
#define push_root               \
new1 =prepare_creds();      \
new1->uid = 0;                   \  
new1->gid = 0;                   \
commit_creds(new1)     

But I am getting errors like multiple declaration of new1 etc.

Even if I declare prepare_creds outside macro definition like

new1 =prepare_creds();   
#define push_root               \
new1->uid = 0;                   \  
new1->gid = 0;                   \
commit_creds(new1)      

I think I am  facing the issue that the macros are inlined during compilation, so when the compiler wants to replace them, it raises issues.

I could think of two ways to solve this issue-

1. define a new macro like #define prep_root() which defines the var once for all, and that I have to put it at the begin of each function needing push_root. This is not a very good method.

2. I should still try to go with inlined functions but how ?

Can someone suggest anything

Regards,
Saket Sinha
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux