Documentation ¶
Overview ¶
Package safecopy provides an efficient implementation of functions to access memory that may result in SIGSEGV or SIGBUS being sent to the accessor.
Index ¶
- func CheckXstate(state *byte) error
- func CompareAndSwapUint32(ptr unsafe.Pointer, old, new uint32) (uint32, error)
- func Copy(dst, src unsafe.Pointer, toCopy uintptr) (uintptr, error)
- func CopyIn(dst []byte, src unsafe.Pointer) (int, error)
- func CopyOut(dst unsafe.Pointer, src []byte) (int, error)
- func FindEndAddress(begin uintptr) uintptr
- func LoadUint32(ptr unsafe.Pointer) (uint32, error)
- func SwapUint32(ptr unsafe.Pointer, new uint32) (uint32, error)
- func SwapUint64(ptr unsafe.Pointer, new uint64) (uint64, error)
- func ZeroOut(dst unsafe.Pointer, toZero uintptr) (uintptr, error)
- type AlignmentError
- type BusError
- type SegvError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckXstate ¶
CheckXstate verifies that xstate can be restored by the xrstor instruction.
func CompareAndSwapUint32 ¶
CompareAndSwapUint32 is equivalent to atomicbitops.CompareAndSwapUint32, except that it returns an error if SIGSEGV or SIGBUS is received while accessing ptr, or if ptr is not aligned to a 4-byte boundary.
func Copy ¶
Copy copies toCopy bytes from src to dst. It returns the number of bytes copied and an error if SIGSEGV or SIGBUS is received while reading from src or writing to dst.
Data is copied in order; if [src, src+toCopy) and [dst, dst+toCopy) overlap, the resulting contents of dst are unspecified.
func CopyIn ¶
CopyIn copies len(dst) bytes from src to dst. It returns the number of bytes copied and an error if SIGSEGV or SIGBUS is received while reading from src.
func CopyOut ¶
CopyOut copies len(src) bytes from src to dst. If returns the number of bytes done and an error if SIGSEGV or SIGBUS is received while writing to dst.
func FindEndAddress ¶
FindEndAddress returns the end address (one byte beyond the last) of the function that contains the specified address (begin).
func LoadUint32 ¶
LoadUint32 is like sync/atomic.LoadUint32, but operates with user memory. It may fail with SIGSEGV or SIGBUS if it is received while reading from ptr.
Preconditions: ptr must be aligned to a 4-byte boundary.
func SwapUint32 ¶
SwapUint32 is equivalent to sync/atomic.SwapUint32, except that it returns an error if SIGSEGV or SIGBUS is received while accessing ptr, or if ptr is not aligned to a 4-byte boundary.
func SwapUint64 ¶
SwapUint64 is equivalent to sync/atomic.SwapUint64, except that it returns an error if SIGSEGV or SIGBUS is received while accessing ptr, or if ptr is not aligned to an 8-byte boundary.
Types ¶
type AlignmentError ¶
type AlignmentError struct { // Addr is the invalid address. Addr uintptr // Alignment is the required alignment. Alignment uintptr }
AlignmentError is returned when a safecopy function is passed an address that does not meet alignment requirements.