summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/include/stdarg.h92
-rw-r--r--lib/libc/include/stdatomic.h119
-rw-r--r--lib/libc/include/stddef.h149
-rw-r--r--lib/libc/src/hyra/mmap.c47
4 files changed, 402 insertions, 5 deletions
diff --git a/lib/libc/include/stdarg.h b/lib/libc/include/stdarg.h
new file mode 100644
index 0000000..dc75475
--- /dev/null
+++ b/lib/libc/include/stdarg.h
@@ -0,0 +1,92 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _STDARG_H
+#define _STDARG_H 1
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define __STDC_VERSION_STDARG_H__ 202311L
+#endif
+
+/* Determine which definitions are needed */
+#if !defined(__need___va_list) && !defined(__need_va_list) && \
+ !defined(__need_va_arg) && \
+ !defined(__need___va_copy) && !defined(__need_va_copy)
+#define __need___va_list
+#define __need_va_list
+#define __need_va_arg
+#define __need___va_copy
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || (defined(__cplusplus) && __cplusplus >= 201103L)
+#define __need_va_copy
+#endif
+#endif
+
+/* __gnuc_va_list type */
+#ifdef __need___va_list
+#ifndef __GNUC_VA_LIST
+#define __GNUC_VA_LIST
+typedef __builtin_va_list __gnuc_va_list;
+#endif /* !__GNUC_VA_LIST */
+#undef __need___va_list
+#endif /* __need___va_list */
+
+/* va_list type */
+#ifdef __need_va_list
+#ifndef _VA_LIST
+#define _VA_LIST
+typedef __builtin_va_list va_list;
+#endif /* !_VA_LIST */
+#undef __need_va_list
+#endif /* __need_va_list */
+
+/* va_start(), va_end(), and va_arg() macros */
+#ifdef __need_va_arg
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define va_start(ap, ...) __builtin_va_start(ap, 0)
+#else
+#define va_start(ap, arg) __builtin_va_start(ap, arg)
+#endif
+#define va_end(ap) __builtin_va_end(ap)
+#define va_arg(ap, type) __builtin_va_arg(ap, type)
+#undef __need_va_arg
+#endif /* __need_va_arg */
+
+/* __va_copy() macro */
+#ifdef __need___va_copy
+#define __va_copy(dest, src) __builtin_va_copy(dest, src)
+#undef __need___va_copy
+#endif /* __need___va_copy */
+
+/* va_copy() macro */
+#ifdef __need_va_copy
+#define va_copy(dest, src) __builtin_va_copy(dest, src)
+#undef __need_va_copy
+#endif /* __need_va_copy */
+
+#endif /* !_STDARG_H */
diff --git a/lib/libc/include/stdatomic.h b/lib/libc/include/stdatomic.h
new file mode 100644
index 0000000..3f80270
--- /dev/null
+++ b/lib/libc/include/stdatomic.h
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _STDATOMIC_H
+#define _STDATOMIC_H 1
+
+#include <stddef.h>
+#include <stdint.h>
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define __STDC_VERSION_STDATOMIC_H__ 202311L
+#endif
+
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L
+
+#define kill_dependency(y) (y)
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ < 202311L) || defined(__cplusplus)
+/* Deprecated in C17, removed in C23 */
+#define ATOMIC_VAR_INIT(value) (value)
+#endif
+
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || defined(__cplusplus)
+#define ATOMIC_FLAG_INIT { false }
+typedef _Atomic(bool) atomic_bool;
+#else
+#define ATOMIC_FLAG_INIT { 0 }
+typedef _Atomic(_Bool) atomic_bool;
+#endif
+
+typedef _Atomic(signed char) atomic_schar;
+
+typedef _Atomic(char) atomic_char;
+typedef _Atomic(short) atomic_short;
+typedef _Atomic(int) atomic_int;
+typedef _Atomic(long) atomic_long;
+typedef _Atomic(long long) atomic_llong;
+
+typedef _Atomic(unsigned char) atomic_uchar;
+typedef _Atomic(unsigned short) atomic_ushort;
+typedef _Atomic(unsigned int) atomic_uint;
+typedef _Atomic(unsigned long) atomic_ulong;
+typedef _Atomic(unsigned long long) atomic_ullong;
+
+typedef _Atomic(uintptr_t) atomic_uintptr_t;
+typedef _Atomic(size_t) atomic_size_t;
+
+typedef struct atomic_flag {
+ atomic_bool _Value;
+} atomic_flag;
+
+typedef enum memory_order {
+ memory_order_relaxed = __ATOMIC_RELAXED,
+ memory_order_consume = __ATOMIC_CONSUME,
+ memory_order_acquire = __ATOMIC_ACQUIRE,
+ memory_order_release = __ATOMIC_RELEASE,
+ memory_order_acq_rel = __ATOMIC_ACQ_REL,
+ memory_order_seq_cst = __ATOMIC_SEQ_CST
+} memory_order;
+
+#define atomic_is_lock_free(obj) __atomic_is_lock_free(sizeof(*(obj)), 0)
+#define atomic_flag_test_and_set(obj) __atomic_test_and_set((obj), memory_order_seq_cst)
+#define atomic_flag_clear(obj) __atomic_clear((obj), memory_order_seq_cst)
+#define atomic_load(obj) __atomic_load_n((obj), memory_order_seq_cst)
+#define atomic_store(obj, desired) __atomic_store_n((obj), (desired), memory_order_seq_cst)
+#define atomic_exchange(obj, desired) __atomic_exchange_n((obj), (desired), memory_order_seq_cst)
+#define atomic_fetch_add(obj, arg) __atomic_fetch_add((obj), (arg), memory_order_seq_cst)
+#define atomic_fetch_sub(obj, arg) __atomic_fetch_sub((obj), (arg), memory_order_seq_cst)
+#define atomic_fetch_and(obj, arg) __atomic_fetch_and((obj), (arg), memory_order_seq_cst)
+#define atomic_fetch_or(obj, arg) __atomic_fetch_or((obj), (arg), memory_order_seq_cst)
+#define atomic_fetch_xor(obj, arg) __atomic_fetch_xor((obj), (arg), memory_order_seq_cst)
+
+#define atomic_signal_fence __atomic_signal_fence
+#define atomic_thread_fence __atomic_thread_fence
+#define atomic_flag_test_and_set_explicit __atomic_test_and_set
+#define atomic_flag_clear_explicit __atomic_clear
+#define atomic_load_explicit __atomic_load_n
+#define atomic_store_explicit __atomic_store_n
+#define atomic_exchange_explicit __atomic_exchange_n
+#define atomic_fetch_add_explicit __atomic_fetch_add
+#define atomic_fetch_sub_explicit __atomic_fetch_sub
+#define atomic_fetch_and_explicit __atomic_fetch_and
+#define atomic_fetch_or_explicit __atomic_fetch_or
+#define atomic_fetch_xor_explicit __atomic_fetch_xor
+
+#define atomic_compare_exchange_strong(obj, expected, desired) __atomic_compare_exchange_n((obj), (expected), (desired), false, memory_order_seq_cst, memory_order_seq_cst)
+#define atomic_compare_exchange_weak(obj, expected, desired) __atomic_compare_exchange_n((obj), (expected), (desired), true, memory_order_seq_cst, memory_order_seq_cst)
+#define atomic_compare_exchange_strong_explicit __atomic_compare_exchange_n
+#define atomic_compare_exchange_weak_explicit __atomic_compare_exchange_n
+
+#endif
+
+#endif /* !_STDATOMIC_H */
diff --git a/lib/libc/include/stddef.h b/lib/libc/include/stddef.h
index 557f69b..642f773 100644
--- a/lib/libc/include/stddef.h
+++ b/lib/libc/include/stddef.h
@@ -28,18 +28,157 @@
*/
#ifndef _STDDEF_H
-#define _STDDEF_H
+#define _STDDEF_H 1
-#include <sys/types.h>
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define __STDC_VERSION_STDDEF_H__ 202311L
+#endif
+
+/* Determine which definitions are needed */
+#if !defined(__need_NULL) && !defined(__need_nullptr_t) && \
+ !defined(__need_size_t) && !defined(__need_rsize_t) && \
+ !defined(__need_wchar_t) && !defined(__need_wint_t) && \
+ !defined(__need_ptrdiff_t) && !defined(__need_max_align_t) && \
+ !defined(__need_offsetof) && !defined(__need_unreachable)
+#define __need_NULL
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L) || defined(__cplusplus)
+#define __need_nullptr_t
+#endif
+#define __need_ptrdiff_t
+#define __need_size_t
+#if defined(__STDC_WANT_LIB_EXT1__) && __STDC_WANT_LIB_EXT1__ >= 1
+#define __need_rsize_t
+#endif
+#define __need_wchar_t
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || (defined(__cplusplus) && __cplusplus >= 201103L)
+#define __need_max_align_t
+#endif
+#define __need_offsetof
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+#define __need_unreachable
+#endif
+#endif
+/* NULL pointer constant */
+#ifdef __need_NULL
+#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
-#elif defined(__cplusplus)
+#else
#define NULL 0L
+#endif /* __cplusplus >= 201103L */
#else
-#define NULL ((void *) 0)
+#define NULL ((void *) 0)
+#endif /* __cplusplus */
+#undef __need_NULL
+#endif /* __need_NULL */
+
+/* nullptr_t type */
+#ifdef __need_nullptr_t
+#ifndef _NULLPTR_T
+#define _NULLPTR_T
+#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 202311L
+typedef typeof(nullptr) nullptr_t;
#endif
+#endif /* !_NULLPTR_T */
+#undef __need_nullptr_t
+#endif /* __need_nullptr_t */
+
+/* size_t type */
+#ifdef __need_size_t
+#ifndef _SIZE_T
+#define _SIZE_T
+#ifdef __SIZE_TYPE__
+typedef __SIZE_TYPE__ size_t;
+#else
+typedef long unsigned int size_t;
+#endif /* __SIZE_TYPE__ */
+#endif /* !_SIZE_T */
+#undef __need_size_t
+#endif /* __need_size_t */
+
+/* rsize_t type */
+#ifdef __need_rsize_t
+#ifndef _RSIZE_T
+#define _RSIZE_T
+#ifdef __SIZE_TYPE__
+typedef __SIZE_TYPE__ rsize_t;
+#else
+typedef long unsigned int rsize_t;
+#endif /* __SIZE_TYPE__ */
+#endif /* !_RSIZE_T */
+#undef __need_rsize_t
+#endif /* __need_rsize_t */
-typedef __size_t size_t;
+/* wchar_t type */
+#ifdef __need_wchar_t
+#ifndef _WCHAR_T
+#define _WCHAR_T
+#ifdef __WCHAR_TYPE__
+typedef __WCHAR_TYPE__ wchar_t;
+#else
+typedef int wchar_t;
+#endif /* __WCHAR_TYPE__ */
+#endif /* !_WCHAR_T */
+#undef __need_wchar_t
+#endif /* __need_wchar_t */
+
+/* wint_t type */
+#ifdef __need_wint_t
+#ifndef _WINT_T
+#define _WINT_T
+#ifdef __WINT_TYPE__
+typedef __WINT_TYPE__ wint_t;
+#else
+typedef unsigned int wint_t;
+#endif /* __WINT_TYPE__ */
+#endif /* !_WINT_T */
+#undef __need_wint_t
+#endif /* __need_wint_t */
+
+/* ptrdiff_t type */
+#ifdef __need_ptrdiff_t
+#ifndef _PTRDIFF_T
+#define _PTRDIFF_T
+#ifdef __PTRDIFF_TYPE__
+typedef __PTRDIFF_TYPE__ ptrdiff_t;
+#else
+typedef long int ptrdiff_t;
+#endif /* __PTRDIFF_TYPE__ */
+#endif /* !_PTRDIFF_T */
+#undef __need_ptrdiff_t
+#endif /* __need_ptrdiff_t */
+
+/* max_align_t type */
+#ifdef __need_max_align_t
+#if defined (_MSC_VER)
+typedef double max_align_t;
+#elif defined(__APPLE__)
+typedef long double max_align_t;
+#else
+typedef struct {
+ long long __longlong __attribute__((__aligned__(__alignof__(long long))));
+ long double __longdouble __attribute__((__aligned__(__alignof__(long double))));
+} max_align_t;
+#endif
+#undef __need_max_align_t
+#endif /* __need_max_align_t */
+
+/* offsetof() macro */
+#ifdef __need_offsetof
+#ifndef offsetof
+#define offsetof(type, member) __builtin_offsetof(type, member)
+#endif
+#undef __need_offsetof
+#endif /* __need_offsetof */
+
+/* unreachable() macro */
+#ifdef __need_unreachable
+/* C++ has std::unreachable() */
+#if !defined(__cplusplus) && !defined(unreachable)
+#define unreachable() __builtin_unreachable()
+#endif
+#undef __need_unreachable
+#endif /* __need_unreachable */
#endif /* !_STDDEF_H */
diff --git a/lib/libc/src/hyra/mmap.c b/lib/libc/src/hyra/mmap.c
new file mode 100644
index 0000000..6870c75
--- /dev/null
+++ b/lib/libc/src/hyra/mmap.c
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023-2025 Ian Marco Moffett and the Osmora Team.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of Hyra nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/syscall.h>
+#include <sys/mman.h>
+#include <sys/types.h>
+
+void *
+mmap(void *addr, size_t len, int prot, int flags,
+ int fildes, off_t off)
+
+{
+ return (void *)syscall(SYS_mmap, (uintptr_t)addr, len,
+ prot, flags, fildes, off);
+}
+
+int
+munmap(void *addr, size_t len)
+{
+ return syscall(SYS_munmap, (uintptr_t)addr, len);
+}