Segment based referencing in c

Programming, for all ages and all languages.
Post Reply
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Segment based referencing in c

Post by thomasloven »

Some xv6 code mirrors have the following line:

Code: Select all

extern struct cpu *cpu asm("%gs:0");
[github]

This is a hack using the assembly label attribute available in some compilers which works by accident rather than by design - if at all.

However, having a simple way of automatically referencing an offset from fs/gs is damn convenient, and having it be a variable rather than a function carries a measure of elegance.

Can the same thing somehow be be done The Right Way™?
thomasloven
Member
Member
Posts: 89
Joined: Tue Feb 26, 2008 10:47 am
Location: Sweden

Re: Segment based referencing in c

Post by thomasloven »

Works like a charm! Thank you!
Post Reply