X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fplat.c;h=2842691e5e22d2e65be373eb10a26b27942ea8ea;hb=HEAD;hp=707d5f74e3e16533f48e11355d2d0f2e05cab273;hpb=1dd8f2036e7da6fc2e28863c9f0be589572a71da;p=libpicofe.git diff --git a/linux/plat.c b/linux/plat.c index 707d5f7..a5f70eb 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -13,15 +13,19 @@ #include #include #include +#include #include #include #include #include -#include #include #include +#ifndef __MINGW32__ +#include +#endif #include "../plat.h" +#include "../posix.h" /* XXX: maybe unhardcode pagesize? */ #define HUGETLB_PAGESIZE (2 * 1024 * 1024) @@ -55,7 +59,13 @@ static int plat_get_exe_dir(char *dst, int len) memcpy(dst, PICO_DATA_DIR, sizeof PICO_DATA_DIR); return sizeof(PICO_DATA_DIR) - 1; #else - int j, ret = readlink("/proc/self/exe", dst, len - 1); + int j, ret = readlink( +#ifdef __FreeBSD__ + "/proc/curproc/file", +#else + "/proc/self/exe", +#endif + dst, len - 1); if (ret < 0) { perror("readlink"); ret = 0; @@ -116,7 +126,7 @@ unsigned int plat_get_ticks_ms(void) ret = (unsigned)tv.tv_sec * 1000; /* approximate /= 1000 */ - ret += ((unsigned)tv.tv_usec * 4195) >> 22; + ret += ((unsigned)tv.tv_usec * 4194) >> 22; return ret; } @@ -141,6 +151,7 @@ void plat_sleep_ms(int ms) int plat_wait_event(int *fds_hnds, int count, int timeout_ms) { +#ifndef __MINGW32__ struct timeval tv, *timeout = NULL; int i, ret, fdmax = -1; fd_set fdset; @@ -172,7 +183,9 @@ int plat_wait_event(int *fds_hnds, int count, int timeout_ms) for (i = 0; i < count; i++) if (FD_ISSET(fds_hnds[i], &fdset)) ret = fds_hnds[i]; - +#else + int ret = -1; +#endif return ret; } @@ -207,6 +220,16 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) } flags &= ~MAP_HUGETLB; ret = mmap(req, size, prot, flags, -1, 0); +#ifdef MADV_HUGEPAGE + if (ret != MAP_FAILED && ((uintptr_t)ret & (2*1024*1024 - 1))) { + // try to manually realign assuming bottom-to-top alloc + munmap(ret, size); + ret = (void *)((uintptr_t)ret & ~(2*1024*1024 - 1)); + ret = mmap(ret, size, prot, flags, -1, 0); + } + if (ret != MAP_FAILED) + madvise(ret, size, MADV_HUGEPAGE); +#endif } if (ret == MAP_FAILED) return NULL;