Closed
Conversation
Author
|
It compiles and the tests are actually passing now! |
Owner
|
Thanks! I think that the test might be clearer as an expect test? I can do the conversion if we agree. I will try to have a look at implementing the junk_filling function on the C side soon. |
This PR makes available the `alloc_stack_noexc` and `rewrite_exception_stack` from `runtime/fiber.c` in the C API. In accordance with the C API the functions are renamed to `caml_alloc_stack_noexc` and `caml_rewrite_exception_stack`, respectively. My motivation for this change is to be able to support multi-shot continuations in OCaml via a library. I am interested in exploring design and programming with multi-shot continuations in my own research. To facility this research, I am in the process of building a [library](https://github.com/dhil/ocaml-multicont) that provides multi-shot continuations on top of OCaml's linear continuations. Under the hood, the library uses a variation of the `clone_continuation` primitive that used to reside in the `Obj` module in previous versions of Multicore OCaml. In order to implement `clone_continuation` as library I need access to the two above mentioned fiber manipulation primitives in `runtime/fiber.c` which are currently marked `static`. It is not clear to me whether there is a good reason for having them as `static`, whereas if they are non-static then I am able to implement continuation cloning externally. I need access to `alloc_stack_noexc` in order to allocate enough space for a carbon-copy of an existing stack segment, and `rewrite_exception_stack` in order to patch up exception pointers for cloned stack segments. In my current implementation I duplicate the implementations of these primitives in order to get going. Obviously, it would be a lot better and more robust if I could simply reuse the implementations in the OCaml runtime directly. As of writing, this PR exposes only the two primitives that I need to get my minimal implementation of multi-shot continuations going. However, I think there is a boarder discussion to be had about whether we should make available the rest of the fiber manipulation primitives in `runtime/fiber.c` too.
Implement suggestions from Gabriel Scherer and Damien Doligez
Expose fiber primitives for continuation cloning
When calling a method with the opcode GETPUBMET, the method address is resolved and possibly cached by modifying a word in the bytecode. If multiple domains execute the same GETPUBMET opcode concurrently, this is technically a data race. However, any integer value in the correct range is a safe value. Therefore we inform the compiler of potential concurrent accesses by using atomic accesses with relaxed memory order.
Generated by configure, but was still being erroneously deleted during partialclean.
Remove utils/config.generated.ml during distclean
Missing case in configure.ac
Fix ocamltest built without unix
Presenting this as a function rather than a constant in the stdlib leaves us with more implementation options open in the future.
Introduce run-time checks that the domain lock is held
Alternate signal stack related changes.
Update frame-pointers test reference files
For backward compatibility with OCaml 4. Fixes: ocaml#11464
Move `Is_young` back to `<caml/address_class.h>` and export it
Try to improve the case when there is function with label argument in a non label module.
documentation: fix typos
…caml#11552) Allocate the initializing float statically and outside the heap, rather than dynamically at first use. Not only it's more efficient, but it also avoids a race condition. Fixes: ocaml#11504
Owner
|
I am closing this draft since the main PR has been opened. |
Octachron
pushed a commit
that referenced
this pull request
Jul 26, 2024
…l#13294) The toplevel printer detects cycles by keeping a hashtable of values that it has already traversed. However, some OCaml runtime types (at least bigarrays) may be partially uninitialized, and hashing them at arbitrary program points may read uninitialized memory. In particular, the OCaml testsuite fails when running with a memory-sanitizer enabled, as bigarray printing results in reads to uninitialized memory: ``` ==133712==WARNING: MemorySanitizer: use-of-uninitialized-value #0 0x4e6d11 in caml_ba_hash /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45 #1 0x52474a in caml_hash /var/home/edwin/git/ocaml/runtime/hash.c:251:35 #2 0x599ebf in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1065:14 #3 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9 #4 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3 #5 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef) #6 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef) #7 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37) Uninitialized value was created by a heap allocation #0 0x47d306 in malloc (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x47d306) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37) #1 0x4e7960 in caml_ba_alloc /var/home/edwin/git/ocaml/runtime/bigarray.c:246:12 #2 0x4e801f in caml_ba_create /var/home/edwin/git/ocaml/runtime/bigarray.c:673:10 #3 0x59b8fc in caml_interprete /var/home/edwin/git/ocaml/runtime/interp.c:1058:14 #4 0x5a909a in caml_main /var/home/edwin/git/ocaml/runtime/startup_byt.c:575:9 #5 0x540ccb in main /var/home/edwin/git/ocaml/runtime/main.c:37:3 #6 0x7f0910abb087 in __libc_start_call_main (/lib64/libc.so.6+0x2a087) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef) #7 0x7f0910abb14a in __libc_start_main@GLIBC_2.2.5 (/lib64/libc.so.6+0x2a14a) (BuildId: 8f53abaad945a669f2bdcd25f471d80e077568ef) #8 0x441804 in _start (/var/home/edwin/git/ocaml/runtime/ocamlrun+0x441804) (BuildId: 7a60eef57e1c2baf770bc38d10d6c227e60ead37) SUMMARY: MemorySanitizer: use-of-uninitialized-value /var/home/edwin/git/ocaml/runtime/bigarray.c:486:45 in caml_ba_hash ``` The only use of hashing in genprintval is to avoid cycles, that is, it is only useful for OCaml values that contain other OCaml values (including possibly themselves). Bigarrays cannot introduce cycles, and they are always printed as "<abstr>" anyway. The present commit proposes to be more conservative in which values are hashed by the cycle detector to avoid this issue: we skip hashing any value with tag above No_scan_tag -- which may not contain any OCaml values. Suggested-by: Gabriel Scherer <gabriel.scherer@gmail.com> Signed-off-by: Edwin Török <edwin.torok@cloud.com> Co-authored-by: Edwin Török <edwin.torok@cloud.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💃