DragonFly BSD
DragonFly kernel List (threaded) for 2004-04
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: nvidia machdep.c patch still useful ?


From: David Cuthbert <dacut@xxxxxxxxx>
Date: Wed, 07 Apr 2004 03:13:50 -0400

Matthew Dillon wrote:
    %fs cannot be set to anything useful by userland, at least I don't
    think it can.  %gs can be set to a user-defined custom segment.

My kernel's not quite up-to-date, but the snippet below successfully queries and sets %fs.


I'm fairly certain that setting any i386 segment register (except %cs) is a non-privileged instruction. Of course, the descriptor must support the appropriate access to actually *use* it...

---

#include <stdio.h>

unsigned short get_fs(void)
{
    unsigned short result;
    __asm__("movw %%fs, %0" : "=r" (result));
    return result;
}

void set_fs(unsigned short value)
{
    __asm__("movw %0, %%fs" : : "r" (value));
    return;
}


int main() { printf("fs is %d\n", get_fs()); set_fs(0); printf("fs is %d\n", get_fs());

    return 0;
}



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]