summaryrefslogtreecommitdiffhomepage
path: root/dev/CRT
diff options
context:
space:
mode:
Diffstat (limited to 'dev/CRT')
-rw-r--r--dev/CRT/ReadMe.md5
-rw-r--r--dev/CRT/__ndk_alloca.hxx15
-rw-r--r--dev/CRT/__ndk_defines.hxx121
-rw-r--r--dev/CRT/__ndk_exception.hxx35
-rw-r--r--dev/CRT/__ndk_new_delete.hxx61
-rw-r--r--dev/CRT/__ndk_runtime.cxx12
-rw-r--r--dev/CRT/build.json10
7 files changed, 259 insertions, 0 deletions
diff --git a/dev/CRT/ReadMe.md b/dev/CRT/ReadMe.md
new file mode 100644
index 00000000..25dc2cb2
--- /dev/null
+++ b/dev/CRT/ReadMe.md
@@ -0,0 +1,5 @@
+# ZKA C++ RunTime
+
+This is the public interface of ZKA' NDK RunTime, please check ndk.dll instead.
+
+###### (c) ZKA Technologies, all rights reserved. \ No newline at end of file
diff --git a/dev/CRT/__ndk_alloca.hxx b/dev/CRT/__ndk_alloca.hxx
new file mode 100644
index 00000000..db572bcd
--- /dev/null
+++ b/dev/CRT/__ndk_alloca.hxx
@@ -0,0 +1,15 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+typedef void* ptr_type;
+typedef __SIZE_TYPE__ size_type;
+
+inline void* __ndk_alloca(size_type sz)
+{
+ return __builtin_alloca(sz);
+}
diff --git a/dev/CRT/__ndk_defines.hxx b/dev/CRT/__ndk_defines.hxx
new file mode 100644
index 00000000..ebf530a5
--- /dev/null
+++ b/dev/CRT/__ndk_defines.hxx
@@ -0,0 +1,121 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#ifndef __NDK_DEFINES_HXX__
+#define __NDK_DEFINES_HXX__
+
+#ifndef __GNUC__
+
+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/__ndk_alloca.hxx>
+#define __ndk_alloca(sz) __ndk_alloca(sz)
+#elif defined(__NDK__)
+
+#define __alloca(sz) __ndk_alloca(sz)
+#endif
+
+#define __deref(ptr) (*(ptr))
+
+#ifdef __cplusplus
+#define __init_decl() \
+ extern "C" \
+ {
+#define __fini_decl() \
+ } \
+ ;
+#else
+#define __init_decl()
+#define __fini_decl()
+#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 float_cast {
+ struct
+ {
+ unsigned int mantissa : 23;
+ unsigned int exponent : 8;
+ unsigned int sign : 1;
+ };
+
+ float f;
+} __attribute__((packed)) float_cast_t;
+
+typedef union double_cast {
+ struct
+ {
+ unsigned long long int mantissa : 52;
+ unsigned int exponent : 11;
+ unsigned int sign : 1;
+ };
+
+ double f;
+} __attribute__((packed)) double_cast_t;
+
+#endif // ifndef __GNUC__
+
+/// Include these helpers as well.
+
+#ifdef __STD_CXX__
+
+#include <CRT/__ndk_exception.hxx>
+#include <CRT/__ndk_malloc.hxx>
+
+#endif // ifdef __STD_CXX__
+
+namespace std
+{
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+} // namespace std
+
+#endif /* __NDK_DEFINES_HXX__ */
diff --git a/dev/CRT/__ndk_exception.hxx b/dev/CRT/__ndk_exception.hxx
new file mode 100644
index 00000000..93407595
--- /dev/null
+++ b/dev/CRT/__ndk_exception.hxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CRT/__ndk_defines.hxx>
+
+/// @brief CRT exit, with exit code (!!! exits all threads. !!!)
+/// @param code
+/// @return
+extern "C" int __exit(int code);
+
+/// @brief Standard C++ namespace
+namespace std
+{
+ inline void __throw_general(void)
+ {
+ __exit(33);
+ }
+
+ inline void __throw_domain_error(const char* error)
+ {
+ __throw_general();
+ __builtin_unreachable(); // prevent from continuing.
+ }
+
+ inline void __throw_bad_array_new_length(void)
+ {
+ __throw_general();
+ __builtin_unreachable(); // prevent from continuing.
+ }
+} // namespace std
diff --git a/dev/CRT/__ndk_new_delete.hxx b/dev/CRT/__ndk_new_delete.hxx
new file mode 100644
index 00000000..464ea334
--- /dev/null
+++ b/dev/CRT/__ndk_new_delete.hxx
@@ -0,0 +1,61 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <CRT/__ndk_defines.hxx>
+#include <SCIKit/SCIBase.hxx>
+
+namespace stdx
+{
+ /// @brief allocate a new class.
+ /// @tparam KindClass the class type to allocate.
+ template <typename KindClass, typename... Args>
+ inline void* allocate(Args&&... args)
+ {
+ return new KindClass(forward(args)...);
+ }
+
+ /// @brief free a class.
+ /// @tparam KindClass the class type to allocate.
+ template <typename KindClass>
+ inline void release(KindClass ptr)
+ {
+ delete ptr;
+ }
+} // namespace stdx
+
+void* operator new(size_type len)
+{
+ if (!len)
+ ++len;
+
+ return RtlCreateHeap(len, 0);
+}
+
+void operator delete(void* ptr)
+{
+ if (!ptr)
+ return;
+
+ RtlDestroyHeap(ptr);
+}
+
+void* operator new[](size_type len)
+{
+ if (!len)
+ ++len;
+
+ return RtlCreateHeap(len, 0);
+}
+
+void operator delete[](void* ptr)
+{
+ if (!ptr)
+ return;
+
+ RtlDestroyHeap(ptr);
+}
diff --git a/dev/CRT/__ndk_runtime.cxx b/dev/CRT/__ndk_runtime.cxx
new file mode 100644
index 00000000..fc63b12d
--- /dev/null
+++ b/dev/CRT/__ndk_runtime.cxx
@@ -0,0 +1,12 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies.
+
+------------------------------------------- */
+
+#include <CRT/__ndk_alloca.hxx>
+#include <CRT/__ndk_defines.hxx>
+#include <CRT/__ndk_exception.hxx>
+#include <CRTKIt/__ndk_new_delete.hxx>
+
+/// @note No sources needed for now.
diff --git a/dev/CRT/build.json b/dev/CRT/build.json
new file mode 100644
index 00000000..2d4c0c1e
--- /dev/null
+++ b/dev/CRT/build.json
@@ -0,0 +1,10 @@
+{
+ "compiler_path": "x86_64-w64-mingw32-g++",
+ "compiler_std": "c++20",
+ "headers_path": ["../", "./"],
+ "sources_path": ["*.cxx"],
+ "output_name": "ndkcrt.dll",
+ "compiler_flags": ["-ffreestanding", "-shared", "-fno-rtti", "-fno-exceptions", " -Wl,--subsystem=17"],
+ "cpp_macros": ["__CRT_AMD64__", "cCRTVersion=0x0100", "cEFSVersionHighest=0x0100", "cEFSVersionLowest=0x0100"]
+ }
+ \ No newline at end of file