Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- go/src/runtime/asan/asan.go +89 -0
- go/src/runtime/cgo/abi_amd64.h +99 -0
- go/src/runtime/cgo/abi_arm64.h +43 -0
- go/src/runtime/cgo/abi_loong64.h +60 -0
- go/src/runtime/cgo/abi_ppc64x.h +195 -0
- go/src/runtime/cgo/asm_386.s +42 -0
- go/src/runtime/cgo/asm_amd64.s +47 -0
- go/src/runtime/cgo/asm_arm.s +69 -0
- go/src/runtime/cgo/asm_arm64.s +50 -0
- go/src/runtime/cgo/asm_loong64.s +53 -0
- go/src/runtime/cgo/asm_mips64x.s +95 -0
- go/src/runtime/cgo/asm_mipsx.s +88 -0
- go/src/runtime/cgo/asm_ppc64x.s +70 -0
- go/src/runtime/cgo/asm_riscv64.s +91 -0
- go/src/runtime/cgo/asm_s390x.s +68 -0
- go/src/runtime/cgo/asm_wasm.s +11 -0
- go/src/runtime/cgo/callbacks.go +169 -0
- go/src/runtime/cgo/callbacks_aix.go +12 -0
- go/src/runtime/cgo/callbacks_traceback.go +17 -0
- go/src/runtime/cgo/cgo.go +41 -0
- go/src/runtime/cgo/clearenv.go +15 -0
- go/src/runtime/cgo/dragonfly.go +19 -0
- go/src/runtime/cgo/freebsd.go +22 -0
- go/src/runtime/cgo/gcc_386.S +48 -0
- go/src/runtime/cgo/gcc_aix_ppc64.S +132 -0
- go/src/runtime/cgo/gcc_aix_ppc64.c +35 -0
- go/src/runtime/cgo/gcc_amd64.S +55 -0
- go/src/runtime/cgo/gcc_android.c +90 -0
- go/src/runtime/cgo/gcc_arm.S +31 -0
- go/src/runtime/cgo/gcc_arm64.S +84 -0
- go/src/runtime/cgo/gcc_clearenv.c +18 -0
- go/src/runtime/cgo/gcc_context.c +20 -0
- go/src/runtime/cgo/gcc_darwin_amd64.c +61 -0
- go/src/runtime/cgo/gcc_darwin_arm64.c +148 -0
- go/src/runtime/cgo/gcc_dragonfly_amd64.c +61 -0
- go/src/runtime/cgo/gcc_fatalf.c +23 -0
- go/src/runtime/cgo/gcc_freebsd.c +72 -0
- go/src/runtime/cgo/gcc_freebsd_amd64.c +72 -0
- go/src/runtime/cgo/gcc_freebsd_sigaction.c +80 -0
- go/src/runtime/cgo/gcc_libinit.c +243 -0
- go/src/runtime/cgo/gcc_libinit_windows.c +214 -0
- go/src/runtime/cgo/gcc_linux.c +67 -0
- go/src/runtime/cgo/gcc_linux_amd64.c +92 -0
- go/src/runtime/cgo/gcc_linux_arm64.c +88 -0
- go/src/runtime/cgo/gcc_linux_ppc64x.S +86 -0
- go/src/runtime/cgo/gcc_linux_s390x.c +64 -0
- go/src/runtime/cgo/gcc_loong64.S +68 -0
- go/src/runtime/cgo/gcc_mips64x.S +89 -0
- go/src/runtime/cgo/gcc_mipsx.S +77 -0
- go/src/runtime/cgo/gcc_mmap.c +39 -0
go/src/runtime/asan/asan.go
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build asan && linux && (arm64 || amd64 || loong64 || riscv64 || ppc64le)
|
| 6 |
+
|
| 7 |
+
package asan
|
| 8 |
+
|
| 9 |
+
/*
|
| 10 |
+
#cgo CFLAGS: -fsanitize=address
|
| 11 |
+
#cgo LDFLAGS: -fsanitize=address
|
| 12 |
+
|
| 13 |
+
#include <stdbool.h>
|
| 14 |
+
#include <stdint.h>
|
| 15 |
+
#include <sanitizer/asan_interface.h>
|
| 16 |
+
#include <sanitizer/lsan_interface.h>
|
| 17 |
+
|
| 18 |
+
void __asan_read_go(void *addr, uintptr_t sz, void *sp, void *pc) {
|
| 19 |
+
if (__asan_region_is_poisoned(addr, sz)) {
|
| 20 |
+
__asan_report_error(pc, 0, sp, addr, false, sz);
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
void __asan_write_go(void *addr, uintptr_t sz, void *sp, void *pc) {
|
| 25 |
+
if (__asan_region_is_poisoned(addr, sz)) {
|
| 26 |
+
__asan_report_error(pc, 0, sp, addr, true, sz);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void __asan_unpoison_go(void *addr, uintptr_t sz) {
|
| 31 |
+
__asan_unpoison_memory_region(addr, sz);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
void __asan_poison_go(void *addr, uintptr_t sz) {
|
| 35 |
+
__asan_poison_memory_region(addr, sz);
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
void __lsan_register_root_region_go(void *addr, uintptr_t sz) {
|
| 39 |
+
__lsan_register_root_region(addr, sz);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
void __lsan_unregister_root_region_go(void *addr, uintptr_t sz) {
|
| 43 |
+
__lsan_unregister_root_region(addr, sz);
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
void __lsan_do_leak_check_go(void) {
|
| 47 |
+
__lsan_do_leak_check();
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
// Keep in sync with the definition in compiler-rt
|
| 51 |
+
// https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/asan/asan_interface_internal.h#L41
|
| 52 |
+
// This structure is used to describe the source location of
|
| 53 |
+
// a place where global was defined.
|
| 54 |
+
struct _asan_global_source_location {
|
| 55 |
+
const char *filename;
|
| 56 |
+
int line_no;
|
| 57 |
+
int column_no;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
// Keep in sync with the definition in compiler-rt
|
| 61 |
+
// https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/asan/asan_interface_internal.h#L48
|
| 62 |
+
// So far, the current implementation is only compatible with the ASan library from version v7 to v9.
|
| 63 |
+
// https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/asan/asan_init_version.h
|
| 64 |
+
// This structure describes an instrumented global variable.
|
| 65 |
+
//
|
| 66 |
+
// TODO: If a later version of the ASan library changes __asan_global or __asan_global_source_location
|
| 67 |
+
// structure, we need to make the same changes.
|
| 68 |
+
struct _asan_global {
|
| 69 |
+
uintptr_t beg;
|
| 70 |
+
uintptr_t size;
|
| 71 |
+
uintptr_t size_with_redzone;
|
| 72 |
+
const char *name;
|
| 73 |
+
const char *module_name;
|
| 74 |
+
uintptr_t has_dynamic_init;
|
| 75 |
+
struct _asan_global_source_location *location;
|
| 76 |
+
uintptr_t odr_indicator;
|
| 77 |
+
};
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
extern void __asan_register_globals(void*, long int);
|
| 81 |
+
|
| 82 |
+
// Register global variables.
|
| 83 |
+
// The 'globals' is an array of structures describing 'n' globals.
|
| 84 |
+
void __asan_register_globals_go(void *addr, uintptr_t n) {
|
| 85 |
+
struct _asan_global *globals = (struct _asan_global *)(addr);
|
| 86 |
+
__asan_register_globals(globals, n);
|
| 87 |
+
}
|
| 88 |
+
*/
|
| 89 |
+
import "C"
|
go/src/runtime/cgo/abi_amd64.h
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
// Macros for transitioning from the host ABI to Go ABI0.
|
| 6 |
+
//
|
| 7 |
+
// These save the frame pointer, so in general, functions that use
|
| 8 |
+
// these should have zero frame size to suppress the automatic frame
|
| 9 |
+
// pointer, though it's harmless to not do this.
|
| 10 |
+
|
| 11 |
+
#ifdef GOOS_windows
|
| 12 |
+
|
| 13 |
+
// REGS_HOST_TO_ABI0_STACK is the stack bytes used by
|
| 14 |
+
// PUSH_REGS_HOST_TO_ABI0.
|
| 15 |
+
#define REGS_HOST_TO_ABI0_STACK (28*8 + 8)
|
| 16 |
+
|
| 17 |
+
// PUSH_REGS_HOST_TO_ABI0 prepares for transitioning from
|
| 18 |
+
// the host ABI to Go ABI0 code. It saves all registers that are
|
| 19 |
+
// callee-save in the host ABI and caller-save in Go ABI0 and prepares
|
| 20 |
+
// for entry to Go.
|
| 21 |
+
//
|
| 22 |
+
// Save DI SI BP BX R12 R13 R14 R15 X6-X15 registers and the DF flag.
|
| 23 |
+
// Clear the DF flag for the Go ABI.
|
| 24 |
+
// MXCSR matches the Go ABI, so we don't have to set that,
|
| 25 |
+
// and Go doesn't modify it, so we don't have to save it.
|
| 26 |
+
#define PUSH_REGS_HOST_TO_ABI0() \
|
| 27 |
+
PUSHFQ \
|
| 28 |
+
CLD \
|
| 29 |
+
ADJSP $(REGS_HOST_TO_ABI0_STACK - 8) \
|
| 30 |
+
MOVQ DI, (0*0)(SP) \
|
| 31 |
+
MOVQ SI, (1*8)(SP) \
|
| 32 |
+
MOVQ BP, (2*8)(SP) \
|
| 33 |
+
MOVQ BX, (3*8)(SP) \
|
| 34 |
+
MOVQ R12, (4*8)(SP) \
|
| 35 |
+
MOVQ R13, (5*8)(SP) \
|
| 36 |
+
MOVQ R14, (6*8)(SP) \
|
| 37 |
+
MOVQ R15, (7*8)(SP) \
|
| 38 |
+
MOVUPS X6, (8*8)(SP) \
|
| 39 |
+
MOVUPS X7, (10*8)(SP) \
|
| 40 |
+
MOVUPS X8, (12*8)(SP) \
|
| 41 |
+
MOVUPS X9, (14*8)(SP) \
|
| 42 |
+
MOVUPS X10, (16*8)(SP) \
|
| 43 |
+
MOVUPS X11, (18*8)(SP) \
|
| 44 |
+
MOVUPS X12, (20*8)(SP) \
|
| 45 |
+
MOVUPS X13, (22*8)(SP) \
|
| 46 |
+
MOVUPS X14, (24*8)(SP) \
|
| 47 |
+
MOVUPS X15, (26*8)(SP)
|
| 48 |
+
|
| 49 |
+
#define POP_REGS_HOST_TO_ABI0() \
|
| 50 |
+
MOVQ (0*0)(SP), DI \
|
| 51 |
+
MOVQ (1*8)(SP), SI \
|
| 52 |
+
MOVQ (2*8)(SP), BP \
|
| 53 |
+
MOVQ (3*8)(SP), BX \
|
| 54 |
+
MOVQ (4*8)(SP), R12 \
|
| 55 |
+
MOVQ (5*8)(SP), R13 \
|
| 56 |
+
MOVQ (6*8)(SP), R14 \
|
| 57 |
+
MOVQ (7*8)(SP), R15 \
|
| 58 |
+
MOVUPS (8*8)(SP), X6 \
|
| 59 |
+
MOVUPS (10*8)(SP), X7 \
|
| 60 |
+
MOVUPS (12*8)(SP), X8 \
|
| 61 |
+
MOVUPS (14*8)(SP), X9 \
|
| 62 |
+
MOVUPS (16*8)(SP), X10 \
|
| 63 |
+
MOVUPS (18*8)(SP), X11 \
|
| 64 |
+
MOVUPS (20*8)(SP), X12 \
|
| 65 |
+
MOVUPS (22*8)(SP), X13 \
|
| 66 |
+
MOVUPS (24*8)(SP), X14 \
|
| 67 |
+
MOVUPS (26*8)(SP), X15 \
|
| 68 |
+
ADJSP $-(REGS_HOST_TO_ABI0_STACK - 8) \
|
| 69 |
+
POPFQ
|
| 70 |
+
|
| 71 |
+
#else
|
| 72 |
+
// SysV ABI
|
| 73 |
+
|
| 74 |
+
#define REGS_HOST_TO_ABI0_STACK (6*8)
|
| 75 |
+
|
| 76 |
+
// SysV MXCSR matches the Go ABI, so we don't have to set that,
|
| 77 |
+
// and Go doesn't modify it, so we don't have to save it.
|
| 78 |
+
// Both SysV and Go require DF to be cleared, so that's already clear.
|
| 79 |
+
// The SysV and Go frame pointer conventions are compatible.
|
| 80 |
+
#define PUSH_REGS_HOST_TO_ABI0() \
|
| 81 |
+
ADJSP $(REGS_HOST_TO_ABI0_STACK) \
|
| 82 |
+
MOVQ BP, (5*8)(SP) \
|
| 83 |
+
LEAQ (5*8)(SP), BP \
|
| 84 |
+
MOVQ BX, (0*8)(SP) \
|
| 85 |
+
MOVQ R12, (1*8)(SP) \
|
| 86 |
+
MOVQ R13, (2*8)(SP) \
|
| 87 |
+
MOVQ R14, (3*8)(SP) \
|
| 88 |
+
MOVQ R15, (4*8)(SP)
|
| 89 |
+
|
| 90 |
+
#define POP_REGS_HOST_TO_ABI0() \
|
| 91 |
+
MOVQ (0*8)(SP), BX \
|
| 92 |
+
MOVQ (1*8)(SP), R12 \
|
| 93 |
+
MOVQ (2*8)(SP), R13 \
|
| 94 |
+
MOVQ (3*8)(SP), R14 \
|
| 95 |
+
MOVQ (4*8)(SP), R15 \
|
| 96 |
+
MOVQ (5*8)(SP), BP \
|
| 97 |
+
ADJSP $-(REGS_HOST_TO_ABI0_STACK)
|
| 98 |
+
|
| 99 |
+
#endif
|
go/src/runtime/cgo/abi_arm64.h
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2021 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
// Macros for transitioning from the host ABI to Go ABI0.
|
| 6 |
+
//
|
| 7 |
+
// These macros save and restore the callee-saved registers
|
| 8 |
+
// from the stack, but they don't adjust stack pointer, so
|
| 9 |
+
// the user should prepare stack space in advance.
|
| 10 |
+
// SAVE_R19_TO_R28(offset) saves R19 ~ R28 to the stack space
|
| 11 |
+
// of ((offset)+0*8)(RSP) ~ ((offset)+9*8)(RSP).
|
| 12 |
+
//
|
| 13 |
+
// SAVE_F8_TO_F15(offset) saves F8 ~ F15 to the stack space
|
| 14 |
+
// of ((offset)+0*8)(RSP) ~ ((offset)+7*8)(RSP).
|
| 15 |
+
//
|
| 16 |
+
// R29 is not saved because Go will save and restore it.
|
| 17 |
+
|
| 18 |
+
#define SAVE_R19_TO_R28(offset) \
|
| 19 |
+
STP (R19, R20), ((offset)+0*8)(RSP) \
|
| 20 |
+
STP (R21, R22), ((offset)+2*8)(RSP) \
|
| 21 |
+
STP (R23, R24), ((offset)+4*8)(RSP) \
|
| 22 |
+
STP (R25, R26), ((offset)+6*8)(RSP) \
|
| 23 |
+
STP (R27, g), ((offset)+8*8)(RSP)
|
| 24 |
+
|
| 25 |
+
#define RESTORE_R19_TO_R28(offset) \
|
| 26 |
+
LDP ((offset)+0*8)(RSP), (R19, R20) \
|
| 27 |
+
LDP ((offset)+2*8)(RSP), (R21, R22) \
|
| 28 |
+
LDP ((offset)+4*8)(RSP), (R23, R24) \
|
| 29 |
+
LDP ((offset)+6*8)(RSP), (R25, R26) \
|
| 30 |
+
LDP ((offset)+8*8)(RSP), (R27, g) /* R28 */
|
| 31 |
+
|
| 32 |
+
#define SAVE_F8_TO_F15(offset) \
|
| 33 |
+
FSTPD (F8, F9), ((offset)+0*8)(RSP) \
|
| 34 |
+
FSTPD (F10, F11), ((offset)+2*8)(RSP) \
|
| 35 |
+
FSTPD (F12, F13), ((offset)+4*8)(RSP) \
|
| 36 |
+
FSTPD (F14, F15), ((offset)+6*8)(RSP)
|
| 37 |
+
|
| 38 |
+
#define RESTORE_F8_TO_F15(offset) \
|
| 39 |
+
FLDPD ((offset)+0*8)(RSP), (F8, F9) \
|
| 40 |
+
FLDPD ((offset)+2*8)(RSP), (F10, F11) \
|
| 41 |
+
FLDPD ((offset)+4*8)(RSP), (F12, F13) \
|
| 42 |
+
FLDPD ((offset)+6*8)(RSP), (F14, F15)
|
| 43 |
+
|
go/src/runtime/cgo/abi_loong64.h
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
// Macros for transitioning from the host ABI to Go ABI0.
|
| 6 |
+
//
|
| 7 |
+
// These macros save and restore the callee-saved registers
|
| 8 |
+
// from the stack, but they don't adjust stack pointer, so
|
| 9 |
+
// the user should prepare stack space in advance.
|
| 10 |
+
// SAVE_R22_TO_R31(offset) saves R22 ~ R31 to the stack space
|
| 11 |
+
// of ((offset)+0*8)(R3) ~ ((offset)+9*8)(R3).
|
| 12 |
+
//
|
| 13 |
+
// SAVE_F24_TO_F31(offset) saves F24 ~ F31 to the stack space
|
| 14 |
+
// of ((offset)+0*8)(R3) ~ ((offset)+7*8)(R3).
|
| 15 |
+
//
|
| 16 |
+
// Note: g is R22
|
| 17 |
+
|
| 18 |
+
#define SAVE_R22_TO_R31(offset) \
|
| 19 |
+
MOVV g, ((offset)+(0*8))(R3) \
|
| 20 |
+
MOVV R23, ((offset)+(1*8))(R3) \
|
| 21 |
+
MOVV R24, ((offset)+(2*8))(R3) \
|
| 22 |
+
MOVV R25, ((offset)+(3*8))(R3) \
|
| 23 |
+
MOVV R26, ((offset)+(4*8))(R3) \
|
| 24 |
+
MOVV R27, ((offset)+(5*8))(R3) \
|
| 25 |
+
MOVV R28, ((offset)+(6*8))(R3) \
|
| 26 |
+
MOVV R29, ((offset)+(7*8))(R3) \
|
| 27 |
+
MOVV R30, ((offset)+(8*8))(R3) \
|
| 28 |
+
MOVV R31, ((offset)+(9*8))(R3)
|
| 29 |
+
|
| 30 |
+
#define SAVE_F24_TO_F31(offset) \
|
| 31 |
+
MOVD F24, ((offset)+(0*8))(R3) \
|
| 32 |
+
MOVD F25, ((offset)+(1*8))(R3) \
|
| 33 |
+
MOVD F26, ((offset)+(2*8))(R3) \
|
| 34 |
+
MOVD F27, ((offset)+(3*8))(R3) \
|
| 35 |
+
MOVD F28, ((offset)+(4*8))(R3) \
|
| 36 |
+
MOVD F29, ((offset)+(5*8))(R3) \
|
| 37 |
+
MOVD F30, ((offset)+(6*8))(R3) \
|
| 38 |
+
MOVD F31, ((offset)+(7*8))(R3)
|
| 39 |
+
|
| 40 |
+
#define RESTORE_R22_TO_R31(offset) \
|
| 41 |
+
MOVV ((offset)+(0*8))(R3), g \
|
| 42 |
+
MOVV ((offset)+(1*8))(R3), R23 \
|
| 43 |
+
MOVV ((offset)+(2*8))(R3), R24 \
|
| 44 |
+
MOVV ((offset)+(3*8))(R3), R25 \
|
| 45 |
+
MOVV ((offset)+(4*8))(R3), R26 \
|
| 46 |
+
MOVV ((offset)+(5*8))(R3), R27 \
|
| 47 |
+
MOVV ((offset)+(6*8))(R3), R28 \
|
| 48 |
+
MOVV ((offset)+(7*8))(R3), R29 \
|
| 49 |
+
MOVV ((offset)+(8*8))(R3), R30 \
|
| 50 |
+
MOVV ((offset)+(9*8))(R3), R31
|
| 51 |
+
|
| 52 |
+
#define RESTORE_F24_TO_F31(offset) \
|
| 53 |
+
MOVD ((offset)+(0*8))(R3), F24 \
|
| 54 |
+
MOVD ((offset)+(1*8))(R3), F25 \
|
| 55 |
+
MOVD ((offset)+(2*8))(R3), F26 \
|
| 56 |
+
MOVD ((offset)+(3*8))(R3), F27 \
|
| 57 |
+
MOVD ((offset)+(4*8))(R3), F28 \
|
| 58 |
+
MOVD ((offset)+(5*8))(R3), F29 \
|
| 59 |
+
MOVD ((offset)+(6*8))(R3), F30 \
|
| 60 |
+
MOVD ((offset)+(7*8))(R3), F31
|
go/src/runtime/cgo/abi_ppc64x.h
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2023 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
// Macros for transitioning from the host ABI to Go ABI
|
| 6 |
+
//
|
| 7 |
+
// On PPC64/ELFv2 targets, the following registers are callee
|
| 8 |
+
// saved when called from C. They must be preserved before
|
| 9 |
+
// calling into Go which does not preserve any of them.
|
| 10 |
+
//
|
| 11 |
+
// R14-R31
|
| 12 |
+
// CR2-4
|
| 13 |
+
// VR20-31
|
| 14 |
+
// F14-F31
|
| 15 |
+
//
|
| 16 |
+
// xcoff(aix) and ELFv1 are similar, but may only require a
|
| 17 |
+
// subset of these.
|
| 18 |
+
//
|
| 19 |
+
// These macros assume a 16 byte aligned stack pointer. This
|
| 20 |
+
// is required by ELFv1, ELFv2, and AIX PPC64.
|
| 21 |
+
|
| 22 |
+
#define SAVE_GPR_SIZE (18*8)
|
| 23 |
+
#define SAVE_GPR(offset) \
|
| 24 |
+
MOVD R14, (offset+8*0)(R1) \
|
| 25 |
+
MOVD R15, (offset+8*1)(R1) \
|
| 26 |
+
MOVD R16, (offset+8*2)(R1) \
|
| 27 |
+
MOVD R17, (offset+8*3)(R1) \
|
| 28 |
+
MOVD R18, (offset+8*4)(R1) \
|
| 29 |
+
MOVD R19, (offset+8*5)(R1) \
|
| 30 |
+
MOVD R20, (offset+8*6)(R1) \
|
| 31 |
+
MOVD R21, (offset+8*7)(R1) \
|
| 32 |
+
MOVD R22, (offset+8*8)(R1) \
|
| 33 |
+
MOVD R23, (offset+8*9)(R1) \
|
| 34 |
+
MOVD R24, (offset+8*10)(R1) \
|
| 35 |
+
MOVD R25, (offset+8*11)(R1) \
|
| 36 |
+
MOVD R26, (offset+8*12)(R1) \
|
| 37 |
+
MOVD R27, (offset+8*13)(R1) \
|
| 38 |
+
MOVD R28, (offset+8*14)(R1) \
|
| 39 |
+
MOVD R29, (offset+8*15)(R1) \
|
| 40 |
+
MOVD g, (offset+8*16)(R1) \
|
| 41 |
+
MOVD R31, (offset+8*17)(R1)
|
| 42 |
+
|
| 43 |
+
#define RESTORE_GPR(offset) \
|
| 44 |
+
MOVD (offset+8*0)(R1), R14 \
|
| 45 |
+
MOVD (offset+8*1)(R1), R15 \
|
| 46 |
+
MOVD (offset+8*2)(R1), R16 \
|
| 47 |
+
MOVD (offset+8*3)(R1), R17 \
|
| 48 |
+
MOVD (offset+8*4)(R1), R18 \
|
| 49 |
+
MOVD (offset+8*5)(R1), R19 \
|
| 50 |
+
MOVD (offset+8*6)(R1), R20 \
|
| 51 |
+
MOVD (offset+8*7)(R1), R21 \
|
| 52 |
+
MOVD (offset+8*8)(R1), R22 \
|
| 53 |
+
MOVD (offset+8*9)(R1), R23 \
|
| 54 |
+
MOVD (offset+8*10)(R1), R24 \
|
| 55 |
+
MOVD (offset+8*11)(R1), R25 \
|
| 56 |
+
MOVD (offset+8*12)(R1), R26 \
|
| 57 |
+
MOVD (offset+8*13)(R1), R27 \
|
| 58 |
+
MOVD (offset+8*14)(R1), R28 \
|
| 59 |
+
MOVD (offset+8*15)(R1), R29 \
|
| 60 |
+
MOVD (offset+8*16)(R1), g \
|
| 61 |
+
MOVD (offset+8*17)(R1), R31
|
| 62 |
+
|
| 63 |
+
#define SAVE_FPR_SIZE (18*8)
|
| 64 |
+
#define SAVE_FPR(offset) \
|
| 65 |
+
FMOVD F14, (offset+8*0)(R1) \
|
| 66 |
+
FMOVD F15, (offset+8*1)(R1) \
|
| 67 |
+
FMOVD F16, (offset+8*2)(R1) \
|
| 68 |
+
FMOVD F17, (offset+8*3)(R1) \
|
| 69 |
+
FMOVD F18, (offset+8*4)(R1) \
|
| 70 |
+
FMOVD F19, (offset+8*5)(R1) \
|
| 71 |
+
FMOVD F20, (offset+8*6)(R1) \
|
| 72 |
+
FMOVD F21, (offset+8*7)(R1) \
|
| 73 |
+
FMOVD F22, (offset+8*8)(R1) \
|
| 74 |
+
FMOVD F23, (offset+8*9)(R1) \
|
| 75 |
+
FMOVD F24, (offset+8*10)(R1) \
|
| 76 |
+
FMOVD F25, (offset+8*11)(R1) \
|
| 77 |
+
FMOVD F26, (offset+8*12)(R1) \
|
| 78 |
+
FMOVD F27, (offset+8*13)(R1) \
|
| 79 |
+
FMOVD F28, (offset+8*14)(R1) \
|
| 80 |
+
FMOVD F29, (offset+8*15)(R1) \
|
| 81 |
+
FMOVD F30, (offset+8*16)(R1) \
|
| 82 |
+
FMOVD F31, (offset+8*17)(R1)
|
| 83 |
+
|
| 84 |
+
#define RESTORE_FPR(offset) \
|
| 85 |
+
FMOVD (offset+8*0)(R1), F14 \
|
| 86 |
+
FMOVD (offset+8*1)(R1), F15 \
|
| 87 |
+
FMOVD (offset+8*2)(R1), F16 \
|
| 88 |
+
FMOVD (offset+8*3)(R1), F17 \
|
| 89 |
+
FMOVD (offset+8*4)(R1), F18 \
|
| 90 |
+
FMOVD (offset+8*5)(R1), F19 \
|
| 91 |
+
FMOVD (offset+8*6)(R1), F20 \
|
| 92 |
+
FMOVD (offset+8*7)(R1), F21 \
|
| 93 |
+
FMOVD (offset+8*8)(R1), F22 \
|
| 94 |
+
FMOVD (offset+8*9)(R1), F23 \
|
| 95 |
+
FMOVD (offset+8*10)(R1), F24 \
|
| 96 |
+
FMOVD (offset+8*11)(R1), F25 \
|
| 97 |
+
FMOVD (offset+8*12)(R1), F26 \
|
| 98 |
+
FMOVD (offset+8*13)(R1), F27 \
|
| 99 |
+
FMOVD (offset+8*14)(R1), F28 \
|
| 100 |
+
FMOVD (offset+8*15)(R1), F29 \
|
| 101 |
+
FMOVD (offset+8*16)(R1), F30 \
|
| 102 |
+
FMOVD (offset+8*17)(R1), F31
|
| 103 |
+
|
| 104 |
+
// Save and restore VR20-31 (aka VSR56-63). These
|
| 105 |
+
// macros must point to a 16B aligned offset.
|
| 106 |
+
#define SAVE_VR_SIZE (12*16)
|
| 107 |
+
#define SAVE_VR(offset, rtmp) \
|
| 108 |
+
MOVD $(offset+16*0), rtmp \
|
| 109 |
+
STVX V20, (rtmp)(R1) \
|
| 110 |
+
MOVD $(offset+16*1), rtmp \
|
| 111 |
+
STVX V21, (rtmp)(R1) \
|
| 112 |
+
MOVD $(offset+16*2), rtmp \
|
| 113 |
+
STVX V22, (rtmp)(R1) \
|
| 114 |
+
MOVD $(offset+16*3), rtmp \
|
| 115 |
+
STVX V23, (rtmp)(R1) \
|
| 116 |
+
MOVD $(offset+16*4), rtmp \
|
| 117 |
+
STVX V24, (rtmp)(R1) \
|
| 118 |
+
MOVD $(offset+16*5), rtmp \
|
| 119 |
+
STVX V25, (rtmp)(R1) \
|
| 120 |
+
MOVD $(offset+16*6), rtmp \
|
| 121 |
+
STVX V26, (rtmp)(R1) \
|
| 122 |
+
MOVD $(offset+16*7), rtmp \
|
| 123 |
+
STVX V27, (rtmp)(R1) \
|
| 124 |
+
MOVD $(offset+16*8), rtmp \
|
| 125 |
+
STVX V28, (rtmp)(R1) \
|
| 126 |
+
MOVD $(offset+16*9), rtmp \
|
| 127 |
+
STVX V29, (rtmp)(R1) \
|
| 128 |
+
MOVD $(offset+16*10), rtmp \
|
| 129 |
+
STVX V30, (rtmp)(R1) \
|
| 130 |
+
MOVD $(offset+16*11), rtmp \
|
| 131 |
+
STVX V31, (rtmp)(R1)
|
| 132 |
+
|
| 133 |
+
#define RESTORE_VR(offset, rtmp) \
|
| 134 |
+
MOVD $(offset+16*0), rtmp \
|
| 135 |
+
LVX (rtmp)(R1), V20 \
|
| 136 |
+
MOVD $(offset+16*1), rtmp \
|
| 137 |
+
LVX (rtmp)(R1), V21 \
|
| 138 |
+
MOVD $(offset+16*2), rtmp \
|
| 139 |
+
LVX (rtmp)(R1), V22 \
|
| 140 |
+
MOVD $(offset+16*3), rtmp \
|
| 141 |
+
LVX (rtmp)(R1), V23 \
|
| 142 |
+
MOVD $(offset+16*4), rtmp \
|
| 143 |
+
LVX (rtmp)(R1), V24 \
|
| 144 |
+
MOVD $(offset+16*5), rtmp \
|
| 145 |
+
LVX (rtmp)(R1), V25 \
|
| 146 |
+
MOVD $(offset+16*6), rtmp \
|
| 147 |
+
LVX (rtmp)(R1), V26 \
|
| 148 |
+
MOVD $(offset+16*7), rtmp \
|
| 149 |
+
LVX (rtmp)(R1), V27 \
|
| 150 |
+
MOVD $(offset+16*8), rtmp \
|
| 151 |
+
LVX (rtmp)(R1), V28 \
|
| 152 |
+
MOVD $(offset+16*9), rtmp \
|
| 153 |
+
LVX (rtmp)(R1), V29 \
|
| 154 |
+
MOVD $(offset+16*10), rtmp \
|
| 155 |
+
LVX (rtmp)(R1), V30 \
|
| 156 |
+
MOVD $(offset+16*11), rtmp \
|
| 157 |
+
LVX (rtmp)(R1), V31
|
| 158 |
+
|
| 159 |
+
// LR and CR are saved in the caller's frame. The callee must
|
| 160 |
+
// make space for all other callee-save registers.
|
| 161 |
+
#define SAVE_ALL_REG_SIZE (SAVE_GPR_SIZE+SAVE_FPR_SIZE+SAVE_VR_SIZE)
|
| 162 |
+
|
| 163 |
+
// Stack a frame and save all callee-save registers following the
|
| 164 |
+
// host OS's ABI. Fortunately, this is identical for AIX, ELFv1, and
|
| 165 |
+
// ELFv2. All host ABIs require the stack pointer to maintain 16 byte
|
| 166 |
+
// alignment, and save the callee-save registers in the same places.
|
| 167 |
+
//
|
| 168 |
+
// To restate, R1 is assumed to be aligned when this macro is used.
|
| 169 |
+
// This assumes the caller's frame is compliant with the host ABI.
|
| 170 |
+
// CR and LR are saved into the caller's frame per the host ABI.
|
| 171 |
+
// R0 is initialized to $0 as expected by Go.
|
| 172 |
+
#define STACK_AND_SAVE_HOST_TO_GO_ABI(extra) \
|
| 173 |
+
MOVD LR, R0 \
|
| 174 |
+
MOVD R0, 16(R1) \
|
| 175 |
+
MOVW CR, R0 \
|
| 176 |
+
MOVD R0, 8(R1) \
|
| 177 |
+
MOVDU R1, -(extra)-FIXED_FRAME-SAVE_ALL_REG_SIZE(R1) \
|
| 178 |
+
SAVE_GPR(extra+FIXED_FRAME) \
|
| 179 |
+
SAVE_FPR(extra+FIXED_FRAME+SAVE_GPR_SIZE) \
|
| 180 |
+
SAVE_VR(extra+FIXED_FRAME+SAVE_GPR_SIZE+SAVE_FPR_SIZE, R0) \
|
| 181 |
+
MOVD $0, R0
|
| 182 |
+
|
| 183 |
+
// This unstacks the frame, restoring all callee-save registers
|
| 184 |
+
// as saved by STACK_AND_SAVE_HOST_TO_GO_ABI.
|
| 185 |
+
//
|
| 186 |
+
// R0 is not guaranteed to contain $0 after this macro.
|
| 187 |
+
#define UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(extra) \
|
| 188 |
+
RESTORE_GPR(extra+FIXED_FRAME) \
|
| 189 |
+
RESTORE_FPR(extra+FIXED_FRAME+SAVE_GPR_SIZE) \
|
| 190 |
+
RESTORE_VR(extra+FIXED_FRAME+SAVE_GPR_SIZE+SAVE_FPR_SIZE, R0) \
|
| 191 |
+
ADD $(extra+FIXED_FRAME+SAVE_ALL_REG_SIZE), R1 \
|
| 192 |
+
MOVD 16(R1), R0 \
|
| 193 |
+
MOVD R0, LR \
|
| 194 |
+
MOVD 8(R1), R0 \
|
| 195 |
+
MOVW R0, CR
|
go/src/runtime/cgo/asm_386.s
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
|
| 7 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 8 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 9 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 10 |
+
// function.
|
| 11 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 12 |
+
MOVL _crosscall2_ptr(SB), AX
|
| 13 |
+
MOVL $crosscall2_trampoline<>(SB), BX
|
| 14 |
+
MOVL BX, (AX)
|
| 15 |
+
RET
|
| 16 |
+
|
| 17 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 18 |
+
JMP crosscall2(SB)
|
| 19 |
+
|
| 20 |
+
// Called by C code generated by cmd/cgo.
|
| 21 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 22 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 23 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 24 |
+
TEXT crosscall2(SB),NOSPLIT,$28-16
|
| 25 |
+
MOVL BP, 24(SP)
|
| 26 |
+
MOVL BX, 20(SP)
|
| 27 |
+
MOVL SI, 16(SP)
|
| 28 |
+
MOVL DI, 12(SP)
|
| 29 |
+
|
| 30 |
+
MOVL ctxt+12(FP), AX
|
| 31 |
+
MOVL AX, 8(SP)
|
| 32 |
+
MOVL a+4(FP), AX
|
| 33 |
+
MOVL AX, 4(SP)
|
| 34 |
+
MOVL fn+0(FP), AX
|
| 35 |
+
MOVL AX, 0(SP)
|
| 36 |
+
CALL runtime·cgocallback(SB)
|
| 37 |
+
|
| 38 |
+
MOVL 12(SP), DI
|
| 39 |
+
MOVL 16(SP), SI
|
| 40 |
+
MOVL 20(SP), BX
|
| 41 |
+
MOVL 24(SP), BP
|
| 42 |
+
RET
|
go/src/runtime/cgo/asm_amd64.s
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
#include "abi_amd64.h"
|
| 7 |
+
|
| 8 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 9 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 10 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 11 |
+
// function.
|
| 12 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 13 |
+
MOVQ _crosscall2_ptr(SB), AX
|
| 14 |
+
MOVQ $crosscall2_trampoline<>(SB), BX
|
| 15 |
+
MOVQ BX, (AX)
|
| 16 |
+
RET
|
| 17 |
+
|
| 18 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 19 |
+
JMP crosscall2(SB)
|
| 20 |
+
|
| 21 |
+
// Called by C code generated by cmd/cgo.
|
| 22 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 23 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 24 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 25 |
+
// This signature is known to SWIG, so we can't change it.
|
| 26 |
+
TEXT crosscall2(SB),NOSPLIT,$0-0
|
| 27 |
+
PUSH_REGS_HOST_TO_ABI0()
|
| 28 |
+
|
| 29 |
+
// Make room for arguments to cgocallback.
|
| 30 |
+
ADJSP $0x18
|
| 31 |
+
#ifndef GOOS_windows
|
| 32 |
+
MOVQ DI, 0x0(SP) /* fn */
|
| 33 |
+
MOVQ SI, 0x8(SP) /* arg */
|
| 34 |
+
// Skip n in DX.
|
| 35 |
+
MOVQ CX, 0x10(SP) /* ctxt */
|
| 36 |
+
#else
|
| 37 |
+
MOVQ CX, 0x0(SP) /* fn */
|
| 38 |
+
MOVQ DX, 0x8(SP) /* arg */
|
| 39 |
+
// Skip n in R8.
|
| 40 |
+
MOVQ R9, 0x10(SP) /* ctxt */
|
| 41 |
+
#endif
|
| 42 |
+
|
| 43 |
+
CALL runtime·cgocallback(SB)
|
| 44 |
+
|
| 45 |
+
ADJSP $-0x18
|
| 46 |
+
POP_REGS_HOST_TO_ABI0()
|
| 47 |
+
RET
|
go/src/runtime/cgo/asm_arm.s
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2012 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
|
| 7 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 8 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 9 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 10 |
+
// function.
|
| 11 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 12 |
+
MOVW _crosscall2_ptr(SB), R1
|
| 13 |
+
MOVW $crosscall2_trampoline<>(SB), R2
|
| 14 |
+
MOVW R2, (R1)
|
| 15 |
+
RET
|
| 16 |
+
|
| 17 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 18 |
+
JMP crosscall2(SB)
|
| 19 |
+
|
| 20 |
+
// Called by C code generated by cmd/cgo.
|
| 21 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 22 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 23 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 24 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 25 |
+
SUB $(8*9), R13 // Reserve space for the floating point registers.
|
| 26 |
+
// The C arguments arrive in R0, R1, R2, and R3. We want to
|
| 27 |
+
// pass R0, R1, and R3 to Go, so we push those on the stack.
|
| 28 |
+
// Also, save C callee-save registers R4-R12.
|
| 29 |
+
MOVM.WP [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12], (R13)
|
| 30 |
+
// Finally, save the link register R14. This also puts the
|
| 31 |
+
// arguments we pushed for cgocallback where they need to be,
|
| 32 |
+
// starting at 4(R13).
|
| 33 |
+
MOVW.W R14, -4(R13)
|
| 34 |
+
|
| 35 |
+
// Skip floating point registers if goarmsoftfp!=0.
|
| 36 |
+
MOVB runtime·goarmsoftfp(SB), R11
|
| 37 |
+
CMP $0, R11
|
| 38 |
+
BNE skipfpsave
|
| 39 |
+
MOVD F8, (13*4+8*1)(R13)
|
| 40 |
+
MOVD F9, (13*4+8*2)(R13)
|
| 41 |
+
MOVD F10, (13*4+8*3)(R13)
|
| 42 |
+
MOVD F11, (13*4+8*4)(R13)
|
| 43 |
+
MOVD F12, (13*4+8*5)(R13)
|
| 44 |
+
MOVD F13, (13*4+8*6)(R13)
|
| 45 |
+
MOVD F14, (13*4+8*7)(R13)
|
| 46 |
+
MOVD F15, (13*4+8*8)(R13)
|
| 47 |
+
|
| 48 |
+
skipfpsave:
|
| 49 |
+
BL runtime·load_g(SB)
|
| 50 |
+
// We set up the arguments to cgocallback when saving registers above.
|
| 51 |
+
BL runtime·cgocallback(SB)
|
| 52 |
+
|
| 53 |
+
MOVB runtime·goarmsoftfp(SB), R11
|
| 54 |
+
CMP $0, R11
|
| 55 |
+
BNE skipfprest
|
| 56 |
+
MOVD (13*4+8*1)(R13), F8
|
| 57 |
+
MOVD (13*4+8*2)(R13), F9
|
| 58 |
+
MOVD (13*4+8*3)(R13), F10
|
| 59 |
+
MOVD (13*4+8*4)(R13), F11
|
| 60 |
+
MOVD (13*4+8*5)(R13), F12
|
| 61 |
+
MOVD (13*4+8*6)(R13), F13
|
| 62 |
+
MOVD (13*4+8*7)(R13), F14
|
| 63 |
+
MOVD (13*4+8*8)(R13), F15
|
| 64 |
+
|
| 65 |
+
skipfprest:
|
| 66 |
+
MOVW.P 4(R13), R14
|
| 67 |
+
MOVM.IAW (R13), [R0, R1, R3, R4, R5, R6, R7, R8, R9, g, R11, R12]
|
| 68 |
+
ADD $(8*9), R13
|
| 69 |
+
MOVW R14, R15
|
go/src/runtime/cgo/asm_arm64.s
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
#include "abi_arm64.h"
|
| 7 |
+
|
| 8 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 9 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 10 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 11 |
+
// function.
|
| 12 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 13 |
+
MOVD _crosscall2_ptr(SB), R1
|
| 14 |
+
MOVD $crosscall2_trampoline<>(SB), R2
|
| 15 |
+
MOVD R2, (R1)
|
| 16 |
+
RET
|
| 17 |
+
|
| 18 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 19 |
+
JMP crosscall2(SB)
|
| 20 |
+
|
| 21 |
+
// Called by C code generated by cmd/cgo.
|
| 22 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 23 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 24 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 25 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 26 |
+
/*
|
| 27 |
+
* We still need to save all callee save register as before, and then
|
| 28 |
+
* push 3 args for fn (R0, R1, R3), skipping R2.
|
| 29 |
+
* Also note that at procedure entry in gc world, 8(RSP) will be the
|
| 30 |
+
* first arg.
|
| 31 |
+
*/
|
| 32 |
+
SUB $(8*24), RSP
|
| 33 |
+
STP (R0, R1), (8*1)(RSP)
|
| 34 |
+
MOVD R3, (8*3)(RSP)
|
| 35 |
+
|
| 36 |
+
SAVE_R19_TO_R28(8*4)
|
| 37 |
+
SAVE_F8_TO_F15(8*14)
|
| 38 |
+
STP (R29, R30), (8*22)(RSP)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
// Initialize Go ABI environment
|
| 42 |
+
BL runtime·load_g(SB)
|
| 43 |
+
BL runtime·cgocallback(SB)
|
| 44 |
+
|
| 45 |
+
RESTORE_R19_TO_R28(8*4)
|
| 46 |
+
RESTORE_F8_TO_F15(8*14)
|
| 47 |
+
LDP (8*22)(RSP), (R29, R30)
|
| 48 |
+
|
| 49 |
+
ADD $(8*24), RSP
|
| 50 |
+
RET
|
go/src/runtime/cgo/asm_loong64.s
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
#include "abi_loong64.h"
|
| 7 |
+
|
| 8 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 9 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 10 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 11 |
+
// function.
|
| 12 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 13 |
+
MOVV _crosscall2_ptr(SB), R5
|
| 14 |
+
MOVV $crosscall2_trampoline<>(SB), R6
|
| 15 |
+
MOVV R6, (R5)
|
| 16 |
+
RET
|
| 17 |
+
|
| 18 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 19 |
+
JMP crosscall2(SB)
|
| 20 |
+
|
| 21 |
+
// Called by C code generated by cmd/cgo.
|
| 22 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 23 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 24 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 25 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 26 |
+
/*
|
| 27 |
+
* We still need to save all callee save register as before, and then
|
| 28 |
+
* push 3 args for fn (R4, R5, R7), skipping R6.
|
| 29 |
+
* Also note that at procedure entry in gc world, 8(R29) will be the
|
| 30 |
+
* first arg.
|
| 31 |
+
*/
|
| 32 |
+
|
| 33 |
+
ADDV $(-23*8), R3
|
| 34 |
+
MOVV R4, (1*8)(R3) // fn unsafe.Pointer
|
| 35 |
+
MOVV R5, (2*8)(R3) // a unsafe.Pointer
|
| 36 |
+
MOVV R7, (3*8)(R3) // ctxt uintptr
|
| 37 |
+
|
| 38 |
+
SAVE_R22_TO_R31((4*8))
|
| 39 |
+
SAVE_F24_TO_F31((14*8))
|
| 40 |
+
MOVV R1, (22*8)(R3)
|
| 41 |
+
|
| 42 |
+
// Initialize Go ABI environment
|
| 43 |
+
JAL runtime·load_g(SB)
|
| 44 |
+
|
| 45 |
+
JAL runtime·cgocallback(SB)
|
| 46 |
+
|
| 47 |
+
RESTORE_R22_TO_R31((4*8))
|
| 48 |
+
RESTORE_F24_TO_F31((14*8))
|
| 49 |
+
MOVV (22*8)(R3), R1
|
| 50 |
+
|
| 51 |
+
ADDV $(23*8), R3
|
| 52 |
+
|
| 53 |
+
RET
|
go/src/runtime/cgo/asm_mips64x.s
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build mips64 || mips64le
|
| 6 |
+
|
| 7 |
+
#include "textflag.h"
|
| 8 |
+
|
| 9 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 10 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 11 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 12 |
+
// function.
|
| 13 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 14 |
+
MOVV _crosscall2_ptr(SB), R5
|
| 15 |
+
MOVV $crosscall2_trampoline<>(SB), R6
|
| 16 |
+
MOVV R6, (R5)
|
| 17 |
+
RET
|
| 18 |
+
|
| 19 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 20 |
+
JMP crosscall2(SB)
|
| 21 |
+
|
| 22 |
+
// Called by C code generated by cmd/cgo.
|
| 23 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 24 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 25 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 26 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 27 |
+
/*
|
| 28 |
+
* We still need to save all callee save register as before, and then
|
| 29 |
+
* push 3 args for fn (R4, R5, R7), skipping R6.
|
| 30 |
+
* Also note that at procedure entry in gc world, 8(R29) will be the
|
| 31 |
+
* first arg.
|
| 32 |
+
*/
|
| 33 |
+
#ifndef GOMIPS64_softfloat
|
| 34 |
+
ADDV $(-8*23), R29
|
| 35 |
+
#else
|
| 36 |
+
ADDV $(-8*15), R29
|
| 37 |
+
#endif
|
| 38 |
+
MOVV R4, (8*1)(R29) // fn unsafe.Pointer
|
| 39 |
+
MOVV R5, (8*2)(R29) // a unsafe.Pointer
|
| 40 |
+
MOVV R7, (8*3)(R29) // ctxt uintptr
|
| 41 |
+
MOVV R16, (8*4)(R29)
|
| 42 |
+
MOVV R17, (8*5)(R29)
|
| 43 |
+
MOVV R18, (8*6)(R29)
|
| 44 |
+
MOVV R19, (8*7)(R29)
|
| 45 |
+
MOVV R20, (8*8)(R29)
|
| 46 |
+
MOVV R21, (8*9)(R29)
|
| 47 |
+
MOVV R22, (8*10)(R29)
|
| 48 |
+
MOVV R23, (8*11)(R29)
|
| 49 |
+
MOVV RSB, (8*12)(R29)
|
| 50 |
+
MOVV g, (8*13)(R29)
|
| 51 |
+
MOVV R31, (8*14)(R29)
|
| 52 |
+
#ifndef GOMIPS64_softfloat
|
| 53 |
+
MOVD F24, (8*15)(R29)
|
| 54 |
+
MOVD F25, (8*16)(R29)
|
| 55 |
+
MOVD F26, (8*17)(R29)
|
| 56 |
+
MOVD F27, (8*18)(R29)
|
| 57 |
+
MOVD F28, (8*19)(R29)
|
| 58 |
+
MOVD F29, (8*20)(R29)
|
| 59 |
+
MOVD F30, (8*21)(R29)
|
| 60 |
+
MOVD F31, (8*22)(R29)
|
| 61 |
+
#endif
|
| 62 |
+
// Initialize Go ABI environment
|
| 63 |
+
// prepare SB register = PC & 0xffffffff00000000
|
| 64 |
+
BGEZAL R0, 1(PC)
|
| 65 |
+
SRLV $32, R31, RSB
|
| 66 |
+
SLLV $32, RSB
|
| 67 |
+
JAL runtime·load_g(SB)
|
| 68 |
+
|
| 69 |
+
JAL runtime·cgocallback(SB)
|
| 70 |
+
|
| 71 |
+
MOVV (8*4)(R29), R16
|
| 72 |
+
MOVV (8*5)(R29), R17
|
| 73 |
+
MOVV (8*6)(R29), R18
|
| 74 |
+
MOVV (8*7)(R29), R19
|
| 75 |
+
MOVV (8*8)(R29), R20
|
| 76 |
+
MOVV (8*9)(R29), R21
|
| 77 |
+
MOVV (8*10)(R29), R22
|
| 78 |
+
MOVV (8*11)(R29), R23
|
| 79 |
+
MOVV (8*12)(R29), RSB
|
| 80 |
+
MOVV (8*13)(R29), g
|
| 81 |
+
MOVV (8*14)(R29), R31
|
| 82 |
+
#ifndef GOMIPS64_softfloat
|
| 83 |
+
MOVD (8*15)(R29), F24
|
| 84 |
+
MOVD (8*16)(R29), F25
|
| 85 |
+
MOVD (8*17)(R29), F26
|
| 86 |
+
MOVD (8*18)(R29), F27
|
| 87 |
+
MOVD (8*19)(R29), F28
|
| 88 |
+
MOVD (8*20)(R29), F29
|
| 89 |
+
MOVD (8*21)(R29), F30
|
| 90 |
+
MOVD (8*22)(R29), F31
|
| 91 |
+
ADDV $(8*23), R29
|
| 92 |
+
#else
|
| 93 |
+
ADDV $(8*15), R29
|
| 94 |
+
#endif
|
| 95 |
+
RET
|
go/src/runtime/cgo/asm_mipsx.s
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build mips || mipsle
|
| 6 |
+
|
| 7 |
+
#include "textflag.h"
|
| 8 |
+
|
| 9 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 10 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 11 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 12 |
+
// function.
|
| 13 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 14 |
+
MOVW _crosscall2_ptr(SB), R5
|
| 15 |
+
MOVW $crosscall2_trampoline<>(SB), R6
|
| 16 |
+
MOVW R6, (R5)
|
| 17 |
+
RET
|
| 18 |
+
|
| 19 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 20 |
+
JMP crosscall2(SB)
|
| 21 |
+
|
| 22 |
+
// Called by C code generated by cmd/cgo.
|
| 23 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 24 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 25 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 26 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 27 |
+
/*
|
| 28 |
+
* We still need to save all callee save register as before, and then
|
| 29 |
+
* push 3 args for fn (R4, R5, R7), skipping R6.
|
| 30 |
+
* Also note that at procedure entry in gc world, 4(R29) will be the
|
| 31 |
+
* first arg.
|
| 32 |
+
*/
|
| 33 |
+
|
| 34 |
+
// Space for 9 caller-saved GPR + LR + 6 caller-saved FPR.
|
| 35 |
+
// O32 ABI allows us to smash 16 bytes argument area of caller frame.
|
| 36 |
+
#ifndef GOMIPS_softfloat
|
| 37 |
+
SUBU $(4*14+8*6-16), R29
|
| 38 |
+
#else
|
| 39 |
+
SUBU $(4*14-16), R29 // For soft-float, no FPR.
|
| 40 |
+
#endif
|
| 41 |
+
MOVW R4, (4*1)(R29) // fn unsafe.Pointer
|
| 42 |
+
MOVW R5, (4*2)(R29) // a unsafe.Pointer
|
| 43 |
+
MOVW R7, (4*3)(R29) // ctxt uintptr
|
| 44 |
+
MOVW R16, (4*4)(R29)
|
| 45 |
+
MOVW R17, (4*5)(R29)
|
| 46 |
+
MOVW R18, (4*6)(R29)
|
| 47 |
+
MOVW R19, (4*7)(R29)
|
| 48 |
+
MOVW R20, (4*8)(R29)
|
| 49 |
+
MOVW R21, (4*9)(R29)
|
| 50 |
+
MOVW R22, (4*10)(R29)
|
| 51 |
+
MOVW R23, (4*11)(R29)
|
| 52 |
+
MOVW g, (4*12)(R29)
|
| 53 |
+
MOVW R31, (4*13)(R29)
|
| 54 |
+
#ifndef GOMIPS_softfloat
|
| 55 |
+
MOVD F20, (4*14)(R29)
|
| 56 |
+
MOVD F22, (4*14+8*1)(R29)
|
| 57 |
+
MOVD F24, (4*14+8*2)(R29)
|
| 58 |
+
MOVD F26, (4*14+8*3)(R29)
|
| 59 |
+
MOVD F28, (4*14+8*4)(R29)
|
| 60 |
+
MOVD F30, (4*14+8*5)(R29)
|
| 61 |
+
#endif
|
| 62 |
+
JAL runtime·load_g(SB)
|
| 63 |
+
|
| 64 |
+
JAL runtime·cgocallback(SB)
|
| 65 |
+
|
| 66 |
+
MOVW (4*4)(R29), R16
|
| 67 |
+
MOVW (4*5)(R29), R17
|
| 68 |
+
MOVW (4*6)(R29), R18
|
| 69 |
+
MOVW (4*7)(R29), R19
|
| 70 |
+
MOVW (4*8)(R29), R20
|
| 71 |
+
MOVW (4*9)(R29), R21
|
| 72 |
+
MOVW (4*10)(R29), R22
|
| 73 |
+
MOVW (4*11)(R29), R23
|
| 74 |
+
MOVW (4*12)(R29), g
|
| 75 |
+
MOVW (4*13)(R29), R31
|
| 76 |
+
#ifndef GOMIPS_softfloat
|
| 77 |
+
MOVD (4*14)(R29), F20
|
| 78 |
+
MOVD (4*14+8*1)(R29), F22
|
| 79 |
+
MOVD (4*14+8*2)(R29), F24
|
| 80 |
+
MOVD (4*14+8*3)(R29), F26
|
| 81 |
+
MOVD (4*14+8*4)(R29), F28
|
| 82 |
+
MOVD (4*14+8*5)(R29), F30
|
| 83 |
+
|
| 84 |
+
ADDU $(4*14+8*6-16), R29
|
| 85 |
+
#else
|
| 86 |
+
ADDU $(4*14-16), R29
|
| 87 |
+
#endif
|
| 88 |
+
RET
|
go/src/runtime/cgo/asm_ppc64x.s
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build ppc64 || ppc64le
|
| 6 |
+
|
| 7 |
+
#include "textflag.h"
|
| 8 |
+
#include "asm_ppc64x.h"
|
| 9 |
+
#include "abi_ppc64x.h"
|
| 10 |
+
|
| 11 |
+
#ifdef GO_PPC64X_HAS_FUNCDESC
|
| 12 |
+
// crosscall2 is marked with go:cgo_export_static. On AIX, this creates and exports
|
| 13 |
+
// the symbol name and descriptor as the AIX linker expects, but does not work if
|
| 14 |
+
// referenced from within Go. Create and use an aliased descriptor of crosscall2
|
| 15 |
+
// to workaround this.
|
| 16 |
+
DEFINE_PPC64X_FUNCDESC(_crosscall2<>, crosscall2)
|
| 17 |
+
#define CROSSCALL2_FPTR $_crosscall2<>(SB)
|
| 18 |
+
#else
|
| 19 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 20 |
+
// function.
|
| 21 |
+
#define CROSSCALL2_FPTR $crosscall2_trampoline<>(SB)
|
| 22 |
+
#endif
|
| 23 |
+
|
| 24 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 25 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 26 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 27 |
+
MOVD _crosscall2_ptr(SB), R5
|
| 28 |
+
MOVD CROSSCALL2_FPTR, R6
|
| 29 |
+
MOVD R6, (R5)
|
| 30 |
+
RET
|
| 31 |
+
|
| 32 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 33 |
+
JMP crosscall2(SB)
|
| 34 |
+
|
| 35 |
+
// Called by C code generated by cmd/cgo.
|
| 36 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 37 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 38 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 39 |
+
// The value of R2 is saved on the new stack frame, and not
|
| 40 |
+
// the caller's frame due to issue #43228.
|
| 41 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 42 |
+
// Start with standard C stack frame layout and linkage, allocate
|
| 43 |
+
// 32 bytes of argument space, save callee-save regs, and set R0 to $0.
|
| 44 |
+
STACK_AND_SAVE_HOST_TO_GO_ABI(32)
|
| 45 |
+
// The above will not preserve R2 (TOC). Save it in case Go is
|
| 46 |
+
// compiled without a TOC pointer (e.g -buildmode=default).
|
| 47 |
+
MOVD R2, 24(R1)
|
| 48 |
+
|
| 49 |
+
// Load the current g.
|
| 50 |
+
BL runtime·load_g(SB)
|
| 51 |
+
|
| 52 |
+
#ifdef GO_PPC64X_HAS_FUNCDESC
|
| 53 |
+
// Load the real entry address from the first slot of the function descriptor.
|
| 54 |
+
// The first argument fn might be null, that means dropm in pthread key destructor.
|
| 55 |
+
CMP R3, $0
|
| 56 |
+
BEQ nil_fn
|
| 57 |
+
MOVD 8(R3), R2
|
| 58 |
+
MOVD (R3), R3
|
| 59 |
+
nil_fn:
|
| 60 |
+
#endif
|
| 61 |
+
MOVD R3, FIXED_FRAME+0(R1) // fn unsafe.Pointer
|
| 62 |
+
MOVD R4, FIXED_FRAME+8(R1) // a unsafe.Pointer
|
| 63 |
+
// Skip R5 = n uint32
|
| 64 |
+
MOVD R6, FIXED_FRAME+16(R1) // ctxt uintptr
|
| 65 |
+
BL runtime·cgocallback(SB)
|
| 66 |
+
|
| 67 |
+
// Restore the old frame, and R2.
|
| 68 |
+
MOVD 24(R1), R2
|
| 69 |
+
UNSTACK_AND_RESTORE_GO_TO_HOST_ABI(32)
|
| 70 |
+
RET
|
go/src/runtime/cgo/asm_riscv64.s
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2020 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
|
| 7 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 8 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 9 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 10 |
+
// function.
|
| 11 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 12 |
+
MOV _crosscall2_ptr(SB), X7
|
| 13 |
+
MOV $crosscall2_trampoline<>(SB), X8
|
| 14 |
+
MOV X8, (X7)
|
| 15 |
+
RET
|
| 16 |
+
|
| 17 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 18 |
+
JMP crosscall2(SB)
|
| 19 |
+
|
| 20 |
+
// Called by C code generated by cmd/cgo.
|
| 21 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 22 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 23 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 24 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 25 |
+
/*
|
| 26 |
+
* Push arguments for fn (X10, X11, X13), along with all callee-save
|
| 27 |
+
* registers. Note that at procedure entry the first argument is at
|
| 28 |
+
* 8(X2).
|
| 29 |
+
*/
|
| 30 |
+
ADD $(-8*29), X2
|
| 31 |
+
MOV X10, (8*1)(X2) // fn unsafe.Pointer
|
| 32 |
+
MOV X11, (8*2)(X2) // a unsafe.Pointer
|
| 33 |
+
MOV X13, (8*3)(X2) // ctxt uintptr
|
| 34 |
+
MOV X8, (8*4)(X2)
|
| 35 |
+
MOV X9, (8*5)(X2)
|
| 36 |
+
MOV X18, (8*6)(X2)
|
| 37 |
+
MOV X19, (8*7)(X2)
|
| 38 |
+
MOV X20, (8*8)(X2)
|
| 39 |
+
MOV X21, (8*9)(X2)
|
| 40 |
+
MOV X22, (8*10)(X2)
|
| 41 |
+
MOV X23, (8*11)(X2)
|
| 42 |
+
MOV X24, (8*12)(X2)
|
| 43 |
+
MOV X25, (8*13)(X2)
|
| 44 |
+
MOV X26, (8*14)(X2)
|
| 45 |
+
MOV g, (8*15)(X2)
|
| 46 |
+
MOV X1, (8*16)(X2)
|
| 47 |
+
MOVD F8, (8*17)(X2)
|
| 48 |
+
MOVD F9, (8*18)(X2)
|
| 49 |
+
MOVD F18, (8*19)(X2)
|
| 50 |
+
MOVD F19, (8*20)(X2)
|
| 51 |
+
MOVD F20, (8*21)(X2)
|
| 52 |
+
MOVD F21, (8*22)(X2)
|
| 53 |
+
MOVD F22, (8*23)(X2)
|
| 54 |
+
MOVD F23, (8*24)(X2)
|
| 55 |
+
MOVD F24, (8*25)(X2)
|
| 56 |
+
MOVD F25, (8*26)(X2)
|
| 57 |
+
MOVD F26, (8*27)(X2)
|
| 58 |
+
MOVD F27, (8*28)(X2)
|
| 59 |
+
|
| 60 |
+
// Initialize Go ABI environment
|
| 61 |
+
CALL runtime·load_g(SB)
|
| 62 |
+
CALL runtime·cgocallback(SB)
|
| 63 |
+
|
| 64 |
+
MOV (8*4)(X2), X8
|
| 65 |
+
MOV (8*5)(X2), X9
|
| 66 |
+
MOV (8*6)(X2), X18
|
| 67 |
+
MOV (8*7)(X2), X19
|
| 68 |
+
MOV (8*8)(X2), X20
|
| 69 |
+
MOV (8*9)(X2), X21
|
| 70 |
+
MOV (8*10)(X2), X22
|
| 71 |
+
MOV (8*11)(X2), X23
|
| 72 |
+
MOV (8*12)(X2), X24
|
| 73 |
+
MOV (8*13)(X2), X25
|
| 74 |
+
MOV (8*14)(X2), X26
|
| 75 |
+
MOV (8*15)(X2), g
|
| 76 |
+
MOV (8*16)(X2), X1
|
| 77 |
+
MOVD (8*17)(X2), F8
|
| 78 |
+
MOVD (8*18)(X2), F9
|
| 79 |
+
MOVD (8*19)(X2), F18
|
| 80 |
+
MOVD (8*20)(X2), F19
|
| 81 |
+
MOVD (8*21)(X2), F20
|
| 82 |
+
MOVD (8*22)(X2), F21
|
| 83 |
+
MOVD (8*23)(X2), F22
|
| 84 |
+
MOVD (8*24)(X2), F23
|
| 85 |
+
MOVD (8*25)(X2), F24
|
| 86 |
+
MOVD (8*26)(X2), F25
|
| 87 |
+
MOVD (8*27)(X2), F26
|
| 88 |
+
MOVD (8*28)(X2), F27
|
| 89 |
+
ADD $(8*29), X2
|
| 90 |
+
|
| 91 |
+
RET
|
go/src/runtime/cgo/asm_s390x.s
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
|
| 7 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 8 |
+
// It's such a pointer chain: _crosscall2_ptr -> x_crosscall2_ptr -> crosscall2
|
| 9 |
+
// Use a local trampoline, to avoid taking the address of a dynamically exported
|
| 10 |
+
// function.
|
| 11 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 12 |
+
MOVD _crosscall2_ptr(SB), R1
|
| 13 |
+
MOVD $crosscall2_trampoline<>(SB), R2
|
| 14 |
+
MOVD R2, (R1)
|
| 15 |
+
RET
|
| 16 |
+
|
| 17 |
+
TEXT crosscall2_trampoline<>(SB),NOSPLIT,$0-0
|
| 18 |
+
JMP crosscall2(SB)
|
| 19 |
+
|
| 20 |
+
// Called by C code generated by cmd/cgo.
|
| 21 |
+
// func crosscall2(fn, a unsafe.Pointer, n int32, ctxt uintptr)
|
| 22 |
+
// Saves C callee-saved registers and calls cgocallback with three arguments.
|
| 23 |
+
// fn is the PC of a func(a unsafe.Pointer) function.
|
| 24 |
+
TEXT crosscall2(SB),NOSPLIT|NOFRAME,$0
|
| 25 |
+
// Start with standard C stack frame layout and linkage.
|
| 26 |
+
|
| 27 |
+
// Save R6-R15 in the register save area of the calling function.
|
| 28 |
+
STMG R6, R15, 48(R15)
|
| 29 |
+
|
| 30 |
+
// Allocate 96 bytes on the stack.
|
| 31 |
+
MOVD $-96(R15), R15
|
| 32 |
+
|
| 33 |
+
// Save F8-F15 in our stack frame.
|
| 34 |
+
FMOVD F8, 32(R15)
|
| 35 |
+
FMOVD F9, 40(R15)
|
| 36 |
+
FMOVD F10, 48(R15)
|
| 37 |
+
FMOVD F11, 56(R15)
|
| 38 |
+
FMOVD F12, 64(R15)
|
| 39 |
+
FMOVD F13, 72(R15)
|
| 40 |
+
FMOVD F14, 80(R15)
|
| 41 |
+
FMOVD F15, 88(R15)
|
| 42 |
+
|
| 43 |
+
// Initialize Go ABI environment.
|
| 44 |
+
BL runtime·load_g(SB)
|
| 45 |
+
|
| 46 |
+
MOVD R2, 8(R15) // fn unsafe.Pointer
|
| 47 |
+
MOVD R3, 16(R15) // a unsafe.Pointer
|
| 48 |
+
// Skip R4 = n uint32
|
| 49 |
+
MOVD R5, 24(R15) // ctxt uintptr
|
| 50 |
+
BL runtime·cgocallback(SB)
|
| 51 |
+
|
| 52 |
+
FMOVD 32(R15), F8
|
| 53 |
+
FMOVD 40(R15), F9
|
| 54 |
+
FMOVD 48(R15), F10
|
| 55 |
+
FMOVD 56(R15), F11
|
| 56 |
+
FMOVD 64(R15), F12
|
| 57 |
+
FMOVD 72(R15), F13
|
| 58 |
+
FMOVD 80(R15), F14
|
| 59 |
+
FMOVD 88(R15), F15
|
| 60 |
+
|
| 61 |
+
// De-allocate stack frame.
|
| 62 |
+
MOVD $96(R15), R15
|
| 63 |
+
|
| 64 |
+
// Restore R6-R15.
|
| 65 |
+
LMG 48(R15), R6, R15
|
| 66 |
+
|
| 67 |
+
RET
|
| 68 |
+
|
go/src/runtime/cgo/asm_wasm.s
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include "textflag.h"
|
| 6 |
+
|
| 7 |
+
TEXT ·set_crosscall2(SB),NOSPLIT,$0-0
|
| 8 |
+
UNDEF
|
| 9 |
+
|
| 10 |
+
TEXT crosscall2(SB), NOSPLIT, $0
|
| 11 |
+
UNDEF
|
go/src/runtime/cgo/callbacks.go
ADDED
|
@@ -0,0 +1,169 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2011 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
package cgo
|
| 6 |
+
|
| 7 |
+
import "unsafe"
|
| 8 |
+
|
| 9 |
+
// These utility functions are available to be called from code
|
| 10 |
+
// compiled with gcc via crosscall2.
|
| 11 |
+
|
| 12 |
+
// The declaration of crosscall2 is:
|
| 13 |
+
// void crosscall2(void (*fn)(void *), void *, int);
|
| 14 |
+
//
|
| 15 |
+
// We need to export the symbol crosscall2 in order to support
|
| 16 |
+
// callbacks from shared libraries. This applies regardless of
|
| 17 |
+
// linking mode.
|
| 18 |
+
//
|
| 19 |
+
// Compatibility note: SWIG uses crosscall2 in exactly one situation:
|
| 20 |
+
// to call _cgo_panic using the pattern shown below. We need to keep
|
| 21 |
+
// that pattern working. In particular, crosscall2 actually takes four
|
| 22 |
+
// arguments, but it works to call it with three arguments when
|
| 23 |
+
// calling _cgo_panic.
|
| 24 |
+
//
|
| 25 |
+
//go:cgo_export_static crosscall2
|
| 26 |
+
//go:cgo_export_dynamic crosscall2
|
| 27 |
+
|
| 28 |
+
// Panic. The argument is converted into a Go string.
|
| 29 |
+
|
| 30 |
+
// Call like this in code compiled with gcc:
|
| 31 |
+
// struct { const char *p; } a;
|
| 32 |
+
// a.p = /* string to pass to panic */;
|
| 33 |
+
// crosscall2(_cgo_panic, &a, sizeof a);
|
| 34 |
+
// /* The function call will not return. */
|
| 35 |
+
|
| 36 |
+
// TODO: We should export a regular C function to panic, change SWIG
|
| 37 |
+
// to use that instead of the above pattern, and then we can drop
|
| 38 |
+
// backwards-compatibility from crosscall2 and stop exporting it.
|
| 39 |
+
|
| 40 |
+
//go:linkname _runtime_cgo_panic_internal runtime._cgo_panic_internal
|
| 41 |
+
func _runtime_cgo_panic_internal(p *byte)
|
| 42 |
+
|
| 43 |
+
//go:linkname _cgo_panic _cgo_panic
|
| 44 |
+
//go:cgo_export_static _cgo_panic
|
| 45 |
+
//go:cgo_export_dynamic _cgo_panic
|
| 46 |
+
func _cgo_panic(a *struct{ cstr *byte }) {
|
| 47 |
+
_runtime_cgo_panic_internal(a.cstr)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
//go:cgo_import_static x_cgo_init
|
| 51 |
+
//go:linkname x_cgo_init x_cgo_init
|
| 52 |
+
//go:linkname _cgo_init _cgo_init
|
| 53 |
+
var x_cgo_init byte
|
| 54 |
+
var _cgo_init = &x_cgo_init
|
| 55 |
+
|
| 56 |
+
//go:cgo_import_static x_cgo_thread_start
|
| 57 |
+
//go:linkname x_cgo_thread_start x_cgo_thread_start
|
| 58 |
+
//go:linkname _cgo_thread_start _cgo_thread_start
|
| 59 |
+
var x_cgo_thread_start byte
|
| 60 |
+
var _cgo_thread_start = &x_cgo_thread_start
|
| 61 |
+
|
| 62 |
+
// Creates a new system thread without updating any Go state.
|
| 63 |
+
//
|
| 64 |
+
// This method is invoked during shared library loading to create a new OS
|
| 65 |
+
// thread to perform the runtime initialization. This method is similar to
|
| 66 |
+
// _cgo_sys_thread_start except that it doesn't update any Go state.
|
| 67 |
+
|
| 68 |
+
//go:cgo_import_static x_cgo_sys_thread_create
|
| 69 |
+
//go:linkname x_cgo_sys_thread_create x_cgo_sys_thread_create
|
| 70 |
+
//go:linkname _cgo_sys_thread_create _cgo_sys_thread_create
|
| 71 |
+
var x_cgo_sys_thread_create byte
|
| 72 |
+
var _cgo_sys_thread_create = &x_cgo_sys_thread_create
|
| 73 |
+
|
| 74 |
+
// Indicates whether a dummy thread key has been created or not.
|
| 75 |
+
//
|
| 76 |
+
// When calling go exported function from C, we register a destructor
|
| 77 |
+
// callback, for a dummy thread key, by using pthread_key_create.
|
| 78 |
+
|
| 79 |
+
//go:cgo_import_static x_cgo_pthread_key_created
|
| 80 |
+
//go:linkname x_cgo_pthread_key_created x_cgo_pthread_key_created
|
| 81 |
+
//go:linkname _cgo_pthread_key_created _cgo_pthread_key_created
|
| 82 |
+
var x_cgo_pthread_key_created byte
|
| 83 |
+
var _cgo_pthread_key_created = &x_cgo_pthread_key_created
|
| 84 |
+
|
| 85 |
+
// Export crosscall2 to a c function pointer variable.
|
| 86 |
+
// Used to dropm in pthread key destructor, while C thread is exiting.
|
| 87 |
+
|
| 88 |
+
//go:cgo_import_static x_crosscall2_ptr
|
| 89 |
+
//go:linkname x_crosscall2_ptr x_crosscall2_ptr
|
| 90 |
+
//go:linkname _crosscall2_ptr _crosscall2_ptr
|
| 91 |
+
var x_crosscall2_ptr byte
|
| 92 |
+
var _crosscall2_ptr = &x_crosscall2_ptr
|
| 93 |
+
|
| 94 |
+
// Set the x_crosscall2_ptr C function pointer variable point to crosscall2.
|
| 95 |
+
// It's for the runtime package to call at init time.
|
| 96 |
+
func set_crosscall2()
|
| 97 |
+
|
| 98 |
+
//go:linkname _set_crosscall2 runtime.set_crosscall2
|
| 99 |
+
var _set_crosscall2 = set_crosscall2
|
| 100 |
+
|
| 101 |
+
// Store the g into the thread-specific value.
|
| 102 |
+
// So that pthread_key_destructor will dropm when the thread is exiting.
|
| 103 |
+
|
| 104 |
+
//go:cgo_import_static x_cgo_bindm
|
| 105 |
+
//go:linkname x_cgo_bindm x_cgo_bindm
|
| 106 |
+
//go:linkname _cgo_bindm _cgo_bindm
|
| 107 |
+
var x_cgo_bindm byte
|
| 108 |
+
var _cgo_bindm = &x_cgo_bindm
|
| 109 |
+
|
| 110 |
+
// Notifies that the runtime has been initialized.
|
| 111 |
+
//
|
| 112 |
+
// We currently block at every CGO entry point (via _cgo_wait_runtime_init_done)
|
| 113 |
+
// to ensure that the runtime has been initialized before the CGO call is
|
| 114 |
+
// executed. This is necessary for shared libraries where we kickoff runtime
|
| 115 |
+
// initialization in a separate thread and return without waiting for this
|
| 116 |
+
// thread to complete the init.
|
| 117 |
+
|
| 118 |
+
//go:cgo_import_static x_cgo_notify_runtime_init_done
|
| 119 |
+
//go:linkname x_cgo_notify_runtime_init_done x_cgo_notify_runtime_init_done
|
| 120 |
+
//go:linkname _cgo_notify_runtime_init_done _cgo_notify_runtime_init_done
|
| 121 |
+
var x_cgo_notify_runtime_init_done byte
|
| 122 |
+
var _cgo_notify_runtime_init_done = &x_cgo_notify_runtime_init_done
|
| 123 |
+
|
| 124 |
+
// Sets the traceback, context, and symbolizer functions. See
|
| 125 |
+
// runtime.SetCgoTraceback.
|
| 126 |
+
|
| 127 |
+
//go:cgo_import_static x_cgo_set_traceback_functions
|
| 128 |
+
//go:linkname x_cgo_set_traceback_functions x_cgo_set_traceback_functions
|
| 129 |
+
//go:linkname _cgo_set_traceback_functions _cgo_set_traceback_functions
|
| 130 |
+
var x_cgo_set_traceback_functions byte
|
| 131 |
+
var _cgo_set_traceback_functions = &x_cgo_set_traceback_functions
|
| 132 |
+
|
| 133 |
+
// Call the traceback function registered with x_cgo_set_traceback_functions.
|
| 134 |
+
|
| 135 |
+
//go:cgo_import_static x_cgo_call_traceback_function
|
| 136 |
+
//go:linkname x_cgo_call_traceback_function x_cgo_call_traceback_function
|
| 137 |
+
//go:linkname _cgo_call_traceback_function _cgo_call_traceback_function
|
| 138 |
+
var x_cgo_call_traceback_function byte
|
| 139 |
+
var _cgo_call_traceback_function = &x_cgo_call_traceback_function
|
| 140 |
+
|
| 141 |
+
// Call the symbolizer function registered with x_cgo_set_symbolizer_functions.
|
| 142 |
+
|
| 143 |
+
//go:cgo_import_static x_cgo_call_symbolizer_function
|
| 144 |
+
//go:linkname x_cgo_call_symbolizer_function x_cgo_call_symbolizer_function
|
| 145 |
+
//go:linkname _cgo_call_symbolizer_function _cgo_call_symbolizer_function
|
| 146 |
+
var x_cgo_call_symbolizer_function byte
|
| 147 |
+
var _cgo_call_symbolizer_function = &x_cgo_call_symbolizer_function
|
| 148 |
+
|
| 149 |
+
// Calls a libc function to execute background work injected via libc
|
| 150 |
+
// interceptors, such as processing pending signals under the thread
|
| 151 |
+
// sanitizer.
|
| 152 |
+
//
|
| 153 |
+
// Left as a nil pointer if no libc interceptors are expected.
|
| 154 |
+
|
| 155 |
+
//go:cgo_import_static _cgo_yield
|
| 156 |
+
//go:linkname _cgo_yield _cgo_yield
|
| 157 |
+
var _cgo_yield unsafe.Pointer
|
| 158 |
+
|
| 159 |
+
//go:cgo_export_static _cgo_topofstack
|
| 160 |
+
//go:cgo_export_dynamic _cgo_topofstack
|
| 161 |
+
|
| 162 |
+
// x_cgo_getstackbound gets the thread's C stack size and
|
| 163 |
+
// set the G's stack bound based on the stack size.
|
| 164 |
+
|
| 165 |
+
//go:cgo_import_static x_cgo_getstackbound
|
| 166 |
+
//go:linkname x_cgo_getstackbound x_cgo_getstackbound
|
| 167 |
+
//go:linkname _cgo_getstackbound _cgo_getstackbound
|
| 168 |
+
var x_cgo_getstackbound byte
|
| 169 |
+
var _cgo_getstackbound = &x_cgo_getstackbound
|
go/src/runtime/cgo/callbacks_aix.go
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
package cgo
|
| 6 |
+
|
| 7 |
+
// These functions must be exported in order to perform
|
| 8 |
+
// longcall on cgo programs (cf gcc_aix_ppc64.c).
|
| 9 |
+
//
|
| 10 |
+
//go:cgo_export_static __cgo_topofstack
|
| 11 |
+
//go:cgo_export_static runtime.rt0_go
|
| 12 |
+
//go:cgo_export_static _rt0_ppc64_aix_lib
|
go/src/runtime/cgo/callbacks_traceback.go
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build darwin || linux
|
| 6 |
+
|
| 7 |
+
package cgo
|
| 8 |
+
|
| 9 |
+
import _ "unsafe" // for go:linkname
|
| 10 |
+
|
| 11 |
+
// Calls the traceback function passed to SetCgoTraceback.
|
| 12 |
+
|
| 13 |
+
//go:cgo_import_static x_cgo_callers
|
| 14 |
+
//go:linkname x_cgo_callers x_cgo_callers
|
| 15 |
+
//go:linkname _cgo_callers _cgo_callers
|
| 16 |
+
var x_cgo_callers byte
|
| 17 |
+
var _cgo_callers = &x_cgo_callers
|
go/src/runtime/cgo/cgo.go
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
/*
|
| 6 |
+
Package cgo contains runtime support for code generated
|
| 7 |
+
by the cgo tool. See the documentation for the cgo command
|
| 8 |
+
for details on using cgo.
|
| 9 |
+
*/
|
| 10 |
+
package cgo
|
| 11 |
+
|
| 12 |
+
/*
|
| 13 |
+
|
| 14 |
+
#cgo darwin,!arm64 LDFLAGS: -lpthread
|
| 15 |
+
#cgo darwin,arm64 LDFLAGS: -framework CoreFoundation
|
| 16 |
+
#cgo dragonfly LDFLAGS: -lpthread
|
| 17 |
+
#cgo freebsd LDFLAGS: -lpthread
|
| 18 |
+
#cgo android LDFLAGS: -llog
|
| 19 |
+
#cgo !android,linux LDFLAGS: -lpthread
|
| 20 |
+
#cgo netbsd LDFLAGS: -lpthread
|
| 21 |
+
#cgo openbsd LDFLAGS: -lpthread
|
| 22 |
+
#cgo aix LDFLAGS: -Wl,-berok
|
| 23 |
+
#cgo solaris LDFLAGS: -lxnet
|
| 24 |
+
#cgo solaris LDFLAGS: -lsocket
|
| 25 |
+
|
| 26 |
+
// Use -fno-stack-protector to avoid problems locating the
|
| 27 |
+
// proper support functions. See issues #52919, #54313, #58385.
|
| 28 |
+
// Use -Wdeclaration-after-statement because some CI builds use it.
|
| 29 |
+
#cgo CFLAGS: -Wall -Werror -fno-stack-protector -Wdeclaration-after-statement
|
| 30 |
+
|
| 31 |
+
#cgo solaris CPPFLAGS: -D_POSIX_PTHREAD_SEMANTICS
|
| 32 |
+
|
| 33 |
+
*/
|
| 34 |
+
import "C"
|
| 35 |
+
|
| 36 |
+
import "internal/runtime/sys"
|
| 37 |
+
|
| 38 |
+
// Incomplete is used specifically for the semantics of incomplete C types.
|
| 39 |
+
type Incomplete struct {
|
| 40 |
+
_ sys.NotInHeap
|
| 41 |
+
}
|
go/src/runtime/cgo/clearenv.go
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build linux
|
| 6 |
+
|
| 7 |
+
package cgo
|
| 8 |
+
|
| 9 |
+
import _ "unsafe" // for go:linkname
|
| 10 |
+
|
| 11 |
+
//go:cgo_import_static x_cgo_clearenv
|
| 12 |
+
//go:linkname x_cgo_clearenv x_cgo_clearenv
|
| 13 |
+
//go:linkname _cgo_clearenv runtime._cgo_clearenv
|
| 14 |
+
var x_cgo_clearenv byte
|
| 15 |
+
var _cgo_clearenv = &x_cgo_clearenv
|
go/src/runtime/cgo/dragonfly.go
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build dragonfly
|
| 6 |
+
|
| 7 |
+
package cgo
|
| 8 |
+
|
| 9 |
+
import _ "unsafe" // for go:linkname
|
| 10 |
+
|
| 11 |
+
// Supply environ and __progname, because we don't
|
| 12 |
+
// link against the standard DragonFly crt0.o and the
|
| 13 |
+
// libc dynamic library needs them.
|
| 14 |
+
|
| 15 |
+
//go:linkname _environ environ
|
| 16 |
+
//go:linkname _progname __progname
|
| 17 |
+
|
| 18 |
+
var _environ uintptr
|
| 19 |
+
var _progname uintptr
|
go/src/runtime/cgo/freebsd.go
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2010 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build freebsd
|
| 6 |
+
|
| 7 |
+
package cgo
|
| 8 |
+
|
| 9 |
+
import _ "unsafe" // for go:linkname
|
| 10 |
+
|
| 11 |
+
// Supply environ and __progname, because we don't
|
| 12 |
+
// link against the standard FreeBSD crt0.o and the
|
| 13 |
+
// libc dynamic library needs them.
|
| 14 |
+
|
| 15 |
+
//go:linkname _environ environ
|
| 16 |
+
//go:linkname _progname __progname
|
| 17 |
+
|
| 18 |
+
//go:cgo_export_dynamic environ
|
| 19 |
+
//go:cgo_export_dynamic __progname
|
| 20 |
+
|
| 21 |
+
var _environ uintptr
|
| 22 |
+
var _progname uintptr
|
go/src/runtime/cgo/gcc_386.S
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_386.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Windows still insists on underscore prefixes for C function names.
|
| 9 |
+
*/
|
| 10 |
+
#if defined(_WIN32)
|
| 11 |
+
#define EXT(s) _##s
|
| 12 |
+
#else
|
| 13 |
+
#define EXT(s) s
|
| 14 |
+
#endif
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g)
|
| 18 |
+
*
|
| 19 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 20 |
+
* Called from standard x86 ABI, where %ebp, %ebx, %esi,
|
| 21 |
+
* and %edi are callee-save, so they must be saved explicitly.
|
| 22 |
+
*/
|
| 23 |
+
.globl EXT(crosscall1)
|
| 24 |
+
EXT(crosscall1):
|
| 25 |
+
pushl %ebp
|
| 26 |
+
movl %esp, %ebp
|
| 27 |
+
pushl %ebx
|
| 28 |
+
pushl %esi
|
| 29 |
+
pushl %edi
|
| 30 |
+
|
| 31 |
+
movl 16(%ebp), %eax /* g */
|
| 32 |
+
pushl %eax
|
| 33 |
+
movl 12(%ebp), %eax /* setg_gcc */
|
| 34 |
+
call *%eax
|
| 35 |
+
popl %eax
|
| 36 |
+
|
| 37 |
+
movl 8(%ebp), %eax /* fn */
|
| 38 |
+
call *%eax
|
| 39 |
+
|
| 40 |
+
popl %edi
|
| 41 |
+
popl %esi
|
| 42 |
+
popl %ebx
|
| 43 |
+
popl %ebp
|
| 44 |
+
ret
|
| 45 |
+
|
| 46 |
+
#ifdef __ELF__
|
| 47 |
+
.section .note.GNU-stack,"",@progbits
|
| 48 |
+
#endif
|
go/src/runtime/cgo/gcc_aix_ppc64.S
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_aix_ppc64.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* void crosscall_ppc64(void (*fn)(void), void *g)
|
| 9 |
+
*
|
| 10 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 11 |
+
* Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
|
| 12 |
+
* callee-save, so they must be saved explicitly.
|
| 13 |
+
* AIX has a special assembly syntax and keywords that can be mixed with
|
| 14 |
+
* Linux assembly.
|
| 15 |
+
*/
|
| 16 |
+
.toc
|
| 17 |
+
.csect .text[PR]
|
| 18 |
+
.globl crosscall_ppc64
|
| 19 |
+
.globl .crosscall_ppc64
|
| 20 |
+
.csect crosscall_ppc64[DS]
|
| 21 |
+
crosscall_ppc64:
|
| 22 |
+
.llong .crosscall_ppc64, TOC[tc0], 0
|
| 23 |
+
.csect .text[PR]
|
| 24 |
+
.crosscall_ppc64:
|
| 25 |
+
// Start with standard C stack frame layout and linkage
|
| 26 |
+
mflr 0
|
| 27 |
+
std 0, 16(1) // Save LR in caller's frame
|
| 28 |
+
std 2, 40(1) // Save TOC in caller's frame
|
| 29 |
+
bl saveregs
|
| 30 |
+
stdu 1, -296(1)
|
| 31 |
+
|
| 32 |
+
// Set up Go ABI constant registers
|
| 33 |
+
// Must match _cgo_reginit in runtime package.
|
| 34 |
+
xor 0, 0, 0
|
| 35 |
+
|
| 36 |
+
// Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
|
| 37 |
+
mr 30, 4
|
| 38 |
+
|
| 39 |
+
// Call fn
|
| 40 |
+
mr 12, 3
|
| 41 |
+
mtctr 12
|
| 42 |
+
bctrl
|
| 43 |
+
|
| 44 |
+
addi 1, 1, 296
|
| 45 |
+
bl restoreregs
|
| 46 |
+
ld 2, 40(1)
|
| 47 |
+
ld 0, 16(1)
|
| 48 |
+
mtlr 0
|
| 49 |
+
blr
|
| 50 |
+
|
| 51 |
+
saveregs:
|
| 52 |
+
// Save callee-save registers
|
| 53 |
+
// O=-288; for R in {14..31}; do echo "\tstd\t$R, $O(1)"; ((O+=8)); done; for F in f{14..31}; do echo "\tstfd\t$F, $O(1)"; ((O+=8)); done
|
| 54 |
+
std 14, -288(1)
|
| 55 |
+
std 15, -280(1)
|
| 56 |
+
std 16, -272(1)
|
| 57 |
+
std 17, -264(1)
|
| 58 |
+
std 18, -256(1)
|
| 59 |
+
std 19, -248(1)
|
| 60 |
+
std 20, -240(1)
|
| 61 |
+
std 21, -232(1)
|
| 62 |
+
std 22, -224(1)
|
| 63 |
+
std 23, -216(1)
|
| 64 |
+
std 24, -208(1)
|
| 65 |
+
std 25, -200(1)
|
| 66 |
+
std 26, -192(1)
|
| 67 |
+
std 27, -184(1)
|
| 68 |
+
std 28, -176(1)
|
| 69 |
+
std 29, -168(1)
|
| 70 |
+
std 30, -160(1)
|
| 71 |
+
std 31, -152(1)
|
| 72 |
+
stfd 14, -144(1)
|
| 73 |
+
stfd 15, -136(1)
|
| 74 |
+
stfd 16, -128(1)
|
| 75 |
+
stfd 17, -120(1)
|
| 76 |
+
stfd 18, -112(1)
|
| 77 |
+
stfd 19, -104(1)
|
| 78 |
+
stfd 20, -96(1)
|
| 79 |
+
stfd 21, -88(1)
|
| 80 |
+
stfd 22, -80(1)
|
| 81 |
+
stfd 23, -72(1)
|
| 82 |
+
stfd 24, -64(1)
|
| 83 |
+
stfd 25, -56(1)
|
| 84 |
+
stfd 26, -48(1)
|
| 85 |
+
stfd 27, -40(1)
|
| 86 |
+
stfd 28, -32(1)
|
| 87 |
+
stfd 29, -24(1)
|
| 88 |
+
stfd 30, -16(1)
|
| 89 |
+
stfd 31, -8(1)
|
| 90 |
+
|
| 91 |
+
blr
|
| 92 |
+
|
| 93 |
+
restoreregs:
|
| 94 |
+
// O=-288; for R in {14..31}; do echo "\tld\t$R, $O(1)"; ((O+=8)); done; for F in {14..31}; do echo "\tlfd\t$F, $O(1)"; ((O+=8)); done
|
| 95 |
+
ld 14, -288(1)
|
| 96 |
+
ld 15, -280(1)
|
| 97 |
+
ld 16, -272(1)
|
| 98 |
+
ld 17, -264(1)
|
| 99 |
+
ld 18, -256(1)
|
| 100 |
+
ld 19, -248(1)
|
| 101 |
+
ld 20, -240(1)
|
| 102 |
+
ld 21, -232(1)
|
| 103 |
+
ld 22, -224(1)
|
| 104 |
+
ld 23, -216(1)
|
| 105 |
+
ld 24, -208(1)
|
| 106 |
+
ld 25, -200(1)
|
| 107 |
+
ld 26, -192(1)
|
| 108 |
+
ld 27, -184(1)
|
| 109 |
+
ld 28, -176(1)
|
| 110 |
+
ld 29, -168(1)
|
| 111 |
+
ld 30, -160(1)
|
| 112 |
+
ld 31, -152(1)
|
| 113 |
+
lfd 14, -144(1)
|
| 114 |
+
lfd 15, -136(1)
|
| 115 |
+
lfd 16, -128(1)
|
| 116 |
+
lfd 17, -120(1)
|
| 117 |
+
lfd 18, -112(1)
|
| 118 |
+
lfd 19, -104(1)
|
| 119 |
+
lfd 20, -96(1)
|
| 120 |
+
lfd 21, -88(1)
|
| 121 |
+
lfd 22, -80(1)
|
| 122 |
+
lfd 23, -72(1)
|
| 123 |
+
lfd 24, -64(1)
|
| 124 |
+
lfd 25, -56(1)
|
| 125 |
+
lfd 26, -48(1)
|
| 126 |
+
lfd 27, -40(1)
|
| 127 |
+
lfd 28, -32(1)
|
| 128 |
+
lfd 29, -24(1)
|
| 129 |
+
lfd 30, -16(1)
|
| 130 |
+
lfd 31, -8(1)
|
| 131 |
+
|
| 132 |
+
blr
|
go/src/runtime/cgo/gcc_aix_ppc64.c
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2019 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
/*
|
| 6 |
+
* On AIX, call to _cgo_topofstack and Go main are forced to be a longcall.
|
| 7 |
+
* Without it, ld might add trampolines in the middle of .text section
|
| 8 |
+
* to reach these functions which are normally declared in runtime package.
|
| 9 |
+
*/
|
| 10 |
+
extern int __attribute__((longcall)) __cgo_topofstack(void);
|
| 11 |
+
extern int __attribute__((longcall)) runtime_rt0_go(int argc, char **argv);
|
| 12 |
+
extern void __attribute__((longcall)) _rt0_ppc64_aix_lib(void);
|
| 13 |
+
|
| 14 |
+
int _cgo_topofstack(void) {
|
| 15 |
+
return __cgo_topofstack();
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
int main(int argc, char **argv) {
|
| 19 |
+
return runtime_rt0_go(argc, argv);
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
static void libinit(void) __attribute__ ((constructor));
|
| 23 |
+
|
| 24 |
+
/*
|
| 25 |
+
* libinit aims to replace .init_array section which isn't available on aix.
|
| 26 |
+
* Using __attribute__ ((constructor)) let gcc handles this instead of
|
| 27 |
+
* adding special code in cmd/link.
|
| 28 |
+
* However, it will be called for every Go programs which has cgo.
|
| 29 |
+
* Inside _rt0_ppc64_aix_lib(), runtime.isarchive is checked in order
|
| 30 |
+
* to know if this program is a c-archive or a simple cgo program.
|
| 31 |
+
* If it's not set, _rt0_ppc64_ax_lib() returns directly.
|
| 32 |
+
*/
|
| 33 |
+
static void libinit() {
|
| 34 |
+
_rt0_ppc64_aix_lib();
|
| 35 |
+
}
|
go/src/runtime/cgo/gcc_amd64.S
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_amd64.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Apple still insists on underscore prefixes for C function names.
|
| 9 |
+
*/
|
| 10 |
+
#if defined(__APPLE__)
|
| 11 |
+
#define EXT(s) _##s
|
| 12 |
+
#else
|
| 13 |
+
#define EXT(s) s
|
| 14 |
+
#endif
|
| 15 |
+
|
| 16 |
+
/*
|
| 17 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g)
|
| 18 |
+
*
|
| 19 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 20 |
+
* Called from standard x86-64 ABI, where %rbx, %rbp, %r12-%r15
|
| 21 |
+
* are callee-save so they must be saved explicitly.
|
| 22 |
+
* The standard x86-64 ABI passes the three arguments m, g, fn
|
| 23 |
+
* in %rdi, %rsi, %rdx.
|
| 24 |
+
*/
|
| 25 |
+
.globl EXT(crosscall1)
|
| 26 |
+
EXT(crosscall1):
|
| 27 |
+
pushq %rbx
|
| 28 |
+
pushq %rbp
|
| 29 |
+
pushq %r12
|
| 30 |
+
pushq %r13
|
| 31 |
+
pushq %r14
|
| 32 |
+
pushq %r15
|
| 33 |
+
|
| 34 |
+
#if defined(_WIN64)
|
| 35 |
+
movq %r8, %rdi /* arg of setg_gcc */
|
| 36 |
+
call *%rdx /* setg_gcc */
|
| 37 |
+
call *%rcx /* fn */
|
| 38 |
+
#else
|
| 39 |
+
movq %rdi, %rbx
|
| 40 |
+
movq %rdx, %rdi /* arg of setg_gcc */
|
| 41 |
+
call *%rsi /* setg_gcc */
|
| 42 |
+
call *%rbx /* fn */
|
| 43 |
+
#endif
|
| 44 |
+
|
| 45 |
+
popq %r15
|
| 46 |
+
popq %r14
|
| 47 |
+
popq %r13
|
| 48 |
+
popq %r12
|
| 49 |
+
popq %rbp
|
| 50 |
+
popq %rbx
|
| 51 |
+
ret
|
| 52 |
+
|
| 53 |
+
#ifdef __ELF__
|
| 54 |
+
.section .note.GNU-stack,"",@progbits
|
| 55 |
+
#endif
|
go/src/runtime/cgo/gcc_android.c
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <stdarg.h>
|
| 6 |
+
#include <android/log.h>
|
| 7 |
+
#include <pthread.h>
|
| 8 |
+
#include <dlfcn.h>
|
| 9 |
+
#include "libcgo.h"
|
| 10 |
+
|
| 11 |
+
void
|
| 12 |
+
fatalf(const char* format, ...)
|
| 13 |
+
{
|
| 14 |
+
va_list ap;
|
| 15 |
+
|
| 16 |
+
// Write to both stderr and logcat.
|
| 17 |
+
//
|
| 18 |
+
// When running from an .apk, /dev/stderr and /dev/stdout
|
| 19 |
+
// redirect to /dev/null. And when running a test binary
|
| 20 |
+
// via adb shell, it's easy to miss logcat.
|
| 21 |
+
|
| 22 |
+
fprintf(stderr, "runtime/cgo: ");
|
| 23 |
+
va_start(ap, format);
|
| 24 |
+
vfprintf(stderr, format, ap);
|
| 25 |
+
va_end(ap);
|
| 26 |
+
fprintf(stderr, "\n");
|
| 27 |
+
|
| 28 |
+
va_start(ap, format);
|
| 29 |
+
__android_log_vprint(ANDROID_LOG_FATAL, "runtime/cgo", format, ap);
|
| 30 |
+
va_end(ap);
|
| 31 |
+
|
| 32 |
+
abort();
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
// Truncated to a different magic value on 32-bit; that's ok.
|
| 36 |
+
#define magic1 (0x23581321345589ULL)
|
| 37 |
+
|
| 38 |
+
// From https://android.googlesource.com/platform/bionic/+/refs/heads/android10-tests-release/libc/private/bionic_asm_tls.h#69.
|
| 39 |
+
#define TLS_SLOT_APP 2
|
| 40 |
+
|
| 41 |
+
// inittls allocates a thread-local storage slot for g.
|
| 42 |
+
//
|
| 43 |
+
// It finds the first available slot using pthread_key_create and uses
|
| 44 |
+
// it as the offset value for runtime.tls_g.
|
| 45 |
+
static void
|
| 46 |
+
inittls(void **tlsg, void **tlsbase)
|
| 47 |
+
{
|
| 48 |
+
pthread_key_t k;
|
| 49 |
+
int i, err;
|
| 50 |
+
void *handle, *get_ver, *off;
|
| 51 |
+
|
| 52 |
+
// Check for Android Q where we can use the free TLS_SLOT_APP slot.
|
| 53 |
+
handle = dlopen("libc.so", RTLD_LAZY);
|
| 54 |
+
if (handle == NULL) {
|
| 55 |
+
fatalf("inittls: failed to dlopen main program");
|
| 56 |
+
return;
|
| 57 |
+
}
|
| 58 |
+
// android_get_device_api_level is introduced in Android Q, so its mere presence
|
| 59 |
+
// is enough.
|
| 60 |
+
get_ver = dlsym(handle, "android_get_device_api_level");
|
| 61 |
+
dlclose(handle);
|
| 62 |
+
if (get_ver != NULL) {
|
| 63 |
+
off = (void *)(TLS_SLOT_APP*sizeof(void *));
|
| 64 |
+
// tlsg is initialized to Q's free TLS slot. Verify it while we're here.
|
| 65 |
+
if (*tlsg != off) {
|
| 66 |
+
fatalf("tlsg offset wrong, got %ld want %ld\n", *tlsg, off);
|
| 67 |
+
}
|
| 68 |
+
return;
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
err = pthread_key_create(&k, nil);
|
| 72 |
+
if(err != 0) {
|
| 73 |
+
fatalf("pthread_key_create failed: %d", err);
|
| 74 |
+
}
|
| 75 |
+
pthread_setspecific(k, (void*)magic1);
|
| 76 |
+
// If thread local slots are laid out as we expect, our magic word will
|
| 77 |
+
// be located at some low offset from tlsbase. However, just in case something went
|
| 78 |
+
// wrong, the search is limited to sensible offsets. PTHREAD_KEYS_MAX was the
|
| 79 |
+
// original limit, but issue 19472 made a higher limit necessary.
|
| 80 |
+
for (i=0; i<384; i++) {
|
| 81 |
+
if (*(tlsbase+i) == (void*)magic1) {
|
| 82 |
+
*tlsg = (void*)(i*sizeof(void *));
|
| 83 |
+
pthread_setspecific(k, 0);
|
| 84 |
+
return;
|
| 85 |
+
}
|
| 86 |
+
}
|
| 87 |
+
fatalf("inittls: could not find pthread key");
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase) = inittls;
|
go/src/runtime/cgo/gcc_arm.S
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2012 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_arm.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
|
| 9 |
+
*
|
| 10 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 11 |
+
* Called from standard ARM EABI, where r4-r11 are callee-save, so they
|
| 12 |
+
* must be saved explicitly.
|
| 13 |
+
*/
|
| 14 |
+
.globl crosscall1
|
| 15 |
+
crosscall1:
|
| 16 |
+
push {r4, r5, r6, r7, r8, r9, r10, r11, ip, lr}
|
| 17 |
+
mov r4, r0
|
| 18 |
+
mov r5, r1
|
| 19 |
+
mov r0, r2
|
| 20 |
+
|
| 21 |
+
// Because the assembler might target an earlier revision of the ISA
|
| 22 |
+
// by default, we encode BLX as a .word.
|
| 23 |
+
.word 0xe12fff35 // blx r5 // setg(g)
|
| 24 |
+
.word 0xe12fff34 // blx r4 // fn()
|
| 25 |
+
|
| 26 |
+
pop {r4, r5, r6, r7, r8, r9, r10, r11, ip, pc}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
#ifdef __ELF__
|
| 30 |
+
.section .note.GNU-stack,"",%progbits
|
| 31 |
+
#endif
|
go/src/runtime/cgo/gcc_arm64.S
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_arm64.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* Apple still insists on underscore prefixes for C function names.
|
| 9 |
+
*/
|
| 10 |
+
#if defined(__APPLE__)
|
| 11 |
+
#define EXT(s) _##s
|
| 12 |
+
#else
|
| 13 |
+
#define EXT(s) s
|
| 14 |
+
#endif
|
| 15 |
+
|
| 16 |
+
// Apple's ld64 wants 4-byte alignment for ARM code sections.
|
| 17 |
+
// .align in both Apple as and GNU as treat n as aligning to 2**n bytes.
|
| 18 |
+
.align 2
|
| 19 |
+
|
| 20 |
+
/*
|
| 21 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
|
| 22 |
+
*
|
| 23 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 24 |
+
* Called from standard ARM EABI, where x19-x29 are callee-save, so they
|
| 25 |
+
* must be saved explicitly, along with x30 (LR).
|
| 26 |
+
*/
|
| 27 |
+
.globl EXT(crosscall1)
|
| 28 |
+
EXT(crosscall1):
|
| 29 |
+
.cfi_startproc
|
| 30 |
+
stp x29, x30, [sp, #-96]!
|
| 31 |
+
.cfi_def_cfa_offset 96
|
| 32 |
+
.cfi_offset 29, -96
|
| 33 |
+
.cfi_offset 30, -88
|
| 34 |
+
mov x29, sp
|
| 35 |
+
.cfi_def_cfa_register 29
|
| 36 |
+
stp x19, x20, [sp, #80]
|
| 37 |
+
.cfi_offset 19, -16
|
| 38 |
+
.cfi_offset 20, -8
|
| 39 |
+
stp x21, x22, [sp, #64]
|
| 40 |
+
.cfi_offset 21, -32
|
| 41 |
+
.cfi_offset 22, -24
|
| 42 |
+
stp x23, x24, [sp, #48]
|
| 43 |
+
.cfi_offset 23, -48
|
| 44 |
+
.cfi_offset 24, -40
|
| 45 |
+
stp x25, x26, [sp, #32]
|
| 46 |
+
.cfi_offset 25, -64
|
| 47 |
+
.cfi_offset 26, -56
|
| 48 |
+
stp x27, x28, [sp, #16]
|
| 49 |
+
.cfi_offset 27, -80
|
| 50 |
+
.cfi_offset 28, -72
|
| 51 |
+
|
| 52 |
+
mov x19, x0
|
| 53 |
+
mov x20, x1
|
| 54 |
+
mov x0, x2
|
| 55 |
+
|
| 56 |
+
blr x20
|
| 57 |
+
blr x19
|
| 58 |
+
|
| 59 |
+
ldp x27, x28, [sp, #16]
|
| 60 |
+
.cfi_restore 27
|
| 61 |
+
.cfi_restore 28
|
| 62 |
+
ldp x25, x26, [sp, #32]
|
| 63 |
+
.cfi_restore 25
|
| 64 |
+
.cfi_restore 26
|
| 65 |
+
ldp x23, x24, [sp, #48]
|
| 66 |
+
.cfi_restore 23
|
| 67 |
+
.cfi_restore 24
|
| 68 |
+
ldp x21, x22, [sp, #64]
|
| 69 |
+
.cfi_restore 21
|
| 70 |
+
.cfi_restore 22
|
| 71 |
+
ldp x19, x20, [sp, #80]
|
| 72 |
+
.cfi_restore 19
|
| 73 |
+
.cfi_restore 20
|
| 74 |
+
ldp x29, x30, [sp], #96
|
| 75 |
+
.cfi_restore 29
|
| 76 |
+
.cfi_restore 30
|
| 77 |
+
.cfi_def_cfa 31, 0
|
| 78 |
+
ret
|
| 79 |
+
.cfi_endproc
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
#ifdef __ELF__
|
| 83 |
+
.section .note.GNU-stack,"",%progbits
|
| 84 |
+
#endif
|
go/src/runtime/cgo/gcc_clearenv.c
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2025 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build linux
|
| 6 |
+
|
| 7 |
+
#include "libcgo.h"
|
| 8 |
+
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
|
| 11 |
+
/* Stub for calling clearenv */
|
| 12 |
+
void
|
| 13 |
+
x_cgo_clearenv(void **_unused)
|
| 14 |
+
{
|
| 15 |
+
_cgo_tsan_acquire();
|
| 16 |
+
clearenv();
|
| 17 |
+
_cgo_tsan_release();
|
| 18 |
+
}
|
go/src/runtime/cgo/gcc_context.c
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build unix || windows
|
| 6 |
+
|
| 7 |
+
#include "libcgo.h"
|
| 8 |
+
|
| 9 |
+
// Releases the cgo traceback context.
|
| 10 |
+
void _cgo_release_context(uintptr_t ctxt) {
|
| 11 |
+
void (*pfn)(struct cgoContextArg*);
|
| 12 |
+
|
| 13 |
+
pfn = _cgo_get_context_function();
|
| 14 |
+
if (ctxt != 0 && pfn != nil) {
|
| 15 |
+
struct cgoContextArg arg;
|
| 16 |
+
|
| 17 |
+
arg.Context = ctxt;
|
| 18 |
+
(*pfn)(&arg);
|
| 19 |
+
}
|
| 20 |
+
}
|
go/src/runtime/cgo/gcc_darwin_amd64.c
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <string.h> /* for strerror */
|
| 6 |
+
#include <pthread.h>
|
| 7 |
+
#include <signal.h>
|
| 8 |
+
#include "libcgo.h"
|
| 9 |
+
#include "libcgo_unix.h"
|
| 10 |
+
|
| 11 |
+
static void* threadentry(void*);
|
| 12 |
+
static void (*setg_gcc)(void*);
|
| 13 |
+
|
| 14 |
+
void
|
| 15 |
+
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
| 16 |
+
{
|
| 17 |
+
setg_gcc = setg;
|
| 18 |
+
_cgo_set_stacklo(g, NULL);
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
void
|
| 23 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 24 |
+
{
|
| 25 |
+
pthread_attr_t attr;
|
| 26 |
+
sigset_t ign, oset;
|
| 27 |
+
pthread_t p;
|
| 28 |
+
size_t size;
|
| 29 |
+
int err;
|
| 30 |
+
|
| 31 |
+
sigfillset(&ign);
|
| 32 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 33 |
+
|
| 34 |
+
size = pthread_get_stacksize_np(pthread_self());
|
| 35 |
+
pthread_attr_init(&attr);
|
| 36 |
+
pthread_attr_setstacksize(&attr, size);
|
| 37 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 38 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 39 |
+
ts->g->stackhi = size;
|
| 40 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 41 |
+
|
| 42 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 43 |
+
|
| 44 |
+
if (err != 0) {
|
| 45 |
+
fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
|
| 46 |
+
abort();
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 51 |
+
static void*
|
| 52 |
+
threadentry(void *v)
|
| 53 |
+
{
|
| 54 |
+
ThreadStart ts;
|
| 55 |
+
|
| 56 |
+
ts = *(ThreadStart*)v;
|
| 57 |
+
free(v);
|
| 58 |
+
|
| 59 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 60 |
+
return nil;
|
| 61 |
+
}
|
go/src/runtime/cgo/gcc_darwin_arm64.c
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <limits.h>
|
| 6 |
+
#include <pthread.h>
|
| 7 |
+
#include <signal.h>
|
| 8 |
+
#include <string.h> /* for strerror */
|
| 9 |
+
#include <sys/param.h>
|
| 10 |
+
#include <unistd.h>
|
| 11 |
+
#include <stdlib.h>
|
| 12 |
+
|
| 13 |
+
#include "libcgo.h"
|
| 14 |
+
#include "libcgo_unix.h"
|
| 15 |
+
|
| 16 |
+
#include <TargetConditionals.h>
|
| 17 |
+
|
| 18 |
+
#if TARGET_OS_IPHONE
|
| 19 |
+
#include <CoreFoundation/CFBundle.h>
|
| 20 |
+
#include <CoreFoundation/CFString.h>
|
| 21 |
+
#endif
|
| 22 |
+
|
| 23 |
+
static void *threadentry(void*);
|
| 24 |
+
static void (*setg_gcc)(void*);
|
| 25 |
+
|
| 26 |
+
void
|
| 27 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 28 |
+
{
|
| 29 |
+
pthread_attr_t attr;
|
| 30 |
+
sigset_t ign, oset;
|
| 31 |
+
pthread_t p;
|
| 32 |
+
size_t size;
|
| 33 |
+
int err;
|
| 34 |
+
|
| 35 |
+
//fprintf(stderr, "runtime/cgo: _cgo_sys_thread_start: fn=%p, g=%p\n", ts->fn, ts->g); // debug
|
| 36 |
+
sigfillset(&ign);
|
| 37 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 38 |
+
|
| 39 |
+
size = pthread_get_stacksize_np(pthread_self());
|
| 40 |
+
pthread_attr_init(&attr);
|
| 41 |
+
pthread_attr_setstacksize(&attr, size);
|
| 42 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 43 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 44 |
+
ts->g->stackhi = size;
|
| 45 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 46 |
+
|
| 47 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 48 |
+
|
| 49 |
+
if (err != 0) {
|
| 50 |
+
fprintf(stderr, "runtime/cgo: pthread_create failed: %s\n", strerror(err));
|
| 51 |
+
abort();
|
| 52 |
+
}
|
| 53 |
+
}
|
| 54 |
+
|
| 55 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 56 |
+
static void*
|
| 57 |
+
threadentry(void *v)
|
| 58 |
+
{
|
| 59 |
+
ThreadStart ts;
|
| 60 |
+
|
| 61 |
+
ts = *(ThreadStart*)v;
|
| 62 |
+
free(v);
|
| 63 |
+
|
| 64 |
+
#if TARGET_OS_IPHONE
|
| 65 |
+
darwin_arm_init_thread_exception_port();
|
| 66 |
+
#endif
|
| 67 |
+
|
| 68 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 69 |
+
return nil;
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
#if TARGET_OS_IPHONE
|
| 73 |
+
|
| 74 |
+
// init_working_dir sets the current working directory to the app root.
|
| 75 |
+
// By default ios/arm64 processes start in "/".
|
| 76 |
+
static void
|
| 77 |
+
init_working_dir()
|
| 78 |
+
{
|
| 79 |
+
CFBundleRef bundle;
|
| 80 |
+
CFURLRef url_ref;
|
| 81 |
+
CFStringRef url_str_ref;
|
| 82 |
+
char buf[MAXPATHLEN];
|
| 83 |
+
Boolean res;
|
| 84 |
+
int url_len;
|
| 85 |
+
char *dir;
|
| 86 |
+
CFStringRef wd_ref;
|
| 87 |
+
|
| 88 |
+
bundle = CFBundleGetMainBundle();
|
| 89 |
+
if (bundle == NULL) {
|
| 90 |
+
fprintf(stderr, "runtime/cgo: no main bundle\n");
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
url_ref = CFBundleCopyResourceURL(bundle, CFSTR("Info"), CFSTR("plist"), NULL);
|
| 94 |
+
if (url_ref == NULL) {
|
| 95 |
+
// No Info.plist found. It can happen on Corellium virtual devices.
|
| 96 |
+
return;
|
| 97 |
+
}
|
| 98 |
+
url_str_ref = CFURLGetString(url_ref);
|
| 99 |
+
res = CFStringGetCString(url_str_ref, buf, sizeof(buf), kCFStringEncodingUTF8);
|
| 100 |
+
CFRelease(url_ref);
|
| 101 |
+
if (!res) {
|
| 102 |
+
fprintf(stderr, "runtime/cgo: cannot get URL string\n");
|
| 103 |
+
return;
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
// url is of the form "file:///path/to/Info.plist".
|
| 107 |
+
// strip it down to the working directory "/path/to".
|
| 108 |
+
url_len = strlen(buf);
|
| 109 |
+
if (url_len < sizeof("file://")+sizeof("/Info.plist")) {
|
| 110 |
+
fprintf(stderr, "runtime/cgo: bad URL: %s\n", buf);
|
| 111 |
+
return;
|
| 112 |
+
}
|
| 113 |
+
buf[url_len-sizeof("/Info.plist")+1] = 0;
|
| 114 |
+
dir = &buf[0] + sizeof("file://")-1;
|
| 115 |
+
|
| 116 |
+
if (chdir(dir) != 0) {
|
| 117 |
+
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", dir);
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
// The test harness in go_ios_exec passes the relative working directory
|
| 121 |
+
// in the GoExecWrapperWorkingDirectory property of the app bundle.
|
| 122 |
+
wd_ref = CFBundleGetValueForInfoDictionaryKey(bundle, CFSTR("GoExecWrapperWorkingDirectory"));
|
| 123 |
+
if (wd_ref != NULL) {
|
| 124 |
+
if (!CFStringGetCString(wd_ref, buf, sizeof(buf), kCFStringEncodingUTF8)) {
|
| 125 |
+
fprintf(stderr, "runtime/cgo: cannot get GoExecWrapperWorkingDirectory string\n");
|
| 126 |
+
return;
|
| 127 |
+
}
|
| 128 |
+
if (chdir(buf) != 0) {
|
| 129 |
+
fprintf(stderr, "runtime/cgo: chdir(%s) failed\n", buf);
|
| 130 |
+
}
|
| 131 |
+
}
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
#endif // TARGET_OS_IPHONE
|
| 135 |
+
|
| 136 |
+
void
|
| 137 |
+
x_cgo_init(G *g, void (*setg)(void*))
|
| 138 |
+
{
|
| 139 |
+
//fprintf(stderr, "x_cgo_init = %p\n", &x_cgo_init); // aid debugging in presence of ASLR
|
| 140 |
+
setg_gcc = setg;
|
| 141 |
+
_cgo_set_stacklo(g, NULL);
|
| 142 |
+
|
| 143 |
+
#if TARGET_OS_IPHONE
|
| 144 |
+
darwin_arm_init_mach_exception_handler();
|
| 145 |
+
darwin_arm_init_thread_exception_port();
|
| 146 |
+
init_working_dir();
|
| 147 |
+
#endif
|
| 148 |
+
}
|
go/src/runtime/cgo/gcc_dragonfly_amd64.c
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <sys/types.h>
|
| 6 |
+
#include <sys/signalvar.h>
|
| 7 |
+
#include <pthread.h>
|
| 8 |
+
#include <signal.h>
|
| 9 |
+
#include <string.h>
|
| 10 |
+
#include "libcgo.h"
|
| 11 |
+
#include "libcgo_unix.h"
|
| 12 |
+
|
| 13 |
+
static void* threadentry(void*);
|
| 14 |
+
static void (*setg_gcc)(void*);
|
| 15 |
+
|
| 16 |
+
void
|
| 17 |
+
x_cgo_init(G *g, void (*setg)(void*))
|
| 18 |
+
{
|
| 19 |
+
setg_gcc = setg;
|
| 20 |
+
_cgo_set_stacklo(g, NULL);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void
|
| 24 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 25 |
+
{
|
| 26 |
+
pthread_attr_t attr;
|
| 27 |
+
sigset_t ign, oset;
|
| 28 |
+
pthread_t p;
|
| 29 |
+
size_t size;
|
| 30 |
+
int err;
|
| 31 |
+
|
| 32 |
+
SIGFILLSET(ign);
|
| 33 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 34 |
+
|
| 35 |
+
pthread_attr_init(&attr);
|
| 36 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 37 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 38 |
+
|
| 39 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 40 |
+
ts->g->stackhi = size;
|
| 41 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 42 |
+
|
| 43 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 44 |
+
|
| 45 |
+
if (err != 0) {
|
| 46 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 51 |
+
static void*
|
| 52 |
+
threadentry(void *v)
|
| 53 |
+
{
|
| 54 |
+
ThreadStart ts;
|
| 55 |
+
|
| 56 |
+
ts = *(ThreadStart*)v;
|
| 57 |
+
free(v);
|
| 58 |
+
|
| 59 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 60 |
+
return nil;
|
| 61 |
+
}
|
go/src/runtime/cgo/gcc_fatalf.c
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build aix || (!android && linux) || dragonfly || freebsd || netbsd || openbsd || solaris
|
| 6 |
+
|
| 7 |
+
#include <stdarg.h>
|
| 8 |
+
#include <stdio.h>
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include "libcgo.h"
|
| 11 |
+
|
| 12 |
+
void
|
| 13 |
+
fatalf(const char* format, ...)
|
| 14 |
+
{
|
| 15 |
+
va_list ap;
|
| 16 |
+
|
| 17 |
+
fprintf(stderr, "runtime/cgo: ");
|
| 18 |
+
va_start(ap, format);
|
| 19 |
+
vfprintf(stderr, format, ap);
|
| 20 |
+
va_end(ap);
|
| 21 |
+
fprintf(stderr, "\n");
|
| 22 |
+
abort();
|
| 23 |
+
}
|
go/src/runtime/cgo/gcc_freebsd.c
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build freebsd && (386 || arm || arm64 || riscv64)
|
| 6 |
+
|
| 7 |
+
#include <sys/types.h>
|
| 8 |
+
#include <sys/signalvar.h>
|
| 9 |
+
#include <machine/sysarch.h>
|
| 10 |
+
#include <pthread.h>
|
| 11 |
+
#include <signal.h>
|
| 12 |
+
#include <string.h>
|
| 13 |
+
#include "libcgo.h"
|
| 14 |
+
#include "libcgo_unix.h"
|
| 15 |
+
|
| 16 |
+
#ifdef ARM_TP_ADDRESS
|
| 17 |
+
// ARM_TP_ADDRESS is (ARM_VECTORS_HIGH + 0x1000) or 0xffff1000
|
| 18 |
+
// and is known to runtime.read_tls_fallback. Verify it with
|
| 19 |
+
// cpp.
|
| 20 |
+
#if ARM_TP_ADDRESS != 0xffff1000
|
| 21 |
+
#error Wrong ARM_TP_ADDRESS!
|
| 22 |
+
#endif
|
| 23 |
+
#endif
|
| 24 |
+
|
| 25 |
+
static void* threadentry(void*);
|
| 26 |
+
static void (*setg_gcc)(void*);
|
| 27 |
+
|
| 28 |
+
void
|
| 29 |
+
x_cgo_init(G *g, void (*setg)(void*))
|
| 30 |
+
{
|
| 31 |
+
setg_gcc = setg;
|
| 32 |
+
_cgo_set_stacklo(g, NULL);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
void
|
| 36 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 37 |
+
{
|
| 38 |
+
pthread_attr_t attr;
|
| 39 |
+
sigset_t ign, oset;
|
| 40 |
+
pthread_t p;
|
| 41 |
+
size_t size;
|
| 42 |
+
int err;
|
| 43 |
+
|
| 44 |
+
SIGFILLSET(ign);
|
| 45 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 46 |
+
|
| 47 |
+
pthread_attr_init(&attr);
|
| 48 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 49 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 50 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 51 |
+
ts->g->stackhi = size;
|
| 52 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 53 |
+
|
| 54 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 55 |
+
|
| 56 |
+
if (err != 0) {
|
| 57 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 62 |
+
static void*
|
| 63 |
+
threadentry(void *v)
|
| 64 |
+
{
|
| 65 |
+
ThreadStart ts;
|
| 66 |
+
|
| 67 |
+
ts = *(ThreadStart*)v;
|
| 68 |
+
free(v);
|
| 69 |
+
|
| 70 |
+
crosscall1(ts.fn, setg_gcc, ts.g);
|
| 71 |
+
return nil;
|
| 72 |
+
}
|
go/src/runtime/cgo/gcc_freebsd_amd64.c
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <sys/types.h>
|
| 6 |
+
#include <errno.h>
|
| 7 |
+
#include <sys/signalvar.h>
|
| 8 |
+
#include <pthread.h>
|
| 9 |
+
#include <signal.h>
|
| 10 |
+
#include <string.h>
|
| 11 |
+
#include "libcgo.h"
|
| 12 |
+
#include "libcgo_unix.h"
|
| 13 |
+
|
| 14 |
+
static void* threadentry(void*);
|
| 15 |
+
static void (*setg_gcc)(void*);
|
| 16 |
+
|
| 17 |
+
void
|
| 18 |
+
x_cgo_init(G *g, void (*setg)(void*))
|
| 19 |
+
{
|
| 20 |
+
uintptr *pbounds;
|
| 21 |
+
|
| 22 |
+
// Deal with memory sanitizer/clang interaction.
|
| 23 |
+
// See gcc_linux_amd64.c for details.
|
| 24 |
+
setg_gcc = setg;
|
| 25 |
+
pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
|
| 26 |
+
if (pbounds == NULL) {
|
| 27 |
+
fatalf("malloc failed: %s", strerror(errno));
|
| 28 |
+
}
|
| 29 |
+
_cgo_set_stacklo(g, pbounds);
|
| 30 |
+
free(pbounds);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
void
|
| 34 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 35 |
+
{
|
| 36 |
+
pthread_attr_t attr;
|
| 37 |
+
sigset_t ign, oset;
|
| 38 |
+
pthread_t p;
|
| 39 |
+
size_t size;
|
| 40 |
+
int err;
|
| 41 |
+
|
| 42 |
+
SIGFILLSET(ign);
|
| 43 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 44 |
+
|
| 45 |
+
pthread_attr_init(&attr);
|
| 46 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 47 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 48 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 49 |
+
ts->g->stackhi = size;
|
| 50 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 51 |
+
|
| 52 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 53 |
+
|
| 54 |
+
if (err != 0) {
|
| 55 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 60 |
+
static void*
|
| 61 |
+
threadentry(void *v)
|
| 62 |
+
{
|
| 63 |
+
ThreadStart ts;
|
| 64 |
+
|
| 65 |
+
ts = *(ThreadStart*)v;
|
| 66 |
+
_cgo_tsan_acquire();
|
| 67 |
+
free(v);
|
| 68 |
+
_cgo_tsan_release();
|
| 69 |
+
|
| 70 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 71 |
+
return nil;
|
| 72 |
+
}
|
go/src/runtime/cgo/gcc_freebsd_sigaction.c
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2018 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build freebsd && amd64
|
| 6 |
+
|
| 7 |
+
#include <errno.h>
|
| 8 |
+
#include <stddef.h>
|
| 9 |
+
#include <stdint.h>
|
| 10 |
+
#include <string.h>
|
| 11 |
+
#include <signal.h>
|
| 12 |
+
|
| 13 |
+
#include "libcgo.h"
|
| 14 |
+
|
| 15 |
+
// go_sigaction_t is a C version of the sigactiont struct from
|
| 16 |
+
// os_freebsd.go. This definition — and its conversion to and from struct
|
| 17 |
+
// sigaction — are specific to freebsd/amd64.
|
| 18 |
+
typedef struct {
|
| 19 |
+
uint32_t __bits[_SIG_WORDS];
|
| 20 |
+
} go_sigset_t;
|
| 21 |
+
typedef struct {
|
| 22 |
+
uintptr_t handler;
|
| 23 |
+
int32_t flags;
|
| 24 |
+
go_sigset_t mask;
|
| 25 |
+
} go_sigaction_t;
|
| 26 |
+
|
| 27 |
+
int32_t
|
| 28 |
+
x_cgo_sigaction(intptr_t signum, const go_sigaction_t *goact, go_sigaction_t *oldgoact) {
|
| 29 |
+
int32_t ret;
|
| 30 |
+
struct sigaction act;
|
| 31 |
+
struct sigaction oldact;
|
| 32 |
+
size_t i;
|
| 33 |
+
|
| 34 |
+
_cgo_tsan_acquire();
|
| 35 |
+
|
| 36 |
+
memset(&act, 0, sizeof act);
|
| 37 |
+
memset(&oldact, 0, sizeof oldact);
|
| 38 |
+
|
| 39 |
+
if (goact) {
|
| 40 |
+
if (goact->flags & SA_SIGINFO) {
|
| 41 |
+
act.sa_sigaction = (void(*)(int, siginfo_t*, void*))(goact->handler);
|
| 42 |
+
} else {
|
| 43 |
+
act.sa_handler = (void(*)(int))(goact->handler);
|
| 44 |
+
}
|
| 45 |
+
sigemptyset(&act.sa_mask);
|
| 46 |
+
for (i = 0; i < 8 * sizeof(goact->mask); i++) {
|
| 47 |
+
if (goact->mask.__bits[i/32] & ((uint32_t)(1)<<(i&31))) {
|
| 48 |
+
sigaddset(&act.sa_mask, i+1);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
act.sa_flags = goact->flags;
|
| 52 |
+
}
|
| 53 |
+
|
| 54 |
+
ret = sigaction(signum, goact ? &act : NULL, oldgoact ? &oldact : NULL);
|
| 55 |
+
if (ret == -1) {
|
| 56 |
+
// runtime.sigaction expects _cgo_sigaction to return errno on error.
|
| 57 |
+
_cgo_tsan_release();
|
| 58 |
+
return errno;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
if (oldgoact) {
|
| 62 |
+
if (oldact.sa_flags & SA_SIGINFO) {
|
| 63 |
+
oldgoact->handler = (uintptr_t)(oldact.sa_sigaction);
|
| 64 |
+
} else {
|
| 65 |
+
oldgoact->handler = (uintptr_t)(oldact.sa_handler);
|
| 66 |
+
}
|
| 67 |
+
for (i = 0 ; i < _SIG_WORDS; i++) {
|
| 68 |
+
oldgoact->mask.__bits[i] = 0;
|
| 69 |
+
}
|
| 70 |
+
for (i = 0; i < 8 * sizeof(oldgoact->mask); i++) {
|
| 71 |
+
if (sigismember(&oldact.sa_mask, i+1) == 1) {
|
| 72 |
+
oldgoact->mask.__bits[i/32] |= (uint32_t)(1)<<(i&31);
|
| 73 |
+
}
|
| 74 |
+
}
|
| 75 |
+
oldgoact->flags = oldact.sa_flags;
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
_cgo_tsan_release();
|
| 79 |
+
return ret;
|
| 80 |
+
}
|
go/src/runtime/cgo/gcc_libinit.c
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build unix
|
| 6 |
+
|
| 7 |
+
// When cross-compiling with clang to linux/armv5, atomics are emulated
|
| 8 |
+
// and cause a compiler warning. This results in a build failure since
|
| 9 |
+
// cgo uses -Werror. See #65290.
|
| 10 |
+
#pragma GCC diagnostic ignored "-Wpragmas"
|
| 11 |
+
#pragma GCC diagnostic ignored "-Wunknown-warning-option"
|
| 12 |
+
#pragma GCC diagnostic ignored "-Watomic-alignment"
|
| 13 |
+
|
| 14 |
+
#include <pthread.h>
|
| 15 |
+
#include <errno.h>
|
| 16 |
+
#include <stdio.h>
|
| 17 |
+
#include <stdlib.h>
|
| 18 |
+
#include <string.h> // strerror
|
| 19 |
+
#include <time.h>
|
| 20 |
+
#include "libcgo.h"
|
| 21 |
+
#include "libcgo_unix.h"
|
| 22 |
+
|
| 23 |
+
static pthread_cond_t runtime_init_cond = PTHREAD_COND_INITIALIZER;
|
| 24 |
+
static pthread_mutex_t runtime_init_mu = PTHREAD_MUTEX_INITIALIZER;
|
| 25 |
+
static int runtime_init_done;
|
| 26 |
+
|
| 27 |
+
// pthread_g is a pthread specific key, for storing the g that binded to the C thread.
|
| 28 |
+
// The registered pthread_key_destructor will dropm, when the pthread-specified value g is not NULL,
|
| 29 |
+
// while a C thread is exiting.
|
| 30 |
+
static pthread_key_t pthread_g;
|
| 31 |
+
static void pthread_key_destructor(void* g);
|
| 32 |
+
uintptr_t x_cgo_pthread_key_created;
|
| 33 |
+
void (*x_crosscall2_ptr)(void (*fn)(void *), void *, int, size_t);
|
| 34 |
+
|
| 35 |
+
// The traceback function, used when tracing C calls.
|
| 36 |
+
static void (*cgo_traceback_function)(struct cgoTracebackArg*);
|
| 37 |
+
|
| 38 |
+
// The context function, used when tracing back C calls into Go.
|
| 39 |
+
static void (*cgo_context_function)(struct cgoContextArg*);
|
| 40 |
+
|
| 41 |
+
// The symbolizer function, used when symbolizing C frames.
|
| 42 |
+
static void (*cgo_symbolizer_function)(struct cgoSymbolizerArg*);
|
| 43 |
+
|
| 44 |
+
void
|
| 45 |
+
x_cgo_sys_thread_create(void* (*func)(void*), void* arg) {
|
| 46 |
+
pthread_attr_t attr;
|
| 47 |
+
pthread_t p;
|
| 48 |
+
int err;
|
| 49 |
+
|
| 50 |
+
pthread_attr_init(&attr);
|
| 51 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 52 |
+
err = _cgo_try_pthread_create(&p, &attr, func, arg);
|
| 53 |
+
if (err != 0) {
|
| 54 |
+
fprintf(stderr, "pthread_create failed: %s", strerror(err));
|
| 55 |
+
abort();
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
uintptr_t
|
| 60 |
+
_cgo_wait_runtime_init_done(void) {
|
| 61 |
+
void (*pfn)(struct cgoContextArg*);
|
| 62 |
+
int done;
|
| 63 |
+
|
| 64 |
+
pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
|
| 65 |
+
|
| 66 |
+
done = 2;
|
| 67 |
+
if (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) != done) {
|
| 68 |
+
pthread_mutex_lock(&runtime_init_mu);
|
| 69 |
+
while (__atomic_load_n(&runtime_init_done, __ATOMIC_CONSUME) == 0) {
|
| 70 |
+
pthread_cond_wait(&runtime_init_cond, &runtime_init_mu);
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
// The key and x_cgo_pthread_key_created are for the whole program,
|
| 74 |
+
// whereas the specific and destructor is per thread.
|
| 75 |
+
if (x_cgo_pthread_key_created == 0 && pthread_key_create(&pthread_g, pthread_key_destructor) == 0) {
|
| 76 |
+
x_cgo_pthread_key_created = 1;
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
// TODO(iant): For the case of a new C thread calling into Go, such
|
| 80 |
+
// as when using -buildmode=c-archive, we know that Go runtime
|
| 81 |
+
// initialization is complete but we do not know that all Go init
|
| 82 |
+
// functions have been run. We should not fetch cgo_context_function
|
| 83 |
+
// until they have been, because that is where a call to
|
| 84 |
+
// SetCgoTraceback is likely to occur. We are going to wait for Go
|
| 85 |
+
// initialization to be complete anyhow, later, by waiting for
|
| 86 |
+
// main_init_done to be closed in cgocallbackg1. We should wait here
|
| 87 |
+
// instead. See also issue #15943.
|
| 88 |
+
pfn = __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
|
| 89 |
+
|
| 90 |
+
__atomic_store_n(&runtime_init_done, done, __ATOMIC_RELEASE);
|
| 91 |
+
pthread_mutex_unlock(&runtime_init_mu);
|
| 92 |
+
}
|
| 93 |
+
|
| 94 |
+
if (pfn != nil) {
|
| 95 |
+
struct cgoContextArg arg;
|
| 96 |
+
|
| 97 |
+
arg.Context = 0;
|
| 98 |
+
(*pfn)(&arg);
|
| 99 |
+
return arg.Context;
|
| 100 |
+
}
|
| 101 |
+
return 0;
|
| 102 |
+
}
|
| 103 |
+
|
| 104 |
+
// _cgo_set_stacklo sets g->stacklo based on the stack size.
|
| 105 |
+
// This is common code called from x_cgo_init, which is itself
|
| 106 |
+
// called by rt0_go in the runtime package.
|
| 107 |
+
void _cgo_set_stacklo(G *g, uintptr *pbounds)
|
| 108 |
+
{
|
| 109 |
+
uintptr bounds[2];
|
| 110 |
+
|
| 111 |
+
// pbounds can be passed in by the caller; see gcc_linux_amd64.c.
|
| 112 |
+
if (pbounds == NULL) {
|
| 113 |
+
pbounds = &bounds[0];
|
| 114 |
+
}
|
| 115 |
+
|
| 116 |
+
x_cgo_getstackbound(pbounds);
|
| 117 |
+
|
| 118 |
+
g->stacklo = *pbounds;
|
| 119 |
+
|
| 120 |
+
// Sanity check the results now, rather than getting a
|
| 121 |
+
// morestack on g0 crash.
|
| 122 |
+
if (g->stacklo >= g->stackhi) {
|
| 123 |
+
fprintf(stderr, "runtime/cgo: bad stack bounds: lo=%p hi=%p\n", (void*)(g->stacklo), (void*)(g->stackhi));
|
| 124 |
+
abort();
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
// Store the g into a thread-specific value associated with the pthread key pthread_g.
|
| 129 |
+
// And pthread_key_destructor will dropm when the thread is exiting.
|
| 130 |
+
void x_cgo_bindm(void* g) {
|
| 131 |
+
// We assume this will always succeed, otherwise, there might be extra M leaking,
|
| 132 |
+
// when a C thread exits after a cgo call.
|
| 133 |
+
// We only invoke this function once per thread in runtime.needAndBindM,
|
| 134 |
+
// and the next calls just reuse the bound m.
|
| 135 |
+
pthread_setspecific(pthread_g, g);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
void
|
| 139 |
+
x_cgo_notify_runtime_init_done(void* dummy __attribute__ ((unused))) {
|
| 140 |
+
pthread_mutex_lock(&runtime_init_mu);
|
| 141 |
+
__atomic_store_n(&runtime_init_done, 1, __ATOMIC_RELEASE);
|
| 142 |
+
pthread_cond_broadcast(&runtime_init_cond);
|
| 143 |
+
pthread_mutex_unlock(&runtime_init_mu);
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
// Sets the traceback, context, and symbolizer functions. Called from
|
| 147 |
+
// runtime.SetCgoTraceback.
|
| 148 |
+
void x_cgo_set_traceback_functions(struct cgoSetTracebackFunctionsArg* arg) {
|
| 149 |
+
__atomic_store_n(&cgo_traceback_function, arg->Traceback, __ATOMIC_RELEASE);
|
| 150 |
+
__atomic_store_n(&cgo_context_function, arg->Context, __ATOMIC_RELEASE);
|
| 151 |
+
__atomic_store_n(&cgo_symbolizer_function, arg->Symbolizer, __ATOMIC_RELEASE);
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
// Gets the traceback function to call to trace C calls.
|
| 155 |
+
void (*(_cgo_get_traceback_function(void)))(struct cgoTracebackArg*) {
|
| 156 |
+
return __atomic_load_n(&cgo_traceback_function, __ATOMIC_CONSUME);
|
| 157 |
+
}
|
| 158 |
+
|
| 159 |
+
// Call the traceback function registered with x_cgo_set_traceback_functions.
|
| 160 |
+
//
|
| 161 |
+
// The traceback function is an arbitrary user C function which may be built
|
| 162 |
+
// with TSAN, and thus must be wrapped with TSAN acquire/release calls. For
|
| 163 |
+
// normal cgo calls, cmd/cgo automatically inserts TSAN acquire/release calls.
|
| 164 |
+
// Since the traceback, context, and symbolizer functions are registered at
|
| 165 |
+
// startup and called via the runtime, they do not get automatic TSAN
|
| 166 |
+
// acquire/release calls.
|
| 167 |
+
//
|
| 168 |
+
// The only purpose of this wrapper is to perform TSAN acquire/release.
|
| 169 |
+
// Alternatively, if the runtime arranged to safely call TSAN acquire/release,
|
| 170 |
+
// it could perform the call directly.
|
| 171 |
+
void x_cgo_call_traceback_function(struct cgoTracebackArg* arg) {
|
| 172 |
+
void (*pfn)(struct cgoTracebackArg*);
|
| 173 |
+
|
| 174 |
+
pfn = _cgo_get_traceback_function();
|
| 175 |
+
if (pfn == nil) {
|
| 176 |
+
return;
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
_cgo_tsan_acquire();
|
| 180 |
+
(*pfn)(arg);
|
| 181 |
+
_cgo_tsan_release();
|
| 182 |
+
}
|
| 183 |
+
|
| 184 |
+
// Gets the context function to call to record the traceback context
|
| 185 |
+
// when calling a Go function from C code.
|
| 186 |
+
void (*(_cgo_get_context_function(void)))(struct cgoContextArg*) {
|
| 187 |
+
return __atomic_load_n(&cgo_context_function, __ATOMIC_CONSUME);
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
// Gets the symbolizer function to call to symbolize C frames.
|
| 191 |
+
void (*(_cgo_get_symbolizer_function(void)))(struct cgoSymbolizerArg*) {
|
| 192 |
+
return __atomic_load_n(&cgo_symbolizer_function, __ATOMIC_CONSUME);
|
| 193 |
+
}
|
| 194 |
+
|
| 195 |
+
// Call the symbolizer function registered with x_cgo_set_traceback_functions.
|
| 196 |
+
//
|
| 197 |
+
// See comment on x_cgo_call_traceback_function.
|
| 198 |
+
void x_cgo_call_symbolizer_function(struct cgoSymbolizerArg* arg) {
|
| 199 |
+
void (*pfn)(struct cgoSymbolizerArg*);
|
| 200 |
+
|
| 201 |
+
pfn = _cgo_get_symbolizer_function();
|
| 202 |
+
if (pfn == nil) {
|
| 203 |
+
return;
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
_cgo_tsan_acquire();
|
| 207 |
+
(*pfn)(arg);
|
| 208 |
+
_cgo_tsan_release();
|
| 209 |
+
}
|
| 210 |
+
|
| 211 |
+
// _cgo_try_pthread_create retries pthread_create if it fails with
|
| 212 |
+
// EAGAIN.
|
| 213 |
+
int
|
| 214 |
+
_cgo_try_pthread_create(pthread_t* thread, const pthread_attr_t* attr, void* (*pfn)(void*), void* arg) {
|
| 215 |
+
int tries;
|
| 216 |
+
int err;
|
| 217 |
+
struct timespec ts;
|
| 218 |
+
|
| 219 |
+
for (tries = 0; tries < 20; tries++) {
|
| 220 |
+
err = pthread_create(thread, attr, pfn, arg);
|
| 221 |
+
if (err == 0) {
|
| 222 |
+
return 0;
|
| 223 |
+
}
|
| 224 |
+
if (err != EAGAIN) {
|
| 225 |
+
return err;
|
| 226 |
+
}
|
| 227 |
+
ts.tv_sec = 0;
|
| 228 |
+
ts.tv_nsec = (tries + 1) * 1000 * 1000; // Milliseconds.
|
| 229 |
+
nanosleep(&ts, nil);
|
| 230 |
+
}
|
| 231 |
+
return EAGAIN;
|
| 232 |
+
}
|
| 233 |
+
|
| 234 |
+
static void
|
| 235 |
+
pthread_key_destructor(void* g) {
|
| 236 |
+
if (x_crosscall2_ptr != NULL) {
|
| 237 |
+
// fn == NULL means dropm.
|
| 238 |
+
// We restore g by using the stored g, before dropm in runtime.cgocallback,
|
| 239 |
+
// since the g stored in the TLS by Go might be cleared in some platforms,
|
| 240 |
+
// before this destructor invoked.
|
| 241 |
+
x_crosscall2_ptr(NULL, g, 0, 0);
|
| 242 |
+
}
|
| 243 |
+
}
|
go/src/runtime/cgo/gcc_libinit_windows.c
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#ifdef __CYGWIN__
|
| 6 |
+
#error "don't use the cygwin compiler to build native Windows programs; use MinGW instead"
|
| 7 |
+
#endif
|
| 8 |
+
|
| 9 |
+
#define WIN32_LEAN_AND_MEAN
|
| 10 |
+
#include <windows.h>
|
| 11 |
+
|
| 12 |
+
#include <stdio.h>
|
| 13 |
+
#include <stdlib.h>
|
| 14 |
+
|
| 15 |
+
#include "libcgo.h"
|
| 16 |
+
#include "libcgo_windows.h"
|
| 17 |
+
|
| 18 |
+
static volatile LONG runtime_init_once_gate = 0;
|
| 19 |
+
static volatile LONG runtime_init_once_done = 0;
|
| 20 |
+
|
| 21 |
+
static CRITICAL_SECTION runtime_init_cs;
|
| 22 |
+
|
| 23 |
+
static HANDLE runtime_init_wait;
|
| 24 |
+
static int runtime_init_done;
|
| 25 |
+
|
| 26 |
+
// No pthreads on Windows, these are always zero.
|
| 27 |
+
uintptr_t x_cgo_pthread_key_created;
|
| 28 |
+
void (*x_crosscall2_ptr)(void (*fn)(void *), void *, int, size_t);
|
| 29 |
+
|
| 30 |
+
// Pre-initialize the runtime synchronization objects
|
| 31 |
+
void
|
| 32 |
+
_cgo_preinit_init() {
|
| 33 |
+
runtime_init_wait = CreateEvent(NULL, TRUE, FALSE, NULL);
|
| 34 |
+
if (runtime_init_wait == NULL) {
|
| 35 |
+
fprintf(stderr, "runtime: failed to create runtime initialization wait event.\n");
|
| 36 |
+
abort();
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
InitializeCriticalSection(&runtime_init_cs);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
// Make sure that the preinit sequence has run.
|
| 43 |
+
void
|
| 44 |
+
_cgo_maybe_run_preinit() {
|
| 45 |
+
if (!InterlockedExchangeAdd(&runtime_init_once_done, 0)) {
|
| 46 |
+
if (InterlockedIncrement(&runtime_init_once_gate) == 1) {
|
| 47 |
+
_cgo_preinit_init();
|
| 48 |
+
InterlockedIncrement(&runtime_init_once_done);
|
| 49 |
+
} else {
|
| 50 |
+
// Decrement to avoid overflow.
|
| 51 |
+
InterlockedDecrement(&runtime_init_once_gate);
|
| 52 |
+
while(!InterlockedExchangeAdd(&runtime_init_once_done, 0)) {
|
| 53 |
+
Sleep(0);
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
void
|
| 60 |
+
x_cgo_sys_thread_create(unsigned long (__stdcall *func)(void*), void* arg) {
|
| 61 |
+
_cgo_beginthread(func, arg);
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
int
|
| 65 |
+
_cgo_is_runtime_initialized() {
|
| 66 |
+
int status;
|
| 67 |
+
|
| 68 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 69 |
+
status = runtime_init_done;
|
| 70 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 71 |
+
return status;
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
uintptr_t
|
| 75 |
+
_cgo_wait_runtime_init_done(void) {
|
| 76 |
+
void (*pfn)(struct cgoContextArg*);
|
| 77 |
+
|
| 78 |
+
_cgo_maybe_run_preinit();
|
| 79 |
+
while (!_cgo_is_runtime_initialized()) {
|
| 80 |
+
WaitForSingleObject(runtime_init_wait, INFINITE);
|
| 81 |
+
}
|
| 82 |
+
pfn = _cgo_get_context_function();
|
| 83 |
+
if (pfn != nil) {
|
| 84 |
+
struct cgoContextArg arg;
|
| 85 |
+
|
| 86 |
+
arg.Context = 0;
|
| 87 |
+
(*pfn)(&arg);
|
| 88 |
+
return arg.Context;
|
| 89 |
+
}
|
| 90 |
+
return 0;
|
| 91 |
+
}
|
| 92 |
+
|
| 93 |
+
// Should not be used since x_cgo_pthread_key_created will always be zero.
|
| 94 |
+
void x_cgo_bindm(void* dummy) {
|
| 95 |
+
fprintf(stderr, "unexpected cgo_bindm on Windows\n");
|
| 96 |
+
abort();
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
void
|
| 100 |
+
x_cgo_notify_runtime_init_done(void* dummy) {
|
| 101 |
+
_cgo_maybe_run_preinit();
|
| 102 |
+
|
| 103 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 104 |
+
runtime_init_done = 1;
|
| 105 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 106 |
+
|
| 107 |
+
if (!SetEvent(runtime_init_wait)) {
|
| 108 |
+
fprintf(stderr, "runtime: failed to signal runtime initialization complete.\n");
|
| 109 |
+
abort();
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
// The traceback function, used when tracing C calls.
|
| 114 |
+
static void (*cgo_traceback_function)(struct cgoTracebackArg*);
|
| 115 |
+
|
| 116 |
+
// The context function, used when tracing back C calls into Go.
|
| 117 |
+
static void (*cgo_context_function)(struct cgoContextArg*);
|
| 118 |
+
|
| 119 |
+
// The symbolizer function, used when symbolizing C frames.
|
| 120 |
+
static void (*cgo_symbolizer_function)(struct cgoSymbolizerArg*);
|
| 121 |
+
|
| 122 |
+
// Sets the traceback, context, and symbolizer functions. Called from
|
| 123 |
+
// runtime.SetCgoTraceback.
|
| 124 |
+
void x_cgo_set_traceback_functions(struct cgoSetTracebackFunctionsArg* arg) {
|
| 125 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 126 |
+
cgo_traceback_function = arg->Traceback;
|
| 127 |
+
cgo_context_function = arg->Context;
|
| 128 |
+
cgo_symbolizer_function = arg->Symbolizer;
|
| 129 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
// Gets the traceback function to call to trace C calls.
|
| 133 |
+
void (*(_cgo_get_traceback_function(void)))(struct cgoTracebackArg*) {
|
| 134 |
+
void (*ret)(struct cgoTracebackArg*);
|
| 135 |
+
|
| 136 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 137 |
+
ret = cgo_traceback_function;
|
| 138 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 139 |
+
return ret;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
// Call the traceback function registered with x_cgo_set_traceback_functions.
|
| 143 |
+
//
|
| 144 |
+
// On other platforms, this coordinates with C/C++ TSAN. On Windows, there is
|
| 145 |
+
// no C/C++ TSAN.
|
| 146 |
+
void x_cgo_call_traceback_function(struct cgoTracebackArg* arg) {
|
| 147 |
+
void (*pfn)(struct cgoTracebackArg*);
|
| 148 |
+
|
| 149 |
+
pfn = _cgo_get_traceback_function();
|
| 150 |
+
if (pfn == nil) {
|
| 151 |
+
return;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
(*pfn)(arg);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
// Gets the context function to call to record the traceback context
|
| 158 |
+
// when calling a Go function from C code.
|
| 159 |
+
void (*(_cgo_get_context_function(void)))(struct cgoContextArg*) {
|
| 160 |
+
void (*ret)(struct cgoContextArg*);
|
| 161 |
+
|
| 162 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 163 |
+
ret = cgo_context_function;
|
| 164 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 165 |
+
return ret;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
// Gets the symbolizer function to call to symbolize C frames.
|
| 169 |
+
void (*(_cgo_get_symbolizer_function(void)))(struct cgoSymbolizerArg*) {
|
| 170 |
+
void (*ret)(struct cgoSymbolizerArg*);
|
| 171 |
+
|
| 172 |
+
EnterCriticalSection(&runtime_init_cs);
|
| 173 |
+
ret = cgo_symbolizer_function;
|
| 174 |
+
LeaveCriticalSection(&runtime_init_cs);
|
| 175 |
+
return ret;
|
| 176 |
+
}
|
| 177 |
+
|
| 178 |
+
// Call the symbolizer function registered with x_cgo_set_symbolizer_functions.
|
| 179 |
+
//
|
| 180 |
+
// On other platforms, this coordinates with C/C++ TSAN. On Windows, there is
|
| 181 |
+
// no C/C++ TSAN.
|
| 182 |
+
void x_cgo_call_symbolizer_function(struct cgoSymbolizerArg* arg) {
|
| 183 |
+
void (*pfn)(struct cgoSymbolizerArg*);
|
| 184 |
+
|
| 185 |
+
pfn = _cgo_get_symbolizer_function();
|
| 186 |
+
if (pfn == nil) {
|
| 187 |
+
return;
|
| 188 |
+
}
|
| 189 |
+
|
| 190 |
+
(*pfn)(arg);
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
void _cgo_beginthread(unsigned long (__stdcall *func)(void*), void* arg) {
|
| 194 |
+
int tries;
|
| 195 |
+
HANDLE thandle;
|
| 196 |
+
|
| 197 |
+
for (tries = 0; tries < 20; tries++) {
|
| 198 |
+
thandle = CreateThread(NULL, 0, func, arg, 0, NULL);
|
| 199 |
+
if (thandle == 0 && GetLastError() == ERROR_ACCESS_DENIED) {
|
| 200 |
+
// "Insufficient resources", try again in a bit.
|
| 201 |
+
//
|
| 202 |
+
// Note that the first Sleep(0) is a yield.
|
| 203 |
+
Sleep(tries); // milliseconds
|
| 204 |
+
continue;
|
| 205 |
+
} else if (thandle == 0) {
|
| 206 |
+
break;
|
| 207 |
+
}
|
| 208 |
+
CloseHandle(thandle);
|
| 209 |
+
return; // Success!
|
| 210 |
+
}
|
| 211 |
+
|
| 212 |
+
fprintf(stderr, "runtime: failed to create new OS thread (%lu)\n", GetLastError());
|
| 213 |
+
abort();
|
| 214 |
+
}
|
go/src/runtime/cgo/gcc_linux.c
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build linux && (386 || arm || loong64 || mips || mipsle || mips64 || mips64le || riscv64)
|
| 6 |
+
|
| 7 |
+
#include <pthread.h>
|
| 8 |
+
#include <string.h>
|
| 9 |
+
#include <signal.h>
|
| 10 |
+
#include "libcgo.h"
|
| 11 |
+
#include "libcgo_unix.h"
|
| 12 |
+
|
| 13 |
+
static void *threadentry(void*);
|
| 14 |
+
|
| 15 |
+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
|
| 16 |
+
static void (*setg_gcc)(void*);
|
| 17 |
+
|
| 18 |
+
void
|
| 19 |
+
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
| 20 |
+
{
|
| 21 |
+
setg_gcc = setg;
|
| 22 |
+
|
| 23 |
+
_cgo_set_stacklo(g, NULL);
|
| 24 |
+
|
| 25 |
+
if (x_cgo_inittls) {
|
| 26 |
+
x_cgo_inittls(tlsg, tlsbase);
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
void
|
| 31 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 32 |
+
{
|
| 33 |
+
pthread_attr_t attr;
|
| 34 |
+
sigset_t ign, oset;
|
| 35 |
+
pthread_t p;
|
| 36 |
+
size_t size;
|
| 37 |
+
int err;
|
| 38 |
+
|
| 39 |
+
sigfillset(&ign);
|
| 40 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 41 |
+
|
| 42 |
+
pthread_attr_init(&attr);
|
| 43 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 44 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 45 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 46 |
+
ts->g->stackhi = size;
|
| 47 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 48 |
+
|
| 49 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 50 |
+
|
| 51 |
+
if (err != 0) {
|
| 52 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 57 |
+
static void*
|
| 58 |
+
threadentry(void *v)
|
| 59 |
+
{
|
| 60 |
+
ThreadStart ts;
|
| 61 |
+
|
| 62 |
+
ts = *(ThreadStart*)v;
|
| 63 |
+
free(v);
|
| 64 |
+
|
| 65 |
+
crosscall1(ts.fn, setg_gcc, ts.g);
|
| 66 |
+
return nil;
|
| 67 |
+
}
|
go/src/runtime/cgo/gcc_linux_amd64.c
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2009 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <pthread.h>
|
| 6 |
+
#include <errno.h>
|
| 7 |
+
#include <string.h> // strerror
|
| 8 |
+
#include <signal.h>
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include "libcgo.h"
|
| 11 |
+
#include "libcgo_unix.h"
|
| 12 |
+
|
| 13 |
+
static void* threadentry(void*);
|
| 14 |
+
static void (*setg_gcc)(void*);
|
| 15 |
+
|
| 16 |
+
// This will be set in gcc_android.c for android-specific customization.
|
| 17 |
+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
|
| 18 |
+
|
| 19 |
+
void
|
| 20 |
+
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
| 21 |
+
{
|
| 22 |
+
uintptr *pbounds;
|
| 23 |
+
|
| 24 |
+
/* The memory sanitizer distributed with versions of clang
|
| 25 |
+
before 3.8 has a bug: if you call mmap before malloc, mmap
|
| 26 |
+
may return an address that is later overwritten by the msan
|
| 27 |
+
library. Avoid this problem by forcing a call to malloc
|
| 28 |
+
here, before we ever call malloc.
|
| 29 |
+
|
| 30 |
+
This is only required for the memory sanitizer, so it's
|
| 31 |
+
unfortunate that we always run it. It should be possible
|
| 32 |
+
to remove this when we no longer care about versions of
|
| 33 |
+
clang before 3.8. The test for this is
|
| 34 |
+
misc/cgo/testsanitizers.
|
| 35 |
+
|
| 36 |
+
GCC works hard to eliminate a seemingly unnecessary call to
|
| 37 |
+
malloc, so we actually use the memory we allocate. */
|
| 38 |
+
|
| 39 |
+
setg_gcc = setg;
|
| 40 |
+
pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
|
| 41 |
+
if (pbounds == NULL) {
|
| 42 |
+
fatalf("malloc failed: %s", strerror(errno));
|
| 43 |
+
}
|
| 44 |
+
_cgo_set_stacklo(g, pbounds);
|
| 45 |
+
free(pbounds);
|
| 46 |
+
|
| 47 |
+
if (x_cgo_inittls) {
|
| 48 |
+
x_cgo_inittls(tlsg, tlsbase);
|
| 49 |
+
}
|
| 50 |
+
}
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
void
|
| 54 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 55 |
+
{
|
| 56 |
+
pthread_attr_t attr;
|
| 57 |
+
sigset_t ign, oset;
|
| 58 |
+
pthread_t p;
|
| 59 |
+
size_t size;
|
| 60 |
+
int err;
|
| 61 |
+
|
| 62 |
+
sigfillset(&ign);
|
| 63 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 64 |
+
|
| 65 |
+
pthread_attr_init(&attr);
|
| 66 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 67 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 68 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 69 |
+
ts->g->stackhi = size;
|
| 70 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 71 |
+
|
| 72 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 73 |
+
|
| 74 |
+
if (err != 0) {
|
| 75 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 76 |
+
}
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 80 |
+
static void*
|
| 81 |
+
threadentry(void *v)
|
| 82 |
+
{
|
| 83 |
+
ThreadStart ts;
|
| 84 |
+
|
| 85 |
+
ts = *(ThreadStart*)v;
|
| 86 |
+
_cgo_tsan_acquire();
|
| 87 |
+
free(v);
|
| 88 |
+
_cgo_tsan_release();
|
| 89 |
+
|
| 90 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 91 |
+
return nil;
|
| 92 |
+
}
|
go/src/runtime/cgo/gcc_linux_arm64.c
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <pthread.h>
|
| 6 |
+
#include <errno.h>
|
| 7 |
+
#include <string.h>
|
| 8 |
+
#include <signal.h>
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include "libcgo.h"
|
| 11 |
+
#include "libcgo_unix.h"
|
| 12 |
+
|
| 13 |
+
static void *threadentry(void*);
|
| 14 |
+
|
| 15 |
+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase) __attribute__((common));
|
| 16 |
+
static void (*setg_gcc)(void*);
|
| 17 |
+
|
| 18 |
+
void
|
| 19 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 20 |
+
{
|
| 21 |
+
pthread_attr_t attr;
|
| 22 |
+
sigset_t ign, oset;
|
| 23 |
+
pthread_t p;
|
| 24 |
+
size_t size;
|
| 25 |
+
int err;
|
| 26 |
+
|
| 27 |
+
sigfillset(&ign);
|
| 28 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 29 |
+
|
| 30 |
+
pthread_attr_init(&attr);
|
| 31 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 32 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 33 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 34 |
+
ts->g->stackhi = size;
|
| 35 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 36 |
+
|
| 37 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 38 |
+
|
| 39 |
+
if (err != 0) {
|
| 40 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 41 |
+
}
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
extern void crosscall1(void (*fn)(void), void (*setg_gcc)(void*), void *g);
|
| 45 |
+
static void*
|
| 46 |
+
threadentry(void *v)
|
| 47 |
+
{
|
| 48 |
+
ThreadStart ts;
|
| 49 |
+
|
| 50 |
+
ts = *(ThreadStart*)v;
|
| 51 |
+
free(v);
|
| 52 |
+
|
| 53 |
+
crosscall1(ts.fn, setg_gcc, (void*)ts.g);
|
| 54 |
+
return nil;
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
void
|
| 58 |
+
x_cgo_init(G *g, void (*setg)(void*), void **tlsg, void **tlsbase)
|
| 59 |
+
{
|
| 60 |
+
uintptr *pbounds;
|
| 61 |
+
|
| 62 |
+
/* The memory sanitizer distributed with versions of clang
|
| 63 |
+
before 3.8 has a bug: if you call mmap before malloc, mmap
|
| 64 |
+
may return an address that is later overwritten by the msan
|
| 65 |
+
library. Avoid this problem by forcing a call to malloc
|
| 66 |
+
here, before we ever call malloc.
|
| 67 |
+
|
| 68 |
+
This is only required for the memory sanitizer, so it's
|
| 69 |
+
unfortunate that we always run it. It should be possible
|
| 70 |
+
to remove this when we no longer care about versions of
|
| 71 |
+
clang before 3.8. The test for this is
|
| 72 |
+
misc/cgo/testsanitizers.
|
| 73 |
+
|
| 74 |
+
GCC works hard to eliminate a seemingly unnecessary call to
|
| 75 |
+
malloc, so we actually use the memory we allocate. */
|
| 76 |
+
|
| 77 |
+
setg_gcc = setg;
|
| 78 |
+
pbounds = (uintptr*)malloc(2 * sizeof(uintptr));
|
| 79 |
+
if (pbounds == NULL) {
|
| 80 |
+
fatalf("malloc failed: %s", strerror(errno));
|
| 81 |
+
}
|
| 82 |
+
_cgo_set_stacklo(g, pbounds);
|
| 83 |
+
free(pbounds);
|
| 84 |
+
|
| 85 |
+
if (x_cgo_inittls) {
|
| 86 |
+
x_cgo_inittls(tlsg, tlsbase);
|
| 87 |
+
}
|
| 88 |
+
}
|
go/src/runtime/cgo/gcc_linux_ppc64x.S
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2014 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build linux && (ppc64 || ppc64le)
|
| 6 |
+
|
| 7 |
+
.file "gcc_linux_ppc64x.S"
|
| 8 |
+
|
| 9 |
+
// Define a frame which has no argument space, but is compatible with
|
| 10 |
+
// a call into a Go ABI. We allocate 32B to match FIXED_FRAME with
|
| 11 |
+
// similar semantics, except we store the backchain pointer, not the
|
| 12 |
+
// LR at offset 0. R2 is stored in the Go TOC save slot (offset 24).
|
| 13 |
+
.set GPR_OFFSET, 32
|
| 14 |
+
.set FPR_OFFSET, GPR_OFFSET + 18*8
|
| 15 |
+
.set VR_OFFSET, FPR_OFFSET + 18*8
|
| 16 |
+
.set FRAME_SIZE, VR_OFFSET + 12*16
|
| 17 |
+
|
| 18 |
+
.macro FOR_EACH_GPR opcode r=14
|
| 19 |
+
.ifge 31 - \r
|
| 20 |
+
\opcode \r, GPR_OFFSET + 8*(\r-14)(1)
|
| 21 |
+
FOR_EACH_GPR \opcode "(\r+1)"
|
| 22 |
+
.endif
|
| 23 |
+
.endm
|
| 24 |
+
|
| 25 |
+
.macro FOR_EACH_FPR opcode fr=14
|
| 26 |
+
.ifge 31 - \fr
|
| 27 |
+
\opcode \fr, FPR_OFFSET + 8*(\fr-14)(1)
|
| 28 |
+
FOR_EACH_FPR \opcode "(\fr+1)"
|
| 29 |
+
.endif
|
| 30 |
+
.endm
|
| 31 |
+
|
| 32 |
+
.macro FOR_EACH_VR opcode vr=20
|
| 33 |
+
.ifge 31 - \vr
|
| 34 |
+
li 0, VR_OFFSET + 16*(\vr-20)
|
| 35 |
+
\opcode \vr, 1, 0
|
| 36 |
+
FOR_EACH_VR \opcode "(\vr+1)"
|
| 37 |
+
.endif
|
| 38 |
+
.endm
|
| 39 |
+
|
| 40 |
+
/*
|
| 41 |
+
* void crosscall_ppc64(void (*fn)(void), void *g)
|
| 42 |
+
*
|
| 43 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 44 |
+
* Called from standard ppc64 C ABI, where r2, r14-r31, f14-f31 are
|
| 45 |
+
* callee-save, so they must be saved explicitly.
|
| 46 |
+
*/
|
| 47 |
+
.globl crosscall_ppc64
|
| 48 |
+
crosscall_ppc64:
|
| 49 |
+
// Start with standard C stack frame layout and linkage
|
| 50 |
+
mflr %r0
|
| 51 |
+
std %r0, 16(%r1) // Save LR in caller's frame
|
| 52 |
+
mfcr %r0
|
| 53 |
+
std %r0, 8(%r1) // Save CR in caller's frame
|
| 54 |
+
stdu %r1, -FRAME_SIZE(%r1)
|
| 55 |
+
std %r2, 24(%r1)
|
| 56 |
+
|
| 57 |
+
FOR_EACH_GPR std
|
| 58 |
+
FOR_EACH_FPR stfd
|
| 59 |
+
FOR_EACH_VR stvx
|
| 60 |
+
|
| 61 |
+
// Set up Go ABI constant registers
|
| 62 |
+
li %r0, 0
|
| 63 |
+
|
| 64 |
+
// Restore g pointer (r30 in Go ABI, which may have been clobbered by C)
|
| 65 |
+
mr %r30, %r4
|
| 66 |
+
|
| 67 |
+
// Call fn
|
| 68 |
+
mr %r12, %r3
|
| 69 |
+
mtctr %r3
|
| 70 |
+
bctrl
|
| 71 |
+
|
| 72 |
+
FOR_EACH_GPR ld
|
| 73 |
+
FOR_EACH_FPR lfd
|
| 74 |
+
FOR_EACH_VR lvx
|
| 75 |
+
|
| 76 |
+
ld %r2, 24(%r1)
|
| 77 |
+
addi %r1, %r1, FRAME_SIZE
|
| 78 |
+
ld %r0, 16(%r1)
|
| 79 |
+
mtlr %r0
|
| 80 |
+
ld %r0, 8(%r1)
|
| 81 |
+
mtcr %r0
|
| 82 |
+
blr
|
| 83 |
+
|
| 84 |
+
#ifdef __ELF__
|
| 85 |
+
.section .note.GNU-stack,"",%progbits
|
| 86 |
+
#endif
|
go/src/runtime/cgo/gcc_linux_s390x.c
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
#include <pthread.h>
|
| 6 |
+
#include <string.h>
|
| 7 |
+
#include <signal.h>
|
| 8 |
+
#include "libcgo.h"
|
| 9 |
+
#include "libcgo_unix.h"
|
| 10 |
+
|
| 11 |
+
static void *threadentry(void*);
|
| 12 |
+
|
| 13 |
+
void (*x_cgo_inittls)(void **tlsg, void **tlsbase);
|
| 14 |
+
static void (*setg_gcc)(void*);
|
| 15 |
+
|
| 16 |
+
void
|
| 17 |
+
x_cgo_init(G *g, void (*setg)(void*), void **tlsbase)
|
| 18 |
+
{
|
| 19 |
+
setg_gcc = setg;
|
| 20 |
+
_cgo_set_stacklo(g, NULL);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
void
|
| 24 |
+
_cgo_sys_thread_start(ThreadStart *ts)
|
| 25 |
+
{
|
| 26 |
+
pthread_attr_t attr;
|
| 27 |
+
sigset_t ign, oset;
|
| 28 |
+
pthread_t p;
|
| 29 |
+
size_t size;
|
| 30 |
+
int err;
|
| 31 |
+
|
| 32 |
+
sigfillset(&ign);
|
| 33 |
+
pthread_sigmask(SIG_SETMASK, &ign, &oset);
|
| 34 |
+
|
| 35 |
+
pthread_attr_init(&attr);
|
| 36 |
+
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
| 37 |
+
pthread_attr_getstacksize(&attr, &size);
|
| 38 |
+
// Leave stacklo=0 and set stackhi=size; mstart will do the rest.
|
| 39 |
+
ts->g->stackhi = size;
|
| 40 |
+
err = _cgo_try_pthread_create(&p, &attr, threadentry, ts);
|
| 41 |
+
|
| 42 |
+
pthread_sigmask(SIG_SETMASK, &oset, nil);
|
| 43 |
+
|
| 44 |
+
if (err != 0) {
|
| 45 |
+
fatalf("pthread_create failed: %s", strerror(err));
|
| 46 |
+
}
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
extern void crosscall_s390x(void (*fn)(void), void *g);
|
| 50 |
+
|
| 51 |
+
static void*
|
| 52 |
+
threadentry(void *v)
|
| 53 |
+
{
|
| 54 |
+
ThreadStart ts;
|
| 55 |
+
|
| 56 |
+
ts = *(ThreadStart*)v;
|
| 57 |
+
free(v);
|
| 58 |
+
|
| 59 |
+
// Save g for this thread in C TLS
|
| 60 |
+
setg_gcc((void*)ts.g);
|
| 61 |
+
|
| 62 |
+
crosscall_s390x(ts.fn, (void*)ts.g);
|
| 63 |
+
return nil;
|
| 64 |
+
}
|
go/src/runtime/cgo/gcc_loong64.S
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2022 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
.file "gcc_loong64.S"
|
| 6 |
+
|
| 7 |
+
/*
|
| 8 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
|
| 9 |
+
*
|
| 10 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 11 |
+
* Called from standard lp64d ABI, where $r1, $r3, $r22-$r31, and $f24-$f31
|
| 12 |
+
* are callee-save, so they must be saved explicitly, along with $r1 (LR).
|
| 13 |
+
*/
|
| 14 |
+
.globl crosscall1
|
| 15 |
+
crosscall1:
|
| 16 |
+
addi.d $r3, $r3, -160
|
| 17 |
+
st.d $r1, $r3, 0
|
| 18 |
+
st.d $r22, $r3, 8
|
| 19 |
+
st.d $r23, $r3, 16
|
| 20 |
+
st.d $r24, $r3, 24
|
| 21 |
+
st.d $r25, $r3, 32
|
| 22 |
+
st.d $r26, $r3, 40
|
| 23 |
+
st.d $r27, $r3, 48
|
| 24 |
+
st.d $r28, $r3, 56
|
| 25 |
+
st.d $r29, $r3, 64
|
| 26 |
+
st.d $r30, $r3, 72
|
| 27 |
+
st.d $r31, $r3, 80
|
| 28 |
+
fst.d $f24, $r3, 88
|
| 29 |
+
fst.d $f25, $r3, 96
|
| 30 |
+
fst.d $f26, $r3, 104
|
| 31 |
+
fst.d $f27, $r3, 112
|
| 32 |
+
fst.d $f28, $r3, 120
|
| 33 |
+
fst.d $f29, $r3, 128
|
| 34 |
+
fst.d $f30, $r3, 136
|
| 35 |
+
fst.d $f31, $r3, 144
|
| 36 |
+
|
| 37 |
+
// r4 = *fn, r5 = *setg_gcc, r6 = *g
|
| 38 |
+
move $r23, $r4 // save R4
|
| 39 |
+
move $r4, $r6
|
| 40 |
+
jirl $r1, $r5, 0 // call setg_gcc (clobbers R4)
|
| 41 |
+
jirl $r1, $r23, 0 // call fn
|
| 42 |
+
|
| 43 |
+
ld.d $r22, $r3, 8
|
| 44 |
+
ld.d $r23, $r3, 16
|
| 45 |
+
ld.d $r24, $r3, 24
|
| 46 |
+
ld.d $r25, $r3, 32
|
| 47 |
+
ld.d $r26, $r3, 40
|
| 48 |
+
ld.d $r27, $r3, 48
|
| 49 |
+
ld.d $r28, $r3, 56
|
| 50 |
+
ld.d $r29, $r3, 64
|
| 51 |
+
ld.d $r30, $r3, 72
|
| 52 |
+
ld.d $r31, $r3, 80
|
| 53 |
+
fld.d $f24, $r3, 88
|
| 54 |
+
fld.d $f25, $r3, 96
|
| 55 |
+
fld.d $f26, $r3, 104
|
| 56 |
+
fld.d $f27, $r3, 112
|
| 57 |
+
fld.d $f28, $r3, 120
|
| 58 |
+
fld.d $f29, $r3, 128
|
| 59 |
+
fld.d $f30, $r3, 136
|
| 60 |
+
fld.d $f31, $r3, 144
|
| 61 |
+
ld.d $r1, $r3, 0
|
| 62 |
+
addi.d $r3, $r3, 160
|
| 63 |
+
jirl $r0, $r1, 0
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
#ifdef __ELF__
|
| 67 |
+
.section .note.GNU-stack,"",%progbits
|
| 68 |
+
#endif
|
go/src/runtime/cgo/gcc_mips64x.S
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build mips64 || mips64le
|
| 6 |
+
|
| 7 |
+
.file "gcc_mips64x.S"
|
| 8 |
+
|
| 9 |
+
/*
|
| 10 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
|
| 11 |
+
*
|
| 12 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 13 |
+
* Called from standard MIPS N64 ABI, where $16-$23, $28, $30, and $f24-$f31
|
| 14 |
+
* are callee-save, so they must be saved explicitly, along with $31 (LR).
|
| 15 |
+
*/
|
| 16 |
+
.globl crosscall1
|
| 17 |
+
.set noat
|
| 18 |
+
crosscall1:
|
| 19 |
+
#ifndef __mips_soft_float
|
| 20 |
+
daddiu $29, $29, -160
|
| 21 |
+
#else
|
| 22 |
+
daddiu $29, $29, -96 // For soft-float, no need to make room for FP registers
|
| 23 |
+
#endif
|
| 24 |
+
sd $31, 0($29)
|
| 25 |
+
sd $16, 8($29)
|
| 26 |
+
sd $17, 16($29)
|
| 27 |
+
sd $18, 24($29)
|
| 28 |
+
sd $19, 32($29)
|
| 29 |
+
sd $20, 40($29)
|
| 30 |
+
sd $21, 48($29)
|
| 31 |
+
sd $22, 56($29)
|
| 32 |
+
sd $23, 64($29)
|
| 33 |
+
sd $28, 72($29)
|
| 34 |
+
sd $30, 80($29)
|
| 35 |
+
#ifndef __mips_soft_float
|
| 36 |
+
sdc1 $f24, 88($29)
|
| 37 |
+
sdc1 $f25, 96($29)
|
| 38 |
+
sdc1 $f26, 104($29)
|
| 39 |
+
sdc1 $f27, 112($29)
|
| 40 |
+
sdc1 $f28, 120($29)
|
| 41 |
+
sdc1 $f29, 128($29)
|
| 42 |
+
sdc1 $f30, 136($29)
|
| 43 |
+
sdc1 $f31, 144($29)
|
| 44 |
+
#endif
|
| 45 |
+
|
| 46 |
+
// prepare SB register = pc & 0xffffffff00000000
|
| 47 |
+
bal 1f
|
| 48 |
+
1:
|
| 49 |
+
dsrl $28, $31, 32
|
| 50 |
+
dsll $28, $28, 32
|
| 51 |
+
|
| 52 |
+
move $20, $4 // save R4
|
| 53 |
+
move $1, $6
|
| 54 |
+
jalr $5 // call setg_gcc (clobbers R4)
|
| 55 |
+
jalr $20 // call fn
|
| 56 |
+
|
| 57 |
+
ld $16, 8($29)
|
| 58 |
+
ld $17, 16($29)
|
| 59 |
+
ld $18, 24($29)
|
| 60 |
+
ld $19, 32($29)
|
| 61 |
+
ld $20, 40($29)
|
| 62 |
+
ld $21, 48($29)
|
| 63 |
+
ld $22, 56($29)
|
| 64 |
+
ld $23, 64($29)
|
| 65 |
+
ld $28, 72($29)
|
| 66 |
+
ld $30, 80($29)
|
| 67 |
+
#ifndef __mips_soft_float
|
| 68 |
+
ldc1 $f24, 88($29)
|
| 69 |
+
ldc1 $f25, 96($29)
|
| 70 |
+
ldc1 $f26, 104($29)
|
| 71 |
+
ldc1 $f27, 112($29)
|
| 72 |
+
ldc1 $f28, 120($29)
|
| 73 |
+
ldc1 $f29, 128($29)
|
| 74 |
+
ldc1 $f30, 136($29)
|
| 75 |
+
ldc1 $f31, 144($29)
|
| 76 |
+
#endif
|
| 77 |
+
ld $31, 0($29)
|
| 78 |
+
#ifndef __mips_soft_float
|
| 79 |
+
daddiu $29, $29, 160
|
| 80 |
+
#else
|
| 81 |
+
daddiu $29, $29, 96
|
| 82 |
+
#endif
|
| 83 |
+
jr $31
|
| 84 |
+
|
| 85 |
+
.set at
|
| 86 |
+
|
| 87 |
+
#ifdef __ELF__
|
| 88 |
+
.section .note.GNU-stack,"",%progbits
|
| 89 |
+
#endif
|
go/src/runtime/cgo/gcc_mipsx.S
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2016 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build mips || mipsle
|
| 6 |
+
|
| 7 |
+
.file "gcc_mipsx.S"
|
| 8 |
+
|
| 9 |
+
/*
|
| 10 |
+
* void crosscall1(void (*fn)(void), void (*setg_gcc)(void *g), void *g)
|
| 11 |
+
*
|
| 12 |
+
* Calling into the gc tool chain, where all registers are caller save.
|
| 13 |
+
* Called from standard MIPS O32 ABI, where $16-$23, $30, and $f20-$f31
|
| 14 |
+
* are callee-save, so they must be saved explicitly, along with $31 (LR).
|
| 15 |
+
*/
|
| 16 |
+
.globl crosscall1
|
| 17 |
+
.set noat
|
| 18 |
+
crosscall1:
|
| 19 |
+
#ifndef __mips_soft_float
|
| 20 |
+
addiu $29, $29, -88
|
| 21 |
+
#else
|
| 22 |
+
addiu $29, $29, -40 // For soft-float, no need to make room for FP registers
|
| 23 |
+
#endif
|
| 24 |
+
sw $31, 0($29)
|
| 25 |
+
sw $16, 4($29)
|
| 26 |
+
sw $17, 8($29)
|
| 27 |
+
sw $18, 12($29)
|
| 28 |
+
sw $19, 16($29)
|
| 29 |
+
sw $20, 20($29)
|
| 30 |
+
sw $21, 24($29)
|
| 31 |
+
sw $22, 28($29)
|
| 32 |
+
sw $23, 32($29)
|
| 33 |
+
sw $30, 36($29)
|
| 34 |
+
|
| 35 |
+
#ifndef __mips_soft_float
|
| 36 |
+
sdc1 $f20, 40($29)
|
| 37 |
+
sdc1 $f22, 48($29)
|
| 38 |
+
sdc1 $f24, 56($29)
|
| 39 |
+
sdc1 $f26, 64($29)
|
| 40 |
+
sdc1 $f28, 72($29)
|
| 41 |
+
sdc1 $f30, 80($29)
|
| 42 |
+
#endif
|
| 43 |
+
move $20, $4 // save R4
|
| 44 |
+
move $4, $6
|
| 45 |
+
jalr $5 // call setg_gcc
|
| 46 |
+
jalr $20 // call fn
|
| 47 |
+
|
| 48 |
+
lw $16, 4($29)
|
| 49 |
+
lw $17, 8($29)
|
| 50 |
+
lw $18, 12($29)
|
| 51 |
+
lw $19, 16($29)
|
| 52 |
+
lw $20, 20($29)
|
| 53 |
+
lw $21, 24($29)
|
| 54 |
+
lw $22, 28($29)
|
| 55 |
+
lw $23, 32($29)
|
| 56 |
+
lw $30, 36($29)
|
| 57 |
+
#ifndef __mips_soft_float
|
| 58 |
+
ldc1 $f20, 40($29)
|
| 59 |
+
ldc1 $f22, 48($29)
|
| 60 |
+
ldc1 $f24, 56($29)
|
| 61 |
+
ldc1 $f26, 64($29)
|
| 62 |
+
ldc1 $f28, 72($29)
|
| 63 |
+
ldc1 $f30, 80($29)
|
| 64 |
+
#endif
|
| 65 |
+
lw $31, 0($29)
|
| 66 |
+
#ifndef __mips_soft_float
|
| 67 |
+
addiu $29, $29, 88
|
| 68 |
+
#else
|
| 69 |
+
addiu $29, $29, 40
|
| 70 |
+
#endif
|
| 71 |
+
jr $31
|
| 72 |
+
|
| 73 |
+
.set at
|
| 74 |
+
|
| 75 |
+
#ifdef __ELF__
|
| 76 |
+
.section .note.GNU-stack,"",%progbits
|
| 77 |
+
#endif
|
go/src/runtime/cgo/gcc_mmap.c
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Copyright 2015 The Go Authors. All rights reserved.
|
| 2 |
+
// Use of this source code is governed by a BSD-style
|
| 3 |
+
// license that can be found in the LICENSE file.
|
| 4 |
+
|
| 5 |
+
//go:build (linux && (amd64 || arm64 || loong64 || ppc64le)) || (freebsd && amd64)
|
| 6 |
+
|
| 7 |
+
#include <errno.h>
|
| 8 |
+
#include <stdint.h>
|
| 9 |
+
#include <stdlib.h>
|
| 10 |
+
#include <sys/mman.h>
|
| 11 |
+
|
| 12 |
+
#include "libcgo.h"
|
| 13 |
+
|
| 14 |
+
uintptr_t
|
| 15 |
+
x_cgo_mmap(void *addr, uintptr_t length, int32_t prot, int32_t flags, int32_t fd, uint32_t offset) {
|
| 16 |
+
void *p;
|
| 17 |
+
|
| 18 |
+
_cgo_tsan_acquire();
|
| 19 |
+
p = mmap(addr, length, prot, flags, fd, offset);
|
| 20 |
+
_cgo_tsan_release();
|
| 21 |
+
if (p == MAP_FAILED) {
|
| 22 |
+
/* This is what the Go code expects on failure. */
|
| 23 |
+
return (uintptr_t)errno;
|
| 24 |
+
}
|
| 25 |
+
return (uintptr_t)p;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
void
|
| 29 |
+
x_cgo_munmap(void *addr, uintptr_t length) {
|
| 30 |
+
int r;
|
| 31 |
+
|
| 32 |
+
_cgo_tsan_acquire();
|
| 33 |
+
r = munmap(addr, length);
|
| 34 |
+
_cgo_tsan_release();
|
| 35 |
+
if (r < 0) {
|
| 36 |
+
/* The Go runtime is not prepared for munmap to fail. */
|
| 37 |
+
abort();
|
| 38 |
+
}
|
| 39 |
+
}
|