From 7b1f58a06a863542e8ee8b7702c8ae7c4c0714b3 Mon Sep 17 00:00:00 2001 From: marcs-feh Date: Mon, 22 Jan 2024 16:09:44 -0300 Subject: [PATCH 1/5] sys/linux: Add binding to ioctl syscall + fd consts Add binding to ioctl syscall, due to the vast nature of this syscall adding more device specific request values is possible. Also added the stdin, stdout and stderr, to constants.odin --- core/sys/linux/constants.odin | 15 +++++++++++++++ core/sys/linux/sys.odin | 12 +++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/core/sys/linux/constants.odin b/core/sys/linux/constants.odin index 6294602e9..ecd630fa9 100644 --- a/core/sys/linux/constants.odin +++ b/core/sys/linux/constants.odin @@ -1,6 +1,21 @@ package linux +/* + Standard input file descriptor +*/ +STDIN_FILENO :: Fd(0) + +/* + Standard output file descriptor +*/ +STDOUT_FILENO :: Fd(1) + +/* + Standard output file descriptor +*/ +STDERR_FILENO :: Fd(2) + /* Special file descriptor to pass to `*at` functions to specify that relative paths are relative to current directory. diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 9a0f18e9f..7bec8eee2 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -216,7 +216,17 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se return Errno(-ret) } -// TODO(flysand): ioctl +/* + Control devices. The ioctl syscall is a bit special because + its argument is usually a pointer to some driver-specific structure. + The request value is device-specific. Consult your LibC implementation's + ioctls.h file to learn more. + Available since Linux 1.0. +*/ +ioctl :: proc "contextless" (fd: Fd, request: u64, arg: u64) -> (Errno) { + ret := syscall(SYS_ioctl, fd, request, arg) + return Errno(-ret) +} /* Read the file at a specified offset. From 84123cc87980d8365aa5b3c29d857f0f960830c8 Mon Sep 17 00:00:00 2001 From: marcs-feh Date: Wed, 24 Jan 2024 13:40:50 -0300 Subject: [PATCH 2/5] sys/linux: Adjust ioctl signature to fit the actual Linux Kernel implementation --- core/sys/linux/constants.odin | 2 +- core/sys/linux/sys.odin | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/sys/linux/constants.odin b/core/sys/linux/constants.odin index ecd630fa9..6b4c001a8 100644 --- a/core/sys/linux/constants.odin +++ b/core/sys/linux/constants.odin @@ -12,7 +12,7 @@ STDIN_FILENO :: Fd(0) STDOUT_FILENO :: Fd(1) /* - Standard output file descriptor + Standard error file descriptor */ STDERR_FILENO :: Fd(2) diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 7bec8eee2..d98b95113 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -223,7 +223,7 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se ioctls.h file to learn more. Available since Linux 1.0. */ -ioctl :: proc "contextless" (fd: Fd, request: u64, arg: u64) -> (Errno) { +ioctl :: proc "contextless" (fd: Fd, request: i32, arg: uintptr) -> (Errno) { ret := syscall(SYS_ioctl, fd, request, arg) return Errno(-ret) } From b58627490b63e5c4055238c99fd2cde635abd358 Mon Sep 17 00:00:00 2001 From: marcs-feh Date: Fri, 26 Jan 2024 12:09:04 -0300 Subject: [PATCH 3/5] Adjust signture + Fix rebase conflict --- core/sys/linux/sys.odin | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index d98b95113..74a172c75 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -220,12 +220,13 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se Control devices. The ioctl syscall is a bit special because its argument is usually a pointer to some driver-specific structure. The request value is device-specific. Consult your LibC implementation's - ioctls.h file to learn more. + ioctls.h file to learn more. The returned value of ioctl *may* be an error + code value instead of a memory address depending on the request type. Available since Linux 1.0. */ -ioctl :: proc "contextless" (fd: Fd, request: i32, arg: uintptr) -> (Errno) { +ioctl :: proc "contextless" (fd: Fd, request: u64, arg: u64) -> (uintptr) { ret := syscall(SYS_ioctl, fd, request, arg) - return Errno(-ret) + return uintptr(ret) } /* From d931bfcf83894b65d6db3bc846110efb400ab4a1 Mon Sep 17 00:00:00 2001 From: marcs-feh Date: Fri, 26 Jan 2024 16:17:09 -0300 Subject: [PATCH 4/5] resolve conflict --- core/sys/linux/sys.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 74a172c75..7f3c157b3 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -224,7 +224,7 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se code value instead of a memory address depending on the request type. Available since Linux 1.0. */ -ioctl :: proc "contextless" (fd: Fd, request: u64, arg: u64) -> (uintptr) { +ioctl :: proc "contextless" (fd: Fd, request: i32, arg: uintptr) -> (uintptr) { ret := syscall(SYS_ioctl, fd, request, arg) return uintptr(ret) } From c7af8af76a6c6173a410b6cde9f52ad22bcea707 Mon Sep 17 00:00:00 2001 From: Laytan Date: Tue, 13 Aug 2024 15:22:35 +0200 Subject: [PATCH 5/5] Update core/sys/linux/sys.odin --- core/sys/linux/sys.odin | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin index 6ff8e71c7..73ea47ed0 100644 --- a/core/sys/linux/sys.odin +++ b/core/sys/linux/sys.odin @@ -225,7 +225,7 @@ rt_sigprocmask :: proc "contextless" (mask_kind: Sig_Mask_Kind, new_set: ^Sig_Se code value instead of a memory address depending on the request type. Available since Linux 1.0. */ -ioctl :: proc "contextless" (fd: Fd, request: i32, arg: uintptr) -> (uintptr) { +ioctl :: proc "contextless" (fd: Fd, request: u32, arg: uintptr) -> (uintptr) { ret := syscall(SYS_ioctl, fd, request, arg) return uintptr(ret) }