mirror of
https://github.com/libretro/libretro-tyrquake.git
synced 2024-11-27 02:00:41 +00:00
sys: change Sys_MakeCodeWritable API to take start/end addrs
All the callers had their start and end addresses anyway, so do the length calculation in just one place. Fixes the last few WIN64 specific build warnings as well. Signed-off-by: Kevin Shanahan <kmshanah@disenchant.net>
This commit is contained in:
parent
4053376008
commit
43782dde5e
@ -22,7 +22,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
#include "quakedef.h"
|
||||
#include "d_local.h"
|
||||
#include "render.h"
|
||||
#include "sys.h" /* Sys_MakeCodeWriteable() */
|
||||
#include "sys.h"
|
||||
|
||||
int d_vrectx, d_vrecty, d_vrectright_particle, d_vrectbottom_particle;
|
||||
|
||||
@ -40,13 +40,9 @@ void
|
||||
D_Patch(void)
|
||||
{
|
||||
#ifdef USE_X86_ASM
|
||||
|
||||
static qboolean protectset8 = false;
|
||||
|
||||
if (!protectset8) {
|
||||
Sys_MakeCodeWriteable((unsigned long)D_PolysetAff8Start,
|
||||
(unsigned long)D_PolysetAff8End -
|
||||
(unsigned long)D_PolysetAff8Start);
|
||||
Sys_MakeCodeWriteable(D_PolysetAff8Start, D_PolysetAff8End);
|
||||
protectset8 = true;
|
||||
}
|
||||
#endif /* USE_X86_ASM */
|
||||
|
@ -267,8 +267,7 @@ R_Init(void)
|
||||
|
||||
// TODO: collect 386-specific code in one place
|
||||
#ifdef USE_X86_ASM
|
||||
Sys_MakeCodeWriteable((long)R_EdgeCodeStart,
|
||||
(long)R_EdgeCodeEnd - (long)R_EdgeCodeStart);
|
||||
Sys_MakeCodeWriteable(R_EdgeCodeStart, R_EdgeCodeEnd);
|
||||
#endif
|
||||
|
||||
D_Init();
|
||||
@ -505,13 +504,11 @@ R_ViewChanged(vrect_t *pvrect, int lineadj, float aspect)
|
||||
// TODO: collect 386-specific code in one place
|
||||
#ifdef USE_X86_ASM
|
||||
if (r_pixbytes == 1) {
|
||||
Sys_MakeCodeWriteable((long)R_Surf8Start,
|
||||
(long)R_Surf8End - (long)R_Surf8Start);
|
||||
Sys_MakeCodeWriteable(R_Surf8Start, R_Surf8End);
|
||||
colormap = vid.colormap;
|
||||
R_Surf8Patch();
|
||||
} else {
|
||||
Sys_MakeCodeWriteable((long)R_Surf16Start,
|
||||
(long)R_Surf16End - (long)R_Surf16Start);
|
||||
Sys_MakeCodeWriteable(R_Surf16Start, R_Surf16End);
|
||||
colormap = vid.colormap16;
|
||||
R_Surf16Patch();
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ SYSTEM IO
|
||||
*/
|
||||
|
||||
void
|
||||
Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length)
|
||||
Sys_MakeCodeWriteable(void *start_addr, void *end_addr)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -298,19 +298,18 @@ Sys_MakeCodeWriteable
|
||||
================
|
||||
*/
|
||||
void
|
||||
Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length)
|
||||
Sys_MakeCodeWriteable(void *start_addr, void *end_addr)
|
||||
{
|
||||
int r;
|
||||
unsigned long addr;
|
||||
int psize = getpagesize();
|
||||
void *addr;
|
||||
size_t length;
|
||||
intptr_t pagesize;
|
||||
int result;
|
||||
|
||||
addr = (startaddr & ~(psize - 1)) - psize;
|
||||
|
||||
// fprintf(stderr, "writable code %lx(%lx)-%lx, length=%lx\n", startaddr,
|
||||
// addr, startaddr+length, length);
|
||||
|
||||
r = mprotect((char *)addr, length + startaddr - addr + psize, 7);
|
||||
|
||||
if (r < 0)
|
||||
pagesize = getpagesize();
|
||||
addr = (void *)((intptr_t)start_addr & ~(pagesize - 1));
|
||||
length = ((byte *)end_addr - (byte *)addr) + pagesize - 1;
|
||||
length &= ~(pagesize - 1);
|
||||
result = mprotect(addr, length, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
if (result < 0)
|
||||
Sys_Error("Protection change failed");
|
||||
}
|
||||
|
@ -891,12 +891,14 @@ Sys_MakeCodeWriteable
|
||||
================
|
||||
*/
|
||||
void
|
||||
Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length)
|
||||
Sys_MakeCodeWriteable(void *start_addr, void *end_addr)
|
||||
{
|
||||
DWORD dummy;
|
||||
BOOL success;
|
||||
size_t length;
|
||||
|
||||
success = VirtualProtect((LPVOID)startaddr, length, PAGE_READWRITE, &dummy);
|
||||
length = (byte *)end_addr - (byte *)start_addr;
|
||||
success = VirtualProtect(start_addr, length, PAGE_READWRITE, &dummy);
|
||||
if (!success)
|
||||
Sys_Error("Protection change failed");
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ void Sys_mkdir(const char *path);
|
||||
|
||||
//
|
||||
// memory protection
|
||||
//
|
||||
void Sys_MakeCodeWriteable(unsigned long startaddr, unsigned long length);
|
||||
// changes protection from start_addr, up to but not including end_addr
|
||||
void Sys_MakeCodeWriteable(void *start_addr, void *end_addr);
|
||||
|
||||
//
|
||||
// system IO
|
||||
|
Loading…
Reference in New Issue
Block a user