mksysinfo.sh 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524
  1. #!/bin/sh
  2. # Copyright 2009 The Go Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style
  4. # license that can be found in the LICENSE file.
  5. # Create sysinfo.go from gen-sysinfo.go and errno.i.
  6. # This shell script creates the sysinfo.go file which holds types and
  7. # constants extracted from the system header files. This reads the
  8. # raw data from gen-sysinfo.go which is generated using the
  9. # -fdump-go-spec option.
  10. # This currently exposes some names that ideally should not be
  11. # exposed, as they match grep patterns. E.g., WCHAR_MIN gets exposed
  12. # because it starts with W, like the wait flags.
  13. OUT=tmp-sysinfo.go
  14. set -e
  15. echo 'package syscall' > ${OUT}
  16. echo 'import "unsafe"' >> ${OUT}
  17. echo 'type _ unsafe.Pointer' >> ${OUT}
  18. # Get all the consts and types, skipping ones which could not be
  19. # represented in Go and ones which we need to rewrite. We also skip
  20. # function declarations, as we don't need them here. All the symbols
  21. # will all have a leading underscore.
  22. grep -v '^// ' gen-sysinfo.go | \
  23. grep -v '^func' | \
  24. grep -v '^var' | \
  25. grep -v '^type _timeval ' | \
  26. grep -v '^type _timespec_t ' | \
  27. grep -v '^type _timespec ' | \
  28. grep -v '^type _timestruc_t ' | \
  29. grep -v '^type _epoll_' | \
  30. grep -v '^type _*locale[_ ]' | \
  31. grep -v '^type _in6_addr' | \
  32. grep -v 'sockaddr_in6' | \
  33. egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
  34. sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
  35. -e 's/\([^a-zA-Z0-9_]\)_timeval$/\1Timeval/g' \
  36. -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
  37. -e 's/\([^a-zA-Z0-9_]\)_timespec_t$/\1Timespec/g' \
  38. -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
  39. -e 's/\([^a-zA-Z0-9_]\)_timespec$/\1Timespec/g' \
  40. -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
  41. -e 's/\([^a-zA-Z0-9_]\)_timestruc_t$/\1Timestruc/g' \
  42. -e 's/\([^a-zA-Z0-9_]\)_in6_addr\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
  43. -e 's/\([^a-zA-Z0-9_]\)_in6_addr$/\1[16]byte/g' \
  44. -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
  45. -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t$/\1[16]byte/g' \
  46. >> ${OUT}
  47. # The errno constants. These get type Errno.
  48. egrep '#define E[A-Z0-9_]+ [0-9E]' errno.i | \
  49. sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(_\1)/' >> ${OUT}
  50. # Workaround for GNU/Hurd _EMIG_* errors having negative values
  51. egrep '#define E[A-Z0-9_]+ -[0-9]' errno.i | \
  52. sed -e 's/^#define \(E[A-Z0-9_]*\) .*$/const \1 = Errno(-_\1)/' >> ${OUT}
  53. # The O_xxx flags.
  54. egrep '^const _(O|F|FD)_' gen-sysinfo.go | \
  55. sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  56. if ! grep '^const O_ASYNC' ${OUT} >/dev/null 2>&1; then
  57. echo "const O_ASYNC = 0" >> ${OUT}
  58. fi
  59. if ! grep '^const O_CLOEXEC' ${OUT} >/dev/null 2>&1; then
  60. echo "const O_CLOEXEC = 0" >> ${OUT}
  61. fi
  62. # The os package requires F_DUPFD_CLOEXEC to be defined.
  63. if ! grep '^const F_DUPFD_CLOEXEC' ${OUT} >/dev/null 2>&1; then
  64. echo "const F_DUPFD_CLOEXEC = 0" >> ${OUT}
  65. fi
  66. # The internal/poll package requires F_GETPIPE_SZ to be defined.
  67. if ! grep '^const F_GETPIPE_SZ' ${OUT} >/dev/null 2>&1; then
  68. echo "const F_GETPIPE_SZ = 0" >> ${OUT}
  69. fi
  70. # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
  71. # which leads to a constant overflow when using O_CLOEXEC in some
  72. # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
  73. # more present in 7.2 (_FCLOEXEC is a 32 bit value).
  74. if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
  75. sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
  76. mv ${OUT}-2 ${OUT}
  77. fi
  78. # These flags can be lost on i386 GNU/Linux when using
  79. # -D_FILE_OFFSET_BITS=64, because we see "#define F_SETLK F_SETLK64"
  80. # before we see the definition of F_SETLK64.
  81. for flag in F_GETLK F_SETLK F_SETLKW; do
  82. if ! grep "^const ${flag} " ${OUT} >/dev/null 2>&1 \
  83. && grep "^const ${flag}64 " ${OUT} >/dev/null 2>&1; then
  84. echo "const ${flag} = ${flag}64" >> ${OUT}
  85. fi
  86. done
  87. # The Flock_t struct for fcntl.
  88. grep '^type _flock ' gen-sysinfo.go | \
  89. sed -e 's/type _flock/type Flock_t/' \
  90. -e 's/l_type/Type/' \
  91. -e 's/l_whence/Whence/' \
  92. -e 's/l_start/Start/' \
  93. -e 's/l_len/Len/' \
  94. -e 's/l_pid/Pid/' \
  95. >> ${OUT}
  96. # The signal numbers.
  97. grep '^const _SIG[^_]' gen-sysinfo.go | \
  98. grep -v '^const _SIGEV_' | \
  99. sed -e 's/^\(const \)_\(SIG[^= ]*\)\(.*\)$/\1\2 = Signal(_\2)/' >> ${OUT}
  100. if ! grep '^const SIGPOLL ' ${OUT} >/dev/null 2>&1; then
  101. if grep '^const SIGIO ' ${OUT} > /dev/null 2>&1; then
  102. echo "const SIGPOLL = SIGIO" >> ${OUT}
  103. fi
  104. fi
  105. if ! grep '^const SIGCLD ' ${OUT} >/dev/null 2>&1; then
  106. if grep '^const SIGCHLD ' ${OUT} >/dev/null 2>&1; then
  107. echo "const SIGCLD = SIGCHLD" >> ${OUT}
  108. fi
  109. fi
  110. # The syscall numbers. We force the names to upper case.
  111. grep '^const _SYS_' gen-sysinfo.go | \
  112. sed -e 's/const _\(SYS_[^= ]*\).*$/\1/' | \
  113. while read sys; do
  114. sup=`echo $sys | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  115. echo "const $sup = _$sys" >> ${OUT}
  116. done
  117. # Special treatment of SYS_IOCTL for GNU/Hurd.
  118. if ! grep '^const SYS_IOCTL' ${OUT} > /dev/null 2>&1; then
  119. echo "const SYS_IOCTL = 0" >> ${OUT}
  120. fi
  121. # The GNU/Linux support wants to use SYS_GETDENTS64 if available.
  122. if ! grep '^const SYS_GETDENTS ' ${OUT} >/dev/null 2>&1; then
  123. echo "const SYS_GETDENTS = 0" >> ${OUT}
  124. fi
  125. if ! grep '^const SYS_GETDENTS64 ' ${OUT} >/dev/null 2>&1; then
  126. echo "const SYS_GETDENTS64 = 0" >> ${OUT}
  127. fi
  128. # The syscall package wants the geteuid system call number. It isn't
  129. # defined on Alpha, which only provides the getresuid system call.
  130. if ! grep '^const SYS_GETEUID ' ${OUT} >/dev/null 2>&1; then
  131. echo "const SYS_GETEUID = 0" >> ${OUT}
  132. fi
  133. # Stat constants.
  134. grep '^const _S_' gen-sysinfo.go | \
  135. sed -e 's/^\(const \)_\(S_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  136. # Mmap constants.
  137. grep '^const _PROT_' gen-sysinfo.go | \
  138. sed -e 's/^\(const \)_\(PROT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  139. grep '^const _MAP_' gen-sysinfo.go | \
  140. sed -e 's/^\(const \)_\(MAP_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  141. grep '^const _MADV_' gen-sysinfo.go | \
  142. sed -e 's/^\(const \)_\(MADV_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  143. grep '^const _MCL_' gen-sysinfo.go | \
  144. sed -e 's/^\(const \)_\(MCL_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  145. # Process status constants.
  146. grep '^const _W' gen-sysinfo.go |
  147. sed -e 's/^\(const \)_\(W[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  148. # WSTOPPED was introduced in glibc 2.3.4.
  149. if ! grep '^const _WSTOPPED = ' gen-sysinfo.go >/dev/null 2>&1; then
  150. if grep '^const _WUNTRACED = ' gen-sysinfo.go > /dev/null 2>&1; then
  151. echo 'const WSTOPPED = _WUNTRACED' >> ${OUT}
  152. else
  153. echo 'const WSTOPPED = 2' >> ${OUT}
  154. fi
  155. fi
  156. if grep '^const ___WALL = ' gen-sysinfo.go >/dev/null 2>&1 \
  157. && ! grep '^const _WALL = ' gen-sysinfo.go >/dev/null 2>&1; then
  158. echo 'const WALL = ___WALL' >> ${OUT}
  159. fi
  160. # On GNU/Linux the os package requires WEXITED and WNOWAIT.
  161. if test "${GOOS}" = "linux"; then
  162. if ! grep '^const WEXITED = ' ${OUT} >/dev/null 2>&1; then
  163. echo 'const WEXITED = 4' >> ${OUT}
  164. fi
  165. if ! grep '^const WNOWAIT = ' ${OUT} >/dev/null 2>&1; then
  166. echo 'const WNOWAIT = 0x01000000' >> ${OUT}
  167. fi
  168. fi
  169. # Networking constants.
  170. egrep '^const _(AF|ARPHRD|ETH|IN|SOCK|SOL|SO|IPPROTO|TCP|IP|IPV6)_' gen-sysinfo.go |
  171. grep -v '_val =' |
  172. sed -e 's/^\(const \)_\([^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  173. grep '^const _SOMAXCONN' gen-sysinfo.go |
  174. sed -e 's/^\(const \)_\(SOMAXCONN[^= ]*\)\(.*\)$/\1\2 = _\2/' \
  175. >> ${OUT}
  176. grep '^const _SHUT_' gen-sysinfo.go |
  177. sed -e 's/^\(const \)_\(SHUT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  178. # The net package requires some const definitions.
  179. for m in IP_PKTINFO IPV6_V6ONLY IPPROTO_IPV6 IPV6_JOIN_GROUP IPV6_LEAVE_GROUP IPV6_TCLASS SO_REUSEPORT; do
  180. if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
  181. echo "const $m = 0" >> ${OUT}
  182. fi
  183. done
  184. for m in SOCK_CLOEXEC SOCK_NONBLOCK; do
  185. if ! grep "^const $m " ${OUT} >/dev/null 2>&1; then
  186. echo "const $m = -1" >> ${OUT}
  187. fi
  188. done
  189. # On 32-bit GNU/Linux the expression for SO_RCVTIMEO is too complicated
  190. # for -fdump-go-spec.
  191. if ! grep '^const SO_RCVTIMEO ' ${OUT} >/dev/null 2>&1; then
  192. if grep '^const _SO_RCVTIMEO_val' ${OUT} >/dev/null 2>&1; then
  193. echo 'const SO_RCVTIMEO = _SO_RCVTIMEO_val' >> ${OUT}
  194. fi
  195. fi
  196. # The syscall package requires AF_LOCAL.
  197. if ! grep '^const AF_LOCAL ' ${OUT} >/dev/null 2>&1; then
  198. if grep '^const AF_UNIX ' ${OUT} >/dev/null 2>&1; then
  199. echo "const AF_LOCAL = AF_UNIX" >> ${OUT}
  200. fi
  201. fi
  202. # The syscall package requires _AT_FDCWD, but doesn't export it.
  203. if ! grep '^const _AT_FDCWD = ' ${OUT} >/dev/null 2>&1; then
  204. echo "const _AT_FDCWD = -100" >> ${OUT}
  205. fi
  206. # sysctl constants.
  207. grep '^const _CTL' gen-sysinfo.go |
  208. sed -e 's/^\(const \)_\(CTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  209. grep '^const _SYSCTL' gen-sysinfo.go |
  210. sed -e 's/^\(const \)_\(SYSCTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  211. grep '^const _NET_RT' gen-sysinfo.go |
  212. sed -e 's/^\(const \)_\(NET_RT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  213. # The sysctlnode struct.
  214. grep '^type _sysctlnode ' gen-sysinfo.go | \
  215. sed -e 's/_sysctlnode/Sysctlnode/' \
  216. -e 's/sysctl_flags/Flags/' \
  217. -e 's/sysctl_name/Name/' \
  218. -e 's/sysctl_num/Num/' \
  219. >> ${OUT}
  220. # sysconf constants.
  221. grep '^const __SC' gen-sysinfo.go |
  222. sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
  223. # pathconf constants.
  224. grep '^const __PC' gen-sysinfo.go |
  225. sed -e 's/^\(const \)__\(PC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
  226. # The PATH_MAX constant.
  227. if grep '^const _PATH_MAX ' gen-sysinfo.go >/dev/null 2>&1; then
  228. echo 'const PathMax = _PATH_MAX' >> ${OUT}
  229. fi
  230. # epoll constants.
  231. grep '^const _EPOLL' gen-sysinfo.go |
  232. grep -v EPOLLET |
  233. sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  234. # Make sure EPOLLET is positive.
  235. if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go >/dev/null 2>&1; then
  236. grep '^const _EPOLLET ' gen-sysinfo.go |
  237. sed -e 's/^\(const \)_\(EPOLL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  238. else
  239. echo "const EPOLLET = 0x80000000" >> ${OUT}
  240. fi
  241. # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
  242. if ! grep '^const EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
  243. echo "const EPOLLRDHUP = 0x2000" >> ${OUT}
  244. fi
  245. if ! grep '^const EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
  246. echo "const EPOLL_CLOEXEC = 02000000" >> ${OUT}
  247. fi
  248. # Prctl constants.
  249. grep '^const _PR_' gen-sysinfo.go |
  250. sed -e 's/^\(const \)_\(PR_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  251. # Ptrace constants.
  252. grep '^const _PTRACE' gen-sysinfo.go |
  253. sed -e 's/^\(const \)_\(PTRACE[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  254. # We need some ptrace options that are not defined in older versions
  255. # of glibc.
  256. if ! grep '^const PTRACE_SETOPTIONS' ${OUT} > /dev/null 2>&1; then
  257. echo "const PTRACE_SETOPTIONS = 0x4200" >> ${OUT}
  258. fi
  259. if ! grep '^const PTRACE_O_TRACESYSGOOD' ${OUT} > /dev/null 2>&1; then
  260. echo "const PTRACE_O_TRACESYSGOOD = 0x1" >> ${OUT}
  261. fi
  262. if ! grep '^const PTRACE_O_TRACEFORK' ${OUT} > /dev/null 2>&1; then
  263. echo "const PTRACE_O_TRACEFORK = 0x2" >> ${OUT}
  264. fi
  265. if ! grep '^const PTRACE_O_TRACEVFORK' ${OUT} > /dev/null 2>&1; then
  266. echo "const PTRACE_O_TRACEVFORK = 0x4" >> ${OUT}
  267. fi
  268. if ! grep '^const PTRACE_O_TRACECLONE' ${OUT} > /dev/null 2>&1; then
  269. echo "const PTRACE_O_TRACECLONE = 0x8" >> ${OUT}
  270. fi
  271. if ! grep '^const PTRACE_O_TRACEEXEC' ${OUT} > /dev/null 2>&1; then
  272. echo "const PTRACE_O_TRACEEXEC = 0x10" >> ${OUT}
  273. fi
  274. if ! grep '^const PTRACE_O_TRACEVFORKDONE' ${OUT} > /dev/null 2>&1; then
  275. echo "const PTRACE_O_TRACEVFORKDONE = 0x20" >> ${OUT}
  276. fi
  277. if ! grep '^const PTRACE_O_TRACEEXIT' ${OUT} > /dev/null 2>&1; then
  278. echo "const PTRACE_O_TRACEEXIT = 0x40" >> ${OUT}
  279. fi
  280. if ! grep '^const PTRACE_O_MASK' ${OUT} > /dev/null 2>&1; then
  281. echo "const PTRACE_O_MASK = 0x7f" >> ${OUT}
  282. fi
  283. if ! grep '^const _PTRACE_GETEVENTMSG' ${OUT} > /dev/null 2>&1; then
  284. echo "const PTRACE_GETEVENTMSG = 0x4201" >> ${OUT}
  285. fi
  286. if ! grep '^const PTRACE_EVENT_FORK' ${OUT} > /dev/null 2>&1; then
  287. echo "const PTRACE_EVENT_FORK = 1" >> ${OUT}
  288. fi
  289. if ! grep '^const PTRACE_EVENT_VFORK' ${OUT} > /dev/null 2>&1; then
  290. echo "const PTRACE_EVENT_VFORK = 2" >> ${OUT}
  291. fi
  292. if ! grep '^const PTRACE_EVENT_CLONE' ${OUT} > /dev/null 2>&1; then
  293. echo "const PTRACE_EVENT_CLONE = 3" >> ${OUT}
  294. fi
  295. if ! grep '^const PTRACE_EVENT_EXEC' ${OUT} > /dev/null 2>&1; then
  296. echo "const PTRACE_EVENT_EXEC = 4" >> ${OUT}
  297. fi
  298. if ! grep '^const PTRACE_EVENT_VFORK_DONE' ${OUT} > /dev/null 2>&1; then
  299. echo "const PTRACE_EVENT_VFORK_DONE = 5" >> ${OUT}
  300. fi
  301. if ! grep '^const PTRACE_EVENT_EXIT' ${OUT} > /dev/null 2>&1; then
  302. echo "const PTRACE_EVENT_EXIT = 6" >> ${OUT}
  303. fi
  304. if ! grep '^const _PTRACE_TRACEME' ${OUT} > /dev/null 2>&1; then
  305. echo "const _PTRACE_TRACEME = 0" >> ${OUT}
  306. fi
  307. # A helper function that prints a structure from gen-sysinfo.go with the first
  308. # letter of the field names in upper case. $1 is the name of structure. If $2
  309. # is not empty, the structure or type is renamed to $2.
  310. upcase_fields () {
  311. name="$1"
  312. def=`grep "^type $name " gen-sysinfo.go`
  313. fields=`echo $def | sed -e 's/^[^{]*{\(.*\)}$/\1/'`
  314. prefix=`echo $def | sed -e 's/{.*//'`
  315. if test "$2" != ""; then
  316. prefix=`echo $prefix | sed -e "s/$1/$2/"`
  317. fi
  318. if test "$fields" != ""; then
  319. nfields=
  320. while test -n "$fields"; do
  321. field=`echo $fields | sed -e 's/^\([^;]*\);.*$/\1/'`
  322. fields=`echo $fields | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
  323. # capitalize the next character.
  324. f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
  325. r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
  326. f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  327. field="$f$r"
  328. nfields="$nfields $field;"
  329. done
  330. echo "${prefix} {$nfields }"
  331. fi
  332. }
  333. # The registers returned by PTRACE_GETREGS. This is probably
  334. # GNU/Linux specific; it should do no harm if there is no
  335. # _user_regs_struct.
  336. regs=`grep '^type _user_regs_struct struct' gen-sysinfo.go || true`
  337. if test "$regs" = ""; then
  338. # mips*
  339. regs=`grep '^type _pt_regs struct' gen-sysinfo.go || true`
  340. fi
  341. if test "$regs" != ""; then
  342. regs=`echo $regs | sed -e 's/type _pt_regs struct//'`
  343. regs=`echo $regs |
  344. sed -e 's/type __*user_regs_struct struct //' -e 's/[{}]//g'`
  345. regs=`echo $regs | sed -e s'/^ *//'`
  346. nregs=
  347. while test -n "$regs"; do
  348. field=`echo $regs | sed -e 's/^\([^;]*\);.*$/\1/'`
  349. regs=`echo $regs | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
  350. # Capitalize the first character of the field.
  351. f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
  352. r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
  353. f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  354. field="$f$r"
  355. field=`echo "$field" | sed \
  356. -e 's/__user_psw_struct/PtracePsw/' \
  357. -e 's/__user_fpregs_struct/PtraceFpregs/' \
  358. -e 's/__user_per_struct/PtracePer/'`
  359. nregs="$nregs $field;"
  360. done
  361. echo "type PtraceRegs struct {$nregs }" >> ${OUT}
  362. fi
  363. # Some basic types.
  364. echo 'type Size_t _size_t' >> ${OUT}
  365. echo "type Ssize_t _ssize_t" >> ${OUT}
  366. if grep '^const _HAVE_OFF64_T = ' gen-sysinfo.go > /dev/null 2>&1; then
  367. echo "type Offset_t _off64_t" >> ${OUT}
  368. else
  369. echo "type Offset_t _off_t" >> ${OUT}
  370. fi
  371. echo "type Mode_t _mode_t" >> ${OUT}
  372. echo "type Pid_t _pid_t" >> ${OUT}
  373. echo "type Uid_t _uid_t" >> ${OUT}
  374. echo "type Gid_t _gid_t" >> ${OUT}
  375. echo "type Socklen_t _socklen_t" >> ${OUT}
  376. # The C int type.
  377. sizeof_int=`grep '^const ___SIZEOF_INT__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
  378. if test "$sizeof_int" = "4"; then
  379. echo "type _C_int int32" >> ${OUT}
  380. echo "type _C_uint uint32" >> ${OUT}
  381. elif test "$sizeof_int" = "8"; then
  382. echo "type _C_int int64" >> ${OUT}
  383. echo "type _C_uint uint64" >> ${OUT}
  384. else
  385. echo 1>&2 "mksysinfo.sh: could not determine size of int (got $sizeof_int)"
  386. exit 1
  387. fi
  388. # The C long type, needed because that is the type that ptrace returns.
  389. sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
  390. if test "$sizeof_long" = "4"; then
  391. echo "type _C_long int32" >> ${OUT}
  392. echo "type _C_ulong uint32" >> ${OUT}
  393. elif test "$sizeof_long" = "8"; then
  394. echo "type _C_long int64" >> ${OUT}
  395. echo "type _C_ulong uint64" >> ${OUT}
  396. else
  397. echo 1>&2 "mksysinfo.sh: could not determine size of long (got $sizeof_long)"
  398. exit 1
  399. fi
  400. # The time_t type.
  401. if grep '^type _time_t ' gen-sysinfo.go > /dev/null 2>&1; then
  402. echo 'type Time_t _time_t' >> ${OUT}
  403. fi
  404. # The time structures need special handling: we need to name the
  405. # types, so that we can cast integers to the right types when
  406. # assigning to the structures.
  407. timeval=`grep '^type _timeval ' gen-sysinfo.go`
  408. timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
  409. timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
  410. echo "type Timeval_sec_t = $timeval_sec" >> ${OUT}
  411. echo "type Timeval_usec_t = $timeval_usec" >> ${OUT}
  412. echo $timeval | \
  413. sed -e 's/type _timeval /type Timeval /' \
  414. -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timeval_sec_t/' \
  415. -e 's/tv_usec *[a-zA-Z0-9_]*/Usec Timeval_usec_t/' >> ${OUT}
  416. timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
  417. if test "$timespec" = ""; then
  418. # IRIX 6.5 has __timespec instead.
  419. timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
  420. fi
  421. timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
  422. timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
  423. echo "type Timespec_sec_t = $timespec_sec" >> ${OUT}
  424. echo "type Timespec_nsec_t = $timespec_nsec" >> ${OUT}
  425. echo $timespec | \
  426. sed -e 's/^type ___timespec /type Timespec /' \
  427. -e 's/^type _timespec /type Timespec /' \
  428. -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timespec_sec_t/' \
  429. -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timespec_nsec_t/' >> ${OUT}
  430. timestruc=`grep '^type _timestruc_t ' gen-sysinfo.go || true`
  431. if test "$timestruc" = "type _timestruc_t _timespec"; then
  432. echo "type Timestruc Timespec" >> ${OUT}
  433. elif test "$timestruc" != ""; then
  434. timestruc_sec=`echo $timestruc | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
  435. timestruc_nsec=`echo $timestruc | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
  436. echo "type Timestruc_sec_t = $timestruc_sec" >> ${OUT}
  437. echo "type Timestruc_nsec_t = $timestruc_nsec" >> ${OUT}
  438. echo $timestruc | \
  439. sed -e 's/^type _timestruc_t /type Timestruc /' \
  440. -e 's/tv_sec *[a-zA-Z0-9_]*/Sec Timestruc_sec_t/' \
  441. -e 's/tv_nsec *[a-zA-Z0-9_]*/Nsec Timestruc_nsec_t/' >> ${OUT}
  442. fi
  443. # The tms struct.
  444. grep '^type _tms ' gen-sysinfo.go | \
  445. sed -e 's/type _tms/type Tms/' \
  446. -e 's/tms_utime/Utime/' \
  447. -e 's/tms_stime/Stime/' \
  448. -e 's/tms_cutime/Cutime/' \
  449. -e 's/tms_cstime/Cstime/' \
  450. >> ${OUT}
  451. # AIX uses st_timespec struct for stat.
  452. grep '^type _st_timespec ' gen-sysinfo.go | \
  453. sed -e 's/type _st_timespec /type StTimespec /' \
  454. -e 's/tv_sec/Sec/' \
  455. -e 's/tv_nsec/Nsec/' >> ${OUT}
  456. # Special treatment of struct stat st_dev for GNU/Hurd
  457. # /usr/include/i386-gnu/bits/stat.h: #define st_dev st_fsid
  458. st_dev='-e s/st_dev/Dev/'
  459. if grep 'define st_dev st_fsid' gen-sysinfo.go > /dev/null 2>&1; then
  460. st_dev='-e s/st_fsid/Dev/'
  461. fi
  462. # For historical reasons Go uses the suffix "timespec" instead of "tim" for
  463. # stat_t's time fields on NetBSD.
  464. st_times='-e s/st_atim/Atim/ -e s/st_mtim/Mtim/ -e s/st_ctim/Ctim/'
  465. if test "${GOOS}" = "netbsd"; then
  466. st_times='-e s/st_atim/Atimespec/ -e s/st_mtim/Mtimespec/ -e s/st_ctim/Ctimespec/'
  467. fi
  468. # The stat type.
  469. # Prefer largefile variant if available.
  470. stat=`grep '^type _stat64 ' gen-sysinfo.go || true`
  471. if test "$stat" != ""; then
  472. grep '^type _stat64 ' gen-sysinfo.go
  473. else
  474. grep '^type _stat ' gen-sysinfo.go
  475. fi | sed -e 's/type _stat64/type Stat_t/' \
  476. -e 's/type _stat/type Stat_t/' \
  477. ${st_dev} \
  478. ${st_times} \
  479. -e 's/st_ino/Ino/g' \
  480. -e 's/st_nlink/Nlink/' \
  481. -e 's/st_mode/Mode/' \
  482. -e 's/st_uid/Uid/' \
  483. -e 's/st_gid/Gid/' \
  484. -e 's/st_rdev/Rdev/' \
  485. -e 's/st_size/Size/' \
  486. -e 's/st_blksize/Blksize/' \
  487. -e 's/st_blocks/Blocks/' \
  488. -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1Timeval\2/g' \
  489. -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
  490. -e 's/\([^a-zA-Z0-9_]\)_st_timespec_t\([^a-zA-Z0-9_]\)/\1StTimespec\2/g' \
  491. -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1Timespec\2/g' \
  492. -e 's/\([^a-zA-Z0-9_]\)_timestruc_t\([^a-zA-Z0-9_]\)/\1Timestruc\2/g' \
  493. -e 's/Godump_[0-9] struct { \([^;]*;\) };/\1/g' \
  494. >> ${OUT}
  495. # The directory searching types.
  496. # Prefer largefile variant if available.
  497. dirent=`grep '^type _dirent64 ' gen-sysinfo.go || true`
  498. if test "$dirent" != ""; then
  499. grep '^type _dirent64 ' gen-sysinfo.go
  500. else
  501. grep '^type _dirent ' gen-sysinfo.go
  502. fi | sed -e 's/type _dirent64/type Dirent/' \
  503. -e 's/type _dirent/type Dirent/' \
  504. -e 's/d_name \[0+1\]/d_name [0+256]/' \
  505. -e 's/d_name/Name/' \
  506. -e 's/]int8/]byte/' \
  507. -e 's/d_fileno/Fileno/' \
  508. -e 's/d_ino/Ino/' \
  509. -e 's/d_namlen/Namlen/' \
  510. -e 's/d_off/Off/' \
  511. -e 's/d_reclen/Reclen/' \
  512. -e 's/d_type/Type/' \
  513. >> ${OUT}
  514. echo "type DIR _DIR" >> ${OUT}
  515. # Values for d_type field in dirent.
  516. grep '^const _DT_' gen-sysinfo.go |
  517. sed -e 's/^\(const \)_\(DT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  518. # The rusage struct.
  519. rusage=`grep '^type _rusage struct' gen-sysinfo.go`
  520. if test "$rusage" != ""; then
  521. # Remove anonymous unions from GNU/Linux <bits/resource.h>.
  522. rusage=`echo $rusage | sed -e 's/Godump_[0-9][0-9]* struct {\([^}]*\)};/\1/g'`
  523. rusage=`echo $rusage | sed -e 's/type _rusage struct //' -e 's/[{}]//g'`
  524. rusage=`echo $rusage | sed -e 's/^ *//'`
  525. nrusage=
  526. while test -n "$rusage"; do
  527. field=`echo $rusage | sed -e 's/^\([^;]*\);.*$/\1/'`
  528. rusage=`echo $rusage | sed -e 's/^[^;]*; *\(.*\)$/\1/'`
  529. # Drop the leading ru_, capitalize the next character.
  530. field=`echo $field | sed -e 's/^ru_//'`
  531. f=`echo $field | sed -e 's/^\(.\).*$/\1/'`
  532. r=`echo $field | sed -e 's/^.\(.*\)$/\1/'`
  533. f=`echo $f | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ`
  534. # Fix _timeval _timespec, and _timestruc_t.
  535. r=`echo $r | sed -e s'/ _timeval$/ Timeval/'`
  536. r=`echo $r | sed -e s'/ _timespec$/ Timespec/'`
  537. r=`echo $r | sed -e s'/ _timestruc_t$/ Timestruc/'`
  538. field="$f$r"
  539. nrusage="$nrusage $field;"
  540. done
  541. echo "type Rusage struct {$nrusage }" >> ${OUT}
  542. else
  543. echo "type Rusage struct {}" >> ${OUT}
  544. fi
  545. # The RUSAGE constants.
  546. grep '^const _RUSAGE_' gen-sysinfo.go | \
  547. sed -e 's/^\(const \)_\(RUSAGE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  548. # The utsname struct.
  549. grep '^type _utsname ' gen-sysinfo.go | \
  550. sed -e 's/_utsname/Utsname/' \
  551. -e 's/sysname/Sysname/' \
  552. -e 's/nodename/Nodename/' \
  553. -e 's/release/Release/' \
  554. -e 's/version/Version/' \
  555. -e 's/machine/Machine/' \
  556. -e 's/domainname/Domainname/' \
  557. >> ${OUT}
  558. # The iovec struct.
  559. iovec=`grep '^type _iovec ' gen-sysinfo.go`
  560. iovec_len=`echo $iovec | sed -n -e 's/^.*iov_len \([^ ]*\);.*$/\1/p'`
  561. echo "type Iovec_len_t $iovec_len" >> ${OUT}
  562. echo $iovec | \
  563. sed -e 's/_iovec/Iovec/' \
  564. -e 's/iov_base/Base/' \
  565. -e 's/iov_len *[a-zA-Z0-9_]*/Len Iovec_len_t/' \
  566. >> ${OUT}
  567. # The msghdr struct.
  568. msghdr=`grep '^type _msghdr ' gen-sysinfo.go`
  569. msghdr_controllen=`echo $msghdr | sed -n -e 's/^.*msg_controllen \([^ ]*\);.*$/\1/p'`
  570. echo "type Msghdr_controllen_t $msghdr_controllen" >> ${OUT}
  571. echo $msghdr | \
  572. sed -e 's/_msghdr/Msghdr/' \
  573. -e 's/msg_name/Name/' \
  574. -e 's/msg_namelen/Namelen/' \
  575. -e 's/msg_iov/Iov/' \
  576. -e 's/msg_iovlen/Iovlen/' \
  577. -e 's/_iovec/Iovec/' \
  578. -e 's/msg_control/Control/' \
  579. -e 's/msg_controllen *[a-zA-Z0-9_]*/Controllen Msghdr_controllen_t/' \
  580. -e 's/msg_flags/Flags/' \
  581. >> ${OUT}
  582. # The MSG_ flags for Msghdr.
  583. grep '^const _MSG_' gen-sysinfo.go | \
  584. sed -e 's/^\(const \)_\(MSG_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  585. # The cmsghdr struct.
  586. cmsghdr=`grep '^type _cmsghdr ' gen-sysinfo.go`
  587. if test -n "$cmsghdr"; then
  588. cmsghdr_len=`echo $cmsghdr | sed -n -e 's/^.*cmsg_len \([^ ]*\);.*$/\1/p'`
  589. echo "type Cmsghdr_len_t $cmsghdr_len" >> ${OUT}
  590. echo "$cmsghdr" | \
  591. sed -e 's/_cmsghdr/Cmsghdr/' \
  592. -e 's/cmsg_len *[a-zA-Z0-9_]*/Len Cmsghdr_len_t/' \
  593. -e 's/cmsg_level/Level/' \
  594. -e 's/cmsg_type/Type/' \
  595. -e 's/\[\]/[0]/' \
  596. >> ${OUT}
  597. fi
  598. # The SCM_ flags for Cmsghdr.
  599. grep '^const _SCM_' gen-sysinfo.go | \
  600. sed -e 's/^\(const \)_\(SCM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  601. # The ucred struct.
  602. upcase_fields "_ucred" "Ucred" >> ${OUT} || true
  603. # The ip_mreq struct.
  604. grep '^type _ip_mreq ' gen-sysinfo.go | \
  605. sed -e 's/_ip_mreq/IPMreq/' \
  606. -e 's/imr_multiaddr/Multiaddr/' \
  607. -e 's/imr_interface/Interface/' \
  608. -e 's/_in_addr/[4]byte/g' \
  609. >> ${OUT}
  610. # We need IPMreq to compile the net package.
  611. if ! grep 'type IPMreq ' ${OUT} >/dev/null 2>&1; then
  612. echo 'type IPMreq struct { Multiaddr [4]byte; Interface [4]byte; }' >> ${OUT}
  613. fi
  614. # The ipv6_mreq struct.
  615. grep '^type _ipv6_mreq ' gen-sysinfo.go | \
  616. sed -e 's/_ipv6_mreq/IPv6Mreq/' \
  617. -e 's/ipv6mr_multiaddr/Multiaddr/' \
  618. -e 's/ipv6mr_interface/Interface/' \
  619. -e 's/_in6_addr/[16]byte/' \
  620. >> ${OUT}
  621. # We need IPv6Mreq to compile the net package.
  622. if ! grep 'type IPv6Mreq ' ${OUT} >/dev/null 2>&1; then
  623. echo 'type IPv6Mreq struct { Multiaddr [16]byte; Interface uint32; }' >> ${OUT}
  624. fi
  625. # The ip_mreqn struct.
  626. grep '^type _ip_mreqn ' gen-sysinfo.go | \
  627. sed -e 's/_ip_mreqn/IPMreqn/' \
  628. -e 's/imr_multiaddr/Multiaddr/' \
  629. -e 's/imr_address/Address/' \
  630. -e 's/imr_ifindex/Ifindex/' \
  631. -e 's/_in_addr/[4]byte/g' \
  632. >> ${OUT}
  633. # We need IPMreq to compile the net package.
  634. if ! grep 'type IPMreqn ' ${OUT} >/dev/null 2>&1; then
  635. echo 'type IPMreqn struct { Multiaddr [4]byte; Interface [4]byte; Ifindex int32 }' >> ${OUT}
  636. fi
  637. # The icmp6_filter struct.
  638. grep '^type _icmp6_filter ' gen-sysinfo.go | \
  639. sed -e 's/_icmp6_filter/ICMPv6Filter/' \
  640. -e 's/data/Data/' \
  641. -e 's/filt/Filt/' \
  642. >> ${OUT}
  643. # We need ICMPv6Filter to compile the syscall package.
  644. if ! grep 'type ICMPv6Filter ' ${OUT} > /dev/null 2>&1; then
  645. echo 'type ICMPv6Filter struct { Data [8]uint32 }' >> ${OUT}
  646. fi
  647. # The ip6_mtuinfo struct.
  648. grep '^type _ip6_mtuinfo ' gen-sysinfo.go | \
  649. sed -e 's/_ip6_mtuinfo/IPv6MTUInfo/' \
  650. -e 's/ip6m_addr/Addr/' \
  651. -e 's/_sockaddr_in6/RawSockaddrInet6/' \
  652. -e 's/ip6m_mtu/Mtu/' \
  653. >> ${OUT}
  654. # We need IPv6MTUInfo to compile the syscall package.
  655. if ! grep 'type IPv6MTUInfo ' ${OUT} >/dev/null 2>&1; then
  656. echo 'type IPv6MTUInfo struct { Addr RawSockaddrInet6; Mtu uint32; }' >> ${OUT}
  657. fi
  658. if ! grep 'const _sizeof_ip6_mtuinfo = ' ${OUT} >/dev/null 2>&1; then
  659. echo 'const SizeofIPv6MTUInfo = 32' >> ${OUT}
  660. fi
  661. # Try to guess the type to use for fd_set.
  662. fd_set=`grep '^type _fd_set ' gen-sysinfo.go || true`
  663. fds_bits_type="_C_long"
  664. if test "$fd_set" != ""; then
  665. fds_bits_type=`echo $fd_set | sed -e 's/.*[]]\([^;]*\); }$/\1/'`
  666. fi
  667. echo "type fds_bits_type $fds_bits_type" >> ${OUT}
  668. # The addrinfo struct.
  669. grep '^type _addrinfo ' gen-sysinfo.go | \
  670. sed -e 's/_addrinfo/Addrinfo/g' \
  671. -e 's/ ai_/ Ai_/g' \
  672. >> ${OUT}
  673. # The addrinfo and nameinfo flags and errors.
  674. grep '^const _AI_' gen-sysinfo.go | \
  675. sed -e 's/^\(const \)_\(AI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  676. grep '^const _EAI_' gen-sysinfo.go | \
  677. sed -e 's/^\(const \)_\(EAI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  678. grep '^const _NI_' gen-sysinfo.go | \
  679. sed -e 's/^\(const \)_\(NI_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  680. # If nothing else defined EAI_OVERFLOW, make sure it has a value.
  681. if ! grep "const EAI_OVERFLOW " ${OUT} >/dev/null 2>&1; then
  682. echo "const EAI_OVERFLOW = 0" >> ${OUT}
  683. fi
  684. # The passwd struct.
  685. grep '^type _passwd ' gen-sysinfo.go | \
  686. sed -e 's/_passwd/Passwd/' \
  687. -e 's/ pw_/ Pw_/g' \
  688. >> ${OUT}
  689. # The group struct.
  690. grep '^type _group ' gen-sysinfo.go | \
  691. sed -e 's/_group/Group/' \
  692. -e 's/ gr_/ Gr_/g' \
  693. >> ${OUT}
  694. # The ioctl flags for the controlling TTY.
  695. grep '^const _TIOC' gen-sysinfo.go | \
  696. grep -v '_val =' | \
  697. sed -e 's/^\(const \)_\(TIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  698. grep '^const _TUNSET' gen-sysinfo.go | \
  699. grep -v '_val =' | \
  700. sed -e 's/^\(const \)_\(TUNSET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  701. # We need TIOCGWINSZ.
  702. if ! grep '^const TIOCGWINSZ' ${OUT} >/dev/null 2>&1; then
  703. if grep '^const _TIOCGWINSZ_val' ${OUT} >/dev/null 2>&1; then
  704. echo 'const TIOCGWINSZ = _TIOCGWINSZ_val' >> ${OUT}
  705. fi
  706. fi
  707. if ! grep '^const TIOCSWINSZ' ${OUT} >/dev/null 2>&1; then
  708. if grep '^const _TIOCSWINSZ_val' ${OUT} >/dev/null 2>&1; then
  709. echo 'const TIOCSWINSZ = _TIOCSWINSZ_val' >> ${OUT}
  710. fi
  711. fi
  712. if ! grep '^const TIOCNOTTY' ${OUT} >/dev/null 2>&1; then
  713. if grep '^const _TIOCNOTTY_val' ${OUT} >/dev/null 2>&1; then
  714. echo 'const TIOCNOTTY = _TIOCNOTTY_val' >> ${OUT}
  715. fi
  716. fi
  717. if ! grep '^const TIOCSCTTY' ${OUT} >/dev/null 2>&1; then
  718. if grep '^const _TIOCSCTTY_val' ${OUT} >/dev/null 2>&1; then
  719. echo 'const TIOCSCTTY = _TIOCSCTTY_val' >> ${OUT}
  720. fi
  721. fi
  722. if ! grep '^const TIOCGPGRP' ${OUT} >/dev/null 2>&1; then
  723. if grep '^const _TIOCGPGRP_val' ${OUT} >/dev/null 2>&1; then
  724. echo 'const TIOCGPGRP = _TIOCGPGRP_val' >> ${OUT}
  725. fi
  726. fi
  727. if ! grep '^const TIOCSPGRP' ${OUT} >/dev/null 2>&1; then
  728. if grep '^const _TIOCSPGRP_val' ${OUT} >/dev/null 2>&1; then
  729. echo 'const TIOCSPGRP = _TIOCSPGRP_val' >> ${OUT}
  730. fi
  731. fi
  732. if ! grep '^const TIOCGPTN' ${OUT} >/dev/null 2>&1; then
  733. if grep '^const _TIOCGPTN_val' ${OUT} >/dev/null 2>&1; then
  734. echo 'const TIOCGPTN = _TIOCGPTN_val' >> ${OUT}
  735. fi
  736. fi
  737. if ! grep '^const TIOCSPTLCK' ${OUT} >/dev/null 2>&1; then
  738. if grep '^const _TIOCSPTLCK_val' ${OUT} >/dev/null 2>&1; then
  739. echo 'const TIOCSPTLCK = _TIOCSPTLCK_val' >> ${OUT}
  740. fi
  741. fi
  742. if ! grep '^const TIOCGDEV' ${OUT} >/dev/null 2>&1; then
  743. if grep '^const _TIOCGDEV_val' ${OUT} >/dev/null 2>&1; then
  744. echo 'const TIOCGDEV = _TIOCGDEV_val' >> ${OUT}
  745. fi
  746. fi
  747. if ! grep '^const TIOCSIG' ${OUT} >/dev/null 2>&1; then
  748. if grep '^const _TIOCSIG_val' ${OUT} >/dev/null 2>&1; then
  749. echo 'const TIOCSIG = _TIOCSIG_val' >> ${OUT}
  750. fi
  751. fi
  752. if ! grep '^const TUNSETNOCSUM' ${OUT} >/dev/null 2>&1; then
  753. if grep '^const _TUNSETNOCSUM_val' ${OUT} >/dev/null 2>&1; then
  754. echo 'const TUNSETNOCSUM = _TUNSETNOCSUM_val' >> ${OUT}
  755. fi
  756. fi
  757. if ! grep '^const TUNSETDEBUG' ${OUT} >/dev/null 2>&1; then
  758. if grep '^const _TUNSETDEBUG_val' ${OUT} >/dev/null 2>&1; then
  759. echo 'const TUNSETDEBUG = _TUNSETDEBUG_val' >> ${OUT}
  760. fi
  761. fi
  762. if ! grep '^const TUNSETIFF' ${OUT} >/dev/null 2>&1; then
  763. if grep '^const _TUNSETIFF_val' ${OUT} >/dev/null 2>&1; then
  764. echo 'const TUNSETIFF = _TUNSETIFF_val' >> ${OUT}
  765. fi
  766. fi
  767. if ! grep '^const TUNSETPERSIST' ${OUT} >/dev/null 2>&1; then
  768. if grep '^const _TUNSETPERSIST_val' ${OUT} >/dev/null 2>&1; then
  769. echo 'const TUNSETPERSIST = _TUNSETPERSIST_val' >> ${OUT}
  770. fi
  771. fi
  772. if ! grep '^const TUNSETOWNER' ${OUT} >/dev/null 2>&1; then
  773. if grep '^const _TUNSETOWNER_val' ${OUT} >/dev/null 2>&1; then
  774. echo 'const TUNSETOWNER = _TUNSETOWNER_val' >> ${OUT}
  775. fi
  776. fi
  777. if ! grep '^const TUNSETLINK' ${OUT} >/dev/null 2>&1; then
  778. if grep '^const _TUNSETLINK_val' ${OUT} >/dev/null 2>&1; then
  779. echo 'const TUNSETLINK = _TUNSETLINK_val' >> ${OUT}
  780. fi
  781. fi
  782. if ! grep '^const TUNSETGROUP' ${OUT} >/dev/null 2>&1; then
  783. if grep '^const _TUNSETGROUP_val' ${OUT} >/dev/null 2>&1; then
  784. echo 'const TUNSETGROUP = _TUNSETGROUP_val' >> ${OUT}
  785. fi
  786. fi
  787. if ! grep '^const TUNGETFEATURES' ${OUT} >/dev/null 2>&1; then
  788. if grep '^const _TUNGETFEATURES_val' ${OUT} >/dev/null 2>&1; then
  789. echo 'const TUNGETFEATURES = _TUNGETFEATURES_val' >> ${OUT}
  790. fi
  791. fi
  792. if ! grep '^const TUNSETOFFLOAD' ${OUT} >/dev/null 2>&1; then
  793. if grep '^const _TUNSETOFFLOAD_val' ${OUT} >/dev/null 2>&1; then
  794. echo 'const TUNSETOFFLOAD = _TUNSETOFFLOAD_val' >> ${OUT}
  795. fi
  796. fi
  797. if ! grep '^const TUNSETTXFILTER' ${OUT} >/dev/null 2>&1; then
  798. if grep '^const _TUNSETTXFILTER_val' ${OUT} >/dev/null 2>&1; then
  799. echo 'const TUNSETTXFILTER = _TUNSETTXFILTER_val' >> ${OUT}
  800. fi
  801. fi
  802. if ! grep '^const TUNGETIFF' ${OUT} >/dev/null 2>&1; then
  803. if grep '^const _TUNGETIFF_val' ${OUT} >/dev/null 2>&1; then
  804. echo 'const TUNGETIFF = _TUNGETIFF_val' >> ${OUT}
  805. fi
  806. fi
  807. if ! grep '^const TUNGETSNDBUF' ${OUT} >/dev/null 2>&1; then
  808. if grep '^const _TUNGETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
  809. echo 'const TUNGETSNDBUF = _TUNGETSNDBUF_val' >> ${OUT}
  810. fi
  811. fi
  812. if ! grep '^const TUNSETSNDBUF' ${OUT} >/dev/null 2>&1; then
  813. if grep '^const _TUNSETSNDBUF_val' ${OUT} >/dev/null 2>&1; then
  814. echo 'const TUNSETSNDBUF = _TUNSETSNDBUF_val' >> ${OUT}
  815. fi
  816. fi
  817. if ! grep '^const TUNATTACHFILTER' ${OUT} >/dev/null 2>&1; then
  818. if grep '^const _TUNATTACHFILTER_val' ${OUT} >/dev/null 2>&1; then
  819. echo 'const TUNATTACHFILTER = _TUNATTACHFILTER_val' >> ${OUT}
  820. fi
  821. fi
  822. if ! grep '^const TUNDETACHFILTER' ${OUT} >/dev/null 2>&1; then
  823. if grep '^const _TUNDETACHFILTER_val' ${OUT} >/dev/null 2>&1; then
  824. echo 'const TUNDETACHFILTER = _TUNDETACHFILTER_val' >> ${OUT}
  825. fi
  826. fi
  827. if ! grep '^const TUNGETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
  828. if grep '^const _TUNGETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
  829. echo 'const TUNGETVNETHDRSZ = _TUNGETVNETHDRSZ_val' >> ${OUT}
  830. fi
  831. fi
  832. if ! grep '^const TUNSETVNETHDRSZ' ${OUT} >/dev/null 2>&1; then
  833. if grep '^const _TUNSETVNETHDRSZ_val' ${OUT} >/dev/null 2>&1; then
  834. echo 'const TUNSETVNETHDRSZ = _TUNSETVNETHDRSZ_val' >> ${OUT}
  835. fi
  836. fi
  837. if ! grep '^const TUNSETQUEUE' ${OUT} >/dev/null 2>&1; then
  838. if grep '^const _TUNSETQUEUE_val' ${OUT} >/dev/null 2>&1; then
  839. echo 'const TUNSETQUEUE = _TUNSETQUEUE_val' >> ${OUT}
  840. fi
  841. fi
  842. if ! grep '^const TUNSETIFINDEX' ${OUT} >/dev/null 2>&1; then
  843. if grep '^const _TUNSETIFINDEX_val' ${OUT} >/dev/null 2>&1; then
  844. echo 'const TUNSETIFINDEX = _TUNSETIFINDEX_val' >> ${OUT}
  845. fi
  846. fi
  847. if ! grep '^const TUNGETFILTER' ${OUT} >/dev/null 2>&1; then
  848. if grep '^const _TUNGETFILTER_val' ${OUT} >/dev/null 2>&1; then
  849. echo 'const TUNGETFILTER = _TUNGETFILTER_val' >> ${OUT}
  850. fi
  851. fi
  852. # The ioctl flags for terminal control
  853. grep '^const _TC[GS]ET' gen-sysinfo.go | grep -v _val | \
  854. sed -e 's/^\(const \)_\(TC[GS]ET[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  855. if ! grep '^const TCGETS' ${OUT} >/dev/null 2>&1; then
  856. if grep '^const _TCGETS_val' ${OUT} >/dev/null 2>&1; then
  857. echo 'const TCGETS = _TCGETS_val' >> ${OUT}
  858. fi
  859. fi
  860. if ! grep '^const TCSETS' ${OUT} >/dev/null 2>&1; then
  861. if grep '^const _TCSETS_val' ${OUT} >/dev/null 2>&1; then
  862. echo 'const TCSETS = _TCSETS_val' >> ${OUT}
  863. fi
  864. fi
  865. # ioctl constants. Might fall back to 0 if TIOCNXCL is missing, too, but
  866. # needs handling in syscalls.exec.go.
  867. if ! grep '^const _TIOCSCTTY ' gen-sysinfo.go >/dev/null 2>&1; then
  868. if grep '^const _TIOCNXCL ' gen-sysinfo.go >/dev/null 2>&1; then
  869. echo "const TIOCSCTTY = TIOCNXCL" >> ${OUT}
  870. fi
  871. fi
  872. # If nothing else defined TIOCSCTTY, make sure it has a value.
  873. if ! grep "const TIOCSCTTY " ${OUT} >/dev/null 2>&1; then
  874. echo "const TIOCSCTTY = 0" >> ${OUT}
  875. fi
  876. # The nlmsghdr struct.
  877. grep '^type _nlmsghdr ' gen-sysinfo.go | \
  878. sed -e 's/_nlmsghdr/NlMsghdr/' \
  879. -e 's/nlmsg_len/Len/' \
  880. -e 's/nlmsg_type/Type/' \
  881. -e 's/nlmsg_flags/Flags/' \
  882. -e 's/nlmsg_seq/Seq/' \
  883. -e 's/nlmsg_pid/Pid/' \
  884. >> ${OUT}
  885. # The nlmsg flags and operators.
  886. grep '^const _NLM' gen-sysinfo.go | \
  887. sed -e 's/^\(const \)_\(NLM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  888. # NLMSG_HDRLEN is defined as an expression using sizeof.
  889. if ! grep '^const NLMSG_HDRLEN' ${OUT} > /dev/null 2>&1; then
  890. if grep '^const _sizeof_nlmsghdr ' ${OUT} > /dev/null 2>&1; then
  891. echo 'const NLMSG_HDRLEN = (_sizeof_nlmsghdr + (NLMSG_ALIGNTO-1)) &^ (NLMSG_ALIGNTO-1)' >> ${OUT}
  892. fi
  893. fi
  894. # The rtmsg struct.
  895. grep '^type _rtmsg ' gen-sysinfo.go | \
  896. sed -e 's/_rtmsg/RtMsg/' \
  897. -e 's/rtm_family/Family/' \
  898. -e 's/rtm_dst_len/Dst_len/' \
  899. -e 's/rtm_src_len/Src_len/' \
  900. -e 's/rtm_tos/Tos/' \
  901. -e 's/rtm_table/Table/' \
  902. -e 's/rtm_protocol/Protocol/' \
  903. -e 's/rtm_scope/Scope/' \
  904. -e 's/rtm_type/Type/' \
  905. -e 's/rtm_flags/Flags/' \
  906. >> ${OUT}
  907. # The rtgenmsg struct.
  908. grep '^type _rtgenmsg ' gen-sysinfo.go | \
  909. sed -e 's/_rtgenmsg/RtGenmsg/' \
  910. -e 's/rtgen_family/Family/' \
  911. >> ${OUT}
  912. # The rt_msghdr struct.
  913. grep '^type _rt_msghdr ' gen-sysinfo.go | \
  914. sed -e 's/_rt_msghdr/RtMsghdr/g' \
  915. -e 's/rtm_msglen/Msglen/' \
  916. -e 's/rtm_version/Version/' \
  917. -e 's/rtm_type/Type/' \
  918. -e 's/rtm_index/Index/' \
  919. -e 's/rtm_flags/Flags/' \
  920. -e 's/rtm_addrs/Addrs/' \
  921. -e 's/rtm_pid/Pid/' \
  922. -e 's/rtm_seq/Seq/' \
  923. -e 's/rtm_errno/Errno/' \
  924. -e 's/rtm_use/Use/' \
  925. -e 's/rtm_inits/Inits/' \
  926. -e 's/rtm_rmx/Rmx/' \
  927. -e 's/_rt_metrics/RtMetrics/' \
  928. >> ${OUT}
  929. # The rt_metrics struct.
  930. grep '^type _rt_metrics ' gen-sysinfo.go | \
  931. sed -e 's/_rt_metrics/RtMetrics/g' \
  932. -e 's/rmx_locks/Locks/' \
  933. -e 's/rmx_mtu/Mtu/' \
  934. -e 's/rmx_hopcount/Hopcount/' \
  935. -e 's/rmx_recvpipe/Recvpipe/' \
  936. -e 's/rmx_sendpipe/Sendpipe/' \
  937. -e 's/rmx_ssthresh/Ssthresh/' \
  938. -e 's/rmx_rtt/Rtt/' \
  939. -e 's/rmx_rttvar/Rttvar/' \
  940. -e 's/rmx_expire/Expire/' \
  941. -e 's/rmx_pksent/Pksent/' \
  942. >> ${OUT}
  943. # The routing message flags.
  944. grep '^const _RT_' gen-sysinfo.go | \
  945. sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  946. grep '^const _RTA' gen-sysinfo.go | \
  947. sed -e 's/^\(const \)_\(RTA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  948. grep '^const _RTF' gen-sysinfo.go | \
  949. sed -e 's/^\(const \)_\(RTF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  950. grep '^const _RTCF' gen-sysinfo.go | \
  951. sed -e 's/^\(const \)_\(RTCF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  952. grep '^const _RTM' gen-sysinfo.go | \
  953. sed -e 's/^\(const \)_\(RTM[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  954. if test "${GOOS}" = "netbsd"; then
  955. if ! grep "RTM_RESOLVE" ${OUT} >/dev/null 2>&1; then
  956. # NetBSD 8.0 removed RTM_RESOLVE, but it is part of the syscall package's
  957. # stable API, so add it manually.
  958. echo "const RTM_RESOLVE = 0xb" >> ${OUT}
  959. fi
  960. fi
  961. grep '^const _RTN' gen-sysinfo.go | \
  962. sed -e 's/^\(const \)_\(RTN[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  963. grep '^const _RTPROT' gen-sysinfo.go | \
  964. sed -e 's/^\(const \)_\(RTPROT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  965. # The ifinfomsg struct.
  966. grep '^type _ifinfomsg ' gen-sysinfo.go | \
  967. sed -e 's/_ifinfomsg/IfInfomsg/' \
  968. -e 's/ifi_family/Family/' \
  969. -e 's/ifi_type/Type/' \
  970. -e 's/ifi_index/Index/' \
  971. -e 's/ifi_flags/Flags/' \
  972. -e 's/ifi_change/Change/' \
  973. >> ${OUT}
  974. # The if_msghdr struct. Upstream uses inconsistent capitalization for this type
  975. # on AIX, so we do too.
  976. ifmsghdr_name=IfMsghdr
  977. if test "${GOOS}" = "aix"; then
  978. ifmsghdr_name=IfMsgHdr
  979. fi
  980. grep '^type _if_msghdr ' gen-sysinfo.go | \
  981. sed -e "s/_if_msghdr/${ifmsghdr_name}/" \
  982. -e 's/ifm_msglen/Msglen/' \
  983. -e 's/ifm_version/Version/' \
  984. -e 's/ifm_type/Type/' \
  985. -e 's/ifm_addrs/Addrs/' \
  986. -e 's/ifm_flags/Flags/' \
  987. -e 's/ifm_index/Index/' \
  988. -e 's/ifm_addrlen/Addrlen/' \
  989. >> ${OUT}
  990. # The if_announcemsghdr struct.
  991. grep '^type _if_announcemsghdr ' gen-sysinfo.go | \
  992. sed -e 's/_if_announcemsghdr/IfAnnounceMsghdr/g' \
  993. -e 's/ifan_msglen/Msglen/' \
  994. -e 's/ifan_version/Version/' \
  995. -e 's/ifan_type/Type/' \
  996. -e 's/ifan_index/Index/' \
  997. -e 's/ifan_name/Name/' \
  998. -e 's/ifan_what/What/' \
  999. >> ${OUT}
  1000. # The interface information types and flags.
  1001. grep '^const _IFA' gen-sysinfo.go | \
  1002. sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1003. grep '^const _IFLA' gen-sysinfo.go | \
  1004. sed -e 's/^\(const \)_\(IFLA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1005. grep '^const _IFF' gen-sysinfo.go | \
  1006. sed -e 's/^\(const \)_\(IFF[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1007. grep '^const _IFNAMSIZ' gen-sysinfo.go | \
  1008. sed -e 's/^\(const \)_\(IFNAMSIZ[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1009. grep '^const _SIOC' gen-sysinfo.go | \
  1010. grep -v '_val =' | \
  1011. sed -e 's/^\(const \)_\(SIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1012. if ! grep '^const SIOCGIFMTU' ${OUT} >/dev/null 2>&1; then
  1013. if grep '^const _SIOCGIFMTU_val' ${OUT} >/dev/null 2>&1; then
  1014. echo 'const SIOCGIFMTU = _SIOCGIFMTU_val' >> ${OUT}
  1015. fi
  1016. fi
  1017. # The ifaddrmsg struct.
  1018. grep '^type _ifaddrmsg ' gen-sysinfo.go | \
  1019. sed -e 's/_ifaddrmsg/IfAddrmsg/' \
  1020. -e 's/ifa_family/Family/' \
  1021. -e 's/ifa_prefixlen/Prefixlen/' \
  1022. -e 's/ifa_flags/Flags/' \
  1023. -e 's/ifa_scope/Scope/' \
  1024. -e 's/ifa_index/Index/' \
  1025. >> ${OUT}
  1026. # The ifa_msghdr struct.
  1027. grep '^type _ifa_msghdr ' gen-sysinfo.go | \
  1028. sed -e 's/_ifa_msghdr/IfaMsghdr/g' \
  1029. -e 's/ifam_msglen/Msglen/' \
  1030. -e 's/ifam_version/Version/' \
  1031. -e 's/ifam_type/Type/' \
  1032. -e 's/ifam_addrs/Addrs/' \
  1033. -e 's/ifam_flags/Flags/' \
  1034. -e 's/ifam_metric/Metric/' \
  1035. -e 's/ifam_index/Index/' \
  1036. >> ${OUT}
  1037. # The rtattr struct.
  1038. grep '^type _rtattr ' gen-sysinfo.go | \
  1039. sed -e 's/_rtattr/RtAttr/' \
  1040. -e 's/rta_len/Len/' \
  1041. -e 's/rta_type/Type/' \
  1042. >> ${OUT}
  1043. # The bpf_version struct.
  1044. grep '^type _bpf_version ' gen-sysinfo.go | \
  1045. sed -e 's/_bpf_version/BpfVersion/g' \
  1046. -e 's/bv_major/Major/' \
  1047. -e 's/bv_minor/Minor/' \
  1048. >> ${OUT}
  1049. # The bpf_stat struct.
  1050. grep '^type _bpf_stat ' gen-sysinfo.go | \
  1051. sed -e 's/_bpf_stat/BpfStat/g' \
  1052. -e 's/bs_recv/Recv/' \
  1053. -e 's/bs_drop/Drop/' \
  1054. -e 's/bs_capt/Capt/' \
  1055. -e 's/bs_padding/Padding/' \
  1056. >> ${OUT}
  1057. # The bpf_insn struct.
  1058. grep '^type _bpf_insn ' gen-sysinfo.go | \
  1059. sed -e 's/_bpf_insn/BpfInsn/g' \
  1060. -e 's/code/Code/' \
  1061. -e 's/jt/Jt/' \
  1062. -e 's/jf/Jf/' \
  1063. -e 's/k/K/' \
  1064. >> ${OUT}
  1065. # The bpf_program struct.
  1066. grep '^type _bpf_program ' gen-sysinfo.go | \
  1067. sed -e 's/_bpf_program/BpfProgram/g' \
  1068. -e 's/bf_len/Len/' \
  1069. -e 's/bf_insns/Insns/' \
  1070. -e 's/_bpf_insn/BpfInsn/' \
  1071. >> ${OUT}
  1072. # The BPF ioctl constants.
  1073. grep '^const _BIOC' gen-sysinfo.go | \
  1074. grep -v '_val =' | \
  1075. sed -e 's/^\(const \)_\(BIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1076. for c in BIOCFLUSH BIOCGBLEN BIOCGDLT BIOCGETIF BIOCGHDRCMPLT BIOCGRTIMEOUT \
  1077. BIOCGSTATS BIOCIMMEDIATE BIOCPROMISC BIOCSBLEN BIOCSDLT BIOCSETF \
  1078. BIOCSETIF BIOCSHDRCMPLT BIOCSRTIMEOUT BIOCVERSION
  1079. do
  1080. if ! grep "^const ${c}" ${OUT} >/dev/null 2>&1; then
  1081. if grep "^const _${c}_val" ${OUT} >/dev/null 2>&1; then
  1082. echo "const ${c} = _${c}_val" >> ${OUT}
  1083. fi
  1084. fi
  1085. done
  1086. # The in_pktinfo struct.
  1087. grep '^type _in_pktinfo ' gen-sysinfo.go | \
  1088. sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
  1089. -e 's/ipi_ifindex/Ifindex/' \
  1090. -e 's/ipi_spec_dst/Spec_dst/' \
  1091. -e 's/ipi_addr/Addr/' \
  1092. -e 's/_in_addr/[4]byte/g' \
  1093. >> ${OUT}
  1094. # The in6_pktinfo struct.
  1095. grep '^type _in6_pktinfo ' gen-sysinfo.go | \
  1096. sed -e 's/_in6_pktinfo/Inet6Pktinfo/' \
  1097. -e 's/ipi6_addr/Addr/' \
  1098. -e 's/ipi6_ifindex/Ifindex/' \
  1099. -e 's/_in6_addr/[16]byte/' \
  1100. >> ${OUT}
  1101. # The termios struct.
  1102. grep '^type _termios ' gen-sysinfo.go | \
  1103. sed -e 's/_termios/Termios/' \
  1104. -e 's/c_iflag/Iflag/' \
  1105. -e 's/c_oflag/Oflag/' \
  1106. -e 's/c_cflag/Cflag/' \
  1107. -e 's/c_lflag/Lflag/' \
  1108. -e 's/c_line/Line/' \
  1109. -e 's/c_cc/Cc/' \
  1110. -e 's/c_ispeed/Ispeed/' \
  1111. -e 's/c_ospeed/Ospeed/' \
  1112. >> ${OUT}
  1113. # The termios constants.
  1114. for n in IGNBRK BRKINT IGNPAR PARMRK INPCK ISTRIP INLCR IGNCR ICRNL IUCLC \
  1115. IXON IXANY IXOFF IMAXBEL IUTF8 OPOST OLCUC ONLCR OCRNL ONOCR ONLRET \
  1116. OFILL OFDEL NLDLY NL0 NL1 CRDLY CR0 CR1 CR2 CR3 CS5 CS6 CS7 CS8 TABDLY \
  1117. BSDLY VTDLY FFDLY CBAUD CBAUDEX CSIZE CSTOPB CREAD PARENB PARODD HUPCL \
  1118. CLOCAL LOBLK CIBAUD CMSPAR CRTSCTS ISIG ICANON XCASE ECHO ECHOE ECHOK \
  1119. ECHONL ECHOCTL ECHOPRT ECHOKE DEFECHO FLUSHO NOFLSH TOSTOP PENDIN IEXTEN \
  1120. VINTR VQUIT VERASE VKILL VEOF VMIN VEOL VTIME VEOL2 VSWTCH VSTART VSTOP \
  1121. VSUSP VDSUSP VLNEXT VWERASE VREPRINT VDISCARD VSTATUS TCSANOW TCSADRAIN \
  1122. TCSAFLUSH TCIFLUSH TCOFLUSH TCIOFLUSH TCOOFF TCOON TCIOFF TCION B0 B50 \
  1123. B75 B110 B134 B150 B200 B300 B600 B1200 B1800 B2400 B4800 B9600 B19200 \
  1124. B38400 B57600 B115200 B230400 B460800 B500000 B576000 B921600 B1000000 \
  1125. B1152000 B1500000 B2000000 B2500000 B3000000 B3500000 B4000000; do
  1126. grep "^const _$n " gen-sysinfo.go | \
  1127. sed -e 's/^\(const \)_\([^=]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1128. done
  1129. # The mount flags
  1130. grep '^const _MNT_' gen-sysinfo.go |
  1131. sed -e 's/^\(const \)_\(MNT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1132. grep '^const _MS_' gen-sysinfo.go |
  1133. sed -e 's/^\(const \)_\(MS_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1134. # The fallocate flags.
  1135. grep '^const _FALLOC_' gen-sysinfo.go |
  1136. sed -e 's/^\(const \)_\(FALLOC_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1137. # The statfs struct.
  1138. # Prefer largefile variant if available.
  1139. # CentOS 5 does not have f_flags, so pull from f_spare.
  1140. statfs=`grep '^type _statfs64 ' gen-sysinfo.go || true`
  1141. if test "$statfs" = ""; then
  1142. statfs=`grep '^type _statfs ' gen-sysinfo.go || true`
  1143. fi
  1144. if ! echo "$statfs" | grep f_flags >/dev/null 2>&1; then
  1145. statfs=`echo "$statfs" | sed -e 's/f_spare \[4+1\]\([^ ;]*\)/f_flags \1; f_spare [3+1]\1/'`
  1146. fi
  1147. echo "$statfs" | sed -e 's/type _statfs64/type Statfs_t/' \
  1148. -e 's/type _statfs/type Statfs_t/' \
  1149. -e 's/f_type/Type/' \
  1150. -e 's/f_bsize/Bsize/' \
  1151. -e 's/f_blocks/Blocks/' \
  1152. -e 's/f_bfree/Bfree/' \
  1153. -e 's/f_bavail/Bavail/' \
  1154. -e 's/f_files/Files/' \
  1155. -e 's/f_ffree/Ffree/' \
  1156. -e 's/f_fsid/Fsid/' \
  1157. -e 's/f_namelen/Namelen/' \
  1158. -e 's/f_frsize/Frsize/' \
  1159. -e 's/f_flags/Flags/' \
  1160. -e 's/f_spare/Spare/' \
  1161. >> ${OUT}
  1162. # The timex struct.
  1163. timex=`grep '^type _timex ' gen-sysinfo.go || true`
  1164. if test "$timex" = ""; then
  1165. timex=`grep '^// type _timex ' gen-sysinfo.go || true`
  1166. if test "$timex" != ""; then
  1167. timex=`echo $timex | sed -e 's|// ||' -e 's/INVALID-bit-field/int32/g'`
  1168. fi
  1169. fi
  1170. if test "$timex" != ""; then
  1171. echo "$timex" | \
  1172. sed -e 's/_timex/Timex/' \
  1173. -e 's/modes/Modes/' \
  1174. -e 's/offset/Offset/' \
  1175. -e 's/freq/Freq/' \
  1176. -e 's/maxerror/Maxerror/' \
  1177. -e 's/esterror/Esterror/' \
  1178. -e 's/status/Status/' \
  1179. -e 's/constant/Constant/' \
  1180. -e 's/precision/Precision/' \
  1181. -e 's/tolerance/Tolerance/' \
  1182. -e 's/ time / Time /' \
  1183. -e 's/tick/Tick/' \
  1184. -e 's/ppsfreq/Ppsfreq/' \
  1185. -e 's/jitter/Jitter/' \
  1186. -e 's/shift/Shift/' \
  1187. -e 's/stabil/Stabil/' \
  1188. -e 's/jitcnt/Jitcnt/' \
  1189. -e 's/calcnt/Calcnt/' \
  1190. -e 's/errcnt/Errcnt/' \
  1191. -e 's/stbcnt/Stbcnt/' \
  1192. -e 's/tai/Tai/' \
  1193. -e 's/_timeval/Timeval/' \
  1194. >> ${OUT}
  1195. fi
  1196. # The rlimit struct.
  1197. # On systems that use syscall/libcall_posix_largefile.go, use rlimit64
  1198. # if it exists.
  1199. rlimit="_rlimit"
  1200. if test "${GOOS}" = "aix" || test "${GOOS}" = "linux" || (test "${GOOS}" = "solaris" && (test "${GOARCH}" = "386" || test "${GOARCH}" = "sparc")); then
  1201. if grep '^type _rlimit64 ' gen-sysinfo.go > /dev/null 2>&1; then
  1202. rlimit="_rlimit64"
  1203. fi
  1204. fi
  1205. grep "^type ${rlimit} " gen-sysinfo.go | \
  1206. sed -e "s/${rlimit}/Rlimit/" \
  1207. -e 's/rlim_cur/Cur/' \
  1208. -e 's/rlim_max/Max/' \
  1209. >> ${OUT}
  1210. # The RLIMIT constants.
  1211. grep '^const _RLIMIT_' gen-sysinfo.go |
  1212. sed -e 's/^\(const \)_\(RLIMIT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1213. grep '^const _RLIM_' gen-sysinfo.go |
  1214. grep -v '^const _RLIM_INFINITY ' |
  1215. sed -e 's/^\(const \)_\(RLIM_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1216. rliminf=""
  1217. if test "${rlimit}" = "_rlimit64" && grep '^const _RLIM64_INFINITY ' gen-sysinfo.go > /dev/null 2>&1; then
  1218. rliminf=`grep '^const _RLIM64_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
  1219. else
  1220. rliminf=`grep '^const _RLIM_INFINITY ' gen-sysinfo.go | sed -e 's/.* //'`
  1221. fi
  1222. # For compatibility with the gc syscall package, treat 0xffffffffffffffff as -1.
  1223. if test "$rliminf" = "0xffffffffffffffff"; then
  1224. echo "const RLIM_INFINITY = -1" >> ${OUT}
  1225. elif test -n "$rliminf"; then
  1226. echo "const RLIM_INFINITY = $rliminf" >> ${OUT}
  1227. fi
  1228. # The sysinfo struct.
  1229. grep '^type _sysinfo ' gen-sysinfo.go | \
  1230. sed -e 's/_sysinfo/Sysinfo_t/' \
  1231. -e 's/uptime/Uptime/' \
  1232. -e 's/loads/Loads/' \
  1233. -e 's/totalram/Totalram/' \
  1234. -e 's/freeram/Freeram/' \
  1235. -e 's/sharedram/Sharedram/' \
  1236. -e 's/bufferram/Bufferram/' \
  1237. -e 's/totalswap/Totalswap/' \
  1238. -e 's/freeswap/Freeswap/' \
  1239. -e 's/procs/Procs/' \
  1240. -e 's/totalhigh/Totalhigh/' \
  1241. -e 's/freehigh/Freehigh/' \
  1242. -e 's/mem_unit/Unit/' \
  1243. >> ${OUT}
  1244. # The utimbuf struct.
  1245. grep '^type _utimbuf ' gen-sysinfo.go | \
  1246. sed -e 's/_utimbuf/Utimbuf/' \
  1247. -e 's/actime/Actime/' \
  1248. -e 's/modtime/Modtime/' \
  1249. >> ${OUT}
  1250. # The LOCK flags for flock.
  1251. grep '^const _LOCK_' gen-sysinfo.go |
  1252. sed -e 's/^\(const \)_\(LOCK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1253. # The PRIO constants.
  1254. grep '^const _PRIO_' gen-sysinfo.go | \
  1255. sed -e 's/^\(const \)_\(PRIO_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1256. # The GNU/Linux LINUX_REBOOT flags.
  1257. grep '^const _LINUX_REBOOT_' gen-sysinfo.go |
  1258. sed -e 's/^\(const \)_\(LINUX_REBOOT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1259. # The GNU/Linux sock_filter struct.
  1260. grep '^type _sock_filter ' gen-sysinfo.go | \
  1261. sed -e 's/_sock_filter/SockFilter/' \
  1262. -e 's/code/Code/' \
  1263. -e 's/jt/Jt/' \
  1264. -e 's/jf/Jf/' \
  1265. -e 's/k /K /' \
  1266. >> ${OUT}
  1267. # The GNU/Linux sock_fprog struct.
  1268. grep '^type _sock_fprog ' gen-sysinfo.go | \
  1269. sed -e 's/_sock_fprog/SockFprog/' \
  1270. -e 's/len/Len/' \
  1271. -e 's/filter/Filter/' \
  1272. -e 's/_sock_filter/SockFilter/' \
  1273. >> ${OUT}
  1274. # The GNU/Linux filter flags.
  1275. grep '^const _BPF_' gen-sysinfo.go | \
  1276. sed -e 's/^\(const \)_\(BPF_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1277. # The GNU/Linux nlattr struct.
  1278. grep '^type _nlattr ' gen-sysinfo.go | \
  1279. sed -e 's/_nlattr/NlAttr/' \
  1280. -e 's/nla_len/Len/' \
  1281. -e 's/nla_type/Type/' \
  1282. >> ${OUT}
  1283. # The GNU/Linux nlmsgerr struct.
  1284. grep '^type _nlmsgerr ' gen-sysinfo.go | \
  1285. sed -e 's/_nlmsgerr/NlMsgerr/' \
  1286. -e 's/error/Error/' \
  1287. -e 's/msg/Msg/' \
  1288. -e 's/_nlmsghdr/NlMsghdr/' \
  1289. >> ${OUT}
  1290. # The GNU/Linux rtnexthop struct.
  1291. grep '^type _rtnexthop ' gen-sysinfo.go | \
  1292. sed -e 's/_rtnexthop/RtNexthop/' \
  1293. -e 's/rtnh_len/Len/' \
  1294. -e 's/rtnh_flags/Flags/' \
  1295. -e 's/rtnh_hops/Hops/' \
  1296. -e 's/rtnh_ifindex/Ifindex/' \
  1297. >> ${OUT}
  1298. # The GNU/Linux netlink flags.
  1299. grep '^const _NETLINK_' gen-sysinfo.go | \
  1300. sed -e 's/^\(const \)_\(NETLINK_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1301. grep '^const _NLA_' gen-sysinfo.go | grep -v '_val =' | \
  1302. sed -e 's/^\(const \)_\(NLA_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1303. if ! grep '^const NLA_HDRLEN' ${OUT} >/dev/null 2>&1; then
  1304. if grep '^const _NLA_HDRLEN_val' ${OUT} >/dev/null 2>&1; then
  1305. echo 'const NLA_HDRLEN = _NLA_HDRLEN_val' >> ${OUT}
  1306. fi
  1307. fi
  1308. # The GNU/Linux packet socket flags.
  1309. grep '^const _PACKET_' gen-sysinfo.go | \
  1310. sed -e 's/^\(const \)_\(PACKET_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1311. # The GNU/Linux inotify_event struct.
  1312. grep '^type _inotify_event ' gen-sysinfo.go | \
  1313. sed -e 's/_inotify_event/InotifyEvent/' \
  1314. -e 's/wd/Wd/' \
  1315. -e 's/mask/Mask/' \
  1316. -e 's/cookie/Cookie/' \
  1317. -e 's/len/Len/' \
  1318. -e 's/name/Name/' \
  1319. -e 's/\[\]/[0]/' \
  1320. -e 's/\[0\]byte/[0]int8/' \
  1321. >> ${OUT}
  1322. # The GNU/Linux CLONE flags.
  1323. grep '^const _CLONE_' gen-sysinfo.go | \
  1324. sed -e 's/^\(const \)_\(CLONE_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
  1325. # We need some CLONE constants that are not defined in older versions
  1326. # of glibc.
  1327. if ! grep '^const CLONE_NEWUSER ' ${OUT} > /dev/null 2>&1; then
  1328. echo "const CLONE_NEWUSER = 0x10000000" >> ${OUT}
  1329. fi
  1330. if ! grep '^const CLONE_NEWNET ' ${OUT} > /dev/null 2>&1; then
  1331. echo "const CLONE_NEWNET = 0x40000000" >> ${OUT}
  1332. fi
  1333. # Struct sizes.
  1334. set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
  1335. ifaddrmsg IfAddrmsg ifa_msghdr IfaMsghdr ifinfomsg IfInfomsg \
  1336. if_msghdr IfMsghdr in_pktinfo Inet4Pktinfo in6_pktinfo Inet6Pktinfo \
  1337. inotify_event InotifyEvent linger Linger msghdr Msghdr nlattr NlAttr \
  1338. nlmsgerr NlMsgerr nlmsghdr NlMsghdr rtattr RtAttr rt_msghdr RtMsghdr \
  1339. rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
  1340. sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
  1341. icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
  1342. while test $# != 0; do
  1343. nc=$1
  1344. ngo=$2
  1345. shift
  1346. shift
  1347. if grep "^const _sizeof_$nc =" gen-sysinfo.go >/dev/null 2>&1; then
  1348. echo "const Sizeof$ngo = _sizeof_$nc" >> ${OUT}
  1349. fi
  1350. done
  1351. # In order to compile the net package, we need some sizes to exist
  1352. # even if the types do not.
  1353. if ! grep 'const SizeofIPMreq ' ${OUT} >/dev/null 2>&1; then
  1354. echo 'const SizeofIPMreq = 8' >> ${OUT}
  1355. fi
  1356. if ! grep 'const SizeofIPv6Mreq ' ${OUT} >/dev/null 2>&1; then
  1357. echo 'const SizeofIPv6Mreq = 20' >> ${OUT}
  1358. fi
  1359. if ! grep 'const SizeofIPMreqn ' ${OUT} >/dev/null 2>&1; then
  1360. echo 'const SizeofIPMreqn = 12' >> ${OUT}
  1361. fi
  1362. if ! grep 'const SizeofICMPv6Filter ' ${OUT} >/dev/null 2>&1; then
  1363. echo 'const SizeofICMPv6Filter = 32' >> ${OUT}
  1364. fi
  1365. # Type 'uint128' is needed in a couple of type definitions on arm64,such
  1366. # as _user_fpsimd_struct, _elf_fpregset_t, etc.
  1367. if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then
  1368. echo "type uint128 [16]byte" >> ${OUT}
  1369. fi
  1370. exit $?