interplane.Get Omega
Read in your language

omega-bridge

Omega-first language interoperability: checked conversion backends and native language bindings

Brought by drakestapleton

branch main Branches Tags History

omega-bridge / tests / native / v2 / host / hfile.om

51 lines · 1249 bytes Raw Blame History
1note hfile.om: an OM-2 unit for the host-word checks of tests/native/v2/run.sh (section 11). It uses all
2note nine function-mode host words a bridged unit may use (getuid geteuid getgid getegid stat lstat fopen
3note fstat fclose) and read, so tools/native refuses it without --host and accepts it with --host.
4om2
5export fn ids to ulong
6a = ulong getuid
7b = ulong geteuid
8c = ulong getgid
9e = ulong getegid
10ret add add a b add c e
11end
12
13note peek p: lstat and stat p, open it (O_NOFOLLOW O_NONBLOCK O_CLOEXEC, 559104 on AArch64), fstat the
14note descriptor, read up to 16 bytes, close; the byte count read, or minus errno of the first failure.
15export fn peek p view uchar * to long
16s = new uchar 128 0
17r = lstat p 0 len p s 0 128
18if ne r 0
19ret r
20end
21r = stat p 0 len p s 0 128
22if ne r 0
23ret r
24end
25fd = fopen p 0 len p 559104 0
26if lt fd 0
27ret fd
28end
29b = new uchar 16 0
30k = fstat int fd s 0 128
31n = read int fd b 0 16
32z = fclose int fd
33if ne k 0
34ret k
35end
36ret n
37end
38
39note size p: the st_size field (offset 48 of the 128-byte AArch64 stat) of p, or minus errno.
40export fn size p view uchar * to long
41s = new uchar 128 0
42r = stat p 0 len p s 0 128
43if ne r 0
44ret r
45end
46x = ulong 0
47for i ulong 8
48x = or x shl ulong get s add 48 i mul i 8
49end
50ret long x
51end