@@ -164,6 +164,45 @@ func getLibFromImage(t *testing.T, name, platform, fullPath, target string) {
164164 require .NoError (t , err )
165165}
166166
167+ func TestX86LuaClose (t * testing.T ) {
168+ testdata := []struct {
169+ name string
170+ glRefExpected uint64
171+ curLExpected uint64
172+ code []byte
173+ }{
174+ {
175+ name : "size-optimized-register-zero" ,
176+ glRefExpected : 0x10 ,
177+ curLExpected : 0x158 ,
178+ code : []byte {
179+ 0x41 , 0x55 , // pushq %r13
180+ 0x4c , 0x8d , 0x2d , 0x3f , 0xd4 , 0xff , 0xff , // leaq -0x2bc1(%rip), %r13
181+ 0x41 , 0x54 , // pushq %r12
182+ 0x41 , 0xbc , 0x0a , 0x00 , 0x00 , 0x00 , // movl $0xa, %r12d
183+ 0x55 , // pushq %rbp
184+ 0x53 , // pushq %rbx
185+ 0x51 , // pushq %rcx
186+ 0x48 , 0x8b , 0x5f , 0x10 , // movq 0x10(%rdi), %rbx
187+ 0x48 , 0x8b , 0xab , 0xc8 , 0x00 , 0x00 , 0x00 , // movq 0xc8(%rbx), %rbp
188+ 0x48 , 0x89 , 0xef , // movq %rbp, %rdi
189+ 0xe8 , 0x6e , 0x17 , 0x00 , 0x00 , // callq 0x175f0 <luaJIT_profile_stop>
190+ 0x31 , 0xf6 , // xorl %esi, %esi
191+ 0x48 , 0x89 , 0xef , // movq %rbp, %rdi
192+ 0x48 , 0x89 , 0xb3 , 0x58 , 0x01 , 0x00 , 0x00 , // movq %rsi, 0x158(%rbx)
193+ },
194+ },
195+ }
196+
197+ for _ , test := range testdata {
198+ x := x86Extractor {}
199+ glref , curL , err := x .findOffsetsFromLuaClose (test .code )
200+ require .NoError (t , err )
201+ require .Equal (t , test .glRefExpected , glref )
202+ require .Equal (t , test .curLExpected , curL )
203+ }
204+ }
205+
167206// spot testing
168207func TestFiles (t * testing.T ) {
169208 files , err := os .ReadDir ("./testdata" )
0 commit comments