X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fplat.c;h=2842691e5e22d2e65be373eb10a26b27942ea8ea;hb=HEAD;hp=9109a3242c5e251fc63083820e3290d557a654af;hpb=5d636caaaf684a5d4832cd5d4460dfc214a815de;p=libpicofe.git diff --git a/linux/plat.c b/linux/plat.c index 9109a32..2cdcace 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -55,7 +56,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; @@ -75,7 +82,7 @@ int plat_get_skin_dir(char *dst, int len) { int ret = plat_get_exe_dir(dst, len); if (ret < 0) - return ret; + ret = 0; memcpy(dst + ret, "skin/", sizeof "skin/"); return ret + sizeof("skin/") - 1; @@ -207,6 +214,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;