2

我正在使用红色火龙果板(版本 125-14),其中用户应用程序(编译为 .so 文件)根据 Web 请求在 nginx 中动态加载。更具体地说,Nginx 启动一个 websocket 服务器并加载应用程序以处理 websocket 数据。最近我想在我的应用程序中集成 lua,但是一个基本的 lua_pcall 会导致段错误。

    lua_State* L = luaL_newstate();
    luaL_openlibs(L);
    // execute script
    const char lua_script[] = "a=1;";
    int load_stat = luaL_loadbuffer(L, lua_script, strlen(lua_script), lua_script);
    lua_pcall(L, 0, 0, 0);
    // cleanup
    lua_close(L);

所以我在编译Lua的时候加了-g,用gdb看看有没有更多的信息。这就是我通过回溯得到的:

Thread 2 "nginx" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb3796440 (LWP 27528)]
0xb382fb5a in luaD_precall (L=0xb2f771c0, func=0xfffffff0, nresults=0) at ldo.c:511
511       switch (ttypetag(s2v(func))) {
(gdb) backtrace
#0  0xb382fb5a in luaD_precall (L=0xb2f771c0, func=0xfffffff0, nresults=0) at ldo.c:511
#1  0xb382fdd2 in ccall (L=0xb2f771c0, func=0xfffffff0, nResults=0, inc=65537) at ldo.c:575
#2  0xb382fe36 in luaD_callnoyield (L=0xb2f771c0, func=0xfffffff0, nResults=0) at ldo.c:595
#3  0xb382cc5a in f_call (L=0xb2f771c0, ud=0xb3795304) at lapi.c:1031
#4  0xb382f17e in luaD_rawrunprotected (L=0xb2f771c0, f=0xb382cc3d <f_call>, ud=0xb3795304)
    at ldo.c:144
#5  0xb38303e4 in luaD_pcall (L=0xb2f771c0, func=0xb382cc3d <f_call>, u=0xb3795304,
    old_top=1292402216, ef=0) at ldo.c:892
#6  0xb382cce4 in lua_pcallk (L=0xb2f771c0, nargs=0, nresults=0, errfunc=0, ctx=0, k=0x0)
    at lapi.c:1057
#7  0xb3821870 in setupLUA ()
    at /root/.vs/CMakeProject1/657aa1fb-2594-4c6c-95fc-066d885f3252/src/CMakeProject1/CMakeProject1.cpp:103

看来传入的函数指针无效(0xfffffff0)。这意味着 Lua 堆栈有问题吗?

将确切的代码编译为独立的可执行文件是可以的,没有段错误并且结果是正确的。

4

0 回答 0