Use internal stdint and stddef

This changes sel4runtime to use the internal minimal stdint and stddef
removing the dependency for those files from an external libc.

This also removes the imports and dependencies for stdbool, string, and
assert.

Signed-off-by: Curtis Millar <curtis@curtism.me>
diff --git a/include/arch/riscv/sel4runtime/thread_arch.h b/include/arch/riscv/sel4runtime/thread_arch.h
index df19e92..338da10 100644
--- a/include/arch/riscv/sel4runtime/thread_arch.h
+++ b/include/arch/riscv/sel4runtime/thread_arch.h
@@ -9,20 +9,20 @@
  *
  * @TAG(DATA61_BSD)
  */
-#include <stdint.h>
+#include <sel4runtime/stdint.h>
 
-static inline uintptr_t sel4runtime_read_tp(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_tp(void)
 {
 #ifdef __clang__
-    uintptr_t reg;
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__("or %0, tp, x0" : "=r"(reg));
 #else
-    register uintptr_t reg __asm__("tp");
+    register sel4runtime_uintptr_t reg __asm__("tp");
 #endif
     return reg;
 }
 
-static inline void sel4runtime_write_tp(uintptr_t reg)
+static inline void sel4runtime_write_tp(sel4runtime_uintptr_t reg)
 {
     __asm__ __volatile__("or tp, %0, x0" :: "r"(reg));
 }
@@ -30,7 +30,7 @@
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void)
 {
     return sel4runtime_read_tp();
 }
@@ -38,7 +38,7 @@
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     sel4runtime_write_tp(tls_base);
 }
diff --git a/include/sel4_arch/aarch32/sel4runtime/thread_arch.h b/include/sel4_arch/aarch32/sel4runtime/thread_arch.h
index f5daf70..edf853a 100644
--- a/include/sel4_arch/aarch32/sel4runtime/thread_arch.h
+++ b/include/sel4_arch/aarch32/sel4runtime/thread_arch.h
@@ -11,26 +11,26 @@
  */
 #include <autoconf.h>
 #include <sel4/arch/constants.h>
-#include <stdint.h>
+#include <sel4runtime/stdint.h>
 
 #if ((__ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
  || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
 
