Debian Codegraph @

shiny/driver/x11driver/shm_linux_ipc.go

raw symbols SCIP
1 // Copyright 2016 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 linux && (386 || ppc64 || ppc64le || s390x)
6
7 package x11driver
8
9 import (
10 "fmt"
11 "syscall"
12 "unsafe"
13 )
14
15 // These constants are from /usr/include/linux/ipc.h
16 const (
17 ipcPrivate = 0
18 ipcRmID = 0
19
20 shmAt = 21
21 shmDt = 22
22 shmGet = 23
23 shmCtl = 24
24 )
25
26 func shmOpen(size int) (shmid uintptr, addr unsafe.Pointer, err error) {
27 shmid, _, errno0 := syscall.RawSyscall6(syscall.SYS_IPC, shmGet, ipcPrivate, uintptr(size), 0600, 0, 0)
28 if errno0 != 0 {
29 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmget: %v", errno0)
30 }
31 _, _, errno1 := syscall.RawSyscall6(syscall.SYS_IPC, shmAt, shmid, 0, uintptr(unsafe.Pointer(&addr)), 0, 0)
32 _, _, errno2 := syscall.RawSyscall6(syscall.SYS_IPC, shmCtl, shmid, ipcRmID, 0, 0, 0)
33 if errno1 != 0 {
34 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmat: %v", errno1)
35 }
36 if errno2 != 0 {
37 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmctl: %v", errno2)
38 }
39 return shmid, addr, nil
40 }
41
42 func shmClose(p unsafe.Pointer) error {
43 _, _, errno := syscall.RawSyscall6(syscall.SYS_IPC, shmDt, 0, 0, 0, uintptr(p), 0)
44 if errno != 0 {
45 return fmt.Errorf("shmdt: %v", errno)
46 }
47 return nil
48 }