aboutsummaryrefslogtreecommitdiff
path: root/base/runtime/os_specific_linux.odin
blob: dfe3c8841895b06478bc047a84c66c4680fbaa9f (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
37
38
39
40
#+private
package runtime

import "base:intrinsics"

_stderr_write :: proc "contextless" (data: []byte) -> (int, _OS_Errno) {
	when ODIN_ARCH == .amd64 {
		SYS_write :: uintptr(1)
	} else when ODIN_ARCH == .arm64 {
		SYS_write :: uintptr(64)
	} else when ODIN_ARCH == .i386 {
		SYS_write :: uintptr(4)
	} else when ODIN_ARCH == .arm32 {
		SYS_write :: uintptr(4)
	} else when ODIN_ARCH == .riscv64 {
		SYS_write :: uintptr(64)
	}

	stderr :: 2

	ret := int(intrinsics.syscall(SYS_write, uintptr(stderr), uintptr(raw_data(data)), uintptr(len(data))))
	if ret < 0 && ret > -4096 {
		return 0, _OS_Errno(-ret)
	}
	return ret, 0
}


_exit :: proc "contextless" (code: int) -> ! {
	SYS_exit_group ::
		231 when ODIN_ARCH == .amd64 else
		248 when ODIN_ARCH == .arm32 else
		94  when ODIN_ARCH == .arm64 else
		252 when ODIN_ARCH == .i386  else
		94  when ODIN_ARCH == .riscv64 else
		0

	intrinsics.syscall(uintptr(SYS_exit_group), uintptr(i32(code)))
	unreachable()
}