-static inline uintptr_t sel4runtime_read_tpidr_el0(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidr_el0(void)
 {
-    uintptr_t reg;
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__("mrc p15,0,%0,c13,c0,2" : "=r"(reg));
     return reg;
 }
 
-static inline void sel4runtime_write_tpidr_el0(uintptr_t reg)
+static inline void sel4runtime_write_tpidr_el0(sel4runtime_uintptr_t reg)
 {
     __asm__ __volatile__("mcr p15,0,%0,c13,c0,2" :: "r"(reg));
 }
 
-static inline uintptr_t sel4runtime_read_tpidrro_el0(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidrro_el0(void)
 {
-    uintptr_t reg;
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__("mrc p15,0,%0,c13,c0,3" : "=r"(reg));
     return reg;
 }
@@ -38,7 +38,7 @@
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     sel4runtime_write_tpidr_el0(tls_base);
 }
@@ -53,23 +53,23 @@
  * spaces. The IPC buffer and thread pointer occupy the first two words
  * in this frame respectively.
  */
-static inline uintptr_t sel4runtime_read_tpidr_el0(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidr_el0(void)
 {
     void **globals_frame = (void **)seL4_GlobalsFrame;
-    return (uintptr_t)globals_frame[0];
+    return (sel4runtime_uintptr_t)globals_frame[0];
 }
 
-static inline uintptr_t sel4runtime_read_tpidrro_el0(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidrro_el0(void)
 {
     void **globals_frame = (void **)seL4_GlobalsFrame;
-    return (uintptr_t)globals_frame[1];
+    return (sel4runtime_uintptr_t)globals_frame[1];
 }
 
 #ifdef CONFIG_SET_TLS_BASE_SELF
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     seL4_SetTLSBase(tls_base);
 }
@@ -81,7 +81,7 @@
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void)
 {
     return sel4runtime_read_tpidr_el0();
 }
diff --git a/include/sel4_arch/aarch64/sel4runtime/thread_arch.h b/include/sel4_arch/aarch64/sel4runtime/thread_arch.h
index e19a3f4..615f466 100644
--- a/include/sel4_arch/aarch64/sel4runtime/thread_arch.h
+++ b/include/sel4_arch/aarch64/sel4runtime/thread_arch.h
@@ -9,23 +9,23 @@
  *
  * @TAG(DATA61_BSD)
  */
-#include <stdint.h>
+#include <sel4runtime/stdint.h>
 
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_read_tpidr_el0(void) {
-    uintptr_t reg;
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidr_el0(void) {
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__ ("mrs %0,tpidr_el0" : "=r"(reg));
     return reg;
 }
 
-static inline void sel4runtime_write_tpidr_el0(uintptr_t reg) {
+static inline void sel4runtime_write_tpidr_el0(sel4runtime_uintptr_t reg) {
     __asm__ __volatile__ ("msr tpidr_el0,%0" :: "r"(reg));
 }
 
-static inline uintptr_t sel4runtime_read_tpidrro_el0(void) {
-    uintptr_t reg;
+static inline sel4runtime_uintptr_t sel4runtime_read_tpidrro_el0(void) {
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__ ("mrs %0,tpidrro_el0" : "=r"(reg));
     return reg;
 }
@@ -33,14 +33,14 @@
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void) {
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void) {
     return sel4runtime_read_tpidr_el0();
 }
 
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base) {
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base) {
     sel4runtime_write_tpidr_el0(tls_base);
 }
 
diff --git a/include/sel4_arch/ia32/sel4runtime/thread_arch.h b/include/sel4_arch/ia32/sel4runtime/thread_arch.h
index 02d638f..9f8cf49 100644
--- a/include/sel4_arch/ia32/sel4runtime/thread_arch.h
+++ b/include/sel4_arch/ia32/sel4runtime/thread_arch.h
@@ -10,14 +10,14 @@
  * @TAG(DATA61_BSD)
  */
 #include <autoconf.h>
-#include <stdint.h>
+#include <sel4runtime/stdint.h>
 
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void)
 {
-    uintptr_t tp;
+    sel4runtime_uintptr_t tp;
     __asm__ __volatile__("movl %%gs:0,%0" : "=r"(tp));
     return tp;
 }
@@ -26,7 +26,7 @@
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     seL4_SetTLSBase(tls_base);
 }
diff --git a/include/sel4_arch/x86_64/sel4runtime/thread_arch.h b/include/sel4_arch/x86_64/sel4runtime/thread_arch.h
index c21bfdd..bc31db2 100644
--- a/include/sel4_arch/x86_64/sel4runtime/thread_arch.h
+++ b/include/sel4_arch/x86_64/sel4runtime/thread_arch.h
@@ -10,29 +10,29 @@
  * @TAG(DATA61_BSD)
  */
 #include <autoconf.h>
-#include <stdint.h>
+#include <sel4runtime/stdint.h>
 
 #ifdef CONFIG_FSGSBASE_INST
-static inline uintptr_t sel4runtime_read_fs_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_fs_base(void)
 {
-    uintptr_t reg;
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__("rdfsbase %0" : "=r"(reg));
     return reg;
 }
 
-static inline void sel4runtime_write_fs_base(uintptr_t reg)
+static inline void sel4runtime_write_fs_base(sel4runtime_uintptr_t reg)
 {
     __asm__ __volatile__("wrfsbase %0" :: "r"(reg));
 }
 
-static inline uintptr_t sel4runtime_read_gs_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_read_gs_base(void)
 {
-    uintptr_t reg;
+    sel4runtime_uintptr_t reg;
     __asm__ __volatile__("rdgsbase %0" : "=r"(reg));
     return reg;
 }
 
-static inline void sel4runtime_write_gs_base(uintptr_t reg)
+static inline void sel4runtime_write_gs_base(sel4runtime_uintptr_t reg)
 {
     __asm__ __volatile__("wrgsbase %0" :: "r"(reg));
 }
@@ -40,7 +40,7 @@
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void)
 {
     return sel4runtime_read_fs_base();
 }
@@ -48,7 +48,7 @@
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     sel4runtime_write_fs_base(tls_base);
 }
