libc_linux_amd64.go 18 KB

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