Skip to content

Commit

Permalink
Fix warnings when using mingw32 compilers
Browse files Browse the repository at this point in the history
  • Loading branch information
kubo committed Jun 4, 2023
1 parent 7738ea4 commit cba1c8c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 11 additions & 4 deletions src/funchook_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,15 @@
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif

#ifndef __GNUC__
#define __attribute__(arg)
#ifdef __GNUC__
#ifdef __MINGW32__
#include <stdio.h>
#define ATTR_FORMAT_PRINTF(a, b) __attribute__((__format__ (__MINGW_PRINTF_FORMAT, a, b)))
#else
#define ATTR_FORMAT_PRINTF(a, b) __attribute__((__format__ (__printf__, a, b)))
#endif
#else
#define ATTR_FORMAT_PRINTF(a, b)
#endif

#define ROUND_DOWN(num, unit) ((num) & ~((unit) - 1))
Expand Down Expand Up @@ -123,8 +130,8 @@ typedef struct funchook_page {
/* Functions in funchook.c */
extern const size_t funchook_size;
extern char funchook_debug_file[];
void funchook_log(funchook_t *funchook, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
void funchook_set_error_message(funchook_t *funchook, const char *fmt, ...) __attribute__((__format__ (__printf__, 2, 3)));
void funchook_log(funchook_t *funchook, const char *fmt, ...) ATTR_FORMAT_PRINTF(2, 3);
void funchook_set_error_message(funchook_t *funchook, const char *fmt, ...) ATTR_FORMAT_PRINTF(2, 3);

/* Functions in funchook_linux.c & funchook_windows.c */
extern const size_t page_size;
Expand Down
4 changes: 2 additions & 2 deletions src/funchook_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ static int alloc_page_info(funchook_t *funchook, page_list_t **pl_out, void *hin
err, to_errmsg(err, errbuf, sizeof(errbuf)));
return FUNCHOOK_ERROR_MEMORY_FUNCTION;
}
funchook_log(funchook, " process map: %016I64x-%016I64x %s\n",
funchook_log(funchook, " process map: "ADDR_FMT"-"ADDR_FMT" %s\n",
(size_t)mbi.BaseAddress, (size_t)mbi.BaseAddress + mbi.RegionSize,
(mbi.State == MEM_FREE) ? "free" : "used");
if (mbi.State == MEM_FREE) {
Expand Down Expand Up @@ -384,7 +384,7 @@ void *funchook_resolve_func(funchook_t *funchook, void *func)
size_t immlo = ((size_t)(fn[0] & ADRP_XIP0_IMMLO) >> 29) << 12;
size_t imm12 = ((size_t)(fn[1] & LDR_XIP0_IMM12) >> 10) << 3;
pos = addr + immhi + immlo + imm12;
// fprintf(stderr, "%016I64x: %08x %08x %08x : %I64x %I64x %I64x %I64x\n", (size_t)fn, fn[0], fn[1], fn[2], addr, immhi, immlo, imm12);
// fprintf(stderr, ADDR_FMT": %08x %08x %08x : %"PRIxPTR" %"PRIxPTR" %"PRIxPTR" %"PRIxPTR"\n", (size_t)fn, fn[0], fn[1], fn[2], addr, immhi, immlo, imm12);
funchook_log(funchook, " indirect jump to addresss at %p\n", (void*)pos);
}
#endif
Expand Down

0 comments on commit cba1c8c

Please sign in to comment.