You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2b93aab
Browse filesBrowse the repository at this point in the historyBrowse files
0.4.0: a platform question for a native build and an image alike; the platform modules in an image
can_run_on(p) and on<P>(f) beside is_<platform>; R5 revised: a platform module is defined where it
can be answered, a native build of its platform and an image that asks the system it runs upon
(translator, elevated, on_dev_drive, effective_user; translated is false). tests/facts_test runs the
questions on every row, natively and as images.
Co-authored-by: speak-agent <248744407+speak-agent@users.noreply.github.com>
Copy file name to clipboardExpand all lines: README.md
+48-7Lines changed: 48 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ with compile-time platform constants and a few platform modules.
6
6
7
7
```toml
8
8
[dependencies]
9
-
os = { namespace = "mcpplibs", version = "0.3.1" }
9
+
mcpplibs.os = "0.4.0"
10
10
```
11
11
12
12
```cpp
@@ -106,7 +106,7 @@ dropped (0.2.8).
106
106
107
107
| Module | Contents |
108
108
|---|---|
109
-
| `mcpplibs.os.platform` | `PLATFORM`, `ARCH`, `is_linux` / `is_macos` / `is_windows` / `is_posix` / `is_emscripten`, `exe_suffix`, `path_list_separator`; `host()`, a constant expression on a native target |
109
+
| `mcpplibs.os.platform` | `PLATFORM`, `ARCH`, `is_linux` / `is_macos` / `is_windows` / `is_posix` / `is_emscripten`, `exe_suffix`, `path_list_separator`; `host()`, a constant expression on a native target; `can_run_on(p)` and `on<P>(f)`, a platform question that holds in a native build and an image alike |
110
110
| `mcpplibs.os.error` | `errc` (openkal's closed set of conditions), `error`, `result<T>` |
111
111
| `mcpplibs.os.env` | variables (names without case on Windows), `NAME=value` entries as overrides (`assignments`), arguments, the program's own image, lists of directories in the host's separator (`split_list`, `join_list`), PATH search with PATHEXT |
112
112
| `mcpplibs.os.fs` | `write_atomic`, `publish` (no replace), `append`, `sync`, `caps`, `lock`, links, `set_executable`, `stamp_of`, `identity_of`, `owner_of`, `writable`, `locate`, `absolute`, `names_a_place`, `canonical`, a bounded `read`; what a volume does, measured (`measure`, `volume_type`), and the operations that follow it (`place`, `exchange`); names in the host's rules without the file system: `generic`, `native`, `extended`, `is_absolute`, `same`, `within` |
@@ -120,7 +120,7 @@ dropped (0.2.8).
120
120
| `mcpplibs.os.machine` | the machine's architecture (through Rosetta and WoW64), memory and the memory available now, processors (logical, physical, of differing speed) |
121
121
| `mcpplibs.os.random` | bytes from the system's source of unpredictable bytes; `hex` |
122
122
| `mcpplibs.os.library` | shared libraries at run time: `open` (a path or a name the system searches for), `loaded` (one the process has, without loading it), a handle's `symbol` / `function<F>`, `process_symbol` (as the loader resolves one), `suffix` |
123
-
| `mcpplibs.os.linux` / `.macos` / `.windows` / `.posix` | platform modules: declared on every target, defined only on their own |
123
+
| `mcpplibs.os.linux` / `.macos` / `.windows` / `.posix` | platform modules: declared on every target, defined on their own and, where an image can answer, in an image |
124
124
125
125
## Rules
126
126
@@ -133,9 +133,10 @@ dropped (0.2.8).
133
133
- in an image (`<arch>-openkal`) it is an ordinary function, and using it in a constant
134
134
expression is a compile error.
135
135
- **R4.** A native handle does not appear in a portable type.
136
-
- **R5.** A platform module is declared on every target and defined only on its own. A call
137
-
outside `if constexpr` for that platform is a link error. The same call in a discarded branch
138
-
is not an odr-use, so it links. CI asserts both.
136
+
- **R5.** A platform module is declared on every target and defined where it can be answered: in
137
+
a native build of its own platform, and in an image where the image can ask the system it runs
138
+
upon (0.4.0). Elsewhere a call outside `if constexpr` is a link error. The same call in a
139
+
discarded branch is not an odr-use, so it links. CI asserts both.
139
140
- **R6.** Where openkal is not in its shared form, this package's resources do not cross a
140
141
shared-object boundary.
141
142
- **R7.** A name reaches the system as UTF-8 and comes back as UTF-8 on every host, never
@@ -145,11 +146,51 @@ dropped (0.2.8).
145
146
nothing else. The tests write, read and rename names in four scripts.
146
147
147
148
Interface units import `std` and contain no system header and no macro. Implementation units
148
-
on openkal import only `openkal.*`. The Windows and macOS units declare the functions they
149
+
on openkal import only `openkal.*` and this package's own modules. The Windows and macOS units declare the functions they
149
150
call themselves (`src/windows/win32.h`, `src/macos/darwin.h`). Linux's and macOS's kernel
150
151
calls are in `src/linux/arch/` and `src/macos/arch/`, which the manifest selects by
151
152
architecture.
152
153
154
+
## A platform question, in a native build and an image
155
+
156
+
Two questions are asked of the platform, and each has its form:
157
+
158
+
| Question | Form | Native build | Image |
159
+
|---|---|---|---|
160
+
| Is this a native build for the platform? | `if constexpr (os::is_windows)` | a constant | `false` |
161
+
| Does this build run on the platform now? | `if constexpr (os::can_run_on(P))` with `if (os::host() == P)`, or `os::on<P>([&](auto) { ... })` | a constant; another system's branch is discarded | known when the image is loaded |
162
+
163
+
The first is right for code that belongs to a native build alone: a console's code page set
164
+
for the C library's narrow functions has no meaning in an image, whose streams okrun carries.
165
+
The second is right for code that is to take effect wherever the program runs, which is what a
166
+
program shipped as an image needs:
167
+
168
+
```cpp
169
+
if constexpr (os::can_run_on(os::platform::windows))
`on<P>` takes the platform as a parameter, so the body is a template and a build that cannot
177
+
run on `P` never instantiates it; a lambda without the parameter is refused, because its body
178
+
would name another system's module on every build. The platform modules in an image:
179
+
180
+
| Function | In an image |
181
+
|---|---|
182
+
|`linux::translator()`|`/proc/self/status`, the tracer's `comm` and the environment, as on Linux |
183
+
|`windows::elevated()`| the integrity level `whoami /groups` lists (SID `S-1-16-12288` or `S-1-16-16384`) |
184
+
|`windows::on_dev_drive()`|`fsutil devdrv query <volume>`; not known when the tool answers in another language or refuses |
185
+
|`posix::effective_user()`|`/proc/self/status` on Linux, `/usr/bin/id -u` on macOS; the largest number when neither answers |
186
+
|`macos::translated()`|`false`: macOS runs images through an aarch64 okrun only |
187
+
|`windows::code_page()`, `console_output_code_page()`, `long_paths_enabled()`, `machine_registry_path()`, `writable_fixed_drive()`, `posix::set_creation_mask()`| not defined: okrun carries an image's streams and names, and the others belong to a native installation |
188
+
189
+
The system's programs are started by absolute name (`%SystemRoot%\System32`, `/usr/bin`), with a
190
+
bound of ten seconds, and each answer is asked once per process. `host()` decides which system's
191
+
question applies, which is that system's convention; whether a program can be started is
192
+
openkal's capability and is answered by the start itself (openkal SPEC clause 30).
193
+
153
194
## As an ok image
154
195
155
196
Built for `<arch>-openkal` (openkal SPEC clause 12), a program over this library
Copy file name to clipboardExpand all lines: mcpp.toml
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
[package]
2
2
namespace = "mcpplibs"
3
3
name = "os"
4
-
version = "0.3.1"
4
+
version = "0.4.0"
5
5
description = "mcpplibs.os: a C++ operating-system library over openkal --- processes, files, environment, terminals, directories and local IPC, with compile-time platform constants and a few platform modules."
0 commit comments