Hi Sven,

I think that's the library we are talking about... However, make that call to 
@lr[0] will NOT fix the problem, as I mentioned in previous emails.   To help 
you see what happened, I attach the debug log (from lazarus assembly window) 
again.

Also, it is very strange that my programs act very differently on Linux64 and 
Win32.  On windows, even the "correct" version (which runs well on command 
line) will cause access violation in the IDE!

Thanks!

在 日, 12月 30, 2012 at 9:34 下午,Sven Barth <[email protected]> 写道:
On 30.12.2012 05:30, leledumbo wrote: 
> Program received signal SIGSEGV, Segmentation fault. 
> 0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6 
> (gdb) bt 
> #0 0xb7e386d2 in ?? () from /lib/i386-linux-gnu/libc.so.6 
> #1 0xb7fa2d12 in ?? () from /usr/lib/i386-linux-gnu/liblua5.2.so.0 
> #2 0xb7f95f09 in lua_setfield () from 
> /usr/lib/i386-linux-gnu/liblua5.2.so.0 
> #3 0xb7fa9a9a in luaL_setfuncs () from 
> /usr/lib/i386-linux-gnu/liblua5.2.so.0 
> #4 0x08066821 in LUAL_SETFUNCS (L=0x8071008, LR=..., highLR=1, NUP=0) at 
> lua52.pas:835 
> #5 0x080669e4 in LUAL_NEWLIB (L=0x8071008, LR=..., highLR=1) at 
> lua52.pas:859 
> #6 0x0804a3ea in main () at test.pas:31 
> 
> As you can see, the pointer changes when you pass an open array into another 
> function expecting open array, even when static array is used (I've tried 
> that one too). So, somebody with enough compiler knowledge should analyze 
> this. Maybe you should create a bug report. 

If the code of that lua52.pas is the one available here: 
http://lua-users.org/files/wiki_insecure/lua52.pas the error is understandable 
if one looks at the luaL_newlib function (the array overload): 

=== source begin === 

procedure luaL_newlib(L: Plua_State; lr: array of luaL_Reg); 
begin 
luaL_newlibtable(L, lr); 
luaL_setfuncs(L, @lr, 0); 
end; 

=== source end === 

The address of the open array parameter is passed, not the array to the first 
element. If you change the luaL_setfuncs call to 

=== source begin === 

luaL_setfuncs(L, @lr[0], 0); 

=== source end === 

it should work... 

Regards, 
Sven 

-- 
_______________________________________________ 
Lazarus mailing list 
[email protected] 
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
== CASE 1: SIGSEGV @ callq 0x4e01d8 
==================================================================
    procedure luaL_newlib(L: Plua_State; lr: array of luaL_Reg);
    begin
856   luaL_newlibtable(L, lr);
857   luaL_setfuncs(L, @lr, 0);
      //luaL_setfuncs(L, lr, 0);
859 end;
------------------------------------------------------------------------------------------------------
lua52.pas:856           luaL_newlibtable(L, lr);
4E0364 488b55e8         mov    -0x18(%rbp),%rdx
4E0368 488b75f0         mov    -0x10(%rbp),%rsi
4E036C 488b7df8         mov    -0x8(%rbp),%rdi
4E0370 e8e3feffff       callq  0x4e0258 <LUAL_NEWLIBTABLE>
lua52.pas:857           luaL_setfuncs(L, @lr, 0);
4E0375 488b75f0         mov    -0x10(%rbp),%rsi
4E0379 488b7df8         mov    -0x8(%rbp),%rdi
4E037D ba00000000       mov    $0x0,%edx
4E0382 e851feffff       callq  0x4e01d8 
<LUA52_LUAL_SETFUNCS$POINTER$PLUAL_REG$LONGINT>  <--
lua52.pas:859           end;

== CASE 2: SIGSEGV @ callq 0x4e01d8 
==================================================================
    procedure luaL_newlib(L: Plua_State; lr: array of luaL_Reg);
    begin
856   luaL_newlibtable(L, lr);
857   luaL_setfuncs(L, @lr[0], 0);
      //luaL_setfuncs(L, lr, 0);
859 end;
------------------------------------------------------------------------------------------------------
lua52.pas:856           luaL_newlibtable(L, lr);
4E0364 488b55e8         mov    -0x18(%rbp),%rdx
4E0368 488b75f0         mov    -0x10(%rbp),%rsi
4E036C 488b7df8         mov    -0x8(%rbp),%rdi
4E0370 e8e3feffff       callq  0x4e0258 <LUAL_NEWLIBTABLE>
lua52.pas:857           luaL_setfuncs(L, @lr[0], 0);
4E0375 488b75f0         mov    -0x10(%rbp),%rsi
4E0379 488b7df8         mov    -0x8(%rbp),%rdi
4E037D ba00000000       mov    $0x0,%edx
4E0382 e851feffff       callq  0x4e01d8 
<LUA52_LUAL_SETFUNCS$POINTER$PLUAL_REG$LONGINT>  <--
lua52.pas:859           end;

== CASE 3: NO ERROR 
==================================================================================
    procedure luaL_newlib(L: Plua_State; lr: array of luaL_Reg);
    begin
856   luaL_newlibtable(L, lr);
      // luaL_setfuncs(L, @lr, 0);
858   luaL_setfuncs(L, lr, 0);
859 end;
------------------------------------------------------------------------------------------------------
lua52.pas:856           luaL_newlibtable(L, lr);
4E0364 488b55e8         mov    -0x18(%rbp),%rdx
4E0368 488b75f0         mov    -0x10(%rbp),%rsi
4E036C 488b7df8         mov    -0x8(%rbp),%rdi
4E0370 e8e3feffff       callq  0x4e0258 <LUAL_NEWLIBTABLE>
lua52.pas:858           luaL_setfuncs(L, lr, 0);
4E0375 488b55e8         mov    -0x18(%rbp),%rdx
4E0379 488b75f0         mov    -0x10(%rbp),%rsi
4E037D 488b7df8         mov    -0x8(%rbp),%rdi
4E0381 b900000000       mov    $0x0,%ecx
4E0386 e855feffff       callq  0x4e01e0 <LUAL_SETFUNCS>
lua52.pas:859           end;
------------------------------------------------------------------------------------------------------
830 procedure luaL_setfuncs(L: Plua_State; lr: PluaL_Reg; nup: Integer); cdecl; 
external LUA_LIB_NAME;

    procedure luaL_setfuncs(L: Plua_State; lr: array of luaL_Reg; nup: Integer);
    begin
834   luaL_setfuncs(L, @lr, nup);
835 end;
------------------------------------------------------------------------------------------------------
lua52.pas:834           luaL_setfuncs(L, @lr, nup);
4E022F 488b75f0         mov    -0x10(%rbp),%rsi
4E0233 8b55e8           mov    -0x18(%rbp),%edx
4E0236 488b7df8         mov    -0x8(%rbp),%rdi
4E023A e899ffffff       callq  0x4e01d8 
<LUA52_LUAL_SETFUNCS$POINTER$PLUAL_REG$LONGINT>
lua52.pas:835           end;

======================================================================================================

--
_______________________________________________
Lazarus mailing list
[email protected]
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply via email to