| ... | ... | @@ -16279,6 +16279,8 @@ fn createFileMap( |
| 16279 | 16279 | .SUCCESS => {}, |
| 16280 | 16280 | .CONFLICTING_ADDRESSES => return error.MappingAlreadyExists, |
| 16281 | 16281 | .SECTION_PROTECTION => return error.PermissionDenied, |
| 16282 | .ACCESS_DENIED => return error.AccessDenied, |
| 16283 | .INVALID_VIEW_SIZE => |status| return windows.statusBug(status), |
| 16282 | 16284 | else => |status| return windows.unexpectedStatus(status), |
| 16283 | 16285 | } |
| 16284 | 16286 | if (builtin.mode == .Debug) { |
| ... | ... | @@ -16392,32 +16394,47 @@ fn fileMemoryMapSetLength( |
| 16392 | 16394 | const new_len = options.len; |
| 16393 | 16395 | |
| 16394 | 16396 | if (mm.section) |section| { |
| 16395 | | if (alignment.forward(new_len) == alignment.forward(old_memory.len)) { |
| 16397 | const aligned_old_len = alignment.forward(old_memory.len); |
| 16398 | const aligned_new_len = alignment.forward(new_len); |
| 16399 | if (aligned_new_len == aligned_old_len) { |
| 16396 | 16400 | mm.memory.len = new_len; |
| 16397 | 16401 | return; |
| 16398 | 16402 | } |
| 16399 | 16403 | switch (native_os) { |
| 16400 | 16404 | .windows => { |
| 16401 | | var contents_ptr: ?[*]align(page_align) u8 = null; |
| 16402 | | var contents_len = new_len; |
| 16403 | | switch (windows.ntdll.NtMapViewOfSection( |
| 16404 | | section, |
| 16405 | | windows.current_process, |
| 16406 | | @ptrCast(&contents_ptr), |
| 16407 | | null, |
| 16408 | | 0, |
| 16409 | | null, |
| 16410 | | &contents_len, |
| 16411 | | .Unmap, |
| 16412 | | .{}, |
| 16413 | | .{ .READWRITE = true }, |
| 16414 | | )) { |
| 16415 | | .SUCCESS => {}, |
| 16416 | | .SECTION_PROTECTION => return error.PermissionDenied, |
| 16417 | | else => |status| return windows.unexpectedStatus(status), |
| 16405 | if (aligned_new_len > aligned_old_len) { |
| 16406 | var new_section_size: windows.LARGE_INTEGER = @intCast(aligned_new_len); |
| 16407 | switch (windows.ntdll.NtExtendSection(section, &new_section_size)) { |
| 16408 | .SUCCESS => {}, |
| 16409 | else => |status| return windows.unexpectedStatus(status), |
| 16410 | } |
| 16411 | assert(new_section_size == aligned_new_len); |
| 16412 | mm.memory.len = new_len; |
| 16413 | } else { |
| 16414 | _ = windows.ntdll.NtUnmapViewOfSection(windows.current_process, old_memory.ptr); |
| 16415 | windows.CloseHandle(section); |
| 16416 | var contents_len = aligned_new_len; |
| 16417 | var contents_ptr: ?[*]align(std.heap.page_size_min) u8 = null; |
| 16418 | switch (windows.ntdll.NtMapViewOfSection( |
| 16419 | section, |
| 16420 | windows.current_process, |
| 16421 | @ptrCast(&contents_ptr), |
| 16422 | null, |
| 16423 | 0, |
| 16424 | null, |
| 16425 | &contents_len, |
| 16426 | .Unmap, |
| 16427 | .{}, |
| 16428 | .{ .READWRITE = true }, |
| 16429 | )) { |
| 16430 | .SUCCESS => {}, |
| 16431 | .SECTION_PROTECTION => return error.PermissionDenied, |
| 16432 | .INVALID_VIEW_SIZE => |status| return windows.statusBug(status), |
| 16433 | else => |status| return windows.unexpectedStatus(status), |
| 16434 | } |
| 16435 | assert(contents_len == aligned_new_len); |
| 16436 | mm.memory = contents_ptr.?[0..new_len]; |
| 16418 | 16437 | } |
| 16419 | | assert(contents_len == alignment.forward(new_len)); |
| 16420 | | mm.memory = contents_ptr.?[0..new_len]; |
| 16421 | 16438 | }, |
| 16422 | 16439 | .wasi => unreachable, |
| 16423 | 16440 | .linux => { |