| 1 | module closure |
| 2 | |
| 3 | #include <synchapi.h> |
| 4 | |
| 5 | struct ClosureMutex { |
| 6 | closure_mtx C.SRWLOCK |
| 7 | } |
| 8 | |
| 9 | @[inline] |
| 10 | fn closure_alloc_platform() &u8 { |
| 11 | p := &u8(C.VirtualAlloc(0, g_closure.v_page_size * 2, C.MEM_COMMIT | C.MEM_RESERVE, |
| 12 | C.PAGE_READWRITE)) |
| 13 | return p |
| 14 | } |
| 15 | |
| 16 | @[inline] |
| 17 | fn closure_memory_protect_platform(ptr voidptr, size isize, attr MemoryProtectAtrr) { |
| 18 | mut tmp := u32(0) |
| 19 | match attr { |
| 20 | .read_exec { |
| 21 | _ := C.VirtualProtect(ptr, size, C.PAGE_EXECUTE_READ, &tmp) |
| 22 | } |
| 23 | .read_write { |
| 24 | _ := C.VirtualProtect(ptr, size, C.PAGE_READWRITE, &tmp) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | @[inline] |
| 30 | fn get_page_size_platform() int { |
| 31 | // Determine system page size |
| 32 | mut si := C.SYSTEM_INFO{} |
| 33 | C.GetNativeSystemInfo(&si) |
| 34 | |
| 35 | // Calculate required allocation size |
| 36 | page_size := int(si.dwPageSize) * (((assumed_page_size - 1) / int(si.dwPageSize)) + 1) |
| 37 | return page_size |
| 38 | } |
| 39 | |
| 40 | @[inline] |
| 41 | fn closure_mtx_lock_init_platform() { |
| 42 | C.InitializeSRWLock(&g_closure.closure_mtx) |
| 43 | } |
| 44 | |
| 45 | @[inline] |
| 46 | fn closure_mtx_lock_platform() { |
| 47 | C.AcquireSRWLockExclusive(&g_closure.closure_mtx) |
| 48 | } |
| 49 | |
| 50 | @[inline] |
| 51 | fn closure_mtx_unlock_platform() { |
| 52 | C.ReleaseSRWLockExclusive(&g_closure.closure_mtx) |
| 53 | } |
| 54 | |