https://git.reactos.org/?p=reactos.git;a=commitdiff;h=995e16d4d4e65e1d03a28…
commit 995e16d4d4e65e1d03a28eed7d6167b184d79e04
Author: Timo Kreuzer <timo.kreuzer(a)reactos.org>
AuthorDate: Fri Oct 11 14:45:42 2024 +0300
Commit: Timo Kreuzer <timo.kreuzer(a)reactos.org>
CommitDate: Thu Jan 16 14:18:53 2025 +0200
[UCRT] Add missing headers
These are minimal definitions, just enough to make things compile.
---
.../ucrt/inc/corecrt_internal_state_isolation.h | 52 +++++
sdk/lib/ucrt/inc/internal_shared.h | 236 +++++++++++++++++++++
sdk/lib/ucrt/inc/nt.h | 13 ++
sdk/lib/ucrt/inc/ntrtl.h | 15 ++
sdk/lib/ucrt/inc/nturtl.h | 11 +
5 files changed, 327 insertions(+)
diff --git a/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h
b/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h
new file mode 100644
index 00000000000..341de26f6ff
--- /dev/null
+++ b/sdk/lib/ucrt/inc/corecrt_internal_state_isolation.h
@@ -0,0 +1,52 @@
+//
+// corecrt_internal_state_isolation.h
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Header for CRT state management.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#ifdef __cplusplus
+extern "C++"
+{
+ namespace __crt_state_management
+ {
+ constexpr size_t state_index_count = 2;
+ struct scoped_global_state_reset
+ {
+ scoped_global_state_reset() throw() { }
+ ~scoped_global_state_reset() throw() { }
+ }; // FIXME: Implement this
+ template <typename T>
+ class dual_state_global
+ {
+ T _value[2];
+ public:
+ T& value(__crt_cached_ptd_host& ptd) throw();
+ T const& value(__crt_cached_ptd_host& ptd) const throw();
+ T& value(void) throw() { return _value[0]; }
+ T value_explicit(size_t index) throw() { return _value[index]; }
+ T* dangerous_get_state_array() throw() { return _value; }
+ void initialize(T) throw() { }
+ template<typename T2> void uninitialize(T2) throw() { }
+ template<typename T2, size_t N> void initialize_from_array(T2 const
(&values)[N]) throw() { }
+ };
+
+ inline int get_current_state_index(__crt_scoped_get_last_error_reset const
&last_error_reset)
+ {
+ return 0;
+ }
+
+ inline int get_current_state_index(void)
+ {
+ return 0;
+ }
+ }
+}
+#endif // __cplusplus
+
+#define __acrt_select_exit_lock() __acrt_exit_lock
diff --git a/sdk/lib/ucrt/inc/internal_shared.h b/sdk/lib/ucrt/inc/internal_shared.h
new file mode 100644
index 00000000000..a5f50f0f681
--- /dev/null
+++ b/sdk/lib/ucrt/inc/internal_shared.h
@@ -0,0 +1,236 @@
+//
+// internal_shared.h
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Header for definitions shared between vcruntime and UCRT.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <suppress.h>
+#include <intrin.h>
+#include <corecrt_startup.h>
+#include <crtdbg.h>
+#include <windows.h> // for HMODULE
+#include <malloc.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif // __cplusplus
+
+#if defined(_MSC_VER)
+#define _CRTALLOC(x) __declspec(allocate(x))
+#else
+#define _CRTALLOC(x) __attribute__((section(x)))
+#endif
+
+#pragma section(".CRT$XIC", long, read)
+#pragma section(".CRT$XPX", long, read)
+#pragma section(".CRT$XPXA", long, read)
+
+#pragma section(".CRT$XIA", long, read)
+#pragma section(".CRT$XIZ", long, read)
+#pragma section(".CRT$XCA", long, read)
+#pragma section(".CRT$XCZ", long, read)
+#pragma section(".CRT$XPA", long, read)
+#pragma section(".CRT$XPZ", long, read)
+#pragma section(".CRT$XTA", long, read)
+#pragma section(".CRT$XTZ", long, read)
+
+extern _PIFV __xi_a[];
+extern _PIFV __xi_z[];
+extern _PVFV __xc_a[];
+extern _PVFV __xc_z[];
+extern _PVFV __xp_a[];
+extern _PVFV __xp_z[];
+extern _PVFV __xt_a[];
+extern _PVFV __xt_z[];
+
+extern char __ImageBase;
+
+#define CRT_WARNING_DISABLE_PUSH(wn, message) \
+ __pragma(warning(push)) \
+ __pragma(warning(disable: wn))
+
+#define CRT_WARNING_POP \
+ __pragma(warning(pop))
+
+#define _BEGIN_SECURE_CRT_DEPRECATION_DISABLE \
+ __pragma(warning(push)) \
+ __pragma(warning(disable: 4996))
+
+#define _END_SECURE_CRT_DEPRECATION_DISABLE \
+ __pragma(warning(pop))
+
+#define _CRT_DEBUGGER_IGNORE -1
+#define _CRT_DEBUGGER_GSFAILURE 1
+#define _CRT_DEBUGGER_INVALIDPARAMETER 2
+#define _CRT_DEBUGGER_ABORT 3
+
+#define _CRT_DEBUGGER_HOOK(x)
+
+#define _CRT_SECURITYCRITICAL_ATTRIBUTE
+#define _CRT_SECURITYSAFECRITICAL_ATTRIBUTE
+
+#define _VALIDATE_RETURN(expr, errorcode, retexpr) \
+ if (!(expr)) return (retexpr);
+
+#define _VALIDATE_RETURN_VOID(expr, errorcode) \
+ if (!(expr)) return;
+
+#define _VALIDATE_RETURN_NOERRNO(expr, retexpr) \
+ if (!(expr)) return (retexpr);
+
+#define _VALIDATE_RETURN_ERRCODE(expr, errorcode) \
+ if (!(expr)) return (errorcode);
+
+#define _VALIDATE_CLEAR_OSSERR_RETURN(expr, errorcode, retexpr) \
+ if (!(expr)) return (retexpr);
+
+#define _VALIDATE_CLEAR_OSSERR_RETURN_ERRCODE(expr, errorcode) \
+ if (!(expr)) return (errorcode);
+
+#define _VALIDATE_RETURN_NOEXC(expr, errorcode, retexpr) \
+ if (!(expr)) return (retexpr);
+
+#define _VALIDATE_RETURN_ERRCODE_NOEXC(expr, errorcode) \
+ if (!(expr)) return (errorcode);
+
+#define _malloc_crt malloc
+#define _free_crt free
+#define _calloc_crt calloc
+#define _recalloc_crt _recalloc
+#define _malloca_crt _malloca
+#define _freea_crt _freea
+
+#ifdef __cplusplus
+} // extern "C"
+
+template<typename T>
+__forceinline
+T __crt_fast_encode_pointer(T Ptr)
+{
+ // FIXME: use cookie
+ return Ptr;
+}
+
+template<typename T>
+__forceinline
+T __crt_fast_decode_pointer(T Ptr)
+{
+ // FIXME: use cookie
+ return Ptr;
+}
+
+template<typename T>
+T __crt_interlocked_read(const T volatile* ptr)
+{
+ return *ptr;
+}
+
+template<typename T>
+T __crt_interlocked_read_pointer(const T volatile* ptr)
+{
+ return *ptr;
+}
+
+template<typename T>
+T __crt_interlocked_exchange_pointer(T *ptr, void* value)
+{
+ return (T)_InterlockedExchangePointer((void* volatile*)ptr, value);
+}
+
+template<typename T>
+struct __crt_seh_guarded_call
+{
+ template<typename Init, typename Action, typename Cleanup>
+ T operator()(Init init, Action action, Cleanup cleanup)
+ {
+ init();
+ __try
+ {
+ return action();
+ }
+ __finally
+ {
+ cleanup();
+ }
+ }
+};
+
+template<typename FuncPtr>
+FuncPtr __crt_get_proc_address(HMODULE module, const char* name)
+{
+ return (FuncPtr)GetProcAddress(module, name);
+}
+
+template<typename Action, typename Cleanup>
+void __crt_call_and_cleanup(Action action, Cleanup cleanup)
+{
+ action();
+ cleanup();
+}
+
+struct __crt_malloc_free_policy
+{
+ template<typename T>
+ void operator()(T* const ptr) throw()
+ {
+ _free_crt((void*)ptr);
+ }
+};
+
+struct __crt_public_free_policy
+{
+ template<typename T>
+ void operator()(T* const ptr) throw()
+ {
+ _free_crt((void*)ptr);
+ }
+};
+
+struct __crt_malloca_free_policy
+{
+ void operator()(void* const ptr) throw()
+ {
+ _freea_crt(ptr);
+ }
+};
+
+template <typename T, typename FreePolicy = __crt_malloc_free_policy>
+class __crt_unique_heap_ptr
+{
+ T* _ptr;
+public:
+ __crt_unique_heap_ptr() : _ptr(nullptr) {}
+ __crt_unique_heap_ptr(T* ptr) : _ptr(ptr) {}
+ __crt_unique_heap_ptr(__crt_unique_heap_ptr&& from) : _ptr(from._ptr) {
from._ptr = nullptr; }
+ ~__crt_unique_heap_ptr() { FreePolicy()(_ptr); }
+ void attach(T* ptr) { FreePolicy()(_ptr); _ptr = ptr; }
+ T* detach() { T* ptr = _ptr; _ptr = nullptr; return ptr; }
+ operator bool() const { return _ptr != nullptr; }
+ T* get() const { return _ptr; }
+ T** get_address_of() { return &_ptr; }
+
+ // Move assignment
+ __crt_unique_heap_ptr& operator=(__crt_unique_heap_ptr&& from)
+ {
+ FreePolicy()(_ptr);
+ _ptr = from._ptr;
+ from._ptr = nullptr;
+ return *this;
+ }
+};
+
+template <typename T>
+using __crt_scoped_stack_ptr = __crt_unique_heap_ptr<T,
__crt_malloca_free_policy>;
+
+#define _malloc_crt_t(t, n)
(__crt_unique_heap_ptr<t>(static_cast<t*>(_malloc_crt((n) * sizeof(t)))))
+#define _calloc_crt_t(t, n)
(__crt_unique_heap_ptr<t>(static_cast<t*>(_calloc_crt((n), sizeof(t)))))
+#define _recalloc_crt_t(t, p, n)
(__crt_unique_heap_ptr<t>(static_cast<t*>(_recalloc_crt(p, (n), sizeof(t)))))
+#define _malloca_crt_t(t, n)
(__crt_scoped_stack_ptr<t>(static_cast<t*>(_malloca_crt((n) * sizeof(t)))))
+
+#endif // __cplusplus
diff --git a/sdk/lib/ucrt/inc/nt.h b/sdk/lib/ucrt/inc/nt.h
new file mode 100644
index 00000000000..5ec2c7d750e
--- /dev/null
+++ b/sdk/lib/ucrt/inc/nt.h
@@ -0,0 +1,13 @@
+//
+// nt.h
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Header for generic NT things.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <ndk/pstypes.h>
diff --git a/sdk/lib/ucrt/inc/ntrtl.h b/sdk/lib/ucrt/inc/ntrtl.h
new file mode 100644
index 00000000000..cd0a293158d
--- /dev/null
+++ b/sdk/lib/ucrt/inc/ntrtl.h
@@ -0,0 +1,15 @@
+//
+// ntrtl.h
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Header for RTL NT things.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once
+
+#include <ndk/rtltypes.h>
+
+#define RTL_USER_PROC_SECURE_PROCESS 0x80000000
diff --git a/sdk/lib/ucrt/inc/nturtl.h b/sdk/lib/ucrt/inc/nturtl.h
new file mode 100644
index 00000000000..40406382e93
--- /dev/null
+++ b/sdk/lib/ucrt/inc/nturtl.h
@@ -0,0 +1,11 @@
+//
+// nturtl.h
+//
+// Copyright (c) 2024 Timo Kreuzer
+//
+// Header for user mode RTL NT things.
+//
+// SPDX-License-Identifier: MIT
+//
+
+#pragma once