2012-11-09 22:36:55 +00:00
|
|
|
static inline struct pthread *__pthread_self()
|
|
|
|
{
|
2013-12-02 07:45:10 +00:00
|
|
|
#ifdef __clang__
|
|
|
|
char *tp;
|
|
|
|
__asm__ __volatile__ ("mr %0, 2" : "=r"(tp) : : );
|
|
|
|
#else
|
|
|
|
register char *tp __asm__("r2");
|
2015-10-15 16:08:51 +00:00
|
|
|
__asm__ __volatile__ ("" : "=r" (tp) );
|
2013-12-02 07:45:10 +00:00
|
|
|
#endif
|
2012-11-09 22:36:55 +00:00
|
|
|
return (pthread_t)(tp - 0x7000 - sizeof(struct pthread));
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TLS_ABOVE_TP
|
|
|
|
#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + 0x7000)
|
|
|
|
|
fix local-dynamic model TLS on mips and powerpc
the TLS ABI spec for mips, powerpc, and some other (presently
unsupported) RISC archs has the return value of __tls_get_addr offset
by +0x8000 and the result of DTPOFF relocations offset by -0x8000. I
had previously assumed this part of the ABI was actually just an
implementation detail, since the adjustments cancel out. however, when
the local dynamic model is used for accessing TLS that's known to be
in the same DSO, either of the following may happen:
1. the -0x8000 offset may already be applied to the argument structure
passed to __tls_get_addr at ld time, without any opportunity for
runtime relocations.
2. __tls_get_addr may be used with a zero offset argument to obtain a
base address for the module's TLS, to which the caller then applies
immediate offsets for individual objects accessed using the local
dynamic model. since the immediate offsets have the -0x8000 adjustment
applied to them, the base address they use needs to include the
+0x8000 offset.
it would be possible, but more complex, to store the pointers in the
dtv[] array with the +0x8000 offset pre-applied, to avoid the runtime
cost of adding 0x8000 on each call to __tls_get_addr. this change
could be made later if measurements show that it would help.
2015-06-25 22:22:00 +00:00
|
|
|
#define DTP_OFFSET 0x8000
|
|
|
|
|
2012-11-09 22:36:55 +00:00
|
|
|
// the kernel calls the ip "nip", it's the first saved value after the 32
|
|
|
|
// GPRs.
|
2015-11-02 17:39:28 +00:00
|
|
|
#define MC_PC gregs[32]
|
2012-11-09 22:36:55 +00:00
|
|
|
|
fix stack protector crashes on x32 & powerpc due to misplaced TLS canary
i386, x86_64, x32, and powerpc all use TLS for stack protector canary
values in the default stack protector ABI, but the location only
matched the ABI on i386 and x86_64. on x32, the expected location for
the canary contained the tid, thus producing spurious mismatches
(resulting in process termination) upon fork. on powerpc, the expected
location contained the stdio_locks list head, so returning from a
function after calling flockfile produced spurious mismatches. in both
cases, the random canary was not present, and a predictable value was
used instead, making the stack protector hardening much less effective
than it should be.
in the current fix, the thread structure has been expanded to have
canary fields at all three possible locations, and archs that use a
non-default location must define a macro in pthread_arch.h to choose
which location is used. for most archs (which lack TLS canary ABI) the
choice does not matter.
2015-05-06 22:37:19 +00:00
|
|
|
#define CANARY canary_at_end
|