diff --git a/core/relinker/CMakeLists.txt b/core/relinker/CMakeLists.txt index 428b0f2be..f3c4461a9 100644 --- a/core/relinker/CMakeLists.txt +++ b/core/relinker/CMakeLists.txt @@ -180,6 +180,8 @@ if(BUILD_TESTING) ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_tls_function_coverage.py $) add_test(NAME linux_load_alignment COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_linux_load_alignment.py $) + add_test(NAME linux_entry_argv COMMAND ${Python3_EXECUTABLE} + ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_linux_entry_argv.py $) add_test(NAME windows_gui COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/relinker/tests/test_windows_gui.py $) add_test(NAME guest_intel_trampolines COMMAND ${Python3_EXECUTABLE} diff --git a/core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp b/core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp index dc2dbcf9c..c6f63f41d 100644 --- a/core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp +++ b/core/relinker/elfpatcher/include/elfpatcher/general/ElfConstants.hpp @@ -115,12 +115,7 @@ inline constexpr std::uint32_t kDynSymInfoFirstGlobal = 1; inline constexpr std::uint64_t kDynSymAlign = 8; inline constexpr std::uint32_t kDynamicLinkToStrTab = 2; -inline constexpr std::uint8_t kStubOpPopRax = 0x58; -inline constexpr std::uint8_t kStubOpMovRbxRsp[] = {0x48, 0x89, 0xe3}; -inline constexpr std::uint8_t kStubOpSubRsp0x30[] = {0x48, 0x83, 0xec, 0x30}; inline constexpr std::uint8_t kStubOpAndRsp0xf0[] = {0x48, 0x83, 0xe4, 0xf0}; -inline constexpr std::uint8_t kStubOpMovDwordPtrRsp[] = {0x89, 0x04, 0x24}; -inline constexpr std::uint8_t kStubOpMovQwordPtrRsp8Rbx[] = {0x48, 0x89, 0x5c, 0x24, 0x08}; inline constexpr std::uint8_t kStubOpMovRdiRsp[] = {0x48, 0x89, 0xe7}; inline constexpr std::uint8_t kStubOpXorRsiRsi[] = {0x48, 0x31, 0xf6}; inline constexpr std::uint8_t kStubOpCallRel32 = 0xe8; diff --git a/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp b/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp index 25acf3ec3..21bc763d8 100644 --- a/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp +++ b/core/relinker/elfpatcher/src/general/EntryStubBuilder.cpp @@ -15,13 +15,8 @@ std::vector EntryStubBuilder::BuildEntryStub( const std::uint64_t realEntryVaddr ) const { std::vector s; - s.push_back(kStubOpPopRax); - _appendBytes(s, kStubOpMovRbxRsp, sizeof(kStubOpMovRbxRsp)); - _appendBytes(s, kStubOpSubRsp0x30, sizeof(kStubOpSubRsp0x30)); - _appendBytes(s, kStubOpAndRsp0xf0, sizeof(kStubOpAndRsp0xf0)); - _appendBytes(s, kStubOpMovDwordPtrRsp, sizeof(kStubOpMovDwordPtrRsp)); - _appendBytes(s, kStubOpMovQwordPtrRsp8Rbx, sizeof(kStubOpMovQwordPtrRsp8Rbx)); _appendBytes(s, kStubOpMovRdiRsp, sizeof(kStubOpMovRdiRsp)); + _appendBytes(s, kStubOpAndRsp0xf0, sizeof(kStubOpAndRsp0xf0)); _appendBytes(s, kStubOpXorRsiRsi, sizeof(kStubOpXorRsiRsi)); const std::uint64_t callInsnVaddr = stubVaddr + s.size(); const std::uint64_t callNextVaddr = callInsnVaddr + kStubCallInstructionSize; diff --git a/core/relinker/relinker/tests/test_linux_entry_argv.py b/core/relinker/relinker/tests/test_linux_entry_argv.py new file mode 100644 index 000000000..07f91f57f --- /dev/null +++ b/core/relinker/relinker/tests/test_linux_entry_argv.py @@ -0,0 +1,50 @@ +"""Check that a Linux relink hands the guest entry the process argc and inline argv array.""" + +from pathlib import Path +import platform +import signal +import struct +import subprocess +import sys +import tempfile + +from test_linux_load_alignment import fixture + +ENTRY = 0x10 +ARGV_CHECK = bytes.fromhex( + "833f02" "751e" + "48837f0800" "7417" + "488b4710" + "80385a" "750e" + "80780100" "7508" + "48837f1800" "7501" + "cc" + "0f0b") + + +def argv_fixture(): + image = fixture() + struct.pack_into("