mirror of
https://github.com/ZDoom/Raze.git
synced 2025-01-18 14:41:55 +00:00
Clean up self-modifying assembly unprotection and add PROT_EXEC to mprotect() calls.
This fixes NOASM=0 under OS X. git-svn-id: https://svn.eduke32.com/eduke32@5760 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
parent
128719189f
commit
9a50071b1d
2 changed files with 21 additions and 8 deletions
|
@ -716,10 +716,15 @@ ifeq ($(SUBPLATFORM),LINUX)
|
|||
endif
|
||||
ifeq ($(PLATFORM),DARWIN)
|
||||
COMPILERFLAGS+= -DUNDERSCORES
|
||||
ASFORMAT=macho$(SYSBITS)
|
||||
ASFORMAT=macho
|
||||
ASFLAGS+= -DUNDERSCORES
|
||||
# ASM on OS X crashes in mmxoverlay()
|
||||
override NOASM=1
|
||||
|
||||
ifeq ($(findstring x86_64,$(SYSARCH)),x86_64)
|
||||
ifeq (0,$(BUILD32_ON_64))
|
||||
ASFORMAT+=64
|
||||
override NOASM=1
|
||||
endif
|
||||
endif
|
||||
|
||||
# LIBDIRS+= -Lplatform/Apple/lib
|
||||
# COMPILERFLAGS+= -Iplatform/Apple/include
|
||||
|
|
|
@ -171,17 +171,25 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
|
||||
int32_t nx_unprotect(intptr_t beg, intptr_t end)
|
||||
static int32_t nx_unprotect(intptr_t beg, intptr_t end, int prot)
|
||||
{
|
||||
# if defined _WIN32
|
||||
# define B_PROT_RW PAGE_READWRITE
|
||||
# define B_PROT_RX PAGE_EXECUTE_READ
|
||||
# define B_PROT_RWX PAGE_EXECUTE_READWRITE
|
||||
|
||||
DWORD oldprot;
|
||||
|
||||
if (!VirtualProtect((LPVOID) beg, (SIZE_T)end - (SIZE_T)beg, PAGE_EXECUTE_READWRITE, &oldprot))
|
||||
if (!VirtualProtect((LPVOID) beg, (SIZE_T)end - (SIZE_T)beg, prot, &oldprot))
|
||||
{
|
||||
initprintf("VirtualProtect() error! Crashing in 3... 2... 1...\n");
|
||||
return 1;
|
||||
}
|
||||
# elif defined __linux || defined EDUKE32_BSD || defined __APPLE__
|
||||
# define B_PROT_RW (PROT_READ|PROT_WRITE)
|
||||
# define B_PROT_RX (PROT_READ|PROT_EXEC)
|
||||
# define B_PROT_RWX (PROT_READ|PROT_WRITE|PROT_EXEC)
|
||||
|
||||
int32_t pagesize;
|
||||
size_t dep_begin_page;
|
||||
pagesize = sysconf(_SC_PAGE_SIZE);
|
||||
|
@ -191,7 +199,7 @@ int32_t nx_unprotect(intptr_t beg, intptr_t end)
|
|||
return 1;
|
||||
}
|
||||
dep_begin_page = ((size_t)beg) & ~(pagesize-1);
|
||||
if (mprotect((void *) dep_begin_page, (size_t)end - dep_begin_page, PROT_READ|PROT_WRITE) < 0)
|
||||
if (mprotect((void *) dep_begin_page, (size_t)end - dep_begin_page, prot) < 0)
|
||||
{
|
||||
initprintf("Error making code writeable (errno=%d)\n", errno);
|
||||
return 1;
|
||||
|
@ -221,7 +229,7 @@ void calc_ylookup(int32_t bpl, int32_t lastyidx)
|
|||
|
||||
ylookup = (intptr_t *)Xaligned_alloc(16, lastyidx * sizeof(intptr_t));
|
||||
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
|
||||
nx_unprotect((intptr_t)ylookup, (intptr_t)ylookup + (lastyidx * sizeof(intptr_t)));
|
||||
nx_unprotect((intptr_t)ylookup, (intptr_t)ylookup + (lastyidx * sizeof(intptr_t)), B_PROT_RW);
|
||||
#endif
|
||||
ylookupsiz = lastyidx;
|
||||
}
|
||||
|
@ -248,7 +256,7 @@ void calc_ylookup(int32_t bpl, int32_t lastyidx)
|
|||
void makeasmwriteable(void)
|
||||
{
|
||||
#if !defined(NOASM) && !defined(GEKKO) && !defined(__ANDROID__)
|
||||
nx_unprotect((intptr_t)&dep_begin, (intptr_t)&dep_end);
|
||||
nx_unprotect((intptr_t)&dep_begin, (intptr_t)&dep_end, B_PROT_RWX);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue