comparison vendor/golang.org/x/sys/unix/sysvshm_unix.go @ 68:4b79810863f6 draft

Ready to release 0.6.0 Signed-off-by: Izuru Yakumo <yakumo.izuru@chaotic.ninja>
author yakumo.izuru
date Wed, 13 Sep 2023 10:49:50 +0000
parents 787b5ee0289d
children
comparison
equal deleted inserted replaced
67:4edfa07d5fe0 68:4b79810863f6
5 //go:build (darwin && !ios) || linux 5 //go:build (darwin && !ios) || linux
6 // +build darwin,!ios linux 6 // +build darwin,!ios linux
7 7
8 package unix 8 package unix
9 9
10 import ( 10 import "unsafe"
11 "unsafe"
12
13 "golang.org/x/sys/internal/unsafeheader"
14 )
15 11
16 // SysvShmAttach attaches the Sysv shared memory segment associated with the 12 // SysvShmAttach attaches the Sysv shared memory segment associated with the
17 // shared memory identifier id. 13 // shared memory identifier id.
18 func SysvShmAttach(id int, addr uintptr, flag int) ([]byte, error) { 14 func SysvShmAttach(id int, addr uintptr, flag int) ([]byte, error) {
19 addr, errno := shmat(id, addr, flag) 15 addr, errno := shmat(id, addr, flag)
32 shmdt(addr) 28 shmdt(addr)
33 return nil, err 29 return nil, err
34 } 30 }
35 31
36 // Use unsafe to convert addr into a []byte. 32 // Use unsafe to convert addr into a []byte.
37 // TODO: convert to unsafe.Slice once we can assume Go 1.17 33 b := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.Segsz))
38 var b []byte
39 hdr := (*unsafeheader.Slice)(unsafe.Pointer(&b))
40 hdr.Data = unsafe.Pointer(addr)
41 hdr.Cap = int(info.Segsz)
42 hdr.Len = int(info.Segsz)
43 return b, nil 34 return b, nil
44 } 35 }
45 36
46 // SysvShmDetach unmaps the shared memory slice returned from SysvShmAttach. 37 // SysvShmDetach unmaps the shared memory slice returned from SysvShmAttach.
47 // 38 //