28static DWORD get_allocation_granularity(
void) {
29 static DWORD granularity;
34 granularity = sys.dwAllocationGranularity;
44 HANDLE fh = (HANDLE)_get_osfhandle(fd);
45 DWORD alignment = get_allocation_granularity();
59 if (fh == INVALID_HANDLE_VALUE) {
64 fmap_prot |= PAGE_READWRITE;
66 fmap_prot |= PAGE_READONLY;
70 view_prot |= FILE_MAP_WRITE;
73 view_prot |= FILE_MAP_READ;
76 page_start = (offset / alignment) * alignment;
77 page_offset = offset - page_start;
79 if (page_offset != 0) {
81 ctx,
MEMORY_MAP_FAILED,
"failed to mmap. Offset must be a multiple of allocation granularity"
85 out->fmh = CreateFileMapping(fh, NULL, fmap_prot, 0, 0, NULL);
86 if (!out->fmh || out->fmh == INVALID_HANDLE_VALUE) {
91 off_low = (DWORD)(page_start);
92 off_hi = (DWORD)(page_start >> 32);
93 out->
data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len);
95 CloseHandle(out->fmh);
110 if (!UnmapViewOfFile(map->
data)) {
117 if (!CloseHandle(map->fmh)) {
Error handling for the runtime.
#define ERR(ctx, err, msg)
The fiber facing IO API: blocking looking calls a fiber uses to do IO.
int srn_munmap(srn_mmap_buffer_t *map)
srn_error_t * srn_mmap(srn_context_t *ctx, srn_mmap_buffer_t *out, size_t len, int prot, int flags, int fd, off64_t offset)
#define SRN_MMAP_VALIDATE(out, len, prot, flags)
A runtime error, a tag classifying the failure and a human-readable message.
#define PANIC_IF_NULL(ptr)