Inline Macro issue

Saket Sinha saket.sinha89 at gmail.com
Sun Jul 14 15:33:38 EDT 2013


"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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/576357d1/attachment.html 


More information about the Kernelnewbies mailing list