Ticket #804 (closed RFC: fixed)

Opened 5 years ago

Last modified 4 years ago

Avoid entering inner runloop when catching a exception thrown from C with a pir handler

Reported by: NotFound Owned by: NotFound
Priority: normal Milestone:
Component: core Version: 1.3.0
Severity: high Keywords:
Cc: Language:
Patch status: applied Platform: all

Description

The attached patch modifies Parrot_ex_throw_from_c to avoid entering a new runloop when invoking a pir exception handler. This fixes the pir example code on RT #63592

Attachments

RT_63592.patch Download (3.2 KB) - added by NotFound 5 years ago.
TT_804.patch Download (4.2 KB) - added by NotFound 5 years ago.
Cleaned version

Change History

Changed 5 years ago by NotFound

Changed 5 years ago by coke

  • owner set to NotFound

Verified the PIR snippet and the original perl6 snippet, both seem to not segfault now. (at least not in a few seconds as without the patch.)

Changed 5 years ago by NotFound

Cleaned version

Changed 5 years ago by NotFound

Attached a cleaner version after some discussion and suggestions on irc.

Changed 5 years ago by fperrad

this TT_804.patch solves  http://rt.perl.org/rt3/Public/Bug/Display.html?id=59968

but not yet TT #472, where I need to retrieve the backtrace in the handler :

.HLL "lua"
.loadlib "lua_group"

.sub 'main'
    $P1 = box 42
    $P2 = new 'LuaNil'
    push_eh _handler
    $P3 = $P1 + $P2
    say $P3
    pop_eh
    end
  _handler:
    .local pmc ex
    .get_results (ex)
    say 'catch'
# this part doesn't work
#    .local pmc bt
#    bt = ex.'backtrace'()
#    say 'bt'
    rethrow ex
.end

Changed 5 years ago by NotFound

  • status changed from new to assigned
  • patch set to applied

Last patch applied in r39937, I'll keep the ticket opened while looking at the related problems.

Changed 5 years ago by fperrad

With the following PIR code, I obtain a Segfault

$ cat add.pir
.HLL "lua"
.loadlib "lua_group"

.sub 'main'
    push_eh _handler
    'add'()
    pop_eh
    end
  _handler:
    .local pmc ex
    .get_results (ex)
    say 'catch'
    $S0 = ex
    say $S0
    .local pmc bt
    bt = ex.'backtrace'()
    say 'bt'
    .return ()
.end

.sub 'add'
    $P0 = box 42
    $P1 = new 'LuaNil'
    $P2 = $P0 + $P1
.end

$ ./parrot add.pir
catch
attempt to perform arithmetic on a nil value
Segmentation fault

gdb gives :

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0xb6d0e8e0 (LWP 7086)]
0xb7d5c98f in clone_key_arg (interp=0x8dbd040, st=0xbf80b06c) at src/call/pcc.c:1196
1196	    if (key->vtable->base_type != enum_class_Key)
(gdb) bt
#0  0xb7d5c98f in clone_key_arg (interp=0x8dbd040, st=0xbf80b06c) at src/call/pcc.c:1196
#1  0xb7d5ff46 in Parrot_convert_arg (interp=0x8dbd040, st=0xbf80b06c)
    at src/call/pcc.c:1824
#2  0xb7d60c1d in Parrot_process_args (interp=0x8dbd040, st=0xbf80b06c, 
    param_or_result=PARROT_PASS_PARAMS) at src/call/pcc.c:1701
#3  0xb7d61198 in parrot_pass_args (interp=0x8dbd040, src_ctx=0x8e817b0, 
    dest_ctx=0x8e82e88, src_indexes=0x8e837a4, dest_indexes=0xbf80b18c, 
    param_or_result=PARROT_PASS_PARAMS) at src/call/pcc.c:1893
#4  0xb7eac624 in Parrot_Exception_nci_backtrace (interp=0x8dbd040, pmc=0x8e1c278)
    at /home/user/checkout/parrot/tools/build/../../lib/Parrot/Pmc2c/PCCMETHOD.pm:442
#5  0xb7ebc560 in Parrot_NCI_invoke (interp=0x8dbd040, pmc=0x8e1c278, next=0x8e837c8)
    at ./src/pmc/nci.pmc:335
#6  0xb7cf322d in Parrot_callmethodcc_p_sc (cur_opcode=0x8e837bc, interp=0x8dbd040)
    at src/ops/object.ops:80
#7  0xb7d8c6b0 in runops_slow_core (interp=0x8dbd040, pc=0x8e837bc)
    at src/runcore/cores.c:462
#8  0xb7d8b2ae in runops_int (interp=0x8dbd040, offset=16) at src/runcore/main.c:987
#9  0xb7d64ae5 in runops (interp=0x8dbd040, offs=0) at src/call/ops.c:119
#10 0xb7d64f23 in runops_args (interp=0x8dbd040, sub=0x8e309a8, obj=0x8e20298, 
    meth_unused=0x0, sig=0xb7fac73f "vP", ap=0xbf80b39c "x\t�\b��\200��9")
    at src/call/ops.c:269
#11 0xb7d65de6 in Parrot_runops_fromc_args (interp=0x8dbd040, sub=0x8e309a8, 
    sig=0xb7fac73f "vP") at src/call/ops.c:338
#12 0xb7d42a37 in Parrot_runcode (interp=0x8dbd040, argc=1, argv=0xbf80b518)
    at src/embed.c:1021
#13 0xb7f808ef in imcc_run_pbc (interp=0x8dbd040, obj_file=0, output_file=0x0, argc=1, 
    argv=0xbf80b518) at compilers/imcc/main.c:801
#14 0xb7f814ec in imcc_run (interp=0x8dbd040, 
    sourcefile=0xbf80c68e "languages/lua/add.pir", argc=1, argv=0xbf80b518)
    at compilers/imcc/main.c:1092
#15 0x08048988 in main (argc=1, argv=0xbf80b518) at src/main.c:60
(gdb) 

Changed 4 years ago by NotFound

TT #472 is closed. Can this ticket be also closed or there is some remaining issue?

Changed 4 years ago by NotFound

  • status changed from assigned to closed
  • resolution set to fixed

No objection in moths, closing ticket.

Note: See TracTickets for help on using tickets.