1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "precompile.h"
- #include "sp_shm.h"
- #include "sp_def.h"
- #include "shm_mem.h"
- #define MEM_KEY 95555
- #define MEM_SIZE (SHM_MEM_SIZE * 1024 * 1024)
- #define GET_ADDRESS(x) ((void*)((1+(x)) << 28))
- int sp_shm_get_range(int mask)
- {
- int i;
- int range = 0;
- /*if start to refactor, you can think about :
- * https://forums.pcsx2.net/Thread-blog-VirtualAlloc-on-Linux
- */
- for (i = 0; i < 7; ++i) {
- void *address = GET_ADDRESS(i);
- void *ret_address = VirtualAlloc(address, MEM_SIZE, MEM_RESERVE, PAGE_NOACCESS);
- if (address == ret_address) {
- range |= 1 << (i + 1);
- }
- if (ret_address)
- VirtualFree(ret_address, 0, MEM_RELEASE);
- }
- return range & mask;
- }
- void *sp_shm_init(int range, int newcreator)
- {
- int i;
- void *address;
- for (i = 0; i < 7; ++i) {
- if (range & (1 << (i+1))) {
- address = GET_ADDRESS(i);
- if (shm_mem_init2(MEM_KEY, address, newcreator) == 0)
- return address;
- }
- }
- return NULL;
- }
- void sp_shm_term()
- {
- //shm_mem_destroy();
- }
|