|
15 | 15 | // zero, and released; (0.21) where the implementation states it, part of an |
16 | 16 | // executable region is a file's bytes, read from where the file holds them; |
17 | 17 | // (0.22) the null device beside a stream at one position is refused, and is |
18 | | -// refused as unsupported where the implementation does not state it. |
| 18 | +// refused as unsupported where the implementation does not state it; (0.23) a |
| 19 | +// region at an address, zero; a read-only attenuation; the machine's memory |
| 20 | +// and the resource preference. |
19 | 21 | // The terminal is not observed here, |
20 | 22 | // because a test run has none; the implementations observe it on a terminal |
21 | 23 | // they make. |
@@ -235,6 +237,46 @@ int main() { |
235 | 237 | kal_fs_remove(root, "okt.x", 5); |
236 | 238 | } |
237 | 239 |
|
| 240 | + // 0.23: a region at an address, and a region zero when returned; a |
| 241 | + // directory attenuated read-only refuses a creation beneath it; the |
| 242 | + // machine's memory and this program's resource preference are told. |
| 243 | + if ((kal_interfaces() & KAL_IFACE_EXEC) && (kal_exec_props() & KAL_EXEC_PROP_PLACE)) { |
| 244 | + const kal_uintptr a = 65536; |
| 245 | + void* any = kal_exec_alloc(a); |
| 246 | + if (any) { |
| 247 | + kal_exec_free(any, a); |
| 248 | + auto* r = static_cast<unsigned char*>(kal_exec_alloc_at(any, a)); |
| 249 | + check(r == any, "a region is reserved at the address asked for"); |
| 250 | + check(r && r[0] == 0 && r[a - 1] == 0, "and is zero"); |
| 251 | + if (r) { |
| 252 | + check(kal_exec_alloc_at(r, a) == nullptr, "an address already held is refused"); |
| 253 | + kal_exec_free(r, a); |
| 254 | + } |
| 255 | + } |
| 256 | + } |
| 257 | + if (kal_fs_preopen_count() > 0 && kal_fs_preopen(0, &root, nullptr, 0, nullptr) == kal_ok |
| 258 | + && (kal_fs_props(root) & KAL_FS_PROP_ATTENUATE)) { |
| 259 | + kal_dir_rights rights{}; |
| 260 | + rights.self_size = sizeof rights; |
| 261 | + rights.flags = KAL_DIR_READ_ONLY; |
| 262 | + kal_dir ro{}; |
| 263 | + check(kal_fs_dir_attenuate(root, &rights, &ro) == kal_ok, "a directory is attenuated read-only"); |
| 264 | + kal_file f{}; |
| 265 | + check(kal_fs_open(ro, "okt.ro", 6, KAL_OPEN_WRITE | KAL_OPEN_CREATE, &f) != kal_ok, |
| 266 | + "and a creation beneath it is refused"); |
| 267 | + kal_fs_remove(root, "okt.ro", 6); |
| 268 | + kal_fs_close_dir(ro); |
| 269 | + } |
| 270 | + { |
| 271 | + kal_memory_status m{}; |
| 272 | + m.self_size = sizeof m; |
| 273 | + check(kal_memory_info(&m) != kal_ok || !(m.present & KAL_MSTATUS_TOTAL) || m.total_bytes > 0, |
| 274 | + "the machine's memory is told where it is stated"); |
| 275 | + const int pref = kal_env_resources(); |
| 276 | + check(pref == KAL_RESOURCES_BALANCED || pref == KAL_RESOURCES_PERFORMANCE || pref == KAL_RESOURCES_ECONOMY, |
| 277 | + "and the resource preference is one of three"); |
| 278 | + } |
| 279 | + |
238 | 280 | if (failures == 0) kal_stream_write(kal_stdout(), "openkal: held\n", 14); |
239 | 281 | return failures == 0 ? 0 : 1; |
240 | 282 | } |
0 commit comments