Merge in mingw changes.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3873 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
Cory McWilliams 2022-05-16 22:30:14 +00:00
parent 87224d2bb6
commit 7848b5e560
12 changed files with 188 additions and 50 deletions

131
Makefile
View File

@ -2,6 +2,7 @@ PROJECT = tildefriends
BUILD_DIR ?= out BUILD_DIR ?= out
BUILD_DIR_DBG := $(BUILD_DIR)/debug BUILD_DIR_DBG := $(BUILD_DIR)/debug
BUILD_DIR_REL := $(BUILD_DIR)/release BUILD_DIR_REL := $(BUILD_DIR)/release
BUILD_DIR_WIN := $(BUILD_DIR)/win
UNAME_M := $(shell uname -m) UNAME_M := $(shell uname -m)
CFLAGS += \ CFLAGS += \
@ -16,6 +17,10 @@ LDFLAGS += -Wl,-gc-sections
debug: CFLAGS += -Og -g debug: CFLAGS += -Og -g
release: CFLAGS += -DNDEBUG -O3 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) ifeq ($(UNAME_M),x86_64)
debug: CFLAGS += -fsanitize=address -fsanitize=undefined debug: CFLAGS += -fsanitize=address -fsanitize=undefined
@ -25,7 +30,8 @@ endif
APP_SOURCES = $(wildcard src/*.c) APP_SOURCES = $(wildcard src/*.c)
APP_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(APP_SOURCES)) APP_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(APP_SOURCES))
APP_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 += \ $(APP_OBJS): CFLAGS += \
-Ideps/base64c/include \ -Ideps/base64c/include \
-Ideps/crypt_blowfish \ -Ideps/crypt_blowfish \
@ -34,12 +40,14 @@ $(APP_OBJS): CFLAGS += \
-Ideps/libuv/include \ -Ideps/libuv/include \
-Ideps/xopt \ -Ideps/xopt \
-Ideps/libsodium \ -Ideps/libsodium \
-Ideps/libsodium/src/libsodium/include \
-Werror -Werror
BASE64C_SOURCES = deps/base64c/src/base64c.c BASE64C_SOURCES = deps/base64c/src/base64c.c
BASE64C_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BASE64C_SOURCES)) BASE64C_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BASE64C_SOURCES))
BASE64C_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 += \ $(BASE64C_OBJS): CFLAGS += \
-Wno-sign-compare -Wno-sign-compare
@ -47,9 +55,12 @@ BLOWFISH_SOURCES = \
deps/crypt_blowfish/crypt_blowfish.c \ deps/crypt_blowfish/crypt_blowfish.c \
deps/crypt_blowfish/crypt_gensalt.c \ deps/crypt_blowfish/crypt_gensalt.c \
deps/crypt_blowfish/wrapper.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_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(BLOWFISH_SOURCES))
BLOWFISH_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 = \ UV_SOURCES = \
deps/libuv/src/fs-poll.c \ deps/libuv/src/fs-poll.c \
@ -59,6 +70,10 @@ UV_SOURCES = \
deps/libuv/src/strscpy.c \ deps/libuv/src/strscpy.c \
deps/libuv/src/threadpool.c \ deps/libuv/src/threadpool.c \
deps/libuv/src/timer.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/async.c \
deps/libuv/src/unix/core.c \ deps/libuv/src/unix/core.c \
deps/libuv/src/unix/dl.c \ deps/libuv/src/unix/dl.c \
@ -84,13 +99,37 @@ UV_SOURCES = \
deps/libuv/src/unix/tcp.c \ deps/libuv/src/unix/tcp.c \
deps/libuv/src/unix/thread.c \ deps/libuv/src/unix/thread.c \
deps/libuv/src/unix/tty.c \ deps/libuv/src/unix/tty.c \
deps/libuv/src/unix/udp.c \ deps/libuv/src/unix/udp.c
deps/libuv/src/uv-common.c \ UV_SOURCES_WIN = \
deps/libuv/src/uv-data-getter-setters.c \ deps/libuv/src/win/async.c \
deps/libuv/src/version.c deps/libuv/src/win/core.c \
UV_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(UV_SOURCES)) deps/libuv/src/win/detect-wakeup.c \
UV_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.o,$(UV_SOURCES)) deps/libuv/src/win/dl.c \
UV_OBJS := $(UV_OBJS_DBG) $(UV_OBJS_REL) 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 += \ $(UV_OBJS): CFLAGS += \
-Ideps/libuv/include \ -Ideps/libuv/include \
-Ideps/libuv/src \ -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/ed25519/ref10/ed25519_ref10.c \
deps/libsodium/src/libsodium/crypto_core/hsalsa20/ref2/core_hsalsa20_ref2.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_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/cp/hash_sha256_cp.c \
deps/libsodium/src/libsodium/crypto_hash/sha256/hash_sha256.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_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/donna/poly1305_donna.c \
deps/libsodium/src/libsodium/crypto_onetimeauth/poly1305/onetimeauth_poly1305.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/crypto_scalarmult.c \
deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c \ deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/ref10/x25519_ref10.c \
deps/libsodium/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.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/ref/salsa20_ref.c \
deps/libsodium/src/libsodium/crypto_stream/salsa20/stream_salsa20.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/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/crypto_verify/sodium/verify.c \
deps/libsodium/src/libsodium/randombytes/randombytes.c \ deps/libsodium/src/libsodium/randombytes/randombytes.c \
deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \ deps/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c \
deps/libsodium/src/libsodium/sodium/core.c \ deps/libsodium/src/libsodium/sodium/core.c \
deps/libsodium/src/libsodium/sodium/runtime.c \
deps/libsodium/src/libsodium/sodium/utils.c deps/libsodium/src/libsodium/sodium/utils.c
SODIUM_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SODIUM_SOURCES)) SODIUM_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SODIUM_SOURCES))
SODIUM_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 += \ $(SODIUM_OBJS): CFLAGS += \
-DCONFIGURED=1 \ -DCONFIGURED=1 \
-DMINIMAL=1 \ -DMINIMAL=1 \
@ -141,7 +192,8 @@ $(SODIUM_OBJS): CFLAGS += \
SQLITE_SOURCES = deps/sqlite/sqlite3.c SQLITE_SOURCES = deps/sqlite/sqlite3.c
SQLITE_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SQLITE_SOURCES)) SQLITE_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(SQLITE_SOURCES))
SQLITE_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 += \ $(SQLITE_OBJS): CFLAGS += \
-DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \ -DSQLITE_DBCONFIG_DEFAULT_DEFENSIVE \
-DSQLITE_ENABLE_JSON1 \ -DSQLITE_ENABLE_JSON1 \
@ -162,7 +214,14 @@ $(SQLITE_OBJS): CFLAGS += \
XOPT_SOURCES = deps/xopt/xopt.c XOPT_SOURCES = deps/xopt/xopt.c
XOPT_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(XOPT_SOURCES)) XOPT_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(XOPT_SOURCES))
XOPT_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 = \ QUICKJS_SOURCES = \
deps/quickjs/cutils.c \ deps/quickjs/cutils.c \
@ -173,7 +232,8 @@ QUICKJS_SOURCES = \
deps/quickjs/quickjs.c deps/quickjs/quickjs.c
QUICKJS_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(QUICKJS_SOURCES)) QUICKJS_OBJS_DBG = $(patsubst %.c,$(BUILD_DIR_DBG)/%.o,$(QUICKJS_SOURCES))
QUICKJS_OBJS_REL = $(patsubst %.c,$(BUILD_DIR_REL)/%.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 += \ $(QUICKJS_OBJS): CFLAGS += \
-DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \ -DCONFIG_VERSION=\"$(shell cat deps/quickjs/VERSION)\" \
-DDUMP_LEAKS \ -DDUMP_LEAKS \
@ -186,16 +246,27 @@ $(QUICKJS_OBJS): CFLAGS += \
LDFLAGS += \ LDFLAGS += \
-pthread \ -pthread \
-lm
debug: LDFLAGS += \
-ldl \ -ldl \
-lm \
-lssl \ -lssl \
-lcrypto #\ -lcrypto
#-lsodium release: LDFLAGS += \
-ldl \
-lssl \
-lcrypto
win: LDFLAGS += \
-lwsock32 \
-lws2_32 \
-lkernel32 \
-liphlpapi \
-luserenv
debug: $(BUILD_DIR_DBG)/$(PROJECT) debug: $(BUILD_DIR_DBG)/$(PROJECT)
release: $(BUILD_DIR_REL)/$(PROJECT) release: $(BUILD_DIR_REL)/$(PROJECT)
win: $(BUILD_DIR_WIN)/$(PROJECT)
all: debug release all: debug release
.PHONY: all debug release .PHONY: all debug release win
ALL_APP_OBJS_DBG = \ ALL_APP_OBJS_DBG = \
$(APP_OBJS_DBG) \ $(APP_OBJS_DBG) \
@ -215,7 +286,16 @@ ALL_APP_OBJS_REL = \
$(SQLITE_OBJS_REL) \ $(SQLITE_OBJS_REL) \
$(QUICKJS_OBJS_REL) \ $(QUICKJS_OBJS_REL) \
$(XOPT_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) DEPS = $(ALL_APP_OBJS:.o=.d)
-include $(DEPS) -include $(DEPS)
@ -226,6 +306,9 @@ $(BUILD_DIR_DBG)/$(PROJECT): $(ALL_APP_OBJS_DBG)
$(BUILD_DIR_REL)/$(PROJECT): $(ALL_APP_OBJS_REL) $(BUILD_DIR_REL)/$(PROJECT): $(ALL_APP_OBJS_REL)
$(CC) -o $@ $^ $(LDFLAGS) $(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_WIN)/$(PROJECT): $(ALL_APP_OBJS_WIN)
$(CC) -o $@ $^ $(LDFLAGS)
$(BUILD_DIR_DBG)/%.o: %.c $(BUILD_DIR_DBG)/%.o: %.c
@mkdir -p $(dir $@) @mkdir -p $(dir $@)
@echo [c] $@ @echo [c] $@
@ -236,6 +319,16 @@ $(BUILD_DIR_REL)/%.o: %.c
@echo [c] $@ @echo [c] $@
@$(CC) $(CFLAGS) -c $< -o $@ @$(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: clean:
rm -rf $(BUILD_DIR) rm -rf $(BUILD_DIR)
.PHONY: clean .PHONY: clean

View File

@ -2,7 +2,13 @@
#include "ow-crypt.h" #include "ow-crypt.h"
#if defined(_WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
extern BOOLEAN NTAPI SystemFunction036(PVOID Buffer, ULONG BufferLength);
#else
#include <sys/random.h> #include <sys/random.h>
#endif
JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv); JSValue _crypt_hashpw(JSContext* context, JSValueConst this_val, int argc, JSValueConst* argv);
JSValue _crypt_gensalt(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; int length;
JS_ToInt32(context, &length, argv[0]); JS_ToInt32(context, &length, argv[0]);
char buffer[16]; 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); ssize_t bytes = getrandom(buffer, sizeof(buffer), 0);
#endif
char output[7 + 22 + 1]; char output[7 + 22 + 1];
char* salt = crypt_gensalt_rn("$2b$", length, buffer, bytes, output, sizeof(output)); char* salt = crypt_gensalt_rn("$2b$", length, buffer, bytes, output, sizeof(output));
JSValue result = JS_NewString(context, salt); JSValue result = JS_NewString(context, salt);

View File

@ -33,6 +33,13 @@ typedef struct file_stat_t {
uv_fs_t _request; uv_fs_t _request;
} file_stat_t; } 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) void tf_file_register(JSContext* context)
{ {
JSValue global = JS_GetGlobalObject(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) static void _file_read_read_callback(uv_fs_t* req)
{ {
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
fs_req_t* fsreq = (fs_req_t*)req;
tf_task_t* task = req->loop->data; tf_task_t* task = req->loop->data;
JSContext* context = tf_task_get_context(task); JSContext* context = tf_task_get_context(task);
promiseid_t promise = (promiseid_t)(intptr_t)req->data; 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))); 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) if (result < 0)
{ {
free(req); free(req);
@ -116,12 +124,15 @@ static JSValue _file_read_file(JSContext* context, JSValueConst this_val, int ar
promiseid_t promise = -1; promiseid_t promise = -1;
JSValue promise_value = tf_task_allocate_promise(task, &promise); JSValue promise_value = tf_task_allocate_promise(task, &promise);
uv_fs_t* req = malloc(sizeof(uv_fs_t) + k_file_read_max); fs_req_t* req = malloc(sizeof(fs_req_t) + k_file_read_max);
*req = (uv_fs_t) *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) if (result < 0)
{ {
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); 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) static void _file_write_write_callback(uv_fs_t* req)
{ {
uv_fs_req_cleanup(req); uv_fs_req_cleanup(req);
fs_req_t* fsreq = (fs_req_t*)req;
tf_task_t* task = req->loop->data; tf_task_t* task = req->loop->data;
JSContext* context = tf_task_get_context(task); JSContext* context = tf_task_get_context(task);
promiseid_t promise = (promiseid_t)(intptr_t)req->data; 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))); 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) 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; promiseid_t promise = -1;
JSValue promise_value = tf_task_allocate_promise(task, &promise); JSValue promise_value = tf_task_allocate_promise(task, &promise);
uv_fs_t* req = malloc(sizeof(uv_fs_t) + sizeof(size_t) + size); fs_req_t* req = malloc(sizeof(fs_req_t) + size);
*req = (uv_fs_t) *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(req->buffer, buffer, size);
memcpy((char*)(req + 1) + sizeof(size_t), buffer, size);
if (!is_array_buffer) if (!is_array_buffer)
{ {
JS_FreeCString(context, (const char*)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) if (result < 0)
{ {
tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result))); tf_task_reject_promise(task, promise, JS_ThrowInternalError(context, uv_strerror(result)));

View File

@ -14,7 +14,7 @@
#include <string.h> #include <string.h>
#if !defined (_WIN32) && !defined (__MACH__) #if !defined(_WIN32) && !defined(__MACH__)
#include <signal.h> #include <signal.h>
#include <sys/prctl.h> #include <sys/prctl.h>
#include <sys/resource.h> #include <sys/resource.h>
@ -80,7 +80,7 @@ const command_t k_commands[] = {
void shedPrivileges() void shedPrivileges()
{ {
#if !defined (_WIN32) #if !defined(_WIN32)
struct rlimit zeroLimit; struct rlimit zeroLimit;
zeroLimit.rlim_cur = 0; zeroLimit.rlim_cur = 0;
zeroLimit.rlim_max = 0; zeroLimit.rlim_max = 0;
@ -111,7 +111,7 @@ void shedPrivileges()
perror("setrlimit(RLIMIT_NPROC, {0, 0})"); perror("setrlimit(RLIMIT_NPROC, {0, 0})");
exit(-1); exit(-1);
} }
#if !defined (__MACH__) #if !defined(__MACH__)
if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0) if (setrlimit(RLIMIT_LOCKS, &zeroLimit) != 0)
{ {
perror("setrlimit(RLIMIT_LOCKS, {0, 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/docs",
"/~cory/ssb", "/~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]); printf("Exporting %s...\n", k_export[i]);
tf_ssb_export(ssb, 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; int result = 0;
#if !defined (_WIN32) && !defined (__MACH__) #if !defined(_WIN32) && !defined(__MACH__)
setpgid(0, 0); setpgid(0, 0);
#endif #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("Usage: %s command [command-options]\n", file);
printf("commands:\n"); 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); 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[]) int main(int argc, char* argv[])
{ {
#if !defined(_WIN32)
prctl(PR_SET_PDEATHSIG, SIGKILL); prctl(PR_SET_PDEATHSIG, SIGKILL);
#endif
uv_setup_args(argc, argv); uv_setup_args(argc, argv);
tf_taskstub_startup(); tf_taskstub_startup();
#if !defined (_WIN32) #if !defined(_WIN32)
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) if (signal(SIGPIPE, SIG_IGN) == SIG_ERR)
{ {
perror("signal"); perror("signal");
@ -634,7 +636,7 @@ int main(int argc, char* argv[])
if (argc >= 2) 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]; const command_t* command = &k_commands[i];
if (strcmp(argv[1], command->name) == 0) if (strcmp(argv[1], command->name) == 0)

View File

@ -7,8 +7,8 @@
#include <assert.h> #include <assert.h>
#include <malloc.h> #include <malloc.h>
#include <base64c.h> #include <base64c.h>
#include <openssl/evp.h> //#include <openssl/evp.h>
#include <openssl/rand.h> //#include <openssl/rand.h>
#include <quickjs.h> #include <quickjs.h>
#include <sodium/crypto_auth.h> #include <sodium/crypto_auth.h>
#include <sodium/crypto_box.h> #include <sodium/crypto_box.h>

View File

@ -79,7 +79,7 @@ static void _tf_ssb_connections_timer(uv_timer_t* timer)
tf_ssb_connections_t* connections = timer->data; tf_ssb_connections_t* connections = timer->data;
tf_ssb_connection_t* active[4]; tf_ssb_connection_t* active[4];
int count = tf_ssb_get_connections(connections->ssb, active, _countof(active)); int count = tf_ssb_get_connections(connections->ssb, active, _countof(active));
if (count < _countof(active)) if (count < (int)_countof(active))
{ {
char host[256]; char host[256];
int port; int port;

View File

@ -24,7 +24,11 @@ static void _write_file(const char* path, void* blob, size_t size)
static void _make_dir(const char* path) static void _make_dir(const char* path)
{ {
#if defined(_WIN32)
if (mkdir(path) && errno != EEXIST)
#else
if (mkdir(path, 0755) && errno != EEXIST) if (mkdir(path, 0755) && errno != EEXIST)
#endif
{ {
printf("Failed to create directory %s: %s.\n", path, strerror(errno)); printf("Failed to create directory %s: %s.\n", path, strerror(errno));
} }

View File

@ -24,9 +24,7 @@
#include "quickjs.h" #include "quickjs.h"
#include "quickjs-libc.h" #include "quickjs-libc.h"
#ifdef _WIN32 #ifndef _WIN32
static const int STDIN_FILENO = 0;
#else
#include <unistd.h> #include <unistd.h>
#endif #endif

View File

@ -15,9 +15,6 @@
#include <io.h> #include <io.h>
#include <windows.h> #include <windows.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
static const int STDIN_FILENO = 0;
static const int STDOUT_FILENO = 1;
static const int STDERR_FILENO = 2;
#else #else
#include <unistd.h> #include <unistd.h>
#endif #endif

View File

@ -9,6 +9,11 @@
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#if defined(_WIN32)
#define WIFEXITED(x) 1
#define WEXITSTATUS(x) (x)
#endif
static void _test_nop(const tf_test_options_t* options) static void _test_nop(const tf_test_options_t* options)
{ {
FILE* file = fopen("out/test.js", "w"); FILE* file = fopen("out/test.js", "w");

View File

@ -2,6 +2,7 @@
#if defined(_WIN32) #if defined(_WIN32)
#define TF_TLS_SCHANNEL #define TF_TLS_SCHANNEL
#include <malloc.h>
#elif defined(__MACH__) #elif defined(__MACH__)
#define TF_TLS_APPLE #define TF_TLS_APPLE
#else #else
@ -394,6 +395,7 @@ TlsContext* TlsContext::create()
return new TlsContext_osx(); return new TlsContext_osx();
} }
#elif defined (_WIN32) #elif defined (_WIN32)
#if 0
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <cstring> #include <cstring>
@ -1038,6 +1040,7 @@ TlsContext* TlsContext::create()
{ {
return new TlsContext_sspi(); return new TlsContext_sspi();
} }
#endif
#else #else
TlsContext* TlsContext::create() TlsContext* TlsContext::create()
{ {
@ -1084,6 +1087,7 @@ bool tf_tls_context_set_certificate(tf_tls_context_t* context, const char* certi
return result == 1; return result == 1;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return false;
#endif #endif
} }
@ -1099,6 +1103,7 @@ bool tf_tls_context_set_private_key(tf_tls_context_t* context, const char* priva
return result == 1; return result == 1;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return false;
#endif #endif
} }
@ -1123,6 +1128,7 @@ bool tf_tls_context_add_trusted_certificate(tf_tls_context_t* context, const cha
return result; return result;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return false;
#endif #endif
} }
@ -1137,6 +1143,7 @@ tf_tls_session_t* tf_tls_context_create_session(tf_tls_context_t* context)
return session; return session;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return NULL;
#endif #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) 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; int result = -1;
#if defined(TF_TLS_OPENSSL)
X509* certificate = SSL_get_peer_certificate(session->ssl); X509* certificate = SSL_get_peer_certificate(session->ssl);
BIO* bio = BIO_new(BIO_s_mem()); BIO* bio = BIO_new(BIO_s_mem());
PEM_write_bio_X509(bio, certificate); 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; result = mem->length;
} }
BIO_free(bio); BIO_free(bio);
return result;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
#endif #endif
return result;
} }
#if defined(TF_TLS_OPENSSL) #if defined(TF_TLS_OPENSSL)
@ -1380,6 +1387,7 @@ tf_tls_handshake_t tf_tls_session_handshake(tf_tls_session_t* session)
return result; return result;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return k_tls_handshake_failed;
#endif #endif
} }
@ -1413,6 +1421,7 @@ int tf_tls_session_read_plain(tf_tls_session_t* session, char* buffer, size_t by
return result; return result;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return k_tls_read_failed;
#endif #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); return SSL_write(session->ssl, buffer, bytes);
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return -1;
#endif #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); return BIO_read(session->bio_out, buffer, bytes);
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return -1;
#endif #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); return BIO_write(session->bio_in, buffer, bytes);
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return -1;
#endif #endif
} }
@ -1454,5 +1466,6 @@ bool tf_tls_session_get_error(tf_tls_session_t* session, char* buffer, size_t by
return error != 0; return error != 0;
#elif defined(TF_TLS_APPLE) #elif defined(TF_TLS_APPLE)
#elif defined(TF_TLS_SCHANNEL) #elif defined(TF_TLS_SCHANNEL)
return false;
#endif #endif
} }

View File

@ -2,6 +2,7 @@
#include <assert.h> #include <assert.h>
#include <malloc.h> #include <malloc.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <time.h> #include <time.h>
#include <unistd.h> #include <unistd.h>