github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/exp/shiny/driver/x11driver/shm_linux_amd64.go (about)

     1  // Copyright 2015 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  package x11driver
     6  
     7  import (
     8  	"syscall"
     9  	"unsafe"
    10  )
    11  
    12  // These constants are from /usr/include/linux/ipc.h
    13  const (
    14  	ipcPrivate = 0
    15  	ipcCreat   = 0x1000
    16  	ipcRmID    = 0
    17  )
    18  
    19  func shmOpen(size int) (shmid uintptr, addr unsafe.Pointer, err error) {
    20  	shmid, _, errno0 := syscall.RawSyscall(syscall.SYS_SHMGET, ipcPrivate, uintptr(size), ipcCreat|0600)
    21  	if errno0 != 0 {
    22  		return 0, unsafe.Pointer(uintptr(0)), errno0
    23  	}
    24  	p, _, errno1 := syscall.RawSyscall(syscall.SYS_SHMAT, shmid, 0, 0)
    25  	_, _, errno2 := syscall.RawSyscall(syscall.SYS_SHMCTL, shmid, ipcRmID, 0)
    26  	if errno1 != 0 {
    27  		return 0, unsafe.Pointer(uintptr(0)), errno1
    28  	}
    29  	if errno2 != 0 {
    30  		return 0, unsafe.Pointer(uintptr(0)), errno2
    31  	}
    32  	return shmid, unsafe.Pointer(p), nil
    33  }
    34  
    35  func shmClose(p unsafe.Pointer) error {
    36  	_, _, errno := syscall.RawSyscall(syscall.SYS_SHMDT, uintptr(p), 0, 0)
    37  	if errno != 0 {
    38  		return errno
    39  	}
    40  	return nil
    41  }