diff options
Diffstat (limited to 'src/common/mem_arena.cpp')
| -rw-r--r-- | src/common/mem_arena.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/common/mem_arena.cpp b/src/common/mem_arena.cpp index b918eb568..b76ac92d3 100644 --- a/src/common/mem_arena.cpp +++ b/src/common/mem_arena.cpp | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | #include "common/memory_util.h" | 20 | #include "common/memory_util.h" |
| 21 | #include "common/mem_arena.h" | 21 | #include "common/mem_arena.h" |
| 22 | #include "common/string_util.h" | ||
| 22 | 23 | ||
| 23 | #ifndef _WIN32 | 24 | #ifndef _WIN32 |
| 24 | #include <sys/stat.h> | 25 | #include <sys/stat.h> |
| @@ -98,15 +99,7 @@ int ashmem_unpin_region(int fd, size_t offset, size_t len) | |||
| 98 | #endif // Android | 99 | #endif // Android |
| 99 | 100 | ||
| 100 | 101 | ||
| 101 | 102 | #if defined(_WIN32) && !defined(_XBOX) | |
| 102 | #ifndef _WIN32 | ||
| 103 | // do not make this "static" | ||
| 104 | #if defined(MAEMO) || defined(MEEGO_EDITION_HARMATTAN) | ||
| 105 | std::string ram_temp_file = "/home/user/gc_mem.tmp"; | ||
| 106 | #else | ||
| 107 | std::string ram_temp_file = "/tmp/gc_mem.tmp"; | ||
| 108 | #endif | ||
| 109 | #elif !defined(_XBOX) | ||
| 110 | SYSTEM_INFO sysInfo; | 103 | SYSTEM_INFO sysInfo; |
| 111 | #endif | 104 | #endif |
| 112 | 105 | ||
| @@ -145,20 +138,26 @@ void MemArena::GrabLowMemSpace(size_t size) | |||
| 145 | return; | 138 | return; |
| 146 | } | 139 | } |
| 147 | #else | 140 | #else |
| 148 | mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; | 141 | // Try to find a non-existing filename for our shared memory. |
| 149 | fd = open(ram_temp_file.c_str(), O_RDWR | O_CREAT, mode); | 142 | // In most cases the first one will be available, but it's nicer to search |
| 150 | if (fd < 0) | 143 | // a bit more. |
| 151 | { | 144 | for (int i = 0; i < 10000; i++) |
| 152 | ERROR_LOG(MEMMAP, "Failed to grab memory space as a file: %s of size: %08x errno: %d", ram_temp_file.c_str(), (int)size, (int)(errno)); | ||
| 153 | return; | ||
| 154 | } | ||
| 155 | // delete immediately, we keep the fd so it still lives | ||
| 156 | unlink(ram_temp_file.c_str()); | ||
| 157 | if (ftruncate(fd, size) != 0) | ||
| 158 | { | 145 | { |
| 159 | ERROR_LOG(MEMMAP, "Failed to ftruncate %d to size %08x", (int)fd, (int)size); | 146 | std::string file_name = StringFromFormat("/citramem.%d", i); |
| 147 | fd = shm_open(file_name.c_str(), O_RDWR | O_CREAT | O_EXCL, 0600); | ||
| 148 | if (fd != -1) | ||
| 149 | { | ||
| 150 | shm_unlink(file_name.c_str()); | ||
| 151 | break; | ||
| 152 | } | ||
| 153 | else if (errno != EEXIST) | ||
| 154 | { | ||
| 155 | ERROR_LOG(MEMMAP, "shm_open failed: %s", strerror(errno)); | ||
| 156 | return; | ||
| 157 | } | ||
| 160 | } | 158 | } |
| 161 | return; | 159 | if (ftruncate(fd, size) < 0) |
| 160 | ERROR_LOG(MEMMAP, "Failed to allocate low memory space"); | ||
| 162 | #endif | 161 | #endif |
| 163 | } | 162 | } |
| 164 | 163 | ||
| @@ -198,12 +197,12 @@ void *MemArena::CreateView(s64 offset, size_t size, void *base) | |||
| 198 | #elif defined(__FreeBSD__) | 197 | #elif defined(__FreeBSD__) |
| 199 | MAP_NOSYNC | | 198 | MAP_NOSYNC | |
| 200 | #endif | 199 | #endif |
| 201 | ((base == 0) ? 0 : MAP_FIXED), fd, offset); | 200 | ((base == nullptr) ? 0 : MAP_FIXED), fd, offset); |
| 202 | 201 | ||
| 203 | if (retval == MAP_FAILED) | 202 | if (retval == MAP_FAILED) |
| 204 | { | 203 | { |
| 205 | NOTICE_LOG(MEMMAP, "mmap on %s (fd: %d) failed", ram_temp_file.c_str(), (int)fd); | 204 | NOTICE_LOG(MEMMAP, "mmap failed"); |
| 206 | return 0; | 205 | return nullptr; |
| 207 | } | 206 | } |
| 208 | return retval; | 207 | return retval; |
| 209 | #endif | 208 | #endif |