-   Linux - Kernel (
-   -   Linux Kernel source code: What does static void __##func mean? (

GreyGnome 09-17-2020 03:40 PM

Linux Kernel source code: What does static void __##func mean?
I am trying to find out what the CAL interrupt in /proc/interrupts is all about. I understand it's "Function Call interrupts" but there seems to be a dearth of information about what a Function Call interrupt really is. I can presume it means "an interrupt generated whenever you call a system call", but I'm not so sure about that. "Prove it," I says to myself.

So I did some digging and uncovered (assume we're staying in x86-land for now), which says


. This is where the CAL counter gets incremented (it's irq_call_count). Perfect!

But I can't figure out how DEFINE_IDTENTRY_SYSVEC(sysvec_call_function) is called. What is a "sysvec_call_function"? That's not defined anywhere. And DEFINE_IDTENTRY_SYSVEC has a definition that I don't understand:


#define DEFINE_IDTENTRY_SYSVEC(func)                                        \
static void __##func(struct pt_regs *regs);



I think I might understand better if I could figure out what


Can you help? Thanks.

powerboat9 09-17-2020 10:49 PM

While I'm not sure about the details of what you're working on, it looks like that's a token concatenation. Macros in c are based on tokens, not pieces of text like it may at first appear.


#define FOO(x, y) x##y
FOO(abc, def)

would be processed roughly as follows:

[FOO] ( [abc] , [def] )

The "##" acts to concatenate the two identifier tokens into a single identifier token. Essentially, the macro would turn something like:



static void [__my_cool_function] ( struct [pt_regs] * [regs] ) ;

instead of:

static void [__] [my_cool_function] ( struct [pt_regs] * [regs] ) ;

which would produce a compiler error.

GreyGnome 09-18-2020 06:35 PM

Thanks. I understand, from your example, that the square brackets are not inserted by the macro preprocessor? In other words, technically it would be

static void __my_cool_function ( struct pt_regs *regs ) ;

and not

static void [__my_cool_function] ( struct [pt_regs] * [regs] ) ;

...Or do I misunderstand?

powerboat9 09-19-2020 10:17 AM

Yeah, sorry. I was using square brackets to show identifier tokens ([abc] was an identifier token named "abc").

All times are GMT -5. The time now is 09:25 AM.