X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fplat.c;h=707d5f74e3e16533f48e11355d2d0f2e05cab273;hb=533726df95e88932d0bf72345a438ae415b8c04e;hp=06c315e830212e7b394344c649aab84cc534e176;hpb=26ea18173c1228dd5ce39e2a88ffe1ae10fcb365;p=libpicofe.git diff --git a/linux/plat.c b/linux/plat.c index 06c315e..707d5f7 100644 --- a/linux/plat.c +++ b/linux/plat.c @@ -41,7 +41,15 @@ int plat_is_dir(const char *path) return 0; } -static int plat_get_data_dir(char *dst, int len) +int plat_get_data_dir(char *dst, int len) +{ + if (len > 1) + strcpy(dst, "/"); + else *dst = 0; + return strlen(dst); +} + +static int plat_get_exe_dir(char *dst, int len) { #ifdef PICO_DATA_DIR memcpy(dst, PICO_DATA_DIR, sizeof PICO_DATA_DIR); @@ -65,9 +73,9 @@ static int plat_get_data_dir(char *dst, int len) int plat_get_skin_dir(char *dst, int len) { - int ret = plat_get_data_dir(dst, 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; @@ -78,7 +86,7 @@ int plat_get_skin_dir(char *dst, int len) #endif int plat_get_root_dir(char *dst, int len) { -#if !defined(__GP2X__) && !defined(PANDORA) +#if !defined(NO_HOME_DIR) && !defined(__GP2X__) && !defined(PANDORA) const char *home = getenv("HOME"); int ret; @@ -90,7 +98,7 @@ int plat_get_root_dir(char *dst, int len) return ret; } #endif - return plat_get_data_dir(dst, len); + return plat_get_exe_dir(dst, len); } #ifdef __GP2X__ @@ -184,6 +192,10 @@ void *plat_mmap(unsigned long addr, size_t size, int need_exec, int is_fixed) */ if (size >= HUGETLB_THRESHOLD) flags |= MAP_HUGETLB; +#ifdef MAP_JIT + if (need_exec) + flags |= MAP_JIT; +#endif ret = mmap(req, size, prot, flags, -1, 0); if (ret == MAP_FAILED && (flags & MAP_HUGETLB)) { @@ -215,9 +227,22 @@ void *plat_mremap(void *ptr, size_t oldsize, size_t newsize) { void *ret; +#ifdef MREMAP_MAYMOVE ret = mremap(ptr, oldsize, newsize, MREMAP_MAYMOVE); if (ret == MAP_FAILED) - return NULL; +#endif + { + fprintf(stderr, "mremap %p %zd %zd: ", + ptr, oldsize, newsize); + perror(NULL); + // might be because huge pages can't be remapped, + // just make a new mapping + ret = plat_mmap(0, newsize, 0, 0); + if (ret == MAP_FAILED) + return NULL; + memcpy(ret, ptr, oldsize); + munmap(ptr, oldsize); + } if (ret != ptr) printf("warning: mremap moved: %p -> %p\n", ptr, ret);