go4.org/unsafe/assume-no-moving-gc@v0.0.0-20231121144256-b99613f794b6/check.go (about)

     1  // Copyright 2020 Brad Fitzpatrick. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build go1.21
     6  // +build go1.21
     7  
     8  package assume_no_moving_gc
     9  
    10  import (
    11  	"os"
    12  	_ "unsafe"
    13  )
    14  
    15  //go:linkname heapObjectsCanMove runtime.heapObjectsCanMove
    16  func heapObjectsCanMove() bool
    17  
    18  func init() {
    19  	if !heapObjectsCanMove() {
    20  		// The unsafe assumptions made by the package
    21  		// importing this package still hold. All's good. (at
    22  		// least unless they made other assumption this
    23  		// package doesn't concern itself with)
    24  		return
    25  	}
    26  	if os.Getenv(env) == "play-with-fire" {
    27  		return
    28  	}
    29  	panic(`
    30  Something in this program imports go4.org/unsafe/assume-no-moving-gc to
    31  declare that it assumes a non-moving garbage collector, but the version
    32  of Go you're using declares that its heap objects can now move around.
    33  This program is no longer safe. You should update your packages which import
    34  go4.org/unsafe/assume-no-moving-gc. To risk it and bypass this check, set
    35  ASSUME_NO_MOVING_GC_UNSAFE=play-with-fire and cross your fingers.`)
    36  }