commit 191c79c25f49607d77aadead95181a10db65a43b
parent da32f7462dd58617f04a6001ee47ff303b201576
Author: erai <erai@omiltem.net>
Date: Mon, 12 May 2025 19:13:20 -0400
use getrandom instead of rdrandom
Diffstat:
4 files changed, 79 insertions(+), 77 deletions(-)
diff --git a/sshd.om b/sshd.om
@@ -73,16 +73,9 @@ func read_fill(fd: int, buf: *byte, n: int): int {
}
}
-func _rdrand(): int;
func read_rand(buf: *byte, n: int) {
- var i: int;
- i = 0;
- loop {
- if i == n {
- break;
- }
- buf[i] = _rdrand() as byte;
- i = i + 1;
+ if getrandom(buf, n, 0) != n {
+ die("getrandom");
}
}
@@ -1535,7 +1528,7 @@ func dorequest(ctx: *sshd_ctx) {
} else if cr.kind == SSH_CR_SIGNAL {
ok = dosignal(&cr.signal, ctx);
} else {
- die("unknown request");
+ //die("unknown request");
if cr.want_reply {
sf.channel = 0;
encode_channel_failure(&sf, ctx);
diff --git a/syscall.aarch64.om b/syscall.aarch64.om
@@ -60,96 +60,100 @@ func close(fd: int): int {
return syscall(57, fd, 0, 0, 0, 0, 0);
}
-//func fstat(fd: int, buf: *byte): int {
-// return syscall(5, fd, buf as int, 0, 0, 0, 0);
-//}
-//
-//func poll(pfd: *int, nfd: int, timeout: int): int {
-// return syscall(7, pfd as int, nfd, timeout, 0, 0, 0);
-//}
-//
-//func lseek(fd: int, off: int, whence: int): int {
-// return syscall(8, fd, off, whence, 0, 0, 0);
-//}
+func fstat(fd: int, buf: *byte): int {
+ return syscall(80, fd, buf as int, 0, 0, 0, 0);
+}
+
+func getrandom(buf: *byte, len: int, flags: int): int {
+ return syscall(278, buf as int, len, flags, 0, 0, 0);
+}
+
+func poll(pfd: *int, nfd: int, timeout: int): int {
+ return syscall(73, pfd as int, nfd, 0, 0, 0, 0);
+}
+
+func lseek(fd: int, off: int, whence: int): int {
+ return syscall(62, fd, off, whence, 0, 0, 0);
+}
func mmap(addr: int, len: int, prot: int, flags: int, fd: int, off: int): int {
return syscall(222, addr, len, prot, flags, fd, off);
}
-//func munmap(addr: int, len: int): int {
-// return syscall(11, addr, len, 0, 0, 0, 0);
-//}
+func munmap(addr: int, len: int): int {
+ return syscall(215, addr, len, 0, 0, 0, 0);
+}
-//func sigaction(sig: int, act: *sigaction, oact: *sigaction): int {
-// return syscall(13, sig, act as int, oact as int, 8, 0, 0);
-//}
+func sigaction(sig: int, act: *sigaction, oact: *sigaction): int {
+ return syscall(134, sig, act as int, oact as int, 8, 0, 0);
+}
-//func pipe(rfd: *int, wfd: *int): int {
-// var buf: int;
-// var ret: int;
-// ret = syscall(22, (&buf) as int, 0, 0, 0, 0, 0);
-// if ret == 0 {
-// *rfd = buf & (-1 >> 32);
-// *wfd = buf >> 32;
-// }
-// return ret;
-//}
+func pipe(rfd: *int, wfd: *int): int {
+ var buf: int;
+ var ret: int;
+ ret = syscall(59, (&buf) as int, 0, 0, 0, 0, 0);
+ if ret == 0 {
+ *rfd = buf & (-1 >> 32);
+ *wfd = buf >> 32;
+ }
+ return ret;
+}
-//func dup2(old: int, new: int): int {
-// return syscall(33, old, new, 0, 0, 0, 0);
-//}
+func dup2(old: int, new: int): int {
+ return syscall(24, old, new, 0, 0, 0, 0);
+}
-//func socket(pf: int, ty: int, pc: int): int {
-// return syscall(41, pf, ty, pc, 0, 0, 0);
-//}
+func socket(pf: int, ty: int, pc: int): int {
+ return syscall(198, pf, ty, pc, 0, 0, 0);
+}
-//func accept(fd: int, addr: *byte, len: *int): int {
-// return syscall(43, fd, addr as int, len as int, 0, 0, 0);
-//}
+func accept(fd: int, addr: *byte, len: *int): int {
+ return syscall(202, fd, addr as int, len as int, 0, 0, 0);
+}
-//func bind(fd: int, addr: *byte, len: int): int {
-// return syscall(49, fd, addr as int, len as int, 0, 0, 0);
-//}
+func bind(fd: int, addr: *byte, len: int): int {
+ return syscall(200, fd, addr as int, len as int, 0, 0, 0);
+}
-//func listen(fd: int, backlog: int): int {
-// return syscall(50, fd, backlog, 0, 0, 0, 0);
-//}
+func listen(fd: int, backlog: int): int {
+ return syscall(201, fd, backlog, 0, 0, 0, 0);
+}
-//func fork(): int {
-// return syscall(57, 0, 0, 0, 0, 0, 0);
-//}
+func fork(): int {
+ return syscall(220, 0, 0, 0, 0, 0, 0);
+}
-//func exec(cmd: *byte, argv: **byte, envp: **byte): int {
-// return syscall(59, cmd as int, argv as int, envp as int, 0, 0, 0);
-//}
+func exec(cmd: *byte, argv: **byte, envp: **byte): int {
+ return syscall(221, cmd as int, argv as int, envp as int, 0, 0, 0);
+}
func exit(n: int) {
syscall(93, n, 0, 0, 0, 0, 0);
}
-//func wait(pid: int, status: *int, flags: int): int {
-// var s: int;
-// var ret: int;
-// s = 0;
-// ret = syscall(61, pid, s as int, flags, 0, 0, 0);
-// if status {
-// *status = s & (-1 >> 32);
-// }
-// return ret;
-//}
+func wait(pid: int, status: *int, flags: int): int {
+ var s: int;
+ var ret: int;
+ s = 0;
+ ret = syscall(260, pid, s as int, flags, 0, 0, 0);
+ if status {
+ *status = s & (-1 >> 32);
+ }
+ return ret;
+}
-//func rename(oldname: *byte, newname: *byte): int {
-// return syscall(82, oldname as int, newname as int, 0, 0, 0, 0);
-//}
+func rename(oldname: *byte, newname: *byte): int {
+ return syscall(38, -100, oldname as int, -100, newname as int, 0, 0);
+}
-//func mkdir(name: *byte): int {
-// return syscall(83, name as int, 0, 0, 0, 0, 0);
-//}
+func mkdir(name: *byte): int {
+ return syscall(34, -100, name as int, 0, 0, 0, 0);
+}
func unlink(name: *byte): int {
return syscall(35, -100, name as int, 0, 0, 0, 0);
}
-//func getdirents(fd: int, buf: *byte, len: int): int {
-// return syscall(217, fd, buf as int, len, 0, 0, 0);
-//}
+func getdirents(fd: int, buf: *byte, len: int): int {
+ return syscall(61, fd, buf as int, len, 0, 0, 0);
+}
diff --git a/syscall.om b/syscall.om
@@ -17,6 +17,7 @@ func write(fd: int, buf: *byte, n: int): int;
func open(name: *byte, flags: int, mode: int): int;
func close(fd: int): int;
func fstat(fd: int, buf: *byte): int;
+func getrandom(buf: *byte, len: int, flags: int): int;
func poll(pfd: *int, nfd: int, timeout: int): int;
func lseek(fd: int, off: int, whence: int): int;
func mmap(addr: int, len: int, prot: int, flags: int, fd: int, off: int): int;
diff --git a/syscall.x86_64.om b/syscall.x86_64.om
@@ -64,6 +64,10 @@ func fstat(fd: int, buf: *byte): int {
return syscall(5, fd, buf as int, 0, 0, 0, 0);
}
+func getrandom(buf: *byte, len: int, flags: int): int {
+ return syscall(318, buf as int, len, flags, 0, 0, 0);
+}
+
func poll(pfd: *int, nfd: int, timeout: int): int {
return syscall(7, pfd as int, nfd, timeout, 0, 0, 0);
}