help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-smalltalk] Segmentation fault when malloc in C


From: Mathieu Suen
Subject: [Help-smalltalk] Segmentation fault when malloc in C
Date: Wed, 30 Jun 2010 20:46:31 +0200

Hi,

When ever gst invoke my binding in C I got a Seg fault.
The code in is look like :


jit_stack *
alloc_jit_state (size_t insnSize)
{
  jit_stack * new_jit_stack;
  jit_insn * new_pc;
  new_pc = malloc (insnSize);
  new_jit_stack = malloc (sizeof (jit_stack));
  new_jit_stack->state.x.pc = new_pc;    // Line 5
  new_jit_stack->codeBuffer = new_pc;
  return new_jit_stack;
}

And my binding is set with:

  _gst_vm_proxy->defineCFunc ("lightningAllocJitState", alloc_jit_state);

Then in smalltalk I wrote the method that call the binding:

CJitState class >> primAlloc: nByte [
        "Allocate a new jit_state that hold the assembly code"
        <category: 'primitive allocation'>
        <cCall: 'lightningAllocJitState' returning: #{CJitState} args: 
#(#ulong)>
]

With all this I got the Seg fault and the backtrace is:

_gst_mem_alloc (h=0x28622100, sz=48) at alloc.c:226
226           blk->vSmall.avail--;
(gdb) bt
#0  _gst_mem_alloc (h=0x28622100, sz=48) at alloc.c:226
#1  0x280b7bb3 in _gst_tenure_oop (oop=0x28c08260) at oop.c:736
#2  0x280b7c19 in _gst_tenure_all_survivors () at oop.c:1692
#3  0x280b8fb0 in _gst_global_gc (next_allocation=0) at oop.c:1102
#4  0x280ba095 in _gst_scavenge () at oop.c:1269
#5  0x280b9861 in _gst_alloc_obj (size=32, p_oop=0xbfbfdf78) at oop.c:769
#6  0x280e5a07 in VMpr_Behavior_basicNewColon (id=71, numArgs=1) at dict.inl:704
#7  0x280e6401 in _gst_send_message_internal (sendSelector=0x28c01e30, 
sendArgs=1, receiver=0x28c02320, 
    method_class=0x28c055e0) at interp.c:2699
#8  0x280ecc24 in _gst_interpret (processOOP=0x28c08260) at vm.def:713
#9  0x280f7cf0 in _gst_nvmsg_send (receiver=0x28c01800, 
sendSelector=0x28c08210, args=0x0, sendArgs=0)
    at interp.c:2271
#10 0x280af3a3 in _gst_execute_statements (temps=0x0, statements=0x2862712c, 
undeclared=UNDECLARED_TEMPORARIES, 
    quiet=true) at comp.c:691
#11 0x280a0bb2 in parse_eval_definition (p=0xbfbfea70) at gst-parse.c:594
#12 0x280a222b in parse_doit (p=0xbfbfea70, fail_at_eof=Variable "fail_at_eof" 
is not available.
) at gst-parse.c:501
#13 0x280a2876 in parse_chunks (p=0xbfbfea70) at gst-parse.c:364
#14 0x280a2c4b in _gst_parse_chunks () at gst-parse.c:341
#15 0x280a3165 in _gst_parse_stream (method=false) at lex.c:1186
#16 0x280d1aca in _gst_process_file (fileName=0xbfbfed8f "test.st", 
dir=GST_DIR_ABS) at input.c:846
#17 0x08049302 in main (argc=750813184, argv=0x2cd9b000) at main.c:401

But I soon as I remove the line 5 (see the code in C) the seg fault disappear.
I don't really see why.

Thanks for the help

        Mth









___________________________________________________________________________
Yahoo! Mail réinvente le mail ! Découvrez le nouveau Yahoo! Mail et son 
interface révolutionnaire.
http://fr.mail.yahoo.com



reply via email to

[Prev in Thread] Current Thread [Next in Thread]