Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,17 @@ reference can be made (clause 7.18, entry 65). No declaration changes. Both are
requirements upon every implementation, so the minor version advances (clause
8), and the suite observes each.

## Version 0.26.1

A preference about cost that a start does not state is inherited through the
environment the caller gives: a caller that passes its own environment on passes
its preference with it, and one that composes an environment gives the program
that environment with no preference written beside it (clause 7.17, entry 66). Three implementations wrote
their own process's preference into every start and removed a variable of that
name the caller gave; they now leave the environment of such a start as it was
given. No declaration changes. The suite observes a start that composes its
environment.

## How a program uses openkal

A program declares two dependencies. The first fixes the version of the contract
Expand Down
28 changes: 26 additions & 2 deletions SPEC.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# openkal Specification, version 0.26.0
# openkal Specification, version 0.26.1

## 1. Scope

Expand Down Expand Up @@ -1125,7 +1125,14 @@ each program that ended normally (`fs.h`). Clause 11, entry 53.
A program's resource preference --- balanced, performance (memory and storage
spent for time) or economy (time spent for memory and storage) --- is stated by
the program's caller (`KAL_SPAWN_RESOURCES_*`), inherited where nothing is
stated, and read with `kal_env_resources`. No operation of this specification
stated, and read with `kal_env_resources`. A preference is inherited through the
environment the caller gives: where a start states none, the started program has
the one that environment carries, which is the caller's when the caller passes
its own environment on, and the default when the caller composes an environment
that carries none. An implementation writes a preference into a started
program's environment only for a start that states one, and leaves the
environment of a start that states none as it was given (version 0.26.1, clause
11, entry 66). No operation of this specification
answers otherwise for it: each layer of the program, and the implementation,
chooses within itself where it trades one resource for another, and the
environment applies its own policy for memory where it has one. A balanced
Expand Down Expand Up @@ -2294,6 +2301,23 @@ The following are recorded so that they are not mistaken for oversights.
exactly, the answers are those of the table in 7.18, and the property is
claimed only where a reference can be made. No declaration changes.

66. **How a preference not stated is inherited.** **Clarified in 0.26.1**, in
clause 7.17 and the comment of the preference flags. The text said that a
program started without a preference has its caller's, and did not say
through what. Five implementations left the environment a caller gave as it
was, so the program reached the preference through it; three removed a
variable of that name the caller gave and wrote their own process's
preference where it was not the default. Under the second reading no start
gave a program exactly the environment it was given: a program of the
environment that is not an openkal program --- a compiler, a shell ---
received a variable its caller had not written, and a caller that composed
an environment could not start a program with the default. The two readings
agree where a caller passes its own environment on, and that is all the
suite observed. The preference is the one the given environment carries;
the three implementations follow the five in their patch releases, and the
suite observes a start that composes its environment. No declaration
changes.

## 12. Images

