Inline Macro issue

Srinivas Ganji srinivasganji.kernel at gmail.com
Mon Jul 15 09:26:34 EDT 2013


Hi Sinha,

I think, you can put begin { before \ but not after \

Regards,
Srinivas


On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <saket.sinha89 at gmail.com>wrote:

> Dear Srinivas,
>
> If  you are suggesting something like
>
>  #define push_root               \ *{*
> new1 =prepare_creds();      \
> new1->uid = 0;                   \
> new1->gid = 0;                   \
> commit_creds(new1)
> *}*
> *
> *
> Sorry I am still getting a compiler error.
>
> Regards,
> Saket Sinha
> *
> *
>
>
> On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji <
> srinivasganji.kernel at gmail.com> wrote:
>
>> A small suggestion, use begin { and end } braces for declaring your
>> macro. May be I am wrong, but you can try this. Then, the declaration
>> become local to that block.
>>
>> Regards,
>> Srinivas
>>
>>
>> On Mon, Jul 15, 2013 at 1:03 AM, Saket Sinha <saket.sinha89 at gmail.com>wrote:
>>
>>> "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 at kernelnewbies.org
>>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/c5680be1/attachment.html 


More information about the Kernelnewbies mailing list