interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / evidence / freest-leftovers-20261106 / coverage.log

588 lines · 28946 bytes Raw Blame History
1$ bwrap --dev-bind / / --dev /dev --proc /proc -- taskset -c 10-14 nice -n 10 make test-leftovers-coverage
2rm -f build/leftovers/coverage/*.gcda
3cc -std=gnu11 -Wall -Wextra -Werror -MMD -MP -D_GNU_SOURCE -O2 -Isrc -I./m16 -I./nvrm -I./third_party/nvidia-open-580.173.02/src/common/sdk/nvidia/inc -I./third_party/nvidia-open-580.173.02/kernel-open/common/inc -I./third_party/nvidia-open-580.173.02/kernel-open/nvidia-uvm -I./third_party/nvidia-open-580.173.02/src/nvidia/arch/nvalloc/unix/include -I./third_party/aien-gpu-abi1 -DCUDAPP_MIGRATION_PENDING_GEMM_EX=1 -O0 --coverage -DLEFTOVERS_ORACLE -Isrc -o build/leftovers/coverage/diff tests/leftovers_test.c src/cudapp_freest_leftovers.c
4build/leftovers/coverage/diff
5LEFTOVERS PASS checks=3230
6gcov -b -c -t build/leftovers/coverage/diff-leftovers_test.gcno
7 -: 0:Source:tests/leftovers_test.c
8 -: 0:Graph:build/leftovers/coverage/diff-leftovers_test.gcno
9 -: 0:Data:build/leftovers/coverage/diff-leftovers_test.gcda
10 -: 0:Runs:1
11 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
12 -: 2:#include <stdint.h>
13 -: 3:#include <stdio.h>
14 -: 4:#include <string.h>
15 -: 5:#include <limits.h>
16 -: 6:#define CUDAPP_MIGRATION_PENDING_LEFTOVERS 1
17 -: 7:#define omega_path_byte oracle_path_byte
18 -: 8:#define omega_path_copy oracle_path_copy
19 -: 9:#include "omega_path_check.h"
20 -: 10:#undef omega_path_byte
21 -: 11:#undef omega_path_copy
22 -: 12:#undef CUDAPP_MIGRATION_PENDING_LEFTOVERS
23 -: 13:#undef OMEGA_PATH_CHECK_H
24 -: 14:#include "omega_path_check.h"
25 -: 15:#ifdef LEFTOVERS_ORACLE
26 -: 16:#define CUDAPP_MIGRATION_PENDING_LEFTOVERS 1
27 -: 17:#endif
28 -: 18:#include "omega_numeric_lifecycle.h"
29 -: 19:#include "omega_gpu_q36_native.h"
30 -: 20:#ifdef LEFTOVERS_ORACLE
31 -: 21:#undef CUDAPP_MIGRATION_PENDING_LEFTOVERS
32 -: 22:#endif
33 -: 23:atomic_int omega_numeric_native_state;
34 -: 24:static unsigned checks;
35 -: 25:#define CHECK(x) do { ++checks; if (!(x)) { fprintf(stderr,"FAIL line %d\n",__LINE__); return 1; } } while (0)
36function path called 882 returned 100% blocks executed 67%
37 882: 26:static int path(const char *s, size_t cap) {
38 882: 27: char a[64], b[64]; memset(a, 85, sizeof a); memset(b, 85, sizeof b);
39 882: 28: int ar = oracle_path_copy(a, cap, s), br = omega_path_copy(b, cap, s);
40call 0 returned 882
41call 1 returned 882
42 -: 29:#ifdef LEFTOVERS_RED
43 -: 30: br ^= 1;
44 -: 31:#endif
45 882*: 32: CHECK(ar == br);
46branch 0 taken 0 (fallthrough)
47branch 1 taken 882
48call 2 never executed
49 -: 33: /* Refusals promise an empty string, not equality of scratch bytes. */
50 882*: 34: CHECK(cap == 0 || strcmp(a, b) == 0);
51branch 0 taken 863 (fallthrough)
52branch 1 taken 19
53branch 2 taken 0 (fallthrough)
54branch 3 taken 863
55call 4 never executed
56 882: 35: return 0;
57 -: 36:}
58function main called 1 returned 100% blocks executed 70%
59 1: 37:int main(void) {
60 1: 38: const char *cases[] = {NULL,"","/",".","..","...","a/../b","../","a/..","a/./b","a//b/","/..","/a/b","a b","a\nb","AZaz09._-/+,=@:~","..a","a..","a/.../b"};
61 20: 39: for (size_t i=0;i<sizeof cases/sizeof *cases;++i)
62branch 0 taken 19
63branch 1 taken 1 (fallthrough)
64 646*: 40: for (size_t cap=0;cap<=32;++cap) CHECK(path(cases[i],cap)==0);
65call 0 returned 627
66branch 1 taken 0 (fallthrough)
67branch 2 taken 627
68call 3 never executed
69branch 4 taken 627
70branch 5 taken 19 (fallthrough)
71 1*: 41: CHECK(omega_path_copy(NULL, 1, "a") == -1);
72call 0 returned 1
73branch 1 taken 0 (fallthrough)
74branch 2 taken 1
75call 3 never executed
76 1*: 42: CHECK(oracle_path_copy(NULL, 1, "a") == -1);
77call 0 returned 1
78branch 1 taken 0 (fallthrough)
79branch 2 taken 1
80call 3 never executed
81 259*: 43: for (int c=-1;c<=256;++c) CHECK(oracle_path_byte(c)==omega_path_byte(c));
82call 0 returned 258
83call 1 returned 258
84branch 2 taken 0 (fallthrough)
85branch 3 taken 258
86call 4 never executed
87branch 5 taken 258
88branch 6 taken 1 (fallthrough)
89 1: 44: char s[3]={0,'x',0};
90 256*: 45: for (unsigned c=1;c<=255;++c) { s[0]=(char)c; CHECK(path(s,3)==0); }
91call 0 returned 255
92branch 1 taken 0 (fallthrough)
93branch 2 taken 255
94call 3 never executed
95branch 4 taken 255
96branch 5 taken 1 (fallthrough)
97 1: 46: uint64_t r=99;
98 1*: 47: CHECK(omega_leftovers(NULL, 0, 0, 0, 0, 0)==OMEGA_BAD_ARG);
99call 0 returned 1
100branch 1 taken 0 (fallthrough)
101branch 2 taken 1
102call 3 never executed
103 1*: 48: CHECK(omega_leftovers(&r,1,0,'a',UINT64_MAX,UINT64_MAX)==0 && r==4);
104call 0 returned 1
105branch 1 taken 1 (fallthrough)
106branch 2 taken 0
107branch 3 taken 0 (fallthrough)
108branch 4 taken 1
109call 5 never executed
110 1*: 49: CHECK(omega_leftovers(&r,1,0,'a',UINT32_MAX,UINT32_MAX)==0 && r==4);
111call 0 returned 1
112branch 1 taken 1 (fallthrough)
113branch 2 taken 0
114branch 3 taken 0 (fallthrough)
115branch 4 taken 1
116call 5 never executed
117 1: 50: const int ord[]={INT_MIN,-1,0,1,INT_MAX};
118 6: 51: for (unsigned i=0;i<sizeof ord/sizeof *ord;++i) {
119branch 0 taken 5
120branch 1 taken 1 (fallthrough)
121 5*: 52: CHECK(omega_leftovers(&r,2,(uint64_t)(int64_t)ord[i],0,0,0)==0);
122call 0 returned 5
123branch 1 taken 0 (fallthrough)
124branch 2 taken 5
125call 3 never executed
126 5*: 53: CHECK(r==(ord[i]<0?(uint64_t)(int64_t)ord[i]:0));
127branch 0 taken 0 (fallthrough)
128branch 1 taken 5
129call 2 never executed
130 5*: 54: CHECK(omega_q36_native_record_status(ord[i])==(ord[i]<0?ord[i]:0));
131call 0 returned 5
132branch 1 taken 0 (fallthrough)
133branch 2 taken 5
134call 3 never executed
135 -: 55: }
136 5: 56: for (unsigned st=0;st<4;++st) {
137branch 0 taken 4
138branch 1 taken 1 (fallthrough)
139 4: 57: atomic_store(&omega_numeric_native_state,st);
140 4*: 58: CHECK(omega_numeric_native_uncertain()==(st==2));
141call 0 returned 4
142branch 1 taken 0 (fallthrough)
143branch 2 taken 4
144call 3 never executed
145 4*: 59: CHECK(omega_numeric_native_acquire()==(st==0?0:-1));
146call 0 returned 4
147branch 1 taken 1 (fallthrough)
148branch 2 taken 3
149branch 3 taken 0 (fallthrough)
150branch 4 taken 4
151call 5 never executed
152 4*: 60: CHECK(atomic_load(&omega_numeric_native_state)==(st==0?1:(int)st));
153branch 0 taken 3 (fallthrough)
154branch 1 taken 1
155branch 2 taken 0 (fallthrough)
156branch 3 taken 4
157call 4 never executed
158 4: 61: omega_numeric_native_release();
159call 0 returned 4
160 4*: 62: CHECK(atomic_load(&omega_numeric_native_state)==(st<=1?0:(int)st));
161branch 0 taken 2 (fallthrough)
162branch 1 taken 2
163branch 2 taken 0 (fallthrough)
164branch 3 taken 4
165call 4 never executed
166 4: 63: omega_numeric_native_poison(); omega_numeric_native_release();
167call 0 returned 4
168call 1 returned 4
169 4*: 64: CHECK(omega_numeric_native_uncertain());
170call 0 returned 4
171branch 1 taken 0 (fallthrough)
172branch 2 taken 4
173call 3 never executed
174 -: 65: }
175 1: 66: const uint64_t values[]={0,1,31,32,33,UINT32_MAX-1ULL,UINT32_MAX,UINT32_MAX+1ULL,INT64_MAX,1ULL<<63,UINT64_MAX};
176 12: 67: for (unsigned i=0;i<sizeof values/sizeof *values;++i) {
177branch 0 taken 11
178branch 1 taken 1 (fallthrough)
179 33: 68: for (unsigned p=0;p<2;++p) {
180branch 0 taken 22
181branch 1 taken 11 (fallthrough)
182 22*: 69: CHECK(omega_leftovers(&r,5,values[i],p,0,0)==0);
183call 0 returned 22
184branch 1 taken 0 (fallthrough)
185branch 2 taken 22
186call 3 never executed
187 22*: 70: CHECK(r==(values[i]==0?1:(values[i]>>63||!p?UINT64_MAX:0)));
188branch 0 taken 20 (fallthrough)
189branch 1 taken 2
190branch 2 taken 16 (fallthrough)
191branch 3 taken 4
192branch 4 taken 8 (fallthrough)
193branch 5 taken 8
194branch 6 taken 0 (fallthrough)
195branch 7 taken 22
196call 8 never executed
197 -: 71: }
198 132: 72: for (unsigned j=0;j<sizeof values/sizeof *values;++j) {
199branch 0 taken 121
200branch 1 taken 11 (fallthrough)
201 121*: 73: CHECK(omega_leftovers(&r,6,values[i],values[j],0,0)==0);
202call 0 returned 121
203branch 1 taken 0 (fallthrough)
204branch 2 taken 121
205call 3 never executed
206 121*: 74: CHECK(r==(values[j]<values[i] && values[j]<32));
207branch 0 taken 55 (fallthrough)
208branch 1 taken 66
209branch 2 taken 27 (fallthrough)
210branch 3 taken 28
211branch 4 taken 0 (fallthrough)
212branch 5 taken 121
213call 6 never executed
214 -: 75: }
215 -: 76: }
216 1: 77: printf("LEFTOVERS PASS checks=%u\n",checks);
217call 0 returned 1
218 1: 78: return 0;
219 -: 79:}
220 -: 0:Source:src/omega_gpu_q36_native.h
221 -: 0:Graph:build/leftovers/coverage/diff-leftovers_test.gcno
222 -: 0:Data:build/leftovers/coverage/diff-leftovers_test.gcda
223 -: 0:Runs:1
224 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception */
225 -: 2:#ifndef OMEGA_GPU_Q36_NATIVE_H
226 -: 3:#define OMEGA_GPU_Q36_NATIVE_H
227 -: 4:#include "omega_gpu_native_runtime.h"
228 -: 5:#include "omega_gpu_cmdlist_native.h"
229 -: 6:/* Native append returns the successful command-list ordinal, not status zero. */
230function omega_q36_native_record_status called 5 returned 100% blocks executed 100%
231 5: 7:static inline int omega_q36_native_record_status(int ordinal) {
232 -: 8:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
233 5: 9: return ordinal < 0 ? ordinal : 0;
234 -: 10:#else
235 -: 11: uint64_t result = UINT64_MAX;
236 -: 12: (void)omega_leftovers(&result, 2, (uint64_t)(int64_t)ordinal, 0, 0, 0);
237 -: 13: return (int)(int64_t)result;
238 -: 14:#endif
239 -: 15:}
240 -: 16:/* Borrowed router-owner facts. The caller holds the session lock and consumes
241 -: 17: * them before recording can replace either cached kernel. Exact encoded bytes
242 -: 18: * exclude the code allocation's prefetch tail. This conveys no admission. */
243 -: 19:struct OmegaGpuRouter;
244 -: 20:typedef struct {
245 -: 21: OmegaGpuMem code, gate, norm, directory, launch_buffer;
246 -: 22: uint64_t code_bytes;
247 -: 23: uint64_t owner_generation, code_generation;
248 -: 24: const uint64_t *gu_directory, *dn_directory;
249 -: 25: uint32_t entries;
250 -: 26:} OmegaGpuQ36RouterObservation;
251 -: 27:int omega_gpu_q36_router_observe(const struct OmegaGpuRouter *, uint32_t layer,
252 -: 28: uint64_t recorded_code_va, OmegaGpuQ36RouterObservation *);
253 -: 29:/* Same mode-final callback in production and the existing typed HOST_ONLY
254 -: 30: * platform oracle. Borrowed exact owner descriptors only, not an admission
255 -: 31: * constructor. ordinal=UINT64_MAX matches every occurrence of that owner;
256 -: 32: * GU/DN use their independently retained successful-add ordinal instead. */
257 -: 33:typedef struct {
258 -: 34: OmegaGpuMem code;
259 -: 35: uint64_t code_bytes, role, ordinal;
260 -: 36:} OmegaGpuQ36MoeCode;
261 -: 37:typedef struct {
262 -: 38: uint64_t context[16];
263 -: 39: OmegaGpuQ36MoeCode code[272]; /* six-role variants plus selected pair windows */
264 -: 40: uint32_t code_count;
265 -: 41: uint8_t nested[2048]; /* only actual groups10..21; cleared before projection */
266 -: 42:} OmegaGpuQ36MoeProjection;
267 -: 43:int omega_gpu_q36_moe_project(const OmegaGpuCmdList *,
268 -: 44: const OmegaGpuCmdListConsumed *, void *projection);
269 -: 45:/* Independently retained source-owner identities, not an expected-wire view.
270 -: 46: * Admission owns this immutable snapshot. No production constructor exists.
271 -: 47: * Live code, launches, directories and allocations replace their groups. */
272 -: 48:typedef struct {
273 -: 49: uint8_t hashes[2048];
274 -: 50:} OmegaGpuQ36NativeProvenance;
275 -: 51:/* Private graph-owned, immutable accepted-record snapshot. No public setter,
276 -: 52: * q-flag constructor, manifest-string activation, or new qualification store.
277 -: 53: * Production construction stays absent until the independent evaluator/judge
278 -: 54: * can supply an exact accepted receipt through the existing admission chain.
279 -: 55: * A NULL state means no qualified native candidate, not a failed incumbent. */
280 -: 56:typedef struct {
281 -: 57: uint64_t query[64], rows[1024];
282 -: 58: uint8_t wanted[4096], records[65536];
283 -: 59: OmegaGpuNativeArtifact artifact[16];
284 -: 60: OmegaGpuNativeLease prepared[16];
285 -: 61: const uint8_t *expected_closure; /* same retained full MC wire for paired GU/DN */
286 -: 62: const OmegaGpuQ36NativeProvenance *provenance;
287 -: 63:} OmegaGpuQ36NativeState;
288 -: 64:/* Private lookup keys identify actual graph operations, never qualification.
289 -: 65: * Each operation/window owns its original immutable selector query and bytes.
290 -: 66: * Paired MoE roles retain the same independently frozen expected closure. */
291 -: 67:typedef struct {
292 -: 68: uint64_t keys[128], count;
293 -: 69: OmegaGpuQ36NativeState *context; /* points inside the graph-owned immutable arena */
294 -: 70:} OmegaGpuQ36NativeGraph;
295 -: 71:static inline int omega_q36_native_context(OmegaGpuQ36NativeGraph *g,
296 -: 72: const uint64_t actual[4], OmegaGpuQ36NativeState **context) {
297 -: 73: uint64_t bits = 0;
298 -: 74: int64_t result;
299 -: 75: *context = NULL;
300 -: 76: if (!g) return 1;
301 -: 77: if (omega_native_context_lookup(&bits, g->keys, 128, g->count, actual, 4) != OMEGA_OK)
302 -: 78: return -1;
303 -: 79: memcpy(&result, &bits, sizeof result);
304 -: 80:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
305 -: 81: if (result == 0) return 1;
306 -: 82: if (result < 0 || !g->context) return -1;
307 -: 83:#else
308 -: 84: uint64_t disposition = UINT64_MAX;
309 -: 85: (void)omega_leftovers(&disposition, 5, bits, g->context != NULL, 0, 0);
310 -: 86: if (disposition != 0) return (int)(int64_t)disposition;
311 -: 87:#endif
312 -: 88: /* The generated unique-match resolver bounds result to 1..count<=32. */
313 -: 89: *context = &g->context[(uint64_t)result - 1];
314 -: 90: return 0;
315 -: 91:}
316 -: 92:static inline int omega_q36_native_begin_selected(OmegaGpuQ36NativeState *s, OmegaGpuNativeCache *cache,
317 -: 93: const OmegaGpuNativeArtifact **artifact, OmegaGpuNativeLease *lease, const uint64_t **row) {
318 -: 94: uint64_t out[32] = {0}, result = 0;
319 -: 95: if (row) *row = NULL;
320 -: 96: if (!s) return 1;
321 -: 97: if (omega_native_graph(&result, s->query, 64, s->rows, 1024, cache->pool, 528,
322 -: 98: s->wanted, 4096, s->records, 65536, out, 32) != OMEGA_OK || result != 0) return -1;
323 -: 99: /* The generated resolver already bounds the immutable ordinal to <16. */
324 -: 100: *artifact = &s->artifact[out[1]];
325 -: 101: *lease = (OmegaGpuNativeLease){cache, out[17], out[18], out[19]};
326 -: 102: /* The returned lease pins the selected exact resident realization. Recording
327 -: 103: * takes its own reference; the temporary selection pin is always released. */
328 -: 104: if (omega_native_bound(*artifact, lease) != 0) {
329 -: 105: (void)omega_native_lease_op(lease, 9, 0);
330 -: 106: *lease = (OmegaGpuNativeLease){0};
331 -: 107: return -1;
332 -: 108: }
333 -: 109: if (row) *row = s->rows + out[1] * 64;
334 -: 110: return 0;
335 -: 111:}
336 -: 112:static inline int omega_q36_native_begin(OmegaGpuQ36NativeState *s, OmegaGpuNativeCache *cache,
337 -: 113: const OmegaGpuNativeArtifact **artifact, OmegaGpuNativeLease *lease) {
338 -: 114: return omega_q36_native_begin_selected(s, cache, artifact, lease, NULL);
339 -: 115:}
340 -: 116:static inline void omega_q36_native_end(const OmegaGpuNativeLease *lease) {
341 -: 117: (void)omega_native_lease_op(lease, 9, 0);
342 -: 118:}
343 -: 119:static inline void omega_q36_native_release(OmegaGpuQ36NativeState *s) {
344 -: 120: if (!s) return;
345 -: 121: for (unsigned i = 0; i < 16; ++i)
346 -: 122: if (s->prepared[i].cache) (void)omega_native_lease_op(&s->prepared[i], 5, 0);
347 -: 123:}
348 -: 124:static inline void omega_q36_native_graph_release(OmegaGpuQ36NativeGraph *g) {
349 -: 125: if (!g || !g->context) return;
350 -: 126:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
351 -: 127: for (uint64_t i = 0; i < g->count && i < 32; ++i)
352 -: 128:#else
353 -: 129: /* Iteration invokes host lease effects; Omega decides the bounded extent. */
354 -: 130: for (uint64_t i = 0, more = 0;
355 -: 131: omega_leftovers(&more, 6, g->count, i, 0, 0) == OMEGA_OK && more; ++i)
356 -: 132:#endif
357 -: 133: omega_q36_native_release(&g->context[i]);
358 -: 134:}
359 -: 135:#endif
360 -: 0:Source:src/omega_numeric_lifecycle.h
361 -: 0:Graph:build/leftovers/coverage/diff-leftovers_test.gcno
362 -: 0:Data:build/leftovers/coverage/diff-leftovers_test.gcda
363 -: 0:Runs:1
364 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
365 -: 2: * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
366 -: 3: *
367 -: 4: * Licensed under the Apache License, Version 2.0 (the "License");
368 -: 5: * you may not use this file except in compliance with the License.
369 -: 6: * You may obtain a copy of the License at
370 -: 7: *
371 -: 8: * http://www.apache.org/licenses/LICENSE-2.0
372 -: 9: *
373 -: 10: * Unless required by applicable law or agreed to in writing, software
374 -: 11: * distributed under the License is distributed on an "AS IS" BASIS,
375 -: 12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
376 -: 13: * See the License for the specific language governing permissions and
377 -: 14: * limitations under the License.
378 -: 15: */
379 -: 16:
380 -: 17:#ifndef OMEGA_NUMERIC_LIFECYCLE_H
381 -: 18:#define OMEGA_NUMERIC_LIFECYCLE_H
382 -: 19:
383 -: 20:#include <stdatomic.h>
384 -: 21:#include "cudapp_native.h"
385 -: 22:
386 -: 23:/* One owner across the SIMT, reduction and DIV/SQRT launchers. Defined in
387 -: 24: * omega_numeric.c, which all three already link. No reset API: an uncertain
388 -: 25: * completion requires ending the process and investigating the device. This
389 -: 26: * does not assert that process exit itself resets or recovers the GPU. */
390 -: 27:enum { OMEGA_NUMERIC_NATIVE_IDLE, OMEGA_NUMERIC_NATIVE_BUSY,
391 -: 28: OMEGA_NUMERIC_NATIVE_UNCERTAIN };
392 -: 29:extern atomic_int omega_numeric_native_state;
393 -: 30:
394function omega_numeric_native_acquire called 4 returned 100% blocks executed 100%
395 4: 31:static inline int omega_numeric_native_acquire(void) {
396 4: 32: int expected = OMEGA_NUMERIC_NATIVE_IDLE;
397 -: 33:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
398 4: 34: return atomic_compare_exchange_strong(&omega_numeric_native_state, &expected,
399 4: 35: OMEGA_NUMERIC_NATIVE_BUSY) ? 0 : -1;
400branch 0 taken 1 (fallthrough)
401branch 1 taken 3
402 -: 36:#else
403 -: 37: uint64_t result = UINT64_MAX;
404 -: 38: unsigned okay = atomic_compare_exchange_strong(&omega_numeric_native_state,
405 -: 39: &expected, OMEGA_NUMERIC_NATIVE_BUSY);
406 -: 40: (void)omega_leftovers(&result, 3, okay, 0, 0, 0);
407 -: 41: return (int)(int64_t)result;
408 -: 42:#endif
409 -: 43:}
410function omega_numeric_native_uncertain called 8 returned 100% blocks executed 100%
411 8: 44:static inline int omega_numeric_native_uncertain(void) {
412 -: 45:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
413 8: 46: return atomic_load(&omega_numeric_native_state) == OMEGA_NUMERIC_NATIVE_UNCERTAIN;
414 -: 47:#else
415 -: 48: uint64_t result = 1;
416 -: 49: (void)omega_leftovers(&result, 4,
417 -: 50: (uint64_t)(int64_t)atomic_load(&omega_numeric_native_state), 0, 0, 0);
418 -: 51: return (int)result;
419 -: 52:#endif
420 -: 53:}
421function omega_numeric_native_poison called 4 returned 100% blocks executed 100%
422 4: 54:static inline void omega_numeric_native_poison(void) {
423 4: 55: atomic_store(&omega_numeric_native_state, OMEGA_NUMERIC_NATIVE_UNCERTAIN);
424 4: 56:}
425function omega_numeric_native_release called 8 returned 100% blocks executed 100%
426 8: 57:static inline void omega_numeric_native_release(void) {
427 8: 58: int expected = OMEGA_NUMERIC_NATIVE_BUSY;
428 -: 59: /* Never clear a poison latch, even if a cleanup caller arrives late. */
429 8: 60: (void)atomic_compare_exchange_strong(&omega_numeric_native_state, &expected,
430 -: 61: OMEGA_NUMERIC_NATIVE_IDLE);
431 8: 62:}
432 -: 63:#endif
433 -: 0:Source:src/omega_path_check.h
434 -: 0:Graph:build/leftovers/coverage/diff-leftovers_test.gcno
435 -: 0:Data:build/leftovers/coverage/diff-leftovers_test.gcda
436 -: 0:Runs:1
437 -: 1:/* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
438 -: 2: * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
439 -: 3: *
440 -: 4: * omega_path_check.h: a checked copy of a file system path that came from outside the program (an
441 -: 5: * environment variable, a command's output, a caller's argument) before anything opens it.
442 -: 6: *
443 -: 7: * A path is accepted only when it is 1..cap-1 bytes long, every byte is in the POSIX portable file name set
444 -: 8: * [A-Za-z0-9._-] or one of / + , = @ : ~ (no space, quote, control, shell or non-ASCII byte), and no
445 -: 9: * component is "..". Absolute and relative paths are both accepted. The accepted path is copied byte by byte
446 -: 10: * through omega_path_byte, so the bytes the caller later opens are exactly the bytes that were checked.
447 -: 11: * A refused path leaves out as the empty string.
448 -: 12: */
449 -: 13:#ifndef OMEGA_PATH_CHECK_H
450 -: 14:#define OMEGA_PATH_CHECK_H
451 -: 15:
452 -: 16:#include <stddef.h>
453 -: 17:#include "cudapp_native.h"
454 -: 18:
455 -: 19:#if defined(CUDAPP_MIGRATION_PENDING_LEFTOVERS) && CUDAPP_MIGRATION_PENDING_LEFTOVERS
456 -: 20:
457 -: 21:/* c when it may appear in a checked path, -1 otherwise */
458function oracle_path_byte called 2619 returned 100% blocks executed 100%
459 2619: 22:static inline int omega_path_byte(int c) {
460 2619: 23: if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')) return c;
461branch 0 taken 923 (fallthrough)
462branch 1 taken 1696
463branch 2 taken 284 (fallthrough)
464branch 3 taken 639
465branch 4 taken 436 (fallthrough)
466branch 5 taken 1544
467branch 6 taken 321 (fallthrough)
468branch 7 taken 115
469branch 8 taken 467 (fallthrough)
470branch 9 taken 1398
471branch 10 taken 75 (fallthrough)
472branch 11 taken 392
473 1790: 24: switch (c) {
474branch 0 taken 1359
475branch 1 taken 431
476 1359: 25: case '.': case '_': case '-': case '/': case '+': case ',': case '=': case '@': case ':': case '~':
477 1359: 26: return c;
478 431: 27: default:
479 431: 28: return -1;
480 -: 29: }
481 -: 30:}
482 -: 31:
483 -: 32:/* 0 with out = in when in is an acceptable path shorter than cap; -1 with out = "" otherwise */
484function oracle_path_copy called 883 returned 100% blocks executed 100%
485 883: 33:static inline int omega_path_copy(char *out, size_t cap, const char *in) {
486 883: 34: if (!out || cap == 0) return -1;
487branch 0 taken 882 (fallthrough)
488branch 1 taken 1
489branch 2 taken 19 (fallthrough)
490branch 3 taken 863
491 863: 35: out[0] = '\0';
492 863: 36: if (!in || !in[0]) return -1;
493branch 0 taken 831 (fallthrough)
494branch 1 taken 32
495branch 2 taken 32 (fallthrough)
496branch 3 taken 799
497 799: 37: size_t k = 0;
498 2847: 38: for (; in[k]; k++) {
499branch 0 taken 2361
500branch 1 taken 486 (fallthrough)
501 2361: 39: int b = omega_path_byte((unsigned char)in[k]);
502call 0 returned 2361
503 2361: 40: if (b < 0 || k + 1 >= cap) {
504branch 0 taken 2116 (fallthrough)
505branch 1 taken 245
506branch 2 taken 68 (fallthrough)
507branch 3 taken 2048
508 313: 41: out[0] = '\0';
509 313: 42: return -1;
510 -: 43: }
511 2048: 44: out[k] = (char)b;
512 -: 45: }
513 486: 46: out[k] = '\0';
514 1144: 47: for (size_t i = 0; i < k;) {
515branch 0 taken 800
516branch 1 taken 344 (fallthrough)
517 800: 48: size_t j = i;
518 2129: 49: while (j < k && out[j] != '/') j++;
519branch 0 taken 1756 (fallthrough)
520branch 1 taken 373
521branch 2 taken 1329
522branch 3 taken 427 (fallthrough)
523 800: 50: if (j - i == 2 && out[i] == '.' && out[i + 1] == '.') {
524branch 0 taken 213 (fallthrough)
525branch 1 taken 587
526branch 2 taken 143 (fallthrough)
527branch 3 taken 70
528branch 4 taken 142 (fallthrough)
529branch 5 taken 1
530 142: 51: out[0] = '\0';
531 142: 52: return -1;
532 -: 53: }
533 658: 54: i = j + 1;
534 -: 55: }
535 344: 56: return 0;
536 -: 57:}
537 -: 58:#else
538 -: 59:/* Pointer custody and stores stay here; the scalar Omega transducer owns
539 -: 60: * alphabet, component and length decisions. No fixed-size path truncation. */
540function omega_path_byte called 258 returned 100% blocks executed 89%
541 258: 61:static inline int omega_path_byte(int c) {
542 258: 62: uint64_t value = 256;
543 258: 63: if (omega_leftovers(&value, 0, (uint64_t)(int64_t)c, 0, 0, 0) != OMEGA_OK)
544call 0 returned 258
545branch 1 taken 0 (fallthrough)
546branch 2 taken 258
547 #####: 64: return -1;
548 258: 65: return value == 256 ? -1 : (int)value;
549branch 0 taken 72 (fallthrough)
550branch 1 taken 186
551 -: 66:}
552function omega_path_copy called 883 returned 100% blocks executed 100%
553 883: 67:static inline int omega_path_copy(char *out, size_t cap, const char *in) {
554 883: 68: if (!out || cap == 0) return -1;
555branch 0 taken 882 (fallthrough)
556branch 1 taken 1
557branch 2 taken 19 (fallthrough)
558branch 3 taken 863
559 863: 69: out[0] = '\0';
560 863: 70: if (!in) return -1;
561branch 0 taken 32 (fallthrough)
562branch 1 taken 831
563 831: 71: uint64_t state = 0;
564 831: 72: for (size_t k = 0;; ++k) {
565 2797: 73: unsigned char value = (unsigned char)in[k];
566 2797: 74: uint64_t next = 4;
567 2797: 75: if (omega_leftovers(&next, 1, state, value, k, cap) != OMEGA_OK ||
568call 0 returned 2797
569branch 1 taken 2797 (fallthrough)
570branch 2 taken 0
571 2797: 76: next == 4) {
572branch 0 taken 487 (fallthrough)
573branch 1 taken 2310
574 487: 77: out[0] = '\0';
575 831: 78: return -1;
576 -: 79: }
577 2310: 80: out[k] = (char)value;
578 2310: 81: if (next == 5) return 0;
579branch 0 taken 344 (fallthrough)
580branch 1 taken 1966
581 1966: 82: state = next;
582 -: 83: }
583 -: 84:}
584 -: 85:#endif
585 -: 86:
586 -: 87:#endif /* OMEGA_PATH_CHECK_H */
587
588rc=0