aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKimplul <kimi.h.kuparinen@gmail.com>2022-05-28 20:01:58 +0300
committerKimplul <kimi.h.kuparinen@gmail.com>2022-05-28 20:01:58 +0300
commit013a27aec9370221e8afae188a8ed08ed2d406b0 (patch)
treeb2bec6ae390b944f86607f34fb10dc0b438191bd
parent8911a377da22e5a8ad5ca2a0443fbd935f572991 (diff)
downloadkmi-013a27aec9370221e8afae188a8ed08ed2d406b0.tar.gz
kmi-013a27aec9370221e8afae188a8ed08ed2d406b0.zip
continue documenting source
-rw-r--r--arch/riscv64/gen/asm-offsets.c2
-rw-r--r--arch/riscv64/include/types.h3
-rw-r--r--arch/riscv64/kernel/pages.h32
-rw-r--r--arch/riscv64/kernel/regs.h2
-rw-r--r--common/debug.c14
-rw-r--r--common/uapi/ipc.c1
-rw-r--r--common/uapi/mem.c12
-rw-r--r--include/apos/assert.h7
-rw-r--r--include/apos/debug.h289
-rw-r--r--include/apos/mem.h6
-rw-r--r--include/apos/types.h305
-rw-r--r--lib/ubsan.c287
12 files changed, 809 insertions, 151 deletions
diff --git a/arch/riscv64/gen/asm-offsets.c b/arch/riscv64/gen/asm-offsets.c
index 8251500..fbe2726 100644
--- a/arch/riscv64/gen/asm-offsets.c
+++ b/arch/riscv64/gen/asm-offsets.c
@@ -1,6 +1,6 @@
/**
* @file asm-offsets.c
- * riscv64 file used to generate offsets to register slots in stack. See \ref
+ * riscv64 file used to generate offsets to register slots in stack. Used by
* _save_context.
*/
diff --git a/arch/riscv64/include/types.h b/arch/riscv64/include/types.h
index 8cb41bf..de7a85f 100644
--- a/arch/riscv64/include/types.h
+++ b/arch/riscv64/include/types.h
@@ -9,7 +9,10 @@
#include <apos/types.h>
+/** Virtual memory address. */
typedef uintptr_t vm_t;
+
+/** Physical memory address. */
typedef uintptr_t pm_t;
#endif /* APOS_RISCV_TYPES_H */
diff --git a/arch/riscv64/kernel/pages.h b/arch/riscv64/kernel/pages.h
index 3f4b632..cb7ca88 100644
--- a/arch/riscv64/kernel/pages.h
+++ b/arch/riscv64/kernel/pages.h
@@ -6,44 +6,28 @@
* riscv64-specific shorthands for some page sizes.
*/
-/**
- * riscv64 4KiB page, order 0.
- */
+/** riscv64 4KiB page, order 0. */
#define MM_KPAGE MM_O0
-/**
- * riscv64 2MiB page, order 1.
- */
+/** riscv64 2MiB page, order 1. */
#define MM_MPAGE MM_O1
-/**
- * riscv64 1GiB page, order 2.
- */
+/** riscv64 1GiB page, order 2. */
#define MM_GPAGE MM_O2
-/**
- * riscv64 512GiB page, order 3.
- */
+/** riscv64 512GiB page, order 3. */
#define MM_TPAGE MM_O3
-/**
- * riscv64 4KiB page size.
- */
+/** riscv64 4KiB page size. */
#define MM_KPAGE_SIZE SZ_4K
-/**
- * riscv64 2MiB page size.
- */
+/** riscv64 2MiB page size. */
#define MM_MPAGE_SIZE SZ_2M
-/**
- * riscv64 1GiB page size.
- */
+/** riscv64 1GiB page size. */
#define MM_GPAGE_SIZE SZ_1G
-/**
- * riscv64 512GiB page size.
- */
+/** riscv64 512GiB page size. */
#define MM_TPAGE_SIZE SZ_512G
#endif /* APOS_RISCV_PAGES_H */
diff --git a/arch/riscv64/kernel/regs.h b/arch/riscv64/kernel/regs.h
index 511934e..97bb17e 100644
--- a/arch/riscv64/kernel/regs.h
+++ b/arch/riscv64/kernel/regs.h
@@ -3,7 +3,7 @@
/**
* @file regs.h
- * riscv64 registers, currently only base extension integer regs. Used to \ref
+ * riscv64 registers, currently only base extension integer regs. Used in
* _save_context. Used in \ref arch/riscv64/gen/asm-offsets.c to generate a list
* of offsets usable from assembly.
*
diff --git a/common/debug.c b/common/debug.c
index e7bcc50..ae56ab1 100644
--- a/common/debug.c
+++ b/common/debug.c
@@ -19,20 +19,24 @@ static struct dbg_info {
enum serial_dev dev;
} dbg_info = (struct dbg_info){ 0 };
+/* forward declarations. */
+static void __setup_dbg(pm_t pt, enum serial_dev dev);
+static struct dbg_info __dbg_from_fdt(const void *fdt);
+
void init_dbg(const void *fdt)
{
- dbg_info = dbg_from_fdt(fdt);
+ dbg_info = __dbg_from_fdt(fdt);
}
void setup_dmap_dbg()
{
- setup_dbg(dbg_info.dbg_ptr, dbg_info.dev);
+ __setup_dbg(dbg_info.dbg_ptr, dbg_info.dev);
}
void setup_io_dbg(struct vmem *b)
{
vm_t io_ptr = setup_kernel_io(b, dbg_info.dbg_ptr);
- setup_dbg(io_ptr, dbg_info.dev);
+ __setup_dbg(io_ptr, dbg_info.dev);
}
/* if there arises a need for more supported serial drivers, I should probably
@@ -95,7 +99,7 @@ static enum serial_dev __serial_dev_enum(const char *dev_name)
return -1;
}
-struct dbg_info dbg_from_fdt(const void *fdt)
+static struct dbg_info __dbg_from_fdt(const void *fdt)
{
int chosen_offset = fdt_path_offset(fdt, "/chosen");
const char *stdout =
@@ -118,7 +122,7 @@ struct dbg_info dbg_from_fdt(const void *fdt)
return (struct dbg_info){ dbg_ptr, dev };
}
-void setup_dbg(vm_t pt, enum serial_dev dev)
+void __setup_dbg(vm_t pt, enum serial_dev dev)
{
switch (dev) {
case NS16550A:
diff --git a/common/uapi/ipc.c b/common/uapi/ipc.c
index d46ba26..4327c90 100644
--- a/common/uapi/ipc.c
+++ b/common/uapi/ipc.c
@@ -20,6 +20,7 @@ SYSCALL_DEFINE3(ipc_req)(sys_arg_t pid, sys_arg_t d0, sys_arg_t d1)
{
struct tcb *r = get_tcb(pid);
/* TODO: something like jump_to_callback(t) */
+ /* remember difference between ipc_req and ipc_fwd! */
return (struct sys_ret){ d0, d1 };
}
diff --git a/common/uapi/mem.c b/common/uapi/mem.c
index b953119..9d631ae 100644
--- a/common/uapi/mem.c
+++ b/common/uapi/mem.c
@@ -10,21 +10,21 @@
SYSCALL_DEFINE2(req_mem)(sys_arg_t size, sys_arg_t flags)
{
- /* proc_tcb should give the tcb of the TID currently running */
- struct tcb *r = cur_tcb();
+ /* get current effective process */
+ struct tcb *r = cur_proc();
return (struct sys_ret){ OK, alloc_uvmem(r, size, flags) };
}
SYSCALL_DEFINE3(req_fixmem)(sys_arg_t start, sys_arg_t size, sys_arg_t flags)
{
- struct tcb *r = cur_tcb();
+ struct tcb *r = cur_proc();
/* should probably check if the allocation succeeded...? TODO */
return (struct sys_ret){ OK, alloc_fixed_uvmem(r, start, size, flags) };
}
SYSCALL_DEFINE1(free_mem)(sys_arg_t start)
{
- struct tcb *r = cur_tcb();
+ struct tcb *r = cur_proc();
vm_t vm_start = (vm_t)start;
if (vm_start > __pre_top && vm_start < __post_base)
@@ -42,14 +42,14 @@ SYSCALL_DEFINE3(req_pmem)(sys_arg_t paddr, sys_arg_t size, sys_arg_t flags)
* outside the RAM area, and I'll probably have to implement some method
* that keeps track of used regions outside of RAM. We'll see.
*/
- struct tcb *r = cur_tcb();
+ struct tcb *r = cur_proc();
return (struct sys_ret){ OK, alloc_devmem(r, paddr, size, flags) };
}
SYSCALL_DEFINE2(req_sharedmem)(sys_arg_t size, sys_arg_t flags)
{
/* TODO: check that requester is server */
- struct tcb *t = cur_tcb();
+ struct tcb *t = cur_proc();
vm_t start = 0;
if ((start = alloc_shared_uvmem(t, size, flags)))
return (struct sys_ret){ ERR_OOMEM, 0 };
diff --git a/include/apos/assert.h b/include/apos/assert.h
index 429134e..3255481 100644
--- a/include/apos/assert.h
+++ b/include/apos/assert.h
@@ -23,8 +23,7 @@
#define catastrophic_assert(x) \
do { \
if (unlikely(!(x))) { \
- error("catastrophic assertion failed: %s\n", \
- QUOTE(x)); \
+ error("catastrophic assertion failed: " QUOTE(x) "\n"); \
while (1) { \
} \
} \
@@ -33,7 +32,7 @@
#define hard_assert(x, r) \
{ \
if (unlikely(!(x))) { \
- warn("hard assertion failed: %s\n", QUOTE(x)); \
+ warn("hard assertion failed: " QUOTE(x) "\n"); \
return r; \
} \
}
@@ -41,7 +40,7 @@
#define soft_assert(x) \
do { \
if (unlikely(!(x))) { \
- info("soft assertion failed: %s\n", QUOTE(x)); \
+ info("soft assertion failed: " QUOTE(x) "\n"); \
} \
} while (0);
#else
diff --git a/include/apos/debug.h b/include/apos/debug.h
index 88668ff..cb46ba7 100644
--- a/include/apos/debug.h
+++ b/include/apos/debug.h
@@ -4,158 +4,399 @@
/**
* @file debug.h
* Debug printing.
+ *
+ * Note that 'Integer format specifier' means "%i", which is identical to "%d"
+ * in the context of outputting integers.
*/
#include <apos/attrs.h>
#include <apos/pmem.h>
#include <arch/vmem.h>
+/** @name Internal. */
+/** @{ */
+
+/** Long integer prefix. Approximate, but probably good enough */
#if _LP64
-/* approximate, but probably good enough */
#define __PRI64_PREFIX "l"
-#define __PRIPTR_PREFIX "l"
#else
#define __PRI64_PREFIX "ll"
+#endif
+
+/** Long pointer in integer type prefix. */
+#if _LP64
+#define __PRIPTR_PREFIX "l"
+#else
#define __PRIPTR_PREFIX
#endif
-/* Decimal notation. */
+/** @} */
+
+/** @name Decimal format specifiers. */
+/** @{ */
+
+/** Decimal format specifief for \ref int8_t */
#define PRId8 "d"
+
+/** Decimal format specifier for \ref int16_t */
#define PRId16 "d"
+
+/** Decimal format specifier for \ref int32_t */
#define PRId32 "d"
+
+/** Decimal format specifier for int16_t */
#define PRId64 __PRI64_PREFIX "d"
+/** Decimal format specifier for \ref int_least8_t. */
#define PRIdLEAST8 "d"
+
+/** Decimal format specifier for \ref int_least16_t. */
#define PRIdLEAST16 "d"
+
+/** Decimal format specifier for \ref int_least32_t. */
#define PRIdLEAST32 "d"
+
+/** Decimal format specifier for \ref int_least64_t. */
#define PRIdLEAST64 __PRI64_PREFIX "d"
+/** Decimal format specifier for \ref int_fast8_t. */
#define PRIdFAST8 "d"
+
+/** Decimal format specifier for \ref int_fast16_t. */
#define PRIdFAST16 __PRIPTR_PREFIX "d"
+
+/** Decimal format specifier for \ref int_fast32_t. */
#define PRIdFAST32 __PRIPTR_PREFIX "d"
+
+/** Decimal format specifier for \ref int_fast64_t. */
#define PRIdFAST64 __PRI64_PREFIX "d"
+/** Decimal format specifier for \ref intmax_t. */
+#define PRIdMAX __PRI64_PREFIX "d"
+
+/** Decimal format specifier for \ref intptr_t. */
+#define PRIdPTR __PRIPTR_PREFIX "d"
+
+/** @} */
+
+/** @name Integer format specifiers. */
+/** @{ */
+
+/** Integer format specifier for \ref int8_t. */
#define PRIi8 "i"
+
+/** Integer format specifier for \ref int16_t. */
#define PRIi16 "i"
+
+/** Integer format specifier for \ref int32_t. */
#define PRIi32 "i"
+
+/** Integer format specifier for \ref int64_t. */
#define PRIi64 __PRI64_PREFIX "i"
+/** Integer format specifier for \ref int_least8_t. */
#define PRIiLEAST8 "i"
+
+/** Integer format specifier for \ref int_least16_t. */
#define PRIiLEAST16 "i"
+
+/** Integer format specifier for \ref int_least32_t. */
#define PRIiLEAST32 "i"
+
+/** Integer format specifier for \ref int_least64_t. */
#define PRIiLEAST64 __PRI64_PREFIX "i"
+/** Integer format specifier for \ref int_fast8_t. */
#define PRIiFAST8 "i"
+
+/** Integer format specifier for \ref int_fast16_t. */
#define PRIiFAST16 __PRIPTR_PREFIX "i"
+
+/** Integer format specifier for \ref int_fast32_t. */
#define PRIiFAST32 __PRIPTR_PREFIX "i"
+
+/** Integer format specifier for \ref int_fast64_t. */
#define PRIiFAST64 __PRI64_PREFIX "i"
-/* Octal notation. */
+/** Integer format specifier for \ref intmax_t. */
+#define PRIiMAX __PRI64_PREFIX "i"
+
+/** Integer format specifier for \ref intptr_t. */
+#define PRIiPTR __PRIPTR_PREFIX "i"
+
+/** @} */
+
+/** @name Octal format specifiers. */
+/** @{ */
+
+/** Octal format specifier for \ref int8_t. */
#define PRIo8 "o"
+
+/** Octal format specifier for \ref int16_t. */
#define PRIo16 "o"
+
+/** Octal format specifier for \ref int32_t. */
#define PRIo32 "o"
+
+/** Octal format specifier for \ref int64_t. */
#define PRIo64 __PRI64_PREFIX "o"
+/** Octal format specifier for \ref int_least8_t. */
#define PRIoLEAST8 "o"
+
+/** Octal format specifier for \ref int_least16_t. */
#define PRIoLEAST16 "o"
+
+/** Octal format specifier for \ref int_least32_t. */
#define PRIoLEAST32 "o"
+
+/** Octal format specifier for \ref int_least64_t. */
#define PRIoLEAST64 __PRI64_PREFIX "o"
+/** Octal format specifier for \ref int_fast8_t. */
#define PRIoFAST8 "o"
+
+/** Octal format specifier for \ref int_fast16_t. */
#define PRIoFAST16 __PRIPTR_PREFIX "o"
+
+/** Octal format specifier for \ref int_fast32_t. */
#define PRIoFAST32 __PRIPTR_PREFIX "o"
+
+/** Octal format specifier for \ref int_fast64_t. */
#define PRIoFAST64 __PRI64_PREFIX "o"
-/* Unsigned integers. */
+/** Octal format specifier for \ref uintmax_t. */
+#define PRIoMAX __PRI64_PREFIX "o"
+
+/** Octal format specifier for \ref uintptr_t. */
+#define PRIoPTR __PRIPTR_PREFIX "o"
+
+/** @} */
+
+/** @name Unsigned decimal format specifiers. */
+/** @{ */
+
+/** Unsigned decimal format specifier for \ref uint8_t. */
#define PRIu8 "u"
+
+/** Unsigned decimal format specifier for \ref uint16_t. */
#define PRIu16 "u"
+
+/** Unsigned decimal format specifier for \ref uint32_t. */
#define PRIu32 "u"
+
+/** Unsigned decimal format specifier for \ref uint64_t. */
#define PRIu64 __PRI64_PREFIX "u"
+/** Unsigned decimal format specifier for \ref uint_least8_t. */
#define PRIuLEAST8 "u"
+
+/** Unsigned decimal format specifier for \ref uint_least16_t. */
#define PRIuLEAST16 "u"
+
+/** Unsigned decimal format specifier for \ref uint_least32_t. */
#define PRIuLEAST32 "u"
+
+/** Unsigned decimal format specifier for \ref uint_least64_t. */
#define PRIuLEAST64 __PRI64_PREFIX "u"
+/** Unsigned decimal format specifier for \ref uint_fast8_t. */
#define PRIuFAST8 "u"
+
+/** Unsigned decimal format specifier for \ref uint_fast16_t. */
#define PRIuFAST16 __PRIPTR_PREFIX "u"
+
+/** Unsigned decimal format specifier for \ref uint_fast32_t. */
#define PRIuFAST32 __PRIPTR_PREFIX "u"
+
+/** Unsigned decimal format specifier for \ref uint_fast64_t. */
#define PRIuFAST64 __PRI64_PREFIX "u"
-/* lowercase hexadecimal notation. */
+/** Unsigned decimal format specifier for \ref uintmax_t. */
+#define PRIuMAX __PRI64_PREFIX "u"
+
+/** Unsigned decimal format specifier for \ref uintptr_t. */
+#define PRIuPTR __PRIPTR_PREFIX "u"
+
+/** @} */
+
+/** @name Hex format specifiers. */
+/** @{ */
+
+/** Hex format specifier for \ref uint8_t. */
#define PRIx8 "x"
+
+/** Hex format specifier for \ref uint16_t. */
#define PRIx16 "x"
+
+/** Hex format specifier for \ref uint32_t. */
#define PRIx32 "x"
+
+/** Hex format specifier for \ref uint64_t. */
#define PRIx64 __PRI64_PREFIX "x"
+/** Hex format specifier for \ref uint_least8_t. */
#define PRIxLEAST8 "x"
+
+/** Hex format specifier for \ref uint_least16_t. */
#define PRIxLEAST16 "x"
+
+/** Hex format specifier for \ref uint_least32_t. */
#define PRIxLEAST32 "x"
+
+/** Hex format specifier for \ref uint_least64_t. */
#define PRIxLEAST64 __PRI64_PREFIX "x"
+/** Hex format specifier for \ref uint_fast8_t. */
#define PRIxFAST8 "x"
+
+/** Hex format specifier for \ref uint_fast16_t. */
#define PRIxFAST16 __PRIPTR_PREFIX "x"
+
+/** Hex format specifier for \ref uint_fast32_t. */
#define PRIxFAST32 __PRIPTR_PREFIX "x"
+
+/** Hex format specifier for \ref uint_fast64_t. */
#define PRIxFAST64 __PRI64_PREFIX "x"
-/* Binary notation */
+/** Hex format specifier for \ref uintmax_t. */
+#define PRIxMAX __PRI64_PREFIX "x"
+
+/** Hex format specifier for \ref uintptr_t. */
+#define PRIxPTR __PRIPTR_PREFIX "x"
+
+/** @} */
+
+/** @name Binary notation */
+/** @{ */
+
+/** Binary format specifier for \ref uint8_t. */
#define PRIX8 "X"
+
+/** Binary format specifier for \ref uint16_t. */
#define PRIX16 "X"
+
+/** Binary format specifier for \ref uint32_t. */
#define PRIX32 "X"
+
+/** Binary format specifier for \ref uint64_t. */
#define PRIX64 __PRI64_PREFIX "X"
+/** Binary format specifier for \ref uint_least8_t. */
#define PRIXLEAST8 "X"
+
+/** Binary format specifier for \ref uint_least16_t. */
#define PRIXLEAST16 "X"
+
+/** Binary format specifier for \ref uint_least32_t. */
#define PRIXLEAST32 "X"
+
+/** Binary format specifier for \ref uint_least64_t. */
#define PRIXLEAST64 __PRI64_PREFIX "X"
+/** Binary format specifier for \ref uint_fast8_t. */
#define PRIXFAST8 "X"
+
+/** Binary format specifier for \ref uint_fast16_t. */
#define PRIXFAST16 __PRIPTR_PREFIX "X"
+
+/** Binary format specifier for \ref uint_fast32_t. */
#define PRIXFAST32 __PRIPTR_PREFIX "X"
+
+/** Binary format specifier for \ref uint_fast64_t. */
#define PRIXFAST64 __PRI64_PREFIX "X"
-/* Macros for printing `intmax_t' and `uintmax_t'. */
-#define PRIdMAX __PRI64_PREFIX "d"
-#define PRIiMAX __PRI64_PREFIX "i"
-#define PRIoMAX __PRI64_PREFIX "o"
-#define PRIuMAX __PRI64_PREFIX "u"
-#define PRIxMAX __PRI64_PREFIX "x"
+/** Binary format specifier for \ref uintmax_t. */
#define PRIXMAX __PRI64_PREFIX "X"
-/* Macros for printing `intptr_t' and `uintptr_t'. */
-#define PRIdPTR __PRIPTR_PREFIX "d"
-#define PRIiPTR __PRIPTR_PREFIX "i"
-#define PRIoPTR __PRIPTR_PREFIX "o"
-#define PRIuPTR __PRIPTR_PREFIX "u"
-#define PRIxPTR __PRIPTR_PREFIX "x"
+/** Binary format specifier for \ref uintptr_t. */
#define PRIXPTR __PRIPTR_PREFIX "X"
+/** @} */
+
#if defined(DEBUG)
+/** Serial devices supported. */
enum serial_dev {
- /* only the NS16550A and compatible at the moment */
+ /** NS16550A and compatible. Currently the only supported serial device. */
NS16550A,
};
-void __fmt(1, 2) dbg(const char *fmt, ...);
+/**
+ * dbg, apos equivalent of printf.
+ *
+ * @param fmt Format string. Integer subset of normal printf formatting.
+ */
+void dbg(const char *fmt, ...) __fmt(1, 2);
+/**
+ * Initialize debugging, set up serial driver etc.
+ *
+ * @param fdt Pointer to global FDT.
+ */
void init_dbg(const void *fdt);
+/**
+ * Setup debugging in direct mapping context.
+ */
void setup_dmap_dbg();
-void setup_io_dbg(struct vmem *b);
-void setup_dbg(pm_t pt, enum serial_dev dev);
-struct dbg_info dbg_from_fdt(const void *fdt);
+/**
+ * Setup debugging in virtual memory context.
+ *
+ * @param vmem Virtual memory space to use.
+ */
+void setup_io_dbg(struct vmem *vmem);
+
+/** @name Internal. */
+/** @{ */
+/**
+ * Format to append to helper debugging classes.
+ * See \ref bug(), \ref warn(), \ref info() and \ref error().
+ */
#define COMMON_FORMAT "[%s] %s:%d\n\t"
+
+/**
+ * Helper for helper classes.
+ * See \ref bug(), \ref warn(), \ref info(), \ref error().
+ */
#define COMMON_ARGS(s) s, __FILE__, __LINE__
+
+/** @} */
+
+/**
+ * Print a bug message to the serial lines.
+ *
+ * @param fmt Message, integer subset of regular printf.
+ */
#define bug(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("BUG"),##__VA_ARGS__)
+
+/**
+ * Print a warning message to the serial lines.
+ *
+ * @param fmt Message, integer subset of regular printf.
+ */
#define warn(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("WARN"),##__VA_ARGS__)
+
+/**
+ * Print an informational message to the serial lines.
+ *
+ * @param fmt Message, integer subset of regular printf.
+ */
#define info(fmt, ...) dbg(COMMON_FORMAT fmt, COMMON_ARGS("INFO"),##__VA_ARGS__)
+
+/**
+ * Prnt an error message to the serial lines.
+ *
+ * @param fmt Message, integer subset of regular printf.
+ */
#define error(fmt, ...) \
dbg(COMMON_FORMAT fmt, COMMON_ARGS("ERROR"),##__VA_ARGS__)
#else
+/* already documented in previous #if block, let's hope Doxygen doesn't start
+ * complaining :) */
#define dbg(...)
#define dbg_init(...)
#define dbg_from_fdt(...)
diff --git a/include/apos/mem.h b/include/apos/mem.h
index b6d76c1..1486400 100644
--- a/include/apos/mem.h
+++ b/include/apos/mem.h
@@ -48,11 +48,11 @@
__page((x) + BASE_PAGE_SIZE))
#define __bytes(x) (__addr(x))
-/** If memory region is used or not */
+/** Memory region is used. */
#define MR_USED (1 << 8)
-/** If memory region is shared */
+/** Memory region is shared. */
#define MR_SHARED (1 << 9)
-/** Owner of shared region */
+/** Owner of shared region. */
#define MR_OWNED (1 << 10)
/** Copy on write. */
#define MR_COW (1 << 11)
diff --git a/include/apos/types.h b/include/apos/types.h
index 97f663b..5f35ee8 100644
--- a/include/apos/types.h
+++ b/include/apos/types.h
@@ -4,207 +4,478 @@
/**
* @file types.h
* Shorthands for types, similar to stdint.h.
+ *
+ * Implementation detail: Note that according to the C spec, intX_t are optional.
+ * Will have to keep an eye out for architectures where they aren't implemented,
+ * but for now this is likely good enough.
*/
+/** Bool. */
typedef _Bool bool;
+/** True. */
#define true 1
+/** False. */
#define false 0
+/** Type capable of holding the difference between two pointers. */
typedef __PTRDIFF_TYPE__ ptrdiff_t;
+
+/** Type capable of holding a wide char. Unused by the kernel. */
typedef __WCHAR_TYPE__ wchar_t;
+
+/** Type capable of holding a \ref wchar_t and WEOF. Unused by the kernel. */
typedef __WINT_TYPE__ wint_t;
+
+/** Maximum width signed integer type. */
typedef __INTMAX_TYPE__ intmax_t;
+
+/** Maximum width unsigned integer type. */
typedef __UINTMAX_TYPE__ uintmax_t;
+
+/** 8bit signed integer type. */
typedef __INT8_TYPE__ int8_t;
+
+/** 16bit signed integer type. */
typedef __INT16_TYPE__ int16_t;
+
+/** 32bit signed integer type. */
typedef __INT32_TYPE__ int32_t;
+
+/** 64bit signed integer type. */
typedef __INT64_TYPE__ int64_t;
+
+/** 8bit unsigned integer type. */
typedef __UINT8_TYPE__ uint8_t;
+
+/** 16bit unsigned integer type. */
typedef __UINT16_TYPE__ uint16_t;
+
+/** 32bit unsigned integer type. */
typedef __UINT32_TYPE__ uint32_t;
+
+/** 64bit unsigned integer type. */
typedef __UINT64_TYPE__ uint64_t;
+
+/** Smallest signed integer type at least 8 bits wide. */
typedef __INT_LEAST8_TYPE__ int_least8_t;
+
+/** Smallest signed integer type at least 16 bits wide. */
typedef __INT_LEAST16_TYPE__ int_least16_t;
+
+/** Smallest signed integer type at least 32 bits wide. */
typedef __INT_LEAST32_TYPE__ int_least32_t;
+
+/** Smallest signed integer type at least 64 bits wide. */
typedef __INT_LEAST64_TYPE__ int_least64_t;
+
+/** Smallest unsigned integer type at least 8 bits wide. */
typedef __UINT_LEAST8_TYPE__ uint_least8_t;
+
+/** Smallest unsigned integer type at least 16 bits wide. */
typedef __UINT_LEAST16_TYPE__ uint_least16_t;
+
+/** Smallest unsigned integer type at least 32 bits wide. */
typedef __UINT_LEAST32_TYPE__ uint_least32_t;
+
+/** Smallest unsigned integer type at least 64 bits wide. */
typedef __UINT_LEAST64_TYPE__ uint_least64_t;
+
+/** Fastest signed integer type at least 8 bits wide. */
typedef __INT_FAST8_TYPE__ int_fast8_t;
+
+/** Fastest signed integer type at least 16 bits wide. */
typedef __INT_FAST16_TYPE__ int_fast16_t;
+
+/** Fastest signed integer type at least 32 bits wide. */
typedef __INT_FAST32_TYPE__ int_fast32_t;
+
+/** Fastest signed integer type at least 64 bits wide. */
typedef __INT_FAST64_TYPE__ int_fast64_t;
+
+/** Fastest unsigned integer type at least 8 bits wide. */
typedef __UINT_FAST8_TYPE__ uint_fast8_t;
+
+/** Fastest unsigned integer type at least 16 bits wide. */
typedef __UINT_FAST16_TYPE__ uint_fast16_t;
+
+/** Fastest unsigned integer type at least 32 bits wide. */
typedef __UINT_FAST32_TYPE__ uint_fast32_t;
+
+/** Fastest unsigned integer type at least 64 bits wide. */
typedef __UINT_FAST64_TYPE__ uint_fast64_t;
+
+/** Signed integer type capable of holding a pointer. */
typedef __INTPTR_TYPE__ intptr_t;
+
+/** Unsigned integer type capable of holding a pointer. */
typedef __UINTPTR_TYPE__ uintptr_t;
#if __SIZE_WIDTH__ == 64
+/** Largest possible unsigned index an array could use. */
typedef uint64_t size_t;
+
+/** Largest possible signed index an array could use. */
typedef int64_t ssize_t;
#else
+/** Largest possible unsigned index an array could use. */
typedef uint32_t size_t;
+
+/** Largest possible signed index an array could use. */
typedef int32_t ssize_t;
#endif
+/** Expands to integer constant of type \ref int8_t. */
#define INT8_C __INT8_C
+
+/** Expands to integer constant of type \ref int16_t. */
#define INT16_C __INT16_C
+
+/** Expands to integer constant of type \ref int32_t. */
#define INT32_C __INT32_C
+/** Expands to integer constant of type \ref int64_t. */
#define INT64_C __INT64_C
+
+/** Expands to integer constant of type \ref uint8_t. */
#define UINT8_C __UINT8_C
+
+/** Expands to integer constant of type \ref uint16_t. */
#define UINT16_C __UINT16_C
+
+/** Expands to integer constant of type \ref uint32_t. */
#define UINT32_C __UINT32_C
+
+/** Expands to integer constant of type \ref uint64_t. */
#define UINT64_C __UINT64_C
+
+/** Expands to integer constant of type \ref intmax_t. */
#define INTMAX_C __INTMAX_C
+
+/** Expands to integer constant of type \ref uintmax_t. */
#define UINTMAX_C __UINTMAX_C
+/** Number of bits in a byte. */
#define CHAR_BIT __CHAR_BIT__
+/** Largest value a signed char can have. */
#define SCHAR_MAX __SCHAR_MAX__
+
+/** Smallest value a signed char can have. */
#define SCHAR_MIN (-__SCHAR_MAX - 1)
+
+/** Largest value an unsigned char can have. */
#define UCHAR_MAX (2 * __SCHAR_MAX__ - 1)
#if defined(__CHAR_UNSIGNED__)
+/** Smallest value a char can have. */
#define CHAR_MIN 0
+
+/** Largest value a char can have. */
#define CHAR_MAX UCHAR_MAX
#else
+/** Smallest value a char can have. */
#define CHAR_MIN SCHAR_MIN
+
+/** Largest value a char can have. */
#define CHAR_MAX SCHAR_MAX
#endif
-/* probably not necessary? */
+/**
+ * Maximum number of bytes in a multibyte character.
+ * Arbitrary, as far as I can tell.
+ */
#define MB_LEN_MAX 16
+/** Largest value a signed short can have. */
#define SHRT_MAX __SHRT_MAX__
+
+/** Smallest value a signed short can have. */
#define SHRT_MIN (-__SHRT_MAX - 1)
+
+/** Largest value an unsigned short can have. */
#define USHRT_MAX (2 * __SHRT_MAX + 1)
+/** Largest value a signed int can have. */
#define INT_MAX __INT_MAX__
+
+/** Smallest value a signed int can have. */
#define INT_MIN (-__INT_MAX__ - 1)
+
+/** Largest value an unsigned int can have. */
#define UINT_MAX (2 * __INT_MAX__ + 1)
+/** Largest value a signed long can have. */
#define LONG_MAX __LONG__MAX__
+
+/** Smallest value a signed long can have. */
#define LONG_MIN (-__LONG_MAX__ - 1)
+
+/** Largest value an unsigned long can have. */
#define ULONG_MAX (2 * __INT_MAX__ + 1)
+/** Largest value a signed long long can have. */
#define LLONG_MAX __LONG_LONG_MAX__
+
+/** Smallest value a signed long long can have. */
#define LLONG_MIN (-__LONG_LONG_MAX__ - 1)
+
+/** Largest value an unsigned long long can have. */
#define ULLONG_MAX (2 * __LONG_LONG_MAX__ + 1)
+/** Largest value an \ref int8_t can have. */
#define INT8_MAX __INT8_MAX__
+
+/** Smallest value an \ref int8_t can have. */
#define INT8_MIN (-__INT8_MAX__ - 1)
+
+/** Largest value an \ref int8_t can have. */
#define UINT8_MAX __UINT8_MAX__
+/** Largest value an \ref int16_t can have. */
#define INT16_MAX __INT16_MAX__
+
+/** Smallest value an \ref int16_t can have. */
#define INT16_MIN (-__INT16_MAX__ - 1)
+
+/** Largest value an \ref uint16_t can have. */
#define UINT16_MAX __UINT16_MAX__
+/** Largest value an \ref int32_t can have. */
#define INT32_MAX __INT32_MAX__
+
+/** Smallest value an \ref int32_t can have. */
#define INT32_MIN (-__INT32_MAX__ - 1)
+
+/** Largest value a \ref uint16_t can have. */
#define UINT32_MAX __UINT32_MAX__
+/** Largest value an \ref int64_t can have. */
#define INT64_MAX __INT64_MAX__
+
+/** Smallest value an \ref int64_t can have. */
#define INT64_MIN (-__INT64_MAX__ - 1)
+
+/** Largest value an \ref uint64_t can have. */
#define UINT64_MAX __UINT64_MAX__
+/** Largest value an \ref int_least8_t can have. */
#define INT_LEAST8_MAX __INT_LEAST8_MAX__
+
+/** Smallest value an \ref int_least8_t can have. */
#define INT_LEAST8_MIN (-__INT_LEAST8_MAX__ - 1)
+
+/** Largest value an \ref int_least8_t can have. */
#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__
+/** Largest value an \ref int_least16_t can have. */
#define INT_LEAST16_MAX __INT_LEAST16_MAX__
+
+/** Smallest value an \ref int_least16_t can have. */
#define INT_LEAST16_MIN (-__INT_LEAST16_MAX__ - 1)
+
+/** Largest value an \ref int_least16_t can have. */
#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__
+/** Largest value an \ref int_least32_t can have. */
#define INT_LEAST32_MAX __INT_LEAST32_MAX__
+
+/** Smallest value an \ref int_least32_t can have. */
#define INT_LEAST32_MIN (-__INT_LEAST32_MAX__ - 1)
+
+/** Largest value a \ref uint_least32_t can have. */
#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__
+/** Largest value an \ref int_least64_t can have. */
#define INT_LEAST64_MAX __INT_LEAST64_MAX__
+
+/** Smallest value an \ref int_least64_t can have. */
#define INT_LEAST64_MIN (-__INT_LEAST64_MAX__ - 1)
+
+/** Largest value a \ref uint_least64_t can have. */
#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__
+/** Largest value an \ref int_fast8_t can have. */
#define INT_FAST8_MAX __INT_FAST8_MAX__
+
+/** Smallest value an \ref int_fast8_t can have. */
#define INT_FAST8_MIN (-__INT_FAST8_MAX__ - 1)
+
+/** Largest value a \ref uint_fast8_t can have. */
#define UINT_FAST8_MAX __UINT_FAST8_MAX__
+/** Largest value an \ref int_fast16_t can have. */
#define INT_FAST16_MAX __INT_FAST16_MAX__
+
+/** Smallest value an \ref int_fast16_t can have. */
#define INT_FAST16_MIN (-__INT_FAST16_MAX__ - 1)
+
+/** Largest value a \ref uint_fast16_t can have. */
#define UINT_FAST16_MAX __UINT_FAST16_MAX__
+/** Largest value an \ref int_fast32_t can have. */
#define INT_FAST32_MAX __INT_FAST32_MAX__
+
+/** Smallest value an \ref int_fast32_t can have. */
#define INT_FAST32_MIN (-__INT_FAST32_MAX__ - 1)
+
+/** Largest value a \ref int_fast32_t can have. */
#define UINT_FAST32_MAX __UINT_FAST32_MAX__
+/** Largest value an \ref int_fast64_t can have. */
#define INT_FAST64_MAX __INT_FAST64_MAX__
+
+/** Smallest value an \ref int_fast64_t can have. */
#define INT_FAST64_MIN (-__INT_FAST64_MAX__ - 1)
+
+/** Largest value a \ref int_fast64_t can have. */
#define UINT_FAST64_MAX __UINT_FAST64_MAX__
+/** Largest value an \ref intptr_t can have. */
#define INTPTR_MAX __INTPTR_MAX__
+
+/** Smallest value an \ref intptr_t can have. */
#define INTPTR_MIN (-__INTPTR_MAX__ - 1)
+
+/** Largest value a \ref uintptr_t can have. */
#define UINTPTR_MAX __UINTPTR_MAX__
+/** Largest value an \ref intmax_t can have. */
#define INTMAX_MAX __INTMAX_MAX__
+
+/** Smallest value an \ref intmax_t can have. */
#define INTMAX_MIN (-__INTMAX_MAX__ - 1)
+
+/** Largest value a \ref uintmax_t can have. */
#define UINTMAX_MAX __UINTMAX_MAX__
+/** Width of \ref int8_t. */
#define INT8_WIDTH 8
+
+/** Width of \ref int16_t. */
#define INT16_WIDTH 16
+
+/** Width of \ref int32_t. */
#define INT32_WIDTH 32
+
+/** Width of \ref int64_t. */
#define INT64_WIDTH 64
+
+/** Width of \ref uint8_t. */
#define UINT8_WIDTH 8
+
+/** Width of \ref uint16_t. */
#define UINT16_WIDTH 16
+
+/** Width of \ref uint32_t. */
#define UINT32_WIDTH 32
+
+/** Width of \ref uint64_t. */
#define UINT64_WIDTH 64
+/** Width of \ref int_fast8_t. */
#define INT_FAST8_WIDTH __INT_FAST8_WIDTH__
+
+/** Width of \ref int_fast16_t. */
#define INT_FAST16_WIDTH __INT_FAST16_WIDTH__
+
+/** Width of \ref int_fast32_t. */
#define INT_FAST32_WIDTH __INT_FAST32_WIDTH__
+
+/** Width of \ref int_fast64_t. */
#define INT_FAST64_WIDTH __INT_FAST64_WIDTH__
+
+/** Width of \ref uint_fast8_t. */
#define UINT_FAST8_WIDTH __INT_FAST8_WIDTH__
+
+/** Width of \ref uint_fast16_t. */
#define UINT_FAST16_WIDTH __INT_FAST16_WIDTH__
+
+/** Width of \ref uint_fast32_t. */
#define UINT_FAST32_WIDTH __INT_FAST32_WIDTH__
+
+/** Width of \ref uint_fast64_t. */
#define UINT_FAST64_WIDTH __INT_FAST64_WIDTH__
+/** Width of \ref int_least8_t. */
#define INT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+
+/** Width of \ref int_least16_t. */
#define INT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+
+/** Width of \ref int_least32_t. */
#define INT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+
+/** Width of \ref int_least64_t. */
#define INT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+
+/** Width of \ref uint_least8_t. */
#define UINT_LEAST8_WIDTH __INT_LEAST8_WIDTH__
+
+/** Width of \ref uint_least16_t. */
#define UINT_LEAST16_WIDTH __INT_LEAST16_WIDTH__
+
+/** Width of \ref uint_least32_t. */
#define UINT_LEAST32_WIDTH __INT_LEAST32_WIDTH__
+
+/** Width of \ref uint_least64_t. */
#define UINT_LEAST64_WIDTH __INT_LEAST64_WIDTH__
+/** Width of \ref intptr_t. */
#define INTPTR_WIDTH __INTPTR_WIDTH__
+
+/** Width of \ref intmax_t. */
#define INTMAX_WIDTH __INTMAX_WIDTH__
+
+/** Width of \ref uintptr_t. */
#define UINTPTR_WIDTH __INTPTR_WIDTH__
+
+/** Width of \ref uintmax_t. */
#define UINTMAX_WIDTH __INTMAX_WIDTH__
+/** Null. */
#define NULL 0
/* some common types used throughout the kernel */
+/** Status, used with codes in \ref status_codes. */
typedef int_fast8_t stat_t;
+
+/** ID of something. */
typedef uint_fast32_t id_t;
+
+/** Memory region flags. */
typedef uint_fast16_t vmflags_t;
-/* error types (should this go somewhere else? */
-/* negative error codes are reserved for general usage, positive error codes are
- * allowed to be function-specific. */
-enum {
- ERR_MISC = -8, /* something */
- ERR_NOINIT = -7, /* not initialized */
- ERR_INVAL = -6, /* invalid value */
- ERR_EXT = -5, /* already exists */
- ERR_OOMEM = -4, /* out of memory */
- ERR_ADDR = -3, /* illegal address */
- ERR_ALIGN = -2, /* wrong alignment */
- ERR_NF = -1, /* not found */
- OK = 0, /* OK */
- INFO_TRGN = 1, /* try again */
- INFO_SEFF = 2, /* side effects */
- INFO_CONT = 3, /* continue */
+/**
+ * Status codes.
+ * Negative error codes are reserved for general usage, positive error codes are
+ * allowed to be function-specific, although that's sort of difficult to keep
+ * track of.
+ */
+/* should this enum be somewhere else? */
+enum status_codes {
+ /** Something went wrong :/ */
+ ERR_MISC = -8,
+ /** Not initialized. */
+ ERR_NOINIT = -7,
+ /** Invalid value. */
+ ERR_INVAL = -6,
+ /** Already exists. */
+ ERR_EXT = -5,
+ /** Out of memory. */
+ ERR_OOMEM = -4,
+ /** Illegal address. */
+ ERR_ADDR = -3,
+ /** Wrong alignment. */
+ ERR_ALIGN = -2,
+ /** Not found. */
+ ERR_NF = -1,
+ /** OK. */
+ OK = 0,
+ /** Try again. */
+ INFO_TRGN = 1,
+ /** Side effects. */
+ INFO_SEFF = 2,
+ /** Continue. */
+ INFO_CONT = 3,
};
#include <arch/types.h> /* arch-specific type definitions (pm_t/vm_t etc) */
diff --git a/lib/ubsan.c b/lib/ubsan.c
index f1b46d4..4ee360e 100644
--- a/lib/ubsan.c
+++ b/lib/ubsan.c
@@ -3,164 +3,319 @@
* Tiny undefined behaviour sanitizer, mostly lifted from
* https://github.com/Abb1x/tinyubsan/blob/master/src/tinyubsan.c
*
- * \todo Add in more runtime info.
+ * @todo Add in more runtime info.
+ *
+ * Note that this file's documentation is pretty vague, as I don't know the ins
+ * and outs of the undefined behaviour sanitizer subsystem.
*/
#include <apos/types.h>
#include <apos/debug.h>
-struct tu_source_location {
+/**
+ * Describes a source file location.
+ */
+struct source_location {
+ /** Filename. */
const char *file;
+ /** Line number. */
uint32_t line;
+ /** Column number. */
uint32_t column;
};
-struct tu_type_descriptor {
+/**
+ * Describes the type of undefined behaviour.
+ *
+ * Currently largely unused, @todo implement better undefined behaviour bug
+ * messages.
+ */
+struct type_descriptor {
+ /** Type kind. */
uint16_t kind;
+ /** Additional type info. */
uint16_t info;
+ /** Type name. */
char name[];
};
-struct tu_overflow_data {
- struct tu_source_location location;
- struct tu_type_descriptor *type;
+/**
+ * Describes overflows.
+ */
+struct overflow_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information. */
+ struct type_descriptor *type;
};
-struct tu_shift_out_of_bounds_data {
- struct tu_source_location location;
- struct tu_type_descriptor *left_type;
- struct tu_type_descriptor *right_type;
+/**
+ * Describes out of bounds shifts.
+ */
+struct shift_out_of_bounds_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information #1 */
+ struct type_descriptor *left_type;
+ /** Extra information #2 */
+ struct type_descriptor *right_type;
};
-struct tu_invalid_value_data {
- struct tu_source_location location;
- struct tu_type_descriptor *type;
+/**
+ * Describes invalid values.
+ */
+struct invalid_value_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information. */
+ struct type_descriptor *type;
};
-struct tu_array_out_of_bounds_data {
- struct tu_source_location location;
- struct tu_type_descriptor *array_type;
- struct tu_type_descriptor *index_type;
+/**
+ * Describes out of bounds array accesses.
+ */
+struct array_out_of_bounds_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Information about the array. */
+ struct type_descriptor *array_type;
+ /** Information about the access. */
+ struct type_descriptor *index_type;
};
-struct tu_type_mismatch_v1_data {
- struct tu_source_location location;
- struct tu_type_descriptor *type;
+/**
+ * Describes mismatched types. Incorrect pointers at least, possibly other stuff
+ * as well.
+ */
+struct type_mismatch_v1_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information. */
+ struct type_descriptor *type;
+ /** Alignment. */
unsigned char log_alignment;
+ /** Kind (?). */
unsigned char type_check_kind;
};
-struct tu_negative_vla_data {
- struct tu_source_location location;
- struct tu_type_descriptor *type;
+/**
+ * Describes negative VLAs. Note that this kernel explicitly disallows VLAs,
+ * as does the Linux kernel.
+ */
+struct negative_vla_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information. */
+ struct type_descriptor *type;
};
-struct tu_nonnull_return_data {
- struct tu_source_location location;
+/**
+ * Describes nonnull return. A function is marked with nonnull, but still
+ * returns null.
+ */
+struct nonnull_return_data {
+ /** Corresponding source location. */
+ struct source_location location;
};
-struct tu_nonnull_arg_data {
- struct tu_source_location location;
+/**
+ * Describes nonnull arguments. Situations where an argument is marked with
+ * __attribute__("null"), but is given a value.
+ */
+struct nonnull_arg_data {
+ /** Corresponding source location. */
+ struct source_location location;
};
-struct tu_unreachable_data {
- struct tu_source_location location;
+/**
+ * Describes unreachable conditions. Mainly for __builtin_unreachable().
+ */
+struct unreachable_data {
+ /** Corresponding source location. */
+ struct source_location location;
};
-struct tu_invalid_builtin_data {
- struct tu_source_location location;
+/**
+ * Describes invalid builtin data. Incorrect usage of __builtin_*().
+ */
+struct invalid_builtin_data {
+ /** Corresponding source location. */
+ struct source_location location;
+ /** Extra information (?) */
unsigned char kind;
};
-static void tu_print_location(const char *message,
- struct tu_source_location loc)
+/**
+ * Wrapper around \ref bug(). Prepends location information to the message.
+ *
+ * @param message Message to be printed.
+ * @param loc Location information.
+ */
+static void print_location(const char *message,
+ struct source_location loc)
{
bug("ubsan: %s at file %s, line %ju, column %ju\n", message, loc.file,
(uintmax_t)loc.line, (uintmax_t)loc.column);
}
-void __ubsan_handle_add_overflow(struct tu_overflow_data *data)
+/**
+ * Handle overflow during addition.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_add_overflow(struct overflow_data *data)
{
- tu_print_location("addition overflow", data->location);
+ print_location("addition overflow", data->location);
}
-void __ubsan_handle_sub_overflow(struct tu_overflow_data *data)
+/**
+ * Handle overflow during subtraction.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_sub_overflow(struct overflow_data *data)
{
- tu_print_location("subtraction overflow", data->location);
+ print_location("subtraction overflow", data->location);
}
-void __ubsan_handle_mul_overflow(struct tu_overflow_data *data)
+/**
+ * Handle overflow during multiplication.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_mul_overflow(struct overflow_data *data)
{
- tu_print_location("multiplication overflow", data->location);
+ print_location("multiplication overflow", data->location);
}
-void __ubsan_handle_divrem_overflow(struct tu_overflow_data *data)
+/**
+ * Handle overflow during division or taking a remainder.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_divrem_overflow(struct overflow_data *data)
{
- tu_print_location("division overflow", data->location);
+ print_location("division overflow", data->location);
}
-void __ubsan_handle_negate_overflow(struct tu_overflow_data *data)
+/**
+ * Handle overflow during negation.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_negate_overflow(struct overflow_data *data)
{
- tu_print_location("negation overflow", data->location);
+ print_location("negation overflow", data->location);
}
-void __ubsan_handle_pointer_overflow(struct tu_overflow_data *data)
+/**
+ * Handle pointer overflow.
+ *
+ * @param data Overflow information, generated by the compiler.
+ */
+void __ubsan_handle_pointer_overflow(struct overflow_data *data)
{
- tu_print_location("pointer overflow", data->location);
+ print_location("pointer overflow", data->location);
}
+/**
+ * Handle out of bounds shifts.
+ *
+ * @param data Out of bounds information, generated by the compiler.
+ */
void __ubsan_handle_shift_out_of_bounds(
- struct tu_shift_out_of_bounds_data *data)
+ struct shift_out_of_bounds_data *data)
{
- tu_print_location("shift out of bounds", data->location);
+ print_location("shift out of bounds", data->location);
}
-void __ubsan_handle_load_invalid_value(struct tu_invalid_value_data *data)
+/**
+ * Handle invalid load values.
+ *
+ * @param data Load information, generated by the compiler.
+ */
+void __ubsan_handle_load_invalid_value(struct invalid_value_data *data)
{
- tu_print_location("invalid load value", data->location);
+ print_location("invalid load value", data->location);
}
-void __ubsan_handle_out_of_bounds(struct tu_array_out_of_bounds_data *data)
+/**
+ * Handle array out of bounds accesses.
+ *
+ * @param data Out of bounds information, generated by the compiler.
+ */
+void __ubsan_handle_out_of_bounds(struct array_out_of_bounds_data *data)
{
- tu_print_location("array out of bounds", data->location);
+ print_location("array out of bounds", data->location);
}
-void __ubsan_handle_type_mismatch_v1(struct tu_type_mismatch_v1_data *data,
+/**
+ * Handle type mismatch, one format.
+ *
+ * @param data Type mismatch information, generated by the compiler.
+ * @param ptr Pointer that caused a mismatch.
+ */
+void __ubsan_handle_type_mismatch_v1(struct type_mismatch_v1_data *data,
uintptr_t ptr)
{
if (!ptr) {
- tu_print_location("use of NULL pointer", data->location);
+ print_location("use of NULL pointer", data->location);
}
else if (ptr & ((1 << data->log_alignment) - 1)) {
- tu_print_location("use of misaligned pointer", data->location);
+ print_location("use of misaligned pointer", data->location);
} else {
- tu_print_location("no space for object", data->location);
+ print_location("no space for object", data->location);
}
}
-void __ubsan_handle_vla_bound_not_positive(struct tu_negative_vla_data *data)
+/**
+ * Handle negative VLA.
+ *
+ * @param data VLA information, generated by the compiler.
+ */
+void __ubsan_handle_vla_bound_not_positive(struct negative_vla_data *data)
{
- tu_print_location("variable-length argument is negative",
- data->location);
+ print_location("variable-length argument is negative",
+ data->location);
}
-void __ubsan_handle_nonnull_return(struct tu_nonnull_return_data *data)
+/**
+ * Handle nonnull return.
+ *
+ * @param data Return information, generated by compiler.
+ */
+void __ubsan_handle_nonnull_return(struct nonnull_return_data *data)
{
- tu_print_location("non-null return is null", data->location);
+ print_location("non-null return is null", data->location);
}
-void __ubsan_handle_nonnull_arg(struct tu_nonnull_arg_data *data)
+/**
+ * Handle nonnull argument.
+ *
+ * @param data Argument information, generated by compiler.
+ */
+void __ubsan_handle_nonnull_arg(struct nonnull_arg_data *data)
{
- tu_print_location("non-null argument is null", data->location);
+ print_location("non-null argument is null", data->location);
}
-void __ubsan_handle_builtin_unreachable(struct tu_unreachable_data *data)
+/**
+ * Handle unreachable code.
+ *
+ * @param data Unreachable code information, generated by compiler.
+ */
+void __ubsan_handle_builtin_unreachable(struct unreachable_data *data)
{
- tu_print_location("unreachable code reached", data->location);
+ print_location("unreachable code reached", data->location);
}
-void __ubsan_handle_invalid_builtin(struct tu_invalid_builtin_data *data)
+/**
+ * Handle invalid builtin.
+ *
+ * @param data Builtin information, generated by compiler.
+ */
+void __ubsan_handle_invalid_builtin(struct invalid_builtin_data *data)
{
- tu_print_location("invalid builtin", data->location);
+ print_location("invalid builtin", data->location);
}