2020-06-15 14:18:57 +00:00
|
|
|
#ifndef COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_
|
|
|
|
#define COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_
|
2022-04-15 06:39:48 +00:00
|
|
|
#include "libc/nt/struct/overlapped.h"
|
2021-02-06 07:45:34 +00:00
|
|
|
#include "libc/nt/thunk/msabi.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/nt/winsock.h"
|
2020-11-28 20:01:51 +00:00
|
|
|
#include "libc/sock/select.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#include "libc/sock/sock.h"
|
2022-08-06 10:51:50 +00:00
|
|
|
#include "libc/sock/struct/msghdr.h"
|
|
|
|
#include "libc/sock/struct/pollfd.h"
|
2020-06-15 14:18:57 +00:00
|
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
|
|
COSMOPOLITAN_C_START_
|
|
|
|
|
|
|
|
#define FD_READ (1 << FD_READ_BIT)
|
|
|
|
#define FD_READ_BIT 0
|
|
|
|
#define FD_WRITE (1 << FD_WRITE_BIT)
|
|
|
|
#define FD_WRITE_BIT 1
|
|
|
|
#define FD_OOB (1 << FD_OOB_BIT)
|
|
|
|
#define FD_OOB_BIT 2
|
|
|
|
#define FD_ACCEPT (1 << FD_ACCEPT_BIT)
|
|
|
|
#define FD_ACCEPT_BIT 3
|
|
|
|
#define FD_CONNECT (1 << FD_CONNECT_BIT)
|
|
|
|
#define FD_CONNECT_BIT 4
|
|
|
|
#define FD_CLOSE (1 << FD_CLOSE_BIT)
|
|
|
|
#define FD_CLOSE_BIT 5
|
|
|
|
|
2021-02-04 03:35:29 +00:00
|
|
|
struct sockaddr_bsd {
|
2020-06-15 14:18:57 +00:00
|
|
|
uint8_t sa_len; /* « different type */
|
|
|
|
uint8_t sa_family; /* « different type */
|
|
|
|
char sa_data[14];
|
|
|
|
};
|
|
|
|
|
2021-02-04 03:35:29 +00:00
|
|
|
struct sockaddr_in_bsd {
|
2020-06-15 14:18:57 +00:00
|
|
|
uint8_t sin_len; /* « different type */
|
|
|
|
uint8_t sin_family; /* « different type */
|
|
|
|
uint16_t sin_port;
|
|
|
|
struct in_addr sin_addr;
|
|
|
|
uint8_t sin_zero[8];
|
|
|
|
};
|
|
|
|
|
2021-02-04 03:35:29 +00:00
|
|
|
struct msghdr_bsd {
|
2020-06-15 14:18:57 +00:00
|
|
|
void *msg_name;
|
|
|
|
uint32_t msg_namelen;
|
|
|
|
struct iovec *msg_iov;
|
|
|
|
uint32_t msg_iovlen; /* « different type */
|
|
|
|
void *msg_control;
|
|
|
|
uint64_t msg_controllen;
|
|
|
|
uint32_t msg_flags; /* « different type */
|
|
|
|
};
|
|
|
|
|
2021-04-02 02:32:39 +00:00
|
|
|
struct sockaddr_un_bsd {
|
2021-04-23 17:45:19 +00:00
|
|
|
uint8_t sun_len; /* sockaddr len including NUL on freebsd but excluding it on
|
|
|
|
openbsd/xnu */
|
2021-04-02 02:32:39 +00:00
|
|
|
uint8_t sun_family;
|
2021-04-23 17:45:19 +00:00
|
|
|
char sun_path[108];
|
2021-04-02 02:32:39 +00:00
|
|
|
};
|
|
|
|
|
2022-06-22 10:04:25 +00:00
|
|
|
union sockaddr_storage_bsd {
|
|
|
|
struct sockaddr_bsd sa;
|
|
|
|
struct sockaddr_in_bsd sin;
|
|
|
|
struct sockaddr_un_bsd sun;
|
|
|
|
};
|
|
|
|
|
|
|
|
union sockaddr_storage_linux {
|
|
|
|
struct sockaddr sa;
|
|
|
|
struct sockaddr_in sin;
|
|
|
|
struct sockaddr_un sun;
|
|
|
|
};
|
|
|
|
|
2021-06-24 17:53:27 +00:00
|
|
|
/* ------------------------------------------------------------------------------------*/
|
|
|
|
|
2022-04-15 06:39:48 +00:00
|
|
|
#define SOCKFD_OVERLAP_BUFSIZ 128
|
|
|
|
|
2021-02-06 07:45:34 +00:00
|
|
|
struct SockFd {
|
|
|
|
int family;
|
|
|
|
int type;
|
|
|
|
int protocol;
|
2022-06-26 01:17:31 +00:00
|
|
|
uint32_t rcvtimeo;
|
|
|
|
uint32_t sndtimeo;
|
2022-04-15 06:39:48 +00:00
|
|
|
bool32 (*__msabi ConnectEx)(int64_t s, const struct sockaddr *name,
|
|
|
|
int namelen, const void *opt_lpSendBuffer,
|
|
|
|
uint32_t dwSendDataLength,
|
|
|
|
uint32_t *out_lpdwBytesSent,
|
|
|
|
struct NtOverlapped *inout_lpOverlapped);
|
|
|
|
bool32 (*__msabi AcceptEx)(
|
|
|
|
int64_t sListenSocket, int64_t sAcceptSocket,
|
|
|
|
void *out_lpOutputBuffer /*[recvlen+local+remoteaddrlen]*/,
|
|
|
|
uint32_t dwReceiveDataLength, uint32_t dwLocalAddressLength,
|
|
|
|
uint32_t dwRemoteAddressLength, uint32_t *out_lpdwBytesReceived,
|
|
|
|
struct NtOverlapped *inout_lpOverlapped);
|
2021-02-06 07:45:34 +00:00
|
|
|
};
|
|
|
|
|
2022-04-15 06:39:48 +00:00
|
|
|
errno_t __dos2errno(uint32_t) hidden;
|
2020-11-28 20:01:51 +00:00
|
|
|
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
int32_t __sys_accept(int32_t, void *, uint32_t *, int) dontdiscard hidden;
|
|
|
|
int32_t __sys_accept4(int32_t, void *, uint32_t *, int) dontdiscard hidden;
|
2022-06-22 10:04:25 +00:00
|
|
|
int32_t __sys_bind(int32_t, const void *, uint32_t) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int32_t __sys_connect(int32_t, const void *, uint32_t) hidden;
|
|
|
|
int32_t __sys_getpeername(int32_t, void *, uint32_t *) hidden;
|
2022-06-22 10:04:25 +00:00
|
|
|
int32_t __sys_getsockname(int32_t, void *, uint32_t *) hidden;
|
|
|
|
int32_t __sys_socket(int32_t, int32_t, int32_t) hidden;
|
2021-03-17 05:44:54 +00:00
|
|
|
int32_t __sys_socketpair(int32_t, int32_t, int32_t, int32_t[2]) hidden;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
Import C++ Standard Template Library
You can now use the hardest fastest and most dangerous language there is
with Cosmopolitan. So far about 75% of LLVM libcxx has been added. A few
breaking changes needed to be made to help this go smoothly.
- Rename nothrow to dontthrow
- Rename nodiscard to dontdiscard
- Add some libm functions, e.g. lgamma, nan, etc.
- Change intmax_t from int128 to int64 like everything else
- Introduce %jjd formatting directive for int128_t
- Introduce strtoi128(), strtou128(), etc.
- Rename bsrmax() to bsr128()
Some of the templates that should be working currently are std::vector,
std::string, std::map, std::set, std::deque, etc.
2022-03-22 12:51:41 +00:00
|
|
|
int32_t sys_accept4(int32_t, void *, uint32_t *, int) dontdiscard hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int32_t sys_accept(int32_t, void *, uint32_t *) hidden;
|
|
|
|
int32_t sys_bind(int32_t, const void *, uint32_t) hidden;
|
|
|
|
int32_t sys_connect(int32_t, const void *, uint32_t) hidden;
|
|
|
|
int32_t sys_getsockopt(int32_t, int32_t, int32_t, void *, uint32_t *) hidden;
|
|
|
|
int32_t sys_listen(int32_t, int32_t) hidden;
|
|
|
|
int32_t sys_getsockname(int32_t, void *, uint32_t *) hidden;
|
|
|
|
int32_t sys_getpeername(int32_t, void *, uint32_t *) hidden;
|
|
|
|
int32_t sys_poll(struct pollfd *, uint64_t, signed) hidden;
|
|
|
|
int32_t sys_shutdown(int32_t, int32_t) hidden;
|
|
|
|
int32_t sys_socket(int32_t, int32_t, int32_t) hidden;
|
2021-03-17 05:05:59 +00:00
|
|
|
int32_t sys_socketpair(int32_t, int32_t, int32_t, int32_t[2]) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int64_t sys_readv(int32_t, const struct iovec *, int32_t) hidden;
|
|
|
|
int64_t sys_writev(int32_t, const struct iovec *, int32_t) hidden;
|
|
|
|
ssize_t sys_recvfrom(int, void *, size_t, int, void *, uint32_t *) hidden;
|
|
|
|
ssize_t sys_sendto(int, const void *, size_t, int, const void *,
|
|
|
|
uint32_t) hidden;
|
2021-04-08 05:53:23 +00:00
|
|
|
ssize_t sys_sendmsg(int, const struct msghdr *, int) hidden;
|
|
|
|
ssize_t sys_recvmsg(int, struct msghdr *, int) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int32_t sys_select(int32_t, fd_set *, fd_set *, fd_set *,
|
|
|
|
struct timeval *) hidden;
|
2022-08-06 16:56:17 +00:00
|
|
|
int sys_pselect(int, fd_set *, fd_set *, fd_set *, const struct timespec *,
|
|
|
|
const sigset_t *);
|
2021-02-04 03:35:29 +00:00
|
|
|
int sys_setsockopt(int, int, int, const void *, uint32_t) hidden;
|
|
|
|
int32_t sys_epoll_create(int32_t) hidden;
|
|
|
|
int32_t sys_epoll_ctl(int32_t, int32_t, int32_t, void *) hidden;
|
|
|
|
int32_t sys_epoll_wait(int32_t, void *, int32_t, int32_t) hidden;
|
2021-09-28 05:58:51 +00:00
|
|
|
int sys_poll_metal(struct pollfd *, size_t, unsigned);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2022-04-15 06:39:48 +00:00
|
|
|
int sys_poll_nt(struct pollfd *, uint64_t, uint64_t *) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int sys_socket_nt(int, int, int) hidden;
|
2021-03-17 05:05:59 +00:00
|
|
|
/*
|
|
|
|
int sys_socketpair_nt_stream(int, int, int, int[2]) hidden;
|
|
|
|
int sys_socketpair_nt_dgram(int, int, int, int[2]) hidden;
|
|
|
|
*/
|
|
|
|
int sys_socketpair_nt(int, int, int, int[2]) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int sys_select_nt(int, fd_set *, fd_set *, fd_set *, struct timeval *) hidden;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2022-04-18 15:54:42 +00:00
|
|
|
bool __asan_is_valid_msghdr(const struct msghdr *);
|
2022-04-15 06:39:48 +00:00
|
|
|
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
size_t __iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *,
|
|
|
|
size_t) hidden;
|
2022-03-19 10:37:00 +00:00
|
|
|
ssize_t sys_sendto_nt(int, const struct iovec *, size_t, uint32_t, void *,
|
|
|
|
uint32_t) hidden;
|
2020-06-15 14:18:57 +00:00
|
|
|
|
2021-02-27 18:33:32 +00:00
|
|
|
void WinSockInit(void) hidden;
|
2020-11-28 20:01:51 +00:00
|
|
|
int64_t __winsockerr(void) nocallback hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int __fixupnewsockfd(int, int) hidden;
|
2022-06-26 01:17:31 +00:00
|
|
|
int __wsablock(int64_t, struct NtOverlapped *, uint32_t *, bool,
|
|
|
|
uint32_t) hidden;
|
|
|
|
int64_t __winsockblock(int64_t, unsigned, int64_t, uint32_t) hidden;
|
2022-04-08 03:30:04 +00:00
|
|
|
struct SockFd *_dupsockfd(struct SockFd *) hidden;
|
2022-04-15 06:39:48 +00:00
|
|
|
int64_t GetNtBaseSocket(int64_t) hidden;
|
2021-02-04 03:35:29 +00:00
|
|
|
int sys_close_epoll(int) hidden;
|
2020-11-28 20:01:51 +00:00
|
|
|
|
2022-06-22 10:04:25 +00:00
|
|
|
int sockaddr2bsd(const void *, uint32_t, union sockaddr_storage_bsd *,
|
|
|
|
uint32_t *);
|
|
|
|
void sockaddr2linux(const union sockaddr_storage_bsd *, uint32_t,
|
|
|
|
union sockaddr_storage_linux *, uint32_t *);
|
2020-06-15 14:18:57 +00:00
|
|
|
|
|
|
|
COSMOPOLITAN_C_END_
|
|
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
|
|
#endif /* COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_ */
|