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 ¶
This section is empty.
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 Build ¶
func Build(b []byte) func()
Build returns a nullary golang function that will result in jumping into the specified byte slice. The slice should in most cases be a slice returned by Alloc, although you could also use syscall.Mmap or syscall.Mprotect directly.
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 ]
Types ¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package amd64 implements a simple amd64 assembler.
|
Package amd64 implements a simple amd64 assembler. |
|
Package bf implements a JIT compiler for the Brainfuck programming language.
|
Package bf implements a JIT compiler for the Brainfuck programming language. |