我正在使用luajit2.0.4作为lua解释器。 这是情况:
在我加载像cjson.so这样的动态库之后
cjson = require('cjson') a=cjson.new() -- blahblah... do things i want然后我需要覆盖lib文件,(热升级的情况,这里cjson.so_1和cjson.so可能是一样的)
[root@localhost lib]# cp cjson.so_1 cjson.so cp: overwrite `cjson.so'? y它会强制内核截断cjson.so的pmap的物理内存,并在我调用时导致页面丢失
a=cjson.new()再一次,内核会将cjson.so lib重新复制到内存中,这次不会解析全局符号。 所以当我调用需要调用malloc()等外部函数的new()时 ,会发生段错误。
我已经找到了一种通过在C中编写卸载功能来重新加载的方法,
我的问题是我可以通过lua代码本身来做到这一点吗?
I'm using luajit2.0.4 as lua interpreter. here is the situation:
after I load a dynamic lib like cjson.so with
cjson = require('cjson') a=cjson.new() -- blahblah... do things i wantthen I need to overwrite the lib file, ( a situation of hot upgrade, and here cjson.so_1 and cjson.so might be the same)
[root@localhost lib]# cp cjson.so_1 cjson.so cp: overwrite `cjson.so'? yit will force kernel to truncate the physical memory of cjson.so's pmap, and causing a page missing then when I call
a=cjson.new()again, the kernel will recopy the cjson.so lib into memory, this time not parsing the global symbols. so when I call new() which need to call external functions like malloc(), a segment fault will occur.
I've already found a way to reload by writing a unload funtion in C,
and my question is can I do this by lua code itself?
最满意答案
可悲的是,这是不可能的。
由于Lua的工作方式,你必须使用C / C ++来处理这种情况,但不能使用Lua,我希望会有不同的答案,但是Lua已经达到了它的极限。
Sadly, this is not possible.
You'd have to approach the situation using C/C++, but not using Lua, due to the way in which Lua works, and I wish there would've been a different answer but Lua has got it's limits.
更多推荐
发布评论