shiny/driver/x11driver: add support for other architectures on linux
Tested on linux/386.
Change-Id: I9a3a2744a0b057e258189780ca29f4bf2a72deb8
Reviewed-on: https://go-review.googlesource.com/31652
Run-TryBot: Minux Ma <minux@golang.org>
Reviewed-by: Nigel Tao <nigeltao@golang.org>
diff --git a/shiny/driver/x11driver/shm_linux_ipc.go b/shiny/driver/x11driver/shm_linux_ipc.go
new file mode 100644
index 0000000..025f3ff
--- /dev/null
+++ b/shiny/driver/x11driver/shm_linux_ipc.go
@@ -0,0 +1,49 @@
+// Copyright 2016 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// +build linux
+// +build 386 ppc64 ppc64le s390x
+
+package x11driver
+
+import (
+ "fmt"
+ "syscall"
+ "unsafe"
+)
+
+// These constants are from /usr/include/linux/ipc.h
+const (
+ ipcPrivate = 0
+ ipcRmID = 0
+
+ shmAt = 21
+ shmDt = 22
+ shmGet = 23
+ shmCtl = 24
+)
+
+func shmOpen(size int) (shmid uintptr, addr unsafe.Pointer, err error) {
+ shmid, _, errno0 := syscall.RawSyscall6(syscall.SYS_IPC, shmGet, ipcPrivate, uintptr(size), 0600, 0, 0)
+ if errno0 != 0 {
+ return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmget: %v", errno0)
+ }
+ _, _, errno1 := syscall.RawSyscall6(syscall.SYS_IPC, shmAt, shmid, 0, uintptr(unsafe.Pointer(&addr)), 0, 0)
+ _, _, errno2 := syscall.RawSyscall6(syscall.SYS_IPC, shmCtl, shmid, ipcRmID, 0, 0, 0)
+ if errno1 != 0 {
+ return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmat: %v", errno1)
+ }
+ if errno2 != 0 {
+ return 0, unsafe.Pointer(uintptr(0)), fmt.Errorf("shmctl: %v", errno2)
+ }
+ return shmid, addr, nil
+}
+
+func shmClose(p unsafe.Pointer) error {
+ _, _, errno := syscall.RawSyscall6(syscall.SYS_IPC, shmDt, 0, 0, 0, uintptr(p), 0)
+ if errno != 0 {
+ return fmt.Errorf("shmdt: %v", errno)
+ }
+ return nil
+}
diff --git a/shiny/driver/x11driver/shm_linux_amd64.go b/shiny/driver/x11driver/shm_linux_syscall.go
similarity index 94%
rename from shiny/driver/x11driver/shm_linux_amd64.go
rename to shiny/driver/x11driver/shm_linux_syscall.go
index eda5ce7..3cbf80c 100644
--- a/shiny/driver/x11driver/shm_linux_amd64.go
+++ b/shiny/driver/x11driver/shm_linux_syscall.go
@@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
+// +build linux
+// +build amd64 arm arm64 mips64 mips64le
+
package x11driver
import (
diff --git a/shiny/driver/x11driver/shm_other.go b/shiny/driver/x11driver/shm_other.go
index be0634b..ee0a92c 100644
--- a/shiny/driver/x11driver/shm_other.go
+++ b/shiny/driver/x11driver/shm_other.go
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build !linux !amd64
+// +build !linux
package x11driver