@@ -58,9 +58,9 @@
 /*
  * Obtain the value of the TLS base for the current thread.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void)
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void)
 {
-    uintptr_t tp;
+    sel4runtime_uintptr_t tp;
     __asm__ __volatile__("mov %%fs:0,%0" : "=r"(tp));
     return tp;
 }
@@ -69,7 +69,7 @@
 /*
  * Set the value of the TLS base for the current thread.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base)
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base)
 {
     seL4_SetTLSBase(tls_base);
 }
diff --git a/include/sel4runtime.h b/include/sel4runtime.h
index 9ff1f2e..4abaf09 100644
--- a/include/sel4runtime.h
+++ b/include/sel4runtime.h
@@ -14,8 +14,8 @@
  *
  * This provides an interface to the values managed by sel4runtime.
  */
-#include <stddef.h>
-#include <stdint.h>
+#include <sel4runtime/stddef.h>
+#include <sel4runtime/stdint.h>
 #include <sel4/sel4.h>
 #include <sel4runtime/thread.h>
 #include <sel4runtime/auxv.h>
@@ -52,12 +52,12 @@
 /*
  * Get the address of the TLS base register.
  */
-static inline uintptr_t sel4runtime_get_tls_base(void);
+static inline sel4runtime_uintptr_t sel4runtime_get_tls_base(void);
 
 /*
  * Set the address of the TLS base register.
  */
-static inline void sel4runtime_set_tls_base(uintptr_t tls_base);
+static inline void sel4runtime_set_tls_base(sel4runtime_uintptr_t tls_base);
 
 /*
  * Get the bootinfo pointer if the process was provided a bootinfo
@@ -68,13 +68,13 @@
 /*
  * Get the size in bytes needed to store the thread's TLS.
  */
-size_t sel4runtime_get_tls_size(void);
+sel4runtime_size_t sel4runtime_get_tls_size(void);
 
 /*
  * Get the offset used to calculate the thread pointer from the
  * starting address of the thread area.
  */
-size_t sel4runtime_get_tp_offset(void);
+sel4runtime_size_t sel4runtime_get_tp_offset(void);
 
 /*
  * Check if the TLS for the initial thread is enabled.
@@ -93,7 +93,7 @@
  * @returns the pointer to the TLS that should be used to call
  *          seL4_TCB_SetTLSBase or NULL on error.
  */
-uintptr_t sel4runtime_write_tls_image(void *tls_memory);
+sel4runtime_uintptr_t sel4runtime_write_tls_image(void *tls_memory);
 
 /*
  * Move the TLS for the current thread into a new memory location.
@@ -109,7 +109,7 @@
  * @returns the pointer to the TLS that should be used to call
  *          seL4_TCB_SetTLSBase.
  */
-uintptr_t sel4runtime_move_initial_tls(void *tls_memory);
+sel4runtime_uintptr_t sel4runtime_move_initial_tls(void *tls_memory);
 
 /*
  * Writes into a thread_local variable of another thread.
@@ -136,10 +136,10 @@
  * This assumes that TLS has been initialised for the current thread.
  */
 int __sel4runtime_write_tls_variable(
-    uintptr_t dest_tls_base,
+    sel4runtime_uintptr_t dest_tls_base,
     unsigned char *local_tls_dest,
     unsigned char *src,
-    size_t bytes
+    sel4runtime_size_t bytes
 );
 
 /*
diff --git a/src/crt1.c b/src/crt1.c
index 695bcf0..62109c6 100644
--- a/src/crt1.c
+++ b/src/crt1.c
@@ -38,7 +38,7 @@
     // The environment pointer vector follows after the argv.
     char const *const *envp = &argv[argc + 1];
     int envc = 0;
-    while (envp[envc] != NULL) {
+    while (envp[envc] != SEL4RUNTIME_NULL) {
         envc++;
     }
 
diff --git a/src/env.c b/src/env.c
index 0397f51..16124fb 100644
--- a/src/env.c
+++ b/src/env.c
@@ -9,9 +9,6 @@
  *
  * @TAG(DATA61_BSD)
  */
