Documentation
¶
Overview ¶
Package gojit contains basic support for writing JITs in golang. It contains functions for allocating byte slices in executable memory, and converting between such slices and golang function types.
Index ¶
Constants ¶
const PageSize = 4096
PageSize is the size of a memory page. The len argument to Alloc should be an integer multiple of the page size.
Variables ¶
var JitData []uint32
Functions ¶
func Alloc ¶
Alloc returns a byte slice of the specified length that is marked RWX -- i.e. the memory in it can be both written and executed. This is just a simple wrapper around syscall.Mmap.
len most likely needs to be a multiple of PageSize.
func BuildCgo ¶
func BuildCgo(b []byte) func()
BuildCgo is like Build, but the resulting provided code will be called by way of the cgo runtime. This has the advantage of being much easier and safer to program against (your JIT'd code need only conform to your platform's C ABI), at the cost of significant overhead for each call into your code.
func BuildTo ¶
func BuildTo(b []byte, out interface{})
BuildTo converts a byte-slice into an arbitrary-signatured function. The out argument should be a pointer to a variable of `func' type.
Arguments to the resulting function will be passed to code using a hybrid of the GCC and 6c ABIs: The compiled code will receive, via the GCC ABI, a single argument, a void* pointing at the beginning of the 6c argument frame. For concreteness, on amd64, a func([]byte) int would result in %rdi pointing at the 6c stack frame, like so:
24(%rdi) [ return value ] 16(%rdi) [ cap(slice) ] 8(%rdi) [ len(slice) ] 0(%rdi) [ uint8* data ]
func BuildToCgo ¶
func BuildToCgo(b []byte, out interface{})
BuildToCgo is as Build, but uses cgo like BuildCGo