i think it works

This commit is contained in:
maksw committed 2026-04-30 23:52:46 +02:00
commit 0e1479b168
167 files changed
+27008

No files matched your search

+131
View File
@@ -0,0 +1,131 @@
// kernel32.c - Win32 personality: process, thread, memory, sync
// Thin wrappers over syscall.dll stubs. Provides a familiar API for
// user-mode code that was originally written for Windows.
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
// Forward declarations of syscall stubs (from syscall.dll).
extern uint64_t SysAlloc(size_t size);
extern void SysFree(void* ptr, size_t size);
extern void SysYield(void);
extern void SysSleep(uint64_t ms);
extern void SysExitProcess(int code);
extern void SysExitThread(int code);
extern uint64_t SysCreateThread(uintptr_t entry, uintptr_t arg, uint32_t priority);
extern void SysCloseHandle(uint32_t handle);
extern void SysDbgPrint(const char* s);
extern uint64_t SysMutexCreate(void);
extern void SysMutexAcquire(uint32_t handle);
extern void SysMutexRelease(uint32_t handle);
extern uint64_t SysEventCreate(uint32_t manualReset, uint32_t initial);
extern void SysEventSet(uint32_t handle);
extern void SysEventWait(uint32_t handle);
extern uint64_t SysGetTick(void);
#define INVALID_HANDLE_VALUE ((void *)(intptr_t)-1)
#define WAIT_OBJECT_0 0
// ---------------------------------------------------------------------------
// Heap
// ---------------------------------------------------------------------------
void* HeapAlloc(void* heap, unsigned long flags, size_t size) {
(void)heap; (void)flags;
return (void *)SysAlloc(size);
}
void* HeapReAlloc(void* heap, unsigned long flags, void* mem, size_t size) {
(void)heap; (void)flags;
// No in-place resize; alloc + copy + free.
void* n = (void *)SysAlloc(size);
if (!n) return (void *)0;
// We don't track sizes, so copy a conservative max.
// In practice callers should use a custom heap.
SysFree(mem, 0);
return n;
}
int HeapFree(void* heap, unsigned long flags, void* mem) {
(void)heap; (void)flags;
SysFree(mem, 0);
return 1;
}
// ---------------------------------------------------------------------------
// Process / Thread
// ---------------------------------------------------------------------------
void ExitProcess(unsigned int code) { SysExitProcess((int)code); }
void ExitThread(unsigned long code) { SysExitThread((int)code); }
typedef unsigned long (*LPTHREAD_START_ROUTINE)(void *);
void* CreateThread(void* attr, size_t stackSize,
LPTHREAD_START_ROUTINE fn, void* arg,
unsigned long flags, unsigned long* tid) {
(void)attr; (void)stackSize; (void)flags; (void)tid;
uint64_t h = SysCreateThread((uintptr_t)fn, (uintptr_t)arg, 1 /* Normal */);
if (!h) return INVALID_HANDLE_VALUE;
return (void *)(uintptr_t)h;
}
void Sleep(unsigned long ms) { SysSleep((uint64_t)ms); }
void SwitchToThread(void) { SysYield(); }
// ---------------------------------------------------------------------------
// Synchronisation
// ---------------------------------------------------------------------------
void* CreateMutex(void* attr, int initialOwner, const char* name) {
(void)attr; (void)initialOwner; (void)name;
uint64_t h = SysMutexCreate();
if (!h) return INVALID_HANDLE_VALUE;
return (void *)(uintptr_t)h;
}
unsigned long WaitForSingleObject(void* handle, unsigned long ms) {
(void)ms; // Timeout not supported - always blocking for now.
uint32_t h = (uint32_t)(uintptr_t)handle;
// We need to know if this is a mutex, event, etc.
// For simplicity, try event wait; syscall layer validates the type.
SysEventWait(h);
return WAIT_OBJECT_0;
}
int ReleaseMutex(void* handle) {
extern void SysMutexRelease(uint32_t);
SysMutexRelease((uint32_t)(uintptr_t)handle);
return 1;
}
void* CreateEvent(void* attr, int manualReset, int initialState, const char* name) {
(void)attr; (void)name;
uint64_t h = SysEventCreate((uint32_t)manualReset, (uint32_t)initialState);
if (!h) return INVALID_HANDLE_VALUE;
return (void *)(uintptr_t)h;
}
int SetEvent(void* handle) {
SysEventSet((uint32_t)(uintptr_t)handle);
return 1;
}
int CloseHandle(void* handle) {
SysCloseHandle((uint32_t)(uintptr_t)handle);
return 1;
}
void OutputDebugStringA(const char* s) {
SysDbgPrint(s);
}
// ---------------------------------------------------------------------------
// Time
// ---------------------------------------------------------------------------
unsigned long long GetTickCount64(void) { return SysGetTick(); }
unsigned long GetTickCount(void) { return (unsigned long)SysGetTick(); }
// ---------------------------------------------------------------------------
// String helpers (no CRT dependency)
// ---------------------------------------------------------------------------
int lstrlenA(const char* s) {
int n = 0;
while (*s++) n++;
return n;
}
+2
View File
@@ -0,0 +1,2 @@
// ole32.c - stub; no COM at this stage.
static void stub(void) { }
+20
View File
@@ -0,0 +1,20 @@
// user32.c - minimal user32 stubs (no window manager yet)
#include <stdint.h>
// Screen blit is the only graphical primitive available at this stage.
extern void SysScreenBlit(int x, int y, int w, int h, const uint32_t* pixels);
// syscall.dll
extern void SysYield(void);
void BitBlt(int x, int y, int w, int h, const uint32_t* pixels) {
SysScreenBlit(x, y, w, h, pixels);
}
// Message loop stubs - always return 0.
int GetMessage(void* msg, void* hwnd, unsigned int min, unsigned int max) {
(void)msg; (void)hwnd; (void)min; (void)max;
SysYield();
return 0;
}
int DispatchMessage(const void* msg) { (void)msg; return 0; }
+2
View File
@@ -0,0 +1,2 @@
// winmm.c - stub; no multimedia at this stage.
static void stub(void) { }