burn_unsafe.go 895 B

1234567891011121314151617181920212223242526272829
  1. // burn_unsafe.go - burn (unsafe available)
  2. //
  3. // To the extent possible under law, Yawning Angel has waived all copyright
  4. // and related or neighboring rights to the software, using the Creative
  5. // Commons "CC0" public domain dedication. See LICENSE or
  6. // <http://creativecommons.org/publicdomain/zero/1.0/> for full details.
  7. // +build !noasm,!appengine
  8. package norx
  9. import "unsafe"
  10. //go:noescape
  11. //go:linkname memclrNoHeapPointers runtime.memclrNoHeapPointers
  12. func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr)
  13. // Note: The compiler in theory always optimizes the "safe" variant of this
  14. // which uses a naive for loop to the unsafe equivalent, but there's no reason
  15. // to trust it.
  16. func burnBytes(b []byte) {
  17. memclrNoHeapPointers(unsafe.Pointer(&b[0]), uintptr(len(b)))
  18. }
  19. func burnUint64s(b []uint64) {
  20. l := len(b) * 8
  21. memclrNoHeapPointers(unsafe.Pointer(&b[0]), uintptr(l))
  22. }