2009-05-08 17:24:55 -06:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
/*
|
2011-04-19 17:57:05 -06:00
|
|
|
Package unsafe contains operations that step around the type safety of Go programs.
|
2009-11-05 10:40:28 -07:00
|
|
|
*/
|
2009-05-08 17:24:55 -06:00
|
|
|
package unsafe
|
|
|
|
|
|
|
|
// ArbitraryType is here for the purposes of documentation only and is not actually
|
|
|
|
// part of the unsafe package. It represents the type of an arbitrary Go expression.
|
|
|
|
type ArbitraryType int
|
|
|
|
|
|
|
|
// Pointer represents a pointer to an arbitrary type. There are three special operations
|
|
|
|
// available for type Pointer that are not available for other types.
|
|
|
|
// 1) A pointer value of any type can be converted to a Pointer.
|
2011-01-20 10:50:50 -07:00
|
|
|
// 2) A Pointer can be converted to a pointer value of any type.
|
|
|
|
// 3) A uintptr can be converted to a Pointer.
|
|
|
|
// 4) A Pointer can be converted to a uintptr.
|
2009-05-08 17:24:55 -06:00
|
|
|
// Pointer therefore allows a program to defeat the type system and read and write
|
|
|
|
// arbitrary memory. It should be used with extreme care.
|
2009-10-07 12:55:06 -06:00
|
|
|
type Pointer *ArbitraryType
|
2009-05-08 17:24:55 -06:00
|
|
|
|
|
|
|
// Sizeof returns the size in bytes occupied by the value v. The size is that of the
|
|
|
|
// "top level" of the value only. For instance, if v is a slice, it returns the size of
|
|
|
|
// the slice descriptor, not the size of the memory referenced by the slice.
|
2011-08-31 15:59:35 -06:00
|
|
|
func Sizeof(v ArbitraryType) uintptr
|
2009-05-08 17:24:55 -06:00
|
|
|
|
|
|
|
// Offsetof returns the offset within the struct of the field represented by v,
|
2012-02-11 15:10:47 -07:00
|
|
|
// which must be of the form structValue.field. In other words, it returns the
|
2009-05-08 17:24:55 -06:00
|
|
|
// number of bytes between the start of the struct and the start of the field.
|
2011-08-31 15:59:35 -06:00
|
|
|
func Offsetof(v ArbitraryType) uintptr
|
2009-05-08 17:24:55 -06:00
|
|
|
|
2009-11-16 16:39:04 -07:00
|
|
|
// Alignof returns the alignment of the value v. It is the maximum value m such
|
2009-05-08 17:24:55 -06:00
|
|
|
// that the address of a variable with the type of v will always always be zero mod m.
|
2012-02-11 15:10:47 -07:00
|
|
|
// If v is of the form structValue.field, it returns the alignment of field f within struct object obj.
|
2011-08-31 15:59:35 -06:00
|
|
|
func Alignof(v ArbitraryType) uintptr
|