caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christophe Raffalli <christophe@raffalli.eu>
To: Xavier Leroy <Xavier.Leroy@inria.fr>, caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Global roots
Date: Mon, 21 Dec 2020 22:03:32 +0100	[thread overview]
Message-ID: <X+ENpGYozJ31RJui@oulala> (raw)
In-Reply-To: <X+EIOESufd+dxKEa@oulala>

[-- Attachment #1: Type: text/plain, Size: 3315 bytes --]

>
> Thanks for the help.
>
> I took a stronger path and initialized to (fun _ -> assert false).
>
> It seems I have no more segfault (not sure yet as the segfault was no reproductible).


In fact the segfault it still there, takes many run to observe it ...
It is still in caml_callback_asm, meaning the global root pointing
to the OCaml function has been corrupted.

Note: I use caml_register_generational_root and
caml_modify_generational_root to register and modify
the pointer to the callback.

I give my code doing the callback, following some
example I found on the net, in case someone has a comment/hint.
May be the order between Camlparam and acquire runtime is wrong ?

This code reaquires the runtime lock, which is released only by the X event loop
that performs the callback; This means that the same C thread release and acquire the
global runtime lock. I have only two threads.


--------------------------------------------------------------------
static void protect_callback(char *name, value f, value v1)
{
  caml_acquire_runtime_system();
  {
    CAMLparam2(f,v1);
    CAMLlocal1(res);
    res = caml_callback_exn(f, v1);
    if(Is_exception_result(res))
      fprintf(stderr, "Egl.main_loop: "
	      "WARNING: %s raised an exception\n", name) ;
    CAMLdrop;
  }
  caml_release_runtime_system();
}

static void protect_callback2(char *name, value f, value v1, value v2)
{
  caml_acquire_runtime_system();
  {
    CAMLparam3(f,v1,v2);
    CAMLlocal1(res);
    res = caml_callback2_exn(f, v1, v2);
    if(Is_exception_result(res))
      fprintf(stderr, "Egl.main_loop: "
	      "WARNING: %s raised an exception\n", name) ;
    CAMLdrop;
  }
  caml_release_runtime_system();
}

static void protect_callback3(char *name, value f, value v1,
			      value v2, value v3)
{
  caml_acquire_runtime_system();
  {
    CAMLparam4(f,v1,v2,v3);
    CAMLlocal1(res);
    res = caml_callback3_exn(f, v1, v2, v3);
    if(Is_exception_result(res))
      fprintf(stderr, "Egl.main_loop: "
	      "WARNING: %s raised an exception\n", name) ;
    CAMLdrop;
  }
  caml_release_runtime_system();
}

static void protect_callback4(char *name, value f, value v1,
			      value v2, value v3, value v4)
{
  caml_acquire_runtime_system();
  {
    CAMLparam5(f,v1,v2,v3,v4);
    CAMLlocal1(res);
    CAMLlocalN(tmp,4);
    tmp[0] = v1; tmp[1]=v2; tmp[2]=v3; tmp[3]=v4 ;
    res = caml_callbackN_exn(f, 4, tmp);
    if(Is_exception_result(res))
      fprintf(stderr, "Egl.main_loop: "
	      "WARNING: %s raised an exception\n", name) ;
    CAMLdrop;
  }
  caml_release_runtime_system();
}

>
> Christophe
>
> >
> >     I have a multithreaded program, which segfault in callback_asm, while I
> >     think I respect all rules of c interfaces... Except maybe the above...
> >
> >
> > There is an OPAM compiler switch "4.10.0+nnpcheck" that adds run-time checks
> > for ill-formed values according to the no-naked-pointers rules.  Maybe you
> > could use it to rule out this potential problem.
> >
> > Hope this helps,
> >
> > - Xavier Leroy
> >
> >
> >
> >     Chevets,
> >     Christophe
> >     --
> >     Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma
> >     brièveté.
> >

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-12-21 21:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-20 19:56 christophe
2020-12-20 22:22 ` christophe
2020-12-21 18:37 ` Xavier Leroy
2020-12-21 20:40   ` Christophe Raffalli
2020-12-21 21:03     ` Christophe Raffalli [this message]
2020-12-21 22:32       ` ygrek
2020-12-21 23:11         ` Christophe Raffalli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=X+ENpGYozJ31RJui@oulala \
    --to=christophe@raffalli.eu \
    --cc=Xavier.Leroy@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).