summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
Diffstat (limited to 'Userland')
-rw-r--r--Userland/DevTools/UserspaceEmulator/Emulator.h2
-rw-r--r--Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp27
-rw-r--r--Userland/Libraries/LibC/sys/socket.cpp8
-rw-r--r--Userland/Libraries/LibC/sys/socket.h1
4 files changed, 24 insertions, 14 deletions
diff --git a/Userland/DevTools/UserspaceEmulator/Emulator.h b/Userland/DevTools/UserspaceEmulator/Emulator.h
index 3533180ae8..70badf8a78 100644
--- a/Userland/DevTools/UserspaceEmulator/Emulator.h
+++ b/Userland/DevTools/UserspaceEmulator/Emulator.h
@@ -137,7 +137,7 @@ private:
int virt$getpeername(FlatPtr);
int virt$select(FlatPtr);
int virt$get_stack_bounds(FlatPtr, FlatPtr);
- int virt$accept(int sockfd, FlatPtr address, FlatPtr address_length);
+ int virt$accept4(FlatPtr);
int virt$bind(int sockfd, FlatPtr address, socklen_t address_length);
int virt$recvmsg(int sockfd, FlatPtr msg_addr, int flags);
int virt$sendmsg(int sockfd, FlatPtr msg_addr, int flags);
diff --git a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp
index 1fd6af2c83..e3ed2ddc3a 100644
--- a/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp
+++ b/Userland/DevTools/UserspaceEmulator/Emulator_syscalls.cpp
@@ -168,8 +168,8 @@ u32 Emulator::virt_syscall(u32 function, u32 arg1, u32 arg2, u32 arg3)
return virt$fchmod(arg1, arg2);
case SC_fchown:
return virt$fchown(arg1, arg2, arg3);
- case SC_accept:
- return virt$accept(arg1, arg2, arg3);
+ case SC_accept4:
+ return virt$accept4(arg1);
case SC_setsockopt:
return virt$setsockopt(arg1);
case SC_getsockname:
@@ -452,17 +452,20 @@ mode_t Emulator::virt$umask(mode_t mask)
return syscall(SC_umask, mask);
}
-int Emulator::virt$accept(int sockfd, FlatPtr address, FlatPtr address_length)
+int Emulator::virt$accept4(FlatPtr params_addr)
{
- socklen_t host_address_length = 0;
- mmu().copy_from_vm(&host_address_length, address_length, sizeof(host_address_length));
- auto host_buffer = ByteBuffer::create_zeroed(host_address_length);
- int rc = syscall(SC_accept, sockfd, host_buffer.data(), &host_address_length);
- if (rc < 0)
- return rc;
- mmu().copy_to_vm(address, host_buffer.data(), min((socklen_t)host_buffer.size(), host_address_length));
- mmu().copy_to_vm(address_length, &host_address_length, sizeof(host_address_length));
- return rc;
+ Syscall::SC_accept4_params params;
+ mmu().copy_from_vm(&params, params_addr, sizeof(params));
+ sockaddr_storage addr = {};
+ socklen_t addrlen;
+ mmu().copy_from_vm(&addrlen, (FlatPtr)params.addrlen, sizeof(socklen_t));
+ VERIFY(addrlen <= sizeof(addr));
+ int rc = accept4(params.sockfd, (sockaddr*)&addr, &addrlen, params.flags);
+ if (rc == 0) {
+ mmu().copy_to_vm((FlatPtr)params.addr, &addr, addrlen);
+ mmu().copy_to_vm((FlatPtr)params.addrlen, &addrlen, sizeof(socklen_t));
+ }
+ return rc < 0 ? -errno : rc;
}
int Emulator::virt$bind(int sockfd, FlatPtr address, socklen_t address_length)
diff --git a/Userland/Libraries/LibC/sys/socket.cpp b/Userland/Libraries/LibC/sys/socket.cpp
index 96211141b1..ba9cdd38ec 100644
--- a/Userland/Libraries/LibC/sys/socket.cpp
+++ b/Userland/Libraries/LibC/sys/socket.cpp
@@ -34,7 +34,13 @@ int listen(int sockfd, int backlog)
int accept(int sockfd, sockaddr* addr, socklen_t* addrlen)
{
- int rc = syscall(SC_accept, sockfd, addr, addrlen);
+ return accept4(sockfd, addr, addrlen, 0);
+}
+
+int accept4(int sockfd, sockaddr* addr, socklen_t* addrlen, int flags)
+{
+ Syscall::SC_accept4_params params { sockfd, addr, addrlen, flags };
+ int rc = syscall(SC_accept4, &params);
__RETURN_WITH_ERRNO(rc, rc, -1);
}
diff --git a/Userland/Libraries/LibC/sys/socket.h b/Userland/Libraries/LibC/sys/socket.h
index 44b673546d..0ff9aaff14 100644
--- a/Userland/Libraries/LibC/sys/socket.h
+++ b/Userland/Libraries/LibC/sys/socket.h
@@ -127,6 +127,7 @@ int socket(int domain, int type, int protocol);
int bind(int sockfd, const struct sockaddr* addr, socklen_t);
int listen(int sockfd, int backlog);
int accept(int sockfd, struct sockaddr*, socklen_t*);
+int accept4(int sockfd, struct sockaddr*, socklen_t*, int);
int connect(int sockfd, const struct sockaddr*, socklen_t);
int shutdown(int sockfd, int how);
ssize_t send(int sockfd, const void*, size_t, int flags);