xref: /haiku/src/system/libroot/os/arch/m68k/tls.c (revision 68ea01249e1e2088933cb12f9c28d4e5c5d1c9ef)
1 /*
2 ** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
3 ** Distributed under the terms of the MIT License.
4 */
5 
6 // ToDo: this is a dummy implementation - I've not yet gained enough knowledge
7 //	to decide how this should be done, so it's just broken now (okay for single
8 //	threaded apps, though).
9 
10 #warning FIXME: M68K
11 
12 // we don't want to have the inline assembly included here
13 #ifndef _NO_INLINE_ASM
14 #	define _NO_INLINE_ASM 1
15 #endif
16 
17 #include <runtime_loader/runtime_loader.h>
18 
19 #include "support/TLS.h"
20 #include "tls.h"
21 
22 
23 static int32 gNextSlot = TLS_FIRST_FREE_SLOT;
24 static void *gSlots[TLS_MAX_KEYS];
25 
26 struct tls_index {
27 	unsigned long int	module;
28 	unsigned long int	offset;
29 };
30 
31 void* __tls_get_addr(struct tls_index* ti);
32 
33 
34 int32
35 tls_allocate(void)
36 {
37 	int32 next = atomic_add(&gNextSlot, 1);
38 	if (next >= TLS_MAX_KEYS)
39 		return B_NO_MEMORY;
40 
41 	return next;
42 }
43 
44 
45 void *
46 tls_get(int32 index)
47 {
48 	return gSlots[index];
49 }
50 
51 
52 void **
53 tls_address(int32 index)
54 {
55 	return &gSlots[index];
56 }
57 
58 
59 void
60 tls_set(int32 index, void *value)
61 {
62 	gSlots[index] = value;
63 }
64 
65 void*
66 __tls_get_addr(struct tls_index* ti)
67 {
68 	return __gRuntimeLoader->get_tls_address(ti->module, ti->offset);
69 }
70 
71