Browse Source

engine: server: support MAP_ANON synonym for MAP_ANONYMOUS, disable allocating string pool near server library for OSX

pull/2/head
Alibek Omarov 2 years ago
parent
commit
5678d9a253
  1. 15
      engine/server/sv_game.c

15
engine/server/sv_game.c

@ -3092,12 +3092,10 @@ void SV_SetStringArrayMode( qboolean dynamic ) @@ -3092,12 +3092,10 @@ void SV_SetStringArrayMode( qboolean dynamic )
#endif
}
#ifdef XASH_64BIT
#if !XASH_WIN32
#if XASH_64BIT && !XASH_WIN32 && !XASH_APPLE
#define USE_MMAP
#include <sys/mman.h>
#endif
#endif
/*
==================
@ -3128,14 +3126,21 @@ void SV_AllocStringPool( void ) @@ -3128,14 +3126,21 @@ void SV_AllocStringPool( void )
#ifdef USE_MMAP
{
uint flags;
size_t pagesize = sysconf( _SC_PAGESIZE );
int arrlen = (str64.maxstringarray * 2) & ~(pagesize - 1);
void *base = svgame.dllFuncs.pfnGameInit;
void *start = svgame.hInstance - arrlen;
#if defined(MAP_ANON)
flags = MAP_ANON | MAP_PRIVATE;
#elif defined(MAP_ANONYMOUS)
flags = MAP_ANONYMOUS | MAP_PRIVATE;
#endif
while( start - base > INT_MIN )
{
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 );
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
{
ptr = mapptr;
@ -3150,7 +3155,7 @@ void SV_AllocStringPool( void ) @@ -3150,7 +3155,7 @@ void SV_AllocStringPool( void )
start = base;
while( start - base < INT_MAX )
{
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, 0, 0 );
void *mapptr = mmap((void*)((unsigned long)start & ~(pagesize - 1)), arrlen, PROT_READ | PROT_WRITE, flags, 0, 0 );
if( mapptr && mapptr != (void*)-1 && mapptr - base > INT_MIN && mapptr - base < INT_MAX )
{
ptr = mapptr;

Loading…
Cancel
Save