1 // clone: yacfe(master), coccinelle, acomment,
3 // ****************************************************************************
4 // Prelude, this file is to be used with the -macro_file option of the C parser
5 // ****************************************************************************
8 * - macros found in <.h>
9 * - macros found in .c; macros that cannot be parsed.
10 * In the future should be autodetected
11 * (not so easy to do same for macros in .h cos require to access .h file)
12 * - macros found in ".h"
13 * but where we cant detect that it will be a "bad macro"
14 * - macros found in .c; macros correctly parsed
15 * but where we cant detect that it will be a "bad macro"
17 * Some of those macros could be deleted and the C code rewritten because
18 * they are "bad" macros.
20 * todo? perhaps better if could enable/disable some of those expansions
21 * as different software may use conflicting macros.
24 * can maybe have a look in sparse/lib.c to see a list of default #define
25 * handled builtin apparently by gcc.
28 // ****************************************************************************
30 // ****************************************************************************
32 // #define FOO(a, OP, b) a OP b
33 // #define FOO(a,b) fn(a,b)
36 // ****************************************************************************
38 // ****************************************************************************
40 // ****************************************************************************
42 // ****************************************************************************
48 // ****************************************************************************
50 // ****************************************************************************
52 #define __getopt_argv_const const
55 // ****************************************************************************
56 // Gcc (as in the source of gcc code) macros
57 // ****************************************************************************
60 // ****************************************************************************
62 // ****************************************************************************
64 // ----------------------------------------------------------------------------
65 // Attributes. could perhaps generalize via "__.*"
66 // ----------------------------------------------------------------------------
78 #define __init_or_module
79 #define __initdata_or_module
83 #define __cacheline_aligned
84 #define ____cacheline_aligned
85 #define __cacheline_aligned_in_smp
86 #define ____cacheline_aligned_in_smp
87 #define ____cacheline_internodealigned_in_smp
100 #define __maybe_unused
103 #define __attribute_used__
104 #define __attribute_pure__
105 #define __attribute_const__
106 // #define _attribute__const __attribute__((const))
108 #define __always_inline
112 // in the other part of the kernel, in arch/, mm/, etc
119 #define __meminitdata
122 #define __nomods_init
123 #define __apicdebuginit
128 #define __tlb_handler_align
129 #define __lock_aligned
131 #define __nongprelbss
132 #define __nongpreldata
135 #define __section_jiffies
136 #define __vsyscall_fn
137 #define __section_vgetcpu_mode
138 #define __section_vsyscall_gtod_data
150 // maybe only in old kernel
151 #define __openfirmware
154 #define __extension__
163 #define __uses_jump_to_uncached
165 // ----------------------------------------------------------------------------
167 // ----------------------------------------------------------------------------
169 /* string macro. normally handle quite well by mu lalr(k), but
170 * sometimes not enough, if have for instance the XX YY case, could
171 * be considered as a declaration with XX being a typedef, so would
172 * Have ambiguity. So at least by adding this special case, we can
173 * catch more correct string-macro, no more a XX YY but now a good
176 * cf include/linux/kernel.h
178 * For stringification I need to have at least a witness, a string,
179 * and sometimes have just printk(KERN_WARNING MYSTR) and it could
180 * be transformed in a typedef later, so better to at least
181 * transform in string already the string-macro we know.
183 * Perhaps better to apply also as soon as possible the
184 * correct macro-annotation tagging (__init & co) to be able to
185 * filter them as soon as possible so that they will not polluate
186 * our pattern-matching that come later.
189 #define KERN_EMERG "KERN_EMERG"
190 #define KERN_ALERT "KERN_ALERT"
191 #define KERN_CRIT "KERN_CRIT"
192 #define KERN_ERR "KERN_ERR"
193 #define KERN_WARNING "KERN_WARNING"
194 #define KERN_NOTICE "KERN_NOTICE"
195 #define KERN_INFO "KERN_INFO"
196 #define KERN_DEBUG "KERN_DEBUG"
201 * Replaced by a string. We can't put everything as comment
202 * because it can be part of an expression where we wait for
203 * something, where we wait for a string. So at least we
204 * must keep the EX_TABLE token and transform it as a string.
206 * normally not needed if have good stringification of macro
207 * but those macros are sometimes used multiple times
208 * as in EX_TABLE(0b) EX_TABLE(1b) and we don't detect
212 // TODO don't use x :(
213 #define EX_TABLE(x) "TOTO"
214 #define ASM_EXCEPTIONTABLE_ENTRY(x) "TOTO"
215 #define DCACHE_CLEAR(x) "TOTO"
216 #define PPC405_ERR77(x) "TOTO"
221 // ----------------------------------------------------------------------------
223 // ----------------------------------------------------------------------------
224 // pb, false positive, can also be a #define cst and use as 'case CONST:'
225 //#define CONST const
228 #define STATIC static
229 #define _static static
233 #define __CS4231_INLINE__ inline
234 #define CCIO_INLINE inline
235 #define SBA_INLINE inline
237 #define STATIC_INLINE static inline
238 #define __EXTERN_INLINE extern inline
240 #define AGPEXTERN extern
242 #define PNMI_STATIC static
243 #define RLMT_STATIC static
244 #define SISINITSTATIC static
245 #define SCTP_STATIC static
250 #define TRACE_EXIT return
253 // ----------------------------------------------------------------------------
255 // ----------------------------------------------------------------------------
267 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
274 #define compat_init_data
276 #define DIVA_EXIT_FUNCTION
277 #define DIVA_INIT_FUNCTION
278 #define ACPI_SYSTEM_XFACE
281 #define in2000__INITDATA
288 #define ACPI_INTERNAL_VAR_XFACE
292 #define ACPI_STATE_COMMON
293 #define ACPI_PARSE_COMMON
294 #define ACPI_COMMON_DEBUG_MEM_HEADER
297 #define nabi_no_regargs
301 #define ATTRIBUTE_UNUSED
306 #define EARLY_INIT_SECTION_ATTR
311 #define IDI_CALL_ENTITY_T
312 #define IDI_CALL_LINK_T
315 * A trick to suppress uninitialized variable warning without generating any
318 #define uninitialized_var(x) x = x
319 // as in u16 uninitialized_var(ioboard_type); /* GCC be quiet */
321 // ----------------------------------------------------------------------------
322 // ----------------------------------------------------------------------------
324 #define __releases(x)
325 #define __acquires(x)
326 #define __declspec(x)
327 #define __page_aligned(x)
328 #define __vsyscall(x)
330 // ----------------------------------------------------------------------------
331 // ----------------------------------------------------------------------------
334 //conflict with a macro of firefox
335 //#define FASTCALL(x) x
340 // ----------------------------------------------------------------------------
341 // ----------------------------------------------------------------------------
343 // include/asm-arm/mach/arch.h
344 // #define MACHINE_START(x) struct foo { x }
345 #define MACHINE_START(_type,_name) \
346 static const struct machine_desc __mach_desc_##_type \
348 __attribute__((__section__(".arch.info.init"))) = { \
349 .nr = MACH_TYPE_##_type, \
352 #define MACHINE_END \
355 // include/asm-powerpc/machdep.h
356 #define define_machine(name) \
357 extern struct machdep_calls mach_##name; \
358 EXPORT_SYMBOL(mach_##name); \
359 struct machdep_calls mach_##name /*__machine_desc*/ =
362 // ----------------------------------------------------------------------------
363 // Declare like macros (in structure def), or tricky Declare macros
364 // ----------------------------------------------------------------------------
366 // include/asm-i386/pci.h
367 // the DECLARE are detected by parsing_hack but not when they are
368 // inside a struct def.
369 #define DECLARE_PCI_UNMAP_ADDR(ADDR_NAME)
370 #define DECLARE_PCI_UNMAP_LEN(LEN_NAME)
372 // defined in drivers/infiniband/hw/mthca/mthca_doorbell.h
373 #define MTHCA_DECLARE_DOORBELL_LOCK(doorbell_lock)
375 // include/linux/types.h
376 //#define BITS_TO_LONGS(bits) \
377 // (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
378 #define DECLARE_BITMAP(name,bits) \
379 /*unsigned*/ long name[BITS_TO_LONGS(bits)]
382 // include/asm-i386/percpu.h
383 // interesting macro where we see the need of __typeof__(type) with
384 // for example DECLARE_PER_CPU(char[256], iucv_dbf_txt_buf);
385 #define DEFINE_PER_CPU(type, name) \
386 __attribute__((__section__(".data.percpu"))) __typeof__(type) per_cpu__##name
387 #define DECLARE_PER_CPU(type, name) extern __typeof__(type) per_cpu__##name
391 // include/linux/kobject.h
392 #define decl_subsys(_name,_type,_uevent_ops) \
393 struct subsystem _name##_subsys = { \
395 .kobj = { .name = __stringify(_name) }, \
397 .uevent_ops =_uevent_ops, \
401 // ----------------------------------------------------------------------------
402 // ----------------------------------------------------------------------------
404 // pb: if use this macro then we will not transform the argument of CS_CHECK
406 //#define CS_CHECK(fn, ret) \
407 // do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
411 #define BCSP_CRC_INIT(x) x = 0xffff
414 // sound/oss/cs46xx_wrapper-24.h
415 #define CS_OWNER .owner =
416 #define CS_THIS_MODULE THIS_MODULE,
419 // sound/sparc/dbri.c
420 // "bad macro", have a ',' at the end
421 #define CS4215_SINGLE(xname, entry, shift, mask, invert) \
422 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
423 .info = snd_cs4215_info_single, \
424 .get = snd_cs4215_get_single, .put = snd_cs4215_put_single, \
425 .private_value = entry | (shift << 8) | (mask << 16) | (invert << 24) },
427 // drivers/media/video/sn9c102/sn9c102_sensor.h
428 //#define sn9c102_write_const_regs(sn9c102_device, data...) \
429 // ({ const static u8 _valreg[][2] = {data}; \
430 // sn9c102_write_regs(sn9c102_device, _valreg, ARRAY_SIZE(_valreg)); })
436 // drivers/s390/cio/qdio.h
437 #define SYNC_MEMORY if (unlikely(q->siga_sync)) qdio_siga_sync_q(q)
438 #define SYNC_MEMORY_ALL if (unlikely(q->siga_sync)) \
439 qdio_siga_sync(q,~0U,~0U)
440 #define SYNC_MEMORY_ALL_OUTB if (unlikely(q->siga_sync)) \
441 qdio_siga_sync(q,~0U,0)
443 // drivers/scsi/g_NCR5380.c
447 // drivers/scsi/ncr53c8xx.c
448 // generate lots of errors because error en cascade car dans l'initialiseur
449 // il y'a des '}' dans la premiere colonne
450 #define PREFETCH_FLUSH SCR_CALL, PADDRH (wait_dma),
452 // drivers/net/e100.c
453 // pbs false positive, defined in another manner in some files
457 // net/ipv4/netfilter/ip_conntrack_helper_h323_asn1.c
458 // also used in other.c that don't do any include :(
459 // but locally redefined in drivers/net/bnx2.c :( with a
461 #define FNAME(name) name,
464 // drivers/net/tulip/de4x5.c
469 #define MPI_POINTER *
471 // mega4/soc.c mega4/socal.c
472 // cause false typedef inference if let soc_printk
473 #define soc_printk printk
474 #define socal_printk printk
477 // ----------------------------------------------------------------------------
478 // Initializer array macros
479 // ----------------------------------------------------------------------------
481 // drivers/net/wireless/bcm43xx/bcm43xx_wx.c
482 // defined in similar way multiple times, in the same file and in another one
483 #define WX(ioctl) [(ioctl) - SIOCSIWCOMMIT]
484 // #define WX(x) [(x)-SIOCIWFIRST]
486 // drivers/net/wireless/ipw2200.c
487 #define IW_IOCTL(x) [(x)-SIOCSIWCOMMIT]
489 // drivers/net/wireless/zd1211rw/zd_netdev.c
490 #define PRIV_OFFSET(x) [(x)-SIOCIWFIRSTPRIV]
492 // drivers/net/wireless/zd1211rw/zd_rf.h
493 #define RF_CHANNEL(ch) [(ch)-1]
495 // drivers/net/wireless/zd1211rw/zd_rf_uw2453.c
496 #define RF_CHANPAIR(a,b) [CHAN_TO_PAIRIDX(a)]
498 // drivers/net/wireless/arlan-proc.c
499 // incomplete macro, the real macro is quite complex and use other macros
500 #define ARLAN_SYSCTL_TABLE_TOTAL(x)
503 // ----------------------------------------------------------------------------
504 // ----------------------------------------------------------------------------
506 // drivers/net/cxgb3/t3_hw.c
507 #define VPD_ENTRY(name, len) \
508 u8 name##_kword[2]; u8 name##_len; u8 name##_data[len]
511 // #define rtrc(i) {}
513 // ----------------------------------------------------------------------------
514 // ----------------------------------------------------------------------------
516 // drivers/video/nvidia/nv_type.h
517 // use: SetBitField(h_blank_e, 5: 5, 7:7)
518 //#define BITMASK(t,b) (((unsigned)(1U << (((t)-(b)+1)))-1) << (b))
519 //#define MASKEXPAND(mask) BITMASK(1?mask,0?mask)
520 //#define SetBF(mask,value) ((value) << (0?mask))
521 //#define GetBF(var,mask) (((unsigned)((var) & MASKEXPAND(mask))) >> (0?mask) )
522 //#define SetBitField(value,from,to) SetBF(to, GetBF(value,from))
523 //#define SetBit(n) (1<<(n))
524 //#define Set8Bits(value) ((value)&0xff)
527 // drivers/video/sis/init.c
528 // use: GETBITSTR((SiS_Pr->CVTotal -2), 10:10, 0:0)
529 //#define BITMASK(h,l) (((unsigned)(1U << ((h)-(l)+1))-1)<<(l))
530 //#define GENMASK(mask) BITMASK(1?mask,0?mask)
531 //#define GETBITS(var,mask) (((var) & GENMASK(mask)) >> (0?mask))
532 //#define GETBITSTR(val,from,to) ((GETBITS(val,from)) << (0?to))
536 #define ASSERTCMP(X, OP, Y) \
538 if (unlikely(!((X) OP (Y)))) { \
539 printk(KERN_ERR "\n"); \
540 printk(KERN_ERR "AFS: Assertion failed\n"); \
541 printk(KERN_ERR "%lu " /*#OP*/ " %lu is false\n", \
542 (unsigned long)(X), (unsigned long)(Y)); \
543 printk(KERN_ERR "0x%lx " /*#OP*/ " 0x%lx is false\n", \
544 (unsigned long)(X), (unsigned long)(Y)); \
549 #define ASSERTIFCMP(C, X, OP, Y) \
551 if (unlikely((C) && !((X) OP (Y)))) { \
552 printk(KERN_ERR "\n"); \
553 printk(KERN_ERR "AFS: Assertion failed\n"); \
554 printk(KERN_ERR "%lu " /*#OP*/ " %lu is false\n", \
555 (unsigned long)(X), (unsigned long)(Y)); \
556 printk(KERN_ERR "0x%lx " /*#OP*/ " 0x%lx is false\n", \
557 (unsigned long)(X), (unsigned long)(Y)); \
563 #define ASSERTRANGE(L, OP1, N, OP2, H) \
565 if (unlikely(!((L) OP1 (N)) || !((N) OP2 (H)))) { \
566 printk(KERN_ERR "\n"); \
567 printk(KERN_ERR "AFS: Assertion failed\n"); \
568 printk(KERN_ERR "%lu "/*#OP1*/" %lu "/*#OP2*/" %lu is false\n", \
569 (unsigned long)(L), (unsigned long)(N), \
570 (unsigned long)(H)); \
571 printk(KERN_ERR "0x%lx "/*#OP1*/" 0x%lx "/*#OP2*/" 0x%lx is false\n", \
572 (unsigned long)(L), (unsigned long)(N), \
573 (unsigned long)(H)); \
581 // loop, macro without ';', single macro. ex: DEBUG()
583 // TODO should find the definition because we don't use 'x' and so
584 // may lose code sites with coccinelle. If expand correctly, will
585 // still don't transform correctly but at least will detect the place.
590 // Cooperation with parsing_hack.ml: MACROSTATEMENT is a magic string.
591 // I can't just expand those macros into some 'whatever();' because I need
592 // to generate a TMacroStmt for solving some ambiguities in the grammar
593 // for the toplevel stuff I think.
594 #define ASSERT(x) MACROSTATEMENT
595 #define IRDA_ASSERT(x) MACROSTATEMENT
597 #define CHECK_NULL(x) MACROSTATEMENT
599 //#define DEBUG(x) MACROSTATEMENT
600 #define DEBUG0(x) MACROSTATEMENT
601 #define DEBUG1(x) MACROSTATEMENT
602 #define DEBUG2(x) MACROSTATEMENT
603 #define DEBUG3(x) MACROSTATEMENT
606 #define DBG(x) MACROSTATEMENT
607 #define DEB(x) MACROSTATEMENT
608 #define PARSEDEBUG(x) MACROSTATEMENT
609 #define DEBC(x) MACROSTATEMENT
610 #define DBG_TRC(x) MACROSTATEMENT
611 #define DBG_ERR(x) MACROSTATEMENT
612 #define DBG_FTL(x) MACROSTATEMENT
614 #define DBGINFO(x) MACROSTATEMENT
615 #define DFLOW(x) MACROSTATEMENT
616 #define DFLIP(x) MACROSTATEMENT
617 #define DLOG_INT_TRIG(x) MACROSTATEMENT
619 #define D3(x) MACROSTATEMENT
620 #define D1(x) MACROSTATEMENT
621 #define DB(x) MACROSTATEMENT
622 #define DCBDEBUG(x) MACROSTATEMENT
623 #define SCSI_LOG_MLQUEUE(x) MACROSTATEMENT
625 #define PLND(x) MACROSTATEMENT
626 #define FCALND(x) MACROSTATEMENT
627 #define FCALD(x) MACROSTATEMENT
629 #define DEBUGRECURSION(x) MACROSTATEMENT
631 #define DEBUGPIO(x) MACROSTATEMENT
632 #define VDEB(x) MACROSTATEMENT
634 #define READ_UNLOCK_IRQRESTORE(x) MACROSTATEMENT
636 #define TRACE_CATCH(x) MACROSTATEMENT
638 #define PDBGG(x) MACROSTATEMENT
640 #define IF_ABR(x) MACROSTATEMENT
641 #define IF_EVENT(x) MACROSTATEMENT
642 #define IF_ERR(x) MACROSTATEMENT
643 #define IF_CBR(x) MACROSTATEMENT
644 #define IF_INIT(x) MACROSTATEMENT
645 #define IF_RX(x) MACROSTATEMENT
647 #define SOD(x) MACROSTATEMENT
649 #define KDBG(x) MACROSTATEMENT
651 #define IRDA_ASSERT_LABEL(x) MACROSTATEMENT
657 // ----------------------------------------------------------------------------
659 // ----------------------------------------------------------------------------
661 // include/linux/sched.h
662 #define while_each_thread(g, t) \
663 while ((t = next_thread(t)) != g)
667 // net/decnet/dn_fib.c
668 #define for_fib_info() { struct dn_fib_info *fi;\
669 for(fi = dn_fib_info_list; fi; fi = fi->fib_next)
670 #define endfor_fib_info() }
672 #define for_nexthops(fi) { int nhsel; const struct dn_fib_nh *nh;\
673 for(nhsel = 0, nh = (fi)->fib_nh; nhsel < (fi)->fib_nhs; nh++, nhsel++)
675 #define change_nexthops(fi) { int nhsel; struct dn_fib_nh *nh;\
676 for(nhsel = 0, nh = (struct dn_fib_nh *)((fi)->fib_nh); nhsel < (fi)->fib_nhs; nh++, nhsel++)
678 #define endfor_nexthops(fi) }
681 // ----------------------------------------------------------------------------
682 // Macros around function prototype
683 // ----------------------------------------------------------------------------
686 // net/sched/em_meta.c
687 #define META_COLLECTOR(FUNC) static void meta_##FUNC(struct sk_buff *skb, \
688 struct tcf_pkt_info *info, struct meta_value *v, \
689 struct meta_obj *dst, int *err)
692 #define GDTH_INITFUNC(x,y) x y
693 #define ASC_INITFUNC(x,y) x y
696 // ----------------------------------------------------------------------------
698 // ----------------------------------------------------------------------------
700 // include/linux/lockd/debug.h
701 // include/linux/nfs_fs.h
702 // include/linux/nfsd/debug.h
703 // include/linux/sunrpc/debug.h
704 //#define ifdebug(flag) if (unlikely(nlm_debug & NLMDBG_##flag))
705 #define ifdebug(flag) if (0)
709 // ----------------------------------------------------------------------------
712 // ----------------------------------------------------------------------------
713 // for tests-big/ macros, may be obsolete now cos fixed in latest kernel
714 // ----------------------------------------------------------------------------
717 //#define ACPI_MODULE_NAME(x)
722 // ****************************************************************************
723 // Httpd (apache) macros
724 // ****************************************************************************
726 #define AP_DECLARE(x) x
727 #define PROXY_DECLARE(x) x
728 #define CACHE_DECLARE(x) x
729 #define DBD_DECLARE_NONSTD(x) x
730 #define DAV_DECLARE(x) x
731 #define APU_DECLARE(x) x
732 #define APU_DECLARE_NONSTD(x) x
733 #define APR_DECLARE(x) x
734 #define AP_CORE_DECLARE(x) x
735 #define AP_DECLARE_NONSTD(x) x
736 #define AP_CORE_DECLARE_NONSTD(x) x
737 #define APR_OPTIONAL_FN_TYPE(x) x
738 #define DAV_DECLARE_NONSTD(x) x
739 #define APR_DECLARE_NONSTD(x) x
741 #define APU_DECLARE_DATA
742 #define APR_THREAD_FUNC
743 #define AP_DECLARE_DATA
744 #define PROXY_DECLARE_DATA
745 #define AP_MODULE_DECLARE_DATA
746 #define APR_DECLARE_DATA
750 #define APR_INLINE inline
751 #define EXPORT static
752 #define REGISTER register
754 #define MODSSL_D2I_SSL_SESSION_CONST const
755 #define MODSSL_D2I_X509_CONST const
756 #define MODSSL_D2I_PrivateKey_CONST const
757 #define MODSSL_D2I_SSL_SESSION_CONST const
759 #define STACK_OF(X509_NAME) X509_NAME
761 #define MODSSL_PCHAR_CAST (pchar)
765 // generate false positive in Linux
767 #define __declspec(x)
771 //#define module struct xxx
773 #define APR_POOL_IMPLEMENT_ACCESSOR(shm)
775 #define ADD_SUITE(suite) suite;
777 // ****************************************************************************
778 // CISCO vpn client macros
779 // ****************************************************************************
787 #define unlikely(x) x