Feat: pre-validate if there is sufficient memory

This commit is contained in:
khanhduytran0 committed 2025-04-16 18:28:35 +07:00
1 parent f883ebe3e2
commit 9ce90315ab
1 file changed
+13
+13
View File
@@ -20,6 +20,14 @@
extern char **environ;
BOOL validateVirtualMemorySpace(int size) {
void *map = mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
// check if process successfully maps and unmaps a contiguous range
if(map == MAP_FAILED || munmap(map, size) != 0)
return NO;
return YES;
}
void init_loadDefaultEnv() {
/* Define default env */
@@ -167,6 +175,11 @@ int launchJVM(NSString *username, id launchTarget, int width, int height, int mi
allocmem = getPrefInt(@"java.allocated_memory");
}
NSLog(@"[JavaLauncher] Max RAM allocation is set to %d MB", allocmem);
if (!validateVirtualMemorySpace(allocmem)) {
UIKit_returnToSplitView();
showDialog(localize(@"Error", nil), @"Insufficient contiguous virtual memory space. Lower memory allocation and try again.");
return 1;
}
int margc = -1;
const char *margv[1000];