aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-07-30 14:46:37 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2021-08-02 13:54:04 +0200
commit2b2f884c1eccfb2333e7c6860f6c3d3b2d34686f (patch)
tree01802d967fc152d5a89220ee1d77777dd70a4ef0 /go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
parentembeddable-dll-service: .gitignore VS output folders (diff)
downloadwireguard-windows-2b2f884c1eccfb2333e7c6860f6c3d3b2d34686f.tar.xz
wireguard-windows-2b2f884c1eccfb2333e7c6860f6c3d3b2d34686f.zip
build: use official go builds and patch locally
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch59
1 files changed, 59 insertions, 0 deletions
diff --git a/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch b/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
new file mode 100644
index 00000000..d6a1ac65
--- /dev/null
+++ b/go-patches/0001-runtime-allow-builtin-write-function-to-be-redirecte.patch
@@ -0,0 +1,59 @@
+From 1c566ea2420f0503c8494e361bccb943d83c135c Mon Sep 17 00:00:00 2001
+From: "Jason A. Donenfeld" <Jason@zx2c4.com>
+Date: Thu, 3 Dec 2020 13:29:58 +0100
+Subject: [PATCH] runtime: allow builtin write function to be redirected with
+ function pointer
+
+The x/sys/windows package currently uses go:linkname for other facilities
+inside of runtime that are not suitable to be exposed as a public API
+due to their dangers but are still necessary for manipulating any
+low-level plumbing that the runtime controls.
+
+Logging, via the built-in println and panic handler, is one such
+low-level plumbing feature. In this case, x/sys/windows/svc needs to be
+able to redirect panics to the Windows event log. Because the event log
+is a complicated interface, this requires a bit more fiddling than the
+simple solution used on Android (baking it into runtime itself), and
+because Windows services are very diverse, the event log might not even
+always be a desirable destination.
+
+This commit accomplishes this by exposing a function pointer called
+"overrideWrite" that low-level runtime packages like x/sys/windows/svc
+can use to redirect output logs toward the event log or otherwise.
+
+It is not safe or acceptable to use as a generic mechanism, and for that
+reason, we wouldn't want to expose this as a real stable API, similar to
+the other instances of go:linkname in x/sys/windows. But for packages
+that must interoperate with low-level Go runtime fundamentals, this is a
+safety hatch for packages that are developed in tandem with the runtime.
+x/sys/windows is one such package.
+
+Updates #42888.
+
+Change-Id: I77a32ff7e1494324e8cc38e792e007f86d32672d
+---
+ src/runtime/time_nofake.go | 5 +++++
+ 1 file changed, 5 insertions(+)
+
+diff --git a/src/runtime/time_nofake.go b/src/runtime/time_nofake.go
+index 5a4ceaf43d..68c01805a5 100644
+--- a/src/runtime/time_nofake.go
++++ b/src/runtime/time_nofake.go
+@@ -20,9 +20,14 @@ func nanotime() int64 {
+ return nanotime1()
+ }
+
++var overrideWrite func(fd uintptr, p unsafe.Pointer, n int32) int32
++
+ // write must be nosplit on Windows (see write1)
+ //
+ //go:nosplit
+ func write(fd uintptr, p unsafe.Pointer, n int32) int32 {
++ if overrideWrite != nil {
++ return overrideWrite(fd, noescape(p), n)
++ }
+ return write1(fd, p, n)
+ }
+--
+2.32.0
+