Commit 4713e1b5 authored by cznic's avatar cznic
Browse files

checkpoint.go: declare TLSCheckpoint version 1 stable

modernc.org/jit/qbe starts to use TLSCheckpoint version 1 for setjmp and
longjmp in JIT-compiled C, so its format no longer may change freely. A
change to the layout, size or meaning of TLSCheckpoint now comes with a
new TLSCheckpointVersion, and CheckRollback rejects checkpoints of other
versions as malformed, as it rejects a wrong magic word today. Code that
keeps a checkpoint in C memory sizes the space with TLSCheckpointSize,
aligns it to a pointer and copies it as a value. Documentation only.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MmEyBeRhDkPizAphrtc4Nk
parent 18ddf1bd
Loading
Loading
Loading
Loading
+9 −8
Changes for checkpoint.go: 9 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -9,9 +9,10 @@ import (
	"unsafe"
)

// TLSCheckpointVersion is the version of the layout of TLSCheckpoint. It
// changes whenever the layout does. The layout is not frozen: it may change
// until the runtime of modernc.org/jit/qbe uses it.
// TLSCheckpointVersion is the version of TLSCheckpoint. Version 1 is stable. A
// change to the layout, size or meaning of TLSCheckpoint comes with a new
// version, and CheckRollback rejects checkpoints of other versions as
// malformed.
const TLSCheckpointVersion = 1

// TLSCheckpointSize is the size of a TLSCheckpoint in bytes. It depends on the
@@ -35,11 +36,11 @@ var (
// is left alone.
//
// A TLSCheckpoint holds only integers, no Go pointers, so it can be kept in C
// memory, for example in a jmp_buf. Its TLSCheckpointSize bytes start with a
// word that identifies TLSCheckpointVersion. The rest is private to libc. The
// format is versioned through TLSCheckpointVersion and may change, along with
// TLSCheckpointSize, until the runtime of modernc.org/jit/qbe uses it, so do
// not treat it as frozen.
// memory, for example in a jmp_buf. Code that does so sizes the space with
// TLSCheckpointSize, aligns it to a pointer and copies the checkpoint as a
// value. Its TLSCheckpointSize bytes start with a word that identifies
// TLSCheckpointVersion. The rest is private to libc. A checkpoint is valid only
// in the process and for the TLS that made it.
type TLSCheckpoint struct {
	magic    uintptr
	id       uintptr // TLS.ID