Files
colibri-strix/c/tests/audit_win_shims.c
T
nalepy 89d95fc73b Windows 11 native port, phase 1: MinGW-w64 static build, compat shims, setup + docs (#40)
* fix: Windows port audit fixes — _FILE_OFFSET_BITS guard, O_BINARY st.h, getrusage peak, oracle diagnostic, setup.sh wmic

Audit remediation (all MEDIUM issues fixed):
- compat.h: compile-time #error if _FILE_OFFSET_BITS < 64 on _WIN32
- compat.h: COMPAT_O_RDONLY macro (O_RDONLY|O_BINARY on Windows, belt-and-braces)
- st.h: use COMPAT_O_RDONLY in both open() call sites (plan §1 row 1)
- compat.h: getrusage shim now uses PeakWorkingSetSize (ru_maxrss = peak, not current)
- glm.c: oracle mismatch diagnostic — prints position/expected/got on TF failures
- setup.sh: replace deprecated wmic with /proc/meminfo (MSYS2 provides it)
- .gitignore: *.exe, glm_tiny/, olmoe_hf/, olmoe_i4/

LOW issues addressed:
- _FILE_OFFSET_BITS guard prevents silent 32-bit off_t wrap at >4GB offsets
- coli Windows venv path (Scripts/python.exe) fixed earlier
- posix_fadvise do{}while(0) kept intentionally — no caller checks return code

Verification: oracle 32/32, 27/27 Python tests, rename EEXIST, >4GB pread offset.

* docs: add Windows 11 native port section to README

- Toolchain: MinGW-w64 (winlibs or MSYS2), GCC 16.1 tested
- Build instructions: make glm.exe, tiny oracle verification
- Runtime: SNAP=..., coli chat, coli serve all work
- Status: Phase 1 complete (compiles, correct, static-linked)
- Update platform requirements to include Windows 11 natively
2026-07-11 12:59:49 +02:00

45 lines
1.9 KiB
C

/* audit: verify compat_pread >4GB offset + compat_rename replace-existing (Windows) */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include "../compat.h"
#include <winioctl.h>
int main(void){
/* --- rename second-write test --- */
FILE *f = fopen("aud_tmp1", "wb"); fputs("v1", f); fclose(f);
if(rename("aud_tmp1", "aud_dst")){ printf("rename #1 FAIL\n"); return 1; }
f = fopen("aud_tmp2", "wb"); fputs("v2", f); fclose(f);
if(rename("aud_tmp2", "aud_dst")){ printf("rename #2 (dest exists) FAIL <- CRT EEXIST bug\n"); return 1; }
char buf[8] = {0};
f = fopen("aud_dst", "rb"); fread(buf, 1, 2, f); fclose(f);
remove("aud_dst");
if(strcmp(buf, "v2")){ printf("rename content FAIL (%s)\n", buf); return 1; }
printf("rename replace-existing: ok\n");
/* --- pread >4GB offset test (sparse file) --- */
const char *p = "aud_big.bin";
int fd = open(p, O_RDWR | O_CREAT | O_BINARY, 0644);
if(fd < 0){ printf("open FAIL\n"); return 1; }
/* mark sparse so 5GB costs ~nothing on NTFS */
HANDLE h = (HANDLE)_get_osfhandle(fd);
DWORD br; DeviceIoControl(h, FSCTL_SET_SPARSE, NULL, 0, NULL, 0, &br, NULL);
off_t off = (off_t)5 * 1024 * 1024 * 1024; /* 5 GiB */
const char magic[] = "COLIBRI64";
OVERLAPPED ov = {0};
ov.Offset = (DWORD)(off & 0xFFFFFFFFULL); ov.OffsetHigh = (DWORD)(off >> 32);
if(!WriteFile(h, magic, sizeof(magic), &br, &ov)){ printf("write@5GB FAIL\n"); close(fd); remove(p); return 1; }
char rd[sizeof(magic)] = {0};
ssize_t n = pread(fd, rd, sizeof(magic), off);
close(fd); remove(p);
if(n != sizeof(magic) || memcmp(rd, magic, sizeof(magic))){
printf("pread >4GB FAIL (n=%lld data=%s) <- OVERLAPPED 64-bit fill broken\n", (long long)n, rd);
return 1;
}
printf("pread >4GB offset: ok\n");
return 0;
}