Merge remote-tracking branch 'origin/main' into dll

This commit is contained in:
2025-09-28 20:40:26 -06:00
4 changed files with 38 additions and 13 deletions

View File

@@ -97,8 +97,10 @@ jobs:
cp artifacts/static-release/wibo artifacts/out/wibo
- name: Publish release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
with:
files: |
artifacts/out/wibo
artifacts/out/wibo_debug
draft: true
generate_release_notes: true

View File

@@ -5,14 +5,27 @@ if(NOT CMAKE_BUILD_TYPE)
"Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif()
set(CMAKE_C_FLAGS_INIT "-m32")
set(CMAKE_CXX_FLAGS_INIT "-m32")
set(CMAKE_EXE_LINKER_FLAGS_INIT "-m32")
set(CMAKE_SHARED_LINKER_FLAGS_INIT "-m32")
project(wibo LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -fno-pie -no-pie -D_LARGEFILE64_SOURCE")
find_package(Filesystem REQUIRED)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -Wall -fno-pie -no-pie -D_LARGEFILE64_SOURCE")
include(FetchContent)
FetchContent_Declare(
mimalloc
GIT_REPOSITORY https://github.com/microsoft/mimalloc.git
GIT_TAG dfa50c37d951128b1e77167dd9291081aa88eea4 # v3.1.5
)
FetchContent_MakeAvailable(mimalloc)
include_directories(.)
add_executable(wibo
@@ -38,7 +51,7 @@ add_executable(wibo
processes.cpp
strutil.cpp
)
target_link_libraries(wibo PRIVATE std::filesystem)
target_link_libraries(wibo PRIVATE std::filesystem mimalloc-static)
install(TARGETS wibo DESTINATION bin)
include(CTest)

View File

@@ -9,6 +9,7 @@ RUN apk add --no-cache \
g++ \
linux-headers \
binutils \
git \
mingw-w64-binutils \
mingw-w64-gcc

View File

@@ -16,7 +16,7 @@
#include <string>
#include <strings.h>
#include "strutil.h"
#include <malloc.h>
#include <mimalloc.h>
#include <random>
#include <stdarg.h>
#include <system_error>
@@ -139,9 +139,9 @@ namespace kernel32 {
static void *doAlloc(unsigned int dwBytes, bool zero) {
if (dwBytes == 0)
dwBytes = 1;
void *ret = malloc(dwBytes);
void *ret = mi_malloc_aligned(dwBytes, 8);
if (ret && zero) {
memset(ret, 0, malloc_usable_size(ret));
memset(ret, 0, mi_usable_size(ret));
}
return ret;
}
@@ -149,9 +149,9 @@ namespace kernel32 {
static void *doRealloc(void *mem, unsigned int dwBytes, bool zero) {
if (dwBytes == 0)
dwBytes = 1;
size_t oldSize = malloc_usable_size(mem);
void *ret = realloc(mem, dwBytes);
size_t newSize = malloc_usable_size(ret);
size_t oldSize = mi_usable_size(mem);
void *ret = mi_realloc_aligned(mem, dwBytes, 8);
size_t newSize = mi_usable_size(ret);
if (ret && zero && newSize > oldSize) {
memset((char*)ret + oldSize, 0, newSize - oldSize);
}
@@ -630,9 +630,17 @@ namespace kernel32 {
int WIN_FUNC InitOnceBeginInitialize(LPINIT_ONCE lpInitOnce, DWORD dwFlags, PBOOL fPending, LPVOID* lpContext) {
DEBUG_LOG("STUB: InitOnceBeginInitialize\n");
if (fPending != nullptr) {
*fPending = TRUE;
}
return 1;
}
BOOL WIN_FUNC InitOnceComplete(LPINIT_ONCE lpInitOnce, DWORD dwFlags, LPVOID lpContext) {
DEBUG_LOG("STUB: InitOnceComplete\n");
return TRUE;
}
void WIN_FUNC AcquireSRWLockShared(void *SRWLock) { DEBUG_LOG("STUB: AcquireSRWLockShared(%p)\n", SRWLock); }
void WIN_FUNC ReleaseSRWLockShared(void *SRWLock) { DEBUG_LOG("STUB: ReleaseSRWLockShared(%p)\n", SRWLock); }
@@ -762,7 +770,7 @@ namespace kernel32 {
bufSize++;
// Step 2, actually build that buffer
char *buffer = (char *) malloc(bufSize);
char *buffer = (char *) mi_malloc(bufSize);
char *ptr = buffer;
work = environ;
@@ -792,7 +800,7 @@ namespace kernel32 {
bufSizeW++;
// Step 2, actually build that buffer
uint16_t *buffer = (uint16_t *) malloc(bufSizeW * 2);
uint16_t *buffer = (uint16_t *) mi_malloc(bufSizeW * 2);
uint16_t *ptr = buffer;
work = environ;
@@ -2832,7 +2840,7 @@ namespace kernel32 {
unsigned int WIN_FUNC HeapSize(void *hHeap, unsigned int dwFlags, void *lpMem) {
DEBUG_LOG("HeapSize(heap=%p, flags=%x, mem=%p)\n", hHeap, dwFlags, lpMem);
return malloc_usable_size(lpMem);
return mi_usable_size(lpMem);
}
void *WIN_FUNC GetProcessHeap() {
@@ -3492,6 +3500,7 @@ static void *resolveByName(const char *name) {
if (strcmp(name, "EnterCriticalSection") == 0) return (void *) kernel32::EnterCriticalSection;
if (strcmp(name, "LeaveCriticalSection") == 0) return (void *) kernel32::LeaveCriticalSection;
if (strcmp(name, "InitOnceBeginInitialize") == 0) return (void *) kernel32::InitOnceBeginInitialize;
if (strcmp(name, "InitOnceComplete") == 0) return (void *) kernel32::InitOnceComplete;
if (strcmp(name, "AcquireSRWLockShared") == 0) return (void *) kernel32::AcquireSRWLockShared;
if (strcmp(name, "ReleaseSRWLockShared") == 0) return (void *) kernel32::ReleaseSRWLockShared;
if (strcmp(name, "AcquireSRWLockExclusive") == 0) return (void *) kernel32::AcquireSRWLockExclusive;