Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 1 | // Copyright 2009 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 5 | // +build ignore |
| 6 | |
Russ Cox | 8fe75a2 | 2012-02-02 19:42:02 -0500 | [diff] [blame] | 7 | /* |
| 8 | Input to cgo -godefs. See also mkerrors.sh and mkall.sh |
| 9 | */ |
| 10 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 11 | // +godefs map struct_in_addr [4]byte /* in_addr */ |
| 12 | // +godefs map struct_in6_addr [16]byte /* in6_addr */ |
| 13 | |
| 14 | package syscall |
| 15 | |
| 16 | /* |
| 17 | #define _LARGEFILE_SOURCE |
| 18 | #define _LARGEFILE64_SOURCE |
| 19 | #define _FILE_OFFSET_BITS 64 |
| 20 | #define _GNU_SOURCE |
| 21 | |
| 22 | #include <dirent.h> |
| 23 | #include <fcntl.h> |
| 24 | #include <netinet/in.h> |
| 25 | #include <netinet/tcp.h> |
| 26 | #include <netpacket/packet.h> |
| 27 | #include <signal.h> |
| 28 | #include <stdio.h> |
| 29 | #include <sys/epoll.h> |
| 30 | #include <sys/inotify.h> |
| 31 | #include <sys/mman.h> |
| 32 | #include <sys/mount.h> |
| 33 | #include <sys/param.h> |
| 34 | #include <sys/ptrace.h> |
| 35 | #include <sys/resource.h> |
| 36 | #include <sys/select.h> |
| 37 | #include <sys/signal.h> |
| 38 | #include <sys/stat.h> |
| 39 | #include <sys/statfs.h> |
| 40 | #include <sys/sysinfo.h> |
| 41 | #include <sys/time.h> |
| 42 | #include <sys/times.h> |
| 43 | #include <sys/timex.h> |
| 44 | #include <sys/types.h> |
| 45 | #include <sys/un.h> |
| 46 | #include <sys/user.h> |
| 47 | #include <sys/utsname.h> |
| 48 | #include <sys/wait.h> |
| 49 | #include <linux/filter.h> |
| 50 | #include <linux/netlink.h> |
| 51 | #include <linux/rtnetlink.h> |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 52 | #include <linux/icmpv6.h> |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 53 | #include <termios.h> |
| 54 | #include <time.h> |
| 55 | #include <unistd.h> |
| 56 | #include <ustat.h> |
| 57 | #include <utime.h> |
| 58 | |
| 59 | enum { |
| 60 | sizeofPtr = sizeof(void*), |
| 61 | }; |
| 62 | |
| 63 | union sockaddr_all { |
| 64 | struct sockaddr s1; // this one gets used for fields |
| 65 | struct sockaddr_in s2; // these pad it out |
| 66 | struct sockaddr_in6 s3; |
| 67 | struct sockaddr_un s4; |
| 68 | struct sockaddr_ll s5; |
| 69 | struct sockaddr_nl s6; |
| 70 | }; |
| 71 | |
| 72 | struct sockaddr_any { |
| 73 | struct sockaddr addr; |
| 74 | char pad[sizeof(union sockaddr_all) - sizeof(struct sockaddr)]; |
| 75 | }; |
| 76 | |
Robert Griesemer | 465b9c3 | 2012-10-30 13:38:01 -0700 | [diff] [blame] | 77 | // copied from /usr/include/linux/un.h |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 78 | struct my_sockaddr_un { |
| 79 | sa_family_t sun_family; |
Shenghou Ma | 7776b0a | 2014-08-14 12:01:21 -0400 | [diff] [blame] | 80 | #if defined(__ARM_EABI__) || defined(__powerpc64__) |
| 81 | // on ARM and PPC char is by default unsigned |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 82 | signed char sun_path[108]; |
| 83 | #else |
| 84 | char sun_path[108]; |
| 85 | #endif |
| 86 | }; |
| 87 | |
| 88 | #ifdef __ARM_EABI__ |
| 89 | typedef struct user_regs PtraceRegs; |
Aram Hăvărneanu | d0d9310 | 2015-03-08 14:21:00 +0100 | [diff] [blame] | 90 | #elif defined(__aarch64__) |
| 91 | typedef struct user_pt_regs PtraceRegs; |
Shenghou Ma | 7776b0a | 2014-08-14 12:01:21 -0400 | [diff] [blame] | 92 | #elif defined(__powerpc64__) |
| 93 | typedef struct pt_regs PtraceRegs; |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 94 | #else |
| 95 | typedef struct user_regs_struct PtraceRegs; |
| 96 | #endif |
| 97 | |
| 98 | // The real epoll_event is a union, and godefs doesn't handle it well. |
| 99 | struct my_epoll_event { |
| 100 | uint32_t events; |
| 101 | #ifdef __ARM_EABI__ |
| 102 | // padding is not specified in linux/eventpoll.h but added to conform to the |
| 103 | // alignment requirements of EABI |
| 104 | int32_t padFd; |
| 105 | #endif |
| 106 | int32_t fd; |
| 107 | int32_t pad; |
| 108 | }; |
| 109 | |
| 110 | */ |
| 111 | import "C" |
| 112 | |
| 113 | // Machine characteristics; for internal use. |
| 114 | |
| 115 | const ( |
| 116 | sizeofPtr = C.sizeofPtr |
| 117 | sizeofShort = C.sizeof_short |
| 118 | sizeofInt = C.sizeof_int |
| 119 | sizeofLong = C.sizeof_long |
| 120 | sizeofLongLong = C.sizeof_longlong |
| 121 | PathMax = C.PATH_MAX |
| 122 | ) |
| 123 | |
| 124 | // Basic types |
| 125 | |
| 126 | type ( |
| 127 | _C_short C.short |
| 128 | _C_int C.int |
| 129 | _C_long C.long |
| 130 | _C_long_long C.longlong |
| 131 | ) |
| 132 | |
| 133 | // Time |
| 134 | |
| 135 | type Timespec C.struct_timespec |
| 136 | |
| 137 | type Timeval C.struct_timeval |
| 138 | |
| 139 | type Timex C.struct_timex |
| 140 | |
| 141 | type Time_t C.time_t |
| 142 | |
| 143 | type Tms C.struct_tms |
| 144 | |
| 145 | type Utimbuf C.struct_utimbuf |
| 146 | |
| 147 | // Processes |
| 148 | |
| 149 | type Rusage C.struct_rusage |
| 150 | |
| 151 | type Rlimit C.struct_rlimit |
| 152 | |
| 153 | type _Gid_t C.gid_t |
| 154 | |
| 155 | // Files |
| 156 | |
| 157 | type Stat_t C.struct_stat |
| 158 | |
| 159 | type Statfs_t C.struct_statfs |
| 160 | |
| 161 | type Dirent C.struct_dirent |
| 162 | |
| 163 | type Fsid C.fsid_t |
| 164 | |
Brad Fitzpatrick | 055b588 | 2014-01-16 14:08:32 -0800 | [diff] [blame] | 165 | type Flock_t C.struct_flock |
| 166 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 167 | // Sockets |
| 168 | |
| 169 | type RawSockaddrInet4 C.struct_sockaddr_in |
| 170 | |
| 171 | type RawSockaddrInet6 C.struct_sockaddr_in6 |
| 172 | |
| 173 | type RawSockaddrUnix C.struct_my_sockaddr_un |
| 174 | |
| 175 | type RawSockaddrLinklayer C.struct_sockaddr_ll |
| 176 | |
| 177 | type RawSockaddrNetlink C.struct_sockaddr_nl |
| 178 | |
| 179 | type RawSockaddr C.struct_sockaddr |
| 180 | |
| 181 | type RawSockaddrAny C.struct_sockaddr_any |
| 182 | |
| 183 | type _Socklen C.socklen_t |
| 184 | |
| 185 | type Linger C.struct_linger |
| 186 | |
| 187 | type Iovec C.struct_iovec |
| 188 | |
| 189 | type IPMreq C.struct_ip_mreq |
| 190 | |
| 191 | type IPMreqn C.struct_ip_mreqn |
| 192 | |
| 193 | type IPv6Mreq C.struct_ipv6_mreq |
| 194 | |
| 195 | type Msghdr C.struct_msghdr |
| 196 | |
| 197 | type Cmsghdr C.struct_cmsghdr |
| 198 | |
| 199 | type Inet4Pktinfo C.struct_in_pktinfo |
| 200 | |
| 201 | type Inet6Pktinfo C.struct_in6_pktinfo |
| 202 | |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 203 | type IPv6MTUInfo C.struct_ip6_mtuinfo |
| 204 | |
| 205 | type ICMPv6Filter C.struct_icmp6_filter |
| 206 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 207 | type Ucred C.struct_ucred |
| 208 | |
Brad Fitzpatrick | bef036e | 2012-12-10 11:32:07 -0500 | [diff] [blame] | 209 | type TCPInfo C.struct_tcp_info |
| 210 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 211 | const ( |
| 212 | SizeofSockaddrInet4 = C.sizeof_struct_sockaddr_in |
| 213 | SizeofSockaddrInet6 = C.sizeof_struct_sockaddr_in6 |
| 214 | SizeofSockaddrAny = C.sizeof_struct_sockaddr_any |
| 215 | SizeofSockaddrUnix = C.sizeof_struct_sockaddr_un |
| 216 | SizeofSockaddrLinklayer = C.sizeof_struct_sockaddr_ll |
| 217 | SizeofSockaddrNetlink = C.sizeof_struct_sockaddr_nl |
| 218 | SizeofLinger = C.sizeof_struct_linger |
| 219 | SizeofIPMreq = C.sizeof_struct_ip_mreq |
| 220 | SizeofIPMreqn = C.sizeof_struct_ip_mreqn |
| 221 | SizeofIPv6Mreq = C.sizeof_struct_ipv6_mreq |
| 222 | SizeofMsghdr = C.sizeof_struct_msghdr |
| 223 | SizeofCmsghdr = C.sizeof_struct_cmsghdr |
| 224 | SizeofInet4Pktinfo = C.sizeof_struct_in_pktinfo |
| 225 | SizeofInet6Pktinfo = C.sizeof_struct_in6_pktinfo |
Mikio Hara | adbe59e | 2013-05-23 16:22:05 +0900 | [diff] [blame] | 226 | SizeofIPv6MTUInfo = C.sizeof_struct_ip6_mtuinfo |
| 227 | SizeofICMPv6Filter = C.sizeof_struct_icmp6_filter |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 228 | SizeofUcred = C.sizeof_struct_ucred |
Brad Fitzpatrick | bef036e | 2012-12-10 11:32:07 -0500 | [diff] [blame] | 229 | SizeofTCPInfo = C.sizeof_struct_tcp_info |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 230 | ) |
| 231 | |
| 232 | // Netlink routing and interface messages |
| 233 | |
| 234 | const ( |
Mikio Hara | e822860 | 2013-02-23 08:42:04 +0900 | [diff] [blame] | 235 | IFA_UNSPEC = C.IFA_UNSPEC |
| 236 | IFA_ADDRESS = C.IFA_ADDRESS |
| 237 | IFA_LOCAL = C.IFA_LOCAL |
| 238 | IFA_LABEL = C.IFA_LABEL |
| 239 | IFA_BROADCAST = C.IFA_BROADCAST |
| 240 | IFA_ANYCAST = C.IFA_ANYCAST |
| 241 | IFA_CACHEINFO = C.IFA_CACHEINFO |
| 242 | IFA_MULTICAST = C.IFA_MULTICAST |
| 243 | IFLA_UNSPEC = C.IFLA_UNSPEC |
| 244 | IFLA_ADDRESS = C.IFLA_ADDRESS |
| 245 | IFLA_BROADCAST = C.IFLA_BROADCAST |
| 246 | IFLA_IFNAME = C.IFLA_IFNAME |
| 247 | IFLA_MTU = C.IFLA_MTU |
| 248 | IFLA_LINK = C.IFLA_LINK |
| 249 | IFLA_QDISC = C.IFLA_QDISC |
| 250 | IFLA_STATS = C.IFLA_STATS |
| 251 | IFLA_COST = C.IFLA_COST |
| 252 | IFLA_PRIORITY = C.IFLA_PRIORITY |
| 253 | IFLA_MASTER = C.IFLA_MASTER |
| 254 | IFLA_WIRELESS = C.IFLA_WIRELESS |
| 255 | IFLA_PROTINFO = C.IFLA_PROTINFO |
| 256 | IFLA_TXQLEN = C.IFLA_TXQLEN |
| 257 | IFLA_MAP = C.IFLA_MAP |
| 258 | IFLA_WEIGHT = C.IFLA_WEIGHT |
| 259 | IFLA_OPERSTATE = C.IFLA_OPERSTATE |
| 260 | IFLA_LINKMODE = C.IFLA_LINKMODE |
| 261 | IFLA_LINKINFO = C.IFLA_LINKINFO |
| 262 | IFLA_NET_NS_PID = C.IFLA_NET_NS_PID |
| 263 | IFLA_IFALIAS = C.IFLA_IFALIAS |
| 264 | IFLA_MAX = C.IFLA_MAX |
| 265 | RT_SCOPE_UNIVERSE = C.RT_SCOPE_UNIVERSE |
| 266 | RT_SCOPE_SITE = C.RT_SCOPE_SITE |
| 267 | RT_SCOPE_LINK = C.RT_SCOPE_LINK |
| 268 | RT_SCOPE_HOST = C.RT_SCOPE_HOST |
| 269 | RT_SCOPE_NOWHERE = C.RT_SCOPE_NOWHERE |
| 270 | RT_TABLE_UNSPEC = C.RT_TABLE_UNSPEC |
| 271 | RT_TABLE_COMPAT = C.RT_TABLE_COMPAT |
| 272 | RT_TABLE_DEFAULT = C.RT_TABLE_DEFAULT |
| 273 | RT_TABLE_MAIN = C.RT_TABLE_MAIN |
| 274 | RT_TABLE_LOCAL = C.RT_TABLE_LOCAL |
| 275 | RT_TABLE_MAX = C.RT_TABLE_MAX |
| 276 | RTA_UNSPEC = C.RTA_UNSPEC |
| 277 | RTA_DST = C.RTA_DST |
| 278 | RTA_SRC = C.RTA_SRC |
| 279 | RTA_IIF = C.RTA_IIF |
| 280 | RTA_OIF = C.RTA_OIF |
| 281 | RTA_GATEWAY = C.RTA_GATEWAY |
| 282 | RTA_PRIORITY = C.RTA_PRIORITY |
| 283 | RTA_PREFSRC = C.RTA_PREFSRC |
| 284 | RTA_METRICS = C.RTA_METRICS |
| 285 | RTA_MULTIPATH = C.RTA_MULTIPATH |
| 286 | RTA_FLOW = C.RTA_FLOW |
| 287 | RTA_CACHEINFO = C.RTA_CACHEINFO |
| 288 | RTA_TABLE = C.RTA_TABLE |
| 289 | RTN_UNSPEC = C.RTN_UNSPEC |
| 290 | RTN_UNICAST = C.RTN_UNICAST |
| 291 | RTN_LOCAL = C.RTN_LOCAL |
| 292 | RTN_BROADCAST = C.RTN_BROADCAST |
| 293 | RTN_ANYCAST = C.RTN_ANYCAST |
| 294 | RTN_MULTICAST = C.RTN_MULTICAST |
| 295 | RTN_BLACKHOLE = C.RTN_BLACKHOLE |
| 296 | RTN_UNREACHABLE = C.RTN_UNREACHABLE |
| 297 | RTN_PROHIBIT = C.RTN_PROHIBIT |
| 298 | RTN_THROW = C.RTN_THROW |
| 299 | RTN_NAT = C.RTN_NAT |
| 300 | RTN_XRESOLVE = C.RTN_XRESOLVE |
| 301 | RTNLGRP_NONE = C.RTNLGRP_NONE |
| 302 | RTNLGRP_LINK = C.RTNLGRP_LINK |
| 303 | RTNLGRP_NOTIFY = C.RTNLGRP_NOTIFY |
| 304 | RTNLGRP_NEIGH = C.RTNLGRP_NEIGH |
| 305 | RTNLGRP_TC = C.RTNLGRP_TC |
| 306 | RTNLGRP_IPV4_IFADDR = C.RTNLGRP_IPV4_IFADDR |
| 307 | RTNLGRP_IPV4_MROUTE = C.RTNLGRP_IPV4_MROUTE |
| 308 | RTNLGRP_IPV4_ROUTE = C.RTNLGRP_IPV4_ROUTE |
| 309 | RTNLGRP_IPV4_RULE = C.RTNLGRP_IPV4_RULE |
| 310 | RTNLGRP_IPV6_IFADDR = C.RTNLGRP_IPV6_IFADDR |
| 311 | RTNLGRP_IPV6_MROUTE = C.RTNLGRP_IPV6_MROUTE |
| 312 | RTNLGRP_IPV6_ROUTE = C.RTNLGRP_IPV6_ROUTE |
| 313 | RTNLGRP_IPV6_IFINFO = C.RTNLGRP_IPV6_IFINFO |
| 314 | RTNLGRP_IPV6_PREFIX = C.RTNLGRP_IPV6_PREFIX |
| 315 | RTNLGRP_IPV6_RULE = C.RTNLGRP_IPV6_RULE |
| 316 | RTNLGRP_ND_USEROPT = C.RTNLGRP_ND_USEROPT |
| 317 | SizeofNlMsghdr = C.sizeof_struct_nlmsghdr |
| 318 | SizeofNlMsgerr = C.sizeof_struct_nlmsgerr |
| 319 | SizeofRtGenmsg = C.sizeof_struct_rtgenmsg |
| 320 | SizeofNlAttr = C.sizeof_struct_nlattr |
| 321 | SizeofRtAttr = C.sizeof_struct_rtattr |
| 322 | SizeofIfInfomsg = C.sizeof_struct_ifinfomsg |
| 323 | SizeofIfAddrmsg = C.sizeof_struct_ifaddrmsg |
| 324 | SizeofRtMsg = C.sizeof_struct_rtmsg |
| 325 | SizeofRtNexthop = C.sizeof_struct_rtnexthop |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 326 | ) |
| 327 | |
| 328 | type NlMsghdr C.struct_nlmsghdr |
| 329 | |
| 330 | type NlMsgerr C.struct_nlmsgerr |
| 331 | |
| 332 | type RtGenmsg C.struct_rtgenmsg |
| 333 | |
| 334 | type NlAttr C.struct_nlattr |
| 335 | |
| 336 | type RtAttr C.struct_rtattr |
| 337 | |
| 338 | type IfInfomsg C.struct_ifinfomsg |
| 339 | |
| 340 | type IfAddrmsg C.struct_ifaddrmsg |
| 341 | |
| 342 | type RtMsg C.struct_rtmsg |
| 343 | |
| 344 | type RtNexthop C.struct_rtnexthop |
| 345 | |
| 346 | // Linux socket filter |
| 347 | |
| 348 | const ( |
| 349 | SizeofSockFilter = C.sizeof_struct_sock_filter |
| 350 | SizeofSockFprog = C.sizeof_struct_sock_fprog |
| 351 | ) |
| 352 | |
| 353 | type SockFilter C.struct_sock_filter |
| 354 | |
| 355 | type SockFprog C.struct_sock_fprog |
| 356 | |
| 357 | // Inotify |
| 358 | |
| 359 | type InotifyEvent C.struct_inotify_event |
| 360 | |
| 361 | const SizeofInotifyEvent = C.sizeof_struct_inotify_event |
| 362 | |
| 363 | // Ptrace |
| 364 | |
| 365 | // Register structures |
| 366 | type PtraceRegs C.PtraceRegs |
| 367 | |
| 368 | // Misc |
| 369 | |
| 370 | type FdSet C.fd_set |
| 371 | |
| 372 | type Sysinfo_t C.struct_sysinfo |
| 373 | |
| 374 | type Utsname C.struct_utsname |
| 375 | |
| 376 | type Ustat_t C.struct_ustat |
| 377 | |
| 378 | type EpollEvent C.struct_my_epoll_event |
| 379 | |
Nick Craig-Wood | 473441f | 2012-12-13 13:02:39 -0800 | [diff] [blame] | 380 | const ( |
Dave Cheney | c123a80 | 2015-02-25 12:56:44 +1100 | [diff] [blame] | 381 | _AT_FDCWD = C.AT_FDCWD |
| 382 | _AT_REMOVEDIR = C.AT_REMOVEDIR |
| 383 | _AT_SYMLINK_NOFOLLOW = C.AT_SYMLINK_NOFOLLOW |
Nick Craig-Wood | 473441f | 2012-12-13 13:02:39 -0800 | [diff] [blame] | 384 | ) |
| 385 | |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 386 | // Terminal handling |
| 387 | |
| 388 | type Termios C.struct_termios |
| 389 | |
| 390 | const ( |
Shenghou Ma | 5cb7da7 | 2014-08-11 23:43:15 -0400 | [diff] [blame] | 391 | IUCLC = C.IUCLC |
| 392 | OLCUC = C.OLCUC |
| 393 | TCGETS = C.TCGETS |
| 394 | TCSETS = C.TCSETS |
| 395 | XCASE = C.XCASE |
Russ Cox | dd2abe5 | 2011-11-10 19:08:28 -0500 | [diff] [blame] | 396 | ) |