-
Notifications
You must be signed in to change notification settings - Fork 1
/
posix.go
166 lines (144 loc) · 5.1 KB
/
posix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
//go:build darwin || linux
// Package posix is a golang implementation for mmap, shm_open for MacOSx and Linux without CGO !
// MacOSx has an emulation for memfd_create using shm_open.
package posix
import (
"syscall"
"unsafe"
)
//ShmOpen
//Create and open a new object, or open an existing object.
//This is analogous to open. The call returns a file
//descriptor for use by the other interfaces listed below.
func ShmOpen(name string, oflag int, mode uint32) (fd int, err error) {
return shmOpen(name, oflag, mode)
}
//Ftruncate
//Set the size of the shared memory object. (A newly
//created shared memory object has a length of zero.)
func Ftruncate(fd int, length int) error {
return ftruncate(fd, length)
}
//Madvise
//This system call is used to give advice or directions to
//the kernel about the address range beginning at address addr and
//with size length bytes In most cases, the goal of such advice is
//to improve system or application performance.
func Madvise(b []byte, behav int) error {
return madvise(b, behav)
}
//Mmap
//Map the shared memory object into the virtual address
//space of the calling process.
//MmapAt has the same parameters as the C mmap implementation where the address is exposed.
func Mmap(address unsafe.Pointer, length int, prot int, flags int, fd int, offset int64) (data []byte, add uintptr, err error) {
return mapper.Mmap(address, uintptr(length), prot, flags, fd, offset)
}
//Munmap
//Unmap the shared memory object from the virtual address
//space of the calling process.
func Munmap(b []byte) error {
return mapper.Munmap(b)
}
//Mprotect
//changes the access protections for the calling
//process's memory pages containing any part of the address range
//in the interval [addr, addr+len-1]. addr must be aligned to a
//page boundary.
func Mprotect(b []byte, prot int) error {
return mprotect(b, prot)
}
//Mlock
//lock part of the calling process's virtual address space into RAM,
//preventing that memory from being paged to the swap area.
func Mlock(b []byte, size int) error {
return mlock(b, size)
}
//Munlock
//perform the converse operation,
//unlocking part of the calling process's virtual address
//space, so that pages in the specified virtual address range may
//once more to be swapped out if required by the kernel memory
//manager.
func Munlock(b []byte, size int) error {
return munlock(b, size)
}
//Mlockall
//lock all calling process's virtual address space into RAM,
//preventing that memory from being paged to the swap area.
func Mlockall(flags int) error {
return mlockall(flags)
}
//Munlockall
//perform the converse operation,
//unlocking all calling process's virtual address
//space, so that pages in the specified virtual address range may
//once more to be swapped out if required by the kernel memory
//manager.
func Munlockall() error {
return munlockall()
}
//Msync flushes changes made to the in-core copy of a file that
//was mapped into memory using mmap(2) back to the filesystem.
//Without use of this call, there is no guarantee that changes are
//written back before munmap(2) is called. To be more precise, the
//part of the file that corresponds to the memory area starting at
//addr and having length 'length' is updated.
func Msync(b []byte, flags int) error {
return msync(b, flags)
}
//ShmUnlink
//Remove a shared memory object shmName.
func ShmUnlink(path string) (err error) {
return shmUnlink(path)
}
//Close
//the file descriptor allocated by shm_open(3) when it
//is no longer needed.
func Close(fd int) error {
return closeFd(fd)
}
//Fstat
//Obtain a stat structure that describes the shared memory
//object. Among the information returned by this call are
//the object's size (st_size), permissions (st_mode), owner
//(st_uid), and group (st_gid).
func Fstat(fd int, stat *Stat_t) error {
return fstat(fd, stat)
}
//Fchown
//To change the ownership of a shared memory object.
func Fchown(fd int, uid int, gid int) error {
return fchown(fd, uid, gid)
}
//Fchmod
//To change the permissions of a shared memory object.
func Fchmod(fd int, mode int) error {
return fchmod(fd, mode)
}
//Fcntl performs one of the operations described below on the
//open file descriptor fd. The operation is determined by cmd
func Fcntl(fd int, cmd int, arg int) (val int, err error) {
return fcntl(fd, cmd, arg)
}
//Getpagesize
//The function returns the number of bytes in a memory page,
//where "page" is a fixed-length block, the unit for
//memory allocation and file mapping performed by mmap
func Getpagesize() int {
return syscall.Getpagesize()
}
//MemfdCreate creates an anonymous file and returns a file
//descriptor that refers to it. The file behaves like a regular
//file, and so can be modified, truncated, memory-mapped, and so
//on. However, unlike a regular file, it lives in RAM and has a
//volatile backing storage. Once all references to the file are
//dropped, it is automatically released.
//
//NOTE: MacOSx is an Emulation of the original function in Linux
// is made for testing only
func MemfdCreate(name string, flags int) (fd int, err error) {
return memfdCreate(name, flags)
}
// Single-word zero for use when we need a valid pointer to 0 bytes.
var _zero uintptr