go/api/next
Sven Anderson 251daf46fb runtime: implement Pinner API for object pinning
Some C APIs require the use or structures that contain pointers to
buffers (iovec, io_uring, ...).  The pointer passing rules would
require that these buffers are allocated in C memory and to process
this data with Go libraries it would need to be copied.

In order to provide a zero-copy way to use these C APIs, this CL
implements a Pinner API that allows to pin Go objects, which
guarantees that the garbage collector does not move these objects
while pinned.  This allows to relax the pointer passing rules so that
pinned pointers can be stored in C allocated memory or can be
contained in Go memory that is passed to C functions.

The Pin() method accepts pointers to objects of any type and
unsafe.Pointer.  Slices and arrays can be pinned by calling Pin()
with the pointer to the first element.  Pinning of maps is not
supported.

If the GC collects unreachable Pinner holding pinned objects it
panics.  If Pin() is called with the other non-pointer types it
panics as well.

Performance considerations: This change has no impact on execution
time on existing code, because checks are only done in code paths,
that would panic otherwise.  The memory footprint on existing code is
one pointer per memory span.

Fixes: #46787

Signed-off-by: Sven Anderson <sven@anderson.de>
Change-Id: I110031fe789b92277ae45a9455624687bd1c54f2
Reviewed-on: https://go-review.googlesource.com/c/go/+/367296
Auto-Submit: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
2023-05-19 14:59:14 +00:00
..
25448.txt runtime: replace panic(nil) with panic(new(runtime.PanicNilError)) 2023-01-19 22:21:50 +00:00
28089.txt go/ast: add IsGenerated(*File) predicate 2023-04-25 13:57:33 +00:00
34648.txt crypto/elliptic: deprecate unsafe APIs 2023-03-16 16:31:26 +00:00
40221.txt context: add WithoutCancel 2023-03-29 20:41:09 +00:00
41198.txt net/http: let ErrNotSupported match errors.ErrUnsupported 2023-05-10 20:13:04 +00:00
44855.txt net/http: expose "http: server gave HTTP response to HTTPS client" error 2023-04-07 19:44:49 +00:00
46159.txt regexp: add Regexp.TextMarshaler/TextUnmarshaler 2023-04-12 20:03:09 +00:00
46259.txt syscall: add jail support to ForkExec on FreeBSD 2023-02-22 20:38:48 +00:00
46787.txt runtime: implement Pinner API for object pinning 2023-05-19 14:59:14 +00:00
52221.txt crypto/elliptic: deprecate unsafe APIs 2023-03-16 16:31:26 +00:00
52600.txt testing: add Testing function 2023-03-13 21:58:46 +00:00
53573.txt crypto/x509: surface ReasonCode in RevocationList API 2023-03-13 20:25:37 +00:00
53685.txt bytes: add Buffer.Available and Buffer.AvailableBuffer 2023-03-13 17:03:14 +00:00
53747.txt flag: add BoolFunc; FlagSet.BoolFunc 2023-03-16 16:44:21 +00:00
54386.txt bytes, strings: add ContainsFunc 2023-01-24 22:06:45 +00:00
54451.txt io/fs: add FormatFileInfo and FormatDirEntry functions 2023-05-02 17:59:28 +00:00
54768.txt slices: add DeleteFunc 2023-04-07 22:25:51 +00:00
55002.txt reflect,runtime: add Value.Clear 2023-01-30 16:00:58 +00:00
55079.txt all: upgrade Unicode from 13.0.0 to 15.0.0 2023-02-06 04:29:53 +00:00
55107.txt debug/elf: support zstd compression 2023-04-18 20:34:36 +00:00
56102.txt sync: implement OnceFunc, OnceValue, and OnceValues 2023-03-31 20:01:17 +00:00
56345.txt log/slog: Group takes ...any 2023-05-04 19:53:09 +00:00
56491.txt math: add Compare and Compare32 2023-02-15 21:56:30 +00:00
56539.txt net: mptcp: implement listenMPTCP 2023-03-29 22:12:20 +00:00
56661.txt context: add APIs for setting a cancelation cause when deadline or timer expires 2023-01-20 21:41:01 +00:00
56887.txt debug/elf: add DT_FLAGS_1 constants 2023-02-03 04:37:17 +00:00
56892.txt debug/elf: retrieve values for dynamic section tags 2023-03-07 18:26:40 +00:00
56906.txt reflect: deprecate SliceHeader and StringHeader 2023-04-03 17:08:28 +00:00
56921.txt crypto/rsa: deprecate multiprime RSA support 2023-03-16 16:31:24 +00:00
56984.txt math/big: add Int.Float64 conversion 2023-02-02 19:39:34 +00:00
56986.txt cmd/go, go/build: parse directives in file headers 2023-02-23 10:10:21 +00:00
57237.txt encoding/binary: add var NativeEndian 2023-01-27 18:17:20 +00:00
57433.txt slices: new package 2023-02-13 21:00:42 +00:00
57436.txt maps: new package 2023-02-03 18:22:53 +00:00
57708.txt go/token: add (*File).Lines method 2023-02-02 16:40:29 +00:00
57786.txt net/http: support full-duplex HTTP/1 responses 2023-03-07 22:52:18 +00:00
57928.txt context: add AfterFunc 2023-04-19 19:13:01 +00:00
58565.txt slices: add in-place Reverse function 2023-05-19 00:43:02 +00:00
59033.txt go/ast: add File.GoVersion 2023-04-11 19:40:45 +00:00
59060.txt log/slog: function argument to Record.Attrs returns bool 2023-04-12 20:33:37 +00:00
59166.txt net: mptcp: add TCPConn's MultipathTCP checker 2023-04-18 13:48:22 +00:00
59204.txt log/slog: Group takes ...any 2023-05-04 19:53:09 +00:00
59280.txt log/slog: add Source type for source location 2023-04-20 17:36:42 +00:00
59339.txt log/slog: built-in handler constructors take options as a second arg 2023-05-04 18:32:54 +00:00