remove redundant pthread struct members repeated for layout purposes

dtv_copy, canary2, and canary_at_end existed solely to match multiple
ABI and asm-accessed layouts simultaneously. now that pthread_arch.h
can be included before struct __pthread is defined, the struct layout
can depend on macros defined by pthread_arch.h.
This commit is contained in:
Rich Felker 2020-08-24 22:45:51 -04:00
parent 3a5b9ae7cf
commit 57f6e85c9d
8 changed files with 19 additions and 18 deletions

View File

@ -14,5 +14,3 @@ static inline uintptr_t __get_tp()
// the kernel calls the ip "nip", it's the first saved value after the 32
// GPRs.
#define MC_PC gregs[32]
#define CANARY canary_at_end

View File

@ -14,5 +14,3 @@ static inline uintptr_t __get_tp()
// the kernel calls the ip "nip", it's the first saved value after the 32
// GPRs.
#define MC_PC gp_regs[32]
#define CANARY canary_at_end

View File

@ -7,6 +7,6 @@ static inline uintptr_t __get_tp()
#define MC_PC gregs[REG_RIP]
#define CANARY canary2
#define CANARY_PAD
#define tls_mod_off_t unsigned long long

View File

@ -1579,7 +1579,7 @@ static void install_new_tls(void)
/* Install new dtv for each thread. */
for (j=0, td=self; !j || td!=self; j++, td=td->next) {
td->dtv = td->dtv_copy = newdtv[j];
td->dtv = newdtv[j];
}
__tl_unlock();

View File

@ -67,7 +67,7 @@ void *__copy_tls(unsigned char *mem)
}
#endif
dtv[0] = libc.tls_cnt;
td->dtv = td->dtv_copy = dtv;
td->dtv = dtv;
return td;
}

View File

@ -9,7 +9,7 @@ void __init_ssp(void *entropy)
if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
__pthread_self()->CANARY = __stack_chk_guard;
__pthread_self()->canary = __stack_chk_guard;
}
void __stack_chk_fail(void)

View File

@ -11,16 +11,25 @@
#include "atomic.h"
#include "futex.h"
#include "pthread_arch.h"
#define pthread __pthread
struct pthread {
/* Part 1 -- these fields may be external or
* internal (accessed via asm) ABI. Do not change. */
struct pthread *self;
#ifndef TLS_ABOVE_TP
uintptr_t *dtv;
#endif
struct pthread *prev, *next; /* non-ABI */
uintptr_t sysinfo;
uintptr_t canary, canary2;
#ifndef TLS_ABOVE_TP
#ifdef CANARY_PAD
uintptr_t canary_pad;
#endif
uintptr_t canary;
#endif
/* Part 2 -- implementation details, non-ABI. */
int tid;
@ -52,8 +61,10 @@ struct pthread {
/* Part 3 -- the positions of these fields relative to
* the end of the structure is external and internal ABI. */
uintptr_t canary_at_end;
uintptr_t *dtv_copy;
#ifdef TLS_ABOVE_TP
uintptr_t canary;
uintptr_t *dtv;
#endif
};
enum {
@ -99,12 +110,6 @@ struct __timer {
#define _b_waiters2 __u.__vi[4]
#define _b_inst __u.__p[3]
#include "pthread_arch.h"
#ifndef CANARY
#define CANARY canary
#endif
#ifndef TP_OFFSET
#define TP_OFFSET 0
#endif

View File

@ -314,7 +314,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
new->detach_state = DT_JOINABLE;
}
new->robust_list.head = &new->robust_list.head;
new->CANARY = self->CANARY;
new->canary = self->canary;
new->sysinfo = self->sysinfo;
/* Setup argument structure for the new thread on its stack.