Use __attribute__((force_align_arg_pointer)) (#30)

This commit is contained in:
Luke Street 2023-01-23 10:36:14 -05:00 committed by GitHub
parent 9837ce0bf4
commit 6b6a462ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 11 deletions

View File

@ -1,4 +1,10 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug" CACHE STRING
"Build type options: Debug Release RelWithDebInfo MinSizeRel" FORCE)
endif ()
project(wibo LANGUAGES CXX) project(wibo LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
@ -6,7 +12,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
find_package(Filesystem REQUIRED) find_package(Filesystem REQUIRED)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -Wall -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -m32 -Wall")
include_directories(.) include_directories(.)
add_executable(wibo add_executable(wibo
dll/advapi32.cpp dll/advapi32.cpp

View File

@ -8,8 +8,7 @@ RUN apk add --no-cache cmake ninja g++ linux-headers binutils
COPY . /wibo COPY . /wibo
# Build static binary # Build static binary
# Replace with RelWithDebInfo when -O2 crash is fixed RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-static" \
RUN cmake -S /wibo -B /wibo/build -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS="-static" \
&& cmake --build /wibo/build \ && cmake --build /wibo/build \
&& strip -g /wibo/build/wibo && strip -g /wibo/build/wibo

View File

@ -6,7 +6,10 @@
#include <unistd.h> #include <unistd.h>
#include <assert.h> #include <assert.h>
#define WIN_FUNC __attribute__((stdcall)) // On Windows, the incoming stack is aligned to a 4 byte boundary.
// force_align_arg_pointer will realign the stack to match GCC's 16 byte alignment.
#define WIN_ENTRY __attribute__((force_align_arg_pointer))
#define WIN_FUNC WIN_ENTRY __attribute__((stdcall))
#define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__) #define DEBUG_LOG(...) wibo::debug_log(__VA_ARGS__)
namespace user32 { namespace user32 {

View File

@ -933,17 +933,45 @@ namespace kernel32 {
} }
unsigned int WIN_FUNC GetSystemDirectoryA(char *lpBuffer, unsigned int uSize) { unsigned int WIN_FUNC GetSystemDirectoryA(char *lpBuffer, unsigned int uSize) {
strcpy(lpBuffer, "C:\\Windows\\System32"); DEBUG_LOG("GetSystemDirectoryA(%p, %u)\n", lpBuffer, uSize);
return strlen(lpBuffer); if (lpBuffer == nullptr) {
return 0;
}
const char* systemDir = "C:\\Windows\\System32";
const auto len = strlen(systemDir);
// If the buffer is too small, return the required buffer size.
// (Add 1 to include the NUL terminator)
if (uSize < len + 1) {
return len + 1;
}
strcpy(lpBuffer, systemDir);
return len;
} }
unsigned int WIN_FUNC GetWindowsDirectoryA(char *lpBuffer, unsigned int uSize) { unsigned int WIN_FUNC GetWindowsDirectoryA(char *lpBuffer, unsigned int uSize) {
strcpy(lpBuffer, "C:\\Windows"); DEBUG_LOG("GetWindowsDirectoryA(%p, %u)\n", lpBuffer, uSize);
return strlen(lpBuffer); if (lpBuffer == nullptr) {
return 0;
}
const char* systemDir = "C:\\Windows";
const auto len = strlen(systemDir);
// If the buffer is too small, return the required buffer size.
// (Add 1 to include the NUL terminator)
if (uSize < len + 1) {
return len + 1;
}
strcpy(lpBuffer, systemDir);
return len;
} }
unsigned int WIN_FUNC GetCurrentDirectoryA(unsigned int uSize, char *lpBuffer) { unsigned int WIN_FUNC GetCurrentDirectoryA(unsigned int uSize, char *lpBuffer) {
DEBUG_LOG("GetCurrentDirectoryA\n"); DEBUG_LOG("GetCurrentDirectoryA(%u, %p)\n", uSize, lpBuffer);
std::filesystem::path cwd = std::filesystem::current_path(); std::filesystem::path cwd = std::filesystem::current_path();
std::string path = files::pathToWindows(cwd); std::string path = files::pathToWindows(cwd);

View File

@ -1,13 +1,13 @@
#include "common.h" #include "common.h"
namespace lmgr { namespace lmgr {
int lp_checkout(int a, int b, const char* c, const char* d, int e, const char* f, int* out) { int WIN_ENTRY lp_checkout(int a, int b, const char* c, const char* d, int e, const char* f, int* out) {
DEBUG_LOG("lp_checkout %d %d %s %s %d %s\n", a, b, c, d, e, f); DEBUG_LOG("lp_checkout %d %d %s %s %d %s\n", a, b, c, d, e, f);
*out = 1234; *out = 1234;
return 0; return 0;
} }
int lp_checkin() { int WIN_ENTRY lp_checkin() {
DEBUG_LOG("lp_checkin\n"); DEBUG_LOG("lp_checkin\n");
return 0; return 0;
} }