"""Windows shim for the POSIX `resource` module, used only so #477's producer and checker search logic can run on this machine. It reports peak working set in KiB (the Linux ru_maxrss convention) so the caller's `rss *= 1024` yields bytes and the 900 MB guard behaves as on Linux. This shim does NOT change any search decision: the only consumers are the RAM headroom guard (which never fires here) and the receipt field `peak_rss_bytes`, which the recorded deterministic receipts exclude. """ import ctypes import ctypes.wintypes as wt RUSAGE_SELF = 0 class _ProcessMemoryCounters(ctypes.Structure): _fields_ = [ ("cb", wt.DWORD), ("PageFaultCount", wt.DWORD), ("PeakWorkingSetSize", ctypes.c_size_t), ("WorkingSetSize", ctypes.c_size_t), ("QuotaPeakPagedPoolUsage", ctypes.c_size_t), ("QuotaPagedPoolUsage", ctypes.c_size_t), ("QuotaPeakNonPagedPoolUsage", ctypes.c_size_t), ("QuotaNonPagedPoolUsage", ctypes.c_size_t), ("PagefileUsage", ctypes.c_size_t), ("PeakPagefileUsage", ctypes.c_size_t), ] class _Usage: @property def ru_maxrss(self): try: counters = _ProcessMemoryCounters() counters.cb = ctypes.sizeof(counters) ok = ctypes.windll.psapi.GetProcessMemoryInfo( ctypes.windll.kernel32.GetCurrentProcess(), ctypes.byref(counters), ctypes.sizeof(counters), ) if ok: return counters.PeakWorkingSetSize // 1024 # bytes -> KiB except Exception: pass return 0 def getrusage(who=0): return _Usage()