Skip to content

Commit bd8e7e9

Browse files
authored
0.11.0 — openkal 0.12.0 (#24)
* 0.11.0 — openkal 0.12.0 No behaviour changes. The specification's 0.12 additions are prose: clause 11 entry 9 now names what handles-do-not-cross costs a caller composing job control, and the two file-creating operations point at entry 6. This implementation already satisfied both. * Examine whether the disposition was installed ⚠️ The same defect as openkal-macos, and this one SHIPPED --- in 0.11, where this operation was added. The result of installing the disposition was discarded, so an installation that failed would have handed the caller a word that can never change. Found by writing the same code for the other kernel, where the trampoline made the failure mode impossible to overlook. The suite conforms in 181 observations with the change.
1 parent 3872aa4 commit bd8e7e9

2 files changed

Lines changed: 27 additions & 10 deletions

File tree

‎mcpp.toml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
namespace = "mcpplibs"
33
name = "openkal-linux"
4-
version = "0.10.0"
4+
version = "0.11.0"
55
description = "The reference implementation of openkal for Linux, written on the kernel's own system-call interface so that it can be placed beneath a C library as well as above one."
66
license = "Apache-2.0"
77

@@ -18,7 +18,7 @@ authors = ["mcpplibs"]
1818
repo = "https://github.com/mcpplibs/openkal-linux"
1919

2020
[dependencies]
21-
openkal = "0.11.0"
21+
openkal = "0.12.0"
2222

2323
# The package contributes definitions and no modules. The interface it
2424
# implements is declared by the specification package, which this package

‎src/process.cpp‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -486,15 +486,22 @@ void stop_handler(int) {
486486
1 /* FUTEX_WAKE */, 0x7fffffff, 0, 0, 0);
487487
}
488488

489-
void arm_one(int signo) {
489+
// ⚠️ THE RESULT IS EXAMINED, AND IT WAS NOT WHEN THIS SHIPPED IN 0.11. An
490+
// installation that failed would leave a word that can never change, and
491+
// answering the caller with one is `reporting success having done nothing' in
492+
// its exact form: the program asks whether its end has been requested, is told
493+
// no, and goes on being told no after it has been. Found reviewing the same
494+
// code written for the other kernel, where the trampoline made the failure
495+
// mode obvious.
496+
bool arm_one(int signo) {
490497
struct { void* handler; unsigned long flags; void* restorer; unsigned long mask; } act {};
491498
act.handler = reinterpret_cast<void*>(&stop_handler);
492499
#if defined(__x86_64__)
493500
act.flags = sa_restorer_flag;
494501
act.restorer = reinterpret_cast<void*>(&okl_sigreturn_trampoline);
495502
#endif
496-
okl::sys(okl::nr_rt_sigaction, signo,
497-
reinterpret_cast<okl_long>(&act), 0, sizeof act.mask);
503+
return !okl::failed(okl::sys(okl::nr_rt_sigaction, signo,
504+
reinterpret_cast<okl_long>(&act), 0, sizeof act.mask));
498505
}
499506

500507
} // namespace
@@ -504,11 +511,15 @@ void arm_one(int signo) {
504511
// this operation expects --- and it is the only arrangement under which adding
505512
// this operation changes nothing for anyone who does not use it.
506513
const kal_u32* kal_process_stop_requested(void) {
507-
if (!__atomic_exchange_n(&g_stop_armed, 1, __ATOMIC_ACQ_REL)) {
508-
arm_one(15); // SIGTERM
509-
arm_one(2); // SIGINT
514+
// ⚠️ THREE STATES AND NOT TWO: not yet tried, armed, refused. A second
515+
// caller is told what the first found rather than arming again.
516+
int state = __atomic_load_n(&g_stop_armed, __ATOMIC_ACQUIRE);
517+
if (state == 0) {
518+
const bool ok = arm_one(15) && arm_one(2); // SIGTERM, SIGINT
519+
state = ok ? 1 : -1;
520+
__atomic_store_n(&g_stop_armed, state, __ATOMIC_RELEASE);
510521
}
511-
return &g_stop_word;
522+
return state == 1 ? &g_stop_word : nullptr;
512523
}
513524

514525
kal_uintptr kal_process_props(void) {
@@ -517,7 +528,13 @@ kal_uintptr kal_process_props(void) {
517528
| KAL_PROCESS_PROP_CHANNEL | KAL_PROCESS_PROP_GRANT_DIR
518529
| KAL_PROCESS_PROP_BOUND_LIFETIME
519530
| KAL_PROCESS_PROP_JOB
520-
| KAL_PROCESS_PROP_STOP_REQUESTED;
531+
// ⚠️ AGREES WITH `kal_process_stop_requested', because the header
532+
// defines null there as the absence this position reports. Read and
533+
// never armed: asking what an implementation can do must not install a
534+
// disposition, so the position is claimed until an installation has
535+
// actually been refused.
536+
| (__atomic_load_n(&g_stop_armed, __ATOMIC_ACQUIRE) == -1
537+
? 0u : KAL_PROCESS_PROP_STOP_REQUESTED);
521538
}
522539

523540
}

0 commit comments

Comments
 (0)