-#include <assert.h>
-#include <stdbool.h>
-#include <string.h>
 #include <sel4runtime.h>
 #include <sel4runtime/auxv.h>
 #include <sel4runtime/mode/elf.h>
@@ -28,14 +25,14 @@
 #define MIN_ALIGNED __attribute__((aligned (MIN_ALIGN_BYTES)))
 
 // Global vsyscall handler (defined in musllibc)
-extern size_t __sysinfo;
+extern sel4runtime_size_t __sysinfo;
 
 // Static TLS for initial thread.
 static char static_tls[CONFIG_SEL4RUNTIME_STATIC_TLS] MIN_ALIGNED = {};
 
 // Thread lookup pointers.
 typedef struct {
-    uintptr_t tls_base;
+    sel4runtime_uintptr_t tls_base;
 } thread_lookup_t;
 
 // The seL4 runtime environment.
@@ -53,14 +50,14 @@
      * Once the TLS has been initialised for the first thread, this is
      * then set to NULL and the thread local reference should be used.
      */
-    uintptr_t initial_thread_tls_base;
+    sel4runtime_uintptr_t initial_thread_tls_base;
     seL4_CPtr initial_thread_tcb;
     seL4_IPCBuffer *initial_thread_ipc_buffer;
 
     // ELF Headers
     struct {
-        size_t count;
-        size_t size;
+        sel4runtime_size_t count;
+        sel4runtime_size_t size;
         Elf_Phdr *headers;
     } program_header;
 
@@ -69,15 +66,15 @@
         // The location of the initial image in memory.
         void *image;
         // The size of the initial image in memory.
-        size_t image_size;
+        sel4runtime_size_t image_size;
         // The size needed to store the full TLS.
-        size_t memory_size;
+        sel4runtime_size_t memory_size;
         // The size needed to store the TLS and the thread structure.
-        size_t region_size;
+        sel4runtime_size_t region_size;
         // Alignment needed for the TLS data.
-        size_t align;
+        sel4runtime_size_t align;
         // Offset of the TLS data from the thread pointer.
-        size_t offset;
+        sel4runtime_size_t offset;
     } tls;
 
     // Argument vector
@@ -98,7 +95,7 @@
      * Initialise the initial thread as referring to the global thread
      * object.
      */
-    .initial_thread_tls_base = (uintptr_t)NULL,
+    .initial_thread_tls_base = (sel4runtime_uintptr_t)SEL4RUNTIME_NULL,
 };
 
 static void name_process(char const *name);
@@ -107,13 +104,13 @@
 static void load_tls_data(Elf_Phdr *header);
 static void try_init_static_tls(void);
 static void copy_tls_data(unsigned char *tls);
-static uintptr_t tls_base_from_tls_region(unsigned char *tls_region);
-static unsigned char *tls_from_tls_base(uintptr_t tls_base);
+static sel4runtime_uintptr_t tls_base_from_tls_region(unsigned char *tls_region);
+static unsigned char *tls_from_tls_base(sel4runtime_uintptr_t tls_base);
 static unsigned char *tls_from_tls_region(unsigned char *tls_region);
 static thread_lookup_t *thread_lookup_from_tls_region(unsigned char *tls_region);
-static const size_t tls_region_size(size_t mem_size, size_t align);
+static const sel4runtime_size_t tls_region_size(sel4runtime_size_t mem_size, sel4runtime_size_t align);
 static void empty_tls(void);
-static bool is_initial_thread(void);
+static int is_initial_thread(void);
 
 char const *sel4runtime_process_name(void)
 {
@@ -145,7 +142,7 @@
     return env.bootinfo;
 }
 
-size_t sel4runtime_get_tls_size(void)
+sel4runtime_size_t sel4runtime_get_tls_size(void)
 {
     return env.tls.region_size;
 }
@@ -157,13 +154,13 @@
      * object in the TLS will be used rather than the static thread
      * object.
      */
-    return env.initial_thread_tls_base != (uintptr_t)NULL;
+    return env.initial_thread_tls_base != (sel4runtime_uintptr_t)SEL4RUNTIME_NULL;
 }
 
