libc_linux_mips64le.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. // Copyright 2020 The Libc 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. package libc // import "modernc.org/libc"
  5. import (
  6. "os"
  7. "strings"
  8. gotime "time"
  9. "unicode"
  10. "unsafe"
  11. "golang.org/x/sys/unix"
  12. "modernc.org/libc/errno"
  13. "modernc.org/libc/fcntl"
  14. "modernc.org/libc/signal"
  15. "modernc.org/libc/stdio"
  16. "modernc.org/libc/sys/types"
  17. "modernc.org/libc/time"
  18. "modernc.org/libc/wctype"
  19. )
  20. var (
  21. startTime = gotime.Now() // For clock(3)
  22. )
  23. // int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  24. func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
  25. if __ccgo_strace {
  26. trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
  27. }
  28. // musl/arch/x86_64/ksigaction.h
  29. //
  30. // struct k_sigaction {
  31. // void (*handler)(int);
  32. // unsigned long flags;
  33. // void (*restorer)(void);
  34. // unsigned mask[2];
  35. // };
  36. type k_sigaction struct {
  37. handler uintptr
  38. flags ulong
  39. restorer uintptr
  40. mask [2]uint32
  41. }
  42. var kact, koldact uintptr
  43. if act != 0 {
  44. sz := int(unsafe.Sizeof(k_sigaction{}))
  45. kact = t.Alloc(sz)
  46. defer t.Free(sz)
  47. *(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
  48. handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
  49. flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
  50. restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
  51. }
  52. Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
  53. }
  54. if oldact != 0 {
  55. panic(todo(""))
  56. }
  57. if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
  58. t.setErrno(err)
  59. return -1
  60. }
  61. if oldact != 0 {
  62. panic(todo(""))
  63. }
  64. return 0
  65. }
  66. // int fcntl(int fd, int cmd, ... /* arg */ );
  67. func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
  68. if __ccgo_strace {
  69. trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
  70. }
  71. var arg uintptr
  72. if args != 0 {
  73. arg = *(*uintptr)(unsafe.Pointer(args))
  74. }
  75. if cmd == fcntl.F_SETFL {
  76. arg |= unix.O_LARGEFILE
  77. }
  78. n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
  79. if err != 0 {
  80. // if dmesgs {
  81. // dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
  82. // }
  83. t.setErrno(err)
  84. return -1
  85. }
  86. // if dmesgs {
  87. // dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
  88. // }
  89. return int32(n)
  90. }
  91. // int lstat(const char *pathname, struct stat *statbuf);
  92. func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
  93. if __ccgo_strace {
  94. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  95. }
  96. if _, _, err := unix.Syscall(unix.SYS_LSTAT, pathname, statbuf, 0); err != 0 {
  97. // if dmesgs {
  98. // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  99. // }
  100. t.setErrno(err)
  101. return -1
  102. }
  103. // if dmesgs {
  104. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  105. // }
  106. return 0
  107. }
  108. // int stat(const char *pathname, struct stat *statbuf);
  109. func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
  110. if __ccgo_strace {
  111. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  112. }
  113. if _, _, err := unix.Syscall(unix.SYS_STAT, pathname, statbuf, 0); err != 0 {
  114. // if dmesgs {
  115. // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  116. // }
  117. t.setErrno(err)
  118. return -1
  119. }
  120. // if dmesgs {
  121. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  122. // }
  123. return 0
  124. }
  125. // int fstat(int fd, struct stat *statbuf);
  126. func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
  127. if __ccgo_strace {
  128. trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
  129. }
  130. if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
  131. // if dmesgs {
  132. // dmesg("%v: fd %d: %v", origin(1), fd, err)
  133. // }
  134. t.setErrno(err)
  135. return -1
  136. }
  137. // if dmesgs {
  138. // dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
  139. // }
  140. return 0
  141. }
  142. func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  143. if __ccgo_strace {
  144. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  145. }
  146. return Xmmap64(t, addr, length, prot, flags, fd, offset)
  147. }
  148. // void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
  149. func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  150. if __ccgo_strace {
  151. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  152. }
  153. data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
  154. if err != 0 {
  155. // if dmesgs {
  156. // dmesg("%v: %v", origin(1), err)
  157. // }
  158. t.setErrno(err)
  159. return ^uintptr(0) // (void*)-1
  160. }
  161. // if dmesgs {
  162. // dmesg("%v: %#x", origin(1), data)
  163. // }
  164. return data
  165. }
  166. // void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
  167. func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
  168. if __ccgo_strace {
  169. trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
  170. }
  171. var arg uintptr
  172. if args != 0 {
  173. arg = *(*uintptr)(unsafe.Pointer(args))
  174. }
  175. data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
  176. if err != 0 {
  177. // if dmesgs {
  178. // dmesg("%v: %v", origin(1), err)
  179. // }
  180. t.setErrno(err)
  181. return ^uintptr(0) // (void*)-1
  182. }
  183. // if dmesgs {
  184. // dmesg("%v: %#x", origin(1), data)
  185. // }
  186. return data
  187. }
  188. // int ftruncate(int fd, off_t length);
  189. func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
  190. if __ccgo_strace {
  191. trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
  192. }
  193. if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
  194. // if dmesgs {
  195. // dmesg("%v: fd %d: %v", origin(1), fd, err)
  196. // }
  197. t.setErrno(err)
  198. return -1
  199. }
  200. // if dmesgs {
  201. // dmesg("%v: %d %#x: ok", origin(1), fd, length)
  202. // }
  203. return 0
  204. }
  205. // off64_t lseek64(int fd, off64_t offset, int whence);
  206. func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
  207. if __ccgo_strace {
  208. trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
  209. }
  210. n, _, err := unix.Syscall(unix.SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence))
  211. if err != 0 {
  212. // if dmesgs {
  213. // dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
  214. // }
  215. t.setErrno(err)
  216. return -1
  217. }
  218. // if dmesgs {
  219. // dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
  220. // }
  221. return types.Off_t(n)
  222. }
  223. // int utime(const char *filename, const struct utimbuf *times);
  224. func Xutime(t *TLS, filename, times uintptr) int32 {
  225. if __ccgo_strace {
  226. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  227. }
  228. if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
  229. t.setErrno(err)
  230. return -1
  231. }
  232. return 0
  233. }
  234. // unsigned int alarm(unsigned int seconds);
  235. func Xalarm(t *TLS, seconds uint32) uint32 {
  236. if __ccgo_strace {
  237. trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
  238. }
  239. n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
  240. if err != 0 {
  241. panic(todo(""))
  242. }
  243. return uint32(n)
  244. }
  245. // time_t time(time_t *tloc);
  246. func Xtime(t *TLS, tloc uintptr) types.Time_t {
  247. if __ccgo_strace {
  248. trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
  249. }
  250. n := gotime.Now().UTC().Unix()
  251. if tloc != 0 {
  252. *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
  253. }
  254. return types.Time_t(n)
  255. }
  256. // int getrlimit(int resource, struct rlimit *rlim);
  257. func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  258. if __ccgo_strace {
  259. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  260. }
  261. if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  262. t.setErrno(err)
  263. return -1
  264. }
  265. return 0
  266. }
  267. // int mkdir(const char *path, mode_t mode);
  268. func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
  269. if __ccgo_strace {
  270. trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
  271. }
  272. if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
  273. t.setErrno(err)
  274. return -1
  275. }
  276. // if dmesgs {
  277. // dmesg("%v: %q: ok", origin(1), GoString(path))
  278. // }
  279. return 0
  280. }
  281. // int symlink(const char *target, const char *linkpath);
  282. func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
  283. if __ccgo_strace {
  284. trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
  285. }
  286. if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
  287. t.setErrno(err)
  288. return -1
  289. }
  290. // if dmesgs {
  291. // dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
  292. // }
  293. return 0
  294. }
  295. // int chmod(const char *pathname, mode_t mode)
  296. func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
  297. if __ccgo_strace {
  298. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  299. }
  300. if _, _, err := unix.Syscall(unix.SYS_CHMOD, pathname, uintptr(mode), 0); err != 0 {
  301. t.setErrno(err)
  302. return -1
  303. }
  304. // if dmesgs {
  305. // dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
  306. // }
  307. return 0
  308. }
  309. // int utimes(const char *filename, const struct timeval times[2]);
  310. func Xutimes(t *TLS, filename, times uintptr) int32 {
  311. if __ccgo_strace {
  312. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  313. }
  314. if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
  315. t.setErrno(err)
  316. return -1
  317. }
  318. // if dmesgs {
  319. // dmesg("%v: %q: ok", origin(1), GoString(filename))
  320. // }
  321. return 0
  322. }
  323. // int unlink(const char *pathname);
  324. func Xunlink(t *TLS, pathname uintptr) int32 {
  325. if __ccgo_strace {
  326. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  327. }
  328. if _, _, err := unix.Syscall(unix.SYS_UNLINK, pathname, 0, 0); err != 0 {
  329. t.setErrno(err)
  330. return -1
  331. }
  332. // if dmesgs {
  333. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  334. // }
  335. return 0
  336. }
  337. // int access(const char *pathname, int mode);
  338. func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
  339. if __ccgo_strace {
  340. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  341. }
  342. if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
  343. // if dmesgs {
  344. // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  345. // }
  346. t.setErrno(err)
  347. return -1
  348. }
  349. // if dmesgs {
  350. // dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
  351. // }
  352. return 0
  353. }
  354. // int rmdir(const char *pathname);
  355. func Xrmdir(t *TLS, pathname uintptr) int32 {
  356. if __ccgo_strace {
  357. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  358. }
  359. if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
  360. t.setErrno(err)
  361. return -1
  362. }
  363. // if dmesgs {
  364. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  365. // }
  366. return 0
  367. }
  368. // int rename(const char *oldpath, const char *newpath);
  369. func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
  370. if __ccgo_strace {
  371. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  372. }
  373. if _, _, err := unix.Syscall(unix.SYS_RENAME, oldpath, newpath, 0); err != 0 {
  374. t.setErrno(err)
  375. return -1
  376. }
  377. return 0
  378. }
  379. // int mknod(const char *pathname, mode_t mode, dev_t dev);
  380. func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
  381. if __ccgo_strace {
  382. trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
  383. }
  384. if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
  385. t.setErrno(err)
  386. return -1
  387. }
  388. return 0
  389. }
  390. // int chown(const char *pathname, uid_t owner, gid_t group);
  391. func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
  392. if __ccgo_strace {
  393. trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
  394. }
  395. if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
  396. t.setErrno(err)
  397. return -1
  398. }
  399. return 0
  400. }
  401. // int link(const char *oldpath, const char *newpath);
  402. func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
  403. if __ccgo_strace {
  404. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  405. }
  406. if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
  407. t.setErrno(err)
  408. return -1
  409. }
  410. return 0
  411. }
  412. // int pipe(int pipefd[2]);
  413. func Xpipe(t *TLS, pipefd uintptr) int32 {
  414. if __ccgo_strace {
  415. trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
  416. }
  417. if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
  418. t.setErrno(err)
  419. return -1
  420. }
  421. return 0
  422. }
  423. // int dup2(int oldfd, int newfd);
  424. func Xdup2(t *TLS, oldfd, newfd int32) int32 {
  425. if __ccgo_strace {
  426. trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
  427. }
  428. n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
  429. if err != 0 {
  430. t.setErrno(err)
  431. return -1
  432. }
  433. return int32(n)
  434. }
  435. // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
  436. func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
  437. if __ccgo_strace {
  438. trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
  439. }
  440. n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
  441. if err != 0 {
  442. t.setErrno(err)
  443. return -1
  444. }
  445. return types.Ssize_t(n)
  446. }
  447. // FILE *fopen64(const char *pathname, const char *mode);
  448. func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
  449. if __ccgo_strace {
  450. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  451. }
  452. m := strings.ReplaceAll(GoString(mode), "b", "")
  453. var flags int
  454. switch m {
  455. case "r":
  456. flags = os.O_RDONLY
  457. case "r+":
  458. flags = os.O_RDWR
  459. case "w":
  460. flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
  461. case "w+":
  462. flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
  463. case "a":
  464. flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
  465. case "a+":
  466. flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
  467. default:
  468. panic(m)
  469. }
  470. //TODO- flags |= fcntl.O_LARGEFILE
  471. fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
  472. if err != 0 {
  473. t.setErrno(err)
  474. return 0
  475. }
  476. if p := newFile(t, int32(fd)); p != 0 {
  477. return p
  478. }
  479. Xclose(t, int32(fd))
  480. t.setErrno(errno.ENOMEM)
  481. return 0
  482. }
  483. // int iswspace(wint_t wc);
  484. func Xiswspace(t *TLS, wc wctype.Wint_t) int32 {
  485. if __ccgo_strace {
  486. trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
  487. }
  488. return Bool32(unicode.IsSpace(rune(wc)))
  489. }
  490. // int iswalnum(wint_t wc);
  491. func Xiswalnum(t *TLS, wc wctype.Wint_t) int32 {
  492. if __ccgo_strace {
  493. trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
  494. }
  495. return Bool32(unicode.IsLetter(rune(wc)) || unicode.IsNumber(rune(wc)))
  496. }
  497. // int setrlimit(int resource, const struct rlimit *rlim);
  498. func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  499. if __ccgo_strace {
  500. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  501. }
  502. if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  503. t.setErrno(err)
  504. return -1
  505. }
  506. return 0
  507. }
  508. func AtomicLoadPInt8(addr uintptr) (val int8) {
  509. return int8(a_load_8(addr))
  510. }
  511. func AtomicLoadPInt16(addr uintptr) (val int16) {
  512. return int16(a_load_16(addr))
  513. }
  514. func AtomicLoadPUint8(addr uintptr) byte {
  515. return byte(a_load_8(addr))
  516. }
  517. func AtomicLoadPUint16(addr uintptr) uint16 {
  518. return uint16(a_load_16(addr))
  519. }
  520. func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
  521. return byte(a_load_8(ptr))
  522. }
  523. var _table1 = [384]int32{
  524. 129: int32(1),
  525. 130: int32(2),
  526. 131: int32(3),
  527. 132: int32(4),
  528. 133: int32(5),
  529. 134: int32(6),
  530. 135: int32(7),
  531. 136: int32(8),
  532. 137: int32(9),
  533. 138: int32(10),
  534. 139: int32(11),
  535. 140: int32(12),
  536. 141: int32(13),
  537. 142: int32(14),
  538. 143: int32(15),
  539. 144: int32(16),
  540. 145: int32(17),
  541. 146: int32(18),
  542. 147: int32(19),
  543. 148: int32(20),
  544. 149: int32(21),
  545. 150: int32(22),
  546. 151: int32(23),
  547. 152: int32(24),
  548. 153: int32(25),
  549. 154: int32(26),
  550. 155: int32(27),
  551. 156: int32(28),
  552. 157: int32(29),
  553. 158: int32(30),
  554. 159: int32(31),
  555. 160: int32(32),
  556. 161: int32(33),
  557. 162: int32(34),
  558. 163: int32(35),
  559. 164: int32(36),
  560. 165: int32(37),
  561. 166: int32(38),
  562. 167: int32(39),
  563. 168: int32(40),
  564. 169: int32(41),
  565. 170: int32(42),
  566. 171: int32(43),
  567. 172: int32(44),
  568. 173: int32(45),
  569. 174: int32(46),
  570. 175: int32(47),
  571. 176: int32(48),
  572. 177: int32(49),
  573. 178: int32(50),
  574. 179: int32(51),
  575. 180: int32(52),
  576. 181: int32(53),
  577. 182: int32(54),
  578. 183: int32(55),
  579. 184: int32(56),
  580. 185: int32(57),
  581. 186: int32(58),
  582. 187: int32(59),
  583. 188: int32(60),
  584. 189: int32(61),
  585. 190: int32(62),
  586. 191: int32(63),
  587. 192: int32(64),
  588. 193: int32('a'),
  589. 194: int32('b'),
  590. 195: int32('c'),
  591. 196: int32('d'),
  592. 197: int32('e'),
  593. 198: int32('f'),
  594. 199: int32('g'),
  595. 200: int32('h'),
  596. 201: int32('i'),
  597. 202: int32('j'),
  598. 203: int32('k'),
  599. 204: int32('l'),
  600. 205: int32('m'),
  601. 206: int32('n'),
  602. 207: int32('o'),
  603. 208: int32('p'),
  604. 209: int32('q'),
  605. 210: int32('r'),
  606. 211: int32('s'),
  607. 212: int32('t'),
  608. 213: int32('u'),
  609. 214: int32('v'),
  610. 215: int32('w'),
  611. 216: int32('x'),
  612. 217: int32('y'),
  613. 218: int32('z'),
  614. 219: int32(91),
  615. 220: int32(92),
  616. 221: int32(93),
  617. 222: int32(94),
  618. 223: int32(95),
  619. 224: int32(96),
  620. 225: int32('a'),
  621. 226: int32('b'),
  622. 227: int32('c'),
  623. 228: int32('d'),
  624. 229: int32('e'),
  625. 230: int32('f'),
  626. 231: int32('g'),
  627. 232: int32('h'),
  628. 233: int32('i'),
  629. 234: int32('j'),
  630. 235: int32('k'),
  631. 236: int32('l'),
  632. 237: int32('m'),
  633. 238: int32('n'),
  634. 239: int32('o'),
  635. 240: int32('p'),
  636. 241: int32('q'),
  637. 242: int32('r'),
  638. 243: int32('s'),
  639. 244: int32('t'),
  640. 245: int32('u'),
  641. 246: int32('v'),
  642. 247: int32('w'),
  643. 248: int32('x'),
  644. 249: int32('y'),
  645. 250: int32('z'),
  646. 251: int32(123),
  647. 252: int32(124),
  648. 253: int32(125),
  649. 254: int32(126),
  650. 255: int32(127),
  651. }
  652. var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
  653. func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
  654. if __ccgo_strace {
  655. trc("tls=%v, (%v:)", tls, origin(2))
  656. defer func() { trc("-> %v", r) }()
  657. }
  658. return uintptr(unsafe.Pointer(&_ptable1))
  659. }
  660. type Tin6_addr = struct {
  661. F__in6_union struct {
  662. F__s6_addr16 [0][8]uint16
  663. F__s6_addr32 [0][4]uint32
  664. F__s6_addr [16]uint8
  665. }
  666. }
  667. var Xin6addr_any = Tin6_addr{}
  668. func Xrewinddir(tls *TLS, f uintptr) {
  669. if __ccgo_strace {
  670. trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
  671. }
  672. Xfseek(tls, f, 0, stdio.SEEK_SET)
  673. }
  674. // clock_t clock(void);
  675. func Xclock(t *TLS) time.Clock_t {
  676. if __ccgo_strace {
  677. trc("t=%v, (%v:)", t, origin(2))
  678. }
  679. return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
  680. }