[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 09/11] Signed-off-by: Karim Taha <address@hidden>
From: |
Karim Taha |
Subject: |
[PATCH v3 09/11] Signed-off-by: Karim Taha <address@hidden> |
Date: |
Fri, 21 Apr 2023 18:41:58 +0200 |
From: Stacey Son <sson@FreeBSD.org>
accept(2) syscall.
Add the accept(2) syscall to bsd-user/bsd-socket.h.
Signed-off-by: Karim Taha <kariem.taha2.7@gmail.com>
---
bsd-user/bsd-socket.h | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/bsd-user/bsd-socket.h b/bsd-user/bsd-socket.h
index f191f22d63..f748266730 100644
--- a/bsd-user/bsd-socket.h
+++ b/bsd-user/bsd-socket.h
@@ -79,4 +79,37 @@ static inline abi_long do_bsd_connect(int sockfd, abi_ulong
target_addr,
return get_errno(connect(sockfd, addr, addrlen));
}
+/* accept(2) */
+static inline abi_long do_bsd_accept(int fd, abi_ulong target_addr,
+ abi_ulong target_addrlen_addr)
+{
+ socklen_t addrlen;
+ void *addr;
+ abi_long ret;
+
+ if (target_addr == 0) {
+ return get_errno(accept(fd, NULL, NULL));
+ }
+ /* return EINVAL if addrlen pointer is invalid */
+ if (get_user_u32(addrlen, target_addrlen_addr)) {
+ return -TARGET_EINVAL;
+ }
+ if ((int)addrlen < 0) {
+ return -TARGET_EINVAL;
+ }
+ if (!access_ok(VERIFY_WRITE, target_addr, addrlen)) {
+ return -TARGET_EINVAL;
+ }
+ addr = alloca(addrlen);
+
+ ret = get_errno(accept(fd, addr, &addrlen));
+ if (!is_error(ret)) {
+ host_to_target_sockaddr(target_addr, addr, addrlen);
+ if (put_user_u32(addrlen, target_addrlen_addr)) {
+ ret = -TARGET_EFAULT;
+ }
+ }
+ return ret;
+}
+
#endif /* BSD_SOCKET_H */
--
2.40.0
- [PATCH v3 00/11] Contribution task implementations, for the 'FreeBSD user emulation improvements' project., Karim Taha, 2023/04/21
- [PATCH v3 01/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 02/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 03/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 04/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 05/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 06/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 07/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 09/11] Signed-off-by: Karim Taha <address@hidden>,
Karim Taha <=
- [PATCH v3 10/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 08/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21
- [PATCH v3 11/11] Signed-off-by: Karim Taha <address@hidden>, Karim Taha, 2023/04/21