Port changes from SolidPP

This commit is contained in:
2025-11-30 21:33:46 +11:00
parent 38c0e7dda0
commit 54d4547e5f
14 changed files with 476 additions and 253 deletions
+18 -1
View File
@@ -28,6 +28,10 @@ static DN_U32 DN_OS_MemConvertPageToOSFlags_(DN_U32 protect)
DN_API void *DN_OS_MemReserve(DN_USize size, DN_MemCommit commit, DN_U32 page_flags)
{
#if defined(DN_PLATFORM_EMSCRIPTEN)
DN_InvalidCodePathF("Emscripten does not support virtual memory, you should use DN_OS_MemAlloc");
#endif
unsigned long os_page_flags = DN_OS_MemConvertPageToOSFlags_(page_flags);
if (commit == DN_MemCommit_Yes)
@@ -43,6 +47,9 @@ DN_API void *DN_OS_MemReserve(DN_USize size, DN_MemCommit commit, DN_U32 page_fl
DN_API bool DN_OS_MemCommit(void *ptr, DN_USize size, DN_U32 page_flags)
{
#if defined(DN_PLATFORM_EMSCRIPTEN)
DN_InvalidCodePathF("Emscripten does not support virtual memory");
#endif
bool result = false;
if (!ptr || size == 0)
return false;
@@ -56,17 +63,26 @@ DN_API bool DN_OS_MemCommit(void *ptr, DN_USize size, DN_U32 page_flags)
DN_API void DN_OS_MemDecommit(void *ptr, DN_USize size)
{
#if defined(DN_PLATFORM_EMSCRIPTEN)
DN_InvalidCodePathF("Emscripten does not support virtual memory");
#endif
mprotect(ptr, size, PROT_NONE);
madvise(ptr, size, MADV_FREE);
}
DN_API void DN_OS_MemRelease(void *ptr, DN_USize size)
{
#if defined(DN_PLATFORM_EMSCRIPTEN)
DN_InvalidCodePathF("Emscripten does not support virtual memory");
#endif
munmap(ptr, size);
}
DN_API int DN_OS_MemProtect(void *ptr, DN_USize size, DN_U32 page_flags)
{
#if defined(DN_PLATFORM_EMSCRIPTEN)
DN_InvalidCodePathF("Emscripten does not support virtual memory");
#endif
if (!ptr || size == 0)
return 0;
@@ -151,7 +167,8 @@ DN_API DN_U64 DN_OS_DateUnixTimeSFromLocalDate(DN_Date date)
DN_API DN_U64 DN_OS_DateLocalUnixTimeSFromUnixTimeS(DN_U64 unix_ts_s)
{
struct tm tm_local;
void *ret = localtime_r(&unix_ts_s, &tm_local);
time_t unix_ts = unix_ts_s;
void *ret = localtime_r(&unix_ts, &tm_local);
DN_Assert(ret);
long local_offset_seconds = tm_local.tm_gmtoff;
+20 -3
View File
@@ -32,9 +32,12 @@ DN_API void DN_OS_TLSInit(DN_OSTLS *tls, DN_OSTLSInitArgs args)
return;
DN_U64 reserve = args.reserve ? args.reserve : DN_Kilobytes(64);
DN_U64 commit = args.commit ? args.commit : DN_Kilobytes(4);
DN_U64 err_sink_reserve = args.err_sink_reserve ? args.err_sink_reserve : DN_Kilobytes(64);
#if !defined(DN_PLATFORM_EMSCRIPTEN)
DN_U64 commit = args.commit ? args.commit : DN_Kilobytes(4);
DN_U64 err_sink_commit = args.err_sink_commit ? args.err_sink_commit : DN_Kilobytes(4);
#endif
// TODO: We shouldn't have the no alloc track flag here but the initial TLS
// init on OS init happens before CORE init. CORE init is the one responsible
@@ -42,8 +45,22 @@ DN_API void DN_OS_TLSInit(DN_OSTLS *tls, DN_OSTLSInitArgs args)
for (DN_ForItCArray(it, DN_Arena, tls->arenas)) {
DN_Arena *arena = it.data;
switch (DN_Cast(DN_OSTLSArena) it.index) {
default: *arena = DN_ArenaFromVMem(reserve, commit, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack); break;
case DN_OSTLSArena_ErrorSink: *arena = DN_ArenaFromVMem(err_sink_reserve, err_sink_commit, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack); break;
default: {
#if defined(DN_PLATFORM_EMSCRIPTEN)
*arena = DN_ArenaFromHeap(reserve, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack);
#else
*arena = DN_ArenaFromVMem(reserve, commit, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack);
#endif
} break;
case DN_OSTLSArena_ErrorSink: {
#if defined(DN_PLATFORM_EMSCRIPTEN)
*arena = DN_ArenaFromHeap(err_sink_reserve, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack);
#else
*arena = DN_ArenaFromVMem(err_sink_reserve, err_sink_commit, DN_ArenaFlags_AllocCanLeak | DN_ArenaFlags_NoAllocTrack);
#endif
} break;
case DN_OSTLSArena_Count: DN_InvalidCodePath; break;
}
}