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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5FC657FF9F for ; Tue, 8 Mar 2016 17:01:16 +0100 (CET) IronPort-PHdr: 9a23:SX2f0BXgPvqrhZrWbzhb9AAPmkbV8LGtZVwlr6E/grcLSJyIuqrYZxSPt8tkgFKBZ4jH8fUM07OQ6PC/HzxcqsjR+Fk5M7VyFDY9wf0MmAIhBMPXQWbaF9XNKxIAIcJZSVV+9Gu6O0UGUOz3ZlnVv2HgpWVKQka3CwN5K6zPF5LIiIzvjqbpq8KVM1kD2mr1SIgxBSv1hD2ZjtMRj4pmJ/R54TryiVwMRd5rw3h1L0mYhRf265T41pdi9yNNp6BprJYYAu3SNp41Rr1ADTkgL3t9pIiy7UGCHj20+2AEX24Kvh1NCgnDpFGmD9ai+hf948V6wzabO4XoSrZ8cy6v46pxTBj3wHMIMCUm8WeSlIl6pL1WqlStqkos7ZTTZdS6PfBkf67ZNegRRWdbU9wZAyNICJm9Yo9JFOEBMPxVtaHyolIPqV21Agz6V7Cn8SNBmnKjhf5y6O8mCwyTmVF5Eg== Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-ig0-f179.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.213.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.213.179 as permitted sender) identity=mailfrom; client-ip=209.85.213.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ig0-f179.google.com) identity=helo; client-ip=209.85.213.179; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-ig0-f179.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CgAQDB9t5WjrPVVdFcg1g0bQaoR4FOhVCDK4dEgWkhhW4CgToHOhIBAQEBAQEBARABAQEBBwsLCR8xgi2CFQEBBBIRBBkBGxILAQMMBgULDQICCR0CAiIBEQEFAQoSBhMIChCHbAEDEg6hKoExPjGLNoFqgleFTgoZJwMKFTyDcwEBAQEBAQEDAQEBAQEBFAEFCgRthRyDRH6CWoRggToFhhwMgTOGSYkGgUqEGYgLgi+MTIcghXgRHoEPJgGCMQ0RCIFmHi6JfwEBAQ X-IPAS-Result: A0CgAQDB9t5WjrPVVdFcg1g0bQaoR4FOhVCDK4dEgWkhhW4CgToHOhIBAQEBAQEBARABAQEBBwsLCR8xgi2CFQEBBBIRBBkBGxILAQMMBgULDQICCR0CAiIBEQEFAQoSBhMIChCHbAEDEg6hKoExPjGLNoFqgleFTgoZJwMKFTyDcwEBAQEBAQEDAQEBAQEBFAEFCgRthRyDRH6CWoRggToFhhwMgTOGSYkGgUqEGYgLgi+MTIcghXgRHoEPJgGCMQ0RCIFmHi6JfwEBAQ X-IronPort-AV: E=Sophos;i="5.22,556,1449529200"; d="scan'208";a="167662781" Received: from mail-ig0-f179.google.com ([209.85.213.179]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 08 Mar 2016 17:01:15 +0100 Received: by mail-ig0-f179.google.com with SMTP id ig19so54851056igb.0 for ; Tue, 08 Mar 2016 08:01:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=w9v6bzdVLXvISyd3o9e/XMlR4NtKlNMk61X+dbxPA1Y=; b=GALMraXDtdxKX/nazhpjFb/OgJPddv2TS23lW2tvzBoLe61PYY+kgJ9guSdTummQCi 471x26EWHmGUB7JQtmSxR9Q4npnvPT1n2JjH2s3ohcD+uQ+wWwhr3TvO19klUR6I4wjb iKqEnegXwCNcZjh6fu8AX8wUHHHdcYcJi3rQiIMXwR9swknPCesWOZFSPAoo9EInl3Tq NW8zrQ7JLm9OKHu1s61Lroth2JOZDI14Bhlpe6WfU0Cqx3Xk4oTtECNUZuhh3wcJMtbr nAjvFvAAtysEMb9LNY6125n/TSMlaPRm2mP4skv+BkTisWgIMtBcGtN3BOhek5CS0BYu I3Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=w9v6bzdVLXvISyd3o9e/XMlR4NtKlNMk61X+dbxPA1Y=; b=V3qoefpo5b2lxDtiKvRlZWfRB9YWdeC10DNrZsEx1e3IMZprPBZBBtpQtQ+y70h+Zv oJ5uTIr/XBpkYv9wOMLKp5mOTrFAoFF8IGwQmzElLDhDQlvDtxcgvDE+/v+zKE7wx35u 7JtmnDW3nFx43h+iz123yN8Qc374Rozj32xF9te9hZ3n2aN3dQz0i4SAkOzhO/+H10A5 80558aLZUr+b8H2gJjO7mzeYkag0XYtdASUAV9TdOHSwhAxspkXcxVJWvlVver+NbytK tl9U62b5TpZRih37CmRl9TkBLDwhca9yKCQN/RIBkWZJr++LlfiVYwKjS4NOyh7j3smI FsbQ== X-Gm-Message-State: AD7BkJIbIKMxOjQt3nhxvtYo+imavaYb8zp+0iyEV7a3NgIWuxH6PjpN36MyByQA15TdFwgHX+drgn6scHf6Lw== X-Received: by 10.50.59.146 with SMTP id z18mr19127779igq.62.1457452872877; Tue, 08 Mar 2016 08:01:12 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.17.4 with HTTP; Tue, 8 Mar 2016 08:00:33 -0800 (PST) In-Reply-To: <20160308154948.GA5919@frosties> References: <20160308154948.GA5919@frosties> From: Gabriel Scherer Date: Tue, 8 Mar 2016 11:00:33 -0500 Message-ID: To: Goswin von Brederlow Cc: OCaml List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] memory corruption with Weak.t in Gc.finalise 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. 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