func (shma *SharedMemMount) Read(p []byte) (int, error) {
	var err error
	l := uint(len(p))
	if l > (shma.length - shma.offset) {
		l = shma.length - shma.offset
		err = io.EOF
	}
	if l == 0 {
		return 0, err
	}
	src := unsafe.Pointer(uintptr(shma.ptr) + uintptr(shma.offset))
	dest := unsafe.Pointer(&p[0])
	memmove(dest, src, (uintptr)(l))
	shma.offset += l
	return int(l), err
}
Read pulls bytes out of the shared memory segment.
package sysvipc
import "C"
import (
	"errors"
	"io"
	"sync/atomic"
	"time"
	"unsafe"
)
var (
	ErrReadOnlyShm = errors.New("Read-Only shared mem attachment")
)
type SharedMem struct {
	id     int64
	length uint
}
func GetSharedMem(key int64, size uint64, flags *SHMFlags) (*SharedMem, error) {
	rc, err := C.shmget(C.key_t(key), C.size_t(size), C.int(flags.flags()))
	if rc == -1 {
		return nil, err
	}
	return &SharedMem{int64(rc), uint(size)}, nil
}
func (shm *SharedMem) Attach(flags *SHMAttachFlags) (*SharedMemMount, error) {
	ptr, err := C.shmat(C.int(shm.id), nil, C.int(flags.flags()))
	if err != nil {
		return nil, err
	}
	return &SharedMemMount{ptr, 0, shm.length, flags.ro()}, nil
}
func (shm *SharedMem) Stat() (*SHMInfo, error) {
	shmds := C.struct_shmid_ds{}
	rc, err := C.shmctl(C.int(shm.id), C.IPC_STAT, &shmds)
	if rc == -1 {
		return nil, err
	}
	shminf := SHMInfo{
		Perms: IpcPerms{
			OwnerUID:   int(shmds.shm_perm.uid),
			OwnerGID:   int(shmds.shm_perm.gid),
			CreatorUID: int(shmds.shm_perm.cuid),
			CreatorGID: int(shmds.shm_perm.cgid),
			Mode:       uint16(shmds.shm_perm.mode),
		},
		SegmentSize:     uint(shmds.shm_segsz),
		LastAttach:      time.Unix(int64(shmds.shm_atime), 0),
		LastDetach:      time.Unix(int64(shmds.shm_dtime), 0),
		LastChange:      time.Unix(int64(shmds.shm_ctime), 0),
		CreatorPID:      int(shmds.shm_cpid),
		LastUserPID:     int(shmds.shm_lpid),
		CurrentAttaches: uint(shmds.shm_nattch),
	}
	return &shminf, nil
}
func (shm *SharedMem) Set(info *SHMInfo) error {
	shmds := &C.struct_shmid_ds{
		shm_perm: C.struct_ipc_perm{
			uid:  C.__uid_t(info.Perms.OwnerUID),
			gid:  C.__gid_t(info.Perms.OwnerGID),
			mode: C.ushort(info.Perms.Mode & 0x1FF),
		},
	}
	rc, err := C.shmctl(C.int(shm.id), C.IPC_SET, shmds)
	if rc == -1 {
		return err
	}
	return nil
}
func (shm *SharedMem) Remove() error {
	rc, err := C.shmctl(C.int(shm.id), C.IPC_RMID, nil)
	if rc == -1 {
		return err
	}
	return nil
}
type SharedMemMount struct {
	ptr            unsafe.Pointer
	offset, length uint
	readonly bool
}