vendor/golang.org/x/sys/unix/sysvshm_unix.go
changeset 262 8d3354485fc3
parent 260 445e01aede7e
equal deleted inserted replaced
261:270cc4dda0c5 262:8d3354485fc3
     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 //