lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <200805241636.22242.sfuerst@stanford.edu>
Date:	Sat, 24 May 2008 16:36:22 -0700
From:	Steven Fuerst <sfuerst@...nford.edu>
To:	linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH] kconfig: introduce KCONFIG_* symbols for .c files


> On Sat, May 24, 2008 at 09:58:47PM +0100, Jeremy Fitzhardinge wrote:
> >
> > Would
> >
> > #define KCONFIG(x) (CONFIG_##x - 0)
> >
> > if (KCONFIG(PREEMPT)) {
> > ...
> > }
> >
> > work?
> 
> $ cat test.c
> #define KCONFIG(x) (CONFIG_##x - 0)
> 
> int main()
> {
> if (KCONFIG(PREEMPT))
> ;
> 
> return 0;
> }
> $ gcc -O2 -Wall test.c
> test.c: In function âmainâ:
> test.c:5: error: âCONFIG_PREEMPTâ undeclared (first use in this function)
> test.c:5: error: (Each undeclared identifier is reported only once
> test.c:5: error: for each function it appears in.)
> $ gcc --version
> gcc (Debian 4.3.0-5) 4.3.1 20080523 (prerelease)
>
> > J
>
> cu
> Adrian

How about this?

#include <stdio.h>

#define CONFIG_FOO	1
/* #define CONFIG_BAR	1 */

#define STR2(x) #x
#define STR(x) STR2(x)

#define PASTE2(x, y) x##y
#define PASTE(x, y) PASTE2(x, y)

#define KCONFIG2(x, y) STR(PASTE(CONFIG_, x))[y]
#define KCONFIG(x) (!((KCONFIG2(x, 0) == 'C') && \
					(KCONFIG2(x, 1) == 'O') && \
					(KCONFIG2(x, 2) == 'N') && \
					(KCONFIG2(x, 3) == 'F') && \
					(KCONFIG2(x, 4) == 'I') && \
					(KCONFIG2(x, 5) == 'G') && \
					(KCONFIG2(x, 6) == '_')))

int main()
{
	if (KCONFIG(FOO)) printf("FOO\n");
	if (KCONFIG(BAR)) printf("BAR\n");
	return 0;
}


It of course assumes that the result of all defined macros you want to test 
for do not start with "CONFIG_", so this doesn't work generally.  However, 
nearly all of the time the arguement to KCONFIG() will be defined to be "1" 
an integer, or some other known string that doesn't begin with "CONFIG_", so 
this trick is fairly robust.

Steven

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