Small fixes for better cross-platform compatibility (#200)
* Add ifdef check before the Microsoft-specific movsq in memory.cc * Added ifdef before Microsoft-specific movsq and replaced with memcpy in other cases. In memory.cc * Update image_sha_bytes_ from 16 to 20 xex_module.h The value 16 is less than the expected value 20, causing a buffer overflow during sha1 finalization. * Update image_sha_bytes_ loop from 16 to 20 iterations xex_module.cc * Update mapped_memory_posix.cc: Must resize file to map_length. * Should not map nullptr with MAP_FIXED flag. Update memory_posix.cc.
This commit is contained in:
parent
9f1605a2e7
commit
d8aa14da73
|
@ -58,6 +58,7 @@ class PosixMappedMemory : public MappedMemory {
|
||||||
|
|
||||||
void* data =
|
void* data =
|
||||||
mmap(0, map_length, protection, MAP_SHARED, file_descriptor, offset);
|
mmap(0, map_length, protection, MAP_SHARED, file_descriptor, offset);
|
||||||
|
ftruncate(file_descriptor, map_length);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
close(file_descriptor);
|
close(file_descriptor);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
|
@ -176,8 +176,12 @@ static void vastcpy_impl_movdir64m(CacheLine* XE_RESTRICT physaddr,
|
||||||
static void vastcpy_impl_repmovs(CacheLine* XE_RESTRICT physaddr,
|
static void vastcpy_impl_repmovs(CacheLine* XE_RESTRICT physaddr,
|
||||||
CacheLine* XE_RESTRICT rdmapping,
|
CacheLine* XE_RESTRICT rdmapping,
|
||||||
uint32_t written_length) {
|
uint32_t written_length) {
|
||||||
|
#if XE_ARCH_AMD64 == 1 && XE_COMPILER_MSVC == 1
|
||||||
__movsq((unsigned long long*)physaddr, (unsigned long long*)rdmapping,
|
__movsq((unsigned long long*)physaddr, (unsigned long long*)rdmapping,
|
||||||
written_length / 8);
|
written_length / 8);
|
||||||
|
#else
|
||||||
|
memcpy((unsigned char*)physaddr, (const unsigned char*)rdmapping, written_length);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
XE_COLD
|
XE_COLD
|
||||||
static void first_vastcpy(CacheLine* XE_RESTRICT physaddr,
|
static void first_vastcpy(CacheLine* XE_RESTRICT physaddr,
|
||||||
|
|
|
@ -85,6 +85,12 @@ void* AllocFixed(void* base_address, size_t length,
|
||||||
AllocationType allocation_type, PageAccess access) {
|
AllocationType allocation_type, PageAccess access) {
|
||||||
// mmap does not support reserve / commit, so ignore allocation_type.
|
// mmap does not support reserve / commit, so ignore allocation_type.
|
||||||
uint32_t prot = ToPosixProtectFlags(access);
|
uint32_t prot = ToPosixProtectFlags(access);
|
||||||
|
int flags = 0;
|
||||||
|
if (base_address != nullptr) {
|
||||||
|
flags = MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS;
|
||||||
|
} else {
|
||||||
|
flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||||
|
}
|
||||||
void* result = mmap(base_address, length, prot,
|
void* result = mmap(base_address, length, prot,
|
||||||
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
|
MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS, -1, 0);
|
||||||
if (result == MAP_FAILED) {
|
if (result == MAP_FAILED) {
|
||||||
|
|
|
@ -1120,7 +1120,7 @@ void XexModule::Precompile() {
|
||||||
|
|
||||||
char fmtbuf[16];
|
char fmtbuf[16];
|
||||||
|
|
||||||
for (unsigned i = 0; i < 16; ++i) {
|
for (unsigned i = 0; i < 20; ++i) {
|
||||||
sprintf_s(fmtbuf, "%X", image_sha_bytes_[i]);
|
sprintf_s(fmtbuf, "%X", image_sha_bytes_[i]);
|
||||||
image_sha_str_ += &fmtbuf[0];
|
image_sha_str_ += &fmtbuf[0];
|
||||||
}
|
}
|
||||||
|
|
|
@ -282,7 +282,7 @@ class XexModule : public xe::cpu::Module {
|
||||||
XexFormat xex_format_ = kFormatUnknown;
|
XexFormat xex_format_ = kFormatUnknown;
|
||||||
SecurityInfoContext security_info_ = {};
|
SecurityInfoContext security_info_ = {};
|
||||||
|
|
||||||
uint8_t image_sha_bytes_[16];
|
uint8_t image_sha_bytes_[20];
|
||||||
std::string image_sha_str_;
|
std::string image_sha_str_;
|
||||||
XexInfoCache info_cache_;
|
XexInfoCache info_cache_;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue