diff options
Diffstat (limited to 'src/os')
| -rw-r--r-- | src/os/os_linux.c | 38 | ||||
| -rw-r--r-- | src/os/os_wine.c | 90 |
2 files changed, 128 insertions, 0 deletions
diff --git a/src/os/os_linux.c b/src/os/os_linux.c index 46a0434b..e11a41a2 100644 --- a/src/os/os_linux.c +++ b/src/os/os_linux.c @@ -2,6 +2,7 @@ #include <sched.h> #include <unistd.h> #include <stdint.h> +#include <sys/personality.h> #include "os.h" #include "signals.h" @@ -62,3 +63,40 @@ void EmuX86Syscall(void* emu) { x86Syscall((x64emu_t*)emu); } + +void PersonalityAddrLimit32Bit(void) +{ + personality(ADDR_LIMIT_32BIT); +} + +void* InternalMmap(void* addr, unsigned long length, int prot, int flags, int fd, ssize_t offset) +{ +#if 1 // def STATICBUILD + void* ret = (void*)syscall(__NR_mmap, addr, length, prot, flags, fd, offset); +#else + static int grab = 1; + typedef void* (*pFpLiiiL_t)(void*, unsigned long, int, int, int, size_t); + static pFpLiiiL_t libc_mmap64 = NULL; + if (grab) { + libc_mmap64 = dlsym(RTLD_NEXT, "mmap64"); + } + void* ret = libc_mmap64(addr, length, prot, flags, fd, offset); +#endif + return ret; +} + +int InternalMunmap(void* addr, unsigned long length) +{ +#if 1 // def STATICBUILD + int ret = syscall(__NR_munmap, addr, length); +#else + static int grab = 1; + typedef int (*iFpL_t)(void*, unsigned long); + static iFpL_t libc_munmap = NULL; + if (grab) { + libc_munmap = dlsym(RTLD_NEXT, "munmap"); + } + int ret = libc_munmap(addr, length); +#endif + return ret; +} \ No newline at end of file diff --git a/src/os/os_wine.c b/src/os/os_wine.c new file mode 100644 index 00000000..e5bc47b5 --- /dev/null +++ b/src/os/os_wine.c @@ -0,0 +1,90 @@ +#include <windows.h> + +#include "os.h" + +int GetTID(void) +{ + return GetCurrentThreadId(); +} + +void PersonalityAddrLimit32Bit(void) { } + +ULONG_PTR default_zero_bits32 = 0x7fffffff; + +static uint32_t prot_unix_to_win32(uint32_t unx) +{ + if ((unx & (PROT_READ | PROT_WRITE | PROT_EXEC)) == (PROT_READ | PROT_WRITE | PROT_EXEC)) + return PAGE_EXECUTE_READWRITE; + if ((unx & (PROT_READ | PROT_EXEC)) == (PROT_READ | PROT_EXEC)) + return PAGE_EXECUTE_READ; + if ((unx & PROT_EXEC) == PROT_EXEC) + return PAGE_EXECUTE_READ; + if ((unx & (PROT_READ | PROT_WRITE)) == (PROT_READ | PROT_WRITE)) + return PAGE_READWRITE; + if ((unx & PROT_READ) == PROT_READ) + return PAGE_READONLY; + return 0; +} + +int mprotect(void* addr, size_t len, int prot) +{ + ULONG old_prot; + if (VirtualProtect(&addr, len, prot_unix_to_win32(prot), &old_prot)) + return 0; + return -1; +} + +void* mmap(void* addr, size_t length, int prot, int flags, int fd, off_t offset) +{ + if (fd && fd != -1) { + return MAP_FAILED; + } + if (offset) { + return MAP_FAILED; + } + return VirtualAlloc(addr, length, MEM_COMMIT | MEM_RESERVE, prot_unix_to_win32(prot)); +} + +int munmap(void* addr, size_t length) +{ + if (VirtualFree(addr, length, MEM_RELEASE)) + return 0; + return -1; +} + +void* InternalMmap(void* addr, unsigned long length, int prot, int flags, int fd, ssize_t offset) +{ + return mmap(addr, length, prot, flags, fd, offset); +} + +int InternalMunmap(void* addr, unsigned long length) +{ + return munmap(addr, length); +} + +void* WinMalloc(size_t size) +{ + void* ret; + ret = HeapAlloc(GetProcessHeap(), 0, size); + return ret; +} + +void* WinRealloc(void* ptr, size_t size) +{ + void* ret; + if (!ptr) return WinMalloc(size); + ret = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ptr, size); + return ret; +} + +void* WinCalloc(size_t nmemb, size_t size) +{ + void* ret; + ret = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, nmemb * size); + return ret; +} + +void WinFree(void* ptr) +{ + HeapFree(GetProcessHeap(), 0, ptr); +} \ No newline at end of file |