2020-06-15 07:18:57 -07:00
|
|
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
|
|
|
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
|
|
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
|
|
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ Permission to use, copy, modify, and/or distribute this software for │
|
|
|
|
│ any purpose with or without fee is hereby granted, provided that the │
|
|
|
|
│ above copyright notice and this permission notice appear in all copies. │
|
2020-06-15 07:18:57 -07:00
|
|
|
│ │
|
2020-12-27 17:18:44 -08:00
|
|
|
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
|
|
|
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
|
|
|
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
|
|
|
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
|
|
|
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
|
|
|
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
|
|
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
|
|
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
2020-06-15 07:18:57 -07:00
|
|
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
2022-04-14 23:39:48 -07:00
|
|
|
#include "libc/calls/calls.h"
|
2020-06-15 07:18:57 -07:00
|
|
|
#include "libc/dce.h"
|
2022-09-12 23:10:38 -07:00
|
|
|
#include "libc/intrin/strace.internal.h"
|
2022-03-20 08:01:14 -07:00
|
|
|
#include "libc/mem/mem.h"
|
2021-02-03 06:22:51 -08:00
|
|
|
#include "libc/nt/runtime.h"
|
2020-06-15 07:18:57 -07:00
|
|
|
#include "libc/nt/winsock.h"
|
|
|
|
#include "libc/runtime/runtime.h"
|
|
|
|
#include "libc/sock/internal.h"
|
|
|
|
|
|
|
|
#define VERSION 0x0202 /* Windows Vista+ */
|
|
|
|
|
|
|
|
/**
|
2022-07-21 23:53:30 -04:00
|
|
|
* Information about underlying Windows Sockets implementation.
|
2020-06-15 07:18:57 -07:00
|
|
|
*
|
2023-07-26 13:54:49 -07:00
|
|
|
* Cosmopolitan automatically calls __yoink() on this symbol when its
|
2020-06-15 07:18:57 -07:00
|
|
|
* Berkeley Socket wrappers are linked. The latest version of Winsock
|
|
|
|
* was introduced alongside x64, so this should never fail.
|
|
|
|
*/
|
2023-07-24 08:31:54 -07:00
|
|
|
struct NtWsaData kNtWsaData;
|
2020-06-15 07:18:57 -07:00
|
|
|
|
2021-02-27 10:33:32 -08:00
|
|
|
static textwindows void WinSockCleanup(void) {
|
2022-04-14 23:39:48 -07:00
|
|
|
int i, rc;
|
2023-07-10 04:29:46 -07:00
|
|
|
(void)rc;
|
2022-04-14 23:39:48 -07:00
|
|
|
rc = WSACleanup();
|
2022-04-16 10:40:23 -07:00
|
|
|
NTTRACE("WSACleanup() → %d% lm", rc);
|
2020-11-13 01:27:49 -08:00
|
|
|
}
|
|
|
|
|
2023-07-26 13:54:49 -07:00
|
|
|
textwindows dontasan void WinSockInit(void) {
|
2020-06-15 07:18:57 -07:00
|
|
|
int rc;
|
2021-02-27 10:33:32 -08:00
|
|
|
atexit(WinSockCleanup);
|
2022-04-16 10:40:23 -07:00
|
|
|
NTTRACE("WSAStartup()");
|
2020-06-15 07:18:57 -07:00
|
|
|
if ((rc = WSAStartup(VERSION, &kNtWsaData)) != 0 ||
|
|
|
|
kNtWsaData.wVersion != VERSION) {
|
2023-07-30 14:26:21 -07:00
|
|
|
ExitProcess(1 << 8);
|
2020-06-15 07:18:57 -07:00
|
|
|
}
|
|
|
|
}
|