A program written against this specification is built for an environment: its
Expand Down
6 changes: 4 additions & 2 deletions include/openkal/process.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,10 @@ struct kal_spawn {

/* THE RESOURCE PREFERENCE of the started program (version 0.23): balanced,
* space spent for time (performance), or time spent for space (economy). None
* of the three, and the started program has the caller's; more than one is
* kal_err_invalid. The program reads it with kal_env_resources (env.h), and
* of the three, and the started program has the one the environment it is
* given carries --- the caller's, when the caller passes its own environment on;
* the implementation writes none and removes none (version 0.26.1, clause 7.17).
* More than one is kal_err_invalid. The program reads it with kal_env_resources (env.h), and
* each layer acts on it within itself: a loader's caches, a C library's
* allocator, an implementation's caches and the environment's memory policy.
* A request about cost and not about meaning: no operation answers otherwise
Expand Down
2 changes: 1 addition & 1 deletion include/openkal/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
* consumer actually asks for was checked by nobody. */
#define KAL_VERSION_MAJOR 0u
#define KAL_VERSION_MINOR 26u
#define KAL_VERSION_PATCH 0u
#define KAL_VERSION_PATCH 1u

#define KAL_VERSION_MAKE(major, minor, patch) \
(((kal_u64)(major) << 32) | ((kal_u64)(minor) << 16) | \
Expand Down
2 changes: 1 addition & 1 deletion mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal"
version = "0.26.0"
version = "0.26.1"
description = "openkal: a portable kernel ABI specification. This package carries the normative declarations; implementations are separate packages."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down
2 changes: 1 addition & 1 deletion tests/cts/mcpp.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
namespace = "mcpplibs"
name = "openkal-conformance"
version = "0.11.0"
version = "0.11.1"
description = "The behavioural half of clause 9: a suite an implementation of openkal runs against itself, selectable to the interfaces it provides."
license = "Apache-2.0"
authors = ["mcpplibs"]
Expand Down
83 changes: 83 additions & 0 deletions tests/cts/src/sections/child.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const char* argument_for(errand e) {
case errand::write_in_first_grant: return "--child-write-in-first-grant";
case errand::count_vectors: return "--child-count-vectors";
case errand::declare_unit: return "--child-declare-unit";
case errand::report_given: return "--child-report-given";
case errand::relay_composed: return "--child-relay-composed";
case errand::relay_own: return "--child-relay-own";
case errand::none: break;
}
return "";
Expand Down Expand Up @@ -78,6 +81,9 @@ errand child_errand() {
if (same(a, len, argument_for(errand::write_in_first_grant))) return errand::write_in_first_grant;
if (same(a, len, argument_for(errand::count_vectors))) return errand::count_vectors;
if (same(a, len, argument_for(errand::declare_unit))) return errand::declare_unit;
if (same(a, len, argument_for(errand::report_given))) return errand::report_given;
if (same(a, len, argument_for(errand::relay_composed))) return errand::relay_composed;
if (same(a, len, argument_for(errand::relay_own))) return errand::relay_own;
// The errand is the second element; what follows it under
// `count_vectors' is two thousand elements that name none.
break;
Expand Down Expand Up @@ -299,6 +305,69 @@ after g_after;
}
#endif
kal_exit(72);
case errand::report_given:
#ifdef MCPP_FEATURE_ENV
{
// What this copy was given is one variable. An environment may
// add variables of its own to every program it starts (wine
// adds its configuration and SystemRoot), so what is observed is
// that the given one arrived and that no preference was written.
char value[16];
const kal_intptr v = kal_env_var("OKC_E", 5, value, sizeof value);
const bool given = v == 1 && value[0] == '1';
kal_exit(110 + kal_env_resources() + (given ? 0 : 10));
}
#endif
kal_exit(129);
case errand::relay_composed:
#if defined(MCPP_FEATURE_ENV) && defined(MCPP_FEATURE_PROCESS)
{
const char* argv[2] = { "openkal-conformance-child", argument_for(errand::report_given) };
kal_uintptr lens[2] = { 25, 0 };
while (argv[1][lens[1]]) ++lens[1];
const char* env[1] = { "OKC_E=1" };
const kal_uintptr env_lens[1] = { 7 };
int spawned = -1, status = -1, terminated = -1;
if (start_copy_given(argv, lens, 2, env, env_lens, 1, spawned, status, terminated)
&& spawned == kal_ok && terminated == 0)
kal_exit(status);
}
#endif
kal_exit(129);
case errand::relay_own:
#if defined(MCPP_FEATURE_ENV) && defined(MCPP_FEATURE_PROCESS)
{
// Its own environment, composed entry by entry as a caller that
// passes its environment on composes it (process.h).
static char storage[65536];
static const char* env[512];
static kal_uintptr env_lens[512];
kal_uintptr count = 0, used = 0;
for (kal_uintptr i = 0; i < kal_env_var_count() && count < 512; ++i) {
char name[256];
const kal_intptr n = kal_env_var_at(i, name, sizeof name);
if (n <= 0 || static_cast<kal_uintptr>(n) >= sizeof name) continue;
const kal_intptr v = kal_env_var(name, static_cast<kal_uintptr>(n), nullptr, 0);
if (v < 0 || used + static_cast<kal_uintptr>(n + 1 + v) > sizeof storage) continue;
char* entry = storage + used;
for (kal_intptr k = 0; k < n; ++k) entry[k] = name[k];
entry[n] = '=';
kal_env_var(name, static_cast<kal_uintptr>(n), entry + n + 1, static_cast<kal_uintptr>(v));
env[count] = entry;
env_lens[count] = static_cast<kal_uintptr>(n + 1 + v);
used += env_lens[count];
++count;
}
const char* argv[2] = { "openkal-conformance-child", argument_for(errand::report_resources) };
kal_uintptr lens[2] = { 25, 0 };
while (argv[1][lens[1]]) ++lens[1];
int spawned = -1, status = -1, terminated = -1;
if (start_copy_given(argv, lens, 2, env, env_lens, count, spawned, status, terminated)
&& spawned == kal_ok && terminated == 0)
kal_exit(status);
}
#endif
kal_exit(139);
case errand::count_vectors:
#ifdef MCPP_FEATURE_ENV
{
Expand Down Expand Up @@ -397,6 +466,20 @@ bool locate_self(kal_dir& base, const char*& relative, kal_uintptr& relative_len
? (len = static_cast<kal_uintptr>(a0len), a0) : nullptr;
if (!argv0 || len == 0) return false;

// A copy is started with a bare name as its first element, which locates
// nothing; the image's name, as the environment resolved it, locates the
// copy that starts another copy (0.26.1, `relay_composed', `relay_own').
bool bare = true;
for (kal_uintptr i = 0; i < len; ++i) if (is_separator(argv0[i])) { bare = false; break; }
if (bare) {
static char image[1024];
const kal_intptr ilen = kal_env_image(image, sizeof image);
if (ilen > 0 && static_cast<kal_uintptr>(ilen) < sizeof image) {
argv0 = image;
len = static_cast<kal_uintptr>(ilen);
}
}

kal_uintptr best = 0, best_len = 0;
bool found = false;
for (kal_uintptr i = 0; i < kal_fs_preopen_count(); ++i) {
Expand Down
8 changes: 8 additions & 0 deletions tests/cts/src/sections/child.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ enum class errand {
// value, 4 for an argument of `vector_long' bytes (0.26)
declare_unit, // declares its own unit: 80 a reference was made, 81
// kal_err_not_supported, 82 anything else (0.26)
report_given, // ends with 110 + kal_env_resources(), plus 10 when its
// environment lacks `OKC_E=1' (0.26.1)
relay_composed, // starts a copy for `report_given' with no preference and
// the environment `OKC_E=1', and ends with its status;
// 129 when it could not start one (0.26.1)
relay_own, // starts a copy for `report_resources' with no preference
// and its own environment, and ends with its status; 139
// when it could not start one (0.26.1)
};

// What the copy counts under `count_vectors' (clause 7.6): the number of
Expand Down
21 changes: 19 additions & 2 deletions tests/cts/src/sections/process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -754,8 +754,25 @@ void run() {
"a program started for performance reads performance");
observe(kind::behaviour, reported(kal::process::balanced_flag.bits, spawned) == 0,
"a program started balanced reads balanced");
observe(kind::behaviour, reported(0, spawned) == kal_env_resources(),
"a program started without a preference has its caller's");
observe(kind::behaviour, reported(0, spawned) == 0,
"a program started without a preference and given no environment reads the default");
// INHERITED THROUGH THE GIVEN ENVIRONMENT (0.26.1, clause 7.17): a copy
// started for economy starts another without a preference. Given its own
// environment, that one reads economy; given one it composed, it reads
// the default and the variables it was given.
{
int status = -1, terminated = -1;
spawned = -1;
const bool own = start_copy_with(argument_for(errand::relay_own),
kal::process::economy_flag.bits, inherit, spawned, status, terminated);
observe(kind::behaviour, own && spawned == kal_ok && terminated == 0 && status == 42,
"a program started without a preference and given its caller's environment has its caller's");
spawned = -1;
const bool composed = start_copy_with(argument_for(errand::relay_composed),
kal::process::economy_flag.bits, inherit, spawned, status, terminated);
observe(kind::behaviour, composed && spawned == kal_ok && terminated == 0 && status == 110,
"a program started without a preference and given a composed environment reads the default and the variables given");
}
reported((kal::process::economy_flag | kal::process::performance_flag).bits, spawned);
observe(kind::behaviour, spawned == kal_err_invalid, "two preferences at once are refused");
}
Expand Down
Loading