diff options
author | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
---|---|---|
committer | Rutger Broekhoff | 2023-12-29 21:31:53 +0100 |
commit | 404aeae4545d2426c089a5f8d5e82dae56f5212b (patch) | |
tree | 2d84e00af272b39fc04f3795ae06bc48970e57b5 /vendor/golang.org/x/sys/unix/sysvshm_unix.go | |
parent | 209d8b0187ed025dec9ac149ebcced3462877bff (diff) | |
download | gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.tar.gz gitolfs3-404aeae4545d2426c089a5f8d5e82dae56f5212b.zip |
Make Nix builds work
Diffstat (limited to 'vendor/golang.org/x/sys/unix/sysvshm_unix.go')
-rw-r--r-- | vendor/golang.org/x/sys/unix/sysvshm_unix.go | 51 |
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 | |||
7 | package unix | ||
8 | |||
9 | import "unsafe" | ||
10 | |||
11 | // SysvShmAttach attaches the Sysv shared memory segment associated with the | ||
12 | // shared memory identifier id. | ||
13 | func 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. | ||
39 | func 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. | ||
49 | func SysvShmGet(key, size, flag int) (id int, err error) { | ||
50 | return shmget(key, size, flag) | ||
51 | } | ||