From c23b6ecc31138fd35db90fc0616cfb1d8ce292ce Mon Sep 17 00:00:00 2001 From: Justine Tunney Date: Tue, 22 Mar 2022 19:51:27 -0700 Subject: [PATCH] Fix some win32 definitions You can now use psapi.dll and pdh.dll. Some TODOs for Windows have been cleared out. We might have a working load average for the platform that should help GNU Make work well. --- Makefile | 3 + examples/loadavg.c | 1 + libc/calls/calls.mk | 2 + libc/calls/getloadavg.c | 1 - libc/calls/getrusage-nt.c | 11 +- libc/calls/isexecutable.c | 5 +- libc/calls/kill-nt.c | 20 ++- libc/calls/loadavg-nt.c | 95 +++++++++++ libc/calls/loadavg.internal.h | 10 ++ libc/calls/sedebug.c | 92 ++++++++++ libc/calls/sysinfo-nt.c | 4 + libc/calls/sysinfo.c | 8 +- libc/calls/wait4-nt.c | 38 ++++- libc/isystem/windows.h | 9 + libc/log/backtrace2.c | 20 ++- libc/nt/KernelBase/EmptyWorkingSet.s | 2 - libc/nt/KernelBase/EnumDeviceDrivers.s | 2 - libc/nt/KernelBase/EnumPageFilesA.s | 2 - libc/nt/KernelBase/EnumPageFilesW.s | 2 - libc/nt/KernelBase/EnumProcessModules.s | 2 - libc/nt/KernelBase/EnumProcessModulesEx.s | 2 - libc/nt/KernelBase/EnumProcesses.s | 2 - libc/nt/KernelBase/GetDeviceDriverBaseNameA.s | 2 - libc/nt/KernelBase/GetDeviceDriverBaseNameW.s | 2 - libc/nt/KernelBase/GetDeviceDriverFileNameA.s | 2 - libc/nt/KernelBase/GetDeviceDriverFileNameW.s | 2 - libc/nt/KernelBase/GetMappedFileNameA.s | 2 - libc/nt/KernelBase/GetMappedFileNameW.s | 2 - libc/nt/KernelBase/GetModuleBaseNameA.s | 2 - libc/nt/KernelBase/GetModuleBaseNameW.s | 2 - libc/nt/KernelBase/GetModuleFileNameExA.s | 2 - libc/nt/KernelBase/GetModuleFileNameExW.s | 2 - libc/nt/KernelBase/GetModuleInformation.s | 2 - libc/nt/KernelBase/GetPerformanceInfo.s | 2 - libc/nt/KernelBase/GetProcessMemoryInfo.s | 2 - libc/nt/KernelBase/GetWsChanges.s | 2 - libc/nt/KernelBase/GetWsChangesEx.s | 2 - .../KernelBase/InitializeProcessForWsWatch.s | 2 - libc/nt/KernelBase/QueryWorkingSet.s | 2 - libc/nt/KernelBase/QueryWorkingSetEx.s | 2 - libc/nt/advapi32/ImpersonateSelf.s | 13 ++ libc/nt/advapi32/RevertToSelf.s | 12 ++ libc/nt/enum/pdh.h | 17 ++ libc/nt/enum/wt.h | 11 +- libc/nt/kernel32/GetProcessImageFileNameA.s | 12 -- libc/nt/kernel32/K32GetModuleBaseNameA.s | 2 - libc/nt/kernel32/K32GetModuleFileNameExA.s | 2 - .../nt/kernel32/K32GetProcessImageFileNameA.s | 2 - libc/nt/master.sh | 159 ++++++++++++------ libc/nt/nt.mk | 38 +++++ libc/nt/pdh.h | 48 ++++++ libc/nt/pdh/CounterPathCallBack.s | 2 + libc/nt/pdh/LoadPerfCounterTextStringsW.s | 2 + libc/nt/pdh/PdhAddCounterW.s | 2 + libc/nt/pdh/PdhAddEnglishCounterW.s | 12 ++ libc/nt/pdh/PdhBindInputDataSourceW.s | 2 + libc/nt/pdh/PdhBrowseCountersHW.s | 2 + libc/nt/pdh/PdhBrowseCountersW.s | 2 + libc/nt/pdh/PdhCalculateCounterFromRawValue.s | 2 + libc/nt/pdh/PdhCloseLog.s | 2 + libc/nt/pdh/PdhCloseQuery.s | 2 + libc/nt/pdh/PdhCollectQueryData.s | 2 + libc/nt/pdh/PdhCollectQueryDataEx.s | 12 ++ libc/nt/pdh/PdhCollectQueryDataWithTime.s | 2 + libc/nt/pdh/PdhComputeCounterStatistics.s | 2 + libc/nt/pdh/PdhConnectMachineW.s | 2 + libc/nt/pdh/PdhEnumLogSetNamesW.s | 2 + libc/nt/pdh/PdhEnumMachinesHW.s | 2 + libc/nt/pdh/PdhEnumMachinesW.s | 2 + libc/nt/pdh/PdhEnumObjectItemsHW.s | 2 + libc/nt/pdh/PdhEnumObjectItemsW.s | 2 + libc/nt/pdh/PdhEnumObjectsHW.s | 2 + libc/nt/pdh/PdhEnumObjectsW.s | 2 + libc/nt/pdh/PdhExpandCounterPathW.s | 2 + libc/nt/pdh/PdhExpandWildCardPathHW.s | 2 + libc/nt/pdh/PdhExpandWildCardPathW.s | 2 + libc/nt/pdh/PdhFormatFromRawValue.s | 2 + libc/nt/pdh/PdhGetCounterInfoW.s | 2 + libc/nt/pdh/PdhGetCounterTimeBase.s | 2 + libc/nt/pdh/PdhGetDataSourceTimeRangeH.s | 2 + libc/nt/pdh/PdhGetDataSourceTimeRangeW.s | 2 + libc/nt/pdh/PdhGetDefaultPerfCounterHW.s | 2 + libc/nt/pdh/PdhGetDefaultPerfCounterW.s | 2 + libc/nt/pdh/PdhGetDefaultPerfObjectHW.s | 2 + libc/nt/pdh/PdhGetDefaultPerfObjectW.s | 2 + libc/nt/pdh/PdhGetDllVersion.s | 2 + libc/nt/pdh/PdhGetFormattedCounterArrayW.s | 2 + libc/nt/pdh/PdhGetFormattedCounterValue.s | 12 ++ libc/nt/pdh/PdhGetLogFileSize.s | 2 + libc/nt/pdh/PdhGetRawCounterArrayW.s | 2 + libc/nt/pdh/PdhGetRawCounterValue.s | 2 + libc/nt/pdh/PdhIsRealTimeQuery.s | 2 + libc/nt/pdh/PdhLookupPerfIndexByNameW.s | 2 + libc/nt/pdh/PdhLookupPerfNameByIndexW.s | 2 + libc/nt/pdh/PdhMakeCounterPathW.s | 2 + libc/nt/pdh/PdhOpenLogW.s | 2 + libc/nt/pdh/PdhOpenQueryH.s | 2 + libc/nt/pdh/PdhOpenQueryW.s | 12 ++ libc/nt/pdh/PdhParseCounterPathW.s | 2 + libc/nt/pdh/PdhParseInstanceNameW.s | 2 + libc/nt/pdh/PdhReadRawLogRecord.s | 2 + libc/nt/pdh/PdhRemoveCounter.s | 2 + libc/nt/pdh/PdhSelectDataSourceW.s | 2 + libc/nt/pdh/PdhSetCounterScaleFactor.s | 2 + libc/nt/pdh/PdhSetDefaultRealTimeDataSource.s | 2 + libc/nt/pdh/PdhSetQueryTimeRange.s | 2 + libc/nt/pdh/PdhUpdateLogFileCatalog.s | 2 + libc/nt/pdh/PdhUpdateLogW.s | 2 + libc/nt/pdh/PdhValidatePathExW.s | 2 + libc/nt/pdh/PdhValidatePathW.s | 2 + libc/nt/pdh/PerfAddCounters.s | 2 + libc/nt/pdh/PerfCloseQueryHandle.s | 2 + libc/nt/pdh/PerfCreateInstance.s | 2 + libc/nt/pdh/PerfDecrementULongCounterValue.s | 2 + .../pdh/PerfDecrementULongLongCounterValue.s | 2 + libc/nt/pdh/PerfDeleteCounters.s | 2 + libc/nt/pdh/PerfDeleteInstance.s | 2 + libc/nt/pdh/PerfEnumerateCounterSet.s | 2 + .../nt/pdh/PerfEnumerateCounterSetInstances.s | 2 + libc/nt/pdh/PerfIncrementULongCounterValue.s | 2 + .../pdh/PerfIncrementULongLongCounterValue.s | 2 + libc/nt/pdh/PerfOpenQueryHandle.s | 2 + libc/nt/pdh/PerfQueryCounterData.s | 2 + libc/nt/pdh/PerfQueryCounterInfo.s | 2 + .../pdh/PerfQueryCounterSetRegistrationInfo.s | 2 + libc/nt/pdh/PerfQueryInstance.s | 2 + libc/nt/pdh/PerfSetCounterRefValue.s | 2 + libc/nt/pdh/PerfSetCounterSetInfo.s | 2 + libc/nt/pdh/PerfSetULongCounterValue.s | 2 + libc/nt/pdh/PerfSetULongLongCounterValue.s | 2 + libc/nt/pdh/PerfStartProvider.s | 2 + libc/nt/pdh/PerfStartProviderEx.s | 2 + libc/nt/pdh/PerfStopProvider.s | 2 + libc/nt/pdh/UnloadPerfCounterTextStringsW.s | 2 + libc/nt/privilege.h | 3 + libc/nt/process.h | 5 + libc/nt/psapi/EmptyWorkingSet.s | 2 + libc/nt/psapi/EnumDeviceDrivers.s | 2 + libc/nt/psapi/EnumPageFilesW.s | 2 + libc/nt/psapi/EnumProcessModules.s | 2 + libc/nt/psapi/EnumProcessModulesEx.s | 2 + libc/nt/psapi/EnumProcesses.s | 2 + libc/nt/psapi/GetDeviceDriverBaseNameW.s | 2 + libc/nt/psapi/GetDeviceDriverFileNameW.s | 2 + libc/nt/psapi/GetMappedFileNameW.s | 2 + libc/nt/psapi/GetModuleBaseNameW.s | 2 + libc/nt/psapi/GetModuleFileNameExW.s | 2 + libc/nt/psapi/GetModuleInformation.s | 2 + libc/nt/psapi/GetPerformanceInfo.s | 2 + .../GetProcessImageFileNameW.s | 2 +- libc/nt/psapi/GetProcessMemoryInfo.s | 12 ++ libc/nt/psapi/GetWsChanges.s | 2 + libc/nt/psapi/GetWsChangesEx.s | 2 + libc/nt/psapi/InitializeProcessForWsWatch.s | 2 + libc/nt/psapi/QueryWorkingSet.s | 2 + libc/nt/psapi/QueryWorkingSetEx.s | 2 + libc/nt/struct/pdhfmtcountervalue.h | 19 +++ libc/nt/struct/processmemorycounters.h | 22 +++ libc/runtime/fork-nt.c | 3 +- test/libc/calls/mprotect_test.c | 1 - test/libc/stdio/mkostempsm_test.c | 2 - test/libc/tinymath/strtod_test.c | 4 - 162 files changed, 847 insertions(+), 153 deletions(-) create mode 100644 libc/calls/loadavg-nt.c create mode 100644 libc/calls/loadavg.internal.h create mode 100644 libc/calls/sedebug.c delete mode 100644 libc/nt/KernelBase/EmptyWorkingSet.s delete mode 100644 libc/nt/KernelBase/EnumDeviceDrivers.s delete mode 100644 libc/nt/KernelBase/EnumPageFilesA.s delete mode 100644 libc/nt/KernelBase/EnumPageFilesW.s delete mode 100644 libc/nt/KernelBase/EnumProcessModules.s delete mode 100644 libc/nt/KernelBase/EnumProcessModulesEx.s delete mode 100644 libc/nt/KernelBase/EnumProcesses.s delete mode 100644 libc/nt/KernelBase/GetDeviceDriverBaseNameA.s delete mode 100644 libc/nt/KernelBase/GetDeviceDriverBaseNameW.s delete mode 100644 libc/nt/KernelBase/GetDeviceDriverFileNameA.s delete mode 100644 libc/nt/KernelBase/GetDeviceDriverFileNameW.s delete mode 100644 libc/nt/KernelBase/GetMappedFileNameA.s delete mode 100644 libc/nt/KernelBase/GetMappedFileNameW.s delete mode 100644 libc/nt/KernelBase/GetModuleBaseNameA.s delete mode 100644 libc/nt/KernelBase/GetModuleBaseNameW.s delete mode 100644 libc/nt/KernelBase/GetModuleFileNameExA.s delete mode 100644 libc/nt/KernelBase/GetModuleFileNameExW.s delete mode 100644 libc/nt/KernelBase/GetModuleInformation.s delete mode 100644 libc/nt/KernelBase/GetPerformanceInfo.s delete mode 100644 libc/nt/KernelBase/GetProcessMemoryInfo.s delete mode 100644 libc/nt/KernelBase/GetWsChanges.s delete mode 100644 libc/nt/KernelBase/GetWsChangesEx.s delete mode 100644 libc/nt/KernelBase/InitializeProcessForWsWatch.s delete mode 100644 libc/nt/KernelBase/QueryWorkingSet.s delete mode 100644 libc/nt/KernelBase/QueryWorkingSetEx.s create mode 100644 libc/nt/enum/pdh.h delete mode 100644 libc/nt/kernel32/GetProcessImageFileNameA.s delete mode 100644 libc/nt/kernel32/K32GetModuleBaseNameA.s delete mode 100644 libc/nt/kernel32/K32GetModuleFileNameExA.s delete mode 100644 libc/nt/kernel32/K32GetProcessImageFileNameA.s create mode 100644 libc/nt/pdh.h create mode 100644 libc/nt/pdh/CounterPathCallBack.s create mode 100644 libc/nt/pdh/LoadPerfCounterTextStringsW.s create mode 100644 libc/nt/pdh/PdhAddCounterW.s create mode 100644 libc/nt/pdh/PdhAddEnglishCounterW.s create mode 100644 libc/nt/pdh/PdhBindInputDataSourceW.s create mode 100644 libc/nt/pdh/PdhBrowseCountersHW.s create mode 100644 libc/nt/pdh/PdhBrowseCountersW.s create mode 100644 libc/nt/pdh/PdhCalculateCounterFromRawValue.s create mode 100644 libc/nt/pdh/PdhCloseLog.s create mode 100644 libc/nt/pdh/PdhCloseQuery.s create mode 100644 libc/nt/pdh/PdhCollectQueryData.s create mode 100644 libc/nt/pdh/PdhCollectQueryDataEx.s create mode 100644 libc/nt/pdh/PdhCollectQueryDataWithTime.s create mode 100644 libc/nt/pdh/PdhComputeCounterStatistics.s create mode 100644 libc/nt/pdh/PdhConnectMachineW.s create mode 100644 libc/nt/pdh/PdhEnumLogSetNamesW.s create mode 100644 libc/nt/pdh/PdhEnumMachinesHW.s create mode 100644 libc/nt/pdh/PdhEnumMachinesW.s create mode 100644 libc/nt/pdh/PdhEnumObjectItemsHW.s create mode 100644 libc/nt/pdh/PdhEnumObjectItemsW.s create mode 100644 libc/nt/pdh/PdhEnumObjectsHW.s create mode 100644 libc/nt/pdh/PdhEnumObjectsW.s create mode 100644 libc/nt/pdh/PdhExpandCounterPathW.s create mode 100644 libc/nt/pdh/PdhExpandWildCardPathHW.s create mode 100644 libc/nt/pdh/PdhExpandWildCardPathW.s create mode 100644 libc/nt/pdh/PdhFormatFromRawValue.s create mode 100644 libc/nt/pdh/PdhGetCounterInfoW.s create mode 100644 libc/nt/pdh/PdhGetCounterTimeBase.s create mode 100644 libc/nt/pdh/PdhGetDataSourceTimeRangeH.s create mode 100644 libc/nt/pdh/PdhGetDataSourceTimeRangeW.s create mode 100644 libc/nt/pdh/PdhGetDefaultPerfCounterHW.s create mode 100644 libc/nt/pdh/PdhGetDefaultPerfCounterW.s create mode 100644 libc/nt/pdh/PdhGetDefaultPerfObjectHW.s create mode 100644 libc/nt/pdh/PdhGetDefaultPerfObjectW.s create mode 100644 libc/nt/pdh/PdhGetDllVersion.s create mode 100644 libc/nt/pdh/PdhGetFormattedCounterArrayW.s create mode 100644 libc/nt/pdh/PdhGetFormattedCounterValue.s create mode 100644 libc/nt/pdh/PdhGetLogFileSize.s create mode 100644 libc/nt/pdh/PdhGetRawCounterArrayW.s create mode 100644 libc/nt/pdh/PdhGetRawCounterValue.s create mode 100644 libc/nt/pdh/PdhIsRealTimeQuery.s create mode 100644 libc/nt/pdh/PdhLookupPerfIndexByNameW.s create mode 100644 libc/nt/pdh/PdhLookupPerfNameByIndexW.s create mode 100644 libc/nt/pdh/PdhMakeCounterPathW.s create mode 100644 libc/nt/pdh/PdhOpenLogW.s create mode 100644 libc/nt/pdh/PdhOpenQueryH.s create mode 100644 libc/nt/pdh/PdhOpenQueryW.s create mode 100644 libc/nt/pdh/PdhParseCounterPathW.s create mode 100644 libc/nt/pdh/PdhParseInstanceNameW.s create mode 100644 libc/nt/pdh/PdhReadRawLogRecord.s create mode 100644 libc/nt/pdh/PdhRemoveCounter.s create mode 100644 libc/nt/pdh/PdhSelectDataSourceW.s create mode 100644 libc/nt/pdh/PdhSetCounterScaleFactor.s create mode 100644 libc/nt/pdh/PdhSetDefaultRealTimeDataSource.s create mode 100644 libc/nt/pdh/PdhSetQueryTimeRange.s create mode 100644 libc/nt/pdh/PdhUpdateLogFileCatalog.s create mode 100644 libc/nt/pdh/PdhUpdateLogW.s create mode 100644 libc/nt/pdh/PdhValidatePathExW.s create mode 100644 libc/nt/pdh/PdhValidatePathW.s create mode 100644 libc/nt/pdh/PerfAddCounters.s create mode 100644 libc/nt/pdh/PerfCloseQueryHandle.s create mode 100644 libc/nt/pdh/PerfCreateInstance.s create mode 100644 libc/nt/pdh/PerfDecrementULongCounterValue.s create mode 100644 libc/nt/pdh/PerfDecrementULongLongCounterValue.s create mode 100644 libc/nt/pdh/PerfDeleteCounters.s create mode 100644 libc/nt/pdh/PerfDeleteInstance.s create mode 100644 libc/nt/pdh/PerfEnumerateCounterSet.s create mode 100644 libc/nt/pdh/PerfEnumerateCounterSetInstances.s create mode 100644 libc/nt/pdh/PerfIncrementULongCounterValue.s create mode 100644 libc/nt/pdh/PerfIncrementULongLongCounterValue.s create mode 100644 libc/nt/pdh/PerfOpenQueryHandle.s create mode 100644 libc/nt/pdh/PerfQueryCounterData.s create mode 100644 libc/nt/pdh/PerfQueryCounterInfo.s create mode 100644 libc/nt/pdh/PerfQueryCounterSetRegistrationInfo.s create mode 100644 libc/nt/pdh/PerfQueryInstance.s create mode 100644 libc/nt/pdh/PerfSetCounterRefValue.s create mode 100644 libc/nt/pdh/PerfSetCounterSetInfo.s create mode 100644 libc/nt/pdh/PerfSetULongCounterValue.s create mode 100644 libc/nt/pdh/PerfSetULongLongCounterValue.s create mode 100644 libc/nt/pdh/PerfStartProvider.s create mode 100644 libc/nt/pdh/PerfStartProviderEx.s create mode 100644 libc/nt/pdh/PerfStopProvider.s create mode 100644 libc/nt/pdh/UnloadPerfCounterTextStringsW.s create mode 100644 libc/nt/psapi/EmptyWorkingSet.s create mode 100644 libc/nt/psapi/EnumDeviceDrivers.s create mode 100644 libc/nt/psapi/EnumPageFilesW.s create mode 100644 libc/nt/psapi/EnumProcessModules.s create mode 100644 libc/nt/psapi/EnumProcessModulesEx.s create mode 100644 libc/nt/psapi/EnumProcesses.s create mode 100644 libc/nt/psapi/GetDeviceDriverBaseNameW.s create mode 100644 libc/nt/psapi/GetDeviceDriverFileNameW.s create mode 100644 libc/nt/psapi/GetMappedFileNameW.s create mode 100644 libc/nt/psapi/GetModuleBaseNameW.s create mode 100644 libc/nt/psapi/GetModuleFileNameExW.s create mode 100644 libc/nt/psapi/GetModuleInformation.s create mode 100644 libc/nt/psapi/GetPerformanceInfo.s rename libc/nt/{kernel32 => psapi}/GetProcessImageFileNameW.s (75%) create mode 100644 libc/nt/psapi/GetProcessMemoryInfo.s create mode 100644 libc/nt/psapi/GetWsChanges.s create mode 100644 libc/nt/psapi/GetWsChangesEx.s create mode 100644 libc/nt/psapi/InitializeProcessForWsWatch.s create mode 100644 libc/nt/psapi/QueryWorkingSet.s create mode 100644 libc/nt/psapi/QueryWorkingSetEx.s create mode 100644 libc/nt/struct/pdhfmtcountervalue.h create mode 100644 libc/nt/struct/processmemorycounters.h diff --git a/Makefile b/Makefile index 9051281bf..9f8b04ac5 100644 --- a/Makefile +++ b/Makefile @@ -276,6 +276,9 @@ COSMOPOLITAN_OBJECTS = \ LIBC_CALLS \ LIBC_RAND \ LIBC_SYSV_CALLS \ + LIBC_NT_PSAPI \ + LIBC_NT_POWERPROF \ + LIBC_NT_PDH \ LIBC_NT_KERNELBASE \ LIBC_NT_SHELL32 \ LIBC_NT_GDI32 \ diff --git a/examples/loadavg.c b/examples/loadavg.c index 5a5589d71..c2550f066 100644 --- a/examples/loadavg.c +++ b/examples/loadavg.c @@ -10,6 +10,7 @@ #include "libc/calls/calls.h" #include "libc/log/check.h" #include "libc/stdio/stdio.h" +#include "libc/time/time.h" int main(int argc, char *argv[]) { double x[3]; diff --git a/libc/calls/calls.mk b/libc/calls/calls.mk index e81419499..8511564f0 100644 --- a/libc/calls/calls.mk +++ b/libc/calls/calls.mk @@ -44,6 +44,8 @@ LIBC_CALLS_A_DIRECTDEPS = \ LIBC_NT_IPHLPAPI \ LIBC_NT_KERNEL32 \ LIBC_NT_NTDLL \ + LIBC_NT_PDH \ + LIBC_NT_PSAPI \ LIBC_NT_POWERPROF \ LIBC_NT_WS2_32 \ LIBC_STR \ diff --git a/libc/calls/getloadavg.c b/libc/calls/getloadavg.c index 4a10d0b23..5a896926e 100644 --- a/libc/calls/getloadavg.c +++ b/libc/calls/getloadavg.c @@ -31,7 +31,6 @@ int getloadavg(double *a, int n) { struct sysinfo si; if (!n) return 0; if (n < 0) return einval(); - if (IsWindows()) return enosys(); /* TODO(jart) */ if (sysinfo(&si) == -1) return -1; if (n > 3) n = 3; for (i = 0; i < n; i++) { diff --git a/libc/calls/getrusage-nt.c b/libc/calls/getrusage-nt.c index 8d3fbe9e0..9e922131a 100644 --- a/libc/calls/getrusage-nt.c +++ b/libc/calls/getrusage-nt.c @@ -21,7 +21,9 @@ #include "libc/calls/struct/rusage.h" #include "libc/fmt/conv.h" #include "libc/nt/accounting.h" +#include "libc/nt/process.h" #include "libc/nt/runtime.h" +#include "libc/nt/struct/processmemorycounters.h" #include "libc/nt/thread.h" #include "libc/str/str.h" #include "libc/sysv/consts/rusage.h" @@ -32,6 +34,7 @@ textwindows int sys_getrusage_nt(int who, struct rusage *usage) { struct NtFileTime ExitFileTime; struct NtFileTime KernelFileTime; struct NtFileTime UserFileTime; + struct NtProcessMemoryCountersEx memcount; if (!usage) return efault(); if (who == 99) return enosys(); /* @see libc/sysv/consts.sh */ bzero(usage, sizeof(*usage)); @@ -40,8 +43,14 @@ textwindows int sys_getrusage_nt(int who, struct rusage *usage) { &CreationFileTime, &ExitFileTime, &KernelFileTime, &UserFileTime)) { usage->ru_utime = FileTimeToTimeVal(UserFileTime); usage->ru_stime = FileTimeToTimeVal(KernelFileTime); - return 0; } else { return __winerr(); } + if (GetProcessMemoryInfo(GetCurrentProcess(), &memcount, sizeof(memcount))) { + usage->ru_maxrss = memcount.PeakWorkingSetSize; + usage->ru_majflt = memcount.PageFaultCount; + } else { + return __winerr(); + } + return 0; } diff --git a/libc/calls/isexecutable.c b/libc/calls/isexecutable.c index f8de085a6..b1c3974d2 100644 --- a/libc/calls/isexecutable.c +++ b/libc/calls/isexecutable.c @@ -29,8 +29,7 @@ * @vforksafe */ bool isexecutable(const char *path) { - /* execve() depends on this */ - struct stat st; + struct stat st; /* execve() depends on this */ if (fstatat(AT_FDCWD, path, &st, 0)) return 0; - return !!(st.st_mode & 0111); + return !S_ISDIR(st.st_mode) && !!(st.st_mode & 0111); } diff --git a/libc/calls/kill-nt.c b/libc/calls/kill-nt.c index 9f5c5a759..b568ce041 100644 --- a/libc/calls/kill-nt.c +++ b/libc/calls/kill-nt.c @@ -23,24 +23,34 @@ #include "libc/nt/console.h" #include "libc/nt/enum/ctrlevent.h" #include "libc/nt/enum/processaccess.h" +#include "libc/nt/errors.h" #include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/sysv/errfuns.h" textwindows int sys_kill_nt(int pid, int sig) { bool ok; - int event; int64_t handle; + int event, ntpid; if (pid) { pid = ABS(pid); if ((event = GetConsoleCtrlEvent(sig)) != -1) { - ok = !!GenerateConsoleCtrlEvent( - event, __isfdkind(pid, kFdProcess) ? GetProcessId(g_fds.p[pid].handle) - : pid); + /* kill(pid, SIGINT|SIGHUP|SIGQUIT) */ + if (__isfdkind(pid, kFdProcess)) { + ntpid = GetProcessId(g_fds.p[pid].handle); + } else if (!__isfdopen(pid)) { + /* XXX: this is sloppy (see fork-nt.c) */ + ntpid = pid; + } else { + return esrch(); + } + ok = !!GenerateConsoleCtrlEvent(event, ntpid); } else if (__isfdkind(pid, kFdProcess)) { ok = !!TerminateProcess(g_fds.p[pid].handle, 128 + sig); - } else if ((handle = OpenProcess(kNtProcessAllAccess, false, pid))) { + if (!ok && GetLastError() == kNtErrorAccessDenied) ok = true; + } else if ((handle = OpenProcess(kNtProcessTerminate, false, pid))) { ok = !!TerminateProcess(handle, 128 + sig); + if (!ok && GetLastError() == kNtErrorAccessDenied) ok = true; CloseHandle(handle); } else { ok = false; diff --git a/libc/calls/loadavg-nt.c b/libc/calls/loadavg-nt.c new file mode 100644 index 000000000..977b992f2 --- /dev/null +++ b/libc/calls/loadavg-nt.c @@ -0,0 +1,95 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/loadavg.internal.h" +#include "libc/calls/strace.internal.h" +#include "libc/dce.h" +#include "libc/errno.h" +#include "libc/nexgen32e/nt2sysv.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/pdh.h" +#include "libc/nt/enum/securityimpersonationlevel.h" +#include "libc/nt/enum/wt.h" +#include "libc/nt/errors.h" +#include "libc/nt/events.h" +#include "libc/nt/files.h" +#include "libc/nt/pdh.h" +#include "libc/nt/privilege.h" +#include "libc/nt/runtime.h" +#include "libc/nt/struct/luid.h" +#include "libc/nt/struct/pdhfmtcountervalue.h" +#include "libc/nt/struct/tokenprivileges.h" +#include "libc/nt/synchronization.h" +#include "libc/str/str.h" + +/** + * @fileoverview sysinfo() on the new technology + * @kudos Giampaolo Rodola for teaching how to do load average + */ + +#define LOAD_SAMPLING_INTERVAL 1 // in seconds + +// https://github.com/torvalds/linux/blob/345671ea0f9258f410eb057b9ced9cefbbe5dc78/include/linux/sched/loadavg.h#L20-L23 +#define LOAD1F .9200444146293232478931553241 +#define LOAD5F .9834714538216174894737477501 +#define LOAD15F .9944598480048967508795473394 + +double __ntloadavg[3]; + +static void LoadavgNtPoll(int64_t hCounter, bool32 timedOut) { + struct NtPdhFmtCountervalue c; + if (!PdhGetFormattedCounterValue(hCounter, kNtPdhFmtDouble, 0, &c)) { + __ntloadavg[0] = __ntloadavg[0] * LOAD1F + c.doubleValue * (1 - LOAD1F); + __ntloadavg[1] = __ntloadavg[1] * LOAD5F + c.doubleValue * (1 - LOAD5F); + __ntloadavg[2] = __ntloadavg[2] * LOAD15F + c.doubleValue * (1 - LOAD15F); + } else { + STRACE("PdhGetFormattedCounterValue(%ld) failed", hCounter); + } +} + +static textstartup void LoadavgNtInit(void) { + int64_t hQuery, hCounter, hEvent, hWaiter; + if (!IsWindows()) return; + STRACE("LoadavgNtInit()"); + if (PdhOpenQuery(0, 0, &hQuery)) { + STRACE("PdhOpenQuery failed"); + return; + } + if (PdhAddEnglishCounter(hQuery, u"\\System\\Processor Queue Length", 0, + &hCounter)) { + STRACE("PdhAddEnglishCounter() failed"); + return; + } + if (!(hEvent = CreateEvent(0, 0, 0, u"LoadUpdateEvent"))) { + STRACE("CreateEvent() failed"); + return; + } + if (PdhCollectQueryDataEx(hQuery, LOAD_SAMPLING_INTERVAL, hEvent)) { + STRACE("PdhCollectQueryDataEx() failed"); + return; + } + if (!RegisterWaitForSingleObject( + &hWaiter, hEvent, (void *)NT2SYSV(LoadavgNtPoll), + (void *)(intptr_t)hCounter, -1, kNtWtExecutedefault)) { + STRACE("RegisterWaitForSingleObject() failed"); + return; + } + LoadavgNtPoll(hCounter, 0); +} + +const void *const LoadavgNtCtor[] initarray = {LoadavgNtInit}; diff --git a/libc/calls/loadavg.internal.h b/libc/calls/loadavg.internal.h new file mode 100644 index 000000000..dbae0f1a0 --- /dev/null +++ b/libc/calls/loadavg.internal.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_LIBC_CALLS_LOADAVG_INTERNAL_H_ +#define COSMOPOLITAN_LIBC_CALLS_LOADAVG_INTERNAL_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +extern double __ntloadavg[3]; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_CALLS_LOADAVG_INTERNAL_H_ */ diff --git a/libc/calls/sedebug.c b/libc/calls/sedebug.c new file mode 100644 index 000000000..c3988b70b --- /dev/null +++ b/libc/calls/sedebug.c @@ -0,0 +1,92 @@ +/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ +│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ +╞══════════════════════════════════════════════════════════════════════════════╡ +│ Copyright 2022 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/calls/calls.h" +#include "libc/calls/strace.internal.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/securityimpersonationlevel.h" +#include "libc/nt/errors.h" +#include "libc/nt/files.h" +#include "libc/nt/privilege.h" +#include "libc/nt/runtime.h" +#include "libc/nt/struct/luid.h" +#include "libc/nt/struct/tokenprivileges.h" + +static bool32 SetPrivilegeNt(int64_t hToken, const char16_t *lpwPrivilege, + bool32 bEnable) { + struct NtLuid luid; + uint32_t cbPrevious; + struct NtTokenPrivileges tp, tpPrevious; + cbPrevious = sizeof(struct NtTokenPrivileges); + if (!LookupPrivilegeValue(0, lpwPrivilege, &luid)) { + STRACE("LookupPrivilegeValue() failed"); + return false; + } + tp.PrivilegeCount = 1; + tp.Privileges[0].Luid = luid; + tp.Privileges[0].Attributes = 0; + if (!AdjustTokenPrivileges(hToken, false, &tp, sizeof(tp), &tpPrevious, + &cbPrevious)) { + STRACE("AdjustTokenPrivileges() failed"); + return false; + } + tpPrevious.PrivilegeCount = 1; + tpPrevious.Privileges[0].Luid = luid; + if (bEnable) { + tpPrevious.Privileges[0].Attributes |= kNtSePrivilegeEnabled; + } else { + tpPrevious.Privileges[0].Attributes ^= + kNtSePrivilegeEnabled & tpPrevious.Privileges[0].Attributes; + } + if (!AdjustTokenPrivileges(hToken, false, &tpPrevious, cbPrevious, 0, 0)) { + STRACE("AdjustTokenPrivileges() failed"); + return false; + } + return true; +} + +static int64_t GetCurrentProcessSecurityToken(void) { + int64_t hToken; + if (OpenProcessToken(GetCurrentProcess(), + kNtTokenAdjustPrivileges | kNtTokenQuery, &hToken)) { + return hToken; + } else if (GetLastError() == kNtErrorNoToken) { + if (ImpersonateSelf(kNtSecurityImpersonation)) { + if (OpenProcessToken(GetCurrentProcess(), + kNtTokenAdjustPrivileges | kNtTokenQuery, &hToken)) { + return hToken; + } else { + STRACE("OpenProcessToken() failed"); + } + } else { + STRACE("ImpersonateSelf() failed"); + } + } else { + STRACE("OpenProcessToken() failed"); + } + return 0; +} + +bool32 ElevateSeDebugPrivilege(void) { + int64_t hToken; + if (!(hToken = GetCurrentProcessSecurityToken())) return false; + SetPrivilegeNt(hToken, u"SeDebugPrivilege", true); + RevertToSelf(); + CloseHandle(hToken); + return true; +} diff --git a/libc/calls/sysinfo-nt.c b/libc/calls/sysinfo-nt.c index dc866fb8b..934d4fafc 100644 --- a/libc/calls/sysinfo-nt.c +++ b/libc/calls/sysinfo-nt.c @@ -17,6 +17,7 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/internal.h" +#include "libc/calls/loadavg.internal.h" #include "libc/calls/struct/sysinfo.h" #include "libc/nt/accounting.h" #include "libc/nt/struct/memorystatusex.h" @@ -32,6 +33,9 @@ textwindows int sys_sysinfo_nt(struct sysinfo *info) { info->totalram = memstat.ullTotalPhys; info->freeram = memstat.ullAvailPhys; info->procs = sysinfo.dwNumberOfProcessors; + info->loads[0] = __ntloadavg[0] * 65536; + info->loads[1] = __ntloadavg[1] * 65536; + info->loads[2] = __ntloadavg[2] * 65536; info->mem_unit = 1; return 0; } else { diff --git a/libc/calls/sysinfo.c b/libc/calls/sysinfo.c index 11cafd245..18b33083a 100644 --- a/libc/calls/sysinfo.c +++ b/libc/calls/sysinfo.c @@ -47,8 +47,10 @@ int sysinfo(struct sysinfo *info) { } else { rc = sys_sysinfo_nt(info); } - info->procs = MAX(1, info->procs); - info->mem_unit = MAX(1, info->mem_unit); - info->totalram = MAX((8 * 1024 * 1024) / info->mem_unit, info->totalram); + if (rc != -1) { + info->procs = MAX(1, info->procs); + info->mem_unit = MAX(1, info->mem_unit); + info->totalram = MAX((8 * 1024 * 1024) / info->mem_unit, info->totalram); + } return rc; } diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index a55a4a46e..35a1b7e07 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -24,26 +24,47 @@ #include "libc/fmt/conv.h" #include "libc/macros.internal.h" #include "libc/nt/accounting.h" +#include "libc/nt/enum/accessmask.h" +#include "libc/nt/enum/processaccess.h" #include "libc/nt/enum/status.h" #include "libc/nt/enum/wait.h" +#include "libc/nt/process.h" #include "libc/nt/runtime.h" #include "libc/nt/struct/filetime.h" +#include "libc/nt/struct/processmemorycounters.h" #include "libc/nt/synchronization.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" +#include "libc/sysv/consts/o.h" #include "libc/sysv/consts/w.h" #include "libc/sysv/errfuns.h" textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, struct rusage *opt_out_rusage) { int pids[64]; + int64_t handle; int64_t handles[64]; uint32_t dwExitCode; uint32_t i, count, timeout; + struct NtProcessMemoryCountersEx memcount; struct NtFileTime createfiletime, exitfiletime, kernelfiletime, userfiletime; if (pid != -1) { if (!__isfdkind(pid, kFdProcess)) { - return echild(); + /* XXX: this is sloppy (see fork-nt.c) */ + if (!__isfdopen(pid) && + (handle = OpenProcess(kNtSynchronize | kNtProcessQueryInformation, + true, pid))) { + if ((pid = __reservefd()) != -1) { + g_fds.p[pid].kind = kFdProcess; + g_fds.p[pid].handle = handle; + g_fds.p[pid].flags = O_CLOEXEC; + } else { + CloseHandle(handle); + return echild(); + } + } else { + return echild(); + } } handles[0] = g_fds.p[pid].handle; pids[0] = pid; @@ -74,7 +95,6 @@ textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, STRACE("%s failed %u", "WaitForMultipleObjects", GetLastError()); return __winerr(); } - assert(__isfdkind(pids[i], kFdProcess)); if (!GetExitCodeProcess(handles[i], &dwExitCode)) { STRACE("%s failed %u", "GetExitCodeProcess", GetLastError()); return __winerr(); @@ -85,8 +105,14 @@ textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, } if (opt_out_rusage) { bzero(opt_out_rusage, sizeof(*opt_out_rusage)); - if (GetProcessTimes(g_fds.p[pids[i]].handle, &createfiletime, - &exitfiletime, &kernelfiletime, &userfiletime)) { + if (GetProcessMemoryInfo(handles[i], &memcount, sizeof(memcount))) { + opt_out_rusage->ru_maxrss = memcount.PeakWorkingSetSize; + opt_out_rusage->ru_majflt = memcount.PageFaultCount; + } else { + STRACE("%s failed %u", "GetProcessMemoryInfo", GetLastError()); + } + if (GetProcessTimes(handles[i], &createfiletime, &exitfiletime, + &kernelfiletime, &userfiletime)) { opt_out_rusage->ru_utime = WindowsDurationToTimeVal(ReadFileTime(userfiletime)); opt_out_rusage->ru_stime = @@ -95,8 +121,8 @@ textwindows int sys_wait4_nt(int pid, int *opt_out_wstatus, int options, STRACE("%s failed %u", "GetProcessTimes", GetLastError()); } } - CloseHandle(g_fds.p[pids[i]].handle); - g_fds.p[pids[i]].kind = kFdEmpty; + CloseHandle(handles[i]); + __releasefd(pids[i]); return pids[i]; } } diff --git a/libc/isystem/windows.h b/libc/isystem/windows.h index c2571efea..ee92e29f4 100644 --- a/libc/isystem/windows.h +++ b/libc/isystem/windows.h @@ -250,6 +250,12 @@ #define HUMPD int64_t #define HWND int64_t +#define PDH_FUNCTION LONG + +#define PDH_HCOUNTER HANDLE +#define PDH_HQUERY HANDLE +#define PDH_HLOG HANDLE + #define ADDRESS_FAMILY uint16_t #define TUNNEL_TYPE uint32_t #define NET_IF_CONNECTION_TYPE uint32_t @@ -440,6 +446,9 @@ #define _FILE_FULL_EA_INFORMATION NtFileFullEaInformation #define FILE_FULL_EA_INFORMATION struct NtFileFullEaInformation #define PFILE_FULL_EA_INFORMATION struct NtFileFullEaInformation* +#define _PDH_FMT_COUNTERVALUE NtPdhFmtCountervalue +#define PDH_FMT_COUNTERVALUE struct NtPdhFmtCountervalue +#define PPDH_FMT_COUNTERVALUE struct NtPdhFmtCountervalue* #define _LUID NtLuid #define LUID struct NtLuid diff --git a/libc/log/backtrace2.c b/libc/log/backtrace2.c index 0648b13d4..8744e416a 100644 --- a/libc/log/backtrace2.c +++ b/libc/log/backtrace2.c @@ -22,6 +22,7 @@ #include "libc/bits/weaken.h" #include "libc/calls/calls.h" #include "libc/calls/sigbits.h" +#include "libc/calls/strace.internal.h" #include "libc/dce.h" #include "libc/errno.h" #include "libc/fmt/conv.h" @@ -170,15 +171,28 @@ static int PrintBacktrace(int fd, const struct StackFrame *bp) { void ShowBacktrace(int fd, const struct StackFrame *bp) { #ifdef __FNO_OMIT_FRAME_POINTER__ /* asan runtime depends on this function */ + int st, ft; static bool noreentry; - ++g_ftrace; - if (!bp) bp = __builtin_frame_address(0); if (!noreentry) { noreentry = true; + + st = __strace; + __strace = 0; + + ft = g_ftrace; + g_ftrace = 0; + + if (!bp) { + bp = __builtin_frame_address(0); + } + PrintBacktrace(fd, bp); + + __strace = st; + g_ftrace = ft; + noreentry = false; } - --g_ftrace; #else kprintf("ShowBacktrace() needs these flags to show C backtrace:%n" "\t-D__FNO_OMIT_FRAME_POINTER__%n" diff --git a/libc/nt/KernelBase/EmptyWorkingSet.s b/libc/nt/KernelBase/EmptyWorkingSet.s deleted file mode 100644 index 911ef1ca2..000000000 --- a/libc/nt/KernelBase/EmptyWorkingSet.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EmptyWorkingSet,EmptyWorkingSet,287 diff --git a/libc/nt/KernelBase/EnumDeviceDrivers.s b/libc/nt/KernelBase/EnumDeviceDrivers.s deleted file mode 100644 index 9e8f6850e..000000000 --- a/libc/nt/KernelBase/EnumDeviceDrivers.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumDeviceDrivers,EnumDeviceDrivers,300 diff --git a/libc/nt/KernelBase/EnumPageFilesA.s b/libc/nt/KernelBase/EnumPageFilesA.s deleted file mode 100644 index 8ceb2d182..000000000 --- a/libc/nt/KernelBase/EnumPageFilesA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumPageFilesA,EnumPageFilesA,303 diff --git a/libc/nt/KernelBase/EnumPageFilesW.s b/libc/nt/KernelBase/EnumPageFilesW.s deleted file mode 100644 index 66a4b9f37..000000000 --- a/libc/nt/KernelBase/EnumPageFilesW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumPageFilesW,EnumPageFilesW,304 diff --git a/libc/nt/KernelBase/EnumProcessModules.s b/libc/nt/KernelBase/EnumProcessModules.s deleted file mode 100644 index 0b9b116eb..000000000 --- a/libc/nt/KernelBase/EnumProcessModules.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumProcessModules,EnumProcessModules,305 diff --git a/libc/nt/KernelBase/EnumProcessModulesEx.s b/libc/nt/KernelBase/EnumProcessModulesEx.s deleted file mode 100644 index 5e4366cdb..000000000 --- a/libc/nt/KernelBase/EnumProcessModulesEx.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumProcessModulesEx,EnumProcessModulesEx,306 diff --git a/libc/nt/KernelBase/EnumProcesses.s b/libc/nt/KernelBase/EnumProcesses.s deleted file mode 100644 index cb704c5cb..000000000 --- a/libc/nt/KernelBase/EnumProcesses.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_EnumProcesses,EnumProcesses,307 diff --git a/libc/nt/KernelBase/GetDeviceDriverBaseNameA.s b/libc/nt/KernelBase/GetDeviceDriverBaseNameA.s deleted file mode 100644 index df0486063..000000000 --- a/libc/nt/KernelBase/GetDeviceDriverBaseNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetDeviceDriverBaseNameA,GetDeviceDriverBaseNameA,511 diff --git a/libc/nt/KernelBase/GetDeviceDriverBaseNameW.s b/libc/nt/KernelBase/GetDeviceDriverBaseNameW.s deleted file mode 100644 index 1908f1887..000000000 --- a/libc/nt/KernelBase/GetDeviceDriverBaseNameW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetDeviceDriverBaseNameW,GetDeviceDriverBaseNameW,512 diff --git a/libc/nt/KernelBase/GetDeviceDriverFileNameA.s b/libc/nt/KernelBase/GetDeviceDriverFileNameA.s deleted file mode 100644 index 7c6baa79b..000000000 --- a/libc/nt/KernelBase/GetDeviceDriverFileNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetDeviceDriverFileNameA,GetDeviceDriverFileNameA,513 diff --git a/libc/nt/KernelBase/GetDeviceDriverFileNameW.s b/libc/nt/KernelBase/GetDeviceDriverFileNameW.s deleted file mode 100644 index 801b800a6..000000000 --- a/libc/nt/KernelBase/GetDeviceDriverFileNameW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetDeviceDriverFileNameW,GetDeviceDriverFileNameW,514 diff --git a/libc/nt/KernelBase/GetMappedFileNameA.s b/libc/nt/KernelBase/GetMappedFileNameA.s deleted file mode 100644 index 1968033c9..000000000 --- a/libc/nt/KernelBase/GetMappedFileNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetMappedFileNameA,GetMappedFileNameA,594 diff --git a/libc/nt/KernelBase/GetMappedFileNameW.s b/libc/nt/KernelBase/GetMappedFileNameW.s deleted file mode 100644 index 118bab1ac..000000000 --- a/libc/nt/KernelBase/GetMappedFileNameW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetMappedFileNameW,GetMappedFileNameW,595 diff --git a/libc/nt/KernelBase/GetModuleBaseNameA.s b/libc/nt/KernelBase/GetModuleBaseNameA.s deleted file mode 100644 index 0130241e2..000000000 --- a/libc/nt/KernelBase/GetModuleBaseNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetModuleBaseNameA,GetModuleBaseNameA,597 diff --git a/libc/nt/KernelBase/GetModuleBaseNameW.s b/libc/nt/KernelBase/GetModuleBaseNameW.s deleted file mode 100644 index f3c1df4f9..000000000 --- a/libc/nt/KernelBase/GetModuleBaseNameW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetModuleBaseNameW,GetModuleBaseNameW,598 diff --git a/libc/nt/KernelBase/GetModuleFileNameExA.s b/libc/nt/KernelBase/GetModuleFileNameExA.s deleted file mode 100644 index e04572ea3..000000000 --- a/libc/nt/KernelBase/GetModuleFileNameExA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetModuleFileNameExA,GetModuleFileNameExA,600 diff --git a/libc/nt/KernelBase/GetModuleFileNameExW.s b/libc/nt/KernelBase/GetModuleFileNameExW.s deleted file mode 100644 index 61be98603..000000000 --- a/libc/nt/KernelBase/GetModuleFileNameExW.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetModuleFileNameExW,GetModuleFileNameExW,601 diff --git a/libc/nt/KernelBase/GetModuleInformation.s b/libc/nt/KernelBase/GetModuleInformation.s deleted file mode 100644 index c845db472..000000000 --- a/libc/nt/KernelBase/GetModuleInformation.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetModuleInformation,GetModuleInformation,607 diff --git a/libc/nt/KernelBase/GetPerformanceInfo.s b/libc/nt/KernelBase/GetPerformanceInfo.s deleted file mode 100644 index 33d9bae17..000000000 --- a/libc/nt/KernelBase/GetPerformanceInfo.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetPerformanceInfo,GetPerformanceInfo,659 diff --git a/libc/nt/KernelBase/GetProcessMemoryInfo.s b/libc/nt/KernelBase/GetProcessMemoryInfo.s deleted file mode 100644 index ae3f6cd60..000000000 --- a/libc/nt/KernelBase/GetProcessMemoryInfo.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetProcessMemoryInfo,GetProcessMemoryInfo,679 diff --git a/libc/nt/KernelBase/GetWsChanges.s b/libc/nt/KernelBase/GetWsChanges.s deleted file mode 100644 index 24cd8dadb..000000000 --- a/libc/nt/KernelBase/GetWsChanges.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetWsChanges,GetWsChanges,817 diff --git a/libc/nt/KernelBase/GetWsChangesEx.s b/libc/nt/KernelBase/GetWsChangesEx.s deleted file mode 100644 index 80b7db59a..000000000 --- a/libc/nt/KernelBase/GetWsChangesEx.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_GetWsChangesEx,GetWsChangesEx,818 diff --git a/libc/nt/KernelBase/InitializeProcessForWsWatch.s b/libc/nt/KernelBase/InitializeProcessForWsWatch.s deleted file mode 100644 index 6b62b5f8d..000000000 --- a/libc/nt/KernelBase/InitializeProcessForWsWatch.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_InitializeProcessForWsWatch,InitializeProcessForWsWatch,860 diff --git a/libc/nt/KernelBase/QueryWorkingSet.s b/libc/nt/KernelBase/QueryWorkingSet.s deleted file mode 100644 index 33c81e0e8..000000000 --- a/libc/nt/KernelBase/QueryWorkingSet.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_QueryWorkingSet,QueryWorkingSet,1280 diff --git a/libc/nt/KernelBase/QueryWorkingSetEx.s b/libc/nt/KernelBase/QueryWorkingSetEx.s deleted file mode 100644 index 8d4a394b0..000000000 --- a/libc/nt/KernelBase/QueryWorkingSetEx.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp KernelBase,__imp_QueryWorkingSetEx,QueryWorkingSetEx,1281 diff --git a/libc/nt/advapi32/ImpersonateSelf.s b/libc/nt/advapi32/ImpersonateSelf.s index 1410e1d9c..454bd1f2a 100644 --- a/libc/nt/advapi32/ImpersonateSelf.s +++ b/libc/nt/advapi32/ImpersonateSelf.s @@ -1,2 +1,15 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_ImpersonateSelf,ImpersonateSelf,0 + + .text.windows +ImpersonateSelf: + push %rbp + mov %rsp,%rbp + .profilable + mov %rdi,%rcx + sub $32,%rsp + call *__imp_ImpersonateSelf(%rip) + leave + ret + .endfn ImpersonateSelf,globl + .previous diff --git a/libc/nt/advapi32/RevertToSelf.s b/libc/nt/advapi32/RevertToSelf.s index 9b19851fa..982195652 100644 --- a/libc/nt/advapi32/RevertToSelf.s +++ b/libc/nt/advapi32/RevertToSelf.s @@ -1,2 +1,14 @@ .include "o/libc/nt/codegen.inc" .imp advapi32,__imp_RevertToSelf,RevertToSelf,0 + + .text.windows +RevertToSelf: + push %rbp + mov %rsp,%rbp + .profilable + sub $32,%rsp + call *__imp_RevertToSelf(%rip) + leave + ret + .endfn RevertToSelf,globl + .previous diff --git a/libc/nt/enum/pdh.h b/libc/nt/enum/pdh.h new file mode 100644 index 000000000..b4e2f50e8 --- /dev/null +++ b/libc/nt/enum/pdh.h @@ -0,0 +1,17 @@ +#ifndef COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_ +#define COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_ + +#define kNtPdhFmtRaw 0x00000010u +#define kNtPdhFmtAnsi 0x00000020u +#define kNtPdhFmtUnicode 0x00000040u +#define kNtPdhFmtLong 0x00000100u +#define kNtPdhFmtDouble 0x00000200u +#define kNtPdhFmtLarge 0x00000400u +#define kNtPdhFmtNoscale 0x00001000u +#define kNtPdhFmt1000 0x00002000u +#define kNtPdhFmtNodata 0x00004000u +#define kNtPdhFmtNocap100 0x00008000u +#define kNtPerfDetailCostly 0x00010000u +#define kNtPerfDetailStandard 0x0000FFFFu + +#endif /* COSMOPOLITAN_LIBC_NT_ENUM_PDH_H_ */ diff --git a/libc/nt/enum/wt.h b/libc/nt/enum/wt.h index 0430e5da3..a79955ea8 100644 --- a/libc/nt/enum/wt.h +++ b/libc/nt/enum/wt.h @@ -1,10 +1,11 @@ #ifndef COSMOPOLITAN_LIBC_NT_ENUM_WT_H_ #define COSMOPOLITAN_LIBC_NT_ENUM_WT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ -#define kNtWtExecuteonlyonce 8 +#define kNtWtExecutedefault 0x00000000u +#define kNtWtExecuteonlyonce 0x00000008u +#define kNtWtExecuteintimerthread 0x00000020u +#define kNtWtExecuteinpersistentthread 0x00000080u +#define kNtWtExecutelongfunction 0x00000010u +#define kNtWtTransferImpersonation 0𝔵00000100𝔲 -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_ENUM_WT_H_ */ diff --git a/libc/nt/kernel32/GetProcessImageFileNameA.s b/libc/nt/kernel32/GetProcessImageFileNameA.s deleted file mode 100644 index 359e4ff60..000000000 --- a/libc/nt/kernel32/GetProcessImageFileNameA.s +++ /dev/null @@ -1,12 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_GetProcessImageFileNameA,GetProcessImageFileNameA,676 - - .text.windows -GetProcessImageFileNameA: - push %rbp - mov %rsp,%rbp - .profilable - mov __imp_GetProcessImageFileNameA(%rip),%rax - jmp __sysv2nt - .endfn GetProcessImageFileNameA,globl - .previous diff --git a/libc/nt/kernel32/K32GetModuleBaseNameA.s b/libc/nt/kernel32/K32GetModuleBaseNameA.s deleted file mode 100644 index 38c0d1d20..000000000 --- a/libc/nt/kernel32/K32GetModuleBaseNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_K32GetModuleBaseNameA,K32GetModuleBaseNameA,0 diff --git a/libc/nt/kernel32/K32GetModuleFileNameExA.s b/libc/nt/kernel32/K32GetModuleFileNameExA.s deleted file mode 100644 index 217375ed0..000000000 --- a/libc/nt/kernel32/K32GetModuleFileNameExA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_K32GetModuleFileNameExA,K32GetModuleFileNameExA,0 diff --git a/libc/nt/kernel32/K32GetProcessImageFileNameA.s b/libc/nt/kernel32/K32GetProcessImageFileNameA.s deleted file mode 100644 index b28e59ea8..000000000 --- a/libc/nt/kernel32/K32GetProcessImageFileNameA.s +++ /dev/null @@ -1,2 +0,0 @@ -.include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_K32GetProcessImageFileNameA,K32GetProcessImageFileNameA,0 diff --git a/libc/nt/master.sh b/libc/nt/master.sh index 9830809ee..e175d5d09 100755 --- a/libc/nt/master.sh +++ b/libc/nt/master.sh @@ -1,20 +1,5 @@ /usr/bin/env echo ' -*-mode:sh;indent-tabs-mode:nil;tab-width:8;coding:utf-8-*-│ │vi: set net ft=sh ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ ╚────────────────────────────────────────────────────────────────'>/dev/null #*/ . libc/nt/codegen.sh @@ -1355,7 +1340,6 @@ imp 'ElfReportEventAndSource' ElfReportEventAndSourceW advapi32 1263 imp 'ElfReportEvent' ElfReportEventW advapi32 1264 imp 'Ellipse' Ellipse gdi32 1395 imp 'EmptyClipboard' EmptyClipboard user32 1740 -imp 'EmptyWorkingSet' EmptyWorkingSet KernelBase 287 imp 'EnableEUDC' EnableEUDC gdi32 1396 imp 'EnableMenuItem' EnableMenuItem user32 1741 imp 'EnableMouseInPointer' EnableMouseInPointer user32 1742 @@ -1452,7 +1436,6 @@ imp 'EnumDependentServices' EnumDependentServicesW advapi32 1273 imp 'EnumDesktopWindows' EnumDesktopWindows user32 1757 imp 'EnumDesktopsA' EnumDesktopsA user32 1758 imp 'EnumDesktops' EnumDesktopsW user32 1759 -imp 'EnumDeviceDrivers' EnumDeviceDrivers KernelBase 300 imp 'EnumDisplayDevicesA' EnumDisplayDevicesA user32 1760 imp 'EnumDisplayDevices' EnumDisplayDevicesW user32 1761 imp 'EnumDisplayMonitors' EnumDisplayMonitors user32 1762 @@ -1474,11 +1457,6 @@ imp 'EnumLanguageGroupLocalesA' EnumLanguageGroupLocalesA kernel32 321 imp 'EnumLanguageGroupLocales' EnumLanguageGroupLocalesW kernel32 0 # KernelBase imp 'EnumMetaFile' EnumMetaFile gdi32 1457 imp 'EnumObjects' EnumObjects gdi32 1458 -imp 'EnumPageFilesA' EnumPageFilesA KernelBase 303 -imp 'EnumPageFiles' EnumPageFilesW KernelBase 304 -imp 'EnumProcessModules' EnumProcessModules KernelBase 305 -imp 'EnumProcessModulesEx' EnumProcessModulesEx KernelBase 306 -imp 'EnumProcesses' EnumProcesses KernelBase 307 imp 'EnumPropsA' EnumPropsA user32 1767 imp 'EnumPropsExA' EnumPropsExA user32 1768 imp 'EnumPropsEx' EnumPropsExW user32 1769 @@ -2074,10 +2052,6 @@ imp 'GetDefaultCommConfig' GetDefaultCommConfigW kernel32 554 imp 'GetDesktopID' GetDesktopID user32 1832 imp 'GetDesktopWindow' GetDesktopWindow user32 1833 0 imp 'GetDeviceCaps' GetDeviceCaps gdi32 1634 -imp 'GetDeviceDriverBaseNameA' GetDeviceDriverBaseNameA KernelBase 511 -imp 'GetDeviceDriverBaseName' GetDeviceDriverBaseNameW KernelBase 512 -imp 'GetDeviceDriverFileNameA' GetDeviceDriverFileNameA KernelBase 513 -imp 'GetDeviceDriverFileName' GetDeviceDriverFileNameW KernelBase 514 imp 'GetDeviceGammaRamp' GetDeviceGammaRamp gdi32 1635 imp 'GetDevicePowerState' GetDevicePowerState kernel32 555 imp 'GetDialogBaseUnits' GetDialogBaseUnits user32 1834 @@ -2279,8 +2253,6 @@ imp 'GetMailslotInfo' GetMailslotInfo kernel32 626 imp 'GetManagedApplicationCategories' GetManagedApplicationCategories advapi32 1336 imp 'GetManagedApplications' GetManagedApplications advapi32 1337 imp 'GetMapMode' GetMapMode gdi32 1671 -imp 'GetMappedFileNameA' GetMappedFileNameA KernelBase 594 -imp 'GetMappedFileName' GetMappedFileNameW KernelBase 595 imp 'GetMaximumProcessorCount' GetMaximumProcessorCount kernel32 627 1 # Windows 7+ imp 'GetMaximumProcessorGroupCount' GetMaximumProcessorGroupCount kernel32 628 imp 'GetMemoryErrorHandlingCapabilities' GetMemoryErrorHandlingCapabilities kernel32 0 # KernelBase @@ -2308,17 +2280,12 @@ imp 'GetMetaFileBitsEx' GetMetaFileBitsEx gdi32 1673 imp 'GetMetaFile' GetMetaFileW gdi32 1674 imp 'GetMetaRgn' GetMetaRgn gdi32 1675 imp 'GetMiterLimit' GetMiterLimit gdi32 1676 -imp 'GetModuleBaseNameA' GetModuleBaseNameA KernelBase 597 -imp 'GetModuleBaseName' GetModuleBaseNameW KernelBase 598 imp 'GetModuleFileName' GetModuleFileNameW kernel32 0 3 # KernelBase -imp 'GetModuleFileNameA' GetModuleFileNameA kernel32 0 3 # KernelBase -imp 'GetModuleFileNameExA' GetModuleFileNameExA KernelBase 600 -imp 'GetModuleFileNameEx' GetModuleFileNameExW KernelBase 601 imp 'GetModuleHandle' GetModuleHandleA kernel32 0 1 # KernelBase +imp 'GetModuleFileNameA' GetModuleFileNameA kernel32 0 3 # KernelBase imp 'GetModuleHandleW' GetModuleHandleW kernel32 0 1 # KernelBase imp 'GetModuleHandleExA' GetModuleHandleExA kernel32 0 3 # KernelBase imp 'GetModuleHandleEx' GetModuleHandleExW kernel32 0 3 # KernelBase -imp 'GetModuleInformation' GetModuleInformation KernelBase 607 imp 'GetMonitorInfoA' GetMonitorInfoA user32 1900 imp 'GetMonitorInfo' GetMonitorInfoW user32 1901 imp 'GetMouseMovePointsEx' GetMouseMovePointsEx user32 1902 @@ -2420,7 +2387,6 @@ imp 'GetPackagesByPackageFamily' GetPackagesByPackageFamily kernel32 0 # imp 'GetPaletteEntries' GetPaletteEntries gdi32 1687 imp 'GetParent' GetParent user32 1906 1 imp 'GetPath' GetPath gdi32 1688 -imp 'GetPerformanceInfo' GetPerformanceInfo KernelBase 659 imp 'GetPersistedFileLocation' GetPersistedFileLocationW KernelBase 660 imp 'GetPersistedRegistryLocation' GetPersistedRegistryLocationW KernelBase 661 imp 'GetPersistedRegistryValue' GetPersistedRegistryValueW KernelBase 662 @@ -2479,11 +2445,8 @@ imp 'GetProcessHeap' GetProcessHeap kernel32 0 0 # KernelBase imp 'GetProcessHeaps' GetProcessHeaps kernel32 0 2 # KernelBase imp 'GetProcessId' GetProcessId kernel32 0 1 # KernelBase imp 'GetProcessIdOfThread' GetProcessIdOfThread kernel32 0 1 # KernelBase -imp 'GetProcessImageFileNameA' GetProcessImageFileNameA kernel32 676 3 -imp 'GetProcessImageFileName' GetProcessImageFileNameW kernel32 677 3 imp 'GetProcessInformation' GetProcessInformation kernel32 0 4 # KernelBase imp 'GetProcessIoCounters' GetProcessIoCounters kernel32 701 2 -imp 'GetProcessMemoryInfo' GetProcessMemoryInfo KernelBase 679 imp 'GetProcessMitigationPolicy' GetProcessMitigationPolicy kernel32 0 # KernelBase imp 'GetProcessPreferredUILanguages' GetProcessPreferredUILanguages kernel32 0 # KernelBase imp 'GetProcessPriorityBoost' GetProcessPriorityBoost kernel32 0 2 # KernelBase @@ -2778,8 +2741,6 @@ imp 'GetWindowsDirectory' GetWindowsDirectoryW kernel32 0 2 # KernelBase imp 'GetWindowsDirectoryA' GetWindowsDirectoryA kernel32 0 2 # KernelBase imp 'GetWorldTransform' GetWorldTransform gdi32 1733 imp 'GetWriteWatch' GetWriteWatch kernel32 0 # KernelBase -imp 'GetWsChanges' GetWsChanges KernelBase 817 -imp 'GetWsChangesEx' GetWsChangesEx KernelBase 818 imp 'GetXStateFeaturesMask' GetXStateFeaturesMask kernel32 0 # KernelBase imp 'GhostWindowFromHungWindow' GhostWindowFromHungWindow user32 2011 imp 'GlobalAddAtomA' GlobalAddAtomA kernel32 815 @@ -2869,7 +2830,7 @@ imp 'ImpersonateAnonymousToken' ImpersonateAnonymousToken advapi32 0 # Ke imp 'ImpersonateDdeClientWindow' ImpersonateDdeClientWindow user32 2023 imp 'ImpersonateLoggedOnUser' ImpersonateLoggedOnUser advapi32 0 # KernelBase imp 'ImpersonateNamedPipeClient' ImpersonateNamedPipeClient advapi32 0 # KernelBase -imp 'ImpersonateSelf' ImpersonateSelf advapi32 0 # KernelBase +imp 'ImpersonateSelf' ImpersonateSelf advapi32 0 1 # KernelBase imp 'InSendMessage' InSendMessage user32 2024 imp 'InSendMessageEx' InSendMessageEx user32 2025 imp 'IncrementPackageStatusVersion' IncrementPackageStatusVersion KernelBase 847 @@ -2895,7 +2856,6 @@ imp 'InitializeLpkHooks' InitializeLpkHooks user32 2031 imp 'InitializePointerDeviceInjection' InitializePointerDeviceInjection user32 2032 imp 'InitializePointerDeviceInjectionEx' InitializePointerDeviceInjectionEx user32 2033 imp 'InitializeProcThreadAttributeList' InitializeProcThreadAttributeList kernel32 0 4 # KernelBase -imp 'InitializeProcessForWsWatch' InitializeProcessForWsWatch KernelBase 860 imp 'InitializeSecurityDescriptor' InitializeSecurityDescriptor advapi32 0 # KernelBase imp 'InitializeSid' InitializeSid advapi32 0 # KernelBase imp 'InitializeSynchronizationBarrier' InitializeSynchronizationBarrier kernel32 0 # KernelBase @@ -3062,13 +3022,10 @@ imp 'K32GetDeviceDriverFileNameA' K32GetDeviceDriverFileNameA kernel32 0 imp 'K32GetDeviceDriverFileName' K32GetDeviceDriverFileNameW kernel32 0 # KernelBase imp 'K32GetMappedFileNameA' K32GetMappedFileNameA kernel32 0 # KernelBase imp 'K32GetMappedFileName' K32GetMappedFileNameW kernel32 0 # KernelBase -imp 'K32GetModuleBaseNameA' K32GetModuleBaseNameA kernel32 0 # KernelBase imp 'K32GetModuleBaseName' K32GetModuleBaseNameW kernel32 0 # KernelBase -imp 'K32GetModuleFileNameExA' K32GetModuleFileNameExA kernel32 0 # KernelBase imp 'K32GetModuleFileNameEx' K32GetModuleFileNameExW kernel32 0 # KernelBase imp 'K32GetModuleInformation' K32GetModuleInformation kernel32 0 # KernelBase imp 'K32GetPerformanceInfo' K32GetPerformanceInfo kernel32 0 # KernelBase -imp 'K32GetProcessImageFileNameA' K32GetProcessImageFileNameA kernel32 0 # KernelBase imp 'K32GetProcessImageFileName' K32GetProcessImageFileNameW kernel32 0 # KernelBase imp 'K32GetProcessMemoryInfo' K32GetProcessMemoryInfo kernel32 0 # KernelBase imp 'K32GetWsChanges' K32GetWsChanges kernel32 0 # KernelBase @@ -4447,8 +4404,6 @@ imp 'QueryUserServiceName' QueryUserServiceName advapi32 1598 imp 'QueryUserServiceNameForContext' QueryUserServiceNameForContext advapi32 1599 imp 'QueryUsersOnEncryptedFile' QueryUsersOnEncryptedFile advapi32 1600 imp 'QueryVirtualMemoryInformation' QueryVirtualMemoryInformation KernelBase 1279 -imp 'QueryWorkingSet' QueryWorkingSet KernelBase 1280 -imp 'QueryWorkingSetEx' QueryWorkingSetEx KernelBase 1281 imp 'QueueUserAPC' QueueUserAPC kernel32 0 # KernelBase imp 'QueueUserWorkItem' QueueUserWorkItem kernel32 0 # KernelBase imp 'QuirkGetData' QuirkGetData KernelBase 1284 @@ -4759,7 +4714,7 @@ imp 'RestartDialogEx' RestartDialogEx shell32 730 imp 'RestoreDC' RestoreDC gdi32 1808 2 imp 'ResumeThread' ResumeThread kernel32 0 # KernelBase imp 'ReuseDDElParam' ReuseDDElParam user32 2290 -imp 'RevertToSelf' RevertToSelf advapi32 0 # KernelBase +imp 'RevertToSelf' RevertToSelf advapi32 0 0 # KernelBase imp 'RoundRect' RoundRect gdi32 1809 imp 'RsopLoggingEnabledInternal' RsopLoggingEnabledInternal KernelBase 1419 imp 'RtlAbortRXact' RtlAbortRXact ntdll 676 @@ -6360,7 +6315,6 @@ imp 'SetStateVersion' SetStateVersion KernelBase 1549 imp 'SetStdHandle' SetStdHandle kernel32 0 2 # KernelBase imp 'SetStdHandleEx' SetStdHandleEx KernelBase 1551 imp 'SetStretchBltMode' SetStretchBltMode gdi32 1908 -imp 'SetSuspendState' SetSuspendState PowerProf 0 3 imp 'SetSysColors' SetSysColors user32 2375 imp 'SetSysColorsTemp' SetSysColorsTemp user32 2376 imp 'SetSystemCursor' SetSystemCursor user32 2377 @@ -7890,3 +7844,110 @@ imp 'SetPerTcpConnectionEStats' SetPerTcpConnectionEStats iphlpapi 0 imp 'SetTcpEntry' SetTcpEntry iphlpapi 0 imp 'UnenableRouter' UnenableRouter iphlpapi 0 imp 'UnregisterInterfaceTimestampConfigChange' UnregisterInterfaceTimestampConfigChange iphlpapi 0 + +imp 'SetSuspendState' SetSuspendState PowerProf 0 3 + +imp 'CounterPathCallBack' CounterPathCallBack pdh 0 # Applications implement the CounterPathCallBack function to process the counter path strings returned by the Browse dialog box. +imp 'LoadPerfCounterTextStrings' LoadPerfCounterTextStringsW pdh 0 # Loads onto the computer the performance objects and counters defined in the specified initialization file. +imp 'PdhAddCounter' PdhAddCounterW pdh 0 # Adds the specified counter to the query. +imp 'PdhAddEnglishCounter' PdhAddEnglishCounterW pdh 0 4 # Adds the specified language-neutral counter to the query. +imp 'PdhBindInputDataSource' PdhBindInputDataSourceW pdh 0 # Binds one or more binary log files together for reading log data. +imp 'PdhBrowseCounters' PdhBrowseCountersW pdh 0 # Displays a Browse Counters dialog box that the user can use to select one or more counters that they want to add to the query. To use handles to data sources, use the PdhBrowseCountersH function. +imp 'PdhBrowseCountersH' PdhBrowseCountersHW pdh 0 # Displays a Browse Counters dialog box that the user can use to select one or more counters that they want to add to the query. This function is identical to the PdhBrowseCounters function, except that it supports the use of handles to data sources. +imp 'PdhCalculateCounterFromRawValue' PdhCalculateCounterFromRawValue pdh 0 # Calculates the displayable value of two raw counter values. +imp 'PdhCloseLog' PdhCloseLog pdh 0 # Closes the specified log file. +imp 'PdhCloseQuery' PdhCloseQuery pdh 0 # Closes all counters contained in the specified query, closes all handles related to the query, and frees all memory associated with the query. +imp 'PdhCollectQueryData' PdhCollectQueryData pdh 0 # Collects the current raw data value for all counters in the specified query and updates the status code of each counter. +imp 'PdhCollectQueryDataEx' PdhCollectQueryDataEx pdh 0 3 # Uses a separate thread to collect the current raw data value for all counters in the specified query. The function then signals the application-defined event and waits the specified time interval before returning. +imp 'PdhCollectQueryDataWithTime' PdhCollectQueryDataWithTime pdh 0 # Collects the current raw data value for all counters in the specified query and updates the status code of each counter. +imp 'PdhComputeCounterStatistics' PdhComputeCounterStatistics pdh 0 # Computes statistics for a counter from an array of raw values. +imp 'PdhConnectMachine' PdhConnectMachineW pdh 0 # Connects to the specified computer. +imp 'PdhEnumLogSetNames' PdhEnumLogSetNamesW pdh 0 # Enumerates the names of the log sets within the DSN. +imp 'PdhEnumMachines' PdhEnumMachinesW pdh 0 # Returns a list of the computer names associated with counters in a log file. +imp 'PdhEnumMachinesH' PdhEnumMachinesHW pdh 0 # Returns a list of the computer names associated with counters in a log file. +imp 'PdhEnumObjectItems' PdhEnumObjectItemsW pdh 0 # Returns the specified object's counter and instance names that exist on the specified computer or in the specified log file. To use handles to data sources, use the PdhEnumObjectItemsH function. +imp 'PdhEnumObjectItemsH' PdhEnumObjectItemsHW pdh 0 # Returns the specified object's counter and instance names that exist on the specified computer or in the specified log file. This function is identical to the PdhEnumObjectItems function, except that it supports the use of handles to data sources. +imp 'PdhEnumObjects' PdhEnumObjectsW pdh 0 # Returns a list of objects available on the specified computer or in the specified log file. To use handles to data sources, use the PdhEnumObjectsH function. +imp 'PdhEnumObjectsH' PdhEnumObjectsHW pdh 0 # Returns a list of objects available on the specified computer or in the specified log file.This function is identical to PdhEnumObjects, except that it supports the use of handles to data sources. +imp 'PdhExpandCounterPath' PdhExpandCounterPathW pdh 0 # Examines the specified computer (or local computer if none is specified) for counters and instances of counters that match the wildcard strings in the counter path. +imp 'PdhExpandWildCardPath' PdhExpandWildCardPathW pdh 0 # Examines the specified computer or log file and returns those counter paths that match the given counter path which contains wildcard characters. To use handles to data sources, use the PdhExpandWildCardPathH function. +imp 'PdhExpandWildCardPathH' PdhExpandWildCardPathHW pdh 0 # Examines the specified computer or log file and returns those counter paths that match the given counter path which contains wildcard characters.This function is identical to the PdhExpandWildCardPath function, except that it supports the use of handles to data sources. +imp 'PdhFormatFromRawValue' PdhFormatFromRawValue pdh 0 # Computes a displayable value for the given raw counter values. +imp 'PdhGetCounterInfo' PdhGetCounterInfoW pdh 0 # Retrieves information about a counter, such as data size, counter type, path, and user-supplied data values. +imp 'PdhGetCounterTimeBase' PdhGetCounterTimeBase pdh 0 # Returns the time base of the specified counter. +imp 'PdhGetDataSourceTimeRange' PdhGetDataSourceTimeRangeW pdh 0 # Determines the time range, number of entries and, if applicable, the size of the buffer containing the performance data from the specified input source. To use handles to data sources, use the PdhGetDataSourceTimeRangeH function. +imp 'PdhGetDataSourceTimeRangeH' PdhGetDataSourceTimeRangeH pdh 0 # Determines the time range, number of entries and, if applicable, the size of the buffer containing the performance data from the specified input source.This function is identical to the PdhGetDataSourceTimeRange function, except that it supports the use of handles to data sources. +imp 'PdhGetDefaultPerfCounter' PdhGetDefaultPerfCounterW pdh 0 # Retrieves the name of the default counter for the specified object. This name can be used to set the initial counter selection in the Browse Counter dialog box. To use handles to data sources, use the PdhGetDefaultPerfCounterH function. +imp 'PdhGetDefaultPerfCounterH' PdhGetDefaultPerfCounterHW pdh 0 # Retrieves the name of the default counter for the specified object. +imp 'PdhGetDefaultPerfObject' PdhGetDefaultPerfObjectW pdh 0 # Retrieves the name of the default object. This name can be used to set the initial object selection in the Browse Counter dialog box. To use handles to data sources, use the PdhGetDefaultPerfObjectH function. +imp 'PdhGetDefaultPerfObjectH' PdhGetDefaultPerfObjectHW pdh 0 # Retrieves the name of the default object. +imp 'PdhGetDllVersion' PdhGetDllVersion pdh 0 # Returns the version of the currently installed Pdh.dll file. +imp 'PdhGetFormattedCounterArray' PdhGetFormattedCounterArrayW pdh 0 # Returns an array of formatted counter values. Use this function when you want to format the counter values of a counter that contains a wildcard character for the instance name. +imp 'PdhGetFormattedCounterValue' PdhGetFormattedCounterValue pdh 0 4 # Computes a displayable value for the specified counter. +imp 'PdhGetLogFileSize' PdhGetLogFileSize pdh 0 # Returns the size of the specified log file. +imp 'PdhGetRawCounterArray' PdhGetRawCounterArrayW pdh 0 # Returns an array of raw values from the specified counter. Use this function when you want to retrieve the raw counter values of a counter that contains a wildcard character for the instance name. +imp 'PdhGetRawCounterValue' PdhGetRawCounterValue pdh 0 # Returns the current raw value of the counter. +imp 'PdhIsRealTimeQuery' PdhIsRealTimeQuery pdh 0 # Determines if the specified query is a real-time query. +imp 'PdhLookupPerfIndexByName' PdhLookupPerfIndexByNameW pdh 0 # Returns the counter index corresponding to the specified counter name. +imp 'PdhLookupPerfNameByIndex' PdhLookupPerfNameByIndexW pdh 0 # Returns the performance object name or counter name corresponding to the specified index. +imp 'PdhMakeCounterPath' PdhMakeCounterPathW pdh 0 # Creates a full counter path using the members specified in the PDH_COUNTER_PATH_ELEMENTS structure. +imp 'PdhOpenLog' PdhOpenLogW pdh 0 # Opens the specified log file for reading or writing. +imp 'PdhOpenQuery' PdhOpenQueryW pdh 0 3 # Creates a new query that is used to manage the collection of performance data. To use handles to data sources, use the PdhOpenQueryH function. +imp 'PdhOpenQueryH' PdhOpenQueryH pdh 0 # Creates a new query that is used to manage the collection of performance data. This function is identical to the PdhOpenQuery function, except that it supports the use of handles to data sources. +imp 'PdhParseCounterPath' PdhParseCounterPathW pdh 0 # Parses the elements of the counter path and stores the results in the PDH_COUNTER_PATH_ELEMENTS structure. +imp 'PdhParseInstanceName' PdhParseInstanceNameW pdh 0 # Parses the elements of an instance string. +imp 'PdhReadRawLogRecord' PdhReadRawLogRecord pdh 0 # Reads the information in the specified binary trace log file. +imp 'PdhRemoveCounter' PdhRemoveCounter pdh 0 # Removes a counter from a query. +imp 'PdhSelectDataSource' PdhSelectDataSourceW pdh 0 # Displays a dialog window that prompts the user to specify the source of the performance data. +imp 'PdhSetCounterScaleFactor' PdhSetCounterScaleFactor pdh 0 # Sets the scale factor that is applied to the calculated value of the specified counter when you request the formatted counter value. If the PDH_FMT_NOSCALE flag is set, then this scale factor is ignored. +imp 'PdhSetDefaultRealTimeDataSource' PdhSetDefaultRealTimeDataSource pdh 0 # Specifies the source of the real-time data. +imp 'PdhSetQueryTimeRange' PdhSetQueryTimeRange pdh 0 # Limits the samples that you can read from a log file to those within the specified time range, inclusively. +imp 'PdhUpdateLog' PdhUpdateLogW pdh 0 # Collects counter data for the current query and writes the data to the log file. +imp 'PdhUpdateLogFileCatalog' PdhUpdateLogFileCatalog pdh 0 # Synchronizes the information in the log file catalog with the performance data in the log file. +imp 'PdhValidatePath' PdhValidatePathW pdh 0 # Validates that the counter is present on the computer specified in the counter path. +imp 'PdhValidatePathEx' PdhValidatePathExW pdh 0 # Validates that the specified counter is present on the computer or in the log file. +imp 'PerfAddCounters' PerfAddCounters pdh 0 # Adds performance counter specifications to the specified query. +imp 'PerfCloseQueryHandle' PerfCloseQueryHandle pdh 0 # Closes a query handle that you opened by calling PerfOpenQueryHandle. +imp 'PerfCreateInstance' PerfCreateInstance pdh 0 # Creates an instance of the specified counter set. +imp 'PerfDecrementULongCounterValue' PerfDecrementULongCounterValue pdh 0 # Decrements the value of a counter whose value is a 4-byte unsigned integer. Providers use this function. +imp 'PerfDecrementULongLongCounterValue' PerfDecrementULongLongCounterValue pdh 0 # Decrements the value of a counter whose value is an 8-byte unsigned integer. Providers use this function. +imp 'PerfDeleteCounters' PerfDeleteCounters pdh 0 # Removes the specified performance counter specifications from the specified query. +imp 'PerfDeleteInstance' PerfDeleteInstance pdh 0 # Deletes an instance of the counter set created by the PerfCreateInstance function. +imp 'PerfEnumerateCounterSet' PerfEnumerateCounterSet pdh 0 # Gets the counter set identifiers of the counter sets that are registered on the specified system. Counter set identifiers are globally unique identifiers (GUIDs). +imp 'PerfEnumerateCounterSetInstances' PerfEnumerateCounterSetInstances pdh 0 # Gets the names and identifiers of the active instances of a counter set on the specified system. +imp 'PerfIncrementULongCounterValue' PerfIncrementULongCounterValue pdh 0 # Increments the value of a counter whose value is a 4-byte unsigned integer. Providers use this function. +imp 'PerfIncrementULongLongCounterValue' PerfIncrementULongLongCounterValue pdh 0 # Increments the value of a counter whose value is an 8-byte unsigned integer. Providers use this function. +imp 'PerfOpenQueryHandle' PerfOpenQueryHandle pdh 0 # Creates a handle that references a query on the specified system. A query is a list of counter specifications. +imp 'PerfQueryCounterData' PerfQueryCounterData pdh 0 # Gets the values of the performance counters that match the counter specifications in the specified query. +imp 'PerfQueryCounterInfo' PerfQueryCounterInfo pdh 0 # Gets the counter specifications in the specified query. +imp 'PerfQueryCounterSetRegistrationInfo' PerfQueryCounterSetRegistrationInfo pdh 0 # Gets information about a counter set on the specified system. +imp 'PerfQueryInstance' PerfQueryInstance pdh 0 # Retrieves a pointer to the specified counter set instance. Providers use this function. +imp 'PerfSetCounterRefValue' PerfSetCounterRefValue pdh 0 # Updates the value of a counter whose value is a pointer to the actual data. Providers use this function. +imp 'PerfSetCounterSetInfo' PerfSetCounterSetInfo pdh 0 # Specifies the layout of a particular counter set. +imp 'PerfSetULongCounterValue' PerfSetULongCounterValue pdh 0 # Updates the value of a counter whose value is a 4-byte unsigned integer. Providers use this function. +imp 'PerfSetULongLongCounterValue' PerfSetULongLongCounterValue pdh 0 # Updates the value of a counter whose value is an 8-byte unsigned integer. Providers use this function. +imp 'PerfStartProvider' PerfStartProvider pdh 0 # Registers the provider. +imp 'PerfStartProviderEx' PerfStartProviderEx pdh 0 # Registers the provider. +imp 'PerfStopProvider' PerfStopProvider pdh 0 # Removes the provider's registration from the list of registered providers and frees all resources associated with the provider. +imp 'UnloadPerfCounterTextStrings' UnloadPerfCounterTextStringsW pdh 0 # Unloads performance objects and counters from the computer for the specified application. + +imp 'EmptyWorkingSet' EmptyWorkingSet psapi 0 +imp 'EnumDeviceDrivers' EnumDeviceDrivers psapi 0 +imp 'EnumPageFiles' EnumPageFilesW psapi 0 +imp 'EnumProcessModules' EnumProcessModules psapi 0 +imp 'EnumProcessModulesEx' EnumProcessModulesEx psapi 0 +imp 'EnumProcesses' EnumProcesses psapi 0 +imp 'GetDeviceDriverBaseName' GetDeviceDriverBaseNameW psapi 0 +imp 'GetDeviceDriverFileName' GetDeviceDriverFileNameW psapi 0 +imp 'GetMappedFileName' GetMappedFileNameW psapi 0 +imp 'GetModuleBaseName' GetModuleBaseNameW psapi 0 +imp 'GetModuleFileNameEx' GetModuleFileNameExW psapi 0 +imp 'GetModuleInformation' GetModuleInformation psapi 0 +imp 'GetPerformanceInfo' GetPerformanceInfo psapi 0 +imp 'GetProcessImageFileName' GetProcessImageFileNameW psapi 0 3 +imp 'GetProcessMemoryInfo' GetProcessMemoryInfo psapi 0 3 +imp 'GetWsChanges' GetWsChanges psapi 0 +imp 'GetWsChangesEx' GetWsChangesEx psapi 0 +imp 'InitializeProcessForWsWatch' InitializeProcessForWsWatch psapi 0 +imp 'QueryWorkingSet' QueryWorkingSet psapi 0 +imp 'QueryWorkingSetEx' QueryWorkingSetEx psapi 0 diff --git a/libc/nt/nt.mk b/libc/nt/nt.mk index 767e793db..dd0a04d28 100644 --- a/libc/nt/nt.mk +++ b/libc/nt/nt.mk @@ -351,6 +351,44 @@ $(LIBC_NT_POWERPROF_A).pkg: \ #─────────────────────────────────────────────────────────────────────────────── +LIBC_NT_ARTIFACTS += LIBC_NT_PDH_A +LIBC_NT_PDH = $(LIBC_NT_PDH_A_DEPS) $(LIBC_NT_PDH_A) +LIBC_NT_PDH_A = o/$(MODE)/libc/nt/pdh.a +LIBC_NT_PDH_A_SRCS := $(wildcard libc/nt/pdh/*.s) +LIBC_NT_PDH_A_OBJS = $(LIBC_NT_PDH_A_SRCS:%.s=o/$(MODE)/%.o) +LIBC_NT_PDH_A_CHECKS = $(LIBC_NT_PDH_A).pkg +LIBC_NT_PDH_A_DIRECTDEPS = LIBC_NT_KERNEL32 +LIBC_NT_PDH_A_DEPS := \ + $(call uniq,$(foreach x,$(LIBC_NT_PDH_A_DIRECTDEPS),$($(x)))) +$(LIBC_NT_PDH_A): \ + libc/nt/pdh/ \ + $(LIBC_NT_PDH_A).pkg \ + $(LIBC_NT_PDH_A_OBJS) +$(LIBC_NT_PDH_A).pkg: \ + $(LIBC_NT_PDH_A_OBJS) \ + $(foreach x,$(LIBC_NT_PDH_A_DIRECTDEPS),$($(x)_A).pkg) + +#─────────────────────────────────────────────────────────────────────────────── + +LIBC_NT_ARTIFACTS += LIBC_NT_PSAPI_A +LIBC_NT_PSAPI = $(LIBC_NT_PSAPI_A_DEPS) $(LIBC_NT_PSAPI_A) +LIBC_NT_PSAPI_A = o/$(MODE)/libc/nt/psapi.a +LIBC_NT_PSAPI_A_SRCS := $(wildcard libc/nt/psapi/*.s) +LIBC_NT_PSAPI_A_OBJS = $(LIBC_NT_PSAPI_A_SRCS:%.s=o/$(MODE)/%.o) +LIBC_NT_PSAPI_A_CHECKS = $(LIBC_NT_PSAPI_A).pkg +LIBC_NT_PSAPI_A_DIRECTDEPS = LIBC_NT_KERNEL32 +LIBC_NT_PSAPI_A_DEPS := \ + $(call uniq,$(foreach x,$(LIBC_NT_PSAPI_A_DIRECTDEPS),$($(x)))) +$(LIBC_NT_PSAPI_A): \ + libc/nt/psapi/ \ + $(LIBC_NT_PSAPI_A).pkg \ + $(LIBC_NT_PSAPI_A_OBJS) +$(LIBC_NT_PSAPI_A).pkg: \ + $(LIBC_NT_PSAPI_A_OBJS) \ + $(foreach x,$(LIBC_NT_PSAPI_A_DIRECTDEPS),$($(x)_A).pkg) + +#─────────────────────────────────────────────────────────────────────────────── + $(LIBC_NT_OBJS): o/libc/nt/codegen.inc o/libc/nt/codegen.inc: \ diff --git a/libc/nt/pdh.h b/libc/nt/pdh.h new file mode 100644 index 000000000..c3e0b09c5 --- /dev/null +++ b/libc/nt/pdh.h @@ -0,0 +1,48 @@ +#ifndef COSMOPOLITAN_LIBC_NT_PDH_H_ +#define COSMOPOLITAN_LIBC_NT_PDH_H_ +#include "libc/nt/struct/pdhfmtcountervalue.h" + +/* ░░░░ + ▒▒▒░░░▒▒▒▒▒▒▒▓▓▓░ + ▒▒▒▒░░░▒▒▒▒▒▒▓▓▓▓▓▓░ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓░ + ▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▒ ▒▒▒▓▓█ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ░▒▒▒░░░░▒▒▒▒▒▒▓▓▓▓▓▓ █▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓░ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ▒▒▒▒░░░▒▒▒▒▒▒▒▓▓▓▓▓▓ ▒▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▒ + ▒▒▒▒▓▓ ▓▒▒▓▓▓▓ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▓ ▓▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓ + ░░░░░░░░░░░▒▒▒▒ ▓▓▓▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓█ + ▒▒░░░░░░░░░░▒▒▒▒▒▓▓▓ ▓▓▓▓▓▒▒▒▒▒▒▒▒▒▒▓▓▓ + ░▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓░ ░▓███▓ + ▒▒░░░░░░░░░░▒▒▒▒▒▓▓░ ▒▓▓▓▒▒▒ ░▒▒▒▓ ████████████ + ▒▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▒▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒░ ░███ + ▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ███ + ▒▒░░░░░░░░░░▒▒▒▒▒▒▓▓ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ▓██ + ▒░░░░░░░░░░░▒▒▒▒▒▓▓ ▓▓▓▓▒▒▒▒▒▒▒▒░░░▒▒▒▒▒▓ ▓██ + ▒▒░░░▒▒▒░░░▒▒░▒▒▒▓▓▒ ▒▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▒ ███ + ░▒▓ ░▓▓▓▓▒▒▒▒▒▒▒▒░░░░▒▒▒▒▓ ▓██ +╔────────────────────────────────────────────────────────────────▀▀▀─────────│─╗ +│ cosmopolitan § new technology » performance counters ─╬─│┼ +╚────────────────────────────────────────────────────────────────────────────│*/ + +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +int PdhOpenQuery(const char16_t *opt_szDataSource, uint32_t *dwUserData, + int64_t *out_phQuery); + +int PdhAddEnglishCounter(int64_t hQuery, const char16_t *szFullCounterPath, + uint32_t *dwUserData, int64_t *out_phCounter); + +int PdhCollectQueryDataEx(int64_t hQuery, uint32_t dwIntervalTime, + int64_t hNewDataEvent); + +int PdhGetFormattedCounterValue(int64_t hCounter, uint32_t dwFormat, + uint32_t *out_opt_lpdwType, + struct NtPdhFmtCountervalue *out_pValue); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_PDH_H_ */ diff --git a/libc/nt/pdh/CounterPathCallBack.s b/libc/nt/pdh/CounterPathCallBack.s new file mode 100644 index 000000000..25dd6bb6e --- /dev/null +++ b/libc/nt/pdh/CounterPathCallBack.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_CounterPathCallBack,CounterPathCallBack,0 diff --git a/libc/nt/pdh/LoadPerfCounterTextStringsW.s b/libc/nt/pdh/LoadPerfCounterTextStringsW.s new file mode 100644 index 000000000..ac8c7dafa --- /dev/null +++ b/libc/nt/pdh/LoadPerfCounterTextStringsW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_LoadPerfCounterTextStringsW,LoadPerfCounterTextStringsW,0 diff --git a/libc/nt/pdh/PdhAddCounterW.s b/libc/nt/pdh/PdhAddCounterW.s new file mode 100644 index 000000000..62bbe29f5 --- /dev/null +++ b/libc/nt/pdh/PdhAddCounterW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhAddCounterW,PdhAddCounterW,0 diff --git a/libc/nt/pdh/PdhAddEnglishCounterW.s b/libc/nt/pdh/PdhAddEnglishCounterW.s new file mode 100644 index 000000000..5910c3932 --- /dev/null +++ b/libc/nt/pdh/PdhAddEnglishCounterW.s @@ -0,0 +1,12 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhAddEnglishCounterW,PdhAddEnglishCounterW,0 + + .text.windows +PdhAddEnglishCounter: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_PdhAddEnglishCounterW(%rip),%rax + jmp __sysv2nt + .endfn PdhAddEnglishCounter,globl + .previous diff --git a/libc/nt/pdh/PdhBindInputDataSourceW.s b/libc/nt/pdh/PdhBindInputDataSourceW.s new file mode 100644 index 000000000..3743d1f40 --- /dev/null +++ b/libc/nt/pdh/PdhBindInputDataSourceW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhBindInputDataSourceW,PdhBindInputDataSourceW,0 diff --git a/libc/nt/pdh/PdhBrowseCountersHW.s b/libc/nt/pdh/PdhBrowseCountersHW.s new file mode 100644 index 000000000..c3028ea22 --- /dev/null +++ b/libc/nt/pdh/PdhBrowseCountersHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhBrowseCountersHW,PdhBrowseCountersHW,0 diff --git a/libc/nt/pdh/PdhBrowseCountersW.s b/libc/nt/pdh/PdhBrowseCountersW.s new file mode 100644 index 000000000..69eeb1d70 --- /dev/null +++ b/libc/nt/pdh/PdhBrowseCountersW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhBrowseCountersW,PdhBrowseCountersW,0 diff --git a/libc/nt/pdh/PdhCalculateCounterFromRawValue.s b/libc/nt/pdh/PdhCalculateCounterFromRawValue.s new file mode 100644 index 000000000..22e414390 --- /dev/null +++ b/libc/nt/pdh/PdhCalculateCounterFromRawValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCalculateCounterFromRawValue,PdhCalculateCounterFromRawValue,0 diff --git a/libc/nt/pdh/PdhCloseLog.s b/libc/nt/pdh/PdhCloseLog.s new file mode 100644 index 000000000..b71f8cbe6 --- /dev/null +++ b/libc/nt/pdh/PdhCloseLog.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCloseLog,PdhCloseLog,0 diff --git a/libc/nt/pdh/PdhCloseQuery.s b/libc/nt/pdh/PdhCloseQuery.s new file mode 100644 index 000000000..e79564a4b --- /dev/null +++ b/libc/nt/pdh/PdhCloseQuery.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCloseQuery,PdhCloseQuery,0 diff --git a/libc/nt/pdh/PdhCollectQueryData.s b/libc/nt/pdh/PdhCollectQueryData.s new file mode 100644 index 000000000..8ea943130 --- /dev/null +++ b/libc/nt/pdh/PdhCollectQueryData.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCollectQueryData,PdhCollectQueryData,0 diff --git a/libc/nt/pdh/PdhCollectQueryDataEx.s b/libc/nt/pdh/PdhCollectQueryDataEx.s new file mode 100644 index 000000000..94b3acb38 --- /dev/null +++ b/libc/nt/pdh/PdhCollectQueryDataEx.s @@ -0,0 +1,12 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCollectQueryDataEx,PdhCollectQueryDataEx,0 + + .text.windows +PdhCollectQueryDataEx: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_PdhCollectQueryDataEx(%rip),%rax + jmp __sysv2nt + .endfn PdhCollectQueryDataEx,globl + .previous diff --git a/libc/nt/pdh/PdhCollectQueryDataWithTime.s b/libc/nt/pdh/PdhCollectQueryDataWithTime.s new file mode 100644 index 000000000..e79b7812a --- /dev/null +++ b/libc/nt/pdh/PdhCollectQueryDataWithTime.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhCollectQueryDataWithTime,PdhCollectQueryDataWithTime,0 diff --git a/libc/nt/pdh/PdhComputeCounterStatistics.s b/libc/nt/pdh/PdhComputeCounterStatistics.s new file mode 100644 index 000000000..3ec3bfb56 --- /dev/null +++ b/libc/nt/pdh/PdhComputeCounterStatistics.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhComputeCounterStatistics,PdhComputeCounterStatistics,0 diff --git a/libc/nt/pdh/PdhConnectMachineW.s b/libc/nt/pdh/PdhConnectMachineW.s new file mode 100644 index 000000000..24a27a93f --- /dev/null +++ b/libc/nt/pdh/PdhConnectMachineW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhConnectMachineW,PdhConnectMachineW,0 diff --git a/libc/nt/pdh/PdhEnumLogSetNamesW.s b/libc/nt/pdh/PdhEnumLogSetNamesW.s new file mode 100644 index 000000000..cc7009ba3 --- /dev/null +++ b/libc/nt/pdh/PdhEnumLogSetNamesW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumLogSetNamesW,PdhEnumLogSetNamesW,0 diff --git a/libc/nt/pdh/PdhEnumMachinesHW.s b/libc/nt/pdh/PdhEnumMachinesHW.s new file mode 100644 index 000000000..c7edcbbf2 --- /dev/null +++ b/libc/nt/pdh/PdhEnumMachinesHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumMachinesHW,PdhEnumMachinesHW,0 diff --git a/libc/nt/pdh/PdhEnumMachinesW.s b/libc/nt/pdh/PdhEnumMachinesW.s new file mode 100644 index 000000000..5b9dd0c9e --- /dev/null +++ b/libc/nt/pdh/PdhEnumMachinesW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumMachinesW,PdhEnumMachinesW,0 diff --git a/libc/nt/pdh/PdhEnumObjectItemsHW.s b/libc/nt/pdh/PdhEnumObjectItemsHW.s new file mode 100644 index 000000000..ade6c4950 --- /dev/null +++ b/libc/nt/pdh/PdhEnumObjectItemsHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumObjectItemsHW,PdhEnumObjectItemsHW,0 diff --git a/libc/nt/pdh/PdhEnumObjectItemsW.s b/libc/nt/pdh/PdhEnumObjectItemsW.s new file mode 100644 index 000000000..f0a7fffef --- /dev/null +++ b/libc/nt/pdh/PdhEnumObjectItemsW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumObjectItemsW,PdhEnumObjectItemsW,0 diff --git a/libc/nt/pdh/PdhEnumObjectsHW.s b/libc/nt/pdh/PdhEnumObjectsHW.s new file mode 100644 index 000000000..15469b45b --- /dev/null +++ b/libc/nt/pdh/PdhEnumObjectsHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumObjectsHW,PdhEnumObjectsHW,0 diff --git a/libc/nt/pdh/PdhEnumObjectsW.s b/libc/nt/pdh/PdhEnumObjectsW.s new file mode 100644 index 000000000..9992fd00c --- /dev/null +++ b/libc/nt/pdh/PdhEnumObjectsW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhEnumObjectsW,PdhEnumObjectsW,0 diff --git a/libc/nt/pdh/PdhExpandCounterPathW.s b/libc/nt/pdh/PdhExpandCounterPathW.s new file mode 100644 index 000000000..aee0c7aff --- /dev/null +++ b/libc/nt/pdh/PdhExpandCounterPathW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhExpandCounterPathW,PdhExpandCounterPathW,0 diff --git a/libc/nt/pdh/PdhExpandWildCardPathHW.s b/libc/nt/pdh/PdhExpandWildCardPathHW.s new file mode 100644 index 000000000..607e9d590 --- /dev/null +++ b/libc/nt/pdh/PdhExpandWildCardPathHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhExpandWildCardPathHW,PdhExpandWildCardPathHW,0 diff --git a/libc/nt/pdh/PdhExpandWildCardPathW.s b/libc/nt/pdh/PdhExpandWildCardPathW.s new file mode 100644 index 000000000..2378bba8f --- /dev/null +++ b/libc/nt/pdh/PdhExpandWildCardPathW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhExpandWildCardPathW,PdhExpandWildCardPathW,0 diff --git a/libc/nt/pdh/PdhFormatFromRawValue.s b/libc/nt/pdh/PdhFormatFromRawValue.s new file mode 100644 index 000000000..2eaa0158f --- /dev/null +++ b/libc/nt/pdh/PdhFormatFromRawValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhFormatFromRawValue,PdhFormatFromRawValue,0 diff --git a/libc/nt/pdh/PdhGetCounterInfoW.s b/libc/nt/pdh/PdhGetCounterInfoW.s new file mode 100644 index 000000000..9903cd1db --- /dev/null +++ b/libc/nt/pdh/PdhGetCounterInfoW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetCounterInfoW,PdhGetCounterInfoW,0 diff --git a/libc/nt/pdh/PdhGetCounterTimeBase.s b/libc/nt/pdh/PdhGetCounterTimeBase.s new file mode 100644 index 000000000..ce6db166e --- /dev/null +++ b/libc/nt/pdh/PdhGetCounterTimeBase.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetCounterTimeBase,PdhGetCounterTimeBase,0 diff --git a/libc/nt/pdh/PdhGetDataSourceTimeRangeH.s b/libc/nt/pdh/PdhGetDataSourceTimeRangeH.s new file mode 100644 index 000000000..1d646f5af --- /dev/null +++ b/libc/nt/pdh/PdhGetDataSourceTimeRangeH.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDataSourceTimeRangeH,PdhGetDataSourceTimeRangeH,0 diff --git a/libc/nt/pdh/PdhGetDataSourceTimeRangeW.s b/libc/nt/pdh/PdhGetDataSourceTimeRangeW.s new file mode 100644 index 000000000..1c8e2d844 --- /dev/null +++ b/libc/nt/pdh/PdhGetDataSourceTimeRangeW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDataSourceTimeRangeW,PdhGetDataSourceTimeRangeW,0 diff --git a/libc/nt/pdh/PdhGetDefaultPerfCounterHW.s b/libc/nt/pdh/PdhGetDefaultPerfCounterHW.s new file mode 100644 index 000000000..f02c0a014 --- /dev/null +++ b/libc/nt/pdh/PdhGetDefaultPerfCounterHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDefaultPerfCounterHW,PdhGetDefaultPerfCounterHW,0 diff --git a/libc/nt/pdh/PdhGetDefaultPerfCounterW.s b/libc/nt/pdh/PdhGetDefaultPerfCounterW.s new file mode 100644 index 000000000..31d98dd06 --- /dev/null +++ b/libc/nt/pdh/PdhGetDefaultPerfCounterW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDefaultPerfCounterW,PdhGetDefaultPerfCounterW,0 diff --git a/libc/nt/pdh/PdhGetDefaultPerfObjectHW.s b/libc/nt/pdh/PdhGetDefaultPerfObjectHW.s new file mode 100644 index 000000000..7fd0c35a9 --- /dev/null +++ b/libc/nt/pdh/PdhGetDefaultPerfObjectHW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDefaultPerfObjectHW,PdhGetDefaultPerfObjectHW,0 diff --git a/libc/nt/pdh/PdhGetDefaultPerfObjectW.s b/libc/nt/pdh/PdhGetDefaultPerfObjectW.s new file mode 100644 index 000000000..8fa5c376c --- /dev/null +++ b/libc/nt/pdh/PdhGetDefaultPerfObjectW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDefaultPerfObjectW,PdhGetDefaultPerfObjectW,0 diff --git a/libc/nt/pdh/PdhGetDllVersion.s b/libc/nt/pdh/PdhGetDllVersion.s new file mode 100644 index 000000000..03de14368 --- /dev/null +++ b/libc/nt/pdh/PdhGetDllVersion.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetDllVersion,PdhGetDllVersion,0 diff --git a/libc/nt/pdh/PdhGetFormattedCounterArrayW.s b/libc/nt/pdh/PdhGetFormattedCounterArrayW.s new file mode 100644 index 000000000..cda96c436 --- /dev/null +++ b/libc/nt/pdh/PdhGetFormattedCounterArrayW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetFormattedCounterArrayW,PdhGetFormattedCounterArrayW,0 diff --git a/libc/nt/pdh/PdhGetFormattedCounterValue.s b/libc/nt/pdh/PdhGetFormattedCounterValue.s new file mode 100644 index 000000000..0c2a6c48b --- /dev/null +++ b/libc/nt/pdh/PdhGetFormattedCounterValue.s @@ -0,0 +1,12 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetFormattedCounterValue,PdhGetFormattedCounterValue,0 + + .text.windows +PdhGetFormattedCounterValue: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_PdhGetFormattedCounterValue(%rip),%rax + jmp __sysv2nt + .endfn PdhGetFormattedCounterValue,globl + .previous diff --git a/libc/nt/pdh/PdhGetLogFileSize.s b/libc/nt/pdh/PdhGetLogFileSize.s new file mode 100644 index 000000000..71794e7cd --- /dev/null +++ b/libc/nt/pdh/PdhGetLogFileSize.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetLogFileSize,PdhGetLogFileSize,0 diff --git a/libc/nt/pdh/PdhGetRawCounterArrayW.s b/libc/nt/pdh/PdhGetRawCounterArrayW.s new file mode 100644 index 000000000..f52d908ce --- /dev/null +++ b/libc/nt/pdh/PdhGetRawCounterArrayW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetRawCounterArrayW,PdhGetRawCounterArrayW,0 diff --git a/libc/nt/pdh/PdhGetRawCounterValue.s b/libc/nt/pdh/PdhGetRawCounterValue.s new file mode 100644 index 000000000..b9e7839ca --- /dev/null +++ b/libc/nt/pdh/PdhGetRawCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhGetRawCounterValue,PdhGetRawCounterValue,0 diff --git a/libc/nt/pdh/PdhIsRealTimeQuery.s b/libc/nt/pdh/PdhIsRealTimeQuery.s new file mode 100644 index 000000000..880402dd6 --- /dev/null +++ b/libc/nt/pdh/PdhIsRealTimeQuery.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhIsRealTimeQuery,PdhIsRealTimeQuery,0 diff --git a/libc/nt/pdh/PdhLookupPerfIndexByNameW.s b/libc/nt/pdh/PdhLookupPerfIndexByNameW.s new file mode 100644 index 000000000..35def11bb --- /dev/null +++ b/libc/nt/pdh/PdhLookupPerfIndexByNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhLookupPerfIndexByNameW,PdhLookupPerfIndexByNameW,0 diff --git a/libc/nt/pdh/PdhLookupPerfNameByIndexW.s b/libc/nt/pdh/PdhLookupPerfNameByIndexW.s new file mode 100644 index 000000000..f58bb7fcf --- /dev/null +++ b/libc/nt/pdh/PdhLookupPerfNameByIndexW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhLookupPerfNameByIndexW,PdhLookupPerfNameByIndexW,0 diff --git a/libc/nt/pdh/PdhMakeCounterPathW.s b/libc/nt/pdh/PdhMakeCounterPathW.s new file mode 100644 index 000000000..98541e00a --- /dev/null +++ b/libc/nt/pdh/PdhMakeCounterPathW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhMakeCounterPathW,PdhMakeCounterPathW,0 diff --git a/libc/nt/pdh/PdhOpenLogW.s b/libc/nt/pdh/PdhOpenLogW.s new file mode 100644 index 000000000..0886535f0 --- /dev/null +++ b/libc/nt/pdh/PdhOpenLogW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhOpenLogW,PdhOpenLogW,0 diff --git a/libc/nt/pdh/PdhOpenQueryH.s b/libc/nt/pdh/PdhOpenQueryH.s new file mode 100644 index 000000000..5e0a601b5 --- /dev/null +++ b/libc/nt/pdh/PdhOpenQueryH.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhOpenQueryH,PdhOpenQueryH,0 diff --git a/libc/nt/pdh/PdhOpenQueryW.s b/libc/nt/pdh/PdhOpenQueryW.s new file mode 100644 index 000000000..3cd48bbdd --- /dev/null +++ b/libc/nt/pdh/PdhOpenQueryW.s @@ -0,0 +1,12 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhOpenQueryW,PdhOpenQueryW,0 + + .text.windows +PdhOpenQuery: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_PdhOpenQueryW(%rip),%rax + jmp __sysv2nt + .endfn PdhOpenQuery,globl + .previous diff --git a/libc/nt/pdh/PdhParseCounterPathW.s b/libc/nt/pdh/PdhParseCounterPathW.s new file mode 100644 index 000000000..162a1520f --- /dev/null +++ b/libc/nt/pdh/PdhParseCounterPathW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhParseCounterPathW,PdhParseCounterPathW,0 diff --git a/libc/nt/pdh/PdhParseInstanceNameW.s b/libc/nt/pdh/PdhParseInstanceNameW.s new file mode 100644 index 000000000..ebb598a6f --- /dev/null +++ b/libc/nt/pdh/PdhParseInstanceNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhParseInstanceNameW,PdhParseInstanceNameW,0 diff --git a/libc/nt/pdh/PdhReadRawLogRecord.s b/libc/nt/pdh/PdhReadRawLogRecord.s new file mode 100644 index 000000000..467bfcb7d --- /dev/null +++ b/libc/nt/pdh/PdhReadRawLogRecord.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhReadRawLogRecord,PdhReadRawLogRecord,0 diff --git a/libc/nt/pdh/PdhRemoveCounter.s b/libc/nt/pdh/PdhRemoveCounter.s new file mode 100644 index 000000000..d530fbc9f --- /dev/null +++ b/libc/nt/pdh/PdhRemoveCounter.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhRemoveCounter,PdhRemoveCounter,0 diff --git a/libc/nt/pdh/PdhSelectDataSourceW.s b/libc/nt/pdh/PdhSelectDataSourceW.s new file mode 100644 index 000000000..6ee75cb3e --- /dev/null +++ b/libc/nt/pdh/PdhSelectDataSourceW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhSelectDataSourceW,PdhSelectDataSourceW,0 diff --git a/libc/nt/pdh/PdhSetCounterScaleFactor.s b/libc/nt/pdh/PdhSetCounterScaleFactor.s new file mode 100644 index 000000000..aa998a144 --- /dev/null +++ b/libc/nt/pdh/PdhSetCounterScaleFactor.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhSetCounterScaleFactor,PdhSetCounterScaleFactor,0 diff --git a/libc/nt/pdh/PdhSetDefaultRealTimeDataSource.s b/libc/nt/pdh/PdhSetDefaultRealTimeDataSource.s new file mode 100644 index 000000000..e41cd825e --- /dev/null +++ b/libc/nt/pdh/PdhSetDefaultRealTimeDataSource.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhSetDefaultRealTimeDataSource,PdhSetDefaultRealTimeDataSource,0 diff --git a/libc/nt/pdh/PdhSetQueryTimeRange.s b/libc/nt/pdh/PdhSetQueryTimeRange.s new file mode 100644 index 000000000..dc4e7b159 --- /dev/null +++ b/libc/nt/pdh/PdhSetQueryTimeRange.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhSetQueryTimeRange,PdhSetQueryTimeRange,0 diff --git a/libc/nt/pdh/PdhUpdateLogFileCatalog.s b/libc/nt/pdh/PdhUpdateLogFileCatalog.s new file mode 100644 index 000000000..067da7a51 --- /dev/null +++ b/libc/nt/pdh/PdhUpdateLogFileCatalog.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhUpdateLogFileCatalog,PdhUpdateLogFileCatalog,0 diff --git a/libc/nt/pdh/PdhUpdateLogW.s b/libc/nt/pdh/PdhUpdateLogW.s new file mode 100644 index 000000000..f2f30b44b --- /dev/null +++ b/libc/nt/pdh/PdhUpdateLogW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhUpdateLogW,PdhUpdateLogW,0 diff --git a/libc/nt/pdh/PdhValidatePathExW.s b/libc/nt/pdh/PdhValidatePathExW.s new file mode 100644 index 000000000..2d150ebfb --- /dev/null +++ b/libc/nt/pdh/PdhValidatePathExW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhValidatePathExW,PdhValidatePathExW,0 diff --git a/libc/nt/pdh/PdhValidatePathW.s b/libc/nt/pdh/PdhValidatePathW.s new file mode 100644 index 000000000..bb6811c22 --- /dev/null +++ b/libc/nt/pdh/PdhValidatePathW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PdhValidatePathW,PdhValidatePathW,0 diff --git a/libc/nt/pdh/PerfAddCounters.s b/libc/nt/pdh/PerfAddCounters.s new file mode 100644 index 000000000..faacea528 --- /dev/null +++ b/libc/nt/pdh/PerfAddCounters.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfAddCounters,PerfAddCounters,0 diff --git a/libc/nt/pdh/PerfCloseQueryHandle.s b/libc/nt/pdh/PerfCloseQueryHandle.s new file mode 100644 index 000000000..bda6507bb --- /dev/null +++ b/libc/nt/pdh/PerfCloseQueryHandle.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfCloseQueryHandle,PerfCloseQueryHandle,0 diff --git a/libc/nt/pdh/PerfCreateInstance.s b/libc/nt/pdh/PerfCreateInstance.s new file mode 100644 index 000000000..d4668cbd8 --- /dev/null +++ b/libc/nt/pdh/PerfCreateInstance.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfCreateInstance,PerfCreateInstance,0 diff --git a/libc/nt/pdh/PerfDecrementULongCounterValue.s b/libc/nt/pdh/PerfDecrementULongCounterValue.s new file mode 100644 index 000000000..8a4220ef6 --- /dev/null +++ b/libc/nt/pdh/PerfDecrementULongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfDecrementULongCounterValue,PerfDecrementULongCounterValue,0 diff --git a/libc/nt/pdh/PerfDecrementULongLongCounterValue.s b/libc/nt/pdh/PerfDecrementULongLongCounterValue.s new file mode 100644 index 000000000..bfab227b5 --- /dev/null +++ b/libc/nt/pdh/PerfDecrementULongLongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfDecrementULongLongCounterValue,PerfDecrementULongLongCounterValue,0 diff --git a/libc/nt/pdh/PerfDeleteCounters.s b/libc/nt/pdh/PerfDeleteCounters.s new file mode 100644 index 000000000..4adb33980 --- /dev/null +++ b/libc/nt/pdh/PerfDeleteCounters.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfDeleteCounters,PerfDeleteCounters,0 diff --git a/libc/nt/pdh/PerfDeleteInstance.s b/libc/nt/pdh/PerfDeleteInstance.s new file mode 100644 index 000000000..f253b4de3 --- /dev/null +++ b/libc/nt/pdh/PerfDeleteInstance.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfDeleteInstance,PerfDeleteInstance,0 diff --git a/libc/nt/pdh/PerfEnumerateCounterSet.s b/libc/nt/pdh/PerfEnumerateCounterSet.s new file mode 100644 index 000000000..e19de7668 --- /dev/null +++ b/libc/nt/pdh/PerfEnumerateCounterSet.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfEnumerateCounterSet,PerfEnumerateCounterSet,0 diff --git a/libc/nt/pdh/PerfEnumerateCounterSetInstances.s b/libc/nt/pdh/PerfEnumerateCounterSetInstances.s new file mode 100644 index 000000000..4491b9462 --- /dev/null +++ b/libc/nt/pdh/PerfEnumerateCounterSetInstances.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfEnumerateCounterSetInstances,PerfEnumerateCounterSetInstances,0 diff --git a/libc/nt/pdh/PerfIncrementULongCounterValue.s b/libc/nt/pdh/PerfIncrementULongCounterValue.s new file mode 100644 index 000000000..1a3358222 --- /dev/null +++ b/libc/nt/pdh/PerfIncrementULongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfIncrementULongCounterValue,PerfIncrementULongCounterValue,0 diff --git a/libc/nt/pdh/PerfIncrementULongLongCounterValue.s b/libc/nt/pdh/PerfIncrementULongLongCounterValue.s new file mode 100644 index 000000000..accb87e3c --- /dev/null +++ b/libc/nt/pdh/PerfIncrementULongLongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfIncrementULongLongCounterValue,PerfIncrementULongLongCounterValue,0 diff --git a/libc/nt/pdh/PerfOpenQueryHandle.s b/libc/nt/pdh/PerfOpenQueryHandle.s new file mode 100644 index 000000000..0945f43c9 --- /dev/null +++ b/libc/nt/pdh/PerfOpenQueryHandle.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfOpenQueryHandle,PerfOpenQueryHandle,0 diff --git a/libc/nt/pdh/PerfQueryCounterData.s b/libc/nt/pdh/PerfQueryCounterData.s new file mode 100644 index 000000000..37af4c287 --- /dev/null +++ b/libc/nt/pdh/PerfQueryCounterData.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfQueryCounterData,PerfQueryCounterData,0 diff --git a/libc/nt/pdh/PerfQueryCounterInfo.s b/libc/nt/pdh/PerfQueryCounterInfo.s new file mode 100644 index 000000000..42f10abe4 --- /dev/null +++ b/libc/nt/pdh/PerfQueryCounterInfo.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfQueryCounterInfo,PerfQueryCounterInfo,0 diff --git a/libc/nt/pdh/PerfQueryCounterSetRegistrationInfo.s b/libc/nt/pdh/PerfQueryCounterSetRegistrationInfo.s new file mode 100644 index 000000000..113a24e3a --- /dev/null +++ b/libc/nt/pdh/PerfQueryCounterSetRegistrationInfo.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfQueryCounterSetRegistrationInfo,PerfQueryCounterSetRegistrationInfo,0 diff --git a/libc/nt/pdh/PerfQueryInstance.s b/libc/nt/pdh/PerfQueryInstance.s new file mode 100644 index 000000000..413579ebe --- /dev/null +++ b/libc/nt/pdh/PerfQueryInstance.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfQueryInstance,PerfQueryInstance,0 diff --git a/libc/nt/pdh/PerfSetCounterRefValue.s b/libc/nt/pdh/PerfSetCounterRefValue.s new file mode 100644 index 000000000..54c374a0d --- /dev/null +++ b/libc/nt/pdh/PerfSetCounterRefValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfSetCounterRefValue,PerfSetCounterRefValue,0 diff --git a/libc/nt/pdh/PerfSetCounterSetInfo.s b/libc/nt/pdh/PerfSetCounterSetInfo.s new file mode 100644 index 000000000..80c0e9c5b --- /dev/null +++ b/libc/nt/pdh/PerfSetCounterSetInfo.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfSetCounterSetInfo,PerfSetCounterSetInfo,0 diff --git a/libc/nt/pdh/PerfSetULongCounterValue.s b/libc/nt/pdh/PerfSetULongCounterValue.s new file mode 100644 index 000000000..dbe0690e0 --- /dev/null +++ b/libc/nt/pdh/PerfSetULongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfSetULongCounterValue,PerfSetULongCounterValue,0 diff --git a/libc/nt/pdh/PerfSetULongLongCounterValue.s b/libc/nt/pdh/PerfSetULongLongCounterValue.s new file mode 100644 index 000000000..584f098ee --- /dev/null +++ b/libc/nt/pdh/PerfSetULongLongCounterValue.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfSetULongLongCounterValue,PerfSetULongLongCounterValue,0 diff --git a/libc/nt/pdh/PerfStartProvider.s b/libc/nt/pdh/PerfStartProvider.s new file mode 100644 index 000000000..54421fc03 --- /dev/null +++ b/libc/nt/pdh/PerfStartProvider.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfStartProvider,PerfStartProvider,0 diff --git a/libc/nt/pdh/PerfStartProviderEx.s b/libc/nt/pdh/PerfStartProviderEx.s new file mode 100644 index 000000000..ab60ea386 --- /dev/null +++ b/libc/nt/pdh/PerfStartProviderEx.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfStartProviderEx,PerfStartProviderEx,0 diff --git a/libc/nt/pdh/PerfStopProvider.s b/libc/nt/pdh/PerfStopProvider.s new file mode 100644 index 000000000..72a2323e8 --- /dev/null +++ b/libc/nt/pdh/PerfStopProvider.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_PerfStopProvider,PerfStopProvider,0 diff --git a/libc/nt/pdh/UnloadPerfCounterTextStringsW.s b/libc/nt/pdh/UnloadPerfCounterTextStringsW.s new file mode 100644 index 000000000..47bce47d3 --- /dev/null +++ b/libc/nt/pdh/UnloadPerfCounterTextStringsW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp pdh,__imp_UnloadPerfCounterTextStringsW,UnloadPerfCounterTextStringsW,0 diff --git a/libc/nt/privilege.h b/libc/nt/privilege.h index 0f49ba915..988d9340f 100644 --- a/libc/nt/privilege.h +++ b/libc/nt/privilege.h @@ -44,6 +44,9 @@ bool32 AdjustTokenPrivileges(int64_t TokenHandle, bool32 DisableAllPrivileges, struct NtTokenPrivileges *opt_out_PreviousState, uint32_t *opt_out_ReturnLength); +bool32 ImpersonateSelf(int kNtSecurityImpersonationLevel); +bool32 RevertToSelf(void); + COSMOPOLITAN_C_END_ #endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ #endif /* COSMOPOLITAN_LIBC_NT_PRIVILEGE_H_ */ diff --git a/libc/nt/process.h b/libc/nt/process.h index 02ff6d4b1..d93dee46d 100644 --- a/libc/nt/process.h +++ b/libc/nt/process.h @@ -2,6 +2,7 @@ #define COSMOPOLITAN_LIBC_NT_PROCESS_H_ #include "libc/nt/startupinfo.h" #include "libc/nt/struct/processinformation.h" +#include "libc/nt/struct/processmemorycounters.h" #include "libc/nt/struct/securityattributes.h" #include "libc/nt/thunk/msabi.h" /* ░░░░ @@ -68,6 +69,10 @@ bool32 SetPriorityClass(int64_t hProcess, uint32_t dwPriorityClass); bool32 SetProcessPriorityBoost(int64_t hProcess, bool32 bDisablePriorityBoost); bool32 GetProcessPriorityBoost(int64_t hProcess, bool32 *pDisablePriorityBoost); +bool32 GetProcessMemoryInfo( + int64_t hProcess, struct NtProcessMemoryCountersEx *out_ppsmemCounters, + uint32_t cb); + #if ShouldUseMsabiAttribute() #include "libc/nt/thunk/process.inc" #endif /* ShouldUseMsabiAttribute() */ diff --git a/libc/nt/psapi/EmptyWorkingSet.s b/libc/nt/psapi/EmptyWorkingSet.s new file mode 100644 index 000000000..bb1c21f7d --- /dev/null +++ b/libc/nt/psapi/EmptyWorkingSet.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EmptyWorkingSet,EmptyWorkingSet,0 diff --git a/libc/nt/psapi/EnumDeviceDrivers.s b/libc/nt/psapi/EnumDeviceDrivers.s new file mode 100644 index 000000000..3882481f1 --- /dev/null +++ b/libc/nt/psapi/EnumDeviceDrivers.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EnumDeviceDrivers,EnumDeviceDrivers,0 diff --git a/libc/nt/psapi/EnumPageFilesW.s b/libc/nt/psapi/EnumPageFilesW.s new file mode 100644 index 000000000..72fa3494f --- /dev/null +++ b/libc/nt/psapi/EnumPageFilesW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EnumPageFilesW,EnumPageFilesW,0 diff --git a/libc/nt/psapi/EnumProcessModules.s b/libc/nt/psapi/EnumProcessModules.s new file mode 100644 index 000000000..6f93ab8f0 --- /dev/null +++ b/libc/nt/psapi/EnumProcessModules.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EnumProcessModules,EnumProcessModules,0 diff --git a/libc/nt/psapi/EnumProcessModulesEx.s b/libc/nt/psapi/EnumProcessModulesEx.s new file mode 100644 index 000000000..c9cf50f39 --- /dev/null +++ b/libc/nt/psapi/EnumProcessModulesEx.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EnumProcessModulesEx,EnumProcessModulesEx,0 diff --git a/libc/nt/psapi/EnumProcesses.s b/libc/nt/psapi/EnumProcesses.s new file mode 100644 index 000000000..895b1121f --- /dev/null +++ b/libc/nt/psapi/EnumProcesses.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_EnumProcesses,EnumProcesses,0 diff --git a/libc/nt/psapi/GetDeviceDriverBaseNameW.s b/libc/nt/psapi/GetDeviceDriverBaseNameW.s new file mode 100644 index 000000000..9e50059a9 --- /dev/null +++ b/libc/nt/psapi/GetDeviceDriverBaseNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetDeviceDriverBaseNameW,GetDeviceDriverBaseNameW,0 diff --git a/libc/nt/psapi/GetDeviceDriverFileNameW.s b/libc/nt/psapi/GetDeviceDriverFileNameW.s new file mode 100644 index 000000000..d165528ee --- /dev/null +++ b/libc/nt/psapi/GetDeviceDriverFileNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetDeviceDriverFileNameW,GetDeviceDriverFileNameW,0 diff --git a/libc/nt/psapi/GetMappedFileNameW.s b/libc/nt/psapi/GetMappedFileNameW.s new file mode 100644 index 000000000..e582bb488 --- /dev/null +++ b/libc/nt/psapi/GetMappedFileNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetMappedFileNameW,GetMappedFileNameW,0 diff --git a/libc/nt/psapi/GetModuleBaseNameW.s b/libc/nt/psapi/GetModuleBaseNameW.s new file mode 100644 index 000000000..fcd7fa8eb --- /dev/null +++ b/libc/nt/psapi/GetModuleBaseNameW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetModuleBaseNameW,GetModuleBaseNameW,0 diff --git a/libc/nt/psapi/GetModuleFileNameExW.s b/libc/nt/psapi/GetModuleFileNameExW.s new file mode 100644 index 000000000..052f45dc0 --- /dev/null +++ b/libc/nt/psapi/GetModuleFileNameExW.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetModuleFileNameExW,GetModuleFileNameExW,0 diff --git a/libc/nt/psapi/GetModuleInformation.s b/libc/nt/psapi/GetModuleInformation.s new file mode 100644 index 000000000..c490e0628 --- /dev/null +++ b/libc/nt/psapi/GetModuleInformation.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetModuleInformation,GetModuleInformation,0 diff --git a/libc/nt/psapi/GetPerformanceInfo.s b/libc/nt/psapi/GetPerformanceInfo.s new file mode 100644 index 000000000..c09bf8397 --- /dev/null +++ b/libc/nt/psapi/GetPerformanceInfo.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetPerformanceInfo,GetPerformanceInfo,0 diff --git a/libc/nt/kernel32/GetProcessImageFileNameW.s b/libc/nt/psapi/GetProcessImageFileNameW.s similarity index 75% rename from libc/nt/kernel32/GetProcessImageFileNameW.s rename to libc/nt/psapi/GetProcessImageFileNameW.s index e52caecda..d9205e732 100644 --- a/libc/nt/kernel32/GetProcessImageFileNameW.s +++ b/libc/nt/psapi/GetProcessImageFileNameW.s @@ -1,5 +1,5 @@ .include "o/libc/nt/codegen.inc" -.imp kernel32,__imp_GetProcessImageFileNameW,GetProcessImageFileNameW,677 +.imp psapi,__imp_GetProcessImageFileNameW,GetProcessImageFileNameW,0 .text.windows GetProcessImageFileName: diff --git a/libc/nt/psapi/GetProcessMemoryInfo.s b/libc/nt/psapi/GetProcessMemoryInfo.s new file mode 100644 index 000000000..b5e8d936f --- /dev/null +++ b/libc/nt/psapi/GetProcessMemoryInfo.s @@ -0,0 +1,12 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetProcessMemoryInfo,GetProcessMemoryInfo,0 + + .text.windows +GetProcessMemoryInfo: + push %rbp + mov %rsp,%rbp + .profilable + mov __imp_GetProcessMemoryInfo(%rip),%rax + jmp __sysv2nt + .endfn GetProcessMemoryInfo,globl + .previous diff --git a/libc/nt/psapi/GetWsChanges.s b/libc/nt/psapi/GetWsChanges.s new file mode 100644 index 000000000..ce4b33875 --- /dev/null +++ b/libc/nt/psapi/GetWsChanges.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetWsChanges,GetWsChanges,0 diff --git a/libc/nt/psapi/GetWsChangesEx.s b/libc/nt/psapi/GetWsChangesEx.s new file mode 100644 index 000000000..3ced55868 --- /dev/null +++ b/libc/nt/psapi/GetWsChangesEx.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_GetWsChangesEx,GetWsChangesEx,0 diff --git a/libc/nt/psapi/InitializeProcessForWsWatch.s b/libc/nt/psapi/InitializeProcessForWsWatch.s new file mode 100644 index 000000000..69c6a193b --- /dev/null +++ b/libc/nt/psapi/InitializeProcessForWsWatch.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_InitializeProcessForWsWatch,InitializeProcessForWsWatch,0 diff --git a/libc/nt/psapi/QueryWorkingSet.s b/libc/nt/psapi/QueryWorkingSet.s new file mode 100644 index 000000000..25e5852cb --- /dev/null +++ b/libc/nt/psapi/QueryWorkingSet.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_QueryWorkingSet,QueryWorkingSet,0 diff --git a/libc/nt/psapi/QueryWorkingSetEx.s b/libc/nt/psapi/QueryWorkingSetEx.s new file mode 100644 index 000000000..34158f94d --- /dev/null +++ b/libc/nt/psapi/QueryWorkingSetEx.s @@ -0,0 +1,2 @@ +.include "o/libc/nt/codegen.inc" +.imp psapi,__imp_QueryWorkingSetEx,QueryWorkingSetEx,0 diff --git a/libc/nt/struct/pdhfmtcountervalue.h b/libc/nt/struct/pdhfmtcountervalue.h new file mode 100644 index 000000000..644c98fb7 --- /dev/null +++ b/libc/nt/struct/pdhfmtcountervalue.h @@ -0,0 +1,19 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +struct NtPdhFmtCountervalue { + uint32_t CStatus; + union { + int32_t longValue; + double doubleValue; + int64_t largeValue; + const char *AnsiStringValue; + const char16_t *WideStringValue; + }; +}; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PDHFMTCOUNTERVALUE_H_ */ diff --git a/libc/nt/struct/processmemorycounters.h b/libc/nt/struct/processmemorycounters.h new file mode 100644 index 000000000..43bad8814 --- /dev/null +++ b/libc/nt/struct/processmemorycounters.h @@ -0,0 +1,22 @@ +#ifndef COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_ +#define COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +struct NtProcessMemoryCountersEx { + uint32_t cb; /* count bytes */ + uint32_t PageFaultCount; + uint64_t PeakWorkingSetSize; + uint64_t WorkingSetSize; + uint64_t QuotaPeakPagedPoolUsage; + uint64_t QuotaPagedPoolUsage; + uint64_t QuotaPeakNonPagedPoolUsage; + uint64_t QuotaNonPagedPoolUsage; + uint64_t PagefileUsage; + uint64_t PeakPagefileUsage; + uint64_t PrivateUsage; +}; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_LIBC_NT_STRUCT_PROCESSMEMORYCOUNTERS_H_ */ diff --git a/libc/runtime/fork-nt.c b/libc/runtime/fork-nt.c index 7accbf596..6704dfb30 100644 --- a/libc/runtime/fork-nt.c +++ b/libc/runtime/fork-nt.c @@ -328,6 +328,7 @@ textwindows int sys_fork_nt(void) { g_fds.p[pid].handle = procinfo.hProcess; g_fds.p[pid].flags = O_CLOEXEC; untrackpid = -1; + rc = pid; } else { /* * XXX: Ignoring SIGCHLD should track the process information. @@ -336,10 +337,10 @@ textwindows int sys_fork_nt(void) { * functions like poll() so it doesn't get zombdied. */ STRACE("fork() parent closing process handle b/c SIGCHLD=SIG_IGN"); + rc = GetProcessId(procinfo.hProcess); CloseHandle(procinfo.hProcess); } STRACE("fork() parent everything looks good"); - rc = pid; } else { STRACE("fork() parent ~~failed~~ because writing failed"); rc = __winerr(); diff --git a/test/libc/calls/mprotect_test.c b/test/libc/calls/mprotect_test.c index 8cf332040..ec2cd719c 100644 --- a/test/libc/calls/mprotect_test.c +++ b/test/libc/calls/mprotect_test.c @@ -53,7 +53,6 @@ TEST(mprotect, test) { TEST(mprotect, testSegfault) { char *p; struct sigaction ss = {.sa_handler = OnSigSegv, .sa_flags = SA_NODEFER}; - if (IsWindows()) return; /* TODO */ p = gc(memalign(PAGESIZE, PAGESIZE)); EXPECT_NE(-1, sigaction(SIGBUS, &ss, NULL)); EXPECT_NE(-1, sigaction(SIGSEGV, &ss, NULL)); diff --git a/test/libc/stdio/mkostempsm_test.c b/test/libc/stdio/mkostempsm_test.c index af911e000..f99e32a7e 100644 --- a/test/libc/stdio/mkostempsm_test.c +++ b/test/libc/stdio/mkostempsm_test.c @@ -45,7 +45,6 @@ static int MockOpen1(const char *file, int flags, ...) { } TEST(mkostempsm, test1) { - if (IsWindows()) return; /* TODO */ uint64_t rando = 1; char path[PATH_MAX] = "/tmp/mkostemps.XXXXXX"; EXPECT_EQ(123L, mkostempsmi(path, 0, 0, &rando, 0600, MockOpen1)); @@ -74,7 +73,6 @@ static int MockOpen2(const char *file, int flags, ...) { } TEST(mkostempsm, test2) { - if (IsWindows()) return; /* TODO */ uint64_t rando = 1; char path[PATH_MAX] = "/tmp/mkostemps.XXXXXX"; EXPECT_EQ(123, mkostempsmi(path, 0, 0, &rando, 0600, MockOpen2)); diff --git a/test/libc/tinymath/strtod_test.c b/test/libc/tinymath/strtod_test.c index bd9c38388..e1fce65a8 100644 --- a/test/libc/tinymath/strtod_test.c +++ b/test/libc/tinymath/strtod_test.c @@ -33,28 +33,24 @@ void TearDown(void) { } TEST(strtod, testNearest) { - if (IsWindows()) return; fesetround(FE_TONEAREST); EXPECT_STREQ("-1.79769313486231e+308", gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testDownward) { - if (IsWindows()) return; fesetround(FE_DOWNWARD); EXPECT_STREQ("-1.79769313486232e+308", gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testUpward) { - if (IsWindows()) return; fesetround(FE_UPWARD); EXPECT_STREQ("-1.7976931348623e+308", gc(xasprintf("%.15g", strtod("-1.79769313486231e+308", NULL)))); } TEST(strtod, testTowardzero) { - if (IsWindows()) return; char *p; for (int i = 0; i < 9999; ++i) { fesetround(FE_TOWARDZERO);