Page MenuHomeFreeBSD

D21163.diff
No OneTemporary

D21163.diff

Index: head/libexec/rtld-elf/map_object.c
===================================================================
--- head/libexec/rtld-elf/map_object.c
+++ head/libexec/rtld-elf/map_object.c
@@ -313,6 +313,7 @@
obj->tlsindex = ++tls_max_index;
obj->tlssize = phtls->p_memsz;
obj->tlsalign = phtls->p_align;
+ obj->tlspoffset = phtls->p_offset;
obj->tlsinitsize = phtls->p_filesz;
obj->tlsinit = mapbase + phtls->p_vaddr;
}
Index: head/libexec/rtld-elf/rtld.h
===================================================================
--- head/libexec/rtld-elf/rtld.h
+++ head/libexec/rtld-elf/rtld.h
@@ -163,6 +163,7 @@
size_t tlssize; /* Size of TLS block for this module */
size_t tlsoffset; /* Offset of static TLS block for this module */
size_t tlsalign; /* Alignment of static TLS block */
+ size_t tlspoffset; /* p_offset of the static TLS block */
caddr_t relro_page;
size_t relro_size;
@@ -361,7 +362,7 @@
void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
char *xstrdup(const char *);
-void *malloc_aligned(size_t size, size_t align);
+void *malloc_aligned(size_t size, size_t align, size_t offset);
void free_aligned(void *ptr);
extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
extern Elf_Sym sym_zero; /* For resolving undefined weak refs. */
Index: head/libexec/rtld-elf/rtld.c
===================================================================
--- head/libexec/rtld-elf/rtld.c
+++ head/libexec/rtld-elf/rtld.c
@@ -1501,6 +1501,7 @@
obj->tlsalign = ph->p_align;
obj->tlsinitsize = ph->p_filesz;
obj->tlsinit = (void*)(ph->p_vaddr + obj->relocbase);
+ obj->tlspoffset = ph->p_offset;
break;
case PT_GNU_STACK:
@@ -4868,7 +4869,7 @@
Elf_Addr addr;
Elf_Addr i;
size_t extra_size, maxalign, post_size, pre_size, tls_block_size;
- size_t tls_init_align;
+ size_t tls_init_align, tls_init_offset;
if (oldtcb != NULL && tcbsize == TLS_TCB_SIZE)
return (oldtcb);
@@ -4885,7 +4886,7 @@
tls_block_size += pre_size + tls_static_space - TLS_TCB_SIZE - post_size;
/* Allocate whole TLS block */
- tls_block = malloc_aligned(tls_block_size, maxalign);
+ tls_block = malloc_aligned(tls_block_size, maxalign, 0);
tcb = (Elf_Addr **)(tls_block + pre_size + extra_size);
if (oldtcb != NULL) {
@@ -4909,15 +4910,21 @@
for (obj = globallist_curr(objs); obj != NULL;
obj = globallist_next(obj)) {
- if (obj->tlsoffset > 0) {
- addr = (Elf_Addr)tcb + obj->tlsoffset;
- if (obj->tlsinitsize > 0)
- memcpy((void*) addr, obj->tlsinit, obj->tlsinitsize);
- if (obj->tlssize > obj->tlsinitsize)
- memset((void*)(addr + obj->tlsinitsize), 0,
- obj->tlssize - obj->tlsinitsize);
- dtv[obj->tlsindex + 1] = addr;
+ if (obj->tlsoffset == 0)
+ continue;
+ tls_init_offset = obj->tlspoffset & (obj->tlsalign - 1);
+ addr = (Elf_Addr)tcb + obj->tlsoffset;
+ if (tls_init_offset > 0)
+ memset((void *)addr, 0, tls_init_offset);
+ if (obj->tlsinitsize > 0) {
+ memcpy((void *)(addr + tls_init_offset), obj->tlsinit,
+ obj->tlsinitsize);
}
+ if (obj->tlssize > obj->tlsinitsize) {
+ memset((void *)(addr + tls_init_offset + obj->tlsinitsize),
+ 0, obj->tlssize - obj->tlsinitsize - tls_init_offset);
+ }
+ dtv[obj->tlsindex + 1] = addr;
}
}
@@ -4975,7 +4982,7 @@
size = round(tls_static_space, ralign) + round(tcbsize, ralign);
assert(tcbsize >= 2*sizeof(Elf_Addr));
- tls = malloc_aligned(size, ralign);
+ tls = malloc_aligned(size, ralign, 0 /* XXX */);
dtv = xcalloc(tls_max_index + 2, sizeof(Elf_Addr));
segbase = (Elf_Addr)(tls + round(tls_static_space, ralign));
@@ -5068,25 +5075,24 @@
void *
allocate_module_tls(int index)
{
- Obj_Entry* obj;
- char* p;
+ Obj_Entry *obj;
+ char *p;
- TAILQ_FOREACH(obj, &obj_list, next) {
- if (obj->marker)
- continue;
- if (obj->tlsindex == index)
- break;
- }
- if (!obj) {
- _rtld_error("Can't find module with TLS index %d", index);
- rtld_die();
- }
+ TAILQ_FOREACH(obj, &obj_list, next) {
+ if (obj->marker)
+ continue;
+ if (obj->tlsindex == index)
+ break;
+ }
+ if (obj == NULL) {
+ _rtld_error("Can't find module with TLS index %d", index);
+ rtld_die();
+ }
- p = malloc_aligned(obj->tlssize, obj->tlsalign);
- memcpy(p, obj->tlsinit, obj->tlsinitsize);
- memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize);
-
- return p;
+ p = malloc_aligned(obj->tlssize, obj->tlsalign, obj->tlspoffset);
+ memcpy(p, obj->tlsinit, obj->tlsinitsize);
+ memset(p + obj->tlsinitsize, 0, obj->tlssize - obj->tlsinitsize);
+ return (p);
}
bool
Index: head/libexec/rtld-elf/xmalloc.c
===================================================================
--- head/libexec/rtld-elf/xmalloc.c
+++ head/libexec/rtld-elf/xmalloc.c
@@ -27,6 +27,7 @@
* $FreeBSD$
*/
+#include <sys/param.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
@@ -76,16 +77,21 @@
}
void *
-malloc_aligned(size_t size, size_t align)
+malloc_aligned(size_t size, size_t align, size_t offset)
{
- void *mem, *res;
+ char *mem, *res;
+ uintptr_t x;
+ offset &= align - 1;
if (align < sizeof(void *))
align = sizeof(void *);
- mem = xmalloc(size + sizeof(void *) + align - 1);
- res = (void *)round((uintptr_t)mem + sizeof(void *), align);
- *(void **)((uintptr_t)res - sizeof(void *)) = mem;
+ mem = xmalloc(size + 3 * align + offset);
+ x = roundup((uintptr_t)mem + sizeof(void *), align);
+ x += offset;
+ res = (void *)x;
+ x -= sizeof(void *);
+ memcpy((void *)x, &mem, sizeof(mem));
return (res);
}
@@ -99,6 +105,6 @@
return;
x = (uintptr_t)ptr;
x -= sizeof(void *);
- mem = *(void **)x;
+ memcpy(&mem, (void *)x, sizeof(mem));
free(mem);
}

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 10, 4:18 PM (4 h, 40 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16580036
Default Alt Text
D21163.diff (5 KB)

Event Timeline