moved getter for process start time w32

This commit is contained in:
Nikita Smith
2024-11-07 13:33:37 -08:00
parent 4091373517
commit db04792073
4 changed files with 42 additions and 68 deletions
-2
View File
@@ -29,5 +29,3 @@ internal String8Array os_data_from_file_path_parallel(TP_Context *tp, Arena *are
internal String8List os_file_search(Arena *arena, String8List dir_list, String8 file_path);
internal B32 os_folder_path_exists(String8 path);
internal U32 os_get_process_start_time_unix(void);
-50
View File
@@ -1,18 +1,6 @@
// Copyright (c) 2024 Epic Games Tools
// Licensed under the MIT license (https://opensource.org/license/mit/)
internal U32
w32_unix_time_from_file_time(FILETIME file_time)
{
U64 win32_time = ((U64)file_time.dwHighDateTime << 32) | file_time.dwLowDateTime;
U64 unix_time64 = ((win32_time - 0x19DB1DED53E8000ULL) / 10000000);
Assert(unix_time64 <= max_U32);
U32 unix_time32 = (U32)unix_time64;
return unix_time32;
}
internal B32
os_w32_has_path_volume_prefix(String8 path)
{
@@ -128,41 +116,3 @@ os_folder_path_exists(String8 path)
return exists;
}
internal B32
os_set_large_pages(B32 toggle)
{
B32 is_ok = 0;
HANDLE token;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
{
LUID luid;
if(LookupPrivilegeValue(0, SE_LOCK_MEMORY_NAME, &luid))
{
TOKEN_PRIVILEGES priv;
priv.PrivilegeCount = 1;
priv.Privileges[0].Luid = luid;
priv.Privileges[0].Attributes = toggle ? SE_PRIVILEGE_ENABLED : SE_PRIVILEGE_REMOVED;
if (AdjustTokenPrivileges(token, 0, &priv, sizeof(priv), 0, 0) == ERROR_SUCCESS) {
is_ok = 1;
}
}
CloseHandle(token);
}
return is_ok;
}
internal U32
os_get_process_start_time_unix(void)
{
HANDLE handle = GetCurrentProcess();
FILETIME start_time = {0};
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
if (GetProcessTimes(handle, &start_time, &exit_time, &kernel_time, &user_time)) {
return w32_unix_time_from_file_time(start_time);
}
return 0;
}
+3 -2
View File
@@ -166,9 +166,10 @@ internal OS_Handle os_cmd_line_launchf(char *fmt, ...);
////////////////////////////////
//~ rjf: @os_hooks System/Process Info (Implemented Per-OS)
internal OS_SystemInfo *os_get_system_info(void);
internal OS_SystemInfo *os_get_system_info(void);
internal OS_ProcessInfo *os_get_process_info(void);
internal String8 os_get_current_path(Arena *arena);
internal String8 os_get_current_path(Arena *arena);
internal U32 os_get_process_start_time_unix(void);
////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
+39 -14
View File
@@ -90,6 +90,18 @@ os_w32_sleep_ms_from_endt_us(U64 endt_us)
return sleep_ms;
}
internal U32
os_w32_unix_time_from_file_time(FILETIME file_time)
{
U64 win32_time = ((U64)file_time.dwHighDateTime << 32) | file_time.dwLowDateTime;
U64 unix_time64 = ((win32_time - 0x19DB1DED53E8000ULL) / 10000000);
Assert(unix_time64 <= max_U32);
U32 unix_time32 = (U32)unix_time64;
return unix_time32;
}
////////////////////////////////
//~ rjf: Entity Functions
@@ -167,6 +179,21 @@ os_get_current_path(Arena *arena)
return name;
}
internal U32
os_get_process_start_time_unix(void)
{
HANDLE handle = GetCurrentProcess();
FILETIME start_time = {0};
FILETIME exit_time;
FILETIME kernel_time;
FILETIME user_time;
if(GetProcessTimes(handle, &start_time, &exit_time, &kernel_time, &user_time))
{
return os_w32_unix_time_from_file_time(start_time);
}
return 0;
}
////////////////////////////////
//~ rjf: @os_hooks Memory Allocation (Implemented Per-OS)
@@ -710,13 +737,13 @@ os_file_iter_next(Arena *arena, OS_FileIter *iter, OS_FileInfo *info_out)
internal void
os_file_iter_end(OS_FileIter *iter)
{
OS_W32_FileIter *w32_iter = (OS_W32_FileIter*)iter->memory;
HANDLE zero_handle;
MemoryZeroStruct(&zero_handle);
if(!MemoryMatchStruct(&zero_handle, &w32_iter->handle))
{
FindClose(w32_iter->handle);
}
OS_W32_FileIter *w32_iter = (OS_W32_FileIter*)iter->memory;
HANDLE zero_handle;
MemoryZeroStruct(&zero_handle);
if(!MemoryMatchStruct(&zero_handle, &w32_iter->handle))
{
FindClose(w32_iter->handle);
}
}
//- rjf: directory creation
@@ -817,10 +844,8 @@ os_now_unix(void)
{
FILETIME file_time;
GetSystemTimeAsFileTime(&file_time);
U64 win32_time = ((U64)file_time.dwHighDateTime << 32) | file_time.dwLowDateTime;
U64 unix_time64 = ((win32_time - 0x19DB1DED53E8000ULL) / 10000000);
U32 unix_time32 = (U32)unix_time64;
return unix_time32;
U32 unix_time = os_w32_unix_time_from_file_time(file_time);
return unix_time;
}
internal DateTime
@@ -946,21 +971,21 @@ os_process_launch(OS_ProcessLaunchParams *params)
startup_info.hStdOutput = stdout_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
}
if(!os_handle_match(params->stderr_file, os_handle_zero()))
{
HANDLE stderr_handle = (HANDLE)params->stderr_file.u64[0];
startup_info.hStdError = stderr_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
}
if(!os_handle_match(params->stdin_file, os_handle_zero()))
{
HANDLE stdin_handle = (HANDLE)params->stdin_file.u64[0];
startup_info.hStdInput = stdin_handle;
startup_info.dwFlags |= STARTF_USESTDHANDLES;
inherit_handles = 1;
}
}
PROCESS_INFORMATION process_info = {0};
if(CreateProcessW(0, (WCHAR*)cmd16.str, 0, 0, inherit_handles, creation_flags, use_null_env_arg ? 0 : (WCHAR*)env16.str, (WCHAR*)dir16.str, &startup_info, &process_info))
{