summaryrefslogtreecommitdiffhomepage
path: root/CRT
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 09:14:11 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-06 09:14:11 +0100
commit5339d016c07bf717ee388f4feb73544087324af0 (patch)
tree94be6f67ed626091f24aee24ec3b3be03d01e4e7 /CRT
git: port from mercurial repo.
Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CRT')
-rw-r--r--CRT/__cxxkit_alloca.h15
-rw-r--r--CRT/__cxxkit_cookie.asm23
-rw-r--r--CRT/__cxxkit_defines.h89
3 files changed, 127 insertions, 0 deletions
diff --git a/CRT/__cxxkit_alloca.h b/CRT/__cxxkit_alloca.h
new file mode 100644
index 00000000..5d5f54ce
--- /dev/null
+++ b/CRT/__cxxkit_alloca.h
@@ -0,0 +1,15 @@
+/*
+ * ========================================================
+ *
+ * hCore
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+typedef void* ptr_type;
+typedef __SIZE_TYPE__ size_type;
+
+inline void* __cxxkit_alloca_gcc(size_type sz) { return __builtin_alloca(sz); }
diff --git a/CRT/__cxxkit_cookie.asm b/CRT/__cxxkit_cookie.asm
new file mode 100644
index 00000000..9e2292fa
--- /dev/null
+++ b/CRT/__cxxkit_cookie.asm
@@ -0,0 +1,23 @@
+[bits 64]
+[global runtime_cookie_check]
+
+%define LIBALLOC_COOKIE 0x77ccdd
+
+runtime_cookie_check:
+ ret
+
+runtime_cookie_install:
+ push LIBALLOC_COOKIE ;; the cookie
+ jmp rdi
+ cmp rsp, LIBALLOC_COOKIE
+ jne _runtime_cookie_fail
+ ret
+
+_runtime_cookie_fail:
+ mov rsi, 1
+ mov rdi, 33
+ syscall
+
+;; we shouldn't get here if the host has exit (rsi = 1) implemented.
+L0:
+ jmp $ \ No newline at end of file
diff --git a/CRT/__cxxkit_defines.h b/CRT/__cxxkit_defines.h
new file mode 100644
index 00000000..557e0c99
--- /dev/null
+++ b/CRT/__cxxkit_defines.h
@@ -0,0 +1,89 @@
+/*
+ * ========================================================
+ *
+ * hCore
+ * Copyright Mahrouss Logic, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#ifndef __CXKIT_DEF_H
+#define __CXKIT_DEF_H
+
+typedef __SIZE_TYPE__ size_t;
+
+#ifdef __LP64__
+typedef long int ssize_t;
+#else
+typedef int ssize_t;
+#endif // __LP64__
+
+typedef size_t ptrdiff_t;
+typedef size_t uintptr_t;
+typedef void* voidptr_t;
+typedef void* any_t;
+typedef char* caddr_t;
+
+#ifndef NULL
+#define NULL ((voidptr_t)0)
+#endif // !null
+
+#ifdef __GNUC__
+# include <CRT/__cxxkit_alloca.h>
+# define __cxxkit_alloca(sz) __cxxkit_alloca_gcc(sz)
+#elif defined(__HISYS__)
+
+# define __alloca(SZ) __cxxkit_alloca(SZ)
+
+# define __deref(ptr) (*(PTR))
+
+# define __libexport __lib(export)
+# define __libimport __lib(import)
+
+#ifdef __cplusplus
+# define __init_decl() extern "C" {
+# define __fini_decl() };
+#else
+# define __init_decl()
+# define __fini_decl()
+#endif
+#endif
+
+#if __has_builtin(__builtin_alloca)
+# define alloca(sz) __builtin_alloca(sz)
+#ifdef __alloca
+# undef __alloca
+#endif
+#define __alloca alloca
+#else
+# warning alloca not detected
+#endif
+
+typedef long long off_t;
+typedef unsigned long long uoff_t;
+
+typedef union
+{
+ struct
+ {
+ unsigned int mantisa : 23;
+ unsigned int exponent : 8;
+ unsigned int sign : 1;
+ };
+
+ float f;
+} __attribute__((packed)) float_cast_t;
+
+typedef union
+{
+ struct
+ {
+ unsigned long int mantisa : 52;
+ unsigned int exponent : 11;
+ unsigned int sign : 1;
+ };
+
+ double f;
+} __attribute__((packed)) double_cast_t;
+
+#endif /* __CXKIT_DEF_H */