Merge branch 'cuik-fix'

This commit is contained in:
NeGate 2023-01-27 22:25:26 -05:00
commit fbe47be3c5
10 changed files with 154 additions and 142 deletions

View File

@ -2,12 +2,12 @@
:: Compile UTF-8 resource into .obj file
:: this .obj file has to be linked to the executable using it, NOT archived
:: together with ciabatta.lib.
windres -o utf8.obj utf8.rc
ld -relocatable -o libwinsane.obj utf8.obj
rem windres -o utf8.obj utf8.rc
:: Compile chkstk
nasm src\os_win\chkstk.asm -ochkstk.o -fwin64
:: Compile the rest of the party
clang -Wall src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nodefaultlibs -g -mfma
rem clang -Wall src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nodefaultlibs -g -mfma
cuik src\ciabatta.c -o ciabatta.obj -c -DCIABATTA_WIN -I inc -I src\_win -nostdlib
lib /nologo /out:ciabatta.lib chkstk.o ciabatta.obj

View File

@ -6,37 +6,37 @@
#define TSS_DTOR_ITERATIONS 32
#if !defined(_timespec_defined)
#define _timespec_defined
typedef unsigned long long time_t;
struct timespec {
#define _timespec_defined
typedef unsigned long long time_t;
struct timespec {
time_t tv_sec;
long tv_nsec;
};
};
#endif
#if defined(_WIN32)
typedef struct cnd_t {
typedef struct cnd_t {
int idk_yet;
} cnd_t;
} cnd_t;
typedef struct thrd_t {
typedef struct thrd_t {
void* handle;
} thrd_t;
} thrd_t;
typedef struct tss_t {
typedef struct tss_t {
int idk_yet;
} tss_t;
} tss_t;
typedef struct mtx_t {
typedef struct mtx_t {
int type;
// Done to handle recursive mutexes
unsigned long recursion;
unsigned long owner;
_Atomic(int) counter;
void* semaphore;
} mtx_t;
} mtx_t;
#else
#error "Not implemented"
#error "Not implemented"
#endif
typedef void(*tss_dtor_t) (void*);

View File

@ -25,15 +25,15 @@
// Intrinsics
#if !defined(__FMA__)
#if !defined(_MSC_VER)
#error "Get a better CPU (the kind that supports FMA) or enable -mfma"
#endif
#if !defined(_MSC_VER)
#error "Get a better CPU (the kind that supports FMA) or enable -mfma"
#endif
#endif
// xmmintrin.h depends on mm_malloc.h, which itself includes other CRT headers
// Which introduces compiler errors. Actually does it really matter? I would
// need to check again
#undef __STDC_HOSTED__
#include <immintrin.h>
// #include <immintrin.h>
#include <xmmintrin.h>
#include "intrin.h"
@ -65,15 +65,15 @@
// Windows stuff
#if defined(CIABATTA_WIN)
#include "os_win/win.h"
#include "os_win/cookie.c"
#include "os_win/assert.c"
#include "os_win/cmdline.c"
#include "os_win/entry.c"
#include "os_win/environment.c"
#include "os_win/heap.c"
#include "os_win/signal.c"
#include "os_win/stdio.c"
#include "os_win/threads.c"
#include "os_win/time.c"
#include "os_win/win.h"
#include "os_win/cookie.c"
#include "os_win/assert.c"
#include "os_win/cmdline.c"
#include "os_win/entry.c"
#include "os_win/environment.c"
#include "os_win/heap.c"
#include "os_win/signal.c"
#include "os_win/stdio.c"
#include "os_win/threads.c"
#include "os_win/time.c"
#endif

View File

@ -75,6 +75,28 @@ long double fminl(long double x, long double y) {
return fmin(x, y);
}
#ifdef __CUIK__
#warning "Cuik doesn't support the FMA intrinsics... fix that NeGate"
double fma(double x, double y, double z) {
return (x * y) + z;
}
float fmaf(float x, float y, float z) {
return (x * y) + z;
}
long double fmal(long double x, long double y, long double z) {
return (x * y) + z;
}
double sqrt(double x) {
return 0.0;
}
float sqrtf(float x) {
return 0.0;
}
#else
double fma(double x, double y, double z) {
__m128d xd = _mm_set_sd(x);
__m128d yd = _mm_set_sd(y);
@ -115,4 +137,4 @@ float sqrtf(float x) {
long double sqrtl(long double x) {
return sqrt(x);
}
#endif

View File

@ -108,18 +108,9 @@ static int cmdline_to_argv8(const wchar_t *cmd, char **argv) {
return argc;
}
static wchar_t *get_wcmdline() {
// That's right, that's where windows hid the command line
TEB *teb = (TEB *)__readgsqword(offsetof(NT_TIB, Self));
PEB *peb = teb->ProcessEnvironmentBlock;
RTL_USER_PROCESS_PARAMETERS *params = peb->ProcessParameters;
UNICODE_STRING command_line_str = params->CommandLine;
return command_line_str.Buffer;
}
static char **get_command_args(int *argc_ptr) {
static char *argv_buffer[CMDLINE_ARGV_MAX];
wchar_t *cmdline = get_wcmdline();
wchar_t *cmdline = GetCommandLineW();
*argc_ptr = cmdline_to_argv8(cmdline, argv_buffer);
return argv_buffer;
}

View File

@ -1,10 +1,10 @@
u64 __security_cookie;
static void __security_init_cookie() {
void __security_init_cookie() {
// They say it's a random number so I generated
// one using numbergenerator.org
__security_cookie = 0xb26e04cc62ba48a;
__security_cookie = 0xb26e04cc62ba48aULL;
}
void __security_check_cookie(u64 retrieved) {

View File

@ -4,8 +4,8 @@
#pragma weak WinMain
int main(int argc, char** argv);
int wmain(int argc, wchar_t** argv, wchar_t **envp);
int WinMain(HINSTANCE inst, HINSTANCE pinst, LPSTR cmdline, int showcmd);
// int wmain(int argc, wchar_t** argv, wchar_t **envp);
// int WinMain(HINSTANCE inst, HINSTANCE pinst, LPSTR cmdline, int showcmd);
_Noreturn void mainCRTStartup() {
_setup_eh();
@ -24,7 +24,7 @@ _Noreturn void mainCRTStartup() {
exit(exit_code);
}
_Noreturn void WinMainCRTStartup() {
/*_Noreturn void WinMainCRTStartup() {
_setup_eh();
_setup_heap();
_setup_timer();
@ -39,4 +39,4 @@ _Noreturn void WinMainCRTStartup() {
int exit_code = WinMain(inst, 0, cmdline, SW_SHOWDEFAULT);
exit(exit_code);
}
}*/

View File

@ -12,4 +12,3 @@ static void _setup_eh();
static void _setup_heap();
static void _setup_io();
static void _close_io();
static void __security_init_cookie();

View File

@ -7,7 +7,7 @@ int cnt;
int f(void* thr_data)
{
for(int n = 0; n < 1000; ++n) {
for(int n = 0; n < 100000; ++n) {
atomic_fetch_add_explicit(&acnt, 1, memory_order_relaxed); // atomic
++cnt; // undefined behavior, in practice some updates missed
}