syscall_linux.go 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717
  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. // Linux system calls.
  5. // This file is compiled as ordinary Go code,
  6. // but it is also input to mksyscall,
  7. // which parses the //sys lines and generates system call stubs.
  8. // Note that sometimes we use a lowercase //sys name and
  9. // wrap it in our own nicer implementation.
  10. package unix
  11. import (
  12. "encoding/binary"
  13. "net"
  14. "runtime"
  15. "syscall"
  16. "unsafe"
  17. )
  18. /*
  19. * Wrapped
  20. */
  21. func Access(path string, mode uint32) (err error) {
  22. return Faccessat(AT_FDCWD, path, mode, 0)
  23. }
  24. func Chmod(path string, mode uint32) (err error) {
  25. return Fchmodat(AT_FDCWD, path, mode, 0)
  26. }
  27. func Chown(path string, uid int, gid int) (err error) {
  28. return Fchownat(AT_FDCWD, path, uid, gid, 0)
  29. }
  30. func Creat(path string, mode uint32) (fd int, err error) {
  31. return Open(path, O_CREAT|O_WRONLY|O_TRUNC, mode)
  32. }
  33. //sys fchmodat(dirfd int, path string, mode uint32) (err error)
  34. func Fchmodat(dirfd int, path string, mode uint32, flags int) (err error) {
  35. // Linux fchmodat doesn't support the flags parameter. Mimick glibc's behavior
  36. // and check the flags. Otherwise the mode would be applied to the symlink
  37. // destination which is not what the user expects.
  38. if flags&^AT_SYMLINK_NOFOLLOW != 0 {
  39. return EINVAL
  40. } else if flags&AT_SYMLINK_NOFOLLOW != 0 {
  41. return EOPNOTSUPP
  42. }
  43. return fchmodat(dirfd, path, mode)
  44. }
  45. //sys ioctl(fd int, req uint, arg uintptr) (err error)
  46. // ioctl itself should not be exposed directly, but additional get/set
  47. // functions for specific types are permissible.
  48. // IoctlSetPointerInt performs an ioctl operation which sets an
  49. // integer value on fd, using the specified request number. The ioctl
  50. // argument is called with a pointer to the integer value, rather than
  51. // passing the integer value directly.
  52. func IoctlSetPointerInt(fd int, req uint, value int) error {
  53. v := int32(value)
  54. return ioctl(fd, req, uintptr(unsafe.Pointer(&v)))
  55. }
  56. // IoctlSetInt performs an ioctl operation which sets an integer value
  57. // on fd, using the specified request number.
  58. func IoctlSetInt(fd int, req uint, value int) error {
  59. return ioctl(fd, req, uintptr(value))
  60. }
  61. func ioctlSetWinsize(fd int, req uint, value *Winsize) error {
  62. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  63. }
  64. func ioctlSetTermios(fd int, req uint, value *Termios) error {
  65. return ioctl(fd, req, uintptr(unsafe.Pointer(value)))
  66. }
  67. func IoctlSetRTCTime(fd int, value *RTCTime) error {
  68. err := ioctl(fd, RTC_SET_TIME, uintptr(unsafe.Pointer(value)))
  69. runtime.KeepAlive(value)
  70. return err
  71. }
  72. // IoctlGetInt performs an ioctl operation which gets an integer value
  73. // from fd, using the specified request number.
  74. func IoctlGetInt(fd int, req uint) (int, error) {
  75. var value int
  76. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  77. return value, err
  78. }
  79. func IoctlGetWinsize(fd int, req uint) (*Winsize, error) {
  80. var value Winsize
  81. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  82. return &value, err
  83. }
  84. func IoctlGetTermios(fd int, req uint) (*Termios, error) {
  85. var value Termios
  86. err := ioctl(fd, req, uintptr(unsafe.Pointer(&value)))
  87. return &value, err
  88. }
  89. func IoctlGetRTCTime(fd int) (*RTCTime, error) {
  90. var value RTCTime
  91. err := ioctl(fd, RTC_RD_TIME, uintptr(unsafe.Pointer(&value)))
  92. return &value, err
  93. }
  94. //sys Linkat(olddirfd int, oldpath string, newdirfd int, newpath string, flags int) (err error)
  95. func Link(oldpath string, newpath string) (err error) {
  96. return Linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0)
  97. }
  98. func Mkdir(path string, mode uint32) (err error) {
  99. return Mkdirat(AT_FDCWD, path, mode)
  100. }
  101. func Mknod(path string, mode uint32, dev int) (err error) {
  102. return Mknodat(AT_FDCWD, path, mode, dev)
  103. }
  104. func Open(path string, mode int, perm uint32) (fd int, err error) {
  105. return openat(AT_FDCWD, path, mode|O_LARGEFILE, perm)
  106. }
  107. //sys openat(dirfd int, path string, flags int, mode uint32) (fd int, err error)
  108. func Openat(dirfd int, path string, flags int, mode uint32) (fd int, err error) {
  109. return openat(dirfd, path, flags|O_LARGEFILE, mode)
  110. }
  111. //sys ppoll(fds *PollFd, nfds int, timeout *Timespec, sigmask *Sigset_t) (n int, err error)
  112. func Ppoll(fds []PollFd, timeout *Timespec, sigmask *Sigset_t) (n int, err error) {
  113. if len(fds) == 0 {
  114. return ppoll(nil, 0, timeout, sigmask)
  115. }
  116. return ppoll(&fds[0], len(fds), timeout, sigmask)
  117. }
  118. //sys Readlinkat(dirfd int, path string, buf []byte) (n int, err error)
  119. func Readlink(path string, buf []byte) (n int, err error) {
  120. return Readlinkat(AT_FDCWD, path, buf)
  121. }
  122. func Rename(oldpath string, newpath string) (err error) {
  123. return Renameat(AT_FDCWD, oldpath, AT_FDCWD, newpath)
  124. }
  125. func Rmdir(path string) error {
  126. return Unlinkat(AT_FDCWD, path, AT_REMOVEDIR)
  127. }
  128. //sys Symlinkat(oldpath string, newdirfd int, newpath string) (err error)
  129. func Symlink(oldpath string, newpath string) (err error) {
  130. return Symlinkat(oldpath, AT_FDCWD, newpath)
  131. }
  132. func Unlink(path string) error {
  133. return Unlinkat(AT_FDCWD, path, 0)
  134. }
  135. //sys Unlinkat(dirfd int, path string, flags int) (err error)
  136. func Utimes(path string, tv []Timeval) error {
  137. if tv == nil {
  138. err := utimensat(AT_FDCWD, path, nil, 0)
  139. if err != ENOSYS {
  140. return err
  141. }
  142. return utimes(path, nil)
  143. }
  144. if len(tv) != 2 {
  145. return EINVAL
  146. }
  147. var ts [2]Timespec
  148. ts[0] = NsecToTimespec(TimevalToNsec(tv[0]))
  149. ts[1] = NsecToTimespec(TimevalToNsec(tv[1]))
  150. err := utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  151. if err != ENOSYS {
  152. return err
  153. }
  154. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  155. }
  156. //sys utimensat(dirfd int, path string, times *[2]Timespec, flags int) (err error)
  157. func UtimesNano(path string, ts []Timespec) error {
  158. if ts == nil {
  159. err := utimensat(AT_FDCWD, path, nil, 0)
  160. if err != ENOSYS {
  161. return err
  162. }
  163. return utimes(path, nil)
  164. }
  165. if len(ts) != 2 {
  166. return EINVAL
  167. }
  168. err := utimensat(AT_FDCWD, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), 0)
  169. if err != ENOSYS {
  170. return err
  171. }
  172. // If the utimensat syscall isn't available (utimensat was added to Linux
  173. // in 2.6.22, Released, 8 July 2007) then fall back to utimes
  174. var tv [2]Timeval
  175. for i := 0; i < 2; i++ {
  176. tv[i] = NsecToTimeval(TimespecToNsec(ts[i]))
  177. }
  178. return utimes(path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  179. }
  180. func UtimesNanoAt(dirfd int, path string, ts []Timespec, flags int) error {
  181. if ts == nil {
  182. return utimensat(dirfd, path, nil, flags)
  183. }
  184. if len(ts) != 2 {
  185. return EINVAL
  186. }
  187. return utimensat(dirfd, path, (*[2]Timespec)(unsafe.Pointer(&ts[0])), flags)
  188. }
  189. func Futimesat(dirfd int, path string, tv []Timeval) error {
  190. if tv == nil {
  191. return futimesat(dirfd, path, nil)
  192. }
  193. if len(tv) != 2 {
  194. return EINVAL
  195. }
  196. return futimesat(dirfd, path, (*[2]Timeval)(unsafe.Pointer(&tv[0])))
  197. }
  198. func Futimes(fd int, tv []Timeval) (err error) {
  199. // Believe it or not, this is the best we can do on Linux
  200. // (and is what glibc does).
  201. return Utimes("/proc/self/fd/"+itoa(fd), tv)
  202. }
  203. const ImplementsGetwd = true
  204. //sys Getcwd(buf []byte) (n int, err error)
  205. func Getwd() (wd string, err error) {
  206. var buf [PathMax]byte
  207. n, err := Getcwd(buf[0:])
  208. if err != nil {
  209. return "", err
  210. }
  211. // Getcwd returns the number of bytes written to buf, including the NUL.
  212. if n < 1 || n > len(buf) || buf[n-1] != 0 {
  213. return "", EINVAL
  214. }
  215. return string(buf[0 : n-1]), nil
  216. }
  217. func Getgroups() (gids []int, err error) {
  218. n, err := getgroups(0, nil)
  219. if err != nil {
  220. return nil, err
  221. }
  222. if n == 0 {
  223. return nil, nil
  224. }
  225. // Sanity check group count. Max is 1<<16 on Linux.
  226. if n < 0 || n > 1<<20 {
  227. return nil, EINVAL
  228. }
  229. a := make([]_Gid_t, n)
  230. n, err = getgroups(n, &a[0])
  231. if err != nil {
  232. return nil, err
  233. }
  234. gids = make([]int, n)
  235. for i, v := range a[0:n] {
  236. gids[i] = int(v)
  237. }
  238. return
  239. }
  240. func Setgroups(gids []int) (err error) {
  241. if len(gids) == 0 {
  242. return setgroups(0, nil)
  243. }
  244. a := make([]_Gid_t, len(gids))
  245. for i, v := range gids {
  246. a[i] = _Gid_t(v)
  247. }
  248. return setgroups(len(a), &a[0])
  249. }
  250. type WaitStatus uint32
  251. // Wait status is 7 bits at bottom, either 0 (exited),
  252. // 0x7F (stopped), or a signal number that caused an exit.
  253. // The 0x80 bit is whether there was a core dump.
  254. // An extra number (exit code, signal causing a stop)
  255. // is in the high bits. At least that's the idea.
  256. // There are various irregularities. For example, the
  257. // "continued" status is 0xFFFF, distinguishing itself
  258. // from stopped via the core dump bit.
  259. const (
  260. mask = 0x7F
  261. core = 0x80
  262. exited = 0x00
  263. stopped = 0x7F
  264. shift = 8
  265. )
  266. func (w WaitStatus) Exited() bool { return w&mask == exited }
  267. func (w WaitStatus) Signaled() bool { return w&mask != stopped && w&mask != exited }
  268. func (w WaitStatus) Stopped() bool { return w&0xFF == stopped }
  269. func (w WaitStatus) Continued() bool { return w == 0xFFFF }
  270. func (w WaitStatus) CoreDump() bool { return w.Signaled() && w&core != 0 }
  271. func (w WaitStatus) ExitStatus() int {
  272. if !w.Exited() {
  273. return -1
  274. }
  275. return int(w>>shift) & 0xFF
  276. }
  277. func (w WaitStatus) Signal() syscall.Signal {
  278. if !w.Signaled() {
  279. return -1
  280. }
  281. return syscall.Signal(w & mask)
  282. }
  283. func (w WaitStatus) StopSignal() syscall.Signal {
  284. if !w.Stopped() {
  285. return -1
  286. }
  287. return syscall.Signal(w>>shift) & 0xFF
  288. }
  289. func (w WaitStatus) TrapCause() int {
  290. if w.StopSignal() != SIGTRAP {
  291. return -1
  292. }
  293. return int(w>>shift) >> 8
  294. }
  295. //sys wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err error)
  296. func Wait4(pid int, wstatus *WaitStatus, options int, rusage *Rusage) (wpid int, err error) {
  297. var status _C_int
  298. wpid, err = wait4(pid, &status, options, rusage)
  299. if wstatus != nil {
  300. *wstatus = WaitStatus(status)
  301. }
  302. return
  303. }
  304. func Mkfifo(path string, mode uint32) error {
  305. return Mknod(path, mode|S_IFIFO, 0)
  306. }
  307. func Mkfifoat(dirfd int, path string, mode uint32) error {
  308. return Mknodat(dirfd, path, mode|S_IFIFO, 0)
  309. }
  310. func (sa *SockaddrInet4) sockaddr() (unsafe.Pointer, _Socklen, error) {
  311. if sa.Port < 0 || sa.Port > 0xFFFF {
  312. return nil, 0, EINVAL
  313. }
  314. sa.raw.Family = AF_INET
  315. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  316. p[0] = byte(sa.Port >> 8)
  317. p[1] = byte(sa.Port)
  318. for i := 0; i < len(sa.Addr); i++ {
  319. sa.raw.Addr[i] = sa.Addr[i]
  320. }
  321. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet4, nil
  322. }
  323. func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, _Socklen, error) {
  324. if sa.Port < 0 || sa.Port > 0xFFFF {
  325. return nil, 0, EINVAL
  326. }
  327. sa.raw.Family = AF_INET6
  328. p := (*[2]byte)(unsafe.Pointer(&sa.raw.Port))
  329. p[0] = byte(sa.Port >> 8)
  330. p[1] = byte(sa.Port)
  331. sa.raw.Scope_id = sa.ZoneId
  332. for i := 0; i < len(sa.Addr); i++ {
  333. sa.raw.Addr[i] = sa.Addr[i]
  334. }
  335. return unsafe.Pointer(&sa.raw), SizeofSockaddrInet6, nil
  336. }
  337. func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, _Socklen, error) {
  338. name := sa.Name
  339. n := len(name)
  340. if n >= len(sa.raw.Path) {
  341. return nil, 0, EINVAL
  342. }
  343. sa.raw.Family = AF_UNIX
  344. for i := 0; i < n; i++ {
  345. sa.raw.Path[i] = int8(name[i])
  346. }
  347. // length is family (uint16), name, NUL.
  348. sl := _Socklen(2)
  349. if n > 0 {
  350. sl += _Socklen(n) + 1
  351. }
  352. if sa.raw.Path[0] == '@' {
  353. sa.raw.Path[0] = 0
  354. // Don't count trailing NUL for abstract address.
  355. sl--
  356. }
  357. return unsafe.Pointer(&sa.raw), sl, nil
  358. }
  359. // SockaddrLinklayer implements the Sockaddr interface for AF_PACKET type sockets.
  360. type SockaddrLinklayer struct {
  361. Protocol uint16
  362. Ifindex int
  363. Hatype uint16
  364. Pkttype uint8
  365. Halen uint8
  366. Addr [8]byte
  367. raw RawSockaddrLinklayer
  368. }
  369. func (sa *SockaddrLinklayer) sockaddr() (unsafe.Pointer, _Socklen, error) {
  370. if sa.Ifindex < 0 || sa.Ifindex > 0x7fffffff {
  371. return nil, 0, EINVAL
  372. }
  373. sa.raw.Family = AF_PACKET
  374. sa.raw.Protocol = sa.Protocol
  375. sa.raw.Ifindex = int32(sa.Ifindex)
  376. sa.raw.Hatype = sa.Hatype
  377. sa.raw.Pkttype = sa.Pkttype
  378. sa.raw.Halen = sa.Halen
  379. for i := 0; i < len(sa.Addr); i++ {
  380. sa.raw.Addr[i] = sa.Addr[i]
  381. }
  382. return unsafe.Pointer(&sa.raw), SizeofSockaddrLinklayer, nil
  383. }
  384. // SockaddrNetlink implements the Sockaddr interface for AF_NETLINK type sockets.
  385. type SockaddrNetlink struct {
  386. Family uint16
  387. Pad uint16
  388. Pid uint32
  389. Groups uint32
  390. raw RawSockaddrNetlink
  391. }
  392. func (sa *SockaddrNetlink) sockaddr() (unsafe.Pointer, _Socklen, error) {
  393. sa.raw.Family = AF_NETLINK
  394. sa.raw.Pad = sa.Pad
  395. sa.raw.Pid = sa.Pid
  396. sa.raw.Groups = sa.Groups
  397. return unsafe.Pointer(&sa.raw), SizeofSockaddrNetlink, nil
  398. }
  399. // SockaddrHCI implements the Sockaddr interface for AF_BLUETOOTH type sockets
  400. // using the HCI protocol.
  401. type SockaddrHCI struct {
  402. Dev uint16
  403. Channel uint16
  404. raw RawSockaddrHCI
  405. }
  406. func (sa *SockaddrHCI) sockaddr() (unsafe.Pointer, _Socklen, error) {
  407. sa.raw.Family = AF_BLUETOOTH
  408. sa.raw.Dev = sa.Dev
  409. sa.raw.Channel = sa.Channel
  410. return unsafe.Pointer(&sa.raw), SizeofSockaddrHCI, nil
  411. }
  412. // SockaddrL2 implements the Sockaddr interface for AF_BLUETOOTH type sockets
  413. // using the L2CAP protocol.
  414. type SockaddrL2 struct {
  415. PSM uint16
  416. CID uint16
  417. Addr [6]uint8
  418. AddrType uint8
  419. raw RawSockaddrL2
  420. }
  421. func (sa *SockaddrL2) sockaddr() (unsafe.Pointer, _Socklen, error) {
  422. sa.raw.Family = AF_BLUETOOTH
  423. psm := (*[2]byte)(unsafe.Pointer(&sa.raw.Psm))
  424. psm[0] = byte(sa.PSM)
  425. psm[1] = byte(sa.PSM >> 8)
  426. for i := 0; i < len(sa.Addr); i++ {
  427. sa.raw.Bdaddr[i] = sa.Addr[len(sa.Addr)-1-i]
  428. }
  429. cid := (*[2]byte)(unsafe.Pointer(&sa.raw.Cid))
  430. cid[0] = byte(sa.CID)
  431. cid[1] = byte(sa.CID >> 8)
  432. sa.raw.Bdaddr_type = sa.AddrType
  433. return unsafe.Pointer(&sa.raw), SizeofSockaddrL2, nil
  434. }
  435. // SockaddrRFCOMM implements the Sockaddr interface for AF_BLUETOOTH type sockets
  436. // using the RFCOMM protocol.
  437. //
  438. // Server example:
  439. //
  440. // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)
  441. // _ = unix.Bind(fd, &unix.SockaddrRFCOMM{
  442. // Channel: 1,
  443. // Addr: [6]uint8{0, 0, 0, 0, 0, 0}, // BDADDR_ANY or 00:00:00:00:00:00
  444. // })
  445. // _ = Listen(fd, 1)
  446. // nfd, sa, _ := Accept(fd)
  447. // fmt.Printf("conn addr=%v fd=%d", sa.(*unix.SockaddrRFCOMM).Addr, nfd)
  448. // Read(nfd, buf)
  449. //
  450. // Client example:
  451. //
  452. // fd, _ := Socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM)
  453. // _ = Connect(fd, &SockaddrRFCOMM{
  454. // Channel: 1,
  455. // Addr: [6]byte{0x11, 0x22, 0x33, 0xaa, 0xbb, 0xcc}, // CC:BB:AA:33:22:11
  456. // })
  457. // Write(fd, []byte(`hello`))
  458. type SockaddrRFCOMM struct {
  459. // Addr represents a bluetooth address, byte ordering is little-endian.
  460. Addr [6]uint8
  461. // Channel is a designated bluetooth channel, only 1-30 are available for use.
  462. // Since Linux 2.6.7 and further zero value is the first available channel.
  463. Channel uint8
  464. raw RawSockaddrRFCOMM
  465. }
  466. func (sa *SockaddrRFCOMM) sockaddr() (unsafe.Pointer, _Socklen, error) {
  467. sa.raw.Family = AF_BLUETOOTH
  468. sa.raw.Channel = sa.Channel
  469. sa.raw.Bdaddr = sa.Addr
  470. return unsafe.Pointer(&sa.raw), SizeofSockaddrRFCOMM, nil
  471. }
  472. // SockaddrCAN implements the Sockaddr interface for AF_CAN type sockets.
  473. // The RxID and TxID fields are used for transport protocol addressing in
  474. // (CAN_TP16, CAN_TP20, CAN_MCNET, and CAN_ISOTP), they can be left with
  475. // zero values for CAN_RAW and CAN_BCM sockets as they have no meaning.
  476. //
  477. // The SockaddrCAN struct must be bound to the socket file descriptor
  478. // using Bind before the CAN socket can be used.
  479. //
  480. // // Read one raw CAN frame
  481. // fd, _ := Socket(AF_CAN, SOCK_RAW, CAN_RAW)
  482. // addr := &SockaddrCAN{Ifindex: index}
  483. // Bind(fd, addr)
  484. // frame := make([]byte, 16)
  485. // Read(fd, frame)
  486. //
  487. // The full SocketCAN documentation can be found in the linux kernel
  488. // archives at: https://www.kernel.org/doc/Documentation/networking/can.txt
  489. type SockaddrCAN struct {
  490. Ifindex int
  491. RxID uint32
  492. TxID uint32
  493. raw RawSockaddrCAN
  494. }
  495. func (sa *SockaddrCAN) sockaddr() (unsafe.Pointer, _Socklen, error) {
  496. if sa.Ifindex < 0 || sa.Ifindex > 0x7fffffff {
  497. return nil, 0, EINVAL
  498. }
  499. sa.raw.Family = AF_CAN
  500. sa.raw.Ifindex = int32(sa.Ifindex)
  501. rx := (*[4]byte)(unsafe.Pointer(&sa.RxID))
  502. for i := 0; i < 4; i++ {
  503. sa.raw.Addr[i] = rx[i]
  504. }
  505. tx := (*[4]byte)(unsafe.Pointer(&sa.TxID))
  506. for i := 0; i < 4; i++ {
  507. sa.raw.Addr[i+4] = tx[i]
  508. }
  509. return unsafe.Pointer(&sa.raw), SizeofSockaddrCAN, nil
  510. }
  511. // SockaddrALG implements the Sockaddr interface for AF_ALG type sockets.
  512. // SockaddrALG enables userspace access to the Linux kernel's cryptography
  513. // subsystem. The Type and Name fields specify which type of hash or cipher
  514. // should be used with a given socket.
  515. //
  516. // To create a file descriptor that provides access to a hash or cipher, both
  517. // Bind and Accept must be used. Once the setup process is complete, input
  518. // data can be written to the socket, processed by the kernel, and then read
  519. // back as hash output or ciphertext.
  520. //
  521. // Here is an example of using an AF_ALG socket with SHA1 hashing.
  522. // The initial socket setup process is as follows:
  523. //
  524. // // Open a socket to perform SHA1 hashing.
  525. // fd, _ := unix.Socket(unix.AF_ALG, unix.SOCK_SEQPACKET, 0)
  526. // addr := &unix.SockaddrALG{Type: "hash", Name: "sha1"}
  527. // unix.Bind(fd, addr)
  528. // // Note: unix.Accept does not work at this time; must invoke accept()
  529. // // manually using unix.Syscall.
  530. // hashfd, _, _ := unix.Syscall(unix.SYS_ACCEPT, uintptr(fd), 0, 0)
  531. //
  532. // Once a file descriptor has been returned from Accept, it may be used to
  533. // perform SHA1 hashing. The descriptor is not safe for concurrent use, but
  534. // may be re-used repeatedly with subsequent Write and Read operations.
  535. //
  536. // When hashing a small byte slice or string, a single Write and Read may
  537. // be used:
  538. //
  539. // // Assume hashfd is already configured using the setup process.
  540. // hash := os.NewFile(hashfd, "sha1")
  541. // // Hash an input string and read the results. Each Write discards
  542. // // previous hash state. Read always reads the current state.
  543. // b := make([]byte, 20)
  544. // for i := 0; i < 2; i++ {
  545. // io.WriteString(hash, "Hello, world.")
  546. // hash.Read(b)
  547. // fmt.Println(hex.EncodeToString(b))
  548. // }
  549. // // Output:
  550. // // 2ae01472317d1935a84797ec1983ae243fc6aa28
  551. // // 2ae01472317d1935a84797ec1983ae243fc6aa28
  552. //
  553. // For hashing larger byte slices, or byte streams such as those read from
  554. // a file or socket, use Sendto with MSG_MORE to instruct the kernel to update
  555. // the hash digest instead of creating a new one for a given chunk and finalizing it.
  556. //
  557. // // Assume hashfd and addr are already configured using the setup process.
  558. // hash := os.NewFile(hashfd, "sha1")
  559. // // Hash the contents of a file.
  560. // f, _ := os.Open("/tmp/linux-4.10-rc7.tar.xz")
  561. // b := make([]byte, 4096)
  562. // for {
  563. // n, err := f.Read(b)
  564. // if err == io.EOF {
  565. // break
  566. // }
  567. // unix.Sendto(hashfd, b[:n], unix.MSG_MORE, addr)
  568. // }
  569. // hash.Read(b)
  570. // fmt.Println(hex.EncodeToString(b))
  571. // // Output: 85cdcad0c06eef66f805ecce353bec9accbeecc5
  572. //
  573. // For more information, see: http://www.chronox.de/crypto-API/crypto/userspace-if.html.
  574. type SockaddrALG struct {
  575. Type string
  576. Name string
  577. Feature uint32
  578. Mask uint32
  579. raw RawSockaddrALG
  580. }
  581. func (sa *SockaddrALG) sockaddr() (unsafe.Pointer, _Socklen, error) {
  582. // Leave room for NUL byte terminator.
  583. if len(sa.Type) > 13 {
  584. return nil, 0, EINVAL
  585. }
  586. if len(sa.Name) > 63 {
  587. return nil, 0, EINVAL
  588. }
  589. sa.raw.Family = AF_ALG
  590. sa.raw.Feat = sa.Feature
  591. sa.raw.Mask = sa.Mask
  592. typ, err := ByteSliceFromString(sa.Type)
  593. if err != nil {
  594. return nil, 0, err
  595. }
  596. name, err := ByteSliceFromString(sa.Name)
  597. if err != nil {
  598. return nil, 0, err
  599. }
  600. copy(sa.raw.Type[:], typ)
  601. copy(sa.raw.Name[:], name)
  602. return unsafe.Pointer(&sa.raw), SizeofSockaddrALG, nil
  603. }
  604. // SockaddrVM implements the Sockaddr interface for AF_VSOCK type sockets.
  605. // SockaddrVM provides access to Linux VM sockets: a mechanism that enables
  606. // bidirectional communication between a hypervisor and its guest virtual
  607. // machines.
  608. type SockaddrVM struct {
  609. // CID and Port specify a context ID and port address for a VM socket.
  610. // Guests have a unique CID, and hosts may have a well-known CID of:
  611. // - VMADDR_CID_HYPERVISOR: refers to the hypervisor process.
  612. // - VMADDR_CID_HOST: refers to other processes on the host.
  613. CID uint32
  614. Port uint32
  615. raw RawSockaddrVM
  616. }
  617. func (sa *SockaddrVM) sockaddr() (unsafe.Pointer, _Socklen, error) {
  618. sa.raw.Family = AF_VSOCK
  619. sa.raw.Port = sa.Port
  620. sa.raw.Cid = sa.CID
  621. return unsafe.Pointer(&sa.raw), SizeofSockaddrVM, nil
  622. }
  623. type SockaddrXDP struct {
  624. Flags uint16
  625. Ifindex uint32
  626. QueueID uint32
  627. SharedUmemFD uint32
  628. raw RawSockaddrXDP
  629. }
  630. func (sa *SockaddrXDP) sockaddr() (unsafe.Pointer, _Socklen, error) {
  631. sa.raw.Family = AF_XDP
  632. sa.raw.Flags = sa.Flags
  633. sa.raw.Ifindex = sa.Ifindex
  634. sa.raw.Queue_id = sa.QueueID
  635. sa.raw.Shared_umem_fd = sa.SharedUmemFD
  636. return unsafe.Pointer(&sa.raw), SizeofSockaddrXDP, nil
  637. }
  638. // This constant mirrors the #define of PX_PROTO_OE in
  639. // linux/if_pppox.h. We're defining this by hand here instead of
  640. // autogenerating through mkerrors.sh because including
  641. // linux/if_pppox.h causes some declaration conflicts with other
  642. // includes (linux/if_pppox.h includes linux/in.h, which conflicts
  643. // with netinet/in.h). Given that we only need a single zero constant
  644. // out of that file, it's cleaner to just define it by hand here.
  645. const px_proto_oe = 0
  646. type SockaddrPPPoE struct {
  647. SID uint16
  648. Remote net.HardwareAddr
  649. Dev string
  650. raw RawSockaddrPPPoX
  651. }
  652. func (sa *SockaddrPPPoE) sockaddr() (unsafe.Pointer, _Socklen, error) {
  653. if len(sa.Remote) != 6 {
  654. return nil, 0, EINVAL
  655. }
  656. if len(sa.Dev) > IFNAMSIZ-1 {
  657. return nil, 0, EINVAL
  658. }
  659. *(*uint16)(unsafe.Pointer(&sa.raw[0])) = AF_PPPOX
  660. // This next field is in host-endian byte order. We can't use the
  661. // same unsafe pointer cast as above, because this value is not
  662. // 32-bit aligned and some architectures don't allow unaligned
  663. // access.
  664. //
  665. // However, the value of px_proto_oe is 0, so we can use
  666. // encoding/binary helpers to write the bytes without worrying
  667. // about the ordering.
  668. binary.BigEndian.PutUint32(sa.raw[2:6], px_proto_oe)
  669. // This field is deliberately big-endian, unlike the previous
  670. // one. The kernel expects SID to be in network byte order.
  671. binary.BigEndian.PutUint16(sa.raw[6:8], sa.SID)
  672. copy(sa.raw[8:14], sa.Remote)
  673. for i := 14; i < 14+IFNAMSIZ; i++ {
  674. sa.raw[i] = 0
  675. }
  676. copy(sa.raw[14:], sa.Dev)
  677. return unsafe.Pointer(&sa.raw), SizeofSockaddrPPPoX, nil
  678. }
  679. func anyToSockaddr(fd int, rsa *RawSockaddrAny) (Sockaddr, error) {
  680. switch rsa.Addr.Family {
  681. case AF_NETLINK:
  682. pp := (*RawSockaddrNetlink)(unsafe.Pointer(rsa))
  683. sa := new(SockaddrNetlink)
  684. sa.Family = pp.Family
  685. sa.Pad = pp.Pad
  686. sa.Pid = pp.Pid
  687. sa.Groups = pp.Groups
  688. return sa, nil
  689. case AF_PACKET:
  690. pp := (*RawSockaddrLinklayer)(unsafe.Pointer(rsa))
  691. sa := new(SockaddrLinklayer)
  692. sa.Protocol = pp.Protocol
  693. sa.Ifindex = int(pp.Ifindex)
  694. sa.Hatype = pp.Hatype
  695. sa.Pkttype = pp.Pkttype
  696. sa.Halen = pp.Halen
  697. for i := 0; i < len(sa.Addr); i++ {
  698. sa.Addr[i] = pp.Addr[i]
  699. }
  700. return sa, nil
  701. case AF_UNIX:
  702. pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa))
  703. sa := new(SockaddrUnix)
  704. if pp.Path[0] == 0 {
  705. // "Abstract" Unix domain socket.
  706. // Rewrite leading NUL as @ for textual display.
  707. // (This is the standard convention.)
  708. // Not friendly to overwrite in place,
  709. // but the callers below don't care.
  710. pp.Path[0] = '@'
  711. }
  712. // Assume path ends at NUL.
  713. // This is not technically the Linux semantics for
  714. // abstract Unix domain sockets--they are supposed
  715. // to be uninterpreted fixed-size binary blobs--but
  716. // everyone uses this convention.
  717. n := 0
  718. for n < len(pp.Path) && pp.Path[n] != 0 {
  719. n++
  720. }
  721. bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n]
  722. sa.Name = string(bytes)
  723. return sa, nil
  724. case AF_INET:
  725. pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa))
  726. sa := new(SockaddrInet4)
  727. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  728. sa.Port = int(p[0])<<8 + int(p[1])
  729. for i := 0; i < len(sa.Addr); i++ {
  730. sa.Addr[i] = pp.Addr[i]
  731. }
  732. return sa, nil
  733. case AF_INET6:
  734. pp := (*RawSockaddrInet6)(unsafe.Pointer(rsa))
  735. sa := new(SockaddrInet6)
  736. p := (*[2]byte)(unsafe.Pointer(&pp.Port))
  737. sa.Port = int(p[0])<<8 + int(p[1])
  738. sa.ZoneId = pp.Scope_id
  739. for i := 0; i < len(sa.Addr); i++ {
  740. sa.Addr[i] = pp.Addr[i]
  741. }
  742. return sa, nil
  743. case AF_VSOCK:
  744. pp := (*RawSockaddrVM)(unsafe.Pointer(rsa))
  745. sa := &SockaddrVM{
  746. CID: pp.Cid,
  747. Port: pp.Port,
  748. }
  749. return sa, nil
  750. case AF_BLUETOOTH:
  751. proto, err := GetsockoptInt(fd, SOL_SOCKET, SO_PROTOCOL)
  752. if err != nil {
  753. return nil, err
  754. }
  755. // only BTPROTO_L2CAP and BTPROTO_RFCOMM can accept connections
  756. switch proto {
  757. case BTPROTO_L2CAP:
  758. pp := (*RawSockaddrL2)(unsafe.Pointer(rsa))
  759. sa := &SockaddrL2{
  760. PSM: pp.Psm,
  761. CID: pp.Cid,
  762. Addr: pp.Bdaddr,
  763. AddrType: pp.Bdaddr_type,
  764. }
  765. return sa, nil
  766. case BTPROTO_RFCOMM:
  767. pp := (*RawSockaddrRFCOMM)(unsafe.Pointer(rsa))
  768. sa := &SockaddrRFCOMM{
  769. Channel: pp.Channel,
  770. Addr: pp.Bdaddr,
  771. }
  772. return sa, nil
  773. }
  774. case AF_XDP:
  775. pp := (*RawSockaddrXDP)(unsafe.Pointer(rsa))
  776. sa := &SockaddrXDP{
  777. Flags: pp.Flags,
  778. Ifindex: pp.Ifindex,
  779. QueueID: pp.Queue_id,
  780. SharedUmemFD: pp.Shared_umem_fd,
  781. }
  782. return sa, nil
  783. case AF_PPPOX:
  784. pp := (*RawSockaddrPPPoX)(unsafe.Pointer(rsa))
  785. if binary.BigEndian.Uint32(pp[2:6]) != px_proto_oe {
  786. return nil, EINVAL
  787. }
  788. sa := &SockaddrPPPoE{
  789. SID: binary.BigEndian.Uint16(pp[6:8]),
  790. Remote: net.HardwareAddr(pp[8:14]),
  791. }
  792. for i := 14; i < 14+IFNAMSIZ; i++ {
  793. if pp[i] == 0 {
  794. sa.Dev = string(pp[14:i])
  795. break
  796. }
  797. }
  798. return sa, nil
  799. }
  800. return nil, EAFNOSUPPORT
  801. }
  802. func Accept(fd int) (nfd int, sa Sockaddr, err error) {
  803. var rsa RawSockaddrAny
  804. var len _Socklen = SizeofSockaddrAny
  805. nfd, err = accept(fd, &rsa, &len)
  806. if err != nil {
  807. return
  808. }
  809. sa, err = anyToSockaddr(fd, &rsa)
  810. if err != nil {
  811. Close(nfd)
  812. nfd = 0
  813. }
  814. return
  815. }
  816. func Accept4(fd int, flags int) (nfd int, sa Sockaddr, err error) {
  817. var rsa RawSockaddrAny
  818. var len _Socklen = SizeofSockaddrAny
  819. nfd, err = accept4(fd, &rsa, &len, flags)
  820. if err != nil {
  821. return
  822. }
  823. if len > SizeofSockaddrAny {
  824. panic("RawSockaddrAny too small")
  825. }
  826. sa, err = anyToSockaddr(fd, &rsa)
  827. if err != nil {
  828. Close(nfd)
  829. nfd = 0
  830. }
  831. return
  832. }
  833. func Getsockname(fd int) (sa Sockaddr, err error) {
  834. var rsa RawSockaddrAny
  835. var len _Socklen = SizeofSockaddrAny
  836. if err = getsockname(fd, &rsa, &len); err != nil {
  837. return
  838. }
  839. return anyToSockaddr(fd, &rsa)
  840. }
  841. func GetsockoptIPMreqn(fd, level, opt int) (*IPMreqn, error) {
  842. var value IPMreqn
  843. vallen := _Socklen(SizeofIPMreqn)
  844. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  845. return &value, err
  846. }
  847. func GetsockoptUcred(fd, level, opt int) (*Ucred, error) {
  848. var value Ucred
  849. vallen := _Socklen(SizeofUcred)
  850. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  851. return &value, err
  852. }
  853. func GetsockoptTCPInfo(fd, level, opt int) (*TCPInfo, error) {
  854. var value TCPInfo
  855. vallen := _Socklen(SizeofTCPInfo)
  856. err := getsockopt(fd, level, opt, unsafe.Pointer(&value), &vallen)
  857. return &value, err
  858. }
  859. // GetsockoptString returns the string value of the socket option opt for the
  860. // socket associated with fd at the given socket level.
  861. func GetsockoptString(fd, level, opt int) (string, error) {
  862. buf := make([]byte, 256)
  863. vallen := _Socklen(len(buf))
  864. err := getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
  865. if err != nil {
  866. if err == ERANGE {
  867. buf = make([]byte, vallen)
  868. err = getsockopt(fd, level, opt, unsafe.Pointer(&buf[0]), &vallen)
  869. }
  870. if err != nil {
  871. return "", err
  872. }
  873. }
  874. return string(buf[:vallen-1]), nil
  875. }
  876. func SetsockoptIPMreqn(fd, level, opt int, mreq *IPMreqn) (err error) {
  877. return setsockopt(fd, level, opt, unsafe.Pointer(mreq), unsafe.Sizeof(*mreq))
  878. }
  879. // Keyctl Commands (http://man7.org/linux/man-pages/man2/keyctl.2.html)
  880. // KeyctlInt calls keyctl commands in which each argument is an int.
  881. // These commands are KEYCTL_REVOKE, KEYCTL_CHOWN, KEYCTL_CLEAR, KEYCTL_LINK,
  882. // KEYCTL_UNLINK, KEYCTL_NEGATE, KEYCTL_SET_REQKEY_KEYRING, KEYCTL_SET_TIMEOUT,
  883. // KEYCTL_ASSUME_AUTHORITY, KEYCTL_SESSION_TO_PARENT, KEYCTL_REJECT,
  884. // KEYCTL_INVALIDATE, and KEYCTL_GET_PERSISTENT.
  885. //sys KeyctlInt(cmd int, arg2 int, arg3 int, arg4 int, arg5 int) (ret int, err error) = SYS_KEYCTL
  886. // KeyctlBuffer calls keyctl commands in which the third and fourth
  887. // arguments are a buffer and its length, respectively.
  888. // These commands are KEYCTL_UPDATE, KEYCTL_READ, and KEYCTL_INSTANTIATE.
  889. //sys KeyctlBuffer(cmd int, arg2 int, buf []byte, arg5 int) (ret int, err error) = SYS_KEYCTL
  890. // KeyctlString calls keyctl commands which return a string.
  891. // These commands are KEYCTL_DESCRIBE and KEYCTL_GET_SECURITY.
  892. func KeyctlString(cmd int, id int) (string, error) {
  893. // We must loop as the string data may change in between the syscalls.
  894. // We could allocate a large buffer here to reduce the chance that the
  895. // syscall needs to be called twice; however, this is unnecessary as
  896. // the performance loss is negligible.
  897. var buffer []byte
  898. for {
  899. // Try to fill the buffer with data
  900. length, err := KeyctlBuffer(cmd, id, buffer, 0)
  901. if err != nil {
  902. return "", err
  903. }
  904. // Check if the data was written
  905. if length <= len(buffer) {
  906. // Exclude the null terminator
  907. return string(buffer[:length-1]), nil
  908. }
  909. // Make a bigger buffer if needed
  910. buffer = make([]byte, length)
  911. }
  912. }
  913. // Keyctl commands with special signatures.
  914. // KeyctlGetKeyringID implements the KEYCTL_GET_KEYRING_ID command.
  915. // See the full documentation at:
  916. // http://man7.org/linux/man-pages/man3/keyctl_get_keyring_ID.3.html
  917. func KeyctlGetKeyringID(id int, create bool) (ringid int, err error) {
  918. createInt := 0
  919. if create {
  920. createInt = 1
  921. }
  922. return KeyctlInt(KEYCTL_GET_KEYRING_ID, id, createInt, 0, 0)
  923. }
  924. // KeyctlSetperm implements the KEYCTL_SETPERM command. The perm value is the
  925. // key handle permission mask as described in the "keyctl setperm" section of
  926. // http://man7.org/linux/man-pages/man1/keyctl.1.html.
  927. // See the full documentation at:
  928. // http://man7.org/linux/man-pages/man3/keyctl_setperm.3.html
  929. func KeyctlSetperm(id int, perm uint32) error {
  930. _, err := KeyctlInt(KEYCTL_SETPERM, id, int(perm), 0, 0)
  931. return err
  932. }
  933. //sys keyctlJoin(cmd int, arg2 string) (ret int, err error) = SYS_KEYCTL
  934. // KeyctlJoinSessionKeyring implements the KEYCTL_JOIN_SESSION_KEYRING command.
  935. // See the full documentation at:
  936. // http://man7.org/linux/man-pages/man3/keyctl_join_session_keyring.3.html
  937. func KeyctlJoinSessionKeyring(name string) (ringid int, err error) {
  938. return keyctlJoin(KEYCTL_JOIN_SESSION_KEYRING, name)
  939. }
  940. //sys keyctlSearch(cmd int, arg2 int, arg3 string, arg4 string, arg5 int) (ret int, err error) = SYS_KEYCTL
  941. // KeyctlSearch implements the KEYCTL_SEARCH command.
  942. // See the full documentation at:
  943. // http://man7.org/linux/man-pages/man3/keyctl_search.3.html
  944. func KeyctlSearch(ringid int, keyType, description string, destRingid int) (id int, err error) {
  945. return keyctlSearch(KEYCTL_SEARCH, ringid, keyType, description, destRingid)
  946. }
  947. //sys keyctlIOV(cmd int, arg2 int, payload []Iovec, arg5 int) (err error) = SYS_KEYCTL
  948. // KeyctlInstantiateIOV implements the KEYCTL_INSTANTIATE_IOV command. This
  949. // command is similar to KEYCTL_INSTANTIATE, except that the payload is a slice
  950. // of Iovec (each of which represents a buffer) instead of a single buffer.
  951. // See the full documentation at:
  952. // http://man7.org/linux/man-pages/man3/keyctl_instantiate_iov.3.html
  953. func KeyctlInstantiateIOV(id int, payload []Iovec, ringid int) error {
  954. return keyctlIOV(KEYCTL_INSTANTIATE_IOV, id, payload, ringid)
  955. }
  956. //sys keyctlDH(cmd int, arg2 *KeyctlDHParams, buf []byte) (ret int, err error) = SYS_KEYCTL
  957. // KeyctlDHCompute implements the KEYCTL_DH_COMPUTE command. This command
  958. // computes a Diffie-Hellman shared secret based on the provide params. The
  959. // secret is written to the provided buffer and the returned size is the number
  960. // of bytes written (returning an error if there is insufficient space in the
  961. // buffer). If a nil buffer is passed in, this function returns the minimum
  962. // buffer length needed to store the appropriate data. Note that this differs
  963. // from KEYCTL_READ's behavior which always returns the requested payload size.
  964. // See the full documentation at:
  965. // http://man7.org/linux/man-pages/man3/keyctl_dh_compute.3.html
  966. func KeyctlDHCompute(params *KeyctlDHParams, buffer []byte) (size int, err error) {
  967. return keyctlDH(KEYCTL_DH_COMPUTE, params, buffer)
  968. }
  969. func Recvmsg(fd int, p, oob []byte, flags int) (n, oobn int, recvflags int, from Sockaddr, err error) {
  970. var msg Msghdr
  971. var rsa RawSockaddrAny
  972. msg.Name = (*byte)(unsafe.Pointer(&rsa))
  973. msg.Namelen = uint32(SizeofSockaddrAny)
  974. var iov Iovec
  975. if len(p) > 0 {
  976. iov.Base = &p[0]
  977. iov.SetLen(len(p))
  978. }
  979. var dummy byte
  980. if len(oob) > 0 {
  981. if len(p) == 0 {
  982. var sockType int
  983. sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
  984. if err != nil {
  985. return
  986. }
  987. // receive at least one normal byte
  988. if sockType != SOCK_DGRAM {
  989. iov.Base = &dummy
  990. iov.SetLen(1)
  991. }
  992. }
  993. msg.Control = &oob[0]
  994. msg.SetControllen(len(oob))
  995. }
  996. msg.Iov = &iov
  997. msg.Iovlen = 1
  998. if n, err = recvmsg(fd, &msg, flags); err != nil {
  999. return
  1000. }
  1001. oobn = int(msg.Controllen)
  1002. recvflags = int(msg.Flags)
  1003. // source address is only specified if the socket is unconnected
  1004. if rsa.Addr.Family != AF_UNSPEC {
  1005. from, err = anyToSockaddr(fd, &rsa)
  1006. }
  1007. return
  1008. }
  1009. func Sendmsg(fd int, p, oob []byte, to Sockaddr, flags int) (err error) {
  1010. _, err = SendmsgN(fd, p, oob, to, flags)
  1011. return
  1012. }
  1013. func SendmsgN(fd int, p, oob []byte, to Sockaddr, flags int) (n int, err error) {
  1014. var ptr unsafe.Pointer
  1015. var salen _Socklen
  1016. if to != nil {
  1017. var err error
  1018. ptr, salen, err = to.sockaddr()
  1019. if err != nil {
  1020. return 0, err
  1021. }
  1022. }
  1023. var msg Msghdr
  1024. msg.Name = (*byte)(ptr)
  1025. msg.Namelen = uint32(salen)
  1026. var iov Iovec
  1027. if len(p) > 0 {
  1028. iov.Base = &p[0]
  1029. iov.SetLen(len(p))
  1030. }
  1031. var dummy byte
  1032. if len(oob) > 0 {
  1033. if len(p) == 0 {
  1034. var sockType int
  1035. sockType, err = GetsockoptInt(fd, SOL_SOCKET, SO_TYPE)
  1036. if err != nil {
  1037. return 0, err
  1038. }
  1039. // send at least one normal byte
  1040. if sockType != SOCK_DGRAM {
  1041. iov.Base = &dummy
  1042. iov.SetLen(1)
  1043. }
  1044. }
  1045. msg.Control = &oob[0]
  1046. msg.SetControllen(len(oob))
  1047. }
  1048. msg.Iov = &iov
  1049. msg.Iovlen = 1
  1050. if n, err = sendmsg(fd, &msg, flags); err != nil {
  1051. return 0, err
  1052. }
  1053. if len(oob) > 0 && len(p) == 0 {
  1054. n = 0
  1055. }
  1056. return n, nil
  1057. }
  1058. // BindToDevice binds the socket associated with fd to device.
  1059. func BindToDevice(fd int, device string) (err error) {
  1060. return SetsockoptString(fd, SOL_SOCKET, SO_BINDTODEVICE, device)
  1061. }
  1062. //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error)
  1063. func ptracePeek(req int, pid int, addr uintptr, out []byte) (count int, err error) {
  1064. // The peek requests are machine-size oriented, so we wrap it
  1065. // to retrieve arbitrary-length data.
  1066. // The ptrace syscall differs from glibc's ptrace.
  1067. // Peeks returns the word in *data, not as the return value.
  1068. var buf [SizeofPtr]byte
  1069. // Leading edge. PEEKTEXT/PEEKDATA don't require aligned
  1070. // access (PEEKUSER warns that it might), but if we don't
  1071. // align our reads, we might straddle an unmapped page
  1072. // boundary and not get the bytes leading up to the page
  1073. // boundary.
  1074. n := 0
  1075. if addr%SizeofPtr != 0 {
  1076. err = ptrace(req, pid, addr-addr%SizeofPtr, uintptr(unsafe.Pointer(&buf[0])))
  1077. if err != nil {
  1078. return 0, err
  1079. }
  1080. n += copy(out, buf[addr%SizeofPtr:])
  1081. out = out[n:]
  1082. }
  1083. // Remainder.
  1084. for len(out) > 0 {
  1085. // We use an internal buffer to guarantee alignment.
  1086. // It's not documented if this is necessary, but we're paranoid.
  1087. err = ptrace(req, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0])))
  1088. if err != nil {
  1089. return n, err
  1090. }
  1091. copied := copy(out, buf[0:])
  1092. n += copied
  1093. out = out[copied:]
  1094. }
  1095. return n, nil
  1096. }
  1097. func PtracePeekText(pid int, addr uintptr, out []byte) (count int, err error) {
  1098. return ptracePeek(PTRACE_PEEKTEXT, pid, addr, out)
  1099. }
  1100. func PtracePeekData(pid int, addr uintptr, out []byte) (count int, err error) {
  1101. return ptracePeek(PTRACE_PEEKDATA, pid, addr, out)
  1102. }
  1103. func PtracePeekUser(pid int, addr uintptr, out []byte) (count int, err error) {
  1104. return ptracePeek(PTRACE_PEEKUSR, pid, addr, out)
  1105. }
  1106. func ptracePoke(pokeReq int, peekReq int, pid int, addr uintptr, data []byte) (count int, err error) {
  1107. // As for ptracePeek, we need to align our accesses to deal
  1108. // with the possibility of straddling an invalid page.
  1109. // Leading edge.
  1110. n := 0
  1111. if addr%SizeofPtr != 0 {
  1112. var buf [SizeofPtr]byte
  1113. err = ptrace(peekReq, pid, addr-addr%SizeofPtr, uintptr(unsafe.Pointer(&buf[0])))
  1114. if err != nil {
  1115. return 0, err
  1116. }
  1117. n += copy(buf[addr%SizeofPtr:], data)
  1118. word := *((*uintptr)(unsafe.Pointer(&buf[0])))
  1119. err = ptrace(pokeReq, pid, addr-addr%SizeofPtr, word)
  1120. if err != nil {
  1121. return 0, err
  1122. }
  1123. data = data[n:]
  1124. }
  1125. // Interior.
  1126. for len(data) > SizeofPtr {
  1127. word := *((*uintptr)(unsafe.Pointer(&data[0])))
  1128. err = ptrace(pokeReq, pid, addr+uintptr(n), word)
  1129. if err != nil {
  1130. return n, err
  1131. }
  1132. n += SizeofPtr
  1133. data = data[SizeofPtr:]
  1134. }
  1135. // Trailing edge.
  1136. if len(data) > 0 {
  1137. var buf [SizeofPtr]byte
  1138. err = ptrace(peekReq, pid, addr+uintptr(n), uintptr(unsafe.Pointer(&buf[0])))
  1139. if err != nil {
  1140. return n, err
  1141. }
  1142. copy(buf[0:], data)
  1143. word := *((*uintptr)(unsafe.Pointer(&buf[0])))
  1144. err = ptrace(pokeReq, pid, addr+uintptr(n), word)
  1145. if err != nil {
  1146. return n, err
  1147. }
  1148. n += len(data)
  1149. }
  1150. return n, nil
  1151. }
  1152. func PtracePokeText(pid int, addr uintptr, data []byte) (count int, err error) {
  1153. return ptracePoke(PTRACE_POKETEXT, PTRACE_PEEKTEXT, pid, addr, data)
  1154. }
  1155. func PtracePokeData(pid int, addr uintptr, data []byte) (count int, err error) {
  1156. return ptracePoke(PTRACE_POKEDATA, PTRACE_PEEKDATA, pid, addr, data)
  1157. }
  1158. func PtracePokeUser(pid int, addr uintptr, data []byte) (count int, err error) {
  1159. return ptracePoke(PTRACE_POKEUSR, PTRACE_PEEKUSR, pid, addr, data)
  1160. }
  1161. func PtraceGetRegs(pid int, regsout *PtraceRegs) (err error) {
  1162. return ptrace(PTRACE_GETREGS, pid, 0, uintptr(unsafe.Pointer(regsout)))
  1163. }
  1164. func PtraceSetRegs(pid int, regs *PtraceRegs) (err error) {
  1165. return ptrace(PTRACE_SETREGS, pid, 0, uintptr(unsafe.Pointer(regs)))
  1166. }
  1167. func PtraceSetOptions(pid int, options int) (err error) {
  1168. return ptrace(PTRACE_SETOPTIONS, pid, 0, uintptr(options))
  1169. }
  1170. func PtraceGetEventMsg(pid int) (msg uint, err error) {
  1171. var data _C_long
  1172. err = ptrace(PTRACE_GETEVENTMSG, pid, 0, uintptr(unsafe.Pointer(&data)))
  1173. msg = uint(data)
  1174. return
  1175. }
  1176. func PtraceCont(pid int, signal int) (err error) {
  1177. return ptrace(PTRACE_CONT, pid, 0, uintptr(signal))
  1178. }
  1179. func PtraceSyscall(pid int, signal int) (err error) {
  1180. return ptrace(PTRACE_SYSCALL, pid, 0, uintptr(signal))
  1181. }
  1182. func PtraceSingleStep(pid int) (err error) { return ptrace(PTRACE_SINGLESTEP, pid, 0, 0) }
  1183. func PtraceAttach(pid int) (err error) { return ptrace(PTRACE_ATTACH, pid, 0, 0) }
  1184. func PtraceDetach(pid int) (err error) { return ptrace(PTRACE_DETACH, pid, 0, 0) }
  1185. //sys reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error)
  1186. func Reboot(cmd int) (err error) {
  1187. return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "")
  1188. }
  1189. func ReadDirent(fd int, buf []byte) (n int, err error) {
  1190. return Getdents(fd, buf)
  1191. }
  1192. //sys mount(source string, target string, fstype string, flags uintptr, data *byte) (err error)
  1193. func Mount(source string, target string, fstype string, flags uintptr, data string) (err error) {
  1194. // Certain file systems get rather angry and EINVAL if you give
  1195. // them an empty string of data, rather than NULL.
  1196. if data == "" {
  1197. return mount(source, target, fstype, flags, nil)
  1198. }
  1199. datap, err := BytePtrFromString(data)
  1200. if err != nil {
  1201. return err
  1202. }
  1203. return mount(source, target, fstype, flags, datap)
  1204. }
  1205. func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
  1206. if raceenabled {
  1207. raceReleaseMerge(unsafe.Pointer(&ioSync))
  1208. }
  1209. return sendfile(outfd, infd, offset, count)
  1210. }
  1211. // Sendto
  1212. // Recvfrom
  1213. // Socketpair
  1214. /*
  1215. * Direct access
  1216. */
  1217. //sys Acct(path string) (err error)
  1218. //sys AddKey(keyType string, description string, payload []byte, ringid int) (id int, err error)
  1219. //sys Adjtimex(buf *Timex) (state int, err error)
  1220. //sys Chdir(path string) (err error)
  1221. //sys Chroot(path string) (err error)
  1222. //sys ClockGetres(clockid int32, res *Timespec) (err error)
  1223. //sys ClockGettime(clockid int32, time *Timespec) (err error)
  1224. //sys ClockNanosleep(clockid int32, flags int, request *Timespec, remain *Timespec) (err error)
  1225. //sys Close(fd int) (err error)
  1226. //sys CopyFileRange(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error)
  1227. //sys DeleteModule(name string, flags int) (err error)
  1228. //sys Dup(oldfd int) (fd int, err error)
  1229. //sys Dup3(oldfd int, newfd int, flags int) (err error)
  1230. //sysnb EpollCreate1(flag int) (fd int, err error)
  1231. //sysnb EpollCtl(epfd int, op int, fd int, event *EpollEvent) (err error)
  1232. //sys Eventfd(initval uint, flags int) (fd int, err error) = SYS_EVENTFD2
  1233. //sys Exit(code int) = SYS_EXIT_GROUP
  1234. //sys Fallocate(fd int, mode uint32, off int64, len int64) (err error)
  1235. //sys Fchdir(fd int) (err error)
  1236. //sys Fchmod(fd int, mode uint32) (err error)
  1237. //sys Fchownat(dirfd int, path string, uid int, gid int, flags int) (err error)
  1238. //sys fcntl(fd int, cmd int, arg int) (val int, err error)
  1239. //sys Fdatasync(fd int) (err error)
  1240. //sys Fgetxattr(fd int, attr string, dest []byte) (sz int, err error)
  1241. //sys FinitModule(fd int, params string, flags int) (err error)
  1242. //sys Flistxattr(fd int, dest []byte) (sz int, err error)
  1243. //sys Flock(fd int, how int) (err error)
  1244. //sys Fremovexattr(fd int, attr string) (err error)
  1245. //sys Fsetxattr(fd int, attr string, dest []byte, flags int) (err error)
  1246. //sys Fsync(fd int) (err error)
  1247. //sys Getdents(fd int, buf []byte) (n int, err error) = SYS_GETDENTS64
  1248. //sysnb Getpgid(pid int) (pgid int, err error)
  1249. func Getpgrp() (pid int) {
  1250. pid, _ = Getpgid(0)
  1251. return
  1252. }
  1253. //sysnb Getpid() (pid int)
  1254. //sysnb Getppid() (ppid int)
  1255. //sys Getpriority(which int, who int) (prio int, err error)
  1256. //sys Getrandom(buf []byte, flags int) (n int, err error)
  1257. //sysnb Getrusage(who int, rusage *Rusage) (err error)
  1258. //sysnb Getsid(pid int) (sid int, err error)
  1259. //sysnb Gettid() (tid int)
  1260. //sys Getxattr(path string, attr string, dest []byte) (sz int, err error)
  1261. //sys InitModule(moduleImage []byte, params string) (err error)
  1262. //sys InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err error)
  1263. //sysnb InotifyInit1(flags int) (fd int, err error)
  1264. //sysnb InotifyRmWatch(fd int, watchdesc uint32) (success int, err error)
  1265. //sysnb Kill(pid int, sig syscall.Signal) (err error)
  1266. //sys Klogctl(typ int, buf []byte) (n int, err error) = SYS_SYSLOG
  1267. //sys Lgetxattr(path string, attr string, dest []byte) (sz int, err error)
  1268. //sys Listxattr(path string, dest []byte) (sz int, err error)
  1269. //sys Llistxattr(path string, dest []byte) (sz int, err error)
  1270. //sys Lremovexattr(path string, attr string) (err error)
  1271. //sys Lsetxattr(path string, attr string, data []byte, flags int) (err error)
  1272. //sys MemfdCreate(name string, flags int) (fd int, err error)
  1273. //sys Mkdirat(dirfd int, path string, mode uint32) (err error)
  1274. //sys Mknodat(dirfd int, path string, mode uint32, dev int) (err error)
  1275. //sys Nanosleep(time *Timespec, leftover *Timespec) (err error)
  1276. //sys PerfEventOpen(attr *PerfEventAttr, pid int, cpu int, groupFd int, flags int) (fd int, err error)
  1277. //sys PivotRoot(newroot string, putold string) (err error) = SYS_PIVOT_ROOT
  1278. //sysnb prlimit(pid int, resource int, newlimit *Rlimit, old *Rlimit) (err error) = SYS_PRLIMIT64
  1279. //sys Prctl(option int, arg2 uintptr, arg3 uintptr, arg4 uintptr, arg5 uintptr) (err error)
  1280. //sys Pselect(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timespec, sigmask *Sigset_t) (n int, err error) = SYS_PSELECT6
  1281. //sys read(fd int, p []byte) (n int, err error)
  1282. //sys Removexattr(path string, attr string) (err error)
  1283. //sys Renameat2(olddirfd int, oldpath string, newdirfd int, newpath string, flags uint) (err error)
  1284. //sys RequestKey(keyType string, description string, callback string, destRingid int) (id int, err error)
  1285. //sys Setdomainname(p []byte) (err error)
  1286. //sys Sethostname(p []byte) (err error)
  1287. //sysnb Setpgid(pid int, pgid int) (err error)
  1288. //sysnb Setsid() (pid int, err error)
  1289. //sysnb Settimeofday(tv *Timeval) (err error)
  1290. //sys Setns(fd int, nstype int) (err error)
  1291. // issue 1435.
  1292. // On linux Setuid and Setgid only affects the current thread, not the process.
  1293. // This does not match what most callers expect so we must return an error
  1294. // here rather than letting the caller think that the call succeeded.
  1295. func Setuid(uid int) (err error) {
  1296. return EOPNOTSUPP
  1297. }
  1298. func Setgid(uid int) (err error) {
  1299. return EOPNOTSUPP
  1300. }
  1301. //sys Setpriority(which int, who int, prio int) (err error)
  1302. //sys Setxattr(path string, attr string, data []byte, flags int) (err error)
  1303. //sys Signalfd(fd int, mask *Sigset_t, flags int) = SYS_SIGNALFD4
  1304. //sys Statx(dirfd int, path string, flags int, mask int, stat *Statx_t) (err error)
  1305. //sys Sync()
  1306. //sys Syncfs(fd int) (err error)
  1307. //sysnb Sysinfo(info *Sysinfo_t) (err error)
  1308. //sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error)
  1309. //sysnb Tgkill(tgid int, tid int, sig syscall.Signal) (err error)
  1310. //sysnb Times(tms *Tms) (ticks uintptr, err error)
  1311. //sysnb Umask(mask int) (oldmask int)
  1312. //sysnb Uname(buf *Utsname) (err error)
  1313. //sys Unmount(target string, flags int) (err error) = SYS_UMOUNT2
  1314. //sys Unshare(flags int) (err error)
  1315. //sys write(fd int, p []byte) (n int, err error)
  1316. //sys exitThread(code int) (err error) = SYS_EXIT
  1317. //sys readlen(fd int, p *byte, np int) (n int, err error) = SYS_READ
  1318. //sys writelen(fd int, p *byte, np int) (n int, err error) = SYS_WRITE
  1319. // mmap varies by architecture; see syscall_linux_*.go.
  1320. //sys munmap(addr uintptr, length uintptr) (err error)
  1321. var mapper = &mmapper{
  1322. active: make(map[*byte][]byte),
  1323. mmap: mmap,
  1324. munmap: munmap,
  1325. }
  1326. func Mmap(fd int, offset int64, length int, prot int, flags int) (data []byte, err error) {
  1327. return mapper.Mmap(fd, offset, length, prot, flags)
  1328. }
  1329. func Munmap(b []byte) (err error) {
  1330. return mapper.Munmap(b)
  1331. }
  1332. //sys Madvise(b []byte, advice int) (err error)
  1333. //sys Mprotect(b []byte, prot int) (err error)
  1334. //sys Mlock(b []byte) (err error)
  1335. //sys Mlockall(flags int) (err error)
  1336. //sys Msync(b []byte, flags int) (err error)
  1337. //sys Munlock(b []byte) (err error)
  1338. //sys Munlockall() (err error)
  1339. // Vmsplice splices user pages from a slice of Iovecs into a pipe specified by fd,
  1340. // using the specified flags.
  1341. func Vmsplice(fd int, iovs []Iovec, flags int) (int, error) {
  1342. var p unsafe.Pointer
  1343. if len(iovs) > 0 {
  1344. p = unsafe.Pointer(&iovs[0])
  1345. }
  1346. n, _, errno := Syscall6(SYS_VMSPLICE, uintptr(fd), uintptr(p), uintptr(len(iovs)), uintptr(flags), 0, 0)
  1347. if errno != 0 {
  1348. return 0, syscall.Errno(errno)
  1349. }
  1350. return int(n), nil
  1351. }
  1352. //sys faccessat(dirfd int, path string, mode uint32) (err error)
  1353. func Faccessat(dirfd int, path string, mode uint32, flags int) (err error) {
  1354. if flags & ^(AT_SYMLINK_NOFOLLOW|AT_EACCESS) != 0 {
  1355. return EINVAL
  1356. }
  1357. // The Linux kernel faccessat system call does not take any flags.
  1358. // The glibc faccessat implements the flags itself; see
  1359. // https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/faccessat.c;hb=HEAD
  1360. // Because people naturally expect syscall.Faccessat to act
  1361. // like C faccessat, we do the same.
  1362. if flags == 0 {
  1363. return faccessat(dirfd, path, mode)
  1364. }
  1365. var st Stat_t
  1366. if err := Fstatat(dirfd, path, &st, flags&AT_SYMLINK_NOFOLLOW); err != nil {
  1367. return err
  1368. }
  1369. mode &= 7
  1370. if mode == 0 {
  1371. return nil
  1372. }
  1373. var uid int
  1374. if flags&AT_EACCESS != 0 {
  1375. uid = Geteuid()
  1376. } else {
  1377. uid = Getuid()
  1378. }
  1379. if uid == 0 {
  1380. if mode&1 == 0 {
  1381. // Root can read and write any file.
  1382. return nil
  1383. }
  1384. if st.Mode&0111 != 0 {
  1385. // Root can execute any file that anybody can execute.
  1386. return nil
  1387. }
  1388. return EACCES
  1389. }
  1390. var fmode uint32
  1391. if uint32(uid) == st.Uid {
  1392. fmode = (st.Mode >> 6) & 7
  1393. } else {
  1394. var gid int
  1395. if flags&AT_EACCESS != 0 {
  1396. gid = Getegid()
  1397. } else {
  1398. gid = Getgid()
  1399. }
  1400. if uint32(gid) == st.Gid {
  1401. fmode = (st.Mode >> 3) & 7
  1402. } else {
  1403. fmode = st.Mode & 7
  1404. }
  1405. }
  1406. if fmode&mode == mode {
  1407. return nil
  1408. }
  1409. return EACCES
  1410. }
  1411. /*
  1412. * Unimplemented
  1413. */
  1414. // AfsSyscall
  1415. // Alarm
  1416. // ArchPrctl
  1417. // Brk
  1418. // Capget
  1419. // Capset
  1420. // ClockNanosleep
  1421. // ClockSettime
  1422. // Clone
  1423. // EpollCtlOld
  1424. // EpollPwait
  1425. // EpollWaitOld
  1426. // Execve
  1427. // Fork
  1428. // Futex
  1429. // GetKernelSyms
  1430. // GetMempolicy
  1431. // GetRobustList
  1432. // GetThreadArea
  1433. // Getitimer
  1434. // Getpmsg
  1435. // IoCancel
  1436. // IoDestroy
  1437. // IoGetevents
  1438. // IoSetup
  1439. // IoSubmit
  1440. // IoprioGet
  1441. // IoprioSet
  1442. // KexecLoad
  1443. // LookupDcookie
  1444. // Mbind
  1445. // MigratePages
  1446. // Mincore
  1447. // ModifyLdt
  1448. // Mount
  1449. // MovePages
  1450. // MqGetsetattr
  1451. // MqNotify
  1452. // MqOpen
  1453. // MqTimedreceive
  1454. // MqTimedsend
  1455. // MqUnlink
  1456. // Mremap
  1457. // Msgctl
  1458. // Msgget
  1459. // Msgrcv
  1460. // Msgsnd
  1461. // Nfsservctl
  1462. // Personality
  1463. // Pselect6
  1464. // Ptrace
  1465. // Putpmsg
  1466. // Quotactl
  1467. // Readahead
  1468. // Readv
  1469. // RemapFilePages
  1470. // RestartSyscall
  1471. // RtSigaction
  1472. // RtSigpending
  1473. // RtSigprocmask
  1474. // RtSigqueueinfo
  1475. // RtSigreturn
  1476. // RtSigsuspend
  1477. // RtSigtimedwait
  1478. // SchedGetPriorityMax
  1479. // SchedGetPriorityMin
  1480. // SchedGetparam
  1481. // SchedGetscheduler
  1482. // SchedRrGetInterval
  1483. // SchedSetparam
  1484. // SchedYield
  1485. // Security
  1486. // Semctl
  1487. // Semget
  1488. // Semop
  1489. // Semtimedop
  1490. // SetMempolicy
  1491. // SetRobustList
  1492. // SetThreadArea
  1493. // SetTidAddress
  1494. // Shmat
  1495. // Shmctl
  1496. // Shmdt
  1497. // Shmget
  1498. // Sigaltstack
  1499. // Swapoff
  1500. // Swapon
  1501. // Sysfs
  1502. // TimerCreate
  1503. // TimerDelete
  1504. // TimerGetoverrun
  1505. // TimerGettime
  1506. // TimerSettime
  1507. // Timerfd
  1508. // Tkill (obsolete)
  1509. // Tuxcall
  1510. // Umount2
  1511. // Uselib
  1512. // Utimensat
  1513. // Vfork
  1514. // Vhangup
  1515. // Vserver
  1516. // Waitid
  1517. // _Sysctl