From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 1C50C7FF9F for ; Tue, 8 Mar 2016 20:04:18 +0100 (CET) IronPort-PHdr: 9a23:v86/5RQmJjLe+faR4YsNILUxn9psv+yvbD5Q0YIujvd0So/mwa64YhCN2/xhgRfzUJnB7Loc0qyN4/+mCTBLuM7Z+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8KVM1kD3WLlKZpJbzyI7izp/vEMhoVjLqtjgjDomVBvP9ps+GVzOFiIlAz97MrjtLRq8iBXpu5zv5UYCfaySZ8lVqRVBygKNGU85cuj9UWSDFjH2nxJWWwTll9MAhPZxBD8RJb49CXg5cRn3yzPEsrtUrEyESql6e9BUhLkhT0DMCFxpG7QkdNxiudF5RiJuBF1hYLZNtLGfMFid7/QKItJDVFKWdxcAnAQDw== Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=goswin-v-b@web.de; spf=Pass smtp.mailfrom=goswin-v-b@web.de; spf=None smtp.helo=postmaster@mout.web.de Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of goswin-v-b@web.de) identity=pra; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of goswin-v-b@web.de designates 212.227.15.4 as permitted sender) identity=mailfrom; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="goswin-v-b@web.de"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mout.web.de) identity=helo; client-ip=212.227.15.4; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="goswin-v-b@web.de"; x-sender="postmaster@mout.web.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CbAADcId9WkwQP49RchAxtAaodiFQnhzYBDYFpIYVuAoFHOBQBAQEBAQEBARABAQEBBw0JCSEvgi2CFAEBAQMBJxM0EAsLGAkEIQ8FKAkrEod8AQMKCAQKuQ4fKwMfhDIBAQEHAQEBARyJW36CWoULgQ8FhhwMgTOPT4VjiAGCOYZtCoVVhyCHNh4BAYJFEQiBSWmJfwEBAQ X-IPAS-Result: A0CbAADcId9WkwQP49RchAxtAaodiFQnhzYBDYFpIYVuAoFHOBQBAQEBAQEBARABAQEBBw0JCSEvgi2CFAEBAQMBJxM0EAsLGAkEIQ8FKAkrEod8AQMKCAQKuQ4fKwMfhDIBAQEHAQEBARyJW36CWoULgQ8FhhwMgTOPT4VjiAGCOYZtCoVVhyCHNh4BAYJFEQiBSWmJfwEBAQ X-IronPort-AV: E=Sophos;i="5.22,557,1449529200"; d="scan'208";a="206660749" Received: from mout.web.de ([212.227.15.4]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 08 Mar 2016 20:04:17 +0100 Received: from frosties.localnet ([134.3.242.84]) by smtp.web.de (mrweb003) with ESMTPSA (Nemesis) id 0LoYWI-1ZxBPu3gfS-00gUad for ; Tue, 08 Mar 2016 20:04:16 +0100 Received: from mrvn by frosties.localnet with local (Exim 4.84) (envelope-from ) id 1adMvY-0002fp-0H for caml-list@inria.fr; Tue, 08 Mar 2016 20:04:16 +0100 Date: Tue, 8 Mar 2016 20:04:15 +0100 From: Goswin von Brederlow To: caml-list@inria.fr Message-ID: <20160308190415.GA10232@frosties> References: <20160308154948.GA5919@frosties> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) X-Provags-ID: V03:K0:NE+8z0h/PBNzUBnRROuqQS8CYAVBITPkkhLK3o4cMldu56meKQ2 pGJ4YaSItJwZwyd67IUdlQhhJHhnO0zzNTLbOkX4rqyYPpY5xJyrZIZRxwY5e6CVGobsuWv urG4JfKxHNprpwFWeXU+HqJHLbcp6EOWxKHUABFvim8ifBHVbfhrTSAISVTcrJehpoLMLfs 6l/pkeLsjps8MimuJZt+w== X-UI-Out-Filterresults: notjunk:1;V01:K0:mcMexLbcGjM=:/8KOlsfiu2mTbDurglkHCE r+Wyx8iVE19WTKVK8kJjzbUWU+2Wx+yD9U1FCnX6bysUvngk+NBjm20BzS0L6eA3q+H4OwSTC UfemI1cpWiAGZ5s7d1OptfEt22xzdKCaNekcJyXKTh8tkLQN8rHCBpDq6jxdG5Vb0S3ZSALyZ o5aqi4gZ5797Mrwu7czYOQPUOj7aAyksyyYF+f3LiqIXq2h4fBOs3n/6RJ/ZVt6EdmkZsQRzy Y7zYv9leBguNfkc+zRTegdCm807Kc+uliOAbEXQYPQLCI6/CYRpsJJVczwcfetm6bzGIjSl8d vVashJ5EzR35Ek2ZS1cBaoRhCNaWGBuRpGDfCmsI7p1smyYyldSZ//3TLvGwamaPzDp/X1qeF YuqR9ayTRDvQJBhFQ9qxsIBpnbKjIsEEx9mgc4k9TTsssLtO5hJi4ksqlAAvMRO24fWksQ8db yCpJtTz5+43nyn7o0Qe6tlM48ZHGYPVwX0pn+wFZ3VpNVcLc9cO6G6bnd8WZROgtB8iJ7aOlh YiRlvff5sGphAyuJFAICt+gMrOHf1LO4B2E/wZDTlH+Hf3NicZFrwHhHdxOp4qDnWxZgc6sdF CN+Qx4un45W9sR5piXszN8m2EE+Bv81FgWdLm4qdn9jk3IoAc0bFLr38Xb3jPyK987KKfFu6N XLlYjimEaFVfwUV1bRkUKBKBmEv3nPtQ3pANBee2tjdBK60ZMIgk61ysTGHF5tMw792/DpD+3 rtg3wSWp7ESvynOeHxFL+ocxSr1BIa7KDnndkARSiAiHl97u0NWHwTfdj5o= Subject: Re: [Caml-list] memory corruption with Weak.t in Gc.finalise On Tue, Mar 08, 2016 at 11:00:33AM -0500, Gabriel Scherer wrote: > It's great that you have a minimal reproduction example. Could you > create an issue on the issue tracker? > http://caml.inria.fr/mantis/ > > Issues on the bugtracker are easier to keep track of than mails on the > caml-list. If it is a bug in the compiler and not just my code then sure. MfG Goswin > On Tue, Mar 8, 2016 at 10:49 AM, Goswin von Brederlow wrote: > > Hi, > > > > I found a memory corruption in Gc.finalise when sharing a Waek.t with > > C stubs. I made a small test case and it's gotten worse. The code now > > segfaults: > > > > https://github.com/mrvn/ocam-problems/tree/weak-finalise > > > > The problem I had was the address of the obj stored in the Weak.t > > changes (which might be the GC moving it?) and also the tag changes > > from 248 (Object_tag) to 168 (random constructor). > > > > With my smaller test case I further get: > > > > Program received signal SIGSEGV, Segmentation fault. > > 0x000000000043c9f8 in caml_format_exception () > > (gdb) bt > > #0 0x000000000043c9f8 in caml_format_exception () > > #1 0x000000000043cbc1 in caml_fatal_uncaught_exception () > > #2 0x000000000043b1a7 in caml_main () > > #3 0x000000000042c45d in main () > > > > Ideas what is going on there? > > > > MfG > > Goswin > > > > ------------------------------------------------------------------------ > > ==> Makefile <== > > all: test > > ./test > > > > test: main.cmx stubs.o > > ocamlopt -o $@ $+ > > > > %.cmx: %.ml > > ocamlopt -g -c -o $@ $< > > > > %.o: %.c > > gcc -O2 -W -Wall -g -c -o $@ $< > > > > clean: > > rm -f test *.o *.cmx *.cmi *~ > > > > ==> main.ml <== > > external setup : 'a Weak.t -> unit = "setup" > > external test : unit -> unit = "test" > > > > let cleanup obj = > > Printf.printf "cleanup\n%!"; > > test () > > > > class obj = object(self) > > val weak = Weak.create 1 > > initializer Weak.set weak 0 (Some self) > > initializer setup weak > > initializer Gc.finalise cleanup self > > end > > > > let () = > > Printf.printf "Creating object\n%!"; > > ignore (new obj); > > test () > > > > let () = > > Printf.printf "Garbage collection\n%!"; > > Gc.full_major () > > > > let () = > > Printf.printf "checking after GC\n%!"; > > test () > > > > ==> stubs.c <== > > #include > > #include > > #include > > > > value weak; > > > > void setup(value ml_weak) { > > CAMLparam1(ml_weak); > > printf("%s(0x%lx)\n", __PRETTY_FUNCTION__, ml_weak); > > weak = ml_weak; > > caml_register_generational_global_root(&weak); > > CAMLreturn0; > > } > > > > void test(void) { > > CAMLparam0(); > > CAMLlocal1(obj); > > printf("%s\n", __PRETTY_FUNCTION__); > > printf(" weak = 0x%lx\n", weak); > > if (weak != 0) { > > obj = Field(weak, 1); > > printf(" obj = 0x%lx\n", obj); > > if (obj != 0) { > > printf(" tag = %d\n", Tag_val(obj)); > > } > > } > > printf("%s done\n", __PRETTY_FUNCTION__); > > CAMLreturn0; > > } > > > > -- > > Caml-list mailing list. Subscription management and archives: > > https://sympa.inria.fr/sympa/arc/caml-list > > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > > Bug reports: http://caml.inria.fr/bin/caml-bugs > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs