Skip to content

Commit

Permalink
Merge pull request #45 from navytux/v1.x-fix-win32
Browse files Browse the repository at this point in the history
Fix build for Windows with raw MSC
  • Loading branch information
kubo committed Jun 4, 2023
2 parents 0585cb4 + df7bd08 commit 7738ea4
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion include/funchook.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C" {
* or libfunchook.so. Others are invisible.
*/
#ifdef FUNCHOOK_EXPORTS
#if defined(WIN32)
#if defined(_WIN32)
#define FUNCHOOK_EXPORT __declspec(dllexport)
#elif defined(__GNUC__)
#define FUNCHOOK_EXPORT __attribute__((visibility("default")))
Expand Down
8 changes: 4 additions & 4 deletions src/funchook.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#include <stdint.h>
#include <string.h>
#include <limits.h>
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#ifndef PATH_MAX
#define PATH_MAX MAX_PATH
Expand Down Expand Up @@ -78,7 +78,7 @@ static void flush_instruction_cache(void *addr, size_t size)
{
#if defined __GNUC__
__builtin___clear_cache((char*)addr, (char*)addr + size);
#elif defined WIN32
#elif defined _WIN32
FlushInstructionCache(GetCurrentProcess(), addr, size);
#else
#error unsupported OS or compiler
Expand Down Expand Up @@ -230,12 +230,12 @@ static funchook_t *funchook_create_internal(void)
num_entries_in_page = (page_size - offsetof(funchook_page_t, entries)) / sizeof(funchook_entry_t);
#endif
funchook_log(funchook,
#ifdef WIN32
#ifdef _WIN32
" allocation_unit=%"PRIuPTR"\n"
#endif
" page_size=%"PRIuPTR"\n"
" num_entries_in_page=%"PRIuPTR"\n",
#ifdef WIN32
#ifdef _WIN32
allocation_unit,
#endif
page_size, num_entries_in_page);
Expand Down
4 changes: 2 additions & 2 deletions src/funchook_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef FUNCHOOK_INTERNAL_H
#define FUNCHOOK_INTERNAL_H 1
#include "funchook.h"
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#endif

Expand Down Expand Up @@ -104,7 +104,7 @@
typedef struct {
void *addr;
size_t size;
#ifdef WIN32
#ifdef _WIN32
DWORD protect;
#endif
} mem_state_t;
Expand Down
2 changes: 1 addition & 1 deletion test/libfunchook_test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef WIN32
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
Expand Down
2 changes: 1 addition & 1 deletion test/libfunchook_test_noasm.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef WIN32
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
Expand Down
10 changes: 5 additions & 5 deletions test/test_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#if defined(__linux__) && !defined(_GNU_SOURCE)
#define _GNU_SOURCE
#endif
#ifdef WIN32
#ifdef _WIN32
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
Expand All @@ -14,7 +14,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#include <io.h>
#define mode_t int
Expand All @@ -31,7 +31,7 @@
#endif
#include <funchook.h>

#ifdef WIN32
#ifdef _WIN32
#define DLLEXPORT __declspec(dllexport)
#else
#define DLLEXPORT
Expand Down Expand Up @@ -133,7 +133,7 @@ enum load_type {
static void *load_func(const char *module, const char *func)
{
void *addr;
#ifdef WIN32
#ifdef _WIN32
HMODULE hMod = GetModuleHandleA(module);

if (hMod == NULL) {
Expand Down Expand Up @@ -601,7 +601,7 @@ int main()
TEST_FUNCHOOK_EXPECT_ERROR(x86_test_error_jump1, FUNCHOOK_ERROR_CANNOT_FIX_IP_RELATIVE);
TEST_FUNCHOOK_EXPECT_ERROR(x86_test_error_jump2, FUNCHOOK_ERROR_FOUND_BACK_JUMP);

#ifndef WIN32
#ifndef _WIN32
TEST_FUNCHOOK_INT(x86_test_call_get_pc_thunk_ax, LOAD_TYPE_NO_LOAD);
TEST_FUNCHOOK_INT(x86_test_call_get_pc_thunk_bx, LOAD_TYPE_NO_LOAD);
TEST_FUNCHOOK_INT(x86_test_call_get_pc_thunk_cx, LOAD_TYPE_NO_LOAD);
Expand Down
2 changes: 1 addition & 1 deletion test/x86_test.S
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ label_2_1:
#endif
ret

#ifndef WIN32
#ifndef _WIN32
.p2align 4,,15
.globl x86_test_call_get_pc_thunk_ax
x86_test_call_get_pc_thunk_ax:
Expand Down

0 comments on commit 7738ea4

Please sign in to comment.