aboutsummaryrefslogtreecommitdiff
path: root/base/runtime/os_specific_js.odin
blob: 8676f3a6e5d5661a169964d0cd77e18bc186ebd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#+build js
#+private
package runtime

foreign import "odin_env"

_HAS_RAND_BYTES :: true

_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
	foreign odin_env {
		write :: proc "contextless" (fd: u32, p: []byte) ---
	}
	write(1, data)
	return len(data), 0
}

_rand_bytes :: proc "contextless" (dst: []byte) {
	foreign odin_env {
		@(link_name = "rand_bytes")
		env_rand_bytes :: proc "contextless" (buf: []byte) ---
	}

	MAX_PER_CALL_BYTES :: 65536 // 64kiB

	dst := dst
	for len(dst) > 0 {
		to_read := min(len(dst), MAX_PER_CALL_BYTES)
		env_rand_bytes(dst[:to_read])

		dst = dst[to_read:]
	}
}

_exit :: proc "contextless" (code: int) -> ! {
	trap()
}