Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions api/next/78189.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pkg runtime/jit, const UnwindDeclare UnwindMode #78189
pkg runtime/jit, const UnwindSkip UnwindMode #78189
pkg runtime/jit, const UnwindStop UnwindMode #78189
pkg runtime/jit, func StackCheckConfig() StackCheck #78189
pkg runtime/jit, func TailTypeFor[$0 interface{}](uintptr) TailType #78189
pkg runtime/jit, func Register(Region) Handle #78189
pkg runtime/jit, method (TailType) Alloc() unsafe.Pointer #78189
pkg runtime/jit, method (Handle) Unregister() #78189
pkg runtime/jit, method (Handle) AddStackMaps(...StackMap) #78189
pkg runtime/jit, type Handle struct #78189
pkg runtime/jit, type Region struct #78189
pkg runtime/jit, type Region struct, Describe func(uintptr) (string, string, int, bool) #78189
pkg runtime/jit, type Region struct, End uintptr #78189
pkg runtime/jit, type Region struct, StackMaps []StackMap #78189
pkg runtime/jit, type Region struct, Start uintptr #78189
pkg runtime/jit, type Region struct, Unwind UnwindMode #78189
pkg runtime/jit, func Preempt() bool #78189
pkg runtime/jit, type StackCheck struct #78189
pkg runtime/jit, type StackCheck struct, MoreStackPC uintptr #78189
pkg runtime/jit, type StackCheck struct, StackGuardOffset uintptr #78189
pkg runtime/jit, type StackCheck struct, StackSmall uintptr #78189
pkg runtime/jit, type StackMap struct #78189
pkg runtime/jit, type StackMap struct, CallerBPOffset uintptr #78189
pkg runtime/jit, type StackMap struct, CallerPCOffset uintptr #78189
pkg runtime/jit, type StackMap struct, CallerSPOffset uintptr #78189
pkg runtime/jit, type StackMap struct, FrameOffset uintptr #78189
pkg runtime/jit, type StackMap struct, FrameWords uintptr #78189
pkg runtime/jit, type StackMap struct, HasUnwind bool #78189
pkg runtime/jit, type StackMap struct, PCOffset uintptr #78189
pkg runtime/jit, type StackMap struct, PointerMask []uint8 #78189
pkg runtime/jit, type StackMap struct, UnwindBaseDeltaOffset uintptr #78189
pkg runtime/jit, type StackMap struct, UnwindBaseOffset uintptr #78189
pkg runtime/jit, type StackMap struct, UnwindBaseUsesDelta bool #78189
pkg runtime/jit, type TailType struct #78189
pkg runtime/jit, type UnwindMode uint8 #78189
8 changes: 8 additions & 0 deletions src/internal/goexperiment/exp_jit_off.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/internal/goexperiment/exp_jit_on.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/internal/goexperiment/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,9 @@ type Flags struct {

// GoListExportNewFormat enables the new format for go list -export.
GoListExportNewFormat bool

// JIT enables the runtime/jit package for registering user code
// frames (JIT compilers, WASM engines, embedded VMs) with the
// Go runtime's stack unwinder, panic/recover, and GC.
JIT bool
}
35 changes: 35 additions & 0 deletions src/runtime/jit/alloc_unix_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2025 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.

//go:build goexperiment.jit && unix

package jit_test

import (
"syscall"
"unsafe"
)

// allocExecutable allocates a page of executable memory and copies code into it.
func allocExecutable(code []byte) (uintptr, int, error) {
pageSize := syscall.Getpagesize()
mem, err := syscall.Mmap(-1, 0, pageSize,
syscall.PROT_READ|syscall.PROT_WRITE,
syscall.MAP_PRIVATE|syscall.MAP_ANONYMOUS)
if err != nil {
return 0, 0, err
}
copy(mem, code)
err = syscall.Mprotect(mem, syscall.PROT_READ|syscall.PROT_EXEC)
if err != nil {
syscall.Munmap(mem)
return 0, 0, err
}
return uintptr(unsafe.Pointer(&mem[0])), pageSize, nil
}

func freeExecutable(addr uintptr, size int) {
mem := unsafe.Slice((*byte)(unsafe.Pointer(addr)), size)
syscall.Munmap(mem)
}
53 changes: 53 additions & 0 deletions src/runtime/jit/alloc_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright 2025 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.

//go:build goexperiment.jit && windows

package jit_test

import (
"fmt"
"syscall"
"unsafe"
)

const (
_MEM_COMMIT = 0x1000
_MEM_RESERVE = 0x2000
_MEM_RELEASE = 0x8000
_PAGE_READWRITE = 0x04
_PAGE_EXECUTE_READ = 0x20
)

var (
kernel32 = syscall.NewLazyDLL("kernel32.dll")
procVirtualAlloc = kernel32.NewProc("VirtualAlloc")
procVirtualFree = kernel32.NewProc("VirtualFree")
procVirtualProtect = kernel32.NewProc("VirtualProtect")
)

// allocExecutable allocates a page of executable memory and copies code into it.
func allocExecutable(code []byte) (uintptr, int, error) {
const pageSize = 4096
// Allocate RW memory.
addr, _, err := procVirtualAlloc.Call(0, uintptr(pageSize), _MEM_COMMIT|_MEM_RESERVE, _PAGE_READWRITE)
if addr == 0 {
return 0, 0, fmt.Errorf("VirtualAlloc: %w", err)
}
// Copy code into the allocated memory.
dst := unsafe.Slice((*byte)(unsafe.Pointer(addr)), pageSize)
copy(dst, code)
// Change protection to RX (W^X).
var oldProtect uint32
ret, _, err := procVirtualProtect.Call(addr, uintptr(pageSize), _PAGE_EXECUTE_READ, uintptr(unsafe.Pointer(&oldProtect)))
if ret == 0 {
procVirtualFree.Call(addr, 0, _MEM_RELEASE)
return 0, 0, fmt.Errorf("VirtualProtect: %w", err)
}
return addr, pageSize, nil
}

func freeExecutable(addr uintptr, size int) {
procVirtualFree.Call(addr, 0, _MEM_RELEASE)
}
Loading