-
Notifications
You must be signed in to change notification settings - Fork 891
Codebase cleanup and portability refactoring #110
Conversation
|
I think I've found a bug in core/memory.c:332-344: #if defined(__MACH__)
#ifdef __x86_64__
hva = (uint64_t)pmem->kva + (cur_va - pmem->uva);
#else
hva = (uint64_t)(uint32_t)pmem->kva + (cur_va - pmem->uva);
#endif
#else // __MACH
#if defined(_WIN64)
hva = (uint64_t)pmem->kva + (cur_va - pmem->uva);
#else
hva = 0;
#endif
#endifNote how Windows (32-bit) sets If it's a bug, I could easily fix it with this (which show the usefulness of the new HAX_ARCH* macros): #ifdef HAX_ARCH_X86_64
hva = (uint64_t)pmem->kva + (cur_va - pmem->uva);
#else
hva = (uint64_t)(uint32_t)pmem->kva + (cur_va - pmem->uva);
#endif |
- Replaced ASSERT-with-assert, TRUE-with-true, FALSE-with-false, since they were inconsistent (both uppercase and lowercase variants were used across the codebase). - Removed uneccesary macros for uppercase variants. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
Changing `function()` to `function(void)`, fixing `-Wstrict-prototypes`. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
The codebase mixes (u)intN_t and (u)intN. This commit picks the former variant and consistently use it. Unnecessary typedef's to the latter variant are removed. Regex: "int([0-9]+)(?![_\d])" -> "int$1_t" (Mostly accurate). Signed-off-by: Alexandro Sanchez Bach <[email protected]>
Platform-specific headers, e.g. hax_windows.h, defined page-related constants such as page_size and page_shift that are identical in all systems since they are unique to the x86 architecture. This commit moves the definitions to hax_types.h, and: - Makes these macros uppercase (as per coding convention). - Adds the `HAX_` prefix (as per coding convention). This is also necessary to prevent clashes with kernel headers. These macros are used in all of `core`. Platform-specific code is still allowed to use platform-specific macros like the ones defined in the WDK. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
- Replaced `1 << PAGE_SHIFT` with `PAGE_SIZE`. - Added macros for undeclared non-standard functions: `min`, `max`. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
- Moved component_index_t definition from hax_types.h to vmx.h, since it's not a type consumed outside core. - Created unique `HAX_ARCH_*`, `HAX_COMPILER_*`, `HAX_PLATFORM_*` macros: The goal is avoiding dependance in compiler/platform-specific macros throughout the codebase by creating custom macros declared at a single location. - Changed some (wrongly assigned as Windows/MacOS-specific) macros into MSVC/Clang-specific macros, e.g. ALIGNED(x) and PACKED. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
0d07ac8 to
a479c8a
Compare
Thanks! Indeed there's a bug that might affect Win32 hosts in the Anyway, But the BTW, HAXM used to support 32-bit Mac. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regex: "int([0-9]+)(?![_\d])" -> "int$1_t" (Mostly accurate).
Does "mostly" imply that there were exceptions? Just curious.
I'm done with the review. Other than a few picky comments, everything looks good. Thanks!
include/hax_types.h
Outdated
| // MSVC | ||
| #ifdef _MSC_VER | ||
| #define HAX_COMPILER_MSVC | ||
| #define PACKED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apparently MSVC doesn't have a simple equivalent for PACKED. Could you add a FIXME comment for this?
- Throwing compile-time errors if no valid architecture/compiler/platform is found. - Replacing platform-specific macros with the new HAX_ARCH_*/HAX_COMPILER_*/HAX_PLATFORM_* macros. Signed-off-by: Alexandro Sanchez Bach <[email protected]>
|
All fixes applied!
Yeah. The regex rule correctly replaced everything, but it accidentally hit That note in the commit message is a mere reminder of what I did, and also a reminder to double-check if used ever again. :-) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
| } | ||
|
|
||
| #elif defined(__MACH__) | ||
| #elif defined(HAX_PLATFORM_DARWIN) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this is probably to workaround a compiler issue (MSVC vs. Clang), because the Mac code differs from the Windows code only in an extra pair of parentheses. But since we've finished testing the PR, you can address this in a later patch when you add Linux support.
This patch allows for easier portability of HAXM to other platforms (see #108).
Builds successfully under Windows (32-bit and 64-bit configurations) and MacOS.
Changes
Main changes are:
s/ASSERT/assert,s/TRUE/true,s/FALSE/false, since it was inconsistent (both uppercase and lowercase variants were used across the codebase).min,max.hax_windows.hdefined page-related constants such aspage_sizeandpage_shiftthat are identical in all systems since they are unique to the x86 architecture. They were moved tohax_types.h.HAX_ARCH_*,HAX_COMPILER_*,HAX_PLATFORM_*macros: The goal is avoiding dependance in compiler/platform-specific macros throughout the codebase by creating custom macros declared at a single location.function()tofunction(void), fixing-Wstrict-prototypes.Full information in the messages of the individual commits.