1 module rtoslink;
2 
3 pragma(LDC_no_moduleinfo);
4 
5 /++
6 These are the basic hooks to be implemented in C/C++ land. LWDR will call
7 these hooks depending on what is requested of the runtime by user code.
8 ++/
9 
10 @disable ubyte[] internal_heapalloc(uint sz) pure @nogc nothrow {
11 	return cast(ubyte[])(rtosbackend_heapalloc(sz)[0..sz]);
12 }
13 
14 @nogc nothrow pure extern(C) {
15 	/// Called when LWDR requests heap memory
16 	void* rtosbackend_heapalloc(uint sz);
17 	/// Called when LWDR wants to free heap memory
18 	void rtosbackend_heapfreealloc(void* ptr);
19 
20 	/// Called when a D array is access incorrectly.
21 	void rtosbackend_arrayBoundFailure(string file, uint line);
22 	/// Called when assert(bool exp) fails.
23 	void rtosbackend_assert(string file, uint line);
24 	/// Called when assert(bool exp, string msg) fails.
25 	void rtosbackend_assertmsg(string msg, string file, uint line);
26 
27 	/// Set pointer at index in the current thread's TCB (Thread Control Block)
28 	void rtosbackend_setTLSPointerCurrThread(void* ptr, int index);
29 	/// Get pointer at index in the current thread's TCB (Thread Control Block)
30 	void* rtosbackend_getTLSPointerCurrThread(int index);
31 
32 	/// Called when LWDR cannot allocate
33 	void rtosbackend_outOfMemory();
34 
35 	/// Called when LWDR wishes to terminate prematurely.
36 	void rtosbackend_terminate();
37 
38 	version(LWDR_Sync)
39 	{
40 		/// Called when LWDR wants to create a mutex.
41 		void* rtosbackend_mutexInit();
42 		/// Called when LWDR wants to destroy a mutex.
43 		void rtosbackend_mutexDestroy(void*);
44 		/// LWDR wants to lock a mutex (eg, via synchronized).
45 		void rtosbackend_mutexLock(void*);
46 		/// LWDR wants to unlock a mutex (eg, via synchronized).
47 		void rtosbackend_mutexUnlock(void*);
48 		/// Attempt to lock a mutex. Returns 0 if couldn't, 1 if locked.
49 		int rtosbackend_mutexTryLock(void*);
50 		/// LWDR stores a single, global mutex for its own implementation. This function creates it. Called on runtime start.
51 		void* rtosbackend_globalMutexInit();
52 		/// Destroy LWDR's global mutex. Called on runtime shutdown.
53 		void rtosbackend_globalMutexDestroy(void*);
54 	}
55 }