aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/golang.org/x/sys/unix/sysvshm_unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/golang.org/x/sys/unix/sysvshm_unix.go')
-rw-r--r--vendor/golang.org/x/sys/unix/sysvshm_unix.go51
1 files changed, 51 insertions, 0 deletions
diff --git a/vendor/golang.org/x/sys/unix/sysvshm_unix.go b/vendor/golang.org/x/sys/unix/sysvshm_unix.go
new file mode 100644
index 0000000..79a84f1
--- /dev/null
+++ b/vendor/golang.org/x/sys/unix/sysvshm_unix.go
@@ -0,0 +1,51 @@
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build (darwin && !ios) || linux
6
7package unix
8
9import "unsafe"
10
11// SysvShmAttach attaches the Sysv shared memory segment associated with the
12// shared memory identifier id.
13func SysvShmAttach(id int, addr uintptr, flag int) ([]byte, error) {
14 addr, errno := shmat(id, addr, flag)
15 if errno != nil {
16 return nil, errno
17 }
18
19 // Retrieve the size of the shared memory to enable slice creation
20 var info SysvShmDesc
21
22 _, err := SysvShmCtl(id, IPC_STAT, &info)
23 if err != nil {
24 // release the shared memory if we can't find the size
25
26 // ignoring error from shmdt as there's nothing sensible to return here
27 shmdt(addr)
28 return nil, err
29 }
30
31 // Use unsafe to convert addr into a []byte.
32 b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.Segsz))
33 return b, nil
34}
35
36// SysvShmDetach unmaps the shared memory slice returned from SysvShmAttach.
37//
38// It is not safe to use the slice after calling this function.
39func SysvShmDetach(data []byte) error {
40 if len(data) == 0 {
41 return EINVAL
42 }
43
44 return shmdt(uintptr(unsafe.Pointer(&data[0])))
45}
46
47// SysvShmGet returns the Sysv shared memory identifier associated with key.
48// If the IPC_CREAT flag is specified a new segment is created.
49func SysvShmGet(key, size, flag int) (id int, err error) {
50 return shmget(key, size, flag)
51}