From 7848b5e560984904cf8aa9c8b7d737dc47828662 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 16 May 2022 22:30:14 +0000 Subject: [PATCH] Merge in mingw changes. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3873 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- Makefile | 131 ++++++++++++++++++++++++++++++++++++------ src/bcrypt.js.c | 10 ++++ src/file.js.c | 39 +++++++++---- src/main.c | 18 +++--- src/ssb.c | 4 +- src/ssb.connections.c | 2 +- src/ssb.export.c | 4 ++ src/task.c | 4 +- src/taskstub.js.c | 3 - src/tests.c | 5 ++ src/tls.c | 17 +++++- src/trace.c | 1 + 12 files changed, 188 insertions(+), 50 deletions(-) diff --git a/Makefile b/Makefile index 0da36c67..7d84546d 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ PROJECT = tildefriends BUILD_DIR ?= out BUILD_DIR_DBG := $(BUILD_DIR)/debug BUILD_DIR_REL := $(BUILD_DIR)/release +BUILD_DIR_WIN := $(BUILD_DIR)/win UNAME_M := $(shell uname -m) CFLAGS += \ @@ -16,6 +17,10 @@ LDFLAGS += -Wl,-gc-sections debug: CFLAGS += -Og -g release: CFLAGS += -DNDEBUG -O3 +win: CC = i686-w64-mingw32-gcc-win32 +win: AS = $(CC) +win: CFLAGS += -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00 -DNTDDI_VERSION=NTDDI_WIN10 +win: LDFLAGS += -static ifeq ($(UNAME_M),x86_64) debug: CFLAGS += -fsanitize=address -fsanitize=undefined @@ -25,7 +30,8 @@ endif APP_SOURCES = $(wildcard src/*.c) APP_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(APP_SOURCES)) APP_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(APP_SOURCES)) -APP_OBJS := $(APP_OBJS_DBG) $(APP_OBJS_REL) +APP_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(APP_SOURCES)) +APP_OBJS := $(APP_OBJS_DBG) $(APP_OBJS_REL) $(APP_OBJS_WIN) $(APP_OBJS): CFLAGS += \ -Ideps/base64c/include \ -Ideps/crypt_blowfish \ @@ -34,12 +40,14 @@ $(APP_OBJS): CFLAGS += \ -Ideps/libuv/include \ -Ideps/xopt \ -Ideps/libsodium \ + -Ideps/libsodium/src/libsodium/include \ -Werror BASE64C_SOURCES = deps/base64c/src/base64c.c BASE64C_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BASE64C_SOURCES)) BASE64C_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BASE64C_SOURCES)) -BASE64C_OBJS := $(BASE64C_OBJS_DBG) $(BASE64C_OBJS_REL) +BASE64C_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(BASE64C_SOURCES)) +BASE64C_OBJS := $(BASE64C_OBJS_DBG) $(BASE64C_OBJS_REL) $(BASE64C_OBJS_WIN) $(BASE64C_OBJS): CFLAGS += \ -Wno-sign-compare @@ -47,9 +55,12 @@ BLOWFISH_SOURCES = \ deps/crypt_blowfish/crypt_blowfish.c \ deps/crypt_blowfish/crypt_gensalt.c \ deps/crypt_blowfish/wrapper.c +BLOWFISH_SOURCES_WIN = \ + deps/crypt_blowfish/x86.S BLOWFISH_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BLOWFISH_SOURCES)) BLOWFISH_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(BLOWFISH_SOURCES)) -BLOWFISH_OBJS := $(BLOWFISH_OBJS_DBG) $(BLOWFISH_OBJS_REL) +BLOWFISH_OBJS_WIN = $(patsubst %.S,$(BUILD_DIR_WIN)/%.o,$(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(BLOWFISH_SOURCES) $(BLOWFISH_SOURCES_WIN))) +BLOWFISH_OBJS := $(BLOWFISH_OBJS_DBG) $(BLOWFISH_OBJS_REL) $(BLOWFISH_OBJS_WIN) UV_SOURCES = \ deps/libuv/src/fs-poll.c \ @@ -59,6 +70,10 @@ UV_SOURCES = \ deps/libuv/src/strscpy.c \ deps/libuv/src/threadpool.c \ deps/libuv/src/timer.c \ + deps/libuv/src/uv-common.c \ + deps/libuv/src/uv-data-getter-setters.c \ + deps/libuv/src/version.c +UV_SOURCES_UNIX = \ deps/libuv/src/unix/async.c \ deps/libuv/src/unix/core.c \ deps/libuv/src/unix/dl.c \ @@ -84,13 +99,37 @@ UV_SOURCES = \ deps/libuv/src/unix/tcp.c \ deps/libuv/src/unix/thread.c \ deps/libuv/src/unix/tty.c \ - deps/libuv/src/unix/udp.c \ - deps/libuv/src/uv-common.c \ - deps/libuv/src/uv-data-getter-setters.c \ - deps/libuv/src/version.c -UV_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(UV_SOURCES)) -UV_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(UV_SOURCES)) -UV_OBJS := $(UV_OBJS_DBG) $(UV_OBJS_REL) + deps/libuv/src/unix/udp.c +UV_SOURCES_WIN = \ + deps/libuv/src/win/async.c \ + deps/libuv/src/win/core.c \ + deps/libuv/src/win/detect-wakeup.c \ + deps/libuv/src/win/dl.c \ + deps/libuv/src/win/error.c \ + deps/libuv/src/win/fs-event.c \ + deps/libuv/src/win/fs.c \ + deps/libuv/src/win/getaddrinfo.c \ + deps/libuv/src/win/getnameinfo.c \ + deps/libuv/src/win/handle.c \ + deps/libuv/src/win/loop-watcher.c \ + deps/libuv/src/win/pipe.c \ + deps/libuv/src/win/poll.c \ + deps/libuv/src/win/process-stdio.c \ + deps/libuv/src/win/process.c \ + deps/libuv/src/win/signal.c \ + deps/libuv/src/win/snprintf.c \ + deps/libuv/src/win/stream.c \ + deps/libuv/src/win/tcp.c \ + deps/libuv/src/win/thread.c \ + deps/libuv/src/win/tty.c \ + deps/libuv/src/win/udp.c \ + deps/libuv/src/win/util.c \ + deps/libuv/src/win/winapi.c \ + deps/libuv/src/win/winsock.c +UV_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(UV_SOURCES) $(UV_SOURCES_UNIX)) +UV_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(UV_SOURCES) $(UV_SOURCES_UNIX)) +UV_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(UV_SOURCES) $(UV_SOURCES_WIN)) +UV_OBJS := $(UV_OBJS_DBG) $(UV_OBJS_REL) $(UV_OBJS_WIN) $(UV_OBJS): CFLAGS += \ -Ideps/libuv/include \ -Ideps/libuv/src \ @@ -107,11 +146,15 @@ SODIUM_SOURCES = \ deps/libsodium/src/libsodium/crypto_core/ed25519/ref10/ed25519_ref10.c \ deps/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.c \ deps/libsodium/src/libsodium/crypto_core/salsa/ref/core_salsa_ref.c \ + deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/generichash_blake2b.c \ deps/libsodium/src/libsodium/crypto_hash/sha256/cp/hash_sha256_cp.c \ deps/libsodium/src/libsodium/crypto_hash/sha256/hash_sha256.c \ deps/libsodium/src/libsodium/crypto_hash/sha512/cp/hash_sha512_cp.c \ deps/libsodium/src/libsodium/crypto_onetimeauth/poly1305/donna/poly1305_donna.c \ deps/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.c \ + deps/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-core.c \ + deps/libsodium/src/libsodium/crypto_pwhash/argon2/argon2-fill-block-ref.c \ + deps/libsodium/src/libsodium/crypto_pwhash/argon2/blake2b-long.c \ deps/libsodium/src/libsodium/crypto_scalarmult/crypto_scalarmult.c \ deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c \ deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c \ @@ -123,14 +166,22 @@ SODIUM_SOURCES = \ deps/libsodium/src/libsodium/crypto_stream/salsa20/ref/salsa20_ref.c \ deps/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.c \ deps/libsodium/src/libsodium/crypto_stream/xsalsa20/stream_xsalsa20.c \ + deps/libsodium/src/libsodium/crypto_stream/chacha20/stream_chacha20.c \ + deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-ref.c \ + deps/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.c \ + deps/libsodium/src/libsodium/crypto_generichash/blake2b/ref/blake2b-compress-ref.c \ + deps/libsodium/src/libsodium/crypto_secretbox/xsalsa20poly1305/secretbox_xsalsa20poly1305.c \ + deps/libsodium/src/libsodium/crypto_sign/ed25519/sign_ed25519.c \ deps/libsodium/src/libsodium/crypto_verify/sodium/verify.c \ deps/libsodium/src/libsodium/randombytes/randombytes.c \ deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \ deps/libsodium/src/libsodium/sodium/core.c \ + deps/libsodium/src/libsodium/sodium/runtime.c \ deps/libsodium/src/libsodium/sodium/utils.c SODIUM_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SODIUM_SOURCES)) SODIUM_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(SODIUM_SOURCES)) -SODIUM_OBJS := $(SODIUM_OBJS_DBG) $(SODIUM_OBJS_REL) +SODIUM_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(SODIUM_SOURCES)) +SODIUM_OBJS := $(SODIUM_OBJS_DBG) $(SODIUM_OBJS_REL) $(SODIUM_OBJS_WIN) $(SODIUM_OBJS): CFLAGS += \ -DCONFIGURED=1 \ -DMINIMAL=1 \ @@ -141,7 +192,8 @@ $(SODIUM_OBJS): CFLAGS += \ SQLITE_SOURCES = deps/sqlite/sqlite3.c SQLITE_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SQLITE_SOURCES)) SQLITE_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(SQLITE_SOURCES)) -SQLITE_OBJS := $(SQLITE_OBJS_DBG) $(SQLITE_OBJS_REL) +SQLITE_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(SQLITE_SOURCES)) +SQLITE_OBJS := $(SQLITE_OBJS_DBG) $(SQLITE_OBJS_REL) $(SQLITE_OBJS_WIN) $(SQLITE_OBJS): CFLAGS += \ -DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \ -DSQLITE_ENABLE_JSON1 \ @@ -162,7 +214,14 @@ $(SQLITE_OBJS): CFLAGS += \ XOPT_SOURCES = deps/xopt/xopt.c XOPT_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(XOPT_SOURCES)) XOPT_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(XOPT_SOURCES)) -XOPT_OBJS := $(XOPT_OBJS_DBG) $(XOPT_OBJS_REL) +XOPT_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(XOPT_SOURCES)) +XOPT_OBJS := $(XOPT_OBJS_DBG) $(XOPT_OBJS_REL) $(XOPT_OBJS_WIN) +$(XOPT_OBJS_WIN): CFLAGS += \ + -DHAVE_SNPRINTF \ + -DHAVE_VSNPRINTF \ + -DHAVE_VASNPRINTF \ + -DHAVE_VASPRINTF \ + -Dvsnprintf=rpl_vsnprintf QUICKJS_SOURCES = \ deps/quickjs/cutils.c \ @@ -173,7 +232,8 @@ QUICKJS_SOURCES = \ deps/quickjs/quickjs.c QUICKJS_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(QUICKJS_SOURCES)) QUICKJS_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(QUICKJS_SOURCES)) -QUICKJS_OBJS := $(QUICKJS_OBJS_DBG) $(QUICKJS_OBJS_REL) +QUICKJS_OBJS_WIN = $(patsubst %.c,$(BUILD_DIR_WIN)/%.o,$(QUICKJS_SOURCES)) +QUICKJS_OBJS := $(QUICKJS_OBJS_DBG) $(QUICKJS_OBJS_REL) $(QUICKJS_OBJS_WIN) $(QUICKJS_OBJS): CFLAGS += \ -DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \ -DDUMP_LEAKS \ @@ -186,16 +246,27 @@ $(QUICKJS_OBJS): CFLAGS += \ LDFLAGS += \ -pthread \ + -lm +debug: LDFLAGS += \ -ldl \ - -lm \ -lssl \ - -lcrypto #\ - #-lsodium + -lcrypto +release: LDFLAGS += \ + -ldl \ + -lssl \ + -lcrypto +win: LDFLAGS += \ + -lwsock32 \ + -lws2_32 \ + -lkernel32 \ + -liphlpapi \ + -luserenv debug: $(BUILD_DIR_DBG)/$(PROJECT) release: $(BUILD_DIR_REL)/$(PROJECT) +win: $(BUILD_DIR_WIN)/$(PROJECT) all: debug release -.PHONY: all debug release +.PHONY: all debug release win ALL_APP_OBJS_DBG = \ $(APP_OBJS_DBG) \ @@ -215,7 +286,16 @@ ALL_APP_OBJS_REL = \ $(SQLITE_OBJS_REL) \ $(QUICKJS_OBJS_REL) \ $(XOPT_OBJS_REL) -ALL_APP_OBJS := $(ALL_APP_OBJS_DBG) $(ALL_APP_OBJS_REL) +ALL_APP_OBJS_WIN = \ + $(APP_OBJS_WIN) \ + $(BASE64C_OBJS_WIN) \ + $(BLOWFISH_OBJS_WIN) \ + $(UV_OBJS_WIN) \ + $(SODIUM_OBJS_WIN) \ + $(SQLITE_OBJS_WIN) \ + $(QUICKJS_OBJS_WIN) \ + $(XOPT_OBJS_WIN) +ALL_APP_OBJS := $(ALL_APP_OBJS_DBG) $(ALL_APP_OBJS_REL) $(ALL_APP_OBJS_WIN) DEPS = $(ALL_APP_OBJS:.o=.d) -include $(DEPS) @@ -226,6 +306,9 @@ $(BUILD_DIR_DBG)/$(PROJECT): $(ALL_APP_OBJS_DBG) $(BUILD_DIR_REL)/$(PROJECT): $(ALL_APP_OBJS_REL) $(CC) -o $@ $^ $(LDFLAGS) +$(BUILD_DIR_WIN)/$(PROJECT): $(ALL_APP_OBJS_WIN) + $(CC) -o $@ $^ $(LDFLAGS) + $(BUILD_DIR_DBG)/%.o: %.c @mkdir -p $(dir $@) @echo [c] $@ @@ -236,6 +319,16 @@ $(BUILD_DIR_REL)/%.o: %.c @echo [c] $@ @$(CC) $(CFLAGS) -c $< -o $@ +$(BUILD_DIR_WIN)/%.o: %.c + @mkdir -p $(dir $@) + @echo [c] $@ + @$(CC) $(CFLAGS) -c $< -o $@ + +$(BUILD_DIR_WIN)/%.o: %.S + @mkdir -p $(dir $@) + @echo [as] $@ + @$(AS) -c $< -o $@ + clean: rm -rf $(BUILD_DIR) .PHONY: clean diff --git a/src/bcrypt.js.c b/src/bcrypt.js.c index 3154c691..f2a278b9 100644 --- a/src/bcrypt.js.c +++ b/src/bcrypt.js.c @@ -2,7 +2,13 @@ #include "ow-crypt.h" +#if defined(_WIN32) +#define WIN32_LEAN_AND_MEAN +#include +extern BOOLEAN NTAPI SystemFunction036(PVOID Buffer, ULONG BufferLength); +#else #include +#endif JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); @@ -34,7 +40,11 @@ JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSVa int length; JS_ToInt32(context, &length, argv[0]); char buffer[16]; +#if defined(_WIN32) + ssize_t bytes = SystemFunction036(buffer, sizeof(buffer)) ? sizeof(buffer) : 0; +#else ssize_t bytes = getrandom(buffer, sizeof(buffer), 0); +#endif char output[7 + 22 + 1]; char* salt = crypt_gensalt_rn("$2b$", length, buffer, bytes, output, sizeof(output)); JSValue result = JS_NewString(context, salt); diff --git a/src/file.js.c b/src/file.js.c index 1527d246..f2299ecd 100644 --- a/src/file.js.c +++ b/src/file.js.c @@ -33,6 +33,13 @@ typedef struct file_stat_t { uv_fs_t _request; } file_stat_t; +typedef struct fs_req_t { + uv_fs_t fs; + uv_file file; + size_t size; + char buffer[]; +} fs_req_t; + void tf_file_register(JSContext* context) { JSValue global = JS_GetGlobalObject(context); @@ -59,6 +66,7 @@ static void _file_async_close_callback(uv_fs_t* req) static void _file_read_read_callback(uv_fs_t* req) { uv_fs_req_cleanup(req); + fs_req_t* fsreq = (fs_req_t*)req; tf_task_t* task = req->loop->data; JSContext* context = tf_task_get_context(task); promiseid_t promise = (promiseid_t)(intptr_t)req->data; @@ -78,7 +86,7 @@ static void _file_read_read_callback(uv_fs_t* req) { tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); } - int result = uv_fs_close(req->loop, req, req->file, _file_async_close_callback); + int result = uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); if (result < 0) { free(req); @@ -116,12 +124,15 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar promiseid_t promise = -1; JSValue promise_value = tf_task_allocate_promise(task, &promise); - uv_fs_t* req = malloc(sizeof(uv_fs_t) + k_file_read_max); - *req = (uv_fs_t) + fs_req_t* req = malloc(sizeof(fs_req_t) + k_file_read_max); + *req = (fs_req_t) { - .data = (void*)(intptr_t)promise, + .fs = + { + .data = (void*)(intptr_t)promise, + }, }; - int result = uv_fs_open(tf_task_get_loop(task), req, file_name, UV_FS_O_RDONLY, 0, _file_read_open_callback); + int result = uv_fs_open(tf_task_get_loop(task), &req->fs, file_name, UV_FS_O_RDONLY, 0, _file_read_open_callback); if (result < 0) { tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); @@ -134,6 +145,7 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar static void _file_write_write_callback(uv_fs_t* req) { uv_fs_req_cleanup(req); + fs_req_t* fsreq = (fs_req_t*)req; tf_task_t* task = req->loop->data; JSContext* context = tf_task_get_context(task); promiseid_t promise = (promiseid_t)(intptr_t)req->data; @@ -145,7 +157,7 @@ static void _file_write_write_callback(uv_fs_t* req) { tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(req->result))); } - uv_fs_close(req->loop, req, req->file, _file_async_close_callback); + uv_fs_close(req->loop, req, fsreq->file, _file_async_close_callback); } static void _file_write_open_callback(uv_fs_t* req) @@ -193,19 +205,22 @@ static JSValue _file_write_file(JSContext* context, JSValueConst this_val, int a promiseid_t promise = -1; JSValue promise_value = tf_task_allocate_promise(task, &promise); - uv_fs_t* req = malloc(sizeof(uv_fs_t) + sizeof(size_t) + size); - *req = (uv_fs_t) + fs_req_t* req = malloc(sizeof(fs_req_t) + size); + *req = (fs_req_t) { - .data = (void*)(intptr_t)promise, + .fs = + { + .data = (void*)(intptr_t)promise, + }, + .size = size, }; - memcpy(req + 1, &size, sizeof(size_t)); - memcpy((char*)(req + 1) + sizeof(size_t), buffer, size); + memcpy(req->buffer, buffer, size); if (!is_array_buffer) { JS_FreeCString(context, (const char*)buffer); } - int result = uv_fs_open(tf_task_get_loop(task), req, file_name, UV_FS_O_CREAT | UV_FS_O_WRONLY, 0644, _file_write_open_callback); + int result = uv_fs_open(tf_task_get_loop(task), &req->fs, file_name, UV_FS_O_CREAT | UV_FS_O_WRONLY, 0644, _file_write_open_callback); if (result < 0) { tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); diff --git a/src/main.c b/src/main.c index 00a8a7f7..cb4833f4 100644 --- a/src/main.c +++ b/src/main.c @@ -14,7 +14,7 @@ #include -#if !defined (_WIN32) && !defined (__MACH__) +#if !defined(_WIN32) && !defined(__MACH__) #include #include #include @@ -80,7 +80,7 @@ const command_t k_commands[] = { void shedPrivileges() { -#if !defined (_WIN32) +#if !defined(_WIN32) struct rlimit zeroLimit; zeroLimit.rlim_cur = 0; zeroLimit.rlim_max = 0; @@ -111,7 +111,7 @@ void shedPrivileges() perror("setrlimit(RLIMIT_NPROC, {0, 0})"); exit(-1); } -#if !defined (__MACH__) +#if !defined(__MACH__) if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0) { perror("setrlimit(RLIMIT_LOCKS, {0, 0})"); @@ -288,7 +288,7 @@ static int _tf_command_export(const char* file, int argc, char* argv[]) "/~cory/docs", "/~cory/ssb", }; - for (int i = 0; i < _countof(k_export); i++) + for (int i = 0; i < (int)_countof(k_export); i++) { printf("Exporting %s...\n", k_export[i]); tf_ssb_export(ssb, k_export[i]); @@ -417,7 +417,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[]) } int result = 0; -#if !defined (_WIN32) && !defined (__MACH__) +#if !defined(_WIN32) && !defined(__MACH__) setpgid(0, 0); #endif @@ -612,7 +612,7 @@ static int _tf_command_usage(const char* file, int argc, char* argv[]) { printf("Usage: %s command [command-options]\n", file); printf("commands:\n"); - for (int i = 0; i < _countof(k_commands); i++) + for (int i = 0; i < (int)_countof(k_commands); i++) { printf(" %s - %s\n", k_commands[i].name, k_commands[i].description); } @@ -621,11 +621,13 @@ static int _tf_command_usage(const char* file, int argc, char* argv[]) int main(int argc, char* argv[]) { +#if !defined(_WIN32) prctl(PR_SET_PDEATHSIG, SIGKILL); +#endif uv_setup_args(argc, argv); tf_taskstub_startup(); -#if !defined (_WIN32) +#if !defined(_WIN32) if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { perror("signal"); @@ -634,7 +636,7 @@ int main(int argc, char* argv[]) if (argc >= 2) { - for (int i = 0; i < _countof(k_commands); i++) + for (int i = 0; i < (int)_countof(k_commands); i++) { const command_t* command = &k_commands[i]; if (strcmp(argv[1], command->name) == 0) diff --git a/src/ssb.c b/src/ssb.c index 64d5cd42..85656958 100644 --- a/src/ssb.c +++ b/src/ssb.c @@ -7,8 +7,8 @@ #include #include #include -#include -#include +//#include +//#include #include #include #include diff --git a/src/ssb.connections.c b/src/ssb.connections.c index 4d98fab0..95277ec3 100644 --- a/src/ssb.connections.c +++ b/src/ssb.connections.c @@ -79,7 +79,7 @@ static void _tf_ssb_connections_timer(uv_timer_t* timer) tf_ssb_connections_t* connections = timer->data; tf_ssb_connection_t* active[4]; int count = tf_ssb_get_connections(connections->ssb, active, _countof(active)); - if (count < _countof(active)) + if (count < (int)_countof(active)) { char host[256]; int port; diff --git a/src/ssb.export.c b/src/ssb.export.c index c6651e29..e18b7f9d 100644 --- a/src/ssb.export.c +++ b/src/ssb.export.c @@ -24,7 +24,11 @@ static void _write_file(const char* path, void* blob, size_t size) static void _make_dir(const char* path) { +#if defined(_WIN32) + if (mkdir(path) && errno != EEXIST) +#else if (mkdir(path, 0755) && errno != EEXIST) +#endif { printf("Failed to create directory %s: %s.\n", path, strerror(errno)); } diff --git a/src/task.c b/src/task.c index 93d3321a..05cd9f48 100644 --- a/src/task.c +++ b/src/task.c @@ -24,9 +24,7 @@ #include "quickjs.h" #include "quickjs-libc.h" -#ifdef _WIN32 -static const int STDIN_FILENO = 0; -#else +#ifndef _WIN32 #include #endif diff --git a/src/taskstub.js.c b/src/taskstub.js.c index c0996959..55a51d22 100644 --- a/src/taskstub.js.c +++ b/src/taskstub.js.c @@ -15,9 +15,6 @@ #include #include #include -static const int STDIN_FILENO = 0; -static const int STDOUT_FILENO = 1; -static const int STDERR_FILENO = 2; #else #include #endif diff --git a/src/tests.c b/src/tests.c index b5f76717..34db242e 100644 --- a/src/tests.c +++ b/src/tests.c @@ -9,6 +9,11 @@ #include #include +#if defined(_WIN32) +#define WIFEXITED(x) 1 +#define WEXITSTATUS(x) (x) +#endif + static void _test_nop(const tf_test_options_t* options) { FILE* file = fopen("out/test.js", "w"); diff --git a/src/tls.c b/src/tls.c index d94a2ed3..1dbfbeca 100644 --- a/src/tls.c +++ b/src/tls.c @@ -2,6 +2,7 @@ #if defined(_WIN32) #define TF_TLS_SCHANNEL +#include #elif defined(__MACH__) #define TF_TLS_APPLE #else @@ -394,6 +395,7 @@ TlsContext* TlsContext::create() return new TlsContext_osx(); } #elif defined (_WIN32) +#if 0 #include #include #include @@ -1038,6 +1040,7 @@ TlsContext* TlsContext::create() { return new TlsContext_sspi(); } +#endif #else TlsContext* TlsContext::create() { @@ -1084,6 +1087,7 @@ bool tf_tls_context_set_certificate(tf_tls_context_t* context, const char* certi return result == 1; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return false; #endif } @@ -1099,6 +1103,7 @@ bool tf_tls_context_set_private_key(tf_tls_context_t* context, const char* priva return result == 1; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return false; #endif } @@ -1123,6 +1128,7 @@ bool tf_tls_context_add_trusted_certificate(tf_tls_context_t* context, const cha return result; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return false; #endif } @@ -1137,6 +1143,7 @@ tf_tls_session_t* tf_tls_context_create_session(tf_tls_context_t* context) return session; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return NULL; #endif } @@ -1224,8 +1231,8 @@ void tf_tls_session_shutdown(tf_tls_session_t* session) int tf_tls_session_get_peer_certificate(tf_tls_session_t* session, char* buffer, size_t bytes) { -#if defined(TF_TLS_OPENSSL) int result = -1; +#if defined(TF_TLS_OPENSSL) X509* certificate = SSL_get_peer_certificate(session->ssl); BIO* bio = BIO_new(BIO_s_mem()); PEM_write_bio_X509(bio, certificate); @@ -1237,10 +1244,10 @@ int tf_tls_session_get_peer_certificate(tf_tls_session_t* session, char* buffer, result = mem->length; } BIO_free(bio); - return result; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) #endif + return result; } #if defined(TF_TLS_OPENSSL) @@ -1380,6 +1387,7 @@ tf_tls_handshake_t tf_tls_session_handshake(tf_tls_session_t* session) return result; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return k_tls_handshake_failed; #endif } @@ -1413,6 +1421,7 @@ int tf_tls_session_read_plain(tf_tls_session_t* session, char* buffer, size_t by return result; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return k_tls_read_failed; #endif } @@ -1422,6 +1431,7 @@ int tf_tls_session_write_plain(tf_tls_session_t* session, const char* buffer, si return SSL_write(session->ssl, buffer, bytes); #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return -1; #endif } @@ -1431,6 +1441,7 @@ int tf_tls_session_read_encrypted(tf_tls_session_t* session, char* buffer, size_ return BIO_read(session->bio_out, buffer, bytes); #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return -1; #endif } @@ -1440,6 +1451,7 @@ int tf_tls_session_write_encrypted(tf_tls_session_t* session, const char* buffer return BIO_write(session->bio_in, buffer, bytes); #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return -1; #endif } @@ -1454,5 +1466,6 @@ bool tf_tls_session_get_error(tf_tls_session_t* session, char* buffer, size_t by return error != 0; #elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_SCHANNEL) + return false; #endif } diff --git a/src/trace.c b/src/trace.c index 8d205a72..1242aa1d 100644 --- a/src/trace.c +++ b/src/trace.c @@ -2,6 +2,7 @@ #include #include +#include #include #include #include