Debian Codegraph @

shiny/driver/x11driver/shm_openbsd_syscall.go

raw symbols SCIP
1 // Copyright 2017 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 openbsd && (i386 || amd64)
6
7 package x11driver
8
9 import (
10 "fmt"
11 "syscall"
12 "unsafe"
13 )
14
15 // These constants are from /usr/include/sys/ipc.h
16 const (
17 ipcPrivate = 0
18 ipcRmID = 0
19 )
20
21 func shmOpen(size int) (shmid uintptr, addr unsafe.Pointer, err error) {
22 shmid, _, errno0 := syscall.RawSyscall(syscall.SYS_SHMGET, ipcPrivate, uintptr(size), 0666)
23 if errno0 != 0 {
24 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmget: %v", errno0)
25 }
26 p, _, errno1 := syscall.RawSyscall(syscall.SYS_SHMAT, shmid, 0, 0)
27 _, _, errno2 := syscall.RawSyscall(syscall.SYS_SHMCTL, shmid, ipcRmID, 0)
28 if errno1 != 0 {
29 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmat: %v", errno1)
30 }
31 if errno2 != 0 {
32 return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmctl: %v", errno2)
33 }
34 return shmid, unsafe.Pointer(p), nil
35 }
36
37 func shmClose(p unsafe.Pointer) error {
38 _, _, errno := syscall.RawSyscall(syscall.SYS_SHMDT, uintptr(p), 0, 0)
39 if errno != 0 {
40 return fmt.Errorf("shmdt: %v", errno)
41 }
42 return nil
43 }