code wiki / (root) / nx_wflow_execution_evidence_candidate_t346.nx

nx_wflow_execution_evidence_candidate_t346.nx source

↩ module page · 35 lines · 4141 B

1// Isolated additive candidate; records execution facts, never operation success. 2const WFX_REFUSED:i64=0 3const WFX_BEGIN:i64=1 4const WFX_COMPLETE:i64=2 5const WFX_WAIT_UNKNOWN:i64=3 6func wfx_token(s:*u8)->i64{if (s as i64)<=0{return 0};var i:i64=0;while s[i]!=(0 as u8){let c:i64=s[i] as i64;if c<=32||c==127{return 0};i=i+1};if i==0{return 0};return 1} 7func wfx_phase(pv:i64)->*u8{if pv==WFX_REFUSED{return "refused"};if pv==WFX_BEGIN{return "begin"};if pv==WFX_COMPLETE{return "complete"};if pv==WFX_WAIT_UNKNOWN{return "wait-unknown"};return "invalid"} 8struct WfExecutionEvidence{rid:*u8,connector:*u8,elf:*u8,step:i64,attempt:i64,phase:i64,dispatched:i64,exit_known:i64,exit_code:i64,reason:*u8} 9func wf_emit_execution(led:*u8,e:*WfExecutionEvidence)->i64{ 10 if (e as i64)<=0{return WF_EVIDENCE_ERROR} 11 if wfx_token(e.rid)!=1||wfx_token(e.connector)!=1||wfx_token(e.elf)!=1||wfx_token(e.reason)!=1{return WF_EVIDENCE_ERROR} 12 if e.step<0||e.attempt<0||e.phase<0||e.phase>3||e.dispatched<(-1)||e.dispatched>1||e.exit_known<0||e.exit_known>1||e.exit_code<0||e.exit_code>255{return WF_EVIDENCE_ERROR} 13 if e.phase==WFX_REFUSED&&(e.dispatched!=0||e.exit_known!=0){return WF_EVIDENCE_ERROR} 14 if e.phase==WFX_BEGIN&&(e.dispatched!=(-1)||e.exit_known!=0){return WF_EVIDENCE_ERROR} 15 if e.phase==WFX_COMPLETE&&(e.dispatched!=1||e.exit_known!=1){return WF_EVIDENCE_ERROR} 16 if e.phase==WFX_WAIT_UNKNOWN&&(e.dispatched!=1||e.exit_known!=0){return WF_EVIDENCE_ERROR} 17 let a:*WfOwnedText=wf_text_decimal(e.step);let b:*WfOwnedText=wf_text_decimal(e.attempt) 18 var c:*WfOwnedText=0 as *WfOwnedText;if e.dispatched<0{c=wf_text_slice("unknown",0,7)}else{c=wf_text_decimal(e.dispatched)};let d:*WfOwnedText=wf_text_decimal(e.exit_known);let f:*WfOwnedText=wf_text_decimal(e.exit_code) 19 if a==(0 as *WfOwnedText)||b==(0 as *WfOwnedText)||c==(0 as *WfOwnedText)||d==(0 as *WfOwnedText)||f==(0 as *WfOwnedText){wf_text_free(a);wf_text_free(b);wf_text_free(c);wf_text_free(d);wf_text_free(f);return WF_EVIDENCE_ERROR} 20 let fields:*i64=sys_mmap_try(21*8) as *i64 21 if (fields as i64)<=0{wf_text_free(a);wf_text_free(b);wf_text_free(c);wf_text_free(d);wf_text_free(f);return WF_EVIDENCE_ERROR} 22 fields[0]="WFEXEC rid=" as *u8 as i64;fields[1]=e.rid as i64;fields[2]=" connector=" as *u8 as i64;fields[3]=e.connector as i64;fields[4]=" elf=" as *u8 as i64;fields[5]=e.elf as i64;fields[6]=" step=" as *u8 as i64;fields[7]=a.data as i64;fields[8]=" att=" as *u8 as i64;fields[9]=b.data as i64;fields[10]=" phase=" as *u8 as i64;fields[11]=wfx_phase(e.phase) as i64;fields[12]=" dispatched=" as *u8 as i64;fields[13]=c.data as i64;fields[14]=" exit_known=" as *u8 as i64;fields[15]=d.data as i64;fields[16]=" exit=" as *u8 as i64;fields[17]=f.data as i64;fields[18]=" reason=" as *u8 as i64;fields[19]=e.reason as i64;fields[20]=" postcondition=unverified artifact_identity=path-only argv=omitted\n" as *u8 as i64 23 var bytes:i64=1;var i:i64=0;var valid:i64=1 24 while i<21{let n:i64=slen(fields[i] as *u8);if n>WF_TEXT_I64_MAX-bytes{valid=0;break};bytes=bytes+n;i=i+1} 25 var rc:i64=WF_EVIDENCE_ERROR 26 if valid==1{let line:*u8=sys_mmap_try(bytes);if (line as i64)>0{var o:i64=0;i=0;while i<21{o=wf_cat(line,o,fields[i] as *u8);i=i+1};line[o]=0 as u8;rc=wf_append(led,line);if sys_munmap_direct(line,bytes)!=0{rc=WF_EVIDENCE_ERROR}}} 27 if sys_munmap_direct(fields as *u8,21*8)!=0{rc=WF_EVIDENCE_ERROR} 28 if wf_text_free(a)!=0{rc=WF_EVIDENCE_ERROR};if wf_text_free(b)!=0{rc=WF_EVIDENCE_ERROR};if wf_text_free(c)!=0{rc=WF_EVIDENCE_ERROR};if wf_text_free(d)!=0{rc=WF_EVIDENCE_ERROR};if wf_text_free(f)!=0{rc=WF_EVIDENCE_ERROR} 29 return rc 30} 31func wfx_record(cx:*i64,rid:*u8,name:*u8,elf:*u8,step:i64,att:i64,phase:i64,dispatched:i64,known:i64,code:i64,reason:*u8)->i64{ 32 let e:*WfExecutionEvidence=sys_mmap_try(10*8) as *WfExecutionEvidence;if (e as i64)<=0{return WF_EVIDENCE_ERROR} 33 e.rid=rid;e.connector=name;e.elf=elf;e.step=step;e.attempt=att;e.phase=phase;e.dispatched=dispatched;e.exit_known=known;e.exit_code=code;e.reason=reason 34 let rc:i64=wf_emit_execution(cx[2] as *u8,e);let freed:i64=sys_munmap_direct(e as *u8,10*8);if freed!=0{return WF_EVIDENCE_ERROR};return rc 35}