Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_THIS_IP_ macro in linux kernel

Tags:

c

linux-kernel

The following macro appears in include/linux/kernel.h

#define _THIS_IP_  ({ __label__ __here; __here: (unsigned long)&&__here; })

I don't understand what the second & applied to __here would do. The first takes the address of the local label, but what about the second?

like image 990
mk_ Avatar asked Jan 14 '23 18:01

mk_


2 Answers

The second & in && is necessary to make GCC lookup the name as a label, instead of as a variable. For example

foo: ;
int foo;

void *p1 = &&foo;
void *p2 = &foo;

The second initializer refers to the int variable.

like image 135
Johannes Schaub - litb Avatar answered Jan 23 '23 06:01

Johannes Schaub - litb


I think && is to get the address of label.

this is gcc extention and I don't think C99 standard supports this behavior.

for more see this.. gcc Labels and values

And local label declaration

In your case ,

#define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })

In actual code _THIS_IP_ will be replaced by the code below of block scope

{ __label__ __here;
 __here: 
(unsigned long) &&__here; 
}

You are declaring local label __here . Hence to get the address of label we use && while we get the address of variable with single &.

like image 30
Omkant Avatar answered Jan 23 '23 05:01

Omkant