-uintptr_t sel4runtime_write_tls_image(void *tls_memory)
+sel4runtime_uintptr_t sel4runtime_write_tls_image(void *tls_memory)
 {
-    if (tls_memory == NULL) {
-        return (uintptr_t)NULL;
+    if (tls_memory == SEL4RUNTIME_NULL) {
+        return (sel4runtime_uintptr_t)SEL4RUNTIME_NULL;
     }
 
     copy_tls_data(tls_memory);
@@ -171,20 +168,20 @@
     return tls_base_from_tls_region(tls_memory);
 }
 
-uintptr_t sel4runtime_move_initial_tls(void *tls_memory)
+sel4runtime_uintptr_t sel4runtime_move_initial_tls(void *tls_memory)
 {
-    if (tls_memory == NULL) {
-        return (uintptr_t)NULL;
+    if (tls_memory == SEL4RUNTIME_NULL) {
+        return (sel4runtime_uintptr_t)SEL4RUNTIME_NULL;
     }
 
-    uintptr_t tls_base = sel4runtime_write_tls_image(tls_memory);
-    if (tls_base == (uintptr_t)NULL) {
-        return (uintptr_t)NULL;
+    sel4runtime_uintptr_t tls_base = sel4runtime_write_tls_image(tls_memory);
+    if (tls_base == (sel4runtime_uintptr_t)SEL4RUNTIME_NULL) {
+        return (sel4runtime_uintptr_t)SEL4RUNTIME_NULL;
     }
 
     sel4runtime_set_tls_base(tls_base);
 
-    if (env.initial_thread_ipc_buffer != NULL) {
+    if (env.initial_thread_ipc_buffer != SEL4RUNTIME_NULL) {
         __sel4_ipc_buffer = env.initial_thread_ipc_buffer;
     }
 
@@ -217,7 +214,7 @@
 
 void sel4runtime_exit(int code)
 {
-    if (env.pre_exit_cb != NULL) {
+    if (env.pre_exit_cb != SEL4RUNTIME_NULL) {
         code = env.pre_exit_cb(code);
     }
 
@@ -231,16 +228,16 @@
 }
 
 int __sel4runtime_write_tls_variable(
-    uintptr_t dest_tls_base,
+    sel4runtime_uintptr_t dest_tls_base,
     unsigned char *local_tls_dest,
     unsigned char *src,
-    size_t bytes
+    sel4runtime_size_t bytes
 )
 {
-    uintptr_t local_tls_base = sel4runtime_get_tls_base();
+    sel4runtime_uintptr_t local_tls_base = sel4runtime_get_tls_base();
     unsigned char *local_tls = tls_from_tls_base(local_tls_base);
-    size_t offset = local_tls_dest - local_tls;
-    size_t tls_size = env.tls.memory_size;
+    sel4runtime_size_t offset = local_tls_dest - local_tls;
+    sel4runtime_size_t tls_size = env.tls.memory_size;
 
     // Write must not go past end of TLS.
     if (offset > tls_size || offset + bytes > tls_size) {
@@ -308,12 +305,12 @@
             break;
         }
         case AT_SYSINFO: {
-            __sysinfo = (size_t)(auxv[i].a_un.a_ptr);
+            __sysinfo = (sel4runtime_size_t)(auxv[i].a_un.a_ptr);
             break;
         }
         case AT_SEL4_BOOT_INFO: {
             seL4_BootInfo *bootinfo = auxv[i].a_un.a_ptr;
-            if (bootinfo == NULL) {
+            if (bootinfo == SEL4RUNTIME_NULL) {
                 break;
             }
             env.bootinfo = bootinfo;
@@ -337,7 +334,7 @@
 
 static void parse_phdrs(void)
 {
-    for (size_t h = 0; h < env.program_header.count; h++) {
+    for (sel4runtime_size_t h = 0; h < env.program_header.count; h++) {
         Elf_Phdr *header = &env.program_header.headers[h];
         switch (header->p_type) {
         case PT_TLS:
@@ -380,23 +377,23 @@
     __sel4runtime_memset(tbss, 0, env.tls.memory_size - env.tls.image_size);
 
     thread_lookup_t *lookup = thread_lookup_from_tls_region(tls_region);
-    if (lookup != NULL) {
+    if (lookup != SEL4RUNTIME_NULL) {
         lookup->tls_base = tls_base_from_tls_region(tls_region);
     }
 }
 
-static uintptr_t tls_base_from_tls_region(unsigned char *tls_region)
+static sel4runtime_uintptr_t tls_base_from_tls_region(unsigned char *tls_region)
 {
-    uintptr_t tls_base = (uintptr_t)tls_region;
+    sel4runtime_uintptr_t tls_base = (sel4runtime_uintptr_t)tls_region;
 #if !defined(TLS_ABOVE_TP)
     tls_base += env.tls.memory_size;
 #endif
     return ROUND_UP(tls_base, env.tls.align);
 }
 
-static unsigned char *tls_from_tls_base(uintptr_t tls_base)
+static unsigned char *tls_from_tls_base(sel4runtime_uintptr_t tls_base)
 {
-    uintptr_t tls_addr = tls_base;
+    sel4runtime_uintptr_t tls_addr = tls_base;
 #if !defined(TLS_ABOVE_TP)
     tls_addr -= env.tls.memory_size;
 #endif
@@ -418,11 +415,11 @@
 #if !defined(TLS_ABOVE_TP)
     return (thread_lookup_t *)tls_base_from_tls_region(tls_region);
 #else
-    return NULL;
+    return SEL4RUNTIME_NULL;
 #endif
 }
 
-static const size_t tls_region_size(size_t mem_size, size_t align)
+static const sel4runtime_size_t tls_region_size(sel4runtime_size_t mem_size, sel4runtime_size_t align)
 {
     return align
            + ROUND_UP(sizeof(thread_lookup_t), align)
@@ -434,7 +431,7 @@
 
 static void empty_tls(void)
 {
-    env.tls.image = NULL;
+    env.tls.image = SEL4RUNTIME_NULL;
     env.tls.align = MIN_ALIGN_BYTES;
     env.tls.image_size = 0;
     env.tls.memory_size = 0;
@@ -450,8 +447,8 @@
  * This will optimistically assume that the current thread is the
  * initial thread of no thread ever had TLS configured.
  */
-static bool is_initial_thread(void)
+static int is_initial_thread(void)
 {
-    return env.initial_thread_tls_base == (uintptr_t)NULL
+    return env.initial_thread_tls_base == (sel4runtime_uintptr_t)SEL4RUNTIME_NULL
            || sel4runtime_get_tls_base() == env.initial_thread_tls_base;
 }
diff --git a/src/memcpy.c b/src/memcpy.c
index 47d1d8c..ffa7efe 100644
--- a/src/memcpy.c
+++ b/src/memcpy.c
@@ -26,7 +26,7 @@
 
 #include "util.h"
 
-void *__sel4runtime_memcpy(void *restrict dest, const void *restrict src, size_t n)
+void *__sel4runtime_memcpy(void *restrict dest, const void *restrict src, sel4runtime_size_t n)
 {
 	unsigned char *d = dest;
 	const unsigned char *s = src;
@@ -41,12 +41,12 @@
 #define RS >>
 #endif
 
-	typedef uint32_t __attribute__((__may_alias__)) u32;
-	uint32_t w, x;
+	typedef sel4runtime_uint32_t __attribute__((__may_alias__)) u32;
+	sel4runtime_uint32_t w, x;
 
-	for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++;
+	for (; (sel4runtime_uintptr_t)s % 4 && n; n--) *d++ = *s++;
 
-	if ((uintptr_t)d % 4 == 0) {
+	if ((sel4runtime_uintptr_t)d % 4 == 0) {
 		for (; n>=16; s+=16, d+=16, n-=16) {
 			*(u32 *)(d+0) = *(u32 *)(s+0);
 			*(u32 *)(d+4) = *(u32 *)(s+4);
@@ -71,7 +71,7 @@
 		return dest;
 	}
 
-	if (n >= 32) switch ((uintptr_t)d % 4) {
+	if (n >= 32) switch ((sel4runtime_uintptr_t)d % 4) {
 	case 1:
 		w = *(u32 *)s;
 		*d++ = *s++;
diff --git a/src/memset.c b/src/memset.c
index 5a93c32..0ed0784 100644
--- a/src/memset.c
+++ b/src/memset.c
@@ -26,10 +26,10 @@
 
 #include "util.h"
 
-void *__sel4runtime_memset(void *dest, int c, size_t n)
+void *__sel4runtime_memset(void *dest, int c, sel4runtime_size_t n)
 {
 	unsigned char *s = dest;
-	size_t k;
+	sel4runtime_size_t k;
 
 	/* Fill head and tail with minimal branching. Each
 	 * conditional ensures that all the subsequently used
@@ -49,14 +49,14 @@
 	 * already took care of any head/tail that get cut off
 	 * by the alignment. */
 
-	k = -(uintptr_t)s & 3;
+	k = -(sel4runtime_uintptr_t)s & 3;
 	s += k;
 	n -= k;
 	n &= -4;
 
 #ifdef __GNUC__
-	typedef uint32_t __attribute__((__may_alias__)) u32;
-	typedef uint64_t __attribute__((__may_alias__)) u64;
+	typedef sel4runtime_uint32_t __attribute__((__may_alias__)) u32;
+	typedef sel4runtime_uint64_t __attribute__((__may_alias__)) u64;
 
 	u32 c32 = ((u32)-1)/255 * (unsigned char)c;
 
@@ -87,7 +87,7 @@
 	 * and avoid writing the same bytes twice as much as is
 	 * practical without introducing additional branching. */
 
-	k = 24 + ((uintptr_t)s & 4);
+	k = 24 + ((sel4runtime_uintptr_t)s & 4);
 	s += k;
 	n -= k;
 
diff --git a/src/start_root.c b/src/start_root.c
index a9a98eb..677d5f7 100644
--- a/src/start_root.c
+++ b/src/start_root.c
@@ -11,8 +11,8 @@
  */
 #include <sel4/sel4.h>
 #include <sel4runtime/start.h>
-#include <stdint.h>
-#include <stddef.h>
+#include <sel4runtime/stdint.h>
+#include <sel4runtime/stddef.h>
 
 /*
  * As this file is only included when we are running a root server,
@@ -41,9 +41,9 @@
  */
 void __sel4_start_root(seL4_BootInfo *boot_info)
 {
-    uintptr_t tdata_start = (uintptr_t) &_tdata_start[0];
-    uintptr_t tdata_end = (uintptr_t) &_tdata_end[0];
-    uintptr_t tbss_end = (uintptr_t) &_tbss_end[0];
+    sel4runtime_uintptr_t tdata_start = (sel4runtime_uintptr_t) &_tdata_start[0];
+    sel4runtime_uintptr_t tdata_end = (sel4runtime_uintptr_t) &_tdata_end[0];
+    sel4runtime_uintptr_t tbss_end = (sel4runtime_uintptr_t) &_tbss_end[0];
 
     Elf_Phdr tls_header = {
         .p_type   = PT_TLS,
@@ -83,12 +83,12 @@
 
     char const *const envp[] = {
         "seL4=1",
-        NULL,
+        SEL4RUNTIME_NULL,
     };
 
     char const *const argv[] = {
         "rootserver",
-        NULL,
+        SEL4RUNTIME_NULL,
     };
 
     __sel4runtime_start_main(main, ARRAY_LENGTH(argv), argv, envp, auxv);
diff --git a/src/util.h b/src/util.h
index 1b31988..b2ff76d 100644
--- a/src/util.h
+++ b/src/util.h
@@ -9,8 +9,8 @@
  *
  * @TAG(DATA61_BSD)
  */
-#include <stddef.h>
-#include <stdint.h>
+#include <sel4runtime/stddef.h>
+#include <sel4runtime/stdint.h>
 
 #define ALIGN_UP(x, n) (((x) + (n) - 1) & ~((n) - 1))
 #define ALIGN_DOWN(x, n) ((x) & ~((n) - 1))
@@ -35,6 +35,6 @@
 void *__sel4runtime_memcpy(
     void *restrict dest,
     const void *restrict src,
-    size_t n
+    sel4runtime_size_t n
 );
-void *__sel4runtime_memset(void *dest, int c, size_t n);
+void *__sel4runtime_memset(void *dest, int c, sel4runtime_size_t n);