diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cf0cb39..90b1eec 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ jobs: strategy: matrix: os: [ubuntu-latest, windows-latest] - go: ['1.19.13', '1.20.14', '1.21.13', '1.22.6'] + go: ['1.19.13', '1.20.14', '1.21.13', '1.22.6', '1.23.0'] name: Test with Go ${{ matrix.go }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} defaults: @@ -45,7 +45,6 @@ jobs: GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v math/rand" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v -test.short runtime" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v runtime/debug" - GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v runtime/internal/atomic" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v runtime/internal/math" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v runtime/internal/sys" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v strconv" @@ -55,8 +54,18 @@ jobs: GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v sync/atomic" GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v time" + - name: Test (Linux, arm64, Go <=1.22) + if: runner.os == 'Linux' && (startsWith(matrix.go, '1.19.') || startsWith(matrix.go, '1.20.') || startsWith(matrix.go, '1.21.') || startsWith(matrix.go, '1.22.')) + run: | + GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v runtime/internal/atomic" + + - name: Test (Linux, arm64, Go >=1.23) + if: runner.os == 'Linux' && startsWith(matrix.go, '1.23.') + run: | + GOARCH=arm64 go run test.go -qemu -args="-test.run=^Test -test.v internal/runtime/atomic" + - name: Test (amd64) - if: ${{ runner.os == 'Linux' || (runner.os == 'Windows' && !startsWith(matrix.go, '1.22.')) }} + if: runner.os == 'Linux' || (runner.os == 'Windows' && !startsWith(matrix.go, '1.22.') && !startsWith(matrix.go, '1.23.')) run: | go run test.go -args="-test.run=^Test -test.v fmt" go run test.go -args="-test.run=^Test -test.v internal/abi" @@ -73,7 +82,6 @@ jobs: # Set an environment to do the default tests. GO_RAND_TEST_HELPER_CODE=1 go run test.go -args="-test.run=^Test -test.v math/rand" go run test.go -args="-test.run=^Test -test.v runtime/debug" - go run test.go -args="-test.run=^Test -test.v runtime/internal/atomic" go run test.go -args="-test.run=^Test -test.v runtime/internal/math" go run test.go -args="-test.run=^Test -test.v runtime/internal/sys" go run test.go -args="-test.run=^Test -test.v strconv" @@ -83,9 +91,19 @@ jobs: go run test.go -args="-test.run=^Test -test.v sync/atomic" go run test.go -args="-test.run=^Test -test.v time" + - name: Test (amd64, Go <=1.22) + if: (runner.os == 'Linux' || (runner.os == 'Windows' && !startsWith(matrix.go, '1.22.'))) && (startsWith(matrix.go, '1.19.') || startsWith(matrix.go, '1.20.') || startsWith(matrix.go, '1.21.') || startsWith(matrix.go, '1.22.')) + run: | + go run test.go -args="-test.run=^Test -test.v runtime/internal/atomic" + + - name: Test (amd64, Go >=1.23) + if: (runner.os == 'Linux' || (runner.os == 'Windows' && !startsWith(matrix.go, '1.23.'))) && startsWith(matrix.go, '1.23.') + run: | + go run test.go -args="-test.run=^Test -test.v internal/runtime/atomic" + - name: Test (amd64, runtime) # Skip runtime tests with Go 1.19 and Windows, as there is an issue (probably golang/go#51007 and golang/go#57455). - # For Go 1.22, Windows is not supported yet. - if: ${{ runner.os != 'Windows' || (!startsWith(matrix.go, '1.19.') && !startsWith(matrix.go, '1.22.')) }} + # For Go 1.22 and Go 1.23, Windows is not supported yet. + if: runner.os != 'Windows' || (!startsWith(matrix.go, '1.19.') && !startsWith(matrix.go, '1.22.') && !startsWith(matrix.go, '1.23.')) run: | go run test.go -args="-test.run=^Test -test.v -test.short runtime" diff --git a/1.23_linux/internal/reflectlite/reflect_mirror_test.go.patch b/1.23_linux/internal/reflectlite/reflect_mirror_test.go.patch new file mode 100644 index 0000000..6af1b58 --- /dev/null +++ b/1.23_linux/internal/reflectlite/reflect_mirror_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestMirrorWithReflect(t *testing.T) { +//--to +func TestMirrorWithReflect(t *testing.T) { + t.Skip("file is not supported in this environment") diff --git a/1.23_linux/internal/runtime/syscall/asm_linux_amd64.s.patch b/1.23_linux/internal/runtime/syscall/asm_linux_amd64.s.patch new file mode 100644 index 0000000..696c97e --- /dev/null +++ b/1.23_linux/internal/runtime/syscall/asm_linux_amd64.s.patch @@ -0,0 +1,23 @@ +//--from +TEXT ·Syscall6(SB),NOSPLIT,$0 + // a6 already in R9. + // a5 already in R8. + MOVQ SI, R10 // a4 + MOVQ DI, DX // a3 + MOVQ CX, SI // a2 + MOVQ BX, DI // a1 + // num already in AX. + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS ok + NEGQ AX + MOVQ AX, CX // errno + MOVQ $-1, AX // r1 + MOVQ $0, BX // r2 + RET +ok: + // r1 already in AX. + MOVQ DX, BX // r2 + MOVQ $0, CX // errno + RET +//--to diff --git a/1.23_linux/internal/runtime/syscall/asm_linux_arm64.s.patch b/1.23_linux/internal/runtime/syscall/asm_linux_arm64.s.patch new file mode 100644 index 0000000..22c7a0c --- /dev/null +++ b/1.23_linux/internal/runtime/syscall/asm_linux_arm64.s.patch @@ -0,0 +1,24 @@ +//--from +TEXT ·Syscall6(SB),NOSPLIT,$0-80 + MOVD num+0(FP), R8 // syscall entry + MOVD a1+8(FP), R0 + MOVD a2+16(FP), R1 + MOVD a3+24(FP), R2 + MOVD a4+32(FP), R3 + MOVD a5+40(FP), R4 + MOVD a6+48(FP), R5 + SVC + CMN $4095, R0 + BCC ok + MOVD $-1, R4 + MOVD R4, r1+56(FP) + MOVD ZR, r2+64(FP) + NEG R0, R0 + MOVD R0, errno+72(FP) + RET +ok: + MOVD R0, r1+56(FP) + MOVD R1, r2+64(FP) + MOVD ZR, errno+72(FP) + RET +//--to diff --git a/1.23_linux/internal/runtime/syscall/syscall_linux.go.patch b/1.23_linux/internal/runtime/syscall/syscall_linux.go.patch new file mode 100644 index 0000000..470cf1f --- /dev/null +++ b/1.23_linux/internal/runtime/syscall/syscall_linux.go.patch @@ -0,0 +1,8 @@ +//--from +func Syscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr) +//--to +func Syscall6(num, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2, errno uintptr) { + println("not implemented syscall at Syscall6", num) + panic("syscall.Syscall6") + return 0, 0, 0x26 // ENOSYS +} diff --git a/1.23_linux/internal/runtime/syscall/syscall_linux_test.go.patch b/1.23_linux/internal/runtime/syscall/syscall_linux_test.go.patch new file mode 100644 index 0000000..fb3471b --- /dev/null +++ b/1.23_linux/internal/runtime/syscall/syscall_linux_test.go.patch @@ -0,0 +1,22 @@ +//--from +import ( + "internal/runtime/syscall" + "testing" +) +//--to +import ( + "testing" +) +//--from +func TestEpollctlErrorSign(t *testing.T) { + v := syscall.EpollCtl(-1, 1, -1, &syscall.EpollEvent{}) + + const EBADF = 0x09 + if v != EBADF { + t.Errorf("epollctl = %v, want %v", v, EBADF) + } +} +//--to +func TestEpollctlErrorSign(t *testing.T) { + t.Skip("Epollctl is not supported in this environment") +} diff --git a/1.23_linux/internal/syscall/unix/fcntl_unix.go.patch b/1.23_linux/internal/syscall/unix/fcntl_unix.go.patch new file mode 100644 index 0000000..45f968b --- /dev/null +++ b/1.23_linux/internal/syscall/unix/fcntl_unix.go.patch @@ -0,0 +1,12 @@ +//--from +func Fcntl(fd int, cmd int, arg int) (int, error) { + val, errno := fcntl(int32(fd), int32(cmd), int32(arg)) + if val == -1 { + return int(val), syscall.Errno(errno) + } + return int(val), nil +} +//--to +func Fcntl(fd int, cmd int, arg int) (int, error) { + return 0, syscall.ENOSYS +} diff --git a/1.23_linux/internal/testenv/exec.go.patch b/1.23_linux/internal/testenv/exec.go.patch new file mode 100644 index 0000000..a602b7b --- /dev/null +++ b/1.23_linux/internal/testenv/exec.go.patch @@ -0,0 +1,5 @@ +//--from +func tryExec() error { +//--to +func tryExec() error { + return fmt.Errorf("can't probe for exec support") diff --git a/1.23_linux/internal/testenv/testenv.go.patch b/1.23_linux/internal/testenv/testenv.go.patch new file mode 100644 index 0000000..f659d6e --- /dev/null +++ b/1.23_linux/internal/testenv/testenv.go.patch @@ -0,0 +1,5 @@ +//--from +func HasGoBuild() bool { +//--to +func HasGoBuild() bool { + return false diff --git a/1.23_linux/internal/testenv/testenv_notunix.go.patch b/1.23_linux/internal/testenv/testenv_notunix.go.patch new file mode 100644 index 0000000..7e57be1 --- /dev/null +++ b/1.23_linux/internal/testenv/testenv_notunix.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build windows || plan9 || (js && wasm) || wasip1 +//--to +//go:build windows || plan9 || (js && wasm) || wasip1 || linux diff --git a/1.23_linux/internal/testenv/testenv_unix.go.patch b/1.23_linux/internal/testenv/testenv_unix.go.patch new file mode 100644 index 0000000..4d16792 --- /dev/null +++ b/1.23_linux/internal/testenv/testenv_unix.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build unix +//--to +//go:build unix && !linux diff --git a/1.23_linux/math/big/link_test.go.patch b/1.23_linux/math/big/link_test.go.patch new file mode 100644 index 0000000..dd14281 --- /dev/null +++ b/1.23_linux/math/big/link_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestLinkerGC(t *testing.T) { +//--to +func TestLinkerGC(t *testing.T) { + t.Skip("go tools are not supported in this environment") diff --git a/1.23_linux/math/rand/default_test.go.patch b/1.23_linux/math/rand/default_test.go.patch new file mode 100644 index 0000000..395f1d2 --- /dev/null +++ b/1.23_linux/math/rand/default_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestDefaultRace(t *testing.T) { +//--to +func TestDefaultRace(t *testing.T) { + t.Skip("os.Getenv and creating processes are not supported in this environment") diff --git a/1.23_linux/runtime/align_test.go.patch b/1.23_linux/runtime/align_test.go.patch new file mode 100644 index 0000000..054ccab --- /dev/null +++ b/1.23_linux/runtime/align_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestAtomicAlignment(t *testing.T) { +//--to +func TestAtomicAlignment(t *testing.T) { + t.Skip("file is not supported in this environment") diff --git a/1.23_linux/runtime/callers_test.go.patch b/1.23_linux/runtime/callers_test.go.patch new file mode 100644 index 0000000..ee38b2b --- /dev/null +++ b/1.23_linux/runtime/callers_test.go.patch @@ -0,0 +1,15 @@ +//--from +func TestCallersNilPointerPanic(t *testing.T) { +//--to +func TestCallersNilPointerPanic(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") +//--from +func TestCallersDeferNilFuncPanic(t *testing.T) { +//--to +func TestCallersDeferNilFuncPanic(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") +//--from +func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) { +//--to +func TestCallersDeferNilFuncPanicWithLoop(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/runtime/cgo/cgo.go.patch b/1.23_linux/runtime/cgo/cgo.go.patch new file mode 100644 index 0000000..fb70050 --- /dev/null +++ b/1.23_linux/runtime/cgo/cgo.go.patch @@ -0,0 +1,8 @@ +//--from +*/ +import "C" +//--to +#cgo !darwin LDFLAGS: -Wl,-unresolved-symbols=ignore-all +#cgo darwin LDFLAGS: -Wl,-undefined,dynamic_lookup +*/ +import "C" diff --git a/1.23_linux/runtime/cgo/gcc_linux_amd64.c.patch b/1.23_linux/runtime/cgo/gcc_linux_amd64.c.patch new file mode 100644 index 0000000..9c2e591 --- /dev/null +++ b/1.23_linux/runtime/cgo/gcc_linux_amd64.c.patch @@ -0,0 +1,69 @@ +//--from +#include +#include +#include // strerror +#include +#include +#include "libcgo.h" +#include "libcgo_unix.h" +//--to +#include +#include +#include // strerror +#include +#include "libcgo.h" +#include "libcgo_unix.h" +//--from +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + sigfillset(&ign); + pthread_sigmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + // Leave stacklo=0 and set stackhi=size; mstart will do the rest. + ts->g->stackhi = size; + err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); + + pthread_sigmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} +//--to +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + pthread_t p; + size_t size; + int err; + + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + // Leave stacklo=0 and set stackhi=size; mstart will do the rest. + ts->g->stackhi = size; + err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); + + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} +//--from +static void* +threadentry(void *v) +{ +//--to +static void* +threadentry(void *v) +{ + extern void hitsumabushi_initializeThread(void); + hitsumabushi_initializeThread(); diff --git a/1.23_linux/runtime/cgo/gcc_linux_arm64.c.patch b/1.23_linux/runtime/cgo/gcc_linux_arm64.c.patch new file mode 100644 index 0000000..f846c8e --- /dev/null +++ b/1.23_linux/runtime/cgo/gcc_linux_arm64.c.patch @@ -0,0 +1,62 @@ +//--from +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + sigfillset(&ign); + pthread_sigmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_getstacksize(&attr, &size); + // Leave stacklo=0 and set stackhi=size; mstart will do the rest. + ts->g->stackhi = size; + err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); + + pthread_sigmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} +//--to +void +_cgo_sys_thread_start(ThreadStart *ts) +{ + pthread_attr_t attr; + sigset_t ign, oset; + pthread_t p; + size_t size; + int err; + + sigfillset(&ign); + pthread_sigmask(SIG_SETMASK, &ign, &oset); + + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 16 * 4096); // Hack for some special environments + pthread_attr_getstacksize(&attr, &size); + // Leave stacklo=0 and set stackhi=size; mstart will do the rest. + ts->g->stackhi = size; + err = _cgo_try_pthread_create(&p, &attr, threadentry, ts); + + pthread_sigmask(SIG_SETMASK, &oset, nil); + + if (err != 0) { + fatalf("pthread_create failed: %s", strerror(err)); + } +} +//--from +static void* +threadentry(void *v) +{ +//--to +static void* +threadentry(void *v) +{ + // Note that threadentry will also be defined in gcc_linux.go in Go 1.22. + extern void hitsumabushi_initializeThread(void); + hitsumabushi_initializeThread(); diff --git a/1.23_linux/runtime/cgo/gcc_setenv.c.patch b/1.23_linux/runtime/cgo/gcc_setenv.c.patch new file mode 100644 index 0000000..6ba88a4 --- /dev/null +++ b/1.23_linux/runtime/cgo/gcc_setenv.c.patch @@ -0,0 +1,26 @@ +//--from +void +x_cgo_setenv(char **arg) +{ + _cgo_tsan_acquire(); + setenv(arg[0], arg[1], 1); + _cgo_tsan_release(); +} +//--to +void +x_cgo_setenv(char **arg) +{ +} +//--from +void +x_cgo_unsetenv(char **arg) +{ + _cgo_tsan_acquire(); + unsetenv(arg[0]); + _cgo_tsan_release(); +} +//--to +void +x_cgo_unsetenv(char **arg) +{ +} diff --git a/1.23_linux/runtime/cgo/gcc_sigaction.c.patch b/1.23_linux/runtime/cgo/gcc_sigaction.c.patch new file mode 100644 index 0000000..16aee14 --- /dev/null +++ b/1.23_linux/runtime/cgo/gcc_sigaction.c.patch @@ -0,0 +1,4 @@ +//--from +//go:build linux && (amd64 || arm64 || ppc64le) +//--to +//go:build linux && (arm64 || ppc64le) diff --git a/1.23_linux/runtime/cgo/hitsumabushi_clock_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_clock_linux.c new file mode 100644 index 0000000..a37ad66 --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_clock_linux.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +#include + +int hitsumabushi_clock_gettime(clockid_t clk_id, struct timespec *tp) { + return clock_gettime(clk_id, tp); +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_cpu_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_cpu_linux.c new file mode 100644 index 0000000..c30445d --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_cpu_linux.c @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +#include + +int32_t hitsumabushi_getproccount() { + return 1; +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_filesystem_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_filesystem_linux.c new file mode 100644 index 0000000..6308980 --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_filesystem_linux.c @@ -0,0 +1,180 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +// This file defines C functions and system calls for Cgo. + +#include +#include +#include +#include +#include +#include +#include + +#include "libcgo.h" +#include "libcgo_unix.h" + +static const int kFDOffset = 100; + +typedef struct { + const void* content; + size_t content_size; + size_t current; + int32_t fd; +} pseudo_file; + +// TODO: Do we need to protect this by mutex? +static pseudo_file pseudo_files[100]; + +static pthread_mutex_t* pseudo_file_mutex() { + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + return &mutex; +} + +static int32_t open_pseudo_file(const void* content, size_t content_size) { + pthread_mutex_lock(pseudo_file_mutex()); + + int index = 0; + int found = 0; + for (int i = 0; i < sizeof(pseudo_files) / sizeof(pseudo_file); i++) { + if (pseudo_files[i].fd == 0) { + index = i; + found = 1; + break; + } + } + if (!found) { + // Too many pseudo files are opened. + pthread_mutex_unlock(pseudo_file_mutex()); + return -1; + } + int32_t fd = index + kFDOffset; + pseudo_files[index].content = content; + pseudo_files[index].content_size = content_size; + pseudo_files[index].current = 0; + pseudo_files[index].fd = fd; + + pthread_mutex_unlock(pseudo_file_mutex()); + return fd; +} + +static size_t read_pseudo_file(int32_t fd, void *p, int32_t n) { + pthread_mutex_lock(pseudo_file_mutex()); + + int32_t index = fd - kFDOffset; + pseudo_file *file = &pseudo_files[index]; + size_t rest = file->content_size - file->current; + if (rest < n) { + n = rest; + } + memcpy(p, file->content + file->current, n); + pseudo_files[index].current += n; + + pthread_mutex_unlock(pseudo_file_mutex()); + return n; +} + +static void close_pseudo_file(int32_t fd) { + pthread_mutex_lock(pseudo_file_mutex()); + + int32_t index = fd - kFDOffset; + pseudo_files[index].content = NULL; + pseudo_files[index].content_size = 0; + pseudo_files[index].current = 0; + pseudo_files[index].fd = 0; + + pthread_mutex_unlock(pseudo_file_mutex()); +} + +int32_t hitsumabushi_closefd(int32_t fd) { + if (fd >= kFDOffset) { + close_pseudo_file(fd); + return 0; + } + fprintf(stderr, "syscall close(%d) is not implemented\n", fd); + return 0; +} + +int32_t hitsumabushi_open(char *name, int32_t mode, int32_t perm) { + if (strcmp(name, "/proc/self/auxv") == 0) { + static const char auxv[] = + "\x06\x00\x00\x00\x00\x00\x00\x00" // _AT_PAGESZ tag (6) + "\x00\x10\x00\x00\x00\x00\x00\x00" // 4096 bytes per page + "\x00\x00\x00\x00\x00\x00\x00\x00" // Dummy bytes + "\x00\x00\x00\x00\x00\x00\x00\x00"; // Dummy bytes + return open_pseudo_file(auxv, sizeof(auxv) / sizeof(char)); + } + if (strcmp(name, "/sys/kernel/mm/transparent_hugepage/hpage_pmd_size") == 0) { + static const char hpage_pmd_size[] = + "\x30\x5c"; // '0', '\n' + return open_pseudo_file(hpage_pmd_size, sizeof(hpage_pmd_size) / sizeof(char)); + } + fprintf(stderr, "syscall open(%s, %d, %d) is not implemented\n", name, mode, perm); + const static int kENOENT = 0x2; + return kENOENT; +} + +int32_t hitsumabushi_read(int32_t fd, void *p, int32_t n) { + if (fd >= kFDOffset) { + return read_pseudo_file(fd, p, n); + } + fprintf(stderr, "syscall read(%d, %p, %d) is not implemented\n", fd, p, n); + const static int kEBADF = 0x9; + return kEBADF; +} + +int32_t hitsumabushi_write1(uintptr_t fd, void *p, int32_t n) { + static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; + int32_t ret = 0; + pthread_mutex_lock(&m); + switch (fd) { + case 1: + ret = fwrite(p, 1, n, stdout); + fflush(stdout); + break; + case 2: + ret = fwrite(p, 1, n, stderr); + fflush(stderr); + break; + default: + fprintf(stderr, "syscall write(%lu, %p, %d) is not implemented\n", fd, p, n); + ret = -EBADF; + break; + } + pthread_mutex_unlock(&m); + return ret; +} + +int32_t hitsumabushi_lseek(uintptr_t fd, off_t offset, int32_t whence) { + fprintf(stderr, "syscall lseek(%lu, %lu, %d) is not implemented\n", fd, offset, whence); + return -ENOSYS; +} + +int32_t hitsumabushi_fcntl(int32_t fd, int32_t cmd, int32_t arg) +{ + if (fd == 0 || fd == 1 || fd == 2) { + if (cmd == F_GETFL) { + return 0; + } + } + fprintf(stderr, "syscall fcntl(%d, %d, %d) is not implemented\n", fd, cmd, arg); + return -EBADF; +} + +int32_t hitsumabushi_fstat(int32_t fd, struct stat *stat) +{ + fprintf(stderr, "syscall fstat(%d, %p) is not implemented\n", fd, stat); + return -ENOSYS; +} + +int32_t hitsumabushi_renameat(int32_t fd1, char* name1, int32_t fd2, char* name2) +{ + fprintf(stderr, "syscall renameat(%d, %s, %d, %s) is not implemented\n", fd1, name1, fd2, name2); + return -ENOSYS; +} + +int32_t hitsumabushi_fstatat(int32_t fd, char* name, struct stat* p, int32_t flags) +{ + fprintf(stderr, "syscall fstatat(%d, %s, %p, %d) is not implemented\n", fd, name, p, flags); + return -ENOSYS; +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_futex_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_futex_linux.c new file mode 100644 index 0000000..a8ffe6b --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_futex_linux.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +#include +#include +#include +#include +#include + +static const int kPseudoFutexWait = 0; +static const int kPseudoFutexWake = 1; + +static void pseudo_futex(uint32_t *uaddr, int mode, uint32_t val, const struct timespec *reltime) { + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; + static pthread_cond_t cond = PTHREAD_COND_INITIALIZER; + + struct timespec abstime; + if (reltime) { + // We are not sure CLOCK_REALTIME is correct or not here. + // However, this time limit is actually not used as the condition variable is shared by + // all the threads. Before the time limit reaches, the thread wakes up in 99.9999...% cases. + clock_gettime(CLOCK_REALTIME, &abstime); + abstime.tv_sec += reltime->tv_sec; + abstime.tv_nsec += reltime->tv_nsec; + if (1000000000 <= abstime.tv_nsec) { + abstime.tv_sec += 1; + abstime.tv_nsec -= 1000000000; + } + } + + int ret = pthread_mutex_lock(&mutex); + if (ret) { + fprintf(stderr, "pthread_mutex_lock failed: %d\n", ret); + abort(); + } + + switch (mode) { + case kPseudoFutexWait: + if (reltime) { + uint32_t v = 0; + __atomic_load(uaddr, &v, __ATOMIC_RELAXED); + if (v == val) { + int ret = pthread_cond_timedwait(&cond, &mutex, &abstime); + if (ret && ret != ETIMEDOUT) { + fprintf(stderr, "pthread_cond_timedwait failed: %d\n", ret); + abort(); + } + } + } else { + uint32_t v = 0; + __atomic_load(uaddr, &v, __ATOMIC_RELAXED); + if (v == val) { + int ret = pthread_cond_wait(&cond, &mutex); + if (ret) { + fprintf(stderr, "pthread_cond_wait failed: %d\n", ret); + abort(); + } + } + } + break; + case kPseudoFutexWake: + if (val != 1) { + fprintf(stderr, "val for waking must be 1 but %d\n", val); + abort(); + } + // TODO: broadcasting is not efficient. Use a mutex for each uaddr. + int ret = pthread_cond_broadcast(&cond); + if (ret) { + fprintf(stderr, "pthread_cond_broadcast failed: %d\n", ret); + abort(); + } + break; + } + + ret = pthread_mutex_unlock(&mutex); + if (ret) { + fprintf(stderr, "pthread_mutex_unlock failed: %d\n", ret); + abort(); + } +} + +int32_t hitsumabushi_futex(uint32_t *uaddr, int32_t futex_op, uint32_t val, + const struct timespec *timeout, + uint32_t *uaddr2, uint32_t val3) { + enum { + kFutexWaitPrivate = 128, + kFutexWakePrivate = 129, + }; + + switch (futex_op) { + case kFutexWaitPrivate: + pseudo_futex(uaddr, kPseudoFutexWait, val, timeout); + break; + case kFutexWakePrivate: + pseudo_futex(uaddr, kPseudoFutexWake, val, NULL); + break; + } + + // This function should return the number of awaken threads, but now it is impossible. + // Just return 0. + return 0; +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_mem_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_mem_linux.c new file mode 100644 index 0000000..ff008a5 --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_mem_linux.c @@ -0,0 +1,36 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +#include +#include + +void* hitsumabushi_sysReserveOS(void* v, uintptr_t n); + +void* hitsumabushi_sysAllocOS(uintptr_t n) { + return hitsumabushi_sysReserveOS(NULL, n); +} + +void hitsumabushi_sysUnusedOS(void* v, uintptr_t n) { +} + +void hitsumabushi_sysUsedOS(void* v, uintptr_t n) { +} + +void hitsumabushi_sysHugePageOS(void* v, uintptr_t n) { +} + +void hitsumabushi_sysFreeOS(void* v, uintptr_t n) { +} + +void hitsumabushi_sysFaultOS(void* v, uintptr_t n) { +} + +void* hitsumabushi_sysReserveOS(void* v, uintptr_t n) { + if (v) { + return NULL; + } + return calloc(n, 1); +} + +void hitsumabushi_sysMapOS(void* v, uintptr_t n) { +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_syscalls_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_syscalls_linux.c new file mode 100644 index 0000000..074d366 --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_syscalls_linux.c @@ -0,0 +1,146 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +// This file defines C functions and system calls for Cgo. + +#include +#include +#include +#include +#include +#include // for usleep +#include // for size_t + +#include "libcgo.h" +#include "libcgo_unix.h" + +typedef unsigned int gid_t; + +extern int hitsumabushi_clock_gettime(clockid_t clk_id, struct timespec *tp); +extern int32_t hitsumabushi_getproccount(); + +void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset) { + abort(); + return NULL; +} + +int munmap(void *addr, size_t length) { + abort(); + return 0; +} + +int pthread_sigmask(int how, void *set, void *oldset) { + // Do nothing. + return 0; +} + +int setegid(gid_t gid) { + // Do nothing. + return 0; +} + +int seteuid(uid_t gid) { + // Do nothing. + return 0; +} + +int setgid(gid_t gid) { + // Do nothing. + return 0; +} + +int setgroups(size_t size, const gid_t *list) { + // Do nothing. + return 0; +} + +int setregid(gid_t rgid, gid_t egid) { + // Do nothing. + return 0; +} + +int setreuid(uid_t ruid, uid_t euid) { + // Do nothing. + return 0; +} + +int setresgid(gid_t rgid, gid_t egid, gid_t sgid) { + // Do nothing. + return 0; +} + +int setresuid(uid_t ruid, uid_t euid, uid_t suid) { + // Do nothing. + return 0; +} + +int setuid(uid_t gid) { + // Do nothing. + return 0; +} + +int sigaction(int signum, void *act, void *oldact) { + // Do nothing. + return 0; +} + +int sigaddset(void *set, int signum) { + // Do nothing. + return 0; +} + +int sigemptyset(void *set) { + // Do nothing. + return 0; +} + +int sigfillset(void *set) { + // Do nothing. + return 0; +} + +int sigismember(void *set, int signum) { + // Do nothing. + return 0; +} + +uint32_t hitsumabushi_gettid() { + uint64_t tid64 = (uint64_t)(pthread_self()); + uint32_t tid = (uint32_t)(tid64 >> 32) ^ (uint32_t)(tid64); + return tid; +} + +int64_t hitsumabushi_nanotime1() { + struct timespec tp; + hitsumabushi_clock_gettime(CLOCK_MONOTONIC, &tp); + return (int64_t)(tp.tv_sec) * 1000000000ll + (int64_t)tp.tv_nsec; +} + +int32_t hitsumabushi_osyield() { + return sched_yield(); +} + +int32_t hitsumabushi_sched_getaffinity(pid_t pid, size_t cpusetsize, void *mask) { + int32_t numcpu = hitsumabushi_getproccount(); + for (int32_t i = 0; i < numcpu; i += 8) + ((unsigned char*)mask)[i / 8] = (unsigned char)((1u << (numcpu - i)) - 1); + // https://man7.org/linux/man-pages/man2/sched_setaffinity.2.html + // > On success, the raw sched_getaffinity() system call returns the + // > number of bytes placed copied into the mask buffer; + return (numcpu + 7) / 8; +} + +void hitsumabushi_usleep(useconds_t usec) { + usleep(usec); +} + +void hitsumabushi_walltime1(int64_t* sec, int32_t* nsec) { + struct timespec tp; + hitsumabushi_clock_gettime(CLOCK_REALTIME, &tp); + *sec = tp.tv_sec; + *nsec = tp.tv_nsec; +} + +void hitsumabushi_exit(int32_t code) { + exit(code); +} diff --git a/1.23_linux/runtime/cgo/hitsumabushi_thread_linux.c b/1.23_linux/runtime/cgo/hitsumabushi_thread_linux.c new file mode 100644 index 0000000..4d65a47 --- /dev/null +++ b/1.23_linux/runtime/cgo/hitsumabushi_thread_linux.c @@ -0,0 +1,2 @@ +void hitsumabushi_initializeThread(void) { +} diff --git a/1.23_linux/runtime/cgo/linux_syscall.c.patch b/1.23_linux/runtime/cgo/linux_syscall.c.patch new file mode 100644 index 0000000..ee5725b --- /dev/null +++ b/1.23_linux/runtime/cgo/linux_syscall.c.patch @@ -0,0 +1,84 @@ +//--from +#include +#include +#include +#include +#include "libcgo.h" +//--to +#include +#include +#include +#include "libcgo.h" +//--from +void +_cgo_libc_setegid(argset_t* x) { + SET_RETVAL(setegid((gid_t) x->args[0])); +} +//--to +void +_cgo_libc_setegid(argset_t* x) { +} +//--from +void +_cgo_libc_seteuid(argset_t* x) { + SET_RETVAL(seteuid((uid_t) x->args[0])); +} +//--to +void +_cgo_libc_seteuid(argset_t* x) { +} +//--from +void +_cgo_libc_setgid(argset_t* x) { + SET_RETVAL(setgid((gid_t) x->args[0])); +} +//--to +void +_cgo_libc_setgid(argset_t* x) { +} +//--from +void +_cgo_libc_setgroups(argset_t* x) { + SET_RETVAL(setgroups((size_t) x->args[0], (const gid_t *) x->args[1])); +} +//--to +void +_cgo_libc_setgroups(argset_t* x) { +} +//--from +void +_cgo_libc_setregid(argset_t* x) { + SET_RETVAL(setregid((gid_t) x->args[0], (gid_t) x->args[1])); +} +//--to +void +_cgo_libc_setregid(argset_t* x) { +} +//--from +void +_cgo_libc_setresgid(argset_t* x) { + SET_RETVAL(setresgid((gid_t) x->args[0], (gid_t) x->args[1], + (gid_t) x->args[2])); +} +//--to +void +_cgo_libc_setresgid(argset_t* x) { +} +//--from +void +_cgo_libc_setreuid(argset_t* x) { + SET_RETVAL(setreuid((uid_t) x->args[0], (uid_t) x->args[1])); +} +//--to +void +_cgo_libc_setreuid(argset_t* x) { +} +//--from +void +_cgo_libc_setuid(argset_t* x) { + SET_RETVAL(setuid((uid_t) x->args[0])); +} +//--to +void +_cgo_libc_setuid(argset_t* x) { +} diff --git a/1.23_linux/runtime/cgo/sigaction.go.patch b/1.23_linux/runtime/cgo/sigaction.go.patch new file mode 100644 index 0000000..57a28dd --- /dev/null +++ b/1.23_linux/runtime/cgo/sigaction.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build (linux && amd64) || (freebsd && amd64) || (linux && arm64) || (linux && ppc64le) +//--to +//go:build (freebsd && amd64) || (linux && arm64) || (linux && ppc64le) diff --git a/1.23_linux/runtime/crash_test.go.patch b/1.23_linux/runtime/crash_test.go.patch new file mode 100644 index 0000000..19991f5 --- /dev/null +++ b/1.23_linux/runtime/crash_test.go.patch @@ -0,0 +1,10 @@ +//--from +func buildTestProg(t *testing.T, binary string, flags ...string) (string, error) { +//--to +func buildTestProg(t *testing.T, binary string, flags ...string) (string, error) { + t.Skip("buildTestProg is not supported in this environment") +//--from +func TestPanicInlined(t *testing.T) { +//--to +func TestPanicInlined(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/runtime/crash_unix_test.go.patch b/1.23_linux/runtime/crash_unix_test.go.patch new file mode 100644 index 0000000..4d16792 --- /dev/null +++ b/1.23_linux/runtime/crash_unix_test.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build unix +//--to +//go:build unix && !linux diff --git a/1.23_linux/runtime/debug/heapdump_test.go.patch b/1.23_linux/runtime/debug/heapdump_test.go.patch new file mode 100644 index 0000000..3ca3609 --- /dev/null +++ b/1.23_linux/runtime/debug/heapdump_test.go.patch @@ -0,0 +1,15 @@ +//--from +func TestWriteHeapDumpNonempty(t *testing.T) { +//--to +func TestWriteHeapDumpNonempty(t *testing.T) { + t.Skip("file is not supported in this environment") +//--from +func TestWriteHeapDumpFinalizers(t *testing.T) { +//--to +func TestWriteHeapDumpFinalizers(t *testing.T) { + t.Skip("file is not supported in this environment") +//--from +func TestWriteHeapDumpTypeName(t *testing.T) { +//--to +func TestWriteHeapDumpTypeName(t *testing.T) { + t.Skip("file is not supported in this environment") diff --git a/1.23_linux/runtime/debug/panic_test.go.patch b/1.23_linux/runtime/debug/panic_test.go.patch new file mode 100644 index 0000000..03f6ea3 --- /dev/null +++ b/1.23_linux/runtime/debug/panic_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestPanicOnFault(t *testing.T) { +//--to +func TestPanicOnFault(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/runtime/debug_test.go.patch b/1.23_linux/runtime/debug_test.go.patch new file mode 100644 index 0000000..5e631fc --- /dev/null +++ b/1.23_linux/runtime/debug_test.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build (amd64 || arm64 || ppc64le) && linux && !race +//--to +//go:build ignore diff --git a/1.23_linux/runtime/export_unix_test.go b/1.23_linux/runtime/export_unix_test.go new file mode 100644 index 0000000..b4e8769 --- /dev/null +++ b/1.23_linux/runtime/export_unix_test.go @@ -0,0 +1,13 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:build unix + +package runtime + +const ( + O_WRONLY = _O_WRONLY + O_CREAT = _O_CREAT + O_TRUNC = _O_TRUNC +) diff --git a/1.23_linux/runtime/fds_unix.go.patch b/1.23_linux/runtime/fds_unix.go.patch new file mode 100644 index 0000000..9725160 --- /dev/null +++ b/1.23_linux/runtime/fds_unix.go.patch @@ -0,0 +1,5 @@ +//--from +func checkfds() { +//--to +func checkfds() { + return diff --git a/1.23_linux/runtime/mem_linux.go b/1.23_linux/runtime/mem_linux.go new file mode 100644 index 0000000..8af3047 --- /dev/null +++ b/1.23_linux/runtime/mem_linux.go @@ -0,0 +1,83 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This implementation is the most fundamental and minimal allocations like Wasm. +// Malloced memory regions are never freed. + +package runtime + +import ( + "internal/abi" + "unsafe" +) + +// Don't split the stack as this method may be invoked without a valid G, which +// prevents us from allocating more stack. +// +//go:nosplit +//go:cgo_unsafe_args +func sysAllocOS(n uintptr) (ptr unsafe.Pointer) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysAllocOS_trampoline)), unsafe.Pointer(&n)) + return +} +func sysAllocOS_trampoline(n uintptr, size uintptr) uintptr + +//go:nosplit +//go:cgo_unsafe_args +func sysUnusedOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysUnusedOS_trampoline)), unsafe.Pointer(&v)) +} +func sysUnusedOS_trampoline(n uintptr, size uintptr) + +//go:nosplit +//go:cgo_unsafe_args +func sysUsedOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysUsedOS_trampoline)), unsafe.Pointer(&v)) +} +func sysUsedOS_trampoline(n uintptr, size uintptr) + +//go:nosplit +//go:cgo_unsafe_args +func sysHugePageOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysHugePageOS_trampoline)), unsafe.Pointer(&v)) +} +func sysHugePageOS_trampoline(n uintptr, size uintptr) + +func sysNoHugePageOS(v unsafe.Pointer, n uintptr) { +} + +func sysHugePageCollapseOS(v unsafe.Pointer, n uintptr) { +} + +// Don't split the stack as this function may be invoked without a valid G, +// which prevents us from allocating more stack. +// +//go:nosplit +//go:cgo_unsafe_args +func sysFreeOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysFreeOS_trampoline)), unsafe.Pointer(&v)) +} +func sysFreeOS_trampoline(n uintptr, size uintptr) + +//go:nosplit +//go:cgo_unsafe_args +func sysFaultOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysFaultOS_trampoline)), unsafe.Pointer(&v)) +} +func sysFaultOS_trampoline(n uintptr, size uintptr) + +//go:nosplit +//go:cgo_unsafe_args +func sysReserveOS(v unsafe.Pointer, n uintptr) (ptr unsafe.Pointer) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysReserveOS_trampoline)), unsafe.Pointer(&v)) + return +} +func sysReserveOS_trampoline(n uintptr, size uintptr) uintptr + +//go:nosplit +//go:cgo_unsafe_args +func sysMapOS(v unsafe.Pointer, n uintptr) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(sysMapOS_trampoline)), unsafe.Pointer(&v)) +} +func sysMapOS_trampoline(n uintptr, size uintptr) diff --git a/1.23_linux/runtime/memmove_linux_amd64_test.go.patch b/1.23_linux/runtime/memmove_linux_amd64_test.go.patch new file mode 100644 index 0000000..4cc7b98 --- /dev/null +++ b/1.23_linux/runtime/memmove_linux_amd64_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestMemmoveOverflow(t *testing.T) { +//--to +func TestMemmoveOverflow(t *testing.T) { + t.Skip("file is not supported in this environment") diff --git a/1.23_linux/runtime/metrics_test.go.patch b/1.23_linux/runtime/metrics_test.go.patch new file mode 100644 index 0000000..37953a9 --- /dev/null +++ b/1.23_linux/runtime/metrics_test.go.patch @@ -0,0 +1,7 @@ +//--from + name: "runtime/debug.WriteHeapDump", + fn: func(t *testing.T) { +//--to + name: "runtime/debug.WriteHeapDump", + fn: func(t *testing.T) { + t.Skip("debug.WriteHeapDump is not supported in this environment") diff --git a/1.23_linux/runtime/nbpipe_pipe2.go.patch b/1.23_linux/runtime/nbpipe_pipe2.go.patch new file mode 100644 index 0000000..5549d59 --- /dev/null +++ b/1.23_linux/runtime/nbpipe_pipe2.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build dragonfly || freebsd || linux || netbsd || openbsd || solaris +//--to +//go:build dragonfly || freebsd || netbsd || openbsd || solaris diff --git a/1.23_linux/runtime/nbpipe_test.go.patch b/1.23_linux/runtime/nbpipe_test.go.patch new file mode 100644 index 0000000..4d16792 --- /dev/null +++ b/1.23_linux/runtime/nbpipe_test.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build unix +//--to +//go:build unix && !linux diff --git a/1.23_linux/runtime/netpoll_epoll.go.patch b/1.23_linux/runtime/netpoll_epoll.go.patch new file mode 100644 index 0000000..b294f41 --- /dev/null +++ b/1.23_linux/runtime/netpoll_epoll.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build linux +//--to +//go:build ignore diff --git a/1.23_linux/runtime/netpoll_fake.go.patch b/1.23_linux/runtime/netpoll_fake.go.patch new file mode 100644 index 0000000..1e22240 --- /dev/null +++ b/1.23_linux/runtime/netpoll_fake.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build js && wasm +//--to +//go:build linux diff --git a/1.23_linux/runtime/norace_linux_test.go.patch b/1.23_linux/runtime/norace_linux_test.go.patch new file mode 100644 index 0000000..4b4ce8c --- /dev/null +++ b/1.23_linux/runtime/norace_linux_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestNewOSProc0(t *testing.T) { +//--to +func TestNewOSProc0(t *testing.T) { + t.Skip("newosproc0 is not supported in this environment") diff --git a/1.23_linux/runtime/os_linux.go.patch b/1.23_linux/runtime/os_linux.go.patch new file mode 100644 index 0000000..83a7085 --- /dev/null +++ b/1.23_linux/runtime/os_linux.go.patch @@ -0,0 +1,318 @@ +//--from +import ( + "internal/abi" + "internal/goarch" + "internal/runtime/atomic" + "internal/runtime/syscall" + "unsafe" +) +//--to +import ( + "internal/abi" + "internal/runtime/atomic" + "internal/runtime/syscall" + "unsafe" +) +//--from +//go:noescape +func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func futex(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32 { + ret := libcCall(unsafe.Pointer(abi.FuncPCABI0(futex_trampoline)), unsafe.Pointer(&addr)) + return ret +} +func futex_trampoline(addr unsafe.Pointer, op int32, val uint32, ts, addr2 unsafe.Pointer, val3 uint32) int32 +//--from +func sysargs(argc int32, argv **byte) { + n := argc + 1 + + // skip over argv, envp to get to auxv + for argv_index(argv, n) != nil { + n++ + } + + // skip NULL separator + n++ + + // now argv+n is auxv + auxvp := (*[1 << 28]uintptr)(add(unsafe.Pointer(argv), uintptr(n)*goarch.PtrSize)) + + if pairs := sysauxv(auxvp[:]); pairs != 0 { + auxv = auxvp[: pairs*2 : pairs*2] + return + } + // In some situations we don't get a loader-provided + // auxv, such as when loaded as a library on Android. + // Fall back to /proc/self/auxv. + fd := open(&procAuxv[0], 0 /* O_RDONLY */, 0) + if fd < 0 { + // On Android, /proc/self/auxv might be unreadable (issue 9229), so we fallback to + // try using mincore to detect the physical page size. + // mincore should return EINVAL when address is not a multiple of system page size. + const size = 256 << 10 // size of memory region to allocate + p, err := mmap(nil, size, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0) + if err != 0 { + return + } + var n uintptr + for n = 4 << 10; n < size; n <<= 1 { + err := mincore(unsafe.Pointer(uintptr(p)+n), 1, &addrspace_vec[0]) + if err == 0 { + physPageSize = n + break + } + } + if physPageSize == 0 { + physPageSize = size + } + munmap(p, size) + return + } + + n = read(fd, noescape(unsafe.Pointer(&auxvreadbuf[0])), int32(unsafe.Sizeof(auxvreadbuf))) + closefd(fd) + if n < 0 { + return + } + // Make sure buf is terminated, even if we didn't read + // the whole file. + auxvreadbuf[len(auxvreadbuf)-2] = _AT_NULL + pairs := sysauxv(auxvreadbuf[:]) + auxv = auxvreadbuf[: pairs*2 : pairs*2] +} +//--to +func sysargs(argc int32, argv **byte) { + // argc/argv is not reliable on some machines. + // Skip analysing them. + + // In some situations we don't get a loader-provided + // auxv, such as when loaded as a library on Android. + // Fall back to /proc/self/auxv. + fd := open(&procAuxv[0], 0 /* O_RDONLY */, 0) + if fd < 0 { + // On Android, /proc/self/auxv might be unreadable (issue 9229), so we fallback to + // try using mincore to detect the physical page size. + // mincore should return EINVAL when address is not a multiple of system page size. + const size = 256 << 10 // size of memory region to allocate + p, err := mmap(nil, size, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0) + if err != 0 { + return + } + var n uintptr + for n = 4 << 10; n < size; n <<= 1 { + err := mincore(unsafe.Pointer(uintptr(p)+n), 1, &addrspace_vec[0]) + if err == 0 { + physPageSize = n + break + } + } + if physPageSize == 0 { + physPageSize = size + } + munmap(p, size) + return + } + + n := read(fd, noescape(unsafe.Pointer(&auxvreadbuf[0])), int32(unsafe.Sizeof(auxvreadbuf))) + closefd(fd) + if n < 0 { + return + } + // Make sure buf is terminated, even if we didn't read + // the whole file. + auxvreadbuf[len(auxvreadbuf)-2] = _AT_NULL + pairs := sysauxv(auxvreadbuf[:]) + auxv = auxvreadbuf[: pairs*2 : pairs*2] +} +//--from +var urandom_dev = []byte("/dev/urandom\x00") + +func readRandom(r []byte) int { + fd := open(&urandom_dev[0], 0 /* O_RDONLY */, 0) + n := read(fd, unsafe.Pointer(&r[0]), int32(len(r))) + closefd(fd) + return int(n) +} +//--to +//go:nosplit +func readRandom(r []byte) int { + return 0 +} +//--from +func gettid() uint32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func gettid() (tid uint32) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(gettid_trampoline)), unsafe.Pointer(&tid)) + return +} +func gettid_trampoline() uint32 +//--from +//go:noescape +func sigaltstack(new, old *stackt) +//--to +func sigaltstack(new, old *stackt) { + // Do nothing. +} +//--from +func sigprocmask(how int32, new, old *sigset) { + rtsigprocmask(how, new, old, int32(unsafe.Sizeof(*new))) +} +//--to +func sigprocmask(how int32, new, old *sigset) { + // Do nothing. + // rtsigprocmask(how, new, old, int32(unsafe.Sizeof(*new))) +} +//--from +func raise(sig uint32) +//--to +func raise(sig uint32) { + // Do nothing +} +//--from +func raiseproc(sig uint32) +//--to +func raiseproc(sig uint32) { + // Do nothing +} +//--from +//go:noescape +func sched_getaffinity(pid, len uintptr, buf *byte) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func sched_getaffinity(pid, len uintptr, buf *byte) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(sched_getaffinity_trampoline)), unsafe.Pointer(&pid)) +} +func sched_getaffinity_trampoline(pid, len uintptr, buf *byte) int32 +//--from +func osyield() +//--to +//go:nosplit +//go:cgo_unsafe_args +func osyield() { + libcCall(unsafe.Pointer(abi.FuncPCABI0(osyield_trampoline)), nil) +} +func osyield_trampoline() +//--from +func sysSigaction(sig uint32, new, old *sigactiont) { +//--to +func sysSigaction(sig uint32, new, old *sigactiont) { + // Do nothing. + return +//--from +func signalM(mp *m, sig int) { + tgkill(getpid(), int(mp.procid), sig) +} +//--to +func signalM(mp *m, sig int) { + // Do nothiing. +} +//--from +func runPerThreadSyscall() { + gp := getg() + if gp.m.needPerThreadSyscall.Load() == 0 { + return + } + + args := perThreadSyscall + r1, r2, errno := syscall.Syscall6(args.trap, args.a1, args.a2, args.a3, args.a4, args.a5, args.a6) + if GOARCH == "ppc64" || GOARCH == "ppc64le" { + // TODO(https://go.dev/issue/51192 ): ppc64 doesn't use r2. + r2 = 0 + } + if errno != 0 || r1 != args.r1 || r2 != args.r2 { + print("trap:", args.trap, ", a123456=[", args.a1, ",", args.a2, ",", args.a3, ",", args.a4, ",", args.a5, ",", args.a6, "]\n") + print("results: got {r1=", r1, ",r2=", r2, ",errno=", errno, "}, want {r1=", args.r1, ",r2=", args.r2, ",errno=0}\n") + fatal("AllThreadsSyscall6 results differ between threads; runtime corrupted") + } + + gp.m.needPerThreadSyscall.Store(0) +} +//--to +func runPerThreadSyscall() { + // Do nothing. + // needPerThreadSyscall should never be 1 as syscall_runtime_doAllThreadsSyscall is not available with Cgo. +} +//--append +//go:linkname hitsumabushi_closefd hitsumabushi_closefd +//go:cgo_import_static hitsumabushi_closefd +var hitsumabushi_closefd byte + +//go:linkname hitsumabushi_exit hitsumabushi_exit +//go:cgo_import_static hitsumabushi_exit +var hitsumabushi_exit byte + +//go:linkname hitsumabushi_gettid hitsumabushi_gettid +//go:cgo_import_static hitsumabushi_gettid +var hitsumabushi_gettid byte + +//go:linkname hitsumabushi_nanotime1 hitsumabushi_nanotime1 +//go:cgo_import_static hitsumabushi_nanotime1 +var hitsumabushi_nanotime1 byte + +//go:linkname hitsumabushi_open hitsumabushi_open +//go:cgo_import_static hitsumabushi_open +var hitsumabushi_open byte + +//go:linkname hitsumabushi_osyield hitsumabushi_osyield +//go:cgo_import_static hitsumabushi_osyield +var hitsumabushi_osyield byte + +//go:linkname hitsumabushi_read hitsumabushi_read +//go:cgo_import_static hitsumabushi_read +var hitsumabushi_read byte + +//go:linkname hitsumabushi_sched_getaffinity hitsumabushi_sched_getaffinity +//go:cgo_import_static hitsumabushi_sched_getaffinity +var hitsumabushi_sched_getaffinity byte + +//go:linkname hitsumabushi_usleep hitsumabushi_usleep +//go:cgo_import_static hitsumabushi_usleep +var hitsumabushi_usleep byte + +//go:linkname hitsumabushi_walltime1 hitsumabushi_walltime1 +//go:cgo_import_static hitsumabushi_walltime1 +var hitsumabushi_walltime1 byte + +//go:linkname hitsumabushi_write1 hitsumabushi_write1 +//go:cgo_import_static hitsumabushi_write1 +var hitsumabushi_write1 byte + +//go:nosplit +//go:cgo_unsafe_args +func fcntl1(fd, cmd, arg int) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(fcntl_trampoline)), unsafe.Pointer(&fd)) +} +func fcntl_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func fstat1(fd int, stat unsafe.Pointer) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(fstat_trampoline)), unsafe.Pointer(&fd)) +} +func fstat_trampoline(fd int, stat unsafe.Pointer) int32 + +//go:nosplit +//go:cgo_unsafe_args +func lseek1(fd int, offset int64, whence int) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(lseek_trampoline)), unsafe.Pointer(&fd)) +} +func lseek_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func renameat(fd1 int, name1 unsafe.Pointer, fd2 int, name2 unsafe.Pointer) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(renameat_trampoline)), unsafe.Pointer(&fd1)) +} +func renameat_trampoline() + +//go:nosplit +//go:cgo_unsafe_args +func fstatat(fd uintptr, name unsafe.Pointer, p unsafe.Pointer, n int32) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(fstatat_trampoline)), unsafe.Pointer(&fd)) +} +func fstatat_trampoline() diff --git a/1.23_linux/runtime/panicnil_test.go.patch b/1.23_linux/runtime/panicnil_test.go.patch new file mode 100644 index 0000000..54cb49e --- /dev/null +++ b/1.23_linux/runtime/panicnil_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestPanicNil(t *testing.T) { +//--to +func TestPanicNil(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/runtime/proc_test.go.patch b/1.23_linux/runtime/proc_test.go.patch new file mode 100644 index 0000000..478b6b3 --- /dev/null +++ b/1.23_linux/runtime/proc_test.go.patch @@ -0,0 +1,14 @@ +//--from +func TestGoroutineParallelism2(t *testing.T) { + //testGoroutineParallelism2(t, false, false) + testGoroutineParallelism2(t, true, false) + testGoroutineParallelism2(t, false, true) + testGoroutineParallelism2(t, true, true) +} +//--to +func TestGoroutineParallelism2(t *testing.T) { + //testGoroutineParallelism2(t, false, false) + testGoroutineParallelism2(t, true, false) + //testGoroutineParallelism2(t, false, true) + //testGoroutineParallelism2(t, true, true) +} diff --git a/1.23_linux/runtime/rand_test.go.patch b/1.23_linux/runtime/rand_test.go.patch new file mode 100644 index 0000000..84e79b4 --- /dev/null +++ b/1.23_linux/runtime/rand_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestReadRandom(t *testing.T) { +//--to +func TestReadRandom(t *testing.T) { + t.Skip("readRandom is not available in this environment") diff --git a/1.23_linux/runtime/runtime1.go.patch b/1.23_linux/runtime/runtime1.go.patch new file mode 100644 index 0000000..ec85623 --- /dev/null +++ b/1.23_linux/runtime/runtime1.go.patch @@ -0,0 +1,24 @@ +//--from +func argv_index(argv **byte, i int32) *byte { + return *(**byte)(add(unsafe.Pointer(argv), uintptr(i)*goarch.PtrSize)) +} +//--to +func argv_index(argv **byte, i int32) *byte { + return nil +} +//--from +func args(c int32, v **byte) { + argc = c + argv = v + sysargs(c, v) +} +//--to +func args(c int32, v **byte) { + // In the original code, physPageSize is determined at sysargs. + // Hitsumabushi gives an initial value for physPageSize at its declaration, so sysargs doesn't have to be called. +} +//--append +// Expose the entry point for some special environments. + +//go:cgo_export_static _rt0_amd64_linux_lib +//go:cgo_export_dynamic _rt0_amd64_linux_lib diff --git a/1.23_linux/runtime/runtime_linux_test.go.patch b/1.23_linux/runtime/runtime_linux_test.go.patch new file mode 100644 index 0000000..07c9fc3 --- /dev/null +++ b/1.23_linux/runtime/runtime_linux_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestMincoreErrorSign(t *testing.T) { +//--to +func TestMincoreErrorSign(t *testing.T) { + t.Skip("mincore is not supported in this environment") diff --git a/1.23_linux/runtime/runtime_mmap_test.go.patch b/1.23_linux/runtime/runtime_mmap_test.go.patch new file mode 100644 index 0000000..4d16792 --- /dev/null +++ b/1.23_linux/runtime/runtime_mmap_test.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build unix +//--to +//go:build unix && !linux diff --git a/1.23_linux/runtime/runtime_test.go.patch b/1.23_linux/runtime/runtime_test.go.patch new file mode 100644 index 0000000..a4cc9a5 --- /dev/null +++ b/1.23_linux/runtime/runtime_test.go.patch @@ -0,0 +1,5 @@ +//--from +func testSetPanicOnFault(t *testing.T, addr uintptr, nfault *int) { +//--to +func testSetPanicOnFault(t *testing.T, addr uintptr, nfault *int) { + t.Skip("catching faults is not supported in this environment") diff --git a/1.23_linux/runtime/runtime_unix_test.go.patch b/1.23_linux/runtime/runtime_unix_test.go.patch new file mode 100644 index 0000000..ed286ca --- /dev/null +++ b/1.23_linux/runtime/runtime_unix_test.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build aix || darwin || dragonfly || freebsd || linux || netbsd || openbsd || plan9 +//--to +//go:build aix || darwin || dragonfly || freebsd || netbsd || openbsd || plan9 diff --git a/1.23_linux/runtime/stack_test.go.patch b/1.23_linux/runtime/stack_test.go.patch new file mode 100644 index 0000000..c9c56f3 --- /dev/null +++ b/1.23_linux/runtime/stack_test.go.patch @@ -0,0 +1,10 @@ +//--from +func TestDeferLeafSigpanic(t *testing.T) { +//--to +func TestDeferLeafSigpanic(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") +//--from +func TestStackWrapperStackPanic(t *testing.T) { +//--to +func TestStackWrapperStackPanic(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/runtime/stubs2.go.patch b/1.23_linux/runtime/stubs2.go.patch new file mode 100644 index 0000000..0f1bb9d --- /dev/null +++ b/1.23_linux/runtime/stubs2.go.patch @@ -0,0 +1,78 @@ +//--from +import ( + "internal/runtime/atomic" + "unsafe" +) +//--to +import ( + "internal/abi" + "internal/runtime/atomic" + "unsafe" +) +//--from +func read(fd int32, p unsafe.Pointer, n int32) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func read(fd int32, p unsafe.Pointer, n int32) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(read_trampoline)), unsafe.Pointer(&fd)) +} +func read_trampoline(fd int32, p unsafe.Pointer, n int32) int32 +//--from +func closefd(fd int32) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func closefd(fd int32) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(closefd_trampoline)), unsafe.Pointer(&fd)) +} +func closefd_trampoline(fd int32) int32 +//--from +func exit(code int32) +//--to +//go:nosplit +//go:cgo_unsafe_args +func exit(code int32) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(exit_trampoline)), unsafe.Pointer(&code)) +} +func exit_trampoline(code int32) +//--from +func usleep(usec uint32) +//--to +//go:nosplit +//go:cgo_unsafe_args +func usleep(usec uint32) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec)) +} +func usleep_trampoline(usec uint32) +//--from +//go:nosplit +func usleep_no_g(usec uint32) { + usleep(usec) +} +//--to +//go:nosplit +//go:cgo_unsafe_args +func usleep_no_g(usec uint32) { + asmcgocall_no_g(unsafe.Pointer(abi.FuncPCABI0(usleep_trampoline)), unsafe.Pointer(&usec)) +} +//--from +//go:noescape +func write1(fd uintptr, p unsafe.Pointer, n int32) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func write1(fd uintptr, p unsafe.Pointer, n int32) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(write1_trampoline)), unsafe.Pointer(&fd)) +} +func write1_trampoline(fd uintptr, p unsafe.Pointer, n int32) int32 +//--from +//go:noescape +func open(name *byte, mode, perm int32) int32 +//--to +//go:nosplit +//go:cgo_unsafe_args +func open(name *byte, mode, perm int32) int32 { + return libcCall(unsafe.Pointer(abi.FuncPCABI0(open_trampoline)), unsafe.Pointer(&name)) +} +func open_trampoline(name *byte, mode, perm int32) int32 diff --git a/1.23_linux/runtime/stubs3.go.patch b/1.23_linux/runtime/stubs3.go.patch new file mode 100644 index 0000000..8bdc673 --- /dev/null +++ b/1.23_linux/runtime/stubs3.go.patch @@ -0,0 +1,19 @@ +//--from +package runtime +//--to +package runtime + +import ( + "internal/abi" + "unsafe" +) +//--from +func nanotime1() int64 +//--to +//go:nosplit +//go:cgo_unsafe_args +func nanotime1() (now int64) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(nanotime1_trampoline)), unsafe.Pointer(&now)) + return +} +func nanotime1_trampoline() int64 diff --git a/1.23_linux/runtime/sys_libc.go.patch b/1.23_linux/runtime/sys_libc.go.patch new file mode 100644 index 0000000..035277e --- /dev/null +++ b/1.23_linux/runtime/sys_libc.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build darwin || (openbsd && !mips64) +//--to +//go:build darwin || (openbsd && !mips64) || linux diff --git a/1.23_linux/runtime/sys_linux_amd64.s.patch b/1.23_linux/runtime/sys_linux_amd64.s.patch new file mode 100644 index 0000000..ad7efc2 --- /dev/null +++ b/1.23_linux/runtime/sys_linux_amd64.s.patch @@ -0,0 +1,480 @@ +//--from +TEXT runtime·open(SB),NOSPLIT,$0-20 + // This uses openat instead of open, because Android O blocks open. + MOVL $AT_FDCWD, DI // AT_FDCWD, so this acts like open + MOVQ name+0(FP), SI + MOVL mode+8(FP), DX + MOVL perm+12(FP), R10 + MOVL $SYS_openat, AX + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 2(PC) + MOVL $-1, AX + MOVL AX, ret+16(FP) + RET +//--to +TEXT runtime·open_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX // BX is callee-saved + MOVL 8(DI), SI // arg 2 flags + MOVL 12(DI), DX // arg 3 mode + MOVQ 0(DI), DI // arg 1 pathname + XORL AX, AX // vararg: say "no float args" + CALL hitsumabushi_open(SB) + MOVQ AX, 16(BX) + POPQ BP + RET +//--from +TEXT runtime·futex(SB),NOSPLIT,$0 + MOVQ addr+0(FP), DI + MOVL op+8(FP), SI + MOVL val+12(FP), DX + MOVQ ts+16(FP), R10 + MOVQ addr2+24(FP), R8 + MOVL val3+32(FP), R9 + MOVL $SYS_futex, AX + SYSCALL + MOVL AX, ret+40(FP) + RET +//--to +TEXT runtime·futex_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 0(BX), DI // arg 1 addr + MOVL 8(BX), SI // arg 2 op + MOVL 12(BX), DX // arg 3 val + MOVQ 16(BX), CX // arg 4 ts + MOVQ 24(BX), R8 // arg 5 addr2 + MOVL 32(BX), R9 // arg 6 val3 + CALL hitsumabushi_futex(SB) + MOVL AX, 40(BX) + POPQ BP + RET +//--from +TEXT runtime·exit(SB),NOSPLIT,$0-4 + MOVL code+0(FP), DI + MOVL $SYS_exit_group, AX + SYSCALL + RET +//--to +TEXT runtime·exit_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 exit status + CALL hitsumabushi_exit(SB) + MOVL $0xf1, 0xf1 // crash + POPQ BP + RET +//--from +TEXT runtime·read(SB),NOSPLIT,$0-28 + MOVL fd+0(FP), DI + MOVQ p+8(FP), SI + MOVL n+16(FP), DX + MOVL $SYS_read, AX + SYSCALL + MOVL AX, ret+24(FP) + RET +//--to +TEXT runtime·read_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX // BX is callee-saved + MOVQ 0(BX), DI // arg 1 fd + MOVQ 8(BX), SI // arg 2 buf + MOVQ 16(BX), DX // arg 3 count + CALL hitsumabushi_read(SB) + MOVQ AX, 24(BX) // return value + POPQ BP + RET +//--from +TEXT runtime·closefd(SB),NOSPLIT,$0-12 + MOVL fd+0(FP), DI + MOVL $SYS_close, AX + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 2(PC) + MOVL $-1, AX + MOVL AX, ret+8(FP) + RET +//--to +TEXT runtime·closefd_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 fd + CALL hitsumabushi_closefd(SB) + POPQ BP + RET +//--from +TEXT runtime·gettid(SB),NOSPLIT,$0-4 + MOVL $SYS_gettid, AX + SYSCALL + MOVL AX, ret+0(FP) + RET +//--to +TEXT runtime·gettid_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + CALL hitsumabushi_gettid(SB) + POPQ BP + RET +//--from +TEXT runtime·sigaltstack(SB),NOSPLIT,$0 + MOVQ new+0(FP), DI + MOVQ old+8(FP), SI + MOVQ $SYS_sigaltstack, AX + SYSCALL + CMPQ AX, $0xfffffffffffff001 + JLS 2(PC) + MOVL $0xf1, 0xf1 // crash + RET +//--to +TEXT runtime·sigaltstack_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 old + MOVQ 0(DI), DI // arg 1 new + CALL hitsumabushi_sigaltstack(SB) + TESTQ AX, AX + JEQ 2(PC) + MOVL $0xf1, 0xf1 // crash + POPQ BP + RET +//--from +TEXT runtime·raise(SB),NOSPLIT,$0 + MOVL $SYS_getpid, AX + SYSCALL + MOVL AX, R12 + MOVL $SYS_gettid, AX + SYSCALL + MOVL AX, SI // arg 2 tid + MOVL R12, DI // arg 1 pid + MOVL sig+0(FP), DX // arg 3 + MOVL $SYS_tgkill, AX + SYSCALL + RET +//--to +TEXT runtime·raise_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 signal + CALL hitsumabushi_raise(SB) + POPQ BP + RET +//--from +TEXT runtime·raiseproc(SB),NOSPLIT,$0 + MOVL $SYS_getpid, AX + SYSCALL + MOVL AX, DI // arg 1 pid + MOVL sig+0(FP), SI // arg 2 + MOVL $SYS_kill, AX + SYSCALL + RET +//--to +TEXT runtime·raiseproc_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), BX // signal + CALL hitsumabushi_getpid(SB) + MOVL AX, DI // arg 1 pid + MOVL BX, SI // arg 2 signal + CALL hitsumabushi_kill(SB) + POPQ BP + RET +//--from +TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0 + MOVQ pid+0(FP), DI + MOVQ len+8(FP), SI + MOVQ buf+16(FP), DX + MOVL $SYS_sched_getaffinity, AX + SYSCALL + MOVL AX, ret+24(FP) + RET +//--to +TEXT runtime·sched_getaffinity_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 len + MOVQ 16(DI), DX // arg 3 buf + MOVQ 0(DI), DI // arg 1 pid + CALL hitsumabushi_sched_getaffinity(SB) + POPQ BP + RET +//--from +TEXT runtime·osyield(SB),NOSPLIT,$0 + MOVL $SYS_sched_yield, AX + SYSCALL + RET +//--to +TEXT runtime·osyield_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + CALL hitsumabushi_osyield(SB) + POPQ BP + RET +//--from +TEXT runtime·usleep(SB),NOSPLIT,$16 + MOVL $0, DX + MOVL usec+0(FP), AX + MOVL $1000000, CX + DIVL CX + MOVQ AX, 0(SP) + MOVL $1000, AX // usec to nsec + MULL DX + MOVQ AX, 8(SP) + + // nanosleep(&ts, 0) + MOVQ SP, DI + MOVL $0, SI + MOVL $SYS_nanosleep, AX + SYSCALL + RET +//--to +TEXT runtime·usleep_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVL 0(DI), DI // arg 1 usec + CALL hitsumabushi_usleep(SB) + POPQ BP + RET +//--from +TEXT runtime·write1(SB),NOSPLIT,$0-28 + MOVQ fd+0(FP), DI + MOVQ p+8(FP), SI + MOVL n+16(FP), DX + MOVL $SYS_write, AX + SYSCALL + MOVL AX, ret+24(FP) + RET +//--to +TEXT runtime·write1_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 p + MOVQ 16(DI), DX // arg 3 n + MOVQ 0(DI), DI // arg 1 fd + CALL hitsumabushi_write1(SB) + POPQ BP + RET +//--from +TEXT runtime·nanotime1(SB),NOSPLIT,$16-8 + // We don't know how much stack space the VDSO code will need, + // so switch to g0. + // In particular, a kernel configured with CONFIG_OPTIMIZE_INLINING=n + // and hardening can use a full page of stack space in gettime_sym + // due to stack probes inserted to avoid stack/heap collisions. + // See issue #20427. + + MOVQ SP, R12 // Save old SP; R12 unchanged by C code. + + MOVQ g_m(R14), BX // BX unchanged by C code. + + // Set vdsoPC and vdsoSP for SIGPROF traceback. + // Save the old values on stack and restore them on exit, + // so this function is reentrant. + MOVQ m_vdsoPC(BX), CX + MOVQ m_vdsoSP(BX), DX + MOVQ CX, 0(SP) + MOVQ DX, 8(SP) + + LEAQ ret+0(FP), DX + MOVQ -8(DX), CX + MOVQ CX, m_vdsoPC(BX) + MOVQ DX, m_vdsoSP(BX) + + CMPQ R14, m_curg(BX) // Only switch if on curg. + JNE noswitch + + MOVQ m_g0(BX), DX + MOVQ (g_sched+gobuf_sp)(DX), SP // Set SP to g0 stack + +noswitch: + SUBQ $16, SP // Space for results + ANDQ $~15, SP // Align for C code + + MOVL $1, DI // CLOCK_MONOTONIC + LEAQ 0(SP), SI + MOVQ runtime·vdsoClockgettimeSym(SB), AX + CMPQ AX, $0 + JEQ fallback + CALL AX +ret: + MOVQ 0(SP), AX // sec + MOVQ 8(SP), DX // nsec + MOVQ R12, SP // Restore real SP + // Restore vdsoPC, vdsoSP + // We don't worry about being signaled between the two stores. + // If we are not in a signal handler, we'll restore vdsoSP to 0, + // and no one will care about vdsoPC. If we are in a signal handler, + // we cannot receive another signal. + MOVQ 8(SP), CX + MOVQ CX, m_vdsoSP(BX) + MOVQ 0(SP), CX + MOVQ CX, m_vdsoPC(BX) + // sec is in AX, nsec in DX + // return nsec in AX + IMULQ $1000000000, AX + ADDQ DX, AX + MOVQ AX, ret+0(FP) + RET +fallback: + MOVQ $SYS_clock_gettime, AX + SYSCALL + JMP ret +//--to +TEXT runtime·nanotime1_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ DI, BX // BX is callee-saved + MOVQ SP, BP + CALL hitsumabushi_nanotime1(SB) + MOVQ AX, 0(BX) + POPQ BP + RET +//--append +TEXT runtime·sysAllocOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 0(DI), DI + CALL hitsumabushi_sysAllocOS(SB) + MOVQ AX, 8(BX) + POPQ BP + RET + +TEXT runtime·sysUnusedOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysUnusedOS(SB) + POPQ BP + RET + +TEXT runtime·sysUsedOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysUsedOS(SB) + POPQ BP + RET + +TEXT runtime·sysHugePageOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysHugePageOS(SB) + POPQ BP + RET + +TEXT runtime·sysFreeOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysFreeOS(SB) + POPQ BP + RET + +TEXT runtime·sysFaultOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysFaultOS(SB) + POPQ BP + RET + +TEXT runtime·sysReserveOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX // BX is callee-saved + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysReserveOS(SB) + MOVQ AX, 16(BX) + POPQ BP + RET + +TEXT runtime·sysMapOS_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_sysMapOS(SB) + POPQ BP + RET + +TEXT runtime·walltime1_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX // BX is callee-saved + MOVQ 8(DI), SI + MOVQ 0(DI), DI + CALL hitsumabushi_walltime1(SB) + MOVQ AX, 16(BX) // return value + POPQ BP + RET + +TEXT runtime·fcntl_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ 8(DI), SI // arg 2 cmd + MOVQ 16(DI), DX // arg 3 arg + MOVQ 0(DI), DI // arg 1 fd + XORL AX, AX // vararg: say "no float args" + CALL hitsumabushi_fcntl(SB) + POPQ BP + RET + +TEXT runtime·fstat_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 8(DI), SI // arg 2 stat + MOVQ 0(DI), DI // arg 1 fd + CALL hitsumabushi_fstat(SB) + MOVQ AX, 16(BX) // return value + POPQ BP + RET + +TEXT runtime·lseek_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 8(DI), SI // arg 2 offset + MOVQ 16(DI), DX // arg 3 whence + MOVQ 0(DI), DI // arg 1 fd + XORL AX, AX // vararg: say "no float args" + CALL hitsumabushi_lseek(SB) + MOVQ AX, 24(BX) // return value + POPQ BP + RET + +TEXT runtime·renameat_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 0(BX), DI // arg 1 + MOVQ 8(BX), SI // arg 2 + MOVQ 16(BX), DX // arg 3 + MOVQ 24(BX), CX // arg 4 + CALL hitsumabushi_renameat(SB) + MOVL AX, 32(BX) + POPQ BP + RET + +TEXT runtime·fstatat_trampoline(SB),NOSPLIT|NOFRAME,$0 + PUSHQ BP + MOVQ SP, BP + MOVQ DI, BX + MOVQ 0(BX), DI // arg 1 + MOVQ 8(BX), SI // arg 2 + MOVQ 16(BX), DX // arg 3 + MOVQ 24(BX), CX // arg 4 + CALL hitsumabushi_fstatat(SB) + MOVL AX, 32(BX) + POPQ BP + RET diff --git a/1.23_linux/runtime/sys_linux_arm64.s.patch b/1.23_linux/runtime/sys_linux_arm64.s.patch new file mode 100644 index 0000000..a193e0a --- /dev/null +++ b/1.23_linux/runtime/sys_linux_arm64.s.patch @@ -0,0 +1,549 @@ +//--from +#define SYS_exit 93 +#define SYS_read 63 +#define SYS_write 64 +#define SYS_openat 56 +#define SYS_close 57 +#define SYS_pipe2 59 +#define SYS_nanosleep 101 +#define SYS_mmap 222 +#define SYS_munmap 215 +#define SYS_setitimer 103 +#define SYS_clone 220 +#define SYS_sched_yield 124 +#define SYS_rt_sigreturn 139 +#define SYS_rt_sigaction 134 +#define SYS_rt_sigprocmask 135 +#define SYS_sigaltstack 132 +#define SYS_madvise 233 +#define SYS_mincore 232 +#define SYS_getpid 172 +#define SYS_gettid 178 +#define SYS_kill 129 +#define SYS_tgkill 131 +#define SYS_futex 98 +#define SYS_sched_getaffinity 123 +#define SYS_exit_group 94 +#define SYS_clock_gettime 113 +#define SYS_faccessat 48 +#define SYS_socket 198 +#define SYS_connect 203 +#define SYS_brk 214 +#define SYS_timer_create 107 +#define SYS_timer_settime 110 +#define SYS_timer_delete 111 +//--to +#define SYS_exit 2147483647 +#define SYS_read 2147483647 +#define SYS_write 2147483647 +#define SYS_openat 2147483647 +#define SYS_close 2147483647 +#define SYS_pipe2 2147483647 +#define SYS_nanosleep 2147483647 +#define SYS_mmap 2147483647 +#define SYS_munmap 2147483647 +#define SYS_setitimer 2147483647 +#define SYS_clone 2147483647 +#define SYS_sched_yield 2147483647 +#define SYS_rt_sigreturn 2147483647 +#define SYS_rt_sigaction 2147483647 +#define SYS_rt_sigprocmask 2147483647 +#define SYS_sigaltstack 2147483647 +#define SYS_madvise 2147483647 +#define SYS_mincore 2147483647 +#define SYS_getpid 2147483647 +#define SYS_gettid 2147483647 +#define SYS_kill 2147483647 +#define SYS_tgkill 2147483647 +#define SYS_futex 2147483647 +#define SYS_sched_getaffinity 2147483647 +#define SYS_exit_group 2147483647 +#define SYS_clock_gettime 2147483647 +#define SYS_faccessat 2147483647 +#define SYS_socket 2147483647 +#define SYS_connect 2147483647 +#define SYS_brk 2147483647 +#define SYS_timer_create 2147483647 +#define SYS_timer_settime 2147483647 +#define SYS_timer_delete 2147483647 +//--from +TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4 + MOVW code+0(FP), R0 + MOVD $SYS_exit_group, R8 + SVC + RET +//--to +TEXT runtime·exit_trampoline(SB),NOSPLIT,$0 + MOVW 0(R0), R0 + BL hitsumabushi_exit(SB) + RET +//--from +TEXT runtime·open(SB),NOSPLIT|NOFRAME,$0-20 + MOVD $AT_FDCWD, R0 + MOVD name+0(FP), R1 + MOVW mode+8(FP), R2 + MOVW perm+12(FP), R3 + MOVD $SYS_openat, R8 + SVC + CMN $4095, R0 + BCC done + MOVW $-1, R0 +done: + MOVW R0, ret+16(FP) + RET +//--to +TEXT runtime·open_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 + MOVW 12(R0), R2 + MOVD 0(R0), R0 + BL hitsumabushi_open(SB) + RET +//--from +TEXT runtime·closefd(SB),NOSPLIT|NOFRAME,$0-12 + MOVW fd+0(FP), R0 + MOVD $SYS_close, R8 + SVC + CMN $4095, R0 + BCC done + MOVW $-1, R0 +done: + MOVW R0, ret+8(FP) + RET +//--to +TEXT runtime·closefd_trampoline(SB),NOSPLIT,$0-12 + MOVW 0(R0), R0 + BL hitsumabushi_closefd(SB) + RET +//--from +TEXT runtime·write1(SB),NOSPLIT|NOFRAME,$0-28 + MOVD fd+0(FP), R0 + MOVD p+8(FP), R1 + MOVW n+16(FP), R2 + MOVD $SYS_write, R8 + SVC + MOVW R0, ret+24(FP) + RET +//--to +TEXT runtime·write1_trampoline(SB),NOSPLIT,$0-28 + MOVD 8(R0), R1 + MOVW 16(R0), R2 + MOVD 0(R0), R0 + BL hitsumabushi_write1(SB) + RET +//--from +TEXT runtime·read(SB),NOSPLIT|NOFRAME,$0-28 + MOVW fd+0(FP), R0 + MOVD p+8(FP), R1 + MOVW n+16(FP), R2 + MOVD $SYS_read, R8 + SVC + MOVW R0, ret+24(FP) + RET +//--to +TEXT runtime·read_trampoline(SB),NOSPLIT,$0-28 + MOVD 8(R0), R1 + MOVW 16(R0), R2 + MOVW 0(R0), R0 + BL hitsumabushi_read(SB) + RET +//--from +TEXT runtime·usleep(SB),NOSPLIT,$24-4 + MOVWU usec+0(FP), R3 + MOVD R3, R5 + MOVW $1000000, R4 + UDIV R4, R3 + MOVD R3, 8(RSP) + MUL R3, R4 + SUB R4, R5 + MOVW $1000, R4 + MUL R4, R5 + MOVD R5, 16(RSP) + + // nanosleep(&ts, 0) + ADD $8, RSP, R0 + MOVD $0, R1 + MOVD $SYS_nanosleep, R8 + SVC + RET +//--to +TEXT runtime·usleep_trampoline(SB),NOSPLIT,$0 + MOVW 0(R0), R0 + BL hitsumabushi_usleep(SB) + RET +//--from +TEXT runtime·gettid(SB),NOSPLIT,$0-4 + MOVD $SYS_gettid, R8 + SVC + MOVW R0, ret+0(FP) + RET +//--to +TEXT runtime·gettid_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + BL hitsumabushi_gettid(SB) + MOVW R0, 0(R19) // return value + RET +//--from +TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + MOVD $SYS_getpid, R8 + SVC + MOVW R0, R19 + MOVD $SYS_gettid, R8 + SVC + MOVW R0, R1 // arg 2 tid + MOVW R19, R0 // arg 1 pid + MOVW sig+0(FP), R2 // arg 3 + MOVD $SYS_tgkill, R8 + SVC + RET +//--to +//--from +TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0 + MOVD $SYS_getpid, R8 + SVC + MOVW R0, R0 // arg 1 pid + MOVW sig+0(FP), R1 // arg 2 + MOVD $SYS_kill, R8 + SVC + RET +//--to +//--from +TEXT runtime·walltime(SB),NOSPLIT,$24-12 + MOVD RSP, R20 // R20 is unchanged by C code + MOVD RSP, R1 + + MOVD g_m(g), R21 // R21 = m + + // Set vdsoPC and vdsoSP for SIGPROF traceback. + // Save the old values on stack and restore them on exit, + // so this function is reentrant. + MOVD m_vdsoPC(R21), R2 + MOVD m_vdsoSP(R21), R3 + MOVD R2, 8(RSP) + MOVD R3, 16(RSP) + + MOVD $ret-8(FP), R2 // caller's SP + MOVD LR, m_vdsoPC(R21) + MOVD R2, m_vdsoSP(R21) + + MOVD m_curg(R21), R0 + CMP g, R0 + BNE noswitch + + MOVD m_g0(R21), R3 + MOVD (g_sched+gobuf_sp)(R3), R1 // Set RSP to g0 stack + +noswitch: + SUB $16, R1 + BIC $15, R1 // Align for C code + MOVD R1, RSP + + MOVW $CLOCK_REALTIME, R0 + MOVD runtime·vdsoClockgettimeSym(SB), R2 + CBZ R2, fallback + + // Store g on gsignal's stack, so if we receive a signal + // during VDSO code we can find the g. + // If we don't have a signal stack, we won't receive signal, + // so don't bother saving g. + // When using cgo, we already saved g on TLS, also don't save + // g here. + // Also don't save g if we are already on the signal stack. + // We won't get a nested signal. + MOVBU runtime·iscgo(SB), R22 + CBNZ R22, nosaveg + MOVD m_gsignal(R21), R22 // g.m.gsignal + CBZ R22, nosaveg + CMP g, R22 + BEQ nosaveg + MOVD (g_stack+stack_lo)(R22), R22 // g.m.gsignal.stack.lo + MOVD g, (R22) + + BL (R2) + + MOVD ZR, (R22) // clear g slot, R22 is unchanged by C code + + B finish + +nosaveg: + BL (R2) + B finish + +fallback: + MOVD $SYS_clock_gettime, R8 + SVC + +finish: + MOVD 0(RSP), R3 // sec + MOVD 8(RSP), R5 // nsec + + MOVD R20, RSP // restore SP + // Restore vdsoPC, vdsoSP + // We don't worry about being signaled between the two stores. + // If we are not in a signal handler, we'll restore vdsoSP to 0, + // and no one will care about vdsoPC. If we are in a signal handler, + // we cannot receive another signal. + MOVD 16(RSP), R1 + MOVD R1, m_vdsoSP(R21) + MOVD 8(RSP), R1 + MOVD R1, m_vdsoPC(R21) + + MOVD R3, sec+0(FP) + MOVW R5, nsec+8(FP) + RET +//--to +TEXT runtime·walltime1_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_walltime1(SB) + RET +//--from +TEXT runtime·nanotime1(SB),NOSPLIT,$24-8 + MOVD RSP, R20 // R20 is unchanged by C code + MOVD RSP, R1 + + MOVD g_m(g), R21 // R21 = m + + // Set vdsoPC and vdsoSP for SIGPROF traceback. + // Save the old values on stack and restore them on exit, + // so this function is reentrant. + MOVD m_vdsoPC(R21), R2 + MOVD m_vdsoSP(R21), R3 + MOVD R2, 8(RSP) + MOVD R3, 16(RSP) + + MOVD $ret-8(FP), R2 // caller's SP + MOVD LR, m_vdsoPC(R21) + MOVD R2, m_vdsoSP(R21) + + MOVD m_curg(R21), R0 + CMP g, R0 + BNE noswitch + + MOVD m_g0(R21), R3 + MOVD (g_sched+gobuf_sp)(R3), R1 // Set RSP to g0 stack + +noswitch: + SUB $32, R1 + BIC $15, R1 + MOVD R1, RSP + + MOVW $CLOCK_MONOTONIC, R0 + MOVD runtime·vdsoClockgettimeSym(SB), R2 + CBZ R2, fallback + + // Store g on gsignal's stack, so if we receive a signal + // during VDSO code we can find the g. + // If we don't have a signal stack, we won't receive signal, + // so don't bother saving g. + // When using cgo, we already saved g on TLS, also don't save + // g here. + // Also don't save g if we are already on the signal stack. + // We won't get a nested signal. + MOVBU runtime·iscgo(SB), R22 + CBNZ R22, nosaveg + MOVD m_gsignal(R21), R22 // g.m.gsignal + CBZ R22, nosaveg + CMP g, R22 + BEQ nosaveg + MOVD (g_stack+stack_lo)(R22), R22 // g.m.gsignal.stack.lo + MOVD g, (R22) + + BL (R2) + + MOVD ZR, (R22) // clear g slot, R22 is unchanged by C code + + B finish + +nosaveg: + BL (R2) + B finish + +fallback: + MOVD $SYS_clock_gettime, R8 + SVC + +finish: + MOVD 0(RSP), R3 // sec + MOVD 8(RSP), R5 // nsec + + MOVD R20, RSP // restore SP + // Restore vdsoPC, vdsoSP + // We don't worry about being signaled between the two stores. + // If we are not in a signal handler, we'll restore vdsoSP to 0, + // and no one will care about vdsoPC. If we are in a signal handler, + // we cannot receive another signal. + MOVD 16(RSP), R1 + MOVD R1, m_vdsoSP(R21) + MOVD 8(RSP), R1 + MOVD R1, m_vdsoPC(R21) + + // sec is in R3, nsec in R5 + // return nsec in R3 + MOVD $1000000000, R4 + MUL R4, R3 + ADD R5, R3 + MOVD R3, ret+0(FP) + RET +//--to +TEXT runtime·nanotime1_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + BL hitsumabushi_nanotime1(SB) + MOVD R0, 0(R19) // return value + RET +//--from +TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0 + MOVD addr+0(FP), R0 + MOVW op+8(FP), R1 + MOVW val+12(FP), R2 + MOVD ts+16(FP), R3 + MOVD addr2+24(FP), R4 + MOVW val3+32(FP), R5 + MOVD $SYS_futex, R8 + SVC + MOVW R0, ret+40(FP) + RET +//--to +TEXT runtime·futex_trampoline(SB),NOSPLIT,$0 + MOVW 8(R0), R1 + MOVW 12(R0), R2 + MOVD 16(R0), R3 + MOVD 24(R0), R4 + MOVW 32(R0), R5 + MOVD 0(R0), R0 + BL hitsumabushi_futex(SB) + RET +//--from +TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0 + MOVD new+0(FP), R0 + MOVD old+8(FP), R1 + MOVD $SYS_sigaltstack, R8 + SVC + CMN $4095, R0 + BCC ok + MOVD $0, R0 + MOVD R0, (R0) // crash +ok: + RET +//--to +//--from +TEXT runtime·osyield(SB),NOSPLIT|NOFRAME,$0 + MOVD $SYS_sched_yield, R8 + SVC + RET +//--to +TEXT runtime·osyield_trampoline(SB),NOSPLIT,$0 + BL hitsumabushi_osyield(SB) + RET +//--from +TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0 + MOVD pid+0(FP), R0 + MOVD len+8(FP), R1 + MOVD buf+16(FP), R2 + MOVD $SYS_sched_getaffinity, R8 + SVC + MOVW R0, ret+24(FP) + RET +//--to +TEXT runtime·sched_getaffinity_trampoline(SB),NOSPLIT,$0-28 + MOVD 8(R0), R1 + MOVD 16(R0), R2 + MOVD 0(R0), R0 + BL hitsumabushi_sched_getaffinity(SB) + RET +//--append +TEXT runtime·sysAllocOS_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 0(R0), R0 + BL hitsumabushi_sysAllocOS(SB) + MOVD R0, 8(R19) // return value + RET + +TEXT runtime·sysUnusedOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysUnusedOS(SB) + RET + +TEXT runtime·sysUsedOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysUsedOS(SB) + RET + +TEXT runtime·sysHugePageOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysHugePageOS(SB) + RET + +TEXT runtime·sysFreeOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysFreeOS(SB) + RET + +TEXT runtime·sysFaultOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysFaultOS(SB) + RET + +TEXT runtime·sysReserveOS_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysReserveOS(SB) + MOVD R0, 16(R19) // return value + RET + +TEXT runtime·sysMapOS_trampoline(SB),NOSPLIT,$0 + MOVD 8(R0), R1 + MOVD 0(R0), R0 + BL hitsumabushi_sysMapOS(SB) + RET + +TEXT runtime·fcntl_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVW 8(R0), R1 + MOVW 16(R0), R2 + MOVW 0(R0), R0 + BL hitsumabushi_fcntl(SB) + MOVW R0, 24(R19) // return value + RET + +TEXT runtime·fstat_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 8(R0), R1 + MOVW 0(R0), R0 + BL hitsumabushi_fstat(SB) + MOVW R0, 16(R19) // return value + RET + +TEXT runtime·lseek_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 8(R0), R1 + MOVW 16(R0), R2 + MOVW 0(R0), R0 + BL hitsumabushi_lseek(SB) + MOVW R0, 24(R19) // return value + RET + +TEXT runtime·renameat_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 8(R0), R1 + MOVD 16(R0), R2 + MOVW 24(R0), R3 + MOVD 0(R0), R0 + BL hitsumabushi_renameat(SB) + MOVW R0, 32(R19) // return value + RET + +TEXT runtime·fstatat_trampoline(SB),NOSPLIT,$0 + MOVD R0, R19 // R19 is callee-save + MOVD 8(R0), R1 + MOVD 16(R0), R2 + MOVW 24(R0), R3 + MOVD 0(R0), R0 + BL hitsumabushi_fstatat(SB) + MOVW R0, 32(R19) // return value + RET diff --git a/1.23_linux/runtime/time_linux_amd64.s.patch b/1.23_linux/runtime/time_linux_amd64.s.patch new file mode 100644 index 0000000..6380ad8 --- /dev/null +++ b/1.23_linux/runtime/time_linux_amd64.s.patch @@ -0,0 +1,4 @@ +//--from +//go:build !faketime +//--to +//go:build ignore diff --git a/1.23_linux/runtime/timeasm.go.patch b/1.23_linux/runtime/timeasm.go.patch new file mode 100644 index 0000000..ee94d43 --- /dev/null +++ b/1.23_linux/runtime/timeasm.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build !faketime && (windows || (linux && amd64)) +//--to +//go:build !faketime && windows diff --git a/1.23_linux/runtime/timestub.go.patch b/1.23_linux/runtime/timestub.go.patch new file mode 100644 index 0000000..0b7faf6 --- /dev/null +++ b/1.23_linux/runtime/timestub.go.patch @@ -0,0 +1,4 @@ +//--from +//go:build !faketime && !windows && !(linux && amd64) +//--to +//go:build !faketime && !windows diff --git a/1.23_linux/runtime/timestub2.go.patch b/1.23_linux/runtime/timestub2.go.patch new file mode 100644 index 0000000..73e7b6a --- /dev/null +++ b/1.23_linux/runtime/timestub2.go.patch @@ -0,0 +1,27 @@ +//--from +//go:build !aix && !darwin && !freebsd && !openbsd && !solaris && !wasip1 && !windows && !(linux && amd64) +//--to +//go:build !aix && !darwin && !freebsd && !openbsd && !solaris && !wasip1 && !windows +//--from +package runtime +//--to +package runtime + +import ( + "internal/abi" + "unsafe" +) +//--from +func walltime() (sec int64, nsec int32) +//--to +func walltime() (sec int64, nsec int32) { + walltime1(&sec, &nsec) + return +} + +//go:nosplit +//go:cgo_unsafe_args +func walltime1(sec *int64, nsec *int32) { + libcCall(unsafe.Pointer(abi.FuncPCABI0(walltime1_trampoline)), unsafe.Pointer(&sec)) +} +func walltime1_trampoline(sec *int64, nsec *int32) diff --git a/1.23_linux/runtime/traceback_test.go.patch b/1.23_linux/runtime/traceback_test.go.patch new file mode 100644 index 0000000..202179a --- /dev/null +++ b/1.23_linux/runtime/traceback_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestTracebackInlined(t *testing.T) { +//--to +func TestTracebackInlined(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/strconv/fp_test.go.patch b/1.23_linux/strconv/fp_test.go.patch new file mode 100644 index 0000000..dead710 --- /dev/null +++ b/1.23_linux/strconv/fp_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestFp(t *testing.T) { +//--to +func TestFp(t *testing.T) { + t.Skip("file is not supported in this environment") diff --git a/1.23_linux/sync/atomic/atomic_test.go.patch b/1.23_linux/sync/atomic/atomic_test.go.patch new file mode 100644 index 0000000..b56da67 --- /dev/null +++ b/1.23_linux/sync/atomic/atomic_test.go.patch @@ -0,0 +1,15 @@ +//--from +func TestStoreLoadSeqCst32(t *testing.T) { +//--to +func TestStoreLoadSeqCst32(t *testing.T) { + t.Skip("didn't work on QEMU. see golang/go#50188") +//--from +func TestStoreLoadSeqCst64(t *testing.T) { +//--to +func TestStoreLoadSeqCst64(t *testing.T) { + t.Skip("didn't work on QEMU. see golang/go#50188") +//--from +func TestNilDeref(t *testing.T) { +//--to +func TestNilDeref(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/syscall/hitsumabushi_stubs_linux_amd64.go b/1.23_linux/syscall/hitsumabushi_stubs_linux_amd64.go new file mode 100644 index 0000000..e7eba35 --- /dev/null +++ b/1.23_linux/syscall/hitsumabushi_stubs_linux_amd64.go @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +package syscall + +const ( + SYS_FSTATAT = 0xffffffffffffffff // Stub: on amd64 Go uses SYS_NEWFSTATAT instead +) diff --git a/1.23_linux/syscall/hitsumabushi_stubs_linux_arm64.go b/1.23_linux/syscall/hitsumabushi_stubs_linux_arm64.go new file mode 100644 index 0000000..6ce2a39 --- /dev/null +++ b/1.23_linux/syscall/hitsumabushi_stubs_linux_arm64.go @@ -0,0 +1,8 @@ +// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: 2022 The Hitsumabushi Authors + +package syscall + +const ( + SYS_NEWFSTATAT = 0xffffffffffffffff // Stub: on arm64 Go uses SYS_FSTATAT instead +) diff --git a/1.23_linux/syscall/rlimit.go.patch b/1.23_linux/syscall/rlimit.go.patch new file mode 100644 index 0000000..edc8ed3 --- /dev/null +++ b/1.23_linux/syscall/rlimit.go.patch @@ -0,0 +1,14 @@ +//--from +func init() { + var lim Rlimit + if err := Getrlimit(RLIMIT_NOFILE, &lim); err == nil && lim.Cur != lim.Max { + origRlimitNofile.Store(&lim) + nlim := lim + nlim.Cur = nlim.Max + adjustFileLimit(&nlim) + setrlimit(RLIMIT_NOFILE, &nlim) + } +} +//--to +func init() { +} diff --git a/1.23_linux/syscall/syscall_linux.go.patch b/1.23_linux/syscall/syscall_linux.go.patch new file mode 100644 index 0000000..b6f7501 --- /dev/null +++ b/1.23_linux/syscall/syscall_linux.go.patch @@ -0,0 +1,151 @@ +//--from +import ( + "internal/itoa" + runtimesyscall "internal/runtime/syscall" + "runtime" + "unsafe" +) +//--to +import ( + "internal/itoa" + "runtime" + "unsafe" +) +//--from +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + return RawSyscall6(trap, a1, a2, a3, 0, 0, 0) +} +//--to +func RawSyscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + println("not implemented syscall at RawSyscall", trap) + panic("syscall.RawSyscall") + return 0, 0, ENOSYS +} +//--from +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { + var errno uintptr + r1, r2, errno = runtimesyscall.Syscall6(trap, a1, a2, a3, a4, a5, a6) + err = Errno(errno) + return +} +//--to +func RawSyscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { + println("not implemented syscall at RawSyscall6", trap) + panic("syscall.RawSyscall6") + return 0, 0, ENOSYS +} +//--from +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + runtime_entersyscall() + // N.B. Calling RawSyscall here is unsafe with atomic coverage + // instrumentation and race mode. + // + // Coverage instrumentation will add a sync/atomic call to RawSyscall. + // Race mode will add race instrumentation to sync/atomic. Race + // instrumentation requires a P, which we no longer have. + // + // RawSyscall6 is fine because it is implemented in assembly and thus + // has no coverage instrumentation. + // + // This is typically not a problem in the runtime because cmd/go avoids + // adding coverage instrumentation to the runtime in race mode. + r1, r2, err = RawSyscall6(trap, a1, a2, a3, 0, 0, 0) + runtime_exitsyscall() + return +} +//--to +func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err Errno) { + var r int32 + switch trap { + case SYS_FCNTL: + r = fcntl1(a1, a2, a3) + case SYS_FSTAT: + r = fstat1(a1, unsafe.Pointer(a2)) + case SYS_READ: + r = runtime_read(uintptr(a1), unsafe.Pointer(a2), int32(a3)) + case SYS_WRITE: + r = write1(a1, unsafe.Pointer(a2), int32(a3)) + case SYS_LSEEK: + r = lseek1(a1, int64(a2), int32(a3)) + case SYS_CLOSE: + r = runtime_closefd(int32(a1)) + case SYS_MKDIRAT: + println("syscall mkdirat() is not implemented") + // Default to permission denied. TODO: implement this + return 0, 0, EPERM + case SYS_GETDENTS64: + println("syscall getdents64() is not implemented") + // Default to empty directory. TODO: implement this + return 0, 0, 0 + default: + println("unimplemented syscall at runtime.Syscall", trap) + panic("syscall.Syscall") + return 0, 0, ENOSYS + } + + if r < 0 { + return 0, 0, Errno(-r) + } + return uintptr(r), 0, 0 +} + +//go:linkname open runtime.open +func open(name *byte, mode, perm int32) int32 +//go:linkname write1 runtime.write1 +func write1(fd uintptr, p unsafe.Pointer, n int32) int32 +//go:linkname fcntl1 runtime.fcntl1 +func fcntl1(fd uintptr, a uintptr, b uintptr) int32 +//go:linkname fstat1 runtime.fstat1 +func fstat1(fd uintptr, p unsafe.Pointer) int32 +//go:linkname lseek1 runtime.lseek1 +func lseek1(fd uintptr, offset int64, whence int32) int32 +//go:linkname runtime_read runtime.read +func runtime_read(fd uintptr, p unsafe.Pointer, n int32) int32 +//go:linkname runtime_closefd runtime.closefd +func runtime_closefd(fd int32) int32 +//go:linkname runtime_fstatat runtime.fstatat +func runtime_fstatat(fd uintptr, name unsafe.Pointer, p unsafe.Pointer, n int32) int32 +//go:linkname runtime_renameat runtime.renameat +func runtime_renameat(fd1 uintptr, name1 unsafe.Pointer, fd2 uintptr, name2 unsafe.Pointer) int32 +//--from +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { + runtime_entersyscall() + r1, r2, err = RawSyscall6(trap, a1, a2, a3, a4, a5, a6) + runtime_exitsyscall() + return +} +//--to +func Syscall6(trap, a1, a2, a3, a4, a5, a6 uintptr) (r1, r2 uintptr, err Errno) { + var r int32 + switch trap { + case SYS_FSTATAT, SYS_NEWFSTATAT: + r = runtime_fstatat(uintptr(a1), unsafe.Pointer(a2), unsafe.Pointer(a3), int32(a4)) + case SYS_RENAMEAT: + r = runtime_renameat(uintptr(a1), unsafe.Pointer(a2), uintptr(a3), unsafe.Pointer(a4)) + default: + println("unimplemented syscall at runtime.Syscall6", trap) + panic("syscall.Syscall6") + return 0, 0, ENOSYS + } + + if r < 0 { + return 0, 0, Errno(-r) + } + return uintptr(r), 0, 0 +} +//--from +func Open(path string, mode int, perm uint32) (fd int, err error) { + return openat(_AT_FDCWD, path, mode|O_LARGEFILE, perm) +} +//--to +func Open(path string, mode int, perm uint32) (fd int, err error) { + p0, err := BytePtrFromString(path) + if err != nil { + return -1, errnoErr(EINVAL) + } + fd = int(open(p0, int32(mode|O_LARGEFILE), int32(perm))) + if fd < 0 { + return -1, errnoErr(ENOENT) + } + return +} diff --git a/1.23_linux/testing/run_example.go b/1.23_linux/testing/run_example.go new file mode 100644 index 0000000..24d58dd --- /dev/null +++ b/1.23_linux/testing/run_example.go @@ -0,0 +1,7 @@ +package testing + +func runExample(eg InternalExample) (ok bool) { + // Do nothing. + // TODO: Implement os.Pipe2 and use this here. + return true +} diff --git a/1.23_linux/time/format_test.go.patch b/1.23_linux/time/format_test.go.patch new file mode 100644 index 0000000..a3eddcc --- /dev/null +++ b/1.23_linux/time/format_test.go.patch @@ -0,0 +1,10 @@ +//--from +func TestParseInLocation(t *testing.T) { +//--to +func TestParseInLocation(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestLoadLocationZipFile(t *testing.T) { +//--to +func TestLoadLocationZipFile(t *testing.T) { + t.Skip("location is not supported in this environment") diff --git a/1.23_linux/time/internal_test.go.patch b/1.23_linux/time/internal_test.go.patch new file mode 100644 index 0000000..ce52b0d --- /dev/null +++ b/1.23_linux/time/internal_test.go.patch @@ -0,0 +1,23 @@ +//--from +func initTestingZone() { + // For hermeticity, use only tzinfo source from the test's GOROOT, + // not the system sources and not whatever GOROOT may happen to be + // set in the process's environment (if any). + // This test runs in GOROOT/src/time, so GOROOT is "../..", + // but it is theoretically possible + sources := []string{"../../lib/time/zoneinfo.zip"} + z, err := loadLocation("America/Los_Angeles", sources) + if err != nil { + panic("cannot load America/Los_Angeles for testing: " + err.Error() + "; you may want to use -tags=timetzdata") + } + z.name = "Local" + localLoc = *z +} +//--to +func initTestingZone() { + // Data from the playground. + // https://go.dev/play/p/VGXU57KZZ-x + // name is replaced with "Local". + // cachStart, cacheEnd, and cacheZone are removed. + localLoc = Location{name:"Local",zone:[]zone{zone{name:"LMT", offset:-28378, isDST:false}, zone{name:"PDT", offset:-25200, isDST:true}, zone{name:"PST", offset:-28800, isDST:false}, zone{name:"PWT", offset:-25200, isDST:true}, zone{name:"PPT", offset:-25200, isDST:true}}, tx:[]zoneTrans{zoneTrans{when:-576460752303423488, index:0x0, isstd:false, isutc:false}, zoneTrans{when:-2717640000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-1633269600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-1615129200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-1601820000, index:0x1, isstd:true, isutc:true}, zoneTrans{when:-1583679600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-880207200, index:0x3, isstd:false, isutc:false}, zoneTrans{when:-769395600, index:0x4, isstd:false, isutc:false}, zoneTrans{when:-765385200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-687967140, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-662655600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-620838000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-608137200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-589388400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-576082800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-557938800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-544633200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-526489200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-513183600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-495039600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-481734000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-463590000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-450284400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-431535600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-418230000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-400086000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-386780400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-368636400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-355330800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-337186800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-323881200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-305737200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-292431600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-273682800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-260982000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-242233200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-226508400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-210783600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-195058800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-179334000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-163609200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-147884400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-131554800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-116434800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-100105200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-84376800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-68655600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-52927200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-37206000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:-21477600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:-5756400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:9972000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:25693200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:41421600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:57747600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:73476000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:89197200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:104925600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:120646800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:126698400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:152096400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:162381600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:183546000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:199274400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:215600400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:230724000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:247050000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:262778400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:278499600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:294228000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:309949200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:325677600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:341398800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:357127200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:372848400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:388576800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:404902800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:420026400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:436352400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:452080800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:467802000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:483530400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:499251600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:514980000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:530701200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:544615200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:562150800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:576064800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:594205200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:607514400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:625654800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:638964000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:657104400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:671018400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:688554000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:702468000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:720003600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:733917600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:752058000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:765367200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:783507600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:796816800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:814957200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:828871200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:846406800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:860320800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:877856400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:891770400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:909306000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:923220000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:941360400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:954669600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:972810000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:986119200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1004259600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1018173600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1035709200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1049623200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1067158800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1081072800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1099213200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1112522400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1130662800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1143972000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1162112400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1173607200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1194166800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1205056800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1225616400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1236506400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1257066000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1268560800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1289120400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1300010400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1320570000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1331460000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1352019600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1362909600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1383469200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1394359200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1414918800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1425808800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1446368400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1457863200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1478422800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1489312800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1509872400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1520762400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1541322000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1552212000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1572771600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1583661600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1604221200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1615716000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1636275600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1647165600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1667725200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1678615200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1699174800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1710064800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1730624400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1741514400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1762074000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1772964000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1793523600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1805018400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1825578000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1836468000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1857027600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1867917600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1888477200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1899367200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1919926800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1930816800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1951376400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1962871200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:1983430800, index:0x2, isstd:false, isutc:false}, zoneTrans{when:1994320800, index:0x1, isstd:false, isutc:false}, zoneTrans{when:2014880400, index:0x2, isstd:false, isutc:false}, zoneTrans{when:2025770400, index:0x1, isstd:false, isutc:false}, zoneTrans{when:2046330000, index:0x2, isstd:false, isutc:false}, zoneTrans{when:2057220000, index:0x1, isstd:false, isutc:false}, zoneTrans{when:2077779600, index:0x2, isstd:false, isutc:false}, zoneTrans{when:2088669600, index:0x1, isstd:false, isutc:false}, zoneTrans{when:2109229200, index:0x2, isstd:false, isutc:false}, zoneTrans{when:2120119200, index:0x1, isstd:false, isutc:false}, zoneTrans{when:2140678800, index:0x2, isstd:false, isutc:false}}, extend:"PST8PDT,M3.2.0,M11.1.0"} +} diff --git a/1.23_linux/time/sleep_test.go.patch b/1.23_linux/time/sleep_test.go.patch new file mode 100644 index 0000000..5bb47cf --- /dev/null +++ b/1.23_linux/time/sleep_test.go.patch @@ -0,0 +1,10 @@ +//--from +func TestSleep(t *testing.T) { +//--to +func TestSleep(t *testing.T) { + t.Skip("Interrupt (syscall.Kill) is not supported in this environment") +//--from +func TestIssue5745(t *testing.T) { +//--to +func TestIssue5745(t *testing.T) { + t.Skip("handling nil pointer access is not supported in this environment") diff --git a/1.23_linux/time/time_test.go.patch b/1.23_linux/time/time_test.go.patch new file mode 100644 index 0000000..2e0861d --- /dev/null +++ b/1.23_linux/time/time_test.go.patch @@ -0,0 +1,20 @@ +//--from +func TestLoadFixed(t *testing.T) { +//--to +func TestLoadFixed(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestTimeIsDST(t *testing.T) { +//--to +func TestTimeIsDST(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestTimeWithZoneTransition(t *testing.T) { +//--to +func TestTimeWithZoneTransition(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestMarshalBinaryVersion2(t *testing.T) { +//--to +func TestMarshalBinaryVersion2(t *testing.T) { + t.Skip("location is not supported in this environment") diff --git a/1.23_linux/time/tzdata_test.go.patch b/1.23_linux/time/tzdata_test.go.patch new file mode 100644 index 0000000..af5253d --- /dev/null +++ b/1.23_linux/time/tzdata_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestEmbeddedTZData(t *testing.T) { +//--to +func TestEmbeddedTZData(t *testing.T) { + t.Skip("location is not supported in this environment") diff --git a/1.23_linux/time/zoneinfo_test.go.patch b/1.23_linux/time/zoneinfo_test.go.patch new file mode 100644 index 0000000..f2f883c --- /dev/null +++ b/1.23_linux/time/zoneinfo_test.go.patch @@ -0,0 +1,35 @@ +//--from +func TestEnvVarUsage(t *testing.T) { +//--to +func TestEnvVarUsage(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestBadLocationErrMsg(t *testing.T) { +//--to +func TestBadLocationErrMsg(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestVersion3(t *testing.T) { +//--to +func TestVersion3(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestFirstZone(t *testing.T) { +//--to +func TestFirstZone(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestLoadLocationFromTZData(t *testing.T) { +//--to +func TestLoadLocationFromTZData(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestEarlyLocation(t *testing.T) { +//--to +func TestEarlyLocation(t *testing.T) { + t.Skip("location is not supported in this environment") +//--from +func TestLoadLocationFromTZDataSlim(t *testing.T) { +//--to +func TestLoadLocationFromTZDataSlim(t *testing.T) { + t.Skip("location is not supported in this environment") diff --git a/1.23_linux/time/zoneinfo_unix.go.patch b/1.23_linux/time/zoneinfo_unix.go.patch new file mode 100644 index 0000000..06253b7 --- /dev/null +++ b/1.23_linux/time/zoneinfo_unix.go.patch @@ -0,0 +1,52 @@ +//--from +import ( + "syscall" +) +//--to +//--from +func initLocal() { + // consult $TZ to find the time zone to use. + // no $TZ means use the system default /etc/localtime. + // $TZ="" means use UTC. + // $TZ="foo" or $TZ=":foo" if foo is an absolute path, then the file pointed + // by foo will be used to initialize timezone; otherwise, file + // /usr/share/zoneinfo/foo will be used. + + tz, ok := syscall.Getenv("TZ") + switch { + case !ok: + z, err := loadLocation("localtime", []string{"/etc"}) + if err == nil { + localLoc = *z + localLoc.name = "Local" + return + } + case tz != "": + if tz[0] == ':' { + tz = tz[1:] + } + if tz != "" && tz[0] == '/' { + if z, err := loadLocation(tz, []string{""}); err == nil { + localLoc = *z + if tz == "/etc/localtime" { + localLoc.name = "Local" + } else { + localLoc.name = tz + } + return + } + } else if tz != "" && tz != "UTC" { + if z, err := loadLocation(tz, platformZoneSources); err == nil { + localLoc = *z + return + } + } + } + + // Fall back to UTC. + localLoc.name = "UTC" +} +//--to +func initLocal() { + localLoc.name = "UTC" +} diff --git a/1.23_linux/time/zoneinfo_unix_test.go.patch b/1.23_linux/time/zoneinfo_unix_test.go.patch new file mode 100644 index 0000000..290062a --- /dev/null +++ b/1.23_linux/time/zoneinfo_unix_test.go.patch @@ -0,0 +1,5 @@ +//--from +func TestEnvTZUsage(t *testing.T) { +//--to +func TestEnvTZUsage(t *testing.T) { + t.Skip("location is not supported in this environment")