authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-15 13:48:27-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-01-15 14:18:21-08:00
logd2585e68a79b8e43166e797d6adc33282acac046
tree9f5f630e1db7f3fb8a800874b0ecb9e97e20c43b
parentde347dd6a981151609f1b9e79183d3f44046abc0

std.Io.Threaded: use NtExtendSection in fileMemoryMapSetLength

is this a good idea? not sure yet. reverting in the next commit

2 files changed, 42 insertions(+), 20 deletions(-)

lib/std/Io/Threaded.zig+37-20
...@@ -16279,6 +16279,8 @@ fn createFileMap(...@@ -16279,6 +16279,8 @@ fn createFileMap(
16279 .SUCCESS => {},16279 .SUCCESS => {},
16280 .CONFLICTING_ADDRESSES => return error.MappingAlreadyExists,16280 .CONFLICTING_ADDRESSES => return error.MappingAlreadyExists,
16281 .SECTION_PROTECTION => return error.PermissionDenied,16281 .SECTION_PROTECTION => return error.PermissionDenied,
16282 .ACCESS_DENIED => return error.AccessDenied,
16283 .INVALID_VIEW_SIZE => |status| return windows.statusBug(status),
16282 else => |status| return windows.unexpectedStatus(status),16284 else => |status| return windows.unexpectedStatus(status),
16283 }16285 }
16284 if (builtin.mode == .Debug) {16286 if (builtin.mode == .Debug) {
...@@ -16392,32 +16394,47 @@ fn fileMemoryMapSetLength(...@@ -16392,32 +16394,47 @@ fn fileMemoryMapSetLength(
16392 const new_len = options.len;16394 const new_len = options.len;
1639316395
16394 if (mm.section) |section| {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 mm.memory.len = new_len;16400 mm.memory.len = new_len;
16397 return;16401 return;
16398 }16402 }
16399 switch (native_os) {16403 switch (native_os) {
16400 .windows => {16404 .windows => {
16401 var contents_ptr: ?[*]align(page_align) u8 = null;16405 if (aligned_new_len > aligned_old_len) {
16402 var contents_len = new_len;16406 var new_section_size: windows.LARGE_INTEGER = @intCast(aligned_new_len);
16403 switch (windows.ntdll.NtMapViewOfSection(16407 switch (windows.ntdll.NtExtendSection(section, &new_section_size)) {
16404 section,16408 .SUCCESS => {},
16405 windows.current_process,16409 else => |status| return windows.unexpectedStatus(status),
16406 @ptrCast(&contents_ptr),16410 }
16407 null,16411 assert(new_section_size == aligned_new_len);
16408 0,16412 mm.memory.len = new_len;
16409 null,16413 } else {
16410 &contents_len,16414 _ = windows.ntdll.NtUnmapViewOfSection(windows.current_process, old_memory.ptr);
16411 .Unmap,16415 windows.CloseHandle(section);
16412 .{},16416 var contents_len = aligned_new_len;
16413 .{ .READWRITE = true },16417 var contents_ptr: ?[*]align(std.heap.page_size_min) u8 = null;
16414 )) {16418 switch (windows.ntdll.NtMapViewOfSection(
16415 .SUCCESS => {},16419 section,
16416 .SECTION_PROTECTION => return error.PermissionDenied,16420 windows.current_process,
16417 else => |status| return windows.unexpectedStatus(status),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 .wasi => unreachable,16439 .wasi => unreachable,
16423 .linux => {16440 .linux => {
lib/std/os/windows/ntdll.zig+5
...@@ -253,6 +253,11 @@ pub extern "ntdll" fn NtCreateSection(...@@ -253,6 +253,11 @@ pub extern "ntdll" fn NtCreateSection(
253 FileHandle: ?HANDLE,253 FileHandle: ?HANDLE,
254) callconv(.winapi) NTSTATUS;254) callconv(.winapi) NTSTATUS;
255255
256pub extern "ntdll" fn NtExtendSection(
257 SectionHandle: HANDLE,
258 NewSectionSize: *LARGE_INTEGER,
259) callconv(.winapi) NTSTATUS;
260
256pub extern "ntdll" fn NtAllocateVirtualMemory(261pub extern "ntdll" fn NtAllocateVirtualMemory(
257 ProcessHandle: HANDLE,262 ProcessHandle: HANDLE,
258 BaseAddress: *PVOID,263 BaseAddress: *PVOID,