diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 2140d7a02845..1e28aa9bd12d 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -121,6 +121,9 @@ __FBSDID("$FreeBSD$"); #include #include +/* Sanity check for __curthread() */ +CTASSERT(offsetof(struct pcpu, pc_curthread) == 0); + extern u_int64_t hammer_time(u_int64_t, u_int64_t); extern void dblfault_handler(void); diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index 9e0383a8f0a7..b96221b473da 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -159,6 +159,16 @@ extern struct pcpu *pcpup; #define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) #define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) +static __inline struct thread * +__curthread(void) +{ + struct thread *td; + + __asm __volatile("movq %%gs:0,%0" : "=r" (td)); + return (td); +} +#define Xurthread (__curthread()) + #else #error gcc or lint is required to use this file #endif