]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: increase maxargs to avoid syscall18 crash when called with more than 16...
authorEl Mostafa Idrassi <el.mostafa.idrassi@gmail.com>
Tue, 13 Apr 2021 20:08:46 +0000 (20:08 +0000)
committerAlex Brainman <alex.brainman@gmail.com>
Wed, 14 Apr 2021 09:46:36 +0000 (09:46 +0000)
Fixes #45524

Change-Id: Id867f45ea98689b73d5b1b141c19317bc7608b05
GitHub-Last-Rev: e9b09fb557dda291fb6cf27c185063c26832a15b
GitHub-Pull-Request: golang/go#45531
Reviewed-on: https://go-review.googlesource.com/c/go/+/309390
Reviewed-by: El Mostafa Idrassi <el.mostafa.idrassi@gmail.com>
Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Trust: Alex Brainman <alex.brainman@gmail.com>
Trust: Alberto Donizetti <alb.donizetti@gmail.com>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/runtime/sys_windows_amd64.s
src/runtime/syscall_windows_test.go

index f7250c65a81e1ecaf641bed8b2309ace71525924..689633132976465f49a453280d63384d4cbaac61 100644 (file)
@@ -8,7 +8,7 @@
 
 // maxargs should be divisible by 2, as Windows stack
 // must be kept 16-byte aligned on syscall entry.
-#define maxargs 16
+#define maxargs 18
 
 // void runtimeĀ·asmstdcall(void *c);
 TEXT runtimeĀ·asmstdcall<ABIInternal>(SB),NOSPLIT|NOFRAME,$0
index 98e426a3d53d70e8389d2582193fc7299816cd3f..5e9694d444c2d12eb443bb3b4aa32047739703d2 100644 (file)
@@ -744,6 +744,51 @@ uintptr_t cfunc(callback f, uintptr_t n) {
        }
 }
 
+func TestSyscall18(t *testing.T) {
+       if _, err := exec.LookPath("gcc"); err != nil {
+               t.Skip("skipping test: gcc is missing")
+       }
+       if runtime.GOARCH != "amd64" {
+               t.Skipf("skipping test: GOARCH=%s", runtime.GOARCH)
+       }
+
+       const src = `
+#include <stdint.h>
+#include <windows.h>
+
+int cfunc(     int a1, int a2, int a3, int a4, int a5, int a6, int a7, int a8, int a9,
+                       int a10, int a11, int a12, int a13, int a14, int a15, int a16, int a17, int a18) {
+       return 1;
+}
+`
+       tmpdir := t.TempDir()
+
+       srcname := "mydll.c"
+       err := os.WriteFile(filepath.Join(tmpdir, srcname), []byte(src), 0)
+       if err != nil {
+               t.Fatal(err)
+       }
+       outname := "mydll.dll"
+       cmd := exec.Command("gcc", "-shared", "-s", "-Werror", "-o", outname, srcname)
+       cmd.Dir = tmpdir
+       out, err := cmd.CombinedOutput()
+       if err != nil {
+               t.Fatalf("failed to build dll: %v - %v", err, string(out))
+       }
+       dllpath := filepath.Join(tmpdir, outname)
+
+       dll := syscall.MustLoadDLL(dllpath)
+       defer dll.Release()
+
+       proc := dll.MustFindProc("cfunc")
+
+       // proc.Call() will call Syscall18() internally.
+       r, _, err := proc.Call(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18)
+       if r != 1 {
+               t.Errorf("got %d want 1 (err=%v)", r, err)
+       }
+}
+
 func TestFloatArgs(t *testing.T) {
        if _, err := exec.LookPath("gcc"); err != nil {
                t.Skip("skipping test: gcc is missing")