cosmopolitan/libc/sock/internal.h

166 lines
6.2 KiB
C
Raw Normal View History

2020-06-15 14:18:57 +00:00
#ifndef COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_
#define COSMOPOLITAN_LIBC_SOCK_INTERNAL_H_
#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"
#include "libc/sock/select.h"
2020-06-15 14:18:57 +00:00
#include "libc/sock/sock.h"
Prove that Makefile is fully defined The whole repository is now buildable with GNU Make Landlock sandboxing. This proves that no Makefile targets exist which touch files other than their declared prerequisites. In order to do this, we had to: 1. Stop code morphing GCC output in package.com and instead run a newly introduced FIXUPOBJ.COM command after GCC invocations. 2. Disable all the crumby Python unit tests that do things like create files in the current directory, or rename() files between folders. This ended up being a lot of tests, but most of them are still ok. 3. Introduce an .UNSANDBOXED variable to GNU Make to disable Landlock. We currently only do this for things like `make tags`. 4. This change deletes some GNU Make code that was preventing the execve() optimization from working. This means it should no longer be necessary in most cases for command invocations to be indirected through the cocmd interpreter. 5. Missing dependencies had to be declared in certain places, in cases where they couldn't be automatically determined by MKDEPS.COM 6. The libcxx header situation has finally been tamed. One of the things that makes this difficult is MKDEPS.COM only wants to consider the first 64kb of a file, in order to go fast. But libcxx likes to have #include lines buried after huge documentation. 7. An .UNVEIL variable has been introduced to GNU Make just in case we ever wish to explicitly specify additional things that need to be whitelisted which aren't strictly prerequisites. This works in a manner similar to the recently introduced .EXTRA_PREREQS feature. There's now a new build/bootstrap/make.com prebuilt binary available. It should no longer be possible to write invalid Makefile code.
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
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];
};
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];
};
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 {
Add /statusz page to redbean plus other enhancements redbean improvements: - Explicitly disable corking - Simulate Python regex API for Lua - Send warmup requests in main process on startup - Add Class-A granular IPv4 network classification - Add /statusz page so you can monitor your redbean's health - Fix regressions on OpenBSD/NetBSD caused by recent changes - Plug Authorization header into Lua GetUser and GetPass APIs - Recognize X-Forwarded-{For,Host} from local reverse proxies - Add many additional functions to redbean Lua server page API - Report resource usage of child processes on `/` listing page - Introduce `-a` flag for logging child process resource usage - Introduce `-t MILLIS` flag and `ProgramTimeout(ms)` init API - Introduce `-H "Header: value"` flag and `ProgramHeader(k,v)` API Cosmopolitan Libc improvements: - Make strerror() simpler - Make inet_pton() not depend on sscanf() - Fix OpenExecutable() which broke .data section earlier - Fix stdio in cases where it overflows kernel tty buffer - Fix bugs in crash reporting w/o .com.dbg binary present - Add polyfills for SO_LINGER, SO_RCVTIMEO, and SO_SNDTIMEO - Polyfill TCP_CORK on BSD and XNU using TCP_NOPUSH magnums New netcat clone in examples/nc.c: While testing some of the failure conditions for redbean, I noticed that BusyBox's `nc` command is pretty busted, if you use it as an interactive tool, rather than having it be part of a pipeline. Unfortunately this'll only work on UNIX since Windows doesn't let us poll on stdio and sockets at the same time because I don't think they want tools like this running on their platform. So if you want forbidden fruit, it's here so enjoy it
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;
Add /statusz page to redbean plus other enhancements redbean improvements: - Explicitly disable corking - Simulate Python regex API for Lua - Send warmup requests in main process on startup - Add Class-A granular IPv4 network classification - Add /statusz page so you can monitor your redbean's health - Fix regressions on OpenBSD/NetBSD caused by recent changes - Plug Authorization header into Lua GetUser and GetPass APIs - Recognize X-Forwarded-{For,Host} from local reverse proxies - Add many additional functions to redbean Lua server page API - Report resource usage of child processes on `/` listing page - Introduce `-a` flag for logging child process resource usage - Introduce `-t MILLIS` flag and `ProgramTimeout(ms)` init API - Introduce `-H "Header: value"` flag and `ProgramHeader(k,v)` API Cosmopolitan Libc improvements: - Make strerror() simpler - Make inet_pton() not depend on sscanf() - Fix OpenExecutable() which broke .data section earlier - Fix stdio in cases where it overflows kernel tty buffer - Fix bugs in crash reporting w/o .com.dbg binary present - Add polyfills for SO_LINGER, SO_RCVTIMEO, and SO_SNDTIMEO - Polyfill TCP_CORK on BSD and XNU using TCP_NOPUSH magnums New netcat clone in examples/nc.c: While testing some of the failure conditions for redbean, I noticed that BusyBox's `nc` command is pretty busted, if you use it as an interactive tool, rather than having it be part of a pipeline. Unfortunately this'll only work on UNIX since Windows doesn't let us poll on stdio and sockets at the same time because I don't think they want tools like this running on their platform. So if you want forbidden fruit, it's here so enjoy it
2021-04-23 17:45:19 +00:00
char sun_path[108];
2021-04-02 02:32:39 +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;
};
/* ------------------------------------------------------------------------------------*/
#define SOCKFD_OVERLAP_BUFSIZ 128
2021-02-06 07:45:34 +00:00
struct SockFd {
int family;
int type;
int protocol;
uint32_t rcvtimeo;
uint32_t sndtimeo;
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
};
errno_t __dos2errno(uint32_t) hidden;
int32_t __sys_accept(int32_t, void *, uint32_t *, int) dontdiscard hidden;
int32_t __sys_accept4(int32_t, void *, uint32_t *, int) dontdiscard 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_getpeername(int32_t, void *, uint32_t *) hidden;
int32_t __sys_getsockname(int32_t, void *, uint32_t *) hidden;
int32_t __sys_socket(int32_t, int32_t, int32_t) hidden;
int32_t __sys_socketpair(int32_t, int32_t, int32_t, int32_t[2]) hidden;
2020-06-15 14:18:57 +00:00
int32_t sys_accept4(int32_t, void *, uint32_t *, int) dontdiscard hidden;
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;
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;
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 *);
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;
Make numerous improvements - Python static hello world now 1.8mb - Python static fully loaded now 10mb - Python HTTPS client now uses MbedTLS - Python REPL now completes import stmts - Increase stack size for Python for now - Begin synthesizing posixpath and ntpath - Restore Python \N{UNICODE NAME} support - Restore Python NFKD symbol normalization - Add optimized code path for Intel SHA-NI - Get more Python unit tests passing faster - Get Python help() pagination working on NT - Python hashlib now supports MbedTLS PBKDF2 - Make memcpy/memmove/memcmp/bcmp/etc. faster - Add Mersenne Twister and Vigna to LIBC_RAND - Provide privileged __printf() for error code - Fix zipos opendir() so that it reports ENOTDIR - Add basic chmod() implementation for Windows NT - Add Cosmo's best functions to Python cosmo module - Pin function trace indent depth to that of caller - Show memory diagram on invalid access in MODE=dbg - Differentiate stack overflow on crash in MODE=dbg - Add stb_truetype and tools for analyzing font files - Upgrade to UNICODE 13 and reduce its binary footprint - COMPILE.COM now logs resource usage of build commands - Start implementing basic poll() support on bare metal - Set getauxval(AT_EXECFN) to GetModuleFileName() on NT - Add descriptions to strerror() in non-TINY build modes - Add COUNTBRANCH() macro to help with micro-optimizations - Make error / backtrace / asan / memory code more unbreakable - Add fast perfect C implementation of μ-Law and a-Law audio codecs - Make strtol() functions consistent with other libc implementations - Improve Linenoise implementation (see also github.com/jart/bestline) - COMPILE.COM now suppresses stdout/stderr of successful build commands
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
int sys_poll_nt(struct pollfd *, uint64_t, uint64_t *) hidden;
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;
int sys_select_nt(int, fd_set *, fd_set *, fd_set *, struct timeval *) hidden;
2020-06-15 14:18:57 +00:00
bool __asan_is_valid_msghdr(const struct msghdr *);
ssize_t sys_send_nt(int, const struct iovec *, size_t, uint32_t) hidden;
size_t __iovec2nt(struct NtIovec[hasatleast 16], const struct iovec *,
size_t) hidden;
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;
int64_t __winsockerr(void) nocallback hidden;
int __fixupnewsockfd(int, int) hidden;
int __wsablock(int64_t, struct NtOverlapped *, uint32_t *, bool,
uint32_t) hidden;
int64_t __winsockblock(int64_t, unsigned, int64_t, uint32_t) hidden;
struct SockFd *_dupsockfd(struct SockFd *) hidden;
int64_t GetNtBaseSocket(int64_t) hidden;
int sys_close_epoll(int) hidden;
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_ */