Skip to content
Success

Changes

Summary

  1. Add type Obj.raw_data and functions Obj.raw_field, Obj.set_raw_field (commit: ec33006) (details)
  2. Use type Obj.raw_data to represent code pointers in the REPL trace facility (commit: c2db328) (details)
  3. Test intext.ml: do not use the caml_static_alloc primitive (commit: b0cd12d) (details)
  4. Remove the primitive functions caml_static_{alloc,free,resize} (commit: d6f9496) (details)
  5. Bootstrap after removal of caml_static_{alloc,free_resize} primitives (commit: 0a11f73) (details)
  6. Changes entry for #9655 (commit: 0a2dacb) (details)
  7. Changes entry for #9675 (commit: 2ad3a03) (details)
Commit ec33006c0a2253a29dfc55c36b66358cd20b188f by xavier.leroy
Add type Obj.raw_data and functions Obj.raw_field, Obj.set_raw_field

Some OCaml objects contain data that cannot be safely represented
as an OCaml value (type Obj.t).  For example, in no-naked-pointers mode,
this is the case for code pointers inside closures, and for the
"custom operations" pointers inside custom blocks.

This PR introduces a type Obj.raw_data (an alias for nativeint)
to encapsulate this data, and functions
Obj.raw_field / Obj.set_raw_field to read and write the "raw" contents
of fields of blocks.

Note: just like it is wrong to access code pointers and custom operations
using Obj.field / Obj.set_field, it is wrong to access regular fields
possibly containing pointers into the OCaml heap using
Obj.raw_field / Obj.set_raw_field.  The OCaml heap block can be
reclaimed or moved after its address was captured by Obj.raw_field.
Symmetrically, Obj.set_raw_field on a regular field bypasses the
write barrier of the GC.
(commit: ec33006)
The file was modifiedstdlib/obj.ml (diff)
The file was modifiedruntime/obj.c (diff)
The file was modifiedstdlib/obj.mli (diff)
Commit c2db3288c190ff1dfb8a16ba3d242d89d45e5ed9 by xavier.leroy
Use type Obj.raw_data to represent code pointers in the REPL trace facility

Using Obj.t is incorrect in no-naked-pointer mode, as it exposes
code pointers as OCaml values.
(commit: c2db328)
The file was modifiedbytecomp/meta.mli (diff)
The file was modifiedruntime/meta.c (diff)
The file was modifiedtoplevel/trace.ml (diff)
The file was modifiedbytecomp/meta.ml (diff)
Commit b0cd12d1c48fb22d7d06d49c7976bccce7d58068 by xavier.leroy
Test intext.ml: do not use the caml_static_alloc primitive

This primitive (from runtime/obj.c) is being phased out because
it returns a naked pointer outside the OCaml heap.

Instead, for the test, use a statically-allocated buffer
that is never visible from OCaml.
(commit: b0cd12d)
The file was modifiedtestsuite/tests/lib-marshal/intext.ml (diff)
The file was modifiedtestsuite/tests/lib-marshal/intextaux.c (diff)
Commit d6f949608db2566bb928df7aeae5c1e2ca1dad29 by xavier.leroy
Remove the primitive functions caml_static_{alloc,free,resize}

These primitives are dangerous because they produce naked pointers
outside the OCaml heap, with a risk of "GC pointer confusion".
(After caml_free and a heap extension, the freed memory area can be
reallocated as part of the OCaml heap, causing the naked pointer to
become a bad heap pointer).

These primitives are not used anywhere in the core OCaml system
(in particular they are not exposed via the Obj module).
An OPAM-wide grep shows no uses there either.
(commit: d6f9496)
The file was modifiedruntime/obj.c (diff)
Commit 0a11f73c8bde08ec0c0291d525e635c71f3237ec by xavier.leroy
Bootstrap after removal of caml_static_{alloc,free_resize} primitives

Follow-up to d6f949608
(commit: 0a11f73)
The file was modifiedboot/ocamlc (diff)
The file was modifiedboot/ocamllex (diff)
The file was modifiedChanges (diff)
The file was modifiedChanges (diff)