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);
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;
#endif
int plat_get_root_dir(char *dst, int len)
{
-#if defined(__GP2X__) || defined(PANDORA)
- return plat_get_data_dir(dst, len);
-#else
- char *home = getenv("HOME");
- size_t nb = strlen(home);
+#if !defined(NO_HOME_DIR) && !defined(__GP2X__) && !defined(PANDORA)
+ const char *home = getenv("HOME");
+ int ret;
- memcpy(dst, home, nb);
- memcpy(dst + nb, PICO_HOME_DIR, sizeof PICO_HOME_DIR);
- mkdir(dst, 0755);
- return nb + sizeof(PICO_HOME_DIR) - 1;
+ if (home != NULL) {
+ ret = snprintf(dst, len, "%s%s", home, PICO_HOME_DIR);
+ if (ret >= len)
+ ret = len - 1;
+ mkdir(dst, 0755);
+ return ret;
+ }
#endif
+ return plat_get_exe_dir(dst, len);
}
#ifdef __GP2X__
req = (void *)addr;
if (need_exec)
prot |= PROT_EXEC;
+ /* avoid MAP_FIXED, it overrides existing mappings..
if (is_fixed)
flags |= MAP_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)) {
if (ret == MAP_FAILED)
return NULL;
- if (req != NULL && ret != req)
- fprintf(stderr,
- "warning: mmaped to %p, requested %p\n", ret, req);
+ if (req != NULL && ret != req) {
+ fprintf(stderr, "%s: mmaped to %p, requested %p\n",
+ is_fixed ? "error" : "warning", ret, req);
+ if (is_fixed) {
+ munmap(ret, size);
+ return NULL;
+ }
+ }
return ret;
}
{
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);