diff options
author | Andreas Kling <kling@serenityos.org> | 2023-04-03 18:26:46 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2023-04-04 10:33:42 +0200 |
commit | 33711655885dd4450120272d872972fba5f78292 (patch) | |
tree | 33ef5d8554e130b933c6698ef71f2e6a99dc1314 | |
parent | 5bc7882b6877240accc29854203645f79a4e78a6 (diff) | |
download | serenity-33711655885dd4450120272d872972fba5f78292.zip |
Kernel: Make the getsockname/getpeername syscall helper a bit nicer
Instead of templatizing on a bool parameter, use an enum for clarity.
-rw-r--r-- | Kernel/Process.h | 6 | ||||
-rw-r--r-- | Kernel/Syscalls/socket.cpp | 8 |
2 files changed, 9 insertions, 5 deletions
diff --git a/Kernel/Process.h b/Kernel/Process.h index 90ee2cbba8..43e6159555 100644 --- a/Kernel/Process.h +++ b/Kernel/Process.h @@ -454,7 +454,11 @@ public: ErrorOr<FlatPtr> sys$jail_attach(Userspace<Syscall::SC_jail_attach_params const*> user_params); ErrorOr<FlatPtr> sys$get_root_session_id(pid_t force_sid); - template<bool sockname, typename Params> + enum SockOrPeerName { + SockName, + PeerName, + }; + template<SockOrPeerName, typename Params> ErrorOr<void> get_sock_or_peer_name(Params const&); static void initialize(); diff --git a/Kernel/Syscalls/socket.cpp b/Kernel/Syscalls/socket.cpp index fb2b521d6c..d7746ab468 100644 --- a/Kernel/Syscalls/socket.cpp +++ b/Kernel/Syscalls/socket.cpp @@ -325,7 +325,7 @@ ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user return result.value(); } -template<bool sockname, typename Params> +template<Process::SockOrPeerName sock_or_peer_name, typename Params> ErrorOr<void> Process::get_sock_or_peer_name(Params const& params) { socklen_t addrlen_value; @@ -343,7 +343,7 @@ ErrorOr<void> Process::get_sock_or_peer_name(Params const& params) sockaddr_un address_buffer {}; addrlen_value = min(sizeof(sockaddr_un), static_cast<size_t>(addrlen_value)); - if constexpr (sockname) + if constexpr (sock_or_peer_name == SockOrPeerName::SockName) socket.get_local_address((sockaddr*)&address_buffer, &addrlen_value); else socket.get_peer_address((sockaddr*)&address_buffer, &addrlen_value); @@ -355,7 +355,7 @@ ErrorOr<FlatPtr> Process::sys$getsockname(Userspace<Syscall::SC_getsockname_para { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); auto params = TRY(copy_typed_from_user(user_params)); - TRY(get_sock_or_peer_name<true>(params)); + TRY(get_sock_or_peer_name<SockOrPeerName::SockName>(params)); return 0; } @@ -363,7 +363,7 @@ ErrorOr<FlatPtr> Process::sys$getpeername(Userspace<Syscall::SC_getpeername_para { VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this); auto params = TRY(copy_typed_from_user(user_params)); - TRY(get_sock_or_peer_name<false>(params)); + TRY(get_sock_or_peer_name<SockOrPeerName::PeerName>(params)); return 0; } |