mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 07:17:45 -04:00
add mremap implementation for where it's not provided
This commit is contained in:
parent
504e2f5688
commit
8c8b728472
1 changed files with 28 additions and 0 deletions
|
@ -21,6 +21,10 @@
|
||||||
#include "common/version.h"
|
#include "common/version.h"
|
||||||
#include "libretro.h"
|
#include "libretro.h"
|
||||||
|
|
||||||
|
#ifndef MAP_ANONYMOUS
|
||||||
|
#define MAP_ANONYMOUS MAP_ANON
|
||||||
|
#endif
|
||||||
|
|
||||||
static retro_video_refresh_t video_cb;
|
static retro_video_refresh_t video_cb;
|
||||||
static retro_input_poll_t input_poll_cb;
|
static retro_input_poll_t input_poll_cb;
|
||||||
static retro_input_state_t input_state_cb;
|
static retro_input_state_t input_state_cb;
|
||||||
|
@ -92,11 +96,35 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed)
|
||||||
|
|
||||||
void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
|
void *plat_mremap(void *ptr, size_t oldsize, size_t newsize)
|
||||||
{
|
{
|
||||||
|
#ifdef __linux__
|
||||||
void *ret = mremap(ptr, oldsize, newsize, 0);
|
void *ret = mremap(ptr, oldsize, newsize, 0);
|
||||||
if (ret == MAP_FAILED)
|
if (ret == MAP_FAILED)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
#else
|
||||||
|
void *tmp, *ret;
|
||||||
|
size_t preserve_size;
|
||||||
|
|
||||||
|
preserve_size = oldsize;
|
||||||
|
if (preserve_size > newsize)
|
||||||
|
preserve_size = newsize;
|
||||||
|
tmp = malloc(preserve_size);
|
||||||
|
if (tmp == NULL)
|
||||||
|
return NULL;
|
||||||
|
memcpy(tmp, ptr, preserve_size);
|
||||||
|
|
||||||
|
munmap(ptr, oldsize);
|
||||||
|
ret = mmap(ptr, newsize, PROT_READ | PROT_WRITE,
|
||||||
|
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
|
||||||
|
if (ret == MAP_FAILED) {
|
||||||
|
free(tmp);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
memcpy(ret, tmp, preserve_size);
|
||||||
|
free(tmp);
|
||||||
|
return ret;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void plat_munmap(void *ptr, size_t size)
|
void plat_munmap(void *ptr, size_t size)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue