From 1fad513bbc7fd4cfb911a7e8b6bf217dc31f2606 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 14 Apr 2005 00:04:50 +0000 Subject: Attempt to use i386_set_gsbase(), and gracefully fall back to LDT methods if the direct access methods are not implemented. --- libexec/rtld-elf/i386/reloc.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/libexec/rtld-elf/i386/reloc.c b/libexec/rtld-elf/i386/reloc.c index 58cd38a..846b643 100644 --- a/libexec/rtld-elf/i386/reloc.c +++ b/libexec/rtld-elf/i386/reloc.c @@ -329,7 +329,7 @@ allocate_initial_tls(Obj_Entry *objs) void* tls; #ifndef COMPAT_32BIT union descriptor ldt; - int sel; + int error, sel; #endif /* @@ -341,18 +341,21 @@ allocate_initial_tls(Obj_Entry *objs) tls = allocate_tls(objs, NULL, 2*sizeof(Elf_Addr), sizeof(Elf_Addr)); #ifndef COMPAT_32BIT - memset(&ldt, 0, sizeof(ldt)); - ldt.sd.sd_lolimit = 0xffff; /* 4G limit */ - ldt.sd.sd_lobase = ((Elf_Addr)tls) & 0xffffff; - ldt.sd.sd_type = SDT_MEMRWA; - ldt.sd.sd_dpl = SEL_UPL; - ldt.sd.sd_p = 1; /* present */ - ldt.sd.sd_hilimit = 0xf; /* 4G limit */ - ldt.sd.sd_def32 = 1; /* 32 bit */ - ldt.sd.sd_gran = 1; /* limit in pages */ - ldt.sd.sd_hibase = (((Elf_Addr)tls) >> 24) & 0xff; - sel = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1); - __asm __volatile("movl %0,%%gs" : : "rm" ((sel << 3) | 7)); + error = i386_set_gsbase(tls); + if (error) { + memset(&ldt, 0, sizeof(ldt)); + ldt.sd.sd_lolimit = 0xffff; /* 4G limit */ + ldt.sd.sd_lobase = ((Elf_Addr)tls) & 0xffffff; + ldt.sd.sd_type = SDT_MEMRWA; + ldt.sd.sd_dpl = SEL_UPL; + ldt.sd.sd_p = 1; /* present */ + ldt.sd.sd_hilimit = 0xf; /* 4G limit */ + ldt.sd.sd_def32 = 1; /* 32 bit */ + ldt.sd.sd_gran = 1; /* limit in pages */ + ldt.sd.sd_hibase = (((Elf_Addr)tls) >> 24) & 0xff; + sel = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1); + __asm __volatile("movl %0,%%gs" : : "rm" ((sel << 3) | 7)); + } #else _amd64_set_gsbase(tls); #endif -- cgit v1.1