From 3df48322655751e0a06d89e788b2924852895ad9 Mon Sep 17 00:00:00 2001 From: chrox Date: Sat, 24 Oct 2015 23:35:17 +0800 Subject: [PATCH 1/2] fix mcode allocation failure on Android This workaround makes a reservation of mmap slots that are hopefully near the address of `mcode_alloc_at`. Then it unmaps those slots and lets luajit allocate a large slot for mcode. --- platform/android/llapp_main.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/platform/android/llapp_main.lua b/platform/android/llapp_main.lua index 3eab5d099..99f665c03 100644 --- a/platform/android/llapp_main.lua +++ b/platform/android/llapp_main.lua @@ -5,6 +5,8 @@ local ffi = require("ffi") ffi.cdef[[ char *getenv(const char *name); int putenv(const char *envvar); + void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset); + int munmap(void *addr, size_t length); ]] -- check uri of the intent that starts this application @@ -29,6 +31,23 @@ local file = A.jni:context(A.app.activity.vm, function(JNI) end) A.LOGI("intent file path " .. (file or "")) +-- reservation enough mmap slots for mcode allocation +local reserved_slots = {} +for i = 1, 32 do + local len = 0x80000 + i*0x2000 + local p = ffi.C.mmap(nil, len, 0x3, 0x22, -1, 0) + A.LOGI("mmapped " .. tostring(p)) + table.insert(reserved_slots, {p = p, len = len}) +end +-- free the reservation immediately +for _, slot in ipairs(reserved_slots) do + local res = ffi.C.munmap(slot.p, slot.len) + A.LOGI("munmap " .. tostring(slot.p) .. " " .. res) +end +-- and allocate a large mcode segment, hopefully it will success. +require("jit.opt").start("sizemcode=512","maxmcode=512") +for i=1,100 do end -- Force allocation of one large segment + -- run koreader patch before koreader startup pcall(function() dofile("/sdcard/koreader/patch.lua") end) From f3dbf9ce2eaa403e5eeebc4b998b01e05531a986 Mon Sep 17 00:00:00 2001 From: chrox Date: Sun, 25 Oct 2015 12:34:20 +0800 Subject: [PATCH 2/2] move mmap workaround to android-luajit-launcher --- platform/android/llapp_main.lua | 19 ------------------- platform/android/luajit-launcher | 2 +- 2 files changed, 1 insertion(+), 20 deletions(-) diff --git a/platform/android/llapp_main.lua b/platform/android/llapp_main.lua index 99f665c03..3eab5d099 100644 --- a/platform/android/llapp_main.lua +++ b/platform/android/llapp_main.lua @@ -5,8 +5,6 @@ local ffi = require("ffi") ffi.cdef[[ char *getenv(const char *name); int putenv(const char *envvar); - void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset); - int munmap(void *addr, size_t length); ]] -- check uri of the intent that starts this application @@ -31,23 +29,6 @@ local file = A.jni:context(A.app.activity.vm, function(JNI) end) A.LOGI("intent file path " .. (file or "")) --- reservation enough mmap slots for mcode allocation -local reserved_slots = {} -for i = 1, 32 do - local len = 0x80000 + i*0x2000 - local p = ffi.C.mmap(nil, len, 0x3, 0x22, -1, 0) - A.LOGI("mmapped " .. tostring(p)) - table.insert(reserved_slots, {p = p, len = len}) -end --- free the reservation immediately -for _, slot in ipairs(reserved_slots) do - local res = ffi.C.munmap(slot.p, slot.len) - A.LOGI("munmap " .. tostring(slot.p) .. " " .. res) -end --- and allocate a large mcode segment, hopefully it will success. -require("jit.opt").start("sizemcode=512","maxmcode=512") -for i=1,100 do end -- Force allocation of one large segment - -- run koreader patch before koreader startup pcall(function() dofile("/sdcard/koreader/patch.lua") end) diff --git a/platform/android/luajit-launcher b/platform/android/luajit-launcher index b45a1c2df..63f26f697 160000 --- a/platform/android/luajit-launcher +++ b/platform/android/luajit-launcher @@ -1 +1 @@ -Subproject commit b45a1c2df8400ef96c31967646d3f44501c11b39 +Subproject commit 63f26f697fc2f1ce1ef2b0af61dd7875b2a8ce25