Fixed crashes in code generated by SourceHook's HookManGen on Mac OS X (bug 3514, r=dvander).
Fixed crashes in code generated by SourceHook's HookManGen on Mac OS X (
bug 3514, r=dvander).
This fixes two problems:
1) On OS X structures/objects with sizes of 1, 2, 4, or 8 are returned from functions in registers, not memory addresses.
2) A function returning anything which was 8 bytes in size was crashing. This problem affected all compilers/operating systems.
1.1 --- a/core/sourcehook/sourcehook_hookmangen.cpp Tue Nov 24 07:19:57 2009 -0600
1.2 +++ b/core/sourcehook/sourcehook_hookmangen.cpp Tue Nov 24 07:33:52 2009 -0600
1.3 @@ -1,5 +1,5 @@
1.4 /* ======== SourceHook ========
1.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 +* Copyright (C) 2004-2009 Metamod:Source Development Team
1.7 * No warranties of any kind
1.8 *
1.9 * License: zlib/libpng
1.10 @@ -873,7 +873,7 @@
1.11 // mov eax, [ecx]
1.12 // mov edx, [ecx+4]
1.13 IA32_Mov_Reg_Rm(&m_HookFunc, REG_EAX, REG_ECX, MOD_MEM_REG);
1.14 - IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EAX, REG_ECX, 4);
1.15 + IA32_Mov_Reg_Rm_DispAuto(&m_HookFunc, REG_EDX, REG_ECX, 4);
1.16 }
1.17 else
1.18 {
1.19 @@ -1869,8 +1869,18 @@
1.20 // MSVC seems to return _all_ structs, classes, unions in memory
1.21 pi.flags |= PassInfo::PassFlag_RetMem;
1.22 #elif SH_COMP == SH_COMP_GCC
1.23 - // Same goes for GCC :)
1.24 - pi.flags |= PassInfo::PassFlag_RetMem;
1.25 +#if SH_SYS == SH_SYS_APPLE
1.26 + // Apple GCC returns in memory if size isn't a power of 2 or > 8
1.27 + if ((pi.size & (pi.size - 1)) == 0 && pi.size <= 8)
1.28 + {
1.29 + pi.flags |= PassInfo::PassFlag_RetReg;
1.30 + }
1.31 + else
1.32 +#endif
1.33 + {
1.34 + // GCC on Linux does same thing as MSVC
1.35 + pi.flags |= PassInfo::PassFlag_RetMem;
1.36 + }
1.37 #endif
1.38 }
1.39 }
2.1 --- a/core/sourcehook/test/Makefile Tue Nov 24 07:19:57 2009 -0600
2.2 +++ b/core/sourcehook/test/Makefile Tue Nov 24 07:33:52 2009 -0600
2.3 @@ -1,4 +1,4 @@
2.4 -#(C)2004-2008 SourceMM Development Team
2.5 +# (C)2004-2009 Metamod:Source Development Team
2.6 # Makefile written by David "BAILOPAN" Anderson and Pavol Marko
2.7
2.8 OPT_FLAGS = -O3 -funroll-loops -s -pipe
2.9 @@ -9,7 +9,7 @@
2.10 MAX_PARAMS=20
2.11
2.12 BINARY = sourcehook_test
2.13 -OBJECTS = main.cpp sourcehook.cpp ../sourcehook_hookmangen.cpp $(shell ls -t test*.cpp)
2.14 +OBJECTS = main.cpp sourcehook.cpp sourcehook_hookmangen.cpp $(shell ls -t test*.cpp)
2.15 HEADERS = ../sh_list.h ../sh_tinyhash.h ../sh_memory.h ../sh_string.h ../sh_vector.h ../sourcehook_impl.h ../FastDelegate.h ../sourcehook.h ../sh_memfuncinfo.h
2.16
2.17 ifeq "$(DEBUG)" "true"
2.18 @@ -46,10 +46,12 @@
2.19
2.20 all:
2.21 mkdir -p $(BIN_DIR)
2.22 - ln -sf ../sourcehook.cpp sourcehook.cpp
2.23 + ln -sf ../sourcehook.cpp
2.24 + ln -sf ../sourcehook_hookmangen.cpp
2.25 $(MAKE) $(BINARY)
2.26 rm -f $(BINARY)
2.27 rm -f sourcehook.cpp
2.28 + rm -f sourcehook_hookmangen.cpp
2.29 ln -sf $(BIN_DIR)/$(BINARY) $(BINARY)
2.30
2.31