1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 09:48:11 +00:00

Kernel: Use Process::require_promise() instead of REQUIRE_PROMISE()

This change lays the foundation for making the require_promise return
an error hand handling the process abort outside of the syscall
implementations, to avoid cases where we would leak resources.

It also has the advantage that it makes removes a gs pointer read
to look up the current thread, then process for every syscall. We
can instead go through the Process this pointer in most cases.
This commit is contained in:
Brian Gianforcaro 2021-12-29 00:10:17 -08:00 committed by Andreas Kling
parent c4f60844c5
commit bad6d50b86
61 changed files with 133 additions and 132 deletions

View file

@ -14,9 +14,9 @@ namespace Kernel {
#define REQUIRE_PROMISE_FOR_SOCKET_DOMAIN(domain) \
do { \
if (domain == AF_INET) \
REQUIRE_PROMISE(inet); \
require_promise(Pledge::inet); \
else if (domain == AF_LOCAL) \
REQUIRE_PROMISE(unix); \
require_promise(Pledge::unix); \
} while (0)
void Process::setup_socket_fd(int fd, NonnullRefPtr<OpenFileDescription> description, int type)
@ -76,7 +76,7 @@ ErrorOr<FlatPtr> Process::sys$listen(int sockfd, int backlog)
ErrorOr<FlatPtr> Process::sys$accept4(Userspace<const Syscall::SC_accept4_params*> user_params)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(accept);
require_promise(Pledge::accept);
auto params = TRY(copy_typed_from_user(user_params));
int accepting_socket_fd = params.sockfd;
@ -146,7 +146,7 @@ ErrorOr<FlatPtr> Process::sys$connect(int sockfd, Userspace<const sockaddr*> use
ErrorOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(stdio);
require_promise(Pledge::stdio);
if (how & ~SHUT_RDWR)
return EINVAL;
auto description = TRY(fds().open_file_description(sockfd));
@ -161,7 +161,7 @@ ErrorOr<FlatPtr> Process::sys$shutdown(int sockfd, int how)
ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*> user_msg, int flags)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(stdio);
require_promise(Pledge::stdio);
auto msg = TRY(copy_typed_from_user(user_msg));
if (msg.msg_iovlen != 1)
@ -189,7 +189,7 @@ ErrorOr<FlatPtr> Process::sys$sendmsg(int sockfd, Userspace<const struct msghdr*
ErrorOr<FlatPtr> Process::sys$recvmsg(int sockfd, Userspace<struct msghdr*> user_msg, int flags)
{
VERIFY_PROCESS_BIG_LOCK_ACQUIRED(this)
REQUIRE_PROMISE(stdio);
require_promise(Pledge::stdio);
struct msghdr msg;
TRY(copy_from_user(&msg, user_msg));