|
12 | 12 | // (0.20) a transfer at an offset neither uses nor moves the file's position, |
13 | 13 | // this program is told the memory it occupies and its peak, and a region is |
14 | 14 | // reserved, backed, written, its backing returned and backed again reading |
15 | | -// zero, and released. |
| 15 | +// zero, and released; (0.21) where the implementation states it, part of an |
| 16 | +// executable region is a file's bytes, read from where the file holds them. |
16 | 17 | // The terminal is not observed here, |
17 | 18 | // because a test run has none; the implementations observe it on a terminal |
18 | 19 | // they make. |
19 | 20 | #include <openkal/env.h> |
| 21 | +#include <openkal/exec.h> |
20 | 22 | #include <openkal/fs.h> |
21 | 23 | #include <openkal/map.h> |
22 | 24 | #include <openkal/memory.h> |
@@ -187,6 +189,27 @@ int main() { |
187 | 189 | } |
188 | 190 | } |
189 | 191 |
|
| 192 | + if ((kal_interfaces() & KAL_IFACE_EXEC) && (kal_exec_props() & KAL_EXEC_PROP_FILE) |
| 193 | + && kal_fs_preopen_count() > 0 && kal_fs_preopen(0, &root, nullptr, 0, nullptr) == kal_ok) { |
| 194 | + const kal_uintptr a = 65536; |
| 195 | + kal_file f{}; |
| 196 | + if (kal_fs_open(root, "okt.x", 5, KAL_OPEN_READ | KAL_OPEN_WRITE | KAL_OPEN_CREATE | KAL_OPEN_TRUNCATE, &f) == kal_ok) { |
| 197 | + static unsigned char block[65536]; |
| 198 | + for (kal_uintptr i = 0; i < a; ++i) block[i] = static_cast<unsigned char>(i * 7 + 1); |
| 199 | + kal_stream_write(kal_fs_stream(f), block, a); |
| 200 | + auto* r = static_cast<unsigned char*>(kal_exec_alloc(a)); |
| 201 | + check(r != nullptr && kal_exec_map_part(r, 0, a, f, 0, 0) == kal_ok, |
| 202 | + "part of an executable region is made a file's bytes"); |
| 203 | + kal_fs_close_file(f); |
| 204 | + if (r) { |
| 205 | + check(r[0] == 1 && r[a - 1] == static_cast<unsigned char>((a - 1) * 7 + 1), |
| 206 | + "and holds them after the file's handle is closed"); |
| 207 | + kal_exec_free(r, a); |
| 208 | + } |
| 209 | + } |
| 210 | + kal_fs_remove(root, "okt.x", 5); |
| 211 | + } |
| 212 | + |
190 | 213 | if (failures == 0) kal_stream_write(kal_stdout(), "openkal: held\n", 14); |
191 | 214 | return failures == 0 ? 0 : 1; |
192 | 215 | } |
0 commit comments