2 * Copyright 2014, Paweł Dziepak, pdziepak@quarnos.org.
3 * Copyright 2012, Alex Smith, alex@alex-smith.me.uk.
4 * Distributed under the terms of the MIT License.
9 # define _NO_INLINE_ASM 1
14 #include <runtime_loader/runtime_loader.h>
16 #include <support/TLS.h>
23 unsigned long int module
;
24 unsigned long int offset
;
28 static std::atomic
<int> gNextSlot(TLS_FIRST_FREE_SLOT
);
35 __asm__
__volatile__ ("movq %%fs:0, %0" : "=r" (tls
));
43 if (gNextSlot
< TLS_MAX_KEYS
) {
44 auto next
= gNextSlot
++;
45 if (next
< TLS_MAX_KEYS
)
56 return get_tls()[index
];
61 tls_address(int32 index
)
63 return get_tls() + index
;
68 tls_set(int32 index
, void* value
)
70 get_tls()[index
] = value
;
75 __tls_get_addr(tls_index
* ti
)
77 return __gRuntimeLoader
->get_tls_address(ti
->module
, ti
->offset
);