You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

665 lines
17 KiB

  1. // Copyright 2009 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. // +build darwin dragonfly freebsd netbsd openbsd
  5. // BSD system call wrappers shared by *BSD based systems
  6. // including OS X (Darwin) and FreeBSD. Like the other
  7. // syscall_*.go files it is compiled as Go code but also
  8. // used as input to mksyscall which parses the //sys
  9. // lines and generates system call stubs.
  10. package unix
  11. import (
  12. "runtime"
  13. "syscall"
  14. "unsafe"
  15. )
  16. /*
  17. * Wrapped
  18. */
  19. //sysnb getgroups(ngid int, gid *_Gid_t) (n int, err error)
  20. //sysnb setgroups(ngid int, gid *_Gid_t) (err error)
  21. func Getgroups() (gids []int, err error) {
  22. n, err := getgroups(0, nil)
  23. if err != nil {
  24. return nil, err
  25. }
  26. if n == 0 {
  27. return nil, nil
  28. }
  29. // Sanity check group count. Max is 16 on BSD.
  30. if n < 0 || n > 1000 {
  31. return nil, EINVAL
  32. }
  33. a := make([]_Gid_t, n)
  34. n, err = getgroups(n, &a[0])
  35. if err != nil {
  36. return nil, err
  37. }
  38. gids = make([]int, n)
  39. for i, v := range a[0:n] {
  40. gids[i] = int(v)
  41. }
  42. return
  43. }
  44. func Setgroups(gids []int) (err error) {
  45. if len(gids) == 0 {
  46. return setgroups(0, nil)
  47. }
  48. a := make([]_Gid_t, len(gids))
  49. for i, v := range gids {
  50. a[i] = _Gid_t(v)
  51. }
  52. return setgroups(len(a), &a[0])
  53. }
  54. func ReadDirent(fd int, buf []byte) (n int, err error) {
  55. // Final argument is (basep *uintptr) and the syscall doesn't take nil.
  56. // 64 bits should be enough. (32 bits isn't even on 386). Since the
  57. // actual system call is getdirentries64, 64 is a good guess.
  58. // TODO(rsc): Can we use a single global basep for all calls?
  59. var base = (*uintptr)(unsafe.Pointer(new(uint64)))
  60. return Getdirentries(fd, buf, base)
  61. }
  62. // Wait status is 7 bits at bottom, either 0 (exited),
  63. // 0x7F (stopped), or a signal number that caused an exit.
  64. // The 0x80 bit is whether there was a core dump.
  65. // An extra number (exit code, signal causing a stop)
  66. // is in the high bits.
  67. type WaitStatus uint32
  68. const (
  69. mask = 0x7F
  70. core = 0x80
  71. shift = 8
  72. exited = 0
  73. stopped = 0x7F
  74. )
  75. func (w WaitStatus) Exited() bool { return w&mask == exited }
  76. func (w WaitStatus) ExitStatus() int {
  77. if w&mask != exited {
  78. return -1
  79. }
  80. return int(w >> shift)
  81. }
  82. func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != 0 }
  83. func (w WaitStatus) Signal() syscall.Signal {
  84. sig := syscall.Signal(w & mask)
  85. if sig == stopped || sig == 0 {
  86. return -1
  87. }
  88. return sig
  89. }
  90. func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
  91. func (w WaitStatus) Stopped() bool { return w&mask == stopped && syscall.Signal(w>>shift) != SIGSTOP }
  92. func (w WaitStatus) Continued() bool { return w&mask == stopped && syscall.Signal(w>>shift) == SIGSTOP }
  93. func (w WaitStatus) StopSignal() syscall.Signal {
  94. if !w.Stopped() {
  95. return -1
  96. }
  97. return syscall.Signal(w>>shift) & 0xFF
  98. }
  99. func (w WaitStatus) TrapCause() int { return -1 }
  100. //sys wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error)
  101. func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
  102. var status _C_int
  103. wpid, err = wait4(pid, &status, options, rusage)
  104. if wstatus != nil {
  105. *wstatus = WaitStatus(status)
  106. }
  107. return
  108. }
  109. //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error)
  110. //sys bind(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  111. //sys connect(s int, addr unsafe.Pointer, addrlen _Socklen) (err error)
  112. //sysnb socket(domain int, typ int, proto int) (fd int, err error)
  113. //sys getsockopt(s int, level int, name int, val unsafe.Pointer, vallen *_Socklen) (err error)
  114. //sys setsockopt(s int, level int, name int, val unsafe.Pointer, vallen uintptr) (err error)
  115. //sysnb getpeername(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  116. //sysnb getsockname(fd int, rsa *RawSockaddrAny, addrlen *_Socklen) (err error)
  117. //sys Shutdown(s int, how int) (err error)
  118. func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
  119. if sa.Port < 0 || sa.Port > 0xFFFF {
  120. return nil, 0, EINVAL
  121. }
  122. sa.raw.Len = SizeofSockaddrInet4
  123. sa.raw.Family = AF_INET
  124. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  125. p[0] = byte(sa.Port >> 8)
  126. p[1] = byte(sa.Port)
  127. for i := 0; i < len(sa.Addr); i++ {
  128. sa.raw.Addr[i] = sa.Addr[i]
  129. }
  130. return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
  131. }
  132. func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
  133. if sa.Port < 0 || sa.Port > 0xFFFF {
  134. return nil, 0, EINVAL
  135. }
  136. sa.raw.Len = SizeofSockaddrInet6
  137. sa.raw.Family = AF_INET6
  138. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  139. p[0] = byte(sa.Port >> 8)
  140. p[1] = byte(sa.Port)
  141. sa.raw.Scope_id = sa.ZoneId
  142. for i := 0; i < len(sa.Addr); i++ {
  143. sa.raw.Addr[i] = sa.Addr[i]
  144. }
  145. return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
  146. }
  147. func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
  148. name := sa.Name
  149. n := len(name)
  150. if n >= len(sa.raw.Path) || n == 0 {
  151. return nil, 0, EINVAL
  152. }
  153. sa.raw.Len = byte(3 + n) // 2 for Family, Len; 1 for NUL
  154. sa.raw.Family = AF_UNIX
  155. for i := 0; i < n; i++ {
  156. sa.raw.Path[i] = int8(name[i])
  157. }
  158. return unsafe.Pointer(&sa.raw), _Socklen(sa.raw.Len), nil
  159. }
  160. func (sa *SockaddrDatalink) sockaddr() (unsafe.Pointer, _Socklen, error) {
  161. if sa.Index == 0 {
  162. return nil, 0, EINVAL
  163. }
  164. sa.raw.Len = sa.Len
  165. sa.raw.Family = AF_LINK
  166. sa.raw.Index = sa.Index
  167. sa.raw.Type = sa.Type
  168. sa.raw.Nlen = sa.Nlen
  169. sa.raw.Alen = sa.Alen
  170. sa.raw.Slen = sa.Slen
  171. for i := 0; i < len(sa.raw.Data); i++ {
  172. sa.raw.Data[i] = sa.Data[i]
  173. }
  174. return unsafe.Pointer(&sa.raw), SizeofSockaddrDatalink, nil
  175. }
  176. func anyToSockaddr(rsa *RawSockaddrAny) (Sockaddr, error) {
  177. switch rsa.Addr.Family {
  178. case AF_LINK:
  179. pp := (*RawSockaddrDatalink)(unsafe.Pointer(rsa))
  180. sa := new(SockaddrDatalink)
  181. sa.Len = pp.Len
  182. sa.Family = pp.Family
  183. sa.Index = pp.Index
  184. sa.Type = pp.Type
  185. sa.Nlen = pp.Nlen
  186. sa.Alen = pp.Alen
  187. sa.Slen = pp.Slen
  188. for i := 0; i < len(sa.Data); i++ {
  189. sa.Data[i] = pp.Data[i]
  190. }
  191. return sa, nil
  192. case AF_UNIX:
  193. pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
  194. if pp.Len < 2 || pp.Len > SizeofSockaddrUnix {
  195. return nil, EINVAL
  196. }
  197. sa := new(SockaddrUnix)
  198. // Some BSDs include the trailing NUL in the length, whereas
  199. // others do not. Work around this by subtracting the leading
  200. // family and len. The path is then scanned to see if a NUL
  201. // terminator still exists within the length.
  202. n := int(pp.Len) - 2 // subtract leading Family, Len
  203. for i := 0; i < n; i++ {
  204. if pp.Path[i] == 0 {
  205. // found early NUL; assume Len included the NUL
  206. // or was overestimating.
  207. n = i
  208. break
  209. }
  210. }
  211. bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
  212. sa.Name = string(bytes)
  213. return sa, nil
  214. case AF_INET:
  215. pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
  216. sa := new(SockaddrInet4)
  217. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  218. sa.Port = int(p[0])<<8 + int(p[1])
  219. for i := 0; i < len(sa.Addr); i++ {
  220. sa.Addr[i] = pp.Addr[i]
  221. }
  222. return sa, nil
  223. case AF_INET6:
  224. pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
  225. sa := new(SockaddrInet6)
  226. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  227. sa.Port = int(p[0])<<8 + int(p[1])
  228. sa.ZoneId = pp.Scope_id
  229. for i := 0; i < len(sa.Addr); i++ {
  230. sa.Addr[i] = pp.Addr[i]
  231. }
  232. return sa, nil
  233. }
  234. return nil, EAFNOSUPPORT
  235. }
  236. func Accept(fd int) (nfd int, sa Sockaddr, err error) {
  237. var rsa RawSockaddrAny
  238. var len _Socklen = SizeofSockaddrAny
  239. nfd, err = accept(fd, &rsa, &len)
  240. if err != nil {
  241. return
  242. }
  243. if runtime.GOOS == "darwin" && len == 0 {
  244. // Accepted socket has no address.
  245. // This is likely due to a bug in xnu kernels,
  246. // where instead of ECONNABORTED error socket
  247. // is accepted, but has no address.
  248. Close(nfd)
  249. return 0, nil, ECONNABORTED
  250. }
  251. sa, err = anyToSockaddr(&rsa)
  252. if err != nil {
  253. Close(nfd)
  254. nfd = 0
  255. }
  256. return
  257. }
  258. func Getsockname(fd int) (sa Sockaddr, err error) {
  259. var rsa RawSockaddrAny
  260. var len _Socklen = SizeofSockaddrAny
  261. if err = getsockname(fd, &rsa, &len); err != nil {
  262. return
  263. }
  264. // TODO(jsing): DragonFly has a "bug" (see issue 3349), which should be
  265. // reported upstream.
  266. if runtime.GOOS == "dragonfly" && rsa.Addr.Family == AF_UNSPEC && rsa.Addr.Len == 0 {
  267. rsa.Addr.Family = AF_UNIX
  268. rsa.Addr.Len = SizeofSockaddrUnix
  269. }
  270. return anyToSockaddr(&rsa)
  271. }
  272. //sysnb socketpair(domain int, typ int, proto int, fd *[2]int32) (err error)
  273. func GetsockoptByte(fd, level, opt int) (value byte, err error) {
  274. var n byte
  275. vallen := _Socklen(1)
  276. err = getsockopt(fd, level, opt, unsafe.Pointer(&n), &vallen)
  277. return n, err
  278. }
  279. func GetsockoptInet4Addr(fd, level, opt int) (value [4]byte, err error) {
  280. vallen := _Socklen(4)
  281. err = getsockopt(fd, level, opt, unsafe.Pointer(&value[0]), &vallen)
  282. return value, err
  283. }
  284. func GetsockoptIPMreq(fd, level, opt int) (*IPMreq, error) {
  285. var value IPMreq
  286. vallen := _Socklen(SizeofIPMreq)
  287. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  288. return &value, err
  289. }
  290. func GetsockoptIPv6Mreq(fd, level, opt int) (*IPv6Mreq, error) {
  291. var value IPv6Mreq
  292. vallen := _Socklen(SizeofIPv6Mreq)
  293. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  294. return &value, err
  295. }
  296. func GetsockoptIPv6MTUInfo(fd, level, opt int) (*IPv6MTUInfo, error) {
  297. var value IPv6MTUInfo
  298. vallen := _Socklen(SizeofIPv6MTUInfo)
  299. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  300. return &value, err
  301. }
  302. func GetsockoptICMPv6Filter(fd, level, opt int) (*ICMPv6Filter, error) {
  303. var value ICMPv6Filter
  304. vallen := _Socklen(SizeofICMPv6Filter)
  305. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  306. return &value, err
  307. }
  308. // GetsockoptString returns the string value of the socket option opt for the
  309. // socket associated with fd at the given socket level.
  310. func GetsockoptString(fd, level, opt int) (string, error) {
  311. buf := make([]byte, 256)
  312. vallen := _Socklen(len(buf))
  313. err := getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
  314. if err != nil {
  315. return "", err
  316. }
  317. return string(buf[:vallen-1]), nil
  318. }
  319. //sys recvfrom(fd int, p []byte, flags int, from *RawSockaddrAny, fromlen *_Socklen) (n int, err error)
  320. //sys sendto(s int, buf []byte, flags int, to unsafe.Pointer, addrlen _Socklen) (err error)
  321. //sys recvmsg(s int, msg *Msghdr, flags int) (n int, err error)
  322. func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {
  323. var msg Msghdr
  324. var rsa RawSockaddrAny
  325. msg.Name = (*byte)(unsafe.Pointer(&rsa))
  326. msg.Namelen = uint32(SizeofSockaddrAny)
  327. var iov Iovec
  328. if len(p) > 0 {
  329. iov.Base = (*byte)(unsafe.Pointer(&p[0]))
  330. iov.SetLen(len(p))
  331. }
  332. var dummy byte
  333. if len(oob) > 0 {
  334. // receive at least one normal byte
  335. if len(p) == 0 {
  336. iov.Base = &dummy
  337. iov.SetLen(1)
  338. }
  339. msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
  340. msg.SetControllen(len(oob))
  341. }
  342. msg.Iov = &iov
  343. msg.Iovlen = 1
  344. if n, err = recvmsg(fd, &msg, flags); err != nil {
  345. return
  346. }
  347. oobn = int(msg.Controllen)
  348. recvflags = int(msg.Flags)
  349. // source address is only specified if the socket is unconnected
  350. if rsa.Addr.Family != AF_UNSPEC {
  351. from, err = anyToSockaddr(&rsa)
  352. }
  353. return
  354. }
  355. //sys sendmsg(s int, msg *Msghdr, flags int) (n int, err error)
  356. func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
  357. _, err = SendmsgN(fd, p, oob, to, flags)
  358. return
  359. }
  360. func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) {
  361. var ptr unsafe.Pointer
  362. var salen _Socklen
  363. if to != nil {
  364. ptr, salen, err = to.sockaddr()
  365. if err != nil {
  366. return 0, err
  367. }
  368. }
  369. var msg Msghdr
  370. msg.Name = (*byte)(unsafe.Pointer(ptr))
  371. msg.Namelen = uint32(salen)
  372. var iov Iovec
  373. if len(p) > 0 {
  374. iov.Base = (*byte)(unsafe.Pointer(&p[0]))
  375. iov.SetLen(len(p))
  376. }
  377. var dummy byte
  378. if len(oob) > 0 {
  379. // send at least one normal byte
  380. if len(p) == 0 {
  381. iov.Base = &dummy
  382. iov.SetLen(1)
  383. }
  384. msg.Control = (*byte)(unsafe.Pointer(&oob[0]))
  385. msg.SetControllen(len(oob))
  386. }
  387. msg.Iov = &iov
  388. msg.Iovlen = 1
  389. if n, err = sendmsg(fd, &msg, flags); err != nil {
  390. return 0, err
  391. }
  392. if len(oob) > 0 && len(p) == 0 {
  393. n = 0
  394. }
  395. return n, nil
  396. }
  397. //sys kevent(kq int, change unsafe.Pointer, nchange int, event unsafe.Pointer, nevent int, timeout *Timespec) (n int, err error)
  398. func Kevent(kq int, changes, events []Kevent_t, timeout *Timespec) (n int, err error) {
  399. var change, event unsafe.Pointer
  400. if len(changes) > 0 {
  401. change = unsafe.Pointer(&changes[0])
  402. }
  403. if len(events) > 0 {
  404. event = unsafe.Pointer(&events[0])
  405. }
  406. return kevent(kq, change, len(changes), event, len(events), timeout)
  407. }
  408. //sys sysctl(mib []_C_int, old *byte, oldlen *uintptr, new *byte, newlen uintptr) (err error) = SYS___SYSCTL
  409. // sysctlmib translates name to mib number and appends any additional args.
  410. func sysctlmib(name string, args ...int) ([]_C_int, error) {
  411. // Translate name to mib number.
  412. mib, err := nametomib(name)
  413. if err != nil {
  414. return nil, err
  415. }
  416. for _, a := range args {
  417. mib = append(mib, _C_int(a))
  418. }
  419. return mib, nil
  420. }
  421. func Sysctl(name string) (string, error) {
  422. return SysctlArgs(name)
  423. }
  424. func SysctlArgs(name string, args ...int) (string, error) {
  425. buf, err := SysctlRaw(name, args...)
  426. if err != nil {
  427. return "", err
  428. }
  429. n := len(buf)
  430. // Throw away terminating NUL.
  431. if n > 0 && buf[n-1] == '\x00' {
  432. n--
  433. }
  434. return string(buf[0:n]), nil
  435. }
  436. func SysctlUint32(name string) (uint32, error) {
  437. return SysctlUint32Args(name)
  438. }
  439. func SysctlUint32Args(name string, args ...int) (uint32, error) {
  440. mib, err := sysctlmib(name, args...)
  441. if err != nil {
  442. return 0, err
  443. }
  444. n := uintptr(4)
  445. buf := make([]byte, 4)
  446. if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil {
  447. return 0, err
  448. }
  449. if n != 4 {
  450. return 0, EIO
  451. }
  452. return *(*uint32)(unsafe.Pointer(&buf[0])), nil
  453. }
  454. func SysctlUint64(name string, args ...int) (uint64, error) {
  455. mib, err := sysctlmib(name, args...)
  456. if err != nil {
  457. return 0, err
  458. }
  459. n := uintptr(8)
  460. buf := make([]byte, 8)
  461. if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil {
  462. return 0, err
  463. }
  464. if n != 8 {
  465. return 0, EIO
  466. }
  467. return *(*uint64)(unsafe.Pointer(&buf[0])), nil
  468. }
  469. func SysctlRaw(name string, args ...int) ([]byte, error) {
  470. mib, err := sysctlmib(name, args...)
  471. if err != nil {
  472. return nil, err
  473. }
  474. // Find size.
  475. n := uintptr(0)
  476. if err := sysctl(mib, nil, &n, nil, 0); err != nil {
  477. return nil, err
  478. }
  479. if n == 0 {
  480. return nil, nil
  481. }
  482. // Read into buffer of that size.
  483. buf := make([]byte, n)
  484. if err := sysctl(mib, &buf[0], &n, nil, 0); err != nil {
  485. return nil, err
  486. }
  487. // The actual call may return less than the original reported required
  488. // size so ensure we deal with that.
  489. return buf[:n], nil
  490. }
  491. //sys utimes(path string, timeval *[2]Timeval) (err error)
  492. func Utimes(path string, tv []Timeval) error {
  493. if tv == nil {
  494. return utimes(path, nil)
  495. }
  496. if len(tv) != 2 {
  497. return EINVAL
  498. }
  499. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  500. }
  501. func UtimesNano(path string, ts []Timespec) error {
  502. if ts == nil {
  503. err := utimensat(AT_FDCWD, path, nil, 0)
  504. if err != ENOSYS {
  505. return err
  506. }
  507. return utimes(path, nil)
  508. }
  509. if len(ts) != 2 {
  510. return EINVAL
  511. }
  512. // Darwin setattrlist can set nanosecond timestamps
  513. err := setattrlistTimes(path, ts, 0)
  514. if err != ENOSYS {
  515. return err
  516. }
  517. err = utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  518. if err != ENOSYS {
  519. return err
  520. }
  521. // Not as efficient as it could be because Timespec and
  522. // Timeval have different types in the different OSes
  523. tv := [2]Timeval{
  524. NsecToTimeval(TimespecToNsec(ts[0])),
  525. NsecToTimeval(TimespecToNsec(ts[1])),
  526. }
  527. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  528. }
  529. func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error {
  530. if ts == nil {
  531. return utimensat(dirfd, path, nil, flags)
  532. }
  533. if len(ts) != 2 {
  534. return EINVAL
  535. }
  536. err := setattrlistTimes(path, ts, flags)
  537. if err != ENOSYS {
  538. return err
  539. }
  540. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), flags)
  541. }
  542. //sys futimes(fd int, timeval *[2]Timeval) (err error)
  543. func Futimes(fd int, tv []Timeval) error {
  544. if tv == nil {
  545. return futimes(fd, nil)
  546. }
  547. if len(tv) != 2 {
  548. return EINVAL
  549. }
  550. return futimes(fd, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  551. }
  552. //sys fcntl(fd int, cmd int, arg int) (val int, err error)
  553. //sys poll(fds *PollFd, nfds int, timeout int) (n int, err error)
  554. func Poll(fds []PollFd, timeout int) (n int, err error) {
  555. if len(fds) == 0 {
  556. return poll(nil, 0, timeout)
  557. }
  558. return poll(&fds[0], len(fds), timeout)
  559. }
  560. // TODO: wrap
  561. // Acct(name nil-string) (err error)
  562. // Gethostuuid(uuid *byte, timeout *Timespec) (err error)
  563. // Ptrace(req int, pid int, addr uintptr, data int) (ret uintptr, err error)
  564. var mapper = &mmapper{
  565. active: make(map[*byte][]byte),
  566. mmap: mmap,
  567. munmap: munmap,
  568. }
  569. func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
  570. return mapper.Mmap(fd, offset, length, prot, flags)
  571. }
  572. func Munmap(b []byte) (err error) {
  573. return mapper.Munmap(b)
  574. }
  575. //sys Madvise(b []byte, behav int) (err error)
  576. //sys Mlock(b []byte) (err error)
  577. //sys Mlockall(flags int) (err error)
  578. //sys Mprotect(b []byte, prot int) (err error)
  579. //sys Msync(b []byte, flags int) (err error)
  580. //sys Munlock(b []byte) (err error)
  581. //sys Munlockall() (err error)