如何在lua中卸载动态库(how to unload dynamic lib in lua)

编程入门 行业动态 更新时间:2024-10-27 22:20:01
如何在lua中卸载动态库(how to unload dynamic lib in lua)

我正在使用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 want

then 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'? y

it 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.

更多推荐

本文发布于:2023-08-04 11:24:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1415363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:动态   如何在   lua   lib   unload

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!