Hi Saket Sinha Just try as below example - #include <stdio.h> #define pushme \ do \ { \ printf("Hi...\n"); \ } while(0); int main() { printf("in main\n"); pushme return 0; } Thanks & Regards Murali Annamneni -----Original Message----- From: kernelnewbies-bounces@xxxxxxxxxxxxxxxxx [mailto:kernelnewbies-bounces@xxxxxxxxxxxxxxxxx] On Behalf Of kernelnewbies-request@xxxxxxxxxxxxxxxxx Sent: Monday, July 15, 2013 5:03 PM To: kernelnewbies@xxxxxxxxxxxxxxxxx Subject: Kernelnewbies Digest, Vol 32, Issue 20 Send Kernelnewbies mailing list submissions to kernelnewbies@xxxxxxxxxxxxxxxxx To subscribe or unsubscribe via the World Wide Web, visit http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies or, via email, send a message with subject or body 'help' to kernelnewbies-request@xxxxxxxxxxxxxxxxx You can reach the person managing the list at kernelnewbies-owner@xxxxxxxxxxxxxxxxx When replying, please edit your Subject line so it is more specific than "Re: Contents of Kernelnewbies digest..." Today's Topics: 1. Re: Inline Macro issue (Saket Sinha) 2. Re: Inline Macro issue (Mandeep Sandhu) 3. Re: Inline Macro issue (anish singh) 4. Re: Inline Macro issue (Saket Sinha) 5. Re: Inline Macro issue (Saket Sinha) ---------------------------------------------------------------------- Message: 1 Date: Mon, 15 Jul 2013 15:54:55 +0530 From: Saket Sinha <saket.sinha89@xxxxxxxxx> Subject: Re: Inline Macro issue To: Srinivas Ganji <srinivasganji.kernel@xxxxxxxxx> Cc: kernelnewbies@xxxxxxxxxxxxxxxxx Message-ID: <CAK25hWO3zbFu8MgXtPSpGq_0uj+qv07hGJjp018heGTDABN7nA@xxxxxxxxxxxxxx> Content-Type: text/plain; charset="iso-8859-1" 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@xxxxxxxxx> 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@xxxxxxxxx>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@xxxxxxxxxxxxxxxxx >> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies >> >> > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/d360136c/attachment-0001.html ------------------------------ Message: 2 Date: Mon, 15 Jul 2013 16:24:18 +0530 From: Mandeep Sandhu <mandeepsandhu.chd@xxxxxxxxx> Subject: Re: Inline Macro issue To: Saket Sinha <saket.sinha89@xxxxxxxxx> Cc: Srinivas Ganji <srinivasganji.kernel@xxxxxxxxx>, kernelnewbies <kernelnewbies@xxxxxxxxxxxxxxxxx> Message-ID: <CAC+QLdQbBuNEW7EKZk4vUTNuu2LGSZ6gJhf4bde3gC+=D9FP8w@xxxxxxxxxxxxxx> Content-Type: text/plain; charset="iso-8859-1" On Mon, Jul 15, 2013 at 3:54 PM, Saket Sinha <saket.sinha89@xxxxxxxxx>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. > What errors is the compiler giving? Last time you mentioned that it's saying new1 has multiple def's. Is it possible your macro has a declaration of new1 in it. So if you use the macro in the same scope, you'll get re-def errors. You can also try and look at the intermediate file for your source code, i.e after the pre-processing is done (*.i files). I don't remember the exact gcc option. Try --save-temps and look at the <source file name>.i file. HTH, -mandeep > > Regards, > Saket Sinha > * > * > > > On Mon, Jul 15, 2013 at 2:25 PM, Srinivas Ganji < > srinivasganji.kernel@xxxxxxxxx> 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@xxxxxxxxx>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@xxxxxxxxxxxxxxxxx >>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies >>> >>> >> > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies@xxxxxxxxxxxxxxxxx > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/66b262f1/attachment-0001.html ------------------------------ Message: 3 Date: Mon, 15 Jul 2013 16:54:33 +0530 From: anish singh <anish198519851985@xxxxxxxxx> Subject: Re: Inline Macro issue To: Saket Sinha <saket.sinha89@xxxxxxxxx> Cc: Srinivas Ganji <srinivasganji.kernel@xxxxxxxxx>, Mandeep Sandhu <mandeepsandhu.chd@xxxxxxxxx>, kernelnewbies <kernelnewbies@xxxxxxxxxxxxxxxxx> Message-ID: <CAK7N6vp2BCz_B5K2PNvdRJpt-xoqhfNSW9MmavohG1__p9CFiA@xxxxxxxxxxxxxx> Content-Type: text/plain; charset=UTF-8 Do one simple thing.Write a test code which uses that macro and paste it here in ideone.com On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@xxxxxxxxx> wrote: > Mandip: > Error is expected error or declaration at the end of input > Anish: > that '\' should not be there first of all and even if I put it same > error > ------------------------------ Message: 4 Date: Mon, 15 Jul 2013 16:50:34 +0530 From: Saket Sinha <saket.sinha89@xxxxxxxxx> Subject: Re: Inline Macro issue To: Mandeep Sandhu <mandeepsandhu.chd@xxxxxxxxx>, anish198519851985@xxxxxxxxx Cc: Srinivas Ganji <srinivasganji.kernel@xxxxxxxxx>, kernelnewbies <kernelnewbies@xxxxxxxxxxxxxxxxx> Message-ID: <CAK25hWMLndvytwZ0YVFMXhrd44Jb479HmiYLZ48Umozz1pz7vQ@xxxxxxxxxxxxxx> Content-Type: text/plain; charset="iso-8859-1" Mandip: Error is expected error or declaration at the end of input Anish: that '\' should not be there first of all and even if I put it same error -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/41316b0d/attachment-0001.html ------------------------------ Message: 5 Date: Mon, 15 Jul 2013 17:02:49 +0530 From: Saket Sinha <saket.sinha89@xxxxxxxxx> Subject: Re: Inline Macro issue To: anish singh <anish198519851985@xxxxxxxxx> Cc: Srinivas Ganji <srinivasganji.kernel@xxxxxxxxx>, Mandeep Sandhu <mandeepsandhu.chd@xxxxxxxxx>, kernelnewbies <kernelnewbies@xxxxxxxxxxxxxxxxx> Message-ID: <CAK25hWMvjdABa-KS1Ru1bBWaETd7JHKOGXdqhyY8ROLksSKi3w@xxxxxxxxxxxxxx> Content-Type: text/plain; charset="iso-8859-1" Dear Anish, Actually its kernel module, so then I will have to write all the dummy equivalent of the structures and functions involved. I can do this....give my system on remote. Regards, Saket Sinha On Mon, Jul 15, 2013 at 4:54 PM, anish singh <anish198519851985@xxxxxxxxx>wrote: > Do one simple thing.Write a test code > which uses that macro and paste it > here in ideone.com > > On Mon, Jul 15, 2013 at 4:50 PM, Saket Sinha <saket.sinha89@xxxxxxxxx> > wrote: > > Mandip: > > Error is expected error or declaration at the end of input > > Anish: > > that '\' should not be there first of all and even if I put it same > > error > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20130715/1281ba32/attachment.html ------------------------------ _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies End of Kernelnewbies Digest, Vol 32, Issue 20 ********************************************* ::DISCLAIMER:: ---------------------------------------------------------------------------------------------------------------------------------------------------- The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The e mail and its contents (with or without referred errors) shall therefore not attach any liability on the originator or HCL or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of HCL or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and / or publication of this message without the prior written consent of authorized representative of HCL is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects. ---------------------------------------------------------------------------------------------------------------------------------------------------- _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies