Commit 2fca7ae
authored
fix(whp): map file-backed sections to end-of-section in surrogate (hyperlight-dev#1388)
Windows CreateFileMappingW with a read-only file handle caps the section
size at the file's actual size on disk (requesting max_size > file_size
fails with ERROR_NOT_ENOUGH_MEMORY). For files whose size is not a
multiple of the page size, the surrogate's MapViewOfFileNuma2 call was
passing a page-aligned host_size that exceeded the section, failing
with ERROR_ACCESS_DENIED — the map_file_cow zero-copy path was broken
for any non-page-aligned file.
Pass NumberOfBytesToMap=0 for ReadOnlyFile mappings so Windows maps the
section to its end. MapViewOfFile always returns a view whose region is
rounded up to a page boundary, and the OS zero-fills the tail of the
final page — matching POSIX mmap semantics. SandboxMemory sections are
always created with an explicit page-aligned size and still need the
exact host_size so the guard-page bookkeeping below lines up, so keep
host_size for that case.
The map-file-cow-test example now covers an intentionally 8193-byte
file to exercise the unaligned path.
Signed-off-by: danbugs <danilochiarlone@gmail.com>1 parent 2b803de commit 2fca7ae
2 files changed
Lines changed: 48 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
| 25 | + | |
| 26 | + | |
24 | 27 | | |
25 | 28 | | |
26 | 29 | | |
| |||
31 | 34 | | |
32 | 35 | | |
33 | 36 | | |
34 | | - | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
38 | 41 | | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | 42 | | |
44 | 43 | | |
45 | 44 | | |
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
49 | | - | |
| 48 | + | |
50 | 49 | | |
51 | | - | |
52 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
56 | 74 | | |
57 | | - | |
58 | | - | |
| 75 | + | |
| 76 | + | |
59 | 77 | | |
60 | | - | |
| 78 | + | |
| 79 | + | |
61 | 80 | | |
62 | 81 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
103 | 103 | | |
104 | 104 | | |
105 | 105 | | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
106 | 121 | | |
107 | 122 | | |
108 | 123 | | |
109 | 124 | | |
110 | 125 | | |
111 | 126 | | |
112 | | - | |
| 127 | + | |
113 | 128 | | |
114 | 129 | | |
115 | 130 | | |
| |||
0 commit comments