From d4f06b4538c4265ed1d66cce8677730bef75b191 Mon Sep 17 00:00:00 2001 From: kamkow1 Date: Sun, 10 Aug 2025 22:24:30 +0200 Subject: [PATCH] Freestanding headers --- kernel/Makefile | 3 +- kernel/std/LICENSE | 12 ++ kernel/std/README | 3 + kernel/std/include/float.h | 124 ++++++++++++++ kernel/std/include/iso646.h | 45 +++++ kernel/std/include/limits.h | 93 +++++++++++ kernel/std/include/stdalign.h | 36 ++++ kernel/std/include/stdarg.h | 35 ++++ kernel/std/include/stdatomic.h | 22 +++ kernel/std/include/stdbool.h | 37 +++++ kernel/std/include/stddef.h | 51 ++++++ kernel/std/include/stdint.h | 274 +++++++++++++++++++++++++++++++ kernel/std/include/stdnoreturn.h | 24 +++ 13 files changed, 758 insertions(+), 1 deletion(-) create mode 100644 kernel/std/LICENSE create mode 100644 kernel/std/README create mode 100644 kernel/std/include/float.h create mode 100644 kernel/std/include/iso646.h create mode 100644 kernel/std/include/limits.h create mode 100644 kernel/std/include/stdalign.h create mode 100644 kernel/std/include/stdarg.h create mode 100644 kernel/std/include/stdatomic.h create mode 100644 kernel/std/include/stdbool.h create mode 100644 kernel/std/include/stddef.h create mode 100644 kernel/std/include/stdint.h create mode 100644 kernel/std/include/stdnoreturn.h diff --git a/kernel/Makefile b/kernel/Makefile index 8e03705..6fded82 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -2,10 +2,11 @@ ARCH ?= x86_64 -CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon +CFLAGS := -ffreestanding -Wall -Wextra -g -fcommon -nostdinc CFLAGS += -I. \ -I../limine \ + -I./std/include \ -DPRINTF_INCLUDE_CONFIG_H=1 LDFLAGS := -nostdlib -static -T arch/$(ARCH)/link.ld diff --git a/kernel/std/LICENSE b/kernel/std/LICENSE new file mode 100644 index 0000000..9283378 --- /dev/null +++ b/kernel/std/LICENSE @@ -0,0 +1,12 @@ +Copyright (C) 2022-2025 Mintsuki and contributors. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND +FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/kernel/std/README b/kernel/std/README new file mode 100644 index 0000000..319e688 --- /dev/null +++ b/kernel/std/README @@ -0,0 +1,3 @@ +This is a collection of 0BSD-licensed freestanding C headers, for use with GCC or Clang. + +kamkow1: Added stdatomic.h diff --git a/kernel/std/include/float.h b/kernel/std/include/float.h new file mode 100644 index 0000000..73e2a73 --- /dev/null +++ b/kernel/std/include/float.h @@ -0,0 +1,124 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_FLOAT_H +#define __FREESTND_C_HDRS_FLOAT_H 1 + +#undef FLT_ROUNDS +#define FLT_ROUNDS 1 + +#undef FLT_RADIX +#define FLT_RADIX __FLT_RADIX__ + +#undef FLT_MANT_DIG +#define FLT_MANT_DIG __FLT_MANT_DIG__ +#undef DBL_MANT_DIG +#define DBL_MANT_DIG __DBL_MANT_DIG__ +#undef LDBL_MANT_DIG +#define LDBL_MANT_DIG __LDBL_MANT_DIG__ + +#if (defined(__cplusplus) && __cplusplus >= 201103L) \ + || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) + +#undef DECIMAL_DIG +#define DECIMAL_DIG __DECIMAL_DIG__ + +#undef FLT_EVAL_METHOD +#define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ + +#endif + +#undef FLT_DIG +#define FLT_DIG __FLT_DIG__ +#undef DBL_DIG +#define DBL_DIG __DBL_DIG__ +#undef LDBL_DIG +#define LDBL_DIG __LDBL_DIG__ + +#undef FLT_MIN_EXP +#define FLT_MIN_EXP __FLT_MIN_EXP__ +#undef DBL_MIN_EXP +#define DBL_MIN_EXP __DBL_MIN_EXP__ +#undef LDBL_MIN_EXP +#define LDBL_MIN_EXP __LDBL_MIN_EXP__ + +#undef FLT_MIN_10_EXP +#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ +#undef DBL_MIN_10_EXP +#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ +#undef LDBL_MIN_10_EXP +#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ + +#undef FLT_MAX_EXP +#define FLT_MAX_EXP __FLT_MAX_EXP__ +#undef DBL_MAX_EXP +#define DBL_MAX_EXP __DBL_MAX_EXP__ +#undef LDBL_MAX_EXP +#define LDBL_MAX_EXP __LDBL_MAX_EXP__ + +#undef FLT_MAX_10_EXP +#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ +#undef DBL_MAX_10_EXP +#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ +#undef LDBL_MAX_10_EXP +#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ + +#undef FLT_MAX +#define FLT_MAX __FLT_MAX__ +#undef DBL_MAX +#define DBL_MAX __DBL_MAX__ +#undef LDBL_MAX +#define LDBL_MAX __LDBL_MAX__ + +#undef FLT_EPSILON +#define FLT_EPSILON __FLT_EPSILON__ +#undef DBL_EPSILON +#define DBL_EPSILON __DBL_EPSILON__ +#undef LDBL_EPSILON +#define LDBL_EPSILON __LDBL_EPSILON__ + +#undef FLT_MIN +#define FLT_MIN __FLT_MIN__ +#undef DBL_MIN +#define DBL_MIN __DBL_MIN__ +#undef LDBL_MIN +#define LDBL_MIN __LDBL_MIN__ + +#if (defined(__cplusplus) && __cplusplus >= 201703L) \ + || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) + +#undef FLT_DECIMAL_DIG +#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__ +#undef DBL_DECIMAL_DIG +#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__ +#undef LDBL_DECIMAL_DIG +#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ + +#undef FLT_TRUE_MIN +#define FLT_TRUE_MIN __FLT_DENORM_MIN__ +#undef DBL_TRUE_MIN +#define DBL_TRUE_MIN __DBL_DENORM_MIN__ +#undef LDBL_TRUE_MIN +#define LDBL_TRUE_MIN __LDBL_DENORM_MIN__ + +#undef FLT_HAS_SUBNORM +#define FLT_HAS_SUBNORM __FLT_HAS_DENORM__ +#undef DBL_HAS_SUBNORM +#define DBL_HAS_SUBNORM __DBL_HAS_DENORM__ +#undef LDBL_HAS_SUBNORM +#define LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__ + +#endif + +#endif diff --git a/kernel/std/include/iso646.h b/kernel/std/include/iso646.h new file mode 100644 index 0000000..4a04204 --- /dev/null +++ b/kernel/std/include/iso646.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_ISO646_H +#define __FREESTND_C_HDRS_ISO646_H 1 + +#ifndef __cplusplus + +#undef and +#define and && +#undef and_eq +#define and_eq &= +#undef bitand +#define bitand & +#undef bitor +#define bitor | +#undef compl +#define compl ~ +#undef not +#define not ! +#undef not_eq +#define not_eq != +#undef or +#define or || +#undef or_eq +#define or_eq |= +#undef xor +#define xor ^ +#undef xor_eq +#define xor_eq ^= + +#endif + +#endif diff --git a/kernel/std/include/limits.h b/kernel/std/include/limits.h new file mode 100644 index 0000000..82c2dcc --- /dev/null +++ b/kernel/std/include/limits.h @@ -0,0 +1,93 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_LIMITS_H +#define __FREESTND_C_HDRS_LIMITS_H 1 + +#undef CHAR_BIT +#define CHAR_BIT __CHAR_BIT__ + +#ifndef MB_LEN_MAX +# define MB_LEN_MAX 1 +#endif + +#undef SCHAR_MAX +#define SCHAR_MAX __SCHAR_MAX__ +#undef SCHAR_MIN +#define SCHAR_MIN (-SCHAR_MAX - 1) + +#undef UCHAR_MAX +#if __SCHAR_MAX__ == __INT_MAX__ +# define UCHAR_MAX (SCHAR_MAX * 2U + 1U) +#else +# define UCHAR_MAX (SCHAR_MAX * 2 + 1) +#endif + +#ifdef __CHAR_UNSIGNED__ +# undef CHAR_MAX +# define CHAR_MAX UCHAR_MAX +# undef CHAR_MIN +# if __SCHAR_MAX__ == __INT_MAX__ +# define CHAR_MIN 0U +# else +# define CHAR_MIN 0 +# endif +#else +# undef CHAR_MAX +# define CHAR_MAX SCHAR_MAX +# undef CHAR_MIN +# define CHAR_MIN SCHAR_MIN +#endif + +#undef SHRT_MAX +#define SHRT_MAX __SHRT_MAX__ +#undef SHRT_MIN +#define SHRT_MIN (-SHRT_MAX - 1) + +#undef USHRT_MAX +#if __SHRT_MAX__ == __INT_MAX__ +# define USHRT_MAX (SHRT_MAX * 2U + 1U) +#else +# define USHRT_MAX (SHRT_MAX * 2 + 1) +#endif + +#undef INT_MAX +#define INT_MAX __INT_MAX__ +#undef INT_MIN +#define INT_MIN (-INT_MAX - 1) + +#undef UINT_MAX +#define UINT_MAX (INT_MAX * 2U + 1U) + +#undef LONG_MAX +#define LONG_MAX __LONG_MAX__ +#undef LONG_MIN +#define LONG_MIN (-LONG_MAX - 1L) + +#undef ULONG_MAX +#define ULONG_MAX (LONG_MAX * 2UL + 1UL) + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +#undef LLONG_MAX +#define LLONG_MAX __LONG_LONG_MAX__ +#undef LLONG_MIN +#define LLONG_MIN (-LLONG_MAX - 1LL) + +#undef ULLONG_MAX +#define ULLONG_MAX (LLONG_MAX * 2ULL + 1ULL) + +#endif + +#endif diff --git a/kernel/std/include/stdalign.h b/kernel/std/include/stdalign.h new file mode 100644 index 0000000..1483ae3 --- /dev/null +++ b/kernel/std/include/stdalign.h @@ -0,0 +1,36 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDALIGN_H +#define __FREESTND_C_HDRS_STDALIGN_H 1 + +#ifndef __cplusplus + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L + /* These do not need to be defined for C23+ */ +#else +# undef alignas +# define alignas _Alignas +# undef alignof +# define alignof _Alignof + +# undef __alignof_is_defined +# define __alignof_is_defined 1 +# undef __alignas_is_defined +# define __alignas_is_defined 1 +#endif + +#endif + +#endif diff --git a/kernel/std/include/stdarg.h b/kernel/std/include/stdarg.h new file mode 100644 index 0000000..ac21968 --- /dev/null +++ b/kernel/std/include/stdarg.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDARG_H +#define __FREESTND_C_HDRS_STDARG_H 1 + +typedef __builtin_va_list va_list; + +#undef va_start +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L +# define va_start(v, ...) __builtin_va_start(v, 0) +#else +# define va_start(v, l) __builtin_va_start(v, l) +#endif +#undef va_end +#define va_end(v) __builtin_va_end(v) +#undef va_arg +#define va_arg(v, l) __builtin_va_arg(v, l) +#if (defined(__cplusplus) && (__cplusplus >= 201103L)) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) +# undef va_copy +# define va_copy(d, s) __builtin_va_copy(d, s) +#endif + +#endif diff --git a/kernel/std/include/stdatomic.h b/kernel/std/include/stdatomic.h new file mode 100644 index 0000000..32f21d3 --- /dev/null +++ b/kernel/std/include/stdatomic.h @@ -0,0 +1,22 @@ +#ifndef __FREESTND_C_HDRS_STDATOMIC_H +#define __FREESTND_C_HDRS_STDATOMIC_H + +#define memory_order_relaxed __ATOMIC_RELAXED +#define memory_order_consume __ATOMIC_CONSUME +#define memory_order_acquire __ATOMIC_ACQUIRE +#define memory_order_release __ATOMIC_RELEASE +#define memory_order_acq_rel __ATOMIC_ACQ_REL +#define memory_order_seq_cst __ATOMIC_SEQ_CST + +#define atomic_load_explicit __atomic_load_n +#define atomic_store_explicit __atomic_store_n + +#define atomic_store(p, v) atomic_store_explicit(p, v, memory_order_relaxed) +#define atomic_load(p, v) atomic_load_explicit(p, v, memory_order_relaxed) + +#define atomic_compare_exchange_weak(p, old, new) \ + __atomic_compare_exchange_n(p, old, new, true, memory_order_relaxed, memory_order_relaxed) + +#define atomic_bool volatile bool + +#endif diff --git a/kernel/std/include/stdbool.h b/kernel/std/include/stdbool.h new file mode 100644 index 0000000..75140c1 --- /dev/null +++ b/kernel/std/include/stdbool.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDBOOL_H +#define __FREESTND_C_HDRS_STDBOOL_H 1 + +#ifndef __cplusplus + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L + /* These do not need to be defined for C23+ */ +#else +# undef bool +# define bool _Bool + +# undef true +# define true 1 +# undef false +# define false 0 +#endif + +#endif + +#undef __bool_true_false_are_defined +#define __bool_true_false_are_defined 1 + +#endif diff --git a/kernel/std/include/stddef.h b/kernel/std/include/stddef.h new file mode 100644 index 0000000..9d82577 --- /dev/null +++ b/kernel/std/include/stddef.h @@ -0,0 +1,51 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDDEF_H +#define __FREESTND_C_HDRS_STDDEF_H 1 + +typedef __SIZE_TYPE__ size_t; +typedef __PTRDIFF_TYPE__ ptrdiff_t; + +#ifndef __cplusplus +typedef __WCHAR_TYPE__ wchar_t; + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L +typedef typeof(nullptr) nullptr_t; +#endif + +#endif + +#ifdef __cplusplus +typedef decltype(nullptr) nullptr_t; +#endif + +#undef NULL +#ifndef __cplusplus +# define NULL ((void *)0) +#else +# define NULL 0 +#endif + +#undef offsetof +#define offsetof(s, m) __builtin_offsetof(s, m) + +#if defined(__STDC_VERSION__) && __STDC_VERSION__ > 201710L +# undef unreachable +# define unreachable() __builtin_unreachable() + +# define __STDC_VERSION_STDDEF_H__ 202311L +#endif + +#endif diff --git a/kernel/std/include/stdint.h b/kernel/std/include/stdint.h new file mode 100644 index 0000000..07f33ed --- /dev/null +++ b/kernel/std/include/stdint.h @@ -0,0 +1,274 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDINT_H +#define __FREESTND_C_HDRS_STDINT_H 1 + +#ifdef __UINT8_TYPE__ +typedef __UINT8_TYPE__ uint8_t; +#endif +#ifdef __UINT16_TYPE__ +typedef __UINT16_TYPE__ uint16_t; +#endif +#ifdef __UINT32_TYPE__ +typedef __UINT32_TYPE__ uint32_t; +#endif +#ifdef __UINT64_TYPE__ +typedef __UINT64_TYPE__ uint64_t; +#endif + +typedef __UINT_LEAST8_TYPE__ uint_least8_t; +typedef __UINT_LEAST16_TYPE__ uint_least16_t; +typedef __UINT_LEAST32_TYPE__ uint_least32_t; +typedef __UINT_LEAST64_TYPE__ uint_least64_t; + +typedef __UINT_FAST8_TYPE__ uint_fast8_t; +typedef __UINT_FAST16_TYPE__ uint_fast16_t; +typedef __UINT_FAST32_TYPE__ uint_fast32_t; +typedef __UINT_FAST64_TYPE__ uint_fast64_t; + +#ifdef __INT8_TYPE__ +typedef __INT8_TYPE__ int8_t; +#endif +#ifdef __INT16_TYPE__ +typedef __INT16_TYPE__ int16_t; +#endif +#ifdef __INT32_TYPE__ +typedef __INT32_TYPE__ int32_t; +#endif +#ifdef __INT64_TYPE__ +typedef __INT64_TYPE__ int64_t; +#endif + +typedef __INT_LEAST8_TYPE__ int_least8_t; +typedef __INT_LEAST16_TYPE__ int_least16_t; +typedef __INT_LEAST32_TYPE__ int_least32_t; +typedef __INT_LEAST64_TYPE__ int_least64_t; + +typedef __INT_FAST8_TYPE__ int_fast8_t; +typedef __INT_FAST16_TYPE__ int_fast16_t; +typedef __INT_FAST32_TYPE__ int_fast32_t; +typedef __INT_FAST64_TYPE__ int_fast64_t; + +#ifdef __UINTPTR_TYPE__ +typedef __UINTPTR_TYPE__ uintptr_t; +#endif +#ifdef __INTPTR_TYPE__ +typedef __INTPTR_TYPE__ intptr_t; +#endif + +typedef __UINTMAX_TYPE__ uintmax_t; +typedef __INTMAX_TYPE__ intmax_t; + +/* Clang and GCC have different mechanisms for INT32_C and friends. */ +#ifdef __clang__ +# ifndef __FREESTND_C_HDRS_C_JOIN +# define __FREESTND_C_HDRS_C_EXPAND_JOIN(x, suffix) x ## suffix +# define __FREESTND_C_HDRS_C_JOIN(x, suffix) __FREESTND_C_HDRS_C_EXPAND_JOIN(x, suffix) +# endif + +# undef INT8_C +# define INT8_C(x) __FREESTND_C_HDRS_C_JOIN(x, __INT8_C_SUFFIX__) +# undef INT16_C +# define INT16_C(x) __FREESTND_C_HDRS_C_JOIN(x, __INT16_C_SUFFIX__) +# undef INT32_C +# define INT32_C(x) __FREESTND_C_HDRS_C_JOIN(x, __INT32_C_SUFFIX__) +# undef INT64_C +# define INT64_C(x) __FREESTND_C_HDRS_C_JOIN(x, __INT64_C_SUFFIX__) + +# undef UINT8_C +# define UINT8_C(x) __FREESTND_C_HDRS_C_JOIN(x, __UINT8_C_SUFFIX__) +# undef UINT16_C +# define UINT16_C(x) __FREESTND_C_HDRS_C_JOIN(x, __UINT16_C_SUFFIX__) +# undef UINT32_C +# define UINT32_C(x) __FREESTND_C_HDRS_C_JOIN(x, __UINT32_C_SUFFIX__) +# undef UINT64_C +# define UINT64_C(x) __FREESTND_C_HDRS_C_JOIN(x, __UINT64_C_SUFFIX__) + +# undef INTMAX_C +# define INTMAX_C(x) __FREESTND_C_HDRS_C_JOIN(x, __INTMAX_C_SUFFIX__) +# undef UINTMAX_C +# define UINTMAX_C(x) __FREESTND_C_HDRS_C_JOIN(x, __UINTMAX_C_SUFFIX__) +#else +# undef INT8_C +# define INT8_C(x) __INT8_C(x) +# undef INT16_C +# define INT16_C(x) __INT16_C(x) +# undef INT32_C +# define INT32_C(x) __INT32_C(x) +# undef INT64_C +# define INT64_C(x) __INT64_C(x) + +# undef UINT8_C +# define UINT8_C(x) __UINT8_C(x) +# undef UINT16_C +# define UINT16_C(x) __UINT16_C(x) +# undef UINT32_C +# define UINT32_C(x) __UINT32_C(x) +# undef UINT64_C +# define UINT64_C(x) __UINT64_C(x) + +# undef INTMAX_C +# define INTMAX_C(x) __INTMAX_C(x) +# undef UINTMAX_C +# define UINTMAX_C(x) __UINTMAX_C(x) +#endif + +#ifdef __UINT8_MAX__ +# undef UINT8_MAX +# define UINT8_MAX __UINT8_MAX__ +#endif +#ifdef __UINT16_MAX__ +# undef UINT16_MAX +# define UINT16_MAX __UINT16_MAX__ +#endif +#ifdef __UINT32_MAX__ +# undef UINT32_MAX +# define UINT32_MAX __UINT32_MAX__ +#endif +#ifdef __UINT64_MAX__ +# undef UINT64_MAX +# define UINT64_MAX __UINT64_MAX__ +#endif + +#ifdef __INT8_MAX__ +# undef INT8_MAX +# define INT8_MAX __INT8_MAX__ +#endif +#ifdef __INT16_MAX__ +# undef INT16_MAX +# define INT16_MAX __INT16_MAX__ +#endif +#ifdef __INT32_MAX__ +# undef INT32_MAX +# define INT32_MAX __INT32_MAX__ +#endif +#ifdef __INT64_MAX__ +# undef INT64_MAX +# define INT64_MAX __INT64_MAX__ +#endif + +#ifdef __INT8_MAX__ +# undef INT8_MIN +# define INT8_MIN (-INT8_MAX - 1) +#endif +#ifdef __INT16_MAX__ +# undef INT16_MIN +# define INT16_MIN (-INT16_MAX - 1) +#endif +#ifdef __INT32_MAX__ +# undef INT32_MIN +# define INT32_MIN (-INT32_MAX - 1) +#endif +#ifdef __INT64_MAX__ +# undef INT64_MIN +# define INT64_MIN (-INT64_MAX - 1) +#endif + +#undef UINT_LEAST8_MAX +#define UINT_LEAST8_MAX __UINT_LEAST8_MAX__ +#undef UINT_LEAST16_MAX +#define UINT_LEAST16_MAX __UINT_LEAST16_MAX__ +#undef UINT_LEAST32_MAX +#define UINT_LEAST32_MAX __UINT_LEAST32_MAX__ +#undef UINT_LEAST64_MAX +#define UINT_LEAST64_MAX __UINT_LEAST64_MAX__ + +#undef INT_LEAST8_MAX +#define INT_LEAST8_MAX __INT_LEAST8_MAX__ +#undef INT_LEAST16_MAX +#define INT_LEAST16_MAX __INT_LEAST16_MAX__ +#undef INT_LEAST32_MAX +#define INT_LEAST32_MAX __INT_LEAST32_MAX__ +#undef INT_LEAST64_MAX +#define INT_LEAST64_MAX __INT_LEAST64_MAX__ + +#undef INT_LEAST8_MIN +#define INT_LEAST8_MIN (-INT_LEAST8_MAX - 1) +#undef INT_LEAST16_MIN +#define INT_LEAST16_MIN (-INT_LEAST16_MAX - 1) +#undef INT_LEAST32_MIN +#define INT_LEAST32_MIN (-INT_LEAST32_MAX - 1) +#undef INT_LEAST64_MIN +#define INT_LEAST64_MIN (-INT_LEAST64_MAX - 1) + +#undef UINT_FAST8_MAX +#define UINT_FAST8_MAX __UINT_FAST8_MAX__ +#undef UINT_FAST16_MAX +#define UINT_FAST16_MAX __UINT_FAST16_MAX__ +#undef UINT_FAST32_MAX +#define UINT_FAST32_MAX __UINT_FAST32_MAX__ +#undef UINT_FAST64_MAX +#define UINT_FAST64_MAX __UINT_FAST64_MAX__ + +#undef INT_FAST8_MAX +#define INT_FAST8_MAX __INT_FAST8_MAX__ +#undef INT_FAST16_MAX +#define INT_FAST16_MAX __INT_FAST16_MAX__ +#undef INT_FAST32_MAX +#define INT_FAST32_MAX __INT_FAST32_MAX__ +#undef INT_FAST64_MAX +#define INT_FAST64_MAX __INT_FAST64_MAX__ + +#undef INT_FAST8_MIN +#define INT_FAST8_MIN (-INT_FAST8_MAX - 1) +#undef INT_FAST16_MIN +#define INT_FAST16_MIN (-INT_FAST16_MAX - 1) +#undef INT_FAST32_MIN +#define INT_FAST32_MIN (-INT_FAST32_MAX - 1) +#undef INT_FAST64_MIN +#define INT_FAST64_MIN (-INT_FAST64_MAX - 1) + +#ifdef __UINTPTR_MAX__ +# undef UINTPTR_MAX +# define UINTPTR_MAX __UINTPTR_MAX__ +#endif +#ifdef __INTPTR_MAX__ +# undef INTPTR_MAX +# define INTPTR_MAX __INTPTR_MAX__ +# undef INTPTR_MIN +# define INTPTR_MIN (-INTPTR_MAX - 1) +#endif + +#undef UINTMAX_MAX +#define UINTMAX_MAX __UINTMAX_MAX__ +#undef INTMAX_MAX +#define INTMAX_MAX __INTMAX_MAX__ +#undef INTMAX_MIN +#define INTMAX_MIN (-INTMAX_MAX - 1) + +#undef PTRDIFF_MAX +#define PTRDIFF_MAX __PTRDIFF_MAX__ +#undef PTRDIFF_MIN +#define PTRDIFF_MIN (-PTRDIFF_MAX - 1) + +#undef SIG_ATOMIC_MAX +#define SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ +#undef SIG_ATOMIC_MIN +#define SIG_ATOMIC_MIN (-SIG_ATOMIC_MAX - 1) + +#undef SIZE_MAX +#define SIZE_MAX __SIZE_MAX__ + +#undef WCHAR_MAX +#define WCHAR_MAX __WCHAR_MAX__ +#undef WCHAR_MIN +#define WCHAR_MIN (-WCHAR_MAX - 1) + +#undef WINT_MAX +#define WINT_MAX __WINT_MAX__ +#undef WINT_MIN +#define WINT_MIN (-WINT_MAX - 1) + +#endif diff --git a/kernel/std/include/stdnoreturn.h b/kernel/std/include/stdnoreturn.h new file mode 100644 index 0000000..b5c2671 --- /dev/null +++ b/kernel/std/include/stdnoreturn.h @@ -0,0 +1,24 @@ +/* Copyright (C) 2022-2025 Mintsuki and contributors. + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY + * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION + * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __FREESTND_C_HDRS_STDNORETURN_H +#define __FREESTND_C_HDRS_STDNORETURN_H 1 + +#ifndef __cplusplus + +#define noreturn _Noreturn + +#endif + +#endif