View Single Post
Old 09-10-2020, 08:04 AM   #18
pazos
cosiņeiro
pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.pazos ought to be getting tired of karma fortunes by now.
 
Posts: 1,406
Karma: 2451781
Join Date: Apr 2014
Device: BQ Cervantes 4
Quote:
Originally Posted by nhedgehog View Post
Just recognized it myself and run bt.
But what happend after I quit gdb was that I got a message about not having registered an Adobe ID with the device, this message I have not seen before and it is true, I did not have registered it with Adobe.
The adobe ID stuff is very fishy, but I have no idea.

The backtrace points to the garbage collector failing to free some memory. Not sure if it is a bug in the code because that will affect all models and all other platforms.

Anyways, could you try to reproduce with:

Code:
diff --git a/frontend/device/pocketbook/device.lua b/frontend/device/pocketbook/device.lua
index 84c76061..8f36586e 100644
--- a/frontend/device/pocketbook/device.lua
+++ b/frontend/device/pocketbook/device.lua
@@ -10,6 +10,13 @@ require("ffi/posix_h")
 require("ffi/linux_input_h")
 require("ffi/inkview_h")
 
+ffi.cdef[[
+    void *mmap(void *addr, size_t length, int prot, int flags, int fd, size_t offset);
+    int munmap(void *addr, size_t length);
+]]
+
+
+
 -- FIXME: Signal ffi/input.lua (brought in by device/input later on) that we want to use poll mode backend.
 -- Remove this once backend becomes poll-only.
 _G.POCKETBOOK_FFI = true
@@ -17,6 +24,14 @@ _G.POCKETBOOK_FFI = true
 local function yes() return true end
 local function no() return false end
 
+local function isModelBroken()
+    local model = ffi.string(inkview.GetDeviceModel())
+    if model == "PB627" or model == "PB631" or model == "PocketBook 631" then
+        return true
+    end
+    return false
+end
+
 local ext_path = "/mnt/ext1/system/config/extensions.cfg"
 local app_name = "koreader.app"
 
@@ -36,8 +51,28 @@ local PocketBook = Generic:new{
 
     -- all devices that have warmth lights use inkview api
     hasNaturalLightApi = yes,
+
+    should_restrict_JIT = isModelBroken,
 }
 
+function PocketBook:restrictJIT()
+    -- reservation enough mmap slots for mcode allocation
+    local reserved_slots = {}
+    for i = 1, 32 do
+        local len = 0x10000 + i*0x1000
+        local p = ffi.C.mmap(nil, len, 0x3, 0x22, -1, 0)
+        table.insert(reserved_slots, {p = p, len = len})
+    end
+    -- free the reservation immediately
+    for _, slot in ipairs(reserved_slots) do
+        ffi.C.munmap(slot.p, slot.len)
+    end
+    -- and allocate a large mcode segment, hopefully it will succeed.
+    -- 64KB ought to be enough for everyone with 10000 loop threshold
+    require("jit.opt").start("sizemcode=64","maxmcode=64", "hotloop=10000")
+    for _=1,20000 do end  -- Force allocation of one large segment
+end
+
 -- Make sure the C BB cannot be used on devices with a 24bpp fb
 function PocketBook:blacklistCBB()
     -- As well as on those than can't do HW inversion, as otherwise NightMode would be ineffective.
@@ -70,6 +105,10 @@ local function tryOpenBook()
 end
 
 function PocketBook:init()
+    if self.should_restrict_JIT then
+        self:restrictJIT()
+    end
+
     -- Blacklist the C BB before the first BB require...
     self:blacklistCBB()
Bear with me if the diff breaks the code, because it is very untested
pazos is offline   Reply With Quote