mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Make more fixes and improvements
- Remove PAGESIZE constant - Fix realloc() documentation - Fix ttyname_r() error reporting - Make forking more reliable on Windows - Make execvp() a few microseconds faster - Make system() a few microseconds faster - Tighten up the socket-related magic numbers - Loosen restrictions on mmap() offset alignment - Improve GetProgramExecutableName() with getenv("_") - Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd() - Fix flakes in pthread_cancel_test, unix_test, fork_test - Fix recently introduced futex stack overflow regression - Let sockets be passed as stdio to subprocesses on Windows - Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
parent
140a8a52e5
commit
18bb5888e1
311 changed files with 1239 additions and 2622 deletions
|
@ -16,14 +16,19 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/calls/internal.h"
|
||||
#include "libc/calls/state.internal.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/intrin/kprintf.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nt/enum/fileflagandattributes.h"
|
||||
#include "libc/nt/iphlpapi.h"
|
||||
#include "libc/nt/winsock.h"
|
||||
#include "libc/sock/internal.h"
|
||||
#include "libc/sock/yoink.inc"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/af.h"
|
||||
#include "libc/sysv/consts/ipproto.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/so.h"
|
||||
|
@ -42,13 +47,22 @@ __static_yoink("_dupsockfd");
|
|||
textwindows int sys_socket_nt(int family, int type, int protocol) {
|
||||
int64_t h;
|
||||
struct SockFd *sockfd;
|
||||
int fd, oflags, truetype;
|
||||
int fd, oflags, truetype, yes = 1;
|
||||
fd = __reservefd(-1);
|
||||
if (fd == -1) return -1;
|
||||
truetype = type & ~(SOCK_CLOEXEC | SOCK_NONBLOCK);
|
||||
if ((h = WSASocket(family, truetype, protocol, NULL, 0,
|
||||
kNtWsaFlagOverlapped)) != -1) {
|
||||
oflags = 0;
|
||||
|
||||
// sets SO_EXCLUSIVEADDRUSE on all sockets so they won't get pilfered
|
||||
// you can read a blog post on this subject in the find_unused_port()
|
||||
// pydoc of this file third_party/python/Lib/test/support/__init__.py
|
||||
// this needs to happen right after socket is called or it won't work
|
||||
if (family == AF_INET || family == AF_INET6) {
|
||||
unassert(__sys_setsockopt_nt(h, SOL_SOCKET, -5, &yes, 4) != -1);
|
||||
}
|
||||
|
||||
oflags = O_RDWR;
|
||||
if (type & SOCK_CLOEXEC) oflags |= O_CLOEXEC;
|
||||
if (type & SOCK_NONBLOCK) oflags |= O_NONBLOCK;
|
||||
sockfd = calloc(1, sizeof(struct SockFd));
|
||||
|
@ -62,6 +76,7 @@ textwindows int sys_socket_nt(int family, int type, int protocol) {
|
|||
g_fds.p[fd].handle = h;
|
||||
g_fds.p[fd].extra = (uintptr_t)sockfd;
|
||||
__fds_unlock();
|
||||
|
||||
return fd;
|
||||
} else {
|
||||
__releasefd(fd);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue