interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / apps / interplane-forge / tools / bring / src / plat-linux.om

132 lines · 2282 bytes Raw Blame History
1note Linux aarch64 platform; flags are Linux ABI values, not policy limits.
2fn pl_open p view uchar * how ulong mode int to long
3ret fopen p 0 len p pl_oflag how mode
4end
5fn pl_close fd int to void
6x = fclose fd
7end
8fn pl_unlink p view uchar * to long
9ret unlink p 0 len p
10end
11fn pl_rmdir p view uchar * to long
12ret rmdir p 0 len p
13end
14fn pl_mkdir p view uchar * mode int to long
15ret makedir p 0 len p mode
16end
17fn pl_cd p view uchar * to long
18ret chdir p 0 len p
19end
20fn pl_fcd fd int to long
21ret fchdir fd
22end
23note directories: the handle is the O_DIRECTORY descriptor itself, 0 on error
24fn pl_dopen p view uchar * to ulong
25fd = pl_open p 1 0
26if lt fd 0
27ret 0
28end
29ret ulong fd
30end
31fn pl_dfd h ulong to int
32ret int h
33end
34fn pl_dclose h ulong to void
35pl_close int h
36end
37fn pl_dents h ulong b edit uchar * to long
38ret getdnts int h b 0 len b
39end
40fn pl_dname to ulong
41ret 19
42end
43fn pl_dlen b view uchar * o ulong to ulong
44ret rd16 b add o 16
45end
46fn pl_stat p view uchar * b edit uchar * to long
47ret lstat p 0 len p b 0 len b
48end
49fn pl_fstat fd int b edit uchar * to long
50ret fstat fd b 0 len b
51end
52fn pl_readat fd int b edit uchar * pos ulong to long
53ret pread fd b 0 len b long pos
54end
55fn pl_seek fd int pos ulong to long
56ret fseek fd long pos 0
57end
58fn pl_trunc fd int n ulong to long
59ret ftrunc fd long n
60end
61fn pl_argc to long
62ret argcnt
63end
64fn pl_arg i ulong b edit uchar * to long
65ret argread i b 0 len b
66end
67fn pl_envc to long
68ret envcnt
69end
70fn pl_env i ulong b edit uchar * to long
71ret envread i b 0 len b
72end
73fn pl_pid to long
74ret getpid
75end
76fn pl_sleep to void
77x = sleepns 1000000000
78end
79fn pl_run a view uchar * inf int outf int errf int to long
80pid = fork
81if lt pid 0
82ret -1
83end
84if eq pid 0
85if ne inf 0
86x = dupfd inf 0 0
87if lt x 0
88exit 126
89end
90end
91if ne outf 1
92x = dupfd outf 1 0
93if lt x 0
94exit 126
95end
96end
97if ne errf 2
98x = dupfd errf 2 0
99if lt x 0
100exit 126
101end
102end
103x = execprog a 0 len a
104exit 127
105end
106st = new uchar 4 0
107while true bound 9223372036854775807
108r = waitpid int pid st 0 4 0
109if eq r -4
110continue
111end
112if ne r pid
113ret -1
114end
115break
116end
117v = rd32 st 0
118if ne and v 127 0
119ret -1
120end
121ret long and shr v 8 255
122end
123fn pl_cwd o edit uchar * to ulong
124r = cwd o 0 len o
125if le r 0
126die terrio
127end
128ret sub ulong r 1
129end
130fn pl_skip fd int n ulong to long
131ret fseek fd long n 1
132end