| 1 |
#!/usr/bin/env bash |
| 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 |
|
| 6 |
# Generate Go code listing errors and other #defined constant |
| 7 |
# values (ENAMETOOLONG etc.), by asking the preprocessor |
| 8 |
# about the definitions. |
| 9 |
|
| 10 |
unset LANG |
| 11 |
export LC_ALL=C |
| 12 |
export LC_CTYPE=C |
| 13 |
|
| 14 |
if test -z "$GOARCH" -o -z "$GOOS"; then |
| 15 |
echo 1>&2 "GOARCH or GOOS not defined in environment" |
| 16 |
exit 1 |
| 17 |
fi |
| 18 |
|
| 19 |
# Check that we are using the new build system if we should |
| 20 |
if [[ "$GOOS" = "linux" ]] && [[ "$GOLANG_SYS_BUILD" != "docker" ]]; then |
| 21 |
echo 1>&2 "In the Docker based build system, mkerrors should not be called directly." |
| 22 |
echo 1>&2 "See README.md" |
| 23 |
exit 1 |
| 24 |
fi |
| 25 |
|
| 26 |
if [[ "$GOOS" = "aix" ]]; then |
| 27 |
CC=${CC:-gcc} |
| 28 |
else |
| 29 |
CC=${CC:-cc} |
| 30 |
fi |
| 31 |
|
| 32 |
if [[ "$GOOS" = "solaris" ]]; then |
| 33 |
# Assumes GNU versions of utilities in PATH. |
| 34 |
export PATH=/usr/gnu/bin:$PATH |
| 35 |
fi |
| 36 |
|
| 37 |
uname=$(uname) |
| 38 |
|
| 39 |
includes_AIX=' |
| 40 |
#include <net/if.h> |
| 41 |
#include <net/netopt.h> |
| 42 |
#include <netinet/ip_mroute.h> |
| 43 |
#include <sys/protosw.h> |
| 44 |
#include <sys/stropts.h> |
| 45 |
#include <sys/mman.h> |
| 46 |
#include <sys/poll.h> |
| 47 |
#include <sys/select.h> |
| 48 |
#include <sys/termio.h> |
| 49 |
#include <termios.h> |
| 50 |
#include <fcntl.h> |
| 51 |
|
| 52 |
#define AF_LOCAL AF_UNIX |
| 53 |
' |
| 54 |
|
| 55 |
includes_Darwin=' |
| 56 |
#define _DARWIN_C_SOURCE |
| 57 |
#define KERNEL 1 |
| 58 |
#define _DARWIN_USE_64_BIT_INODE |
| 59 |
#define __APPLE_USE_RFC_3542 |
| 60 |
#include <stdint.h> |
| 61 |
#include <sys/stdio.h> |
| 62 |
#include <sys/attr.h> |
| 63 |
#include <sys/clonefile.h> |
| 64 |
#include <sys/kern_control.h> |
| 65 |
#include <sys/types.h> |
| 66 |
#include <sys/event.h> |
| 67 |
#include <sys/ptrace.h> |
| 68 |
#include <sys/select.h> |
| 69 |
#include <sys/socket.h> |
| 70 |
#include <sys/stat.h> |
| 71 |
#include <sys/un.h> |
| 72 |
#include <sys/sockio.h> |
| 73 |
#include <sys/sys_domain.h> |
| 74 |
#include <sys/sysctl.h> |
| 75 |
#include <sys/mman.h> |
| 76 |
#include <sys/mount.h> |
| 77 |
#include <sys/utsname.h> |
| 78 |
#include <sys/wait.h> |
| 79 |
#include <sys/xattr.h> |
| 80 |
#include <sys/vsock.h> |
| 81 |
#include <net/bpf.h> |
| 82 |
#include <net/if.h> |
| 83 |
#include <net/if_types.h> |
| 84 |
#include <net/route.h> |
| 85 |
#include <netinet/in.h> |
| 86 |
#include <netinet/ip.h> |
| 87 |
#include <termios.h> |
| 88 |
|
| 89 |
// for backwards compatibility because moved TIOCREMOTE to Kernel.framework after MacOSX12.0.sdk. |
| 90 |
#define TIOCREMOTE 0x80047469 |
| 91 |
' |
| 92 |
|
| 93 |
includes_DragonFly=' |
| 94 |
#include <sys/types.h> |
| 95 |
#include <sys/event.h> |
| 96 |
#include <sys/select.h> |
| 97 |
#include <sys/socket.h> |
| 98 |
#include <sys/sockio.h> |
| 99 |
#include <sys/stat.h> |
| 100 |
#include <sys/sysctl.h> |
| 101 |
#include <sys/mman.h> |
| 102 |
#include <sys/mount.h> |
| 103 |
#include <sys/wait.h> |
| 104 |
#include <sys/ioctl.h> |
| 105 |
#include <net/bpf.h> |
| 106 |
#include <net/if.h> |
| 107 |
#include <net/if_clone.h> |
| 108 |
#include <net/if_types.h> |
| 109 |
#include <net/route.h> |
| 110 |
#include <netinet/in.h> |
| 111 |
#include <termios.h> |
| 112 |
#include <netinet/ip.h> |
| 113 |
#include <net/ip_mroute/ip_mroute.h> |
| 114 |
' |
| 115 |
|
| 116 |
includes_FreeBSD=' |
| 117 |
#include <sys/capsicum.h> |
| 118 |
#include <sys/param.h> |
| 119 |
#include <sys/types.h> |
| 120 |
#include <sys/disk.h> |
| 121 |
#include <sys/event.h> |
| 122 |
#include <sys/sched.h> |
| 123 |
#include <sys/select.h> |
| 124 |
#include <sys/socket.h> |
| 125 |
#include <sys/un.h> |
| 126 |
#include <sys/sockio.h> |
| 127 |
#include <sys/stat.h> |
| 128 |
#include <sys/sysctl.h> |
| 129 |
#include <sys/mman.h> |
| 130 |
#include <sys/mount.h> |
| 131 |
#include <sys/wait.h> |
| 132 |
#include <sys/ioctl.h> |
| 133 |
#include <sys/ptrace.h> |
| 134 |
#include <net/bpf.h> |
| 135 |
#include <net/if.h> |
| 136 |
#include <net/if_types.h> |
| 137 |
#include <net/route.h> |
| 138 |
#include <netinet/in.h> |
| 139 |
#include <termios.h> |
| 140 |
#include <netinet/ip.h> |
| 141 |
#include <netinet/ip_mroute.h> |
| 142 |
#include <sys/extattr.h> |
| 143 |
|
| 144 |
#if __FreeBSD__ >= 10 |
| 145 |
#define IFT_CARP 0xf8 // IFT_CARP is deprecated in FreeBSD 10 |
| 146 |
#undef SIOCAIFADDR |
| 147 |
#define SIOCAIFADDR _IOW(105, 26, struct oifaliasreq) // ifaliasreq contains if_data |
| 148 |
#undef SIOCSIFPHYADDR |
| 149 |
#define SIOCSIFPHYADDR _IOW(105, 70, struct oifaliasreq) // ifaliasreq contains if_data |
| 150 |
#endif |
| 151 |
' |
| 152 |
|
| 153 |
includes_Linux=' |
| 154 |
#define _LARGEFILE_SOURCE |
| 155 |
#define _LARGEFILE64_SOURCE |
| 156 |
#ifndef __LP64__ |
| 157 |
#define _FILE_OFFSET_BITS 64 |
| 158 |
#endif |
| 159 |
#define _GNU_SOURCE |
| 160 |
|
| 161 |
// See the description in unix/linux/types.go |
| 162 |
#if defined(__ARM_EABI__) || \ |
| 163 |
(defined(__mips__) && (_MIPS_SIM == _ABIO32)) || \ |
| 164 |
(defined(__powerpc__) && (!defined(__powerpc64__))) |
| 165 |
# ifdef _TIME_BITS |
| 166 |
# undef _TIME_BITS |
| 167 |
# endif |
| 168 |
# define _TIME_BITS 32 |
| 169 |
#endif |
| 170 |
|
| 171 |
// <sys/ioctl.h> is broken on powerpc64, as it fails to include definitions of |
| 172 |
// these structures. We just include them copied from <bits/termios.h>. |
| 173 |
#if defined(__powerpc__) |
| 174 |
struct sgttyb { |
| 175 |
char sg_ispeed; |
| 176 |
char sg_ospeed; |
| 177 |
char sg_erase; |
| 178 |
char sg_kill; |
| 179 |
short sg_flags; |
| 180 |
}; |
| 181 |
|
| 182 |
struct tchars { |
| 183 |
char t_intrc; |
| 184 |
char t_quitc; |
| 185 |
char t_startc; |
| 186 |
char t_stopc; |
| 187 |
char t_eofc; |
| 188 |
char t_brkc; |
| 189 |
}; |
| 190 |
|
| 191 |
struct ltchars { |
| 192 |
char t_suspc; |
| 193 |
char t_dsuspc; |
| 194 |
char t_rprntc; |
| 195 |
char t_flushc; |
| 196 |
char t_werasc; |
| 197 |
char t_lnextc; |
| 198 |
}; |
| 199 |
#endif |
| 200 |
|
| 201 |
#include <bits/sockaddr.h> |
| 202 |
#include <sys/epoll.h> |
| 203 |
#include <sys/eventfd.h> |
| 204 |
#include <sys/inotify.h> |
| 205 |
#include <sys/ioctl.h> |
| 206 |
#include <sys/mman.h> |
| 207 |
#include <sys/mount.h> |
| 208 |
#include <sys/prctl.h> |
| 209 |
#include <sys/stat.h> |
| 210 |
#include <sys/types.h> |
| 211 |
#include <sys/time.h> |
| 212 |
#include <sys/select.h> |
| 213 |
#include <sys/signalfd.h> |
| 214 |
#include <sys/socket.h> |
| 215 |
#include <sys/timerfd.h> |
| 216 |
#include <sys/uio.h> |
| 217 |
#include <sys/xattr.h> |
| 218 |
#include <netinet/udp.h> |
| 219 |
#include <linux/audit.h> |
| 220 |
#include <linux/bpf.h> |
| 221 |
#include <linux/can.h> |
| 222 |
#include <linux/can/error.h> |
| 223 |
#include <linux/can/netlink.h> |
| 224 |
#include <linux/can/raw.h> |
| 225 |
#include <linux/capability.h> |
| 226 |
#include <linux/cryptouser.h> |
| 227 |
#include <linux/devlink.h> |
| 228 |
#include <linux/dm-ioctl.h> |
| 229 |
#include <linux/elf.h> |
| 230 |
#include <linux/errqueue.h> |
| 231 |
#include <linux/ethtool_netlink.h> |
| 232 |
#include <linux/falloc.h> |
| 233 |
#include <linux/fanotify.h> |
| 234 |
#include <linux/fib_rules.h> |
| 235 |
#include <linux/filter.h> |
| 236 |
#include <linux/fs.h> |
| 237 |
#include <linux/fscrypt.h> |
| 238 |
#include <linux/fsverity.h> |
| 239 |
#include <linux/genetlink.h> |
| 240 |
#include <linux/hdreg.h> |
| 241 |
#include <linux/hidraw.h> |
| 242 |
#include <linux/if.h> |
| 243 |
#include <linux/if_addr.h> |
| 244 |
#include <linux/if_alg.h> |
| 245 |
#include <linux/if_arp.h> |
| 246 |
#include <linux/if_ether.h> |
| 247 |
#include <linux/if_ppp.h> |
| 248 |
#include <linux/if_tun.h> |
| 249 |
#include <linux/if_packet.h> |
| 250 |
#include <linux/if_xdp.h> |
| 251 |
#include <linux/input.h> |
| 252 |
#include <linux/kcm.h> |
| 253 |
#include <linux/kexec.h> |
| 254 |
#include <linux/keyctl.h> |
| 255 |
#include <linux/landlock.h> |
| 256 |
#include <linux/loop.h> |
| 257 |
#include <linux/lwtunnel.h> |
| 258 |
#include <linux/magic.h> |
| 259 |
#include <linux/mei.h> |
| 260 |
#include <linux/memfd.h> |
| 261 |
#include <linux/module.h> |
| 262 |
#include <linux/mount.h> |
| 263 |
#include <linux/netfilter/nfnetlink.h> |
| 264 |
#include <linux/netfilter/nf_tables.h> |
| 265 |
#include <linux/netlink.h> |
| 266 |
#include <linux/net_namespace.h> |
| 267 |
#include <linux/nfc.h> |
| 268 |
#include <linux/nsfs.h> |
| 269 |
#include <linux/perf_event.h> |
| 270 |
#include <linux/pps.h> |
| 271 |
#include <linux/ptp_clock.h> |
| 272 |
#include <linux/ptrace.h> |
| 273 |
#include <linux/random.h> |
| 274 |
#include <linux/reboot.h> |
| 275 |
#include <linux/rtc.h> |
| 276 |
#include <linux/rtnetlink.h> |
| 277 |
#include <linux/sched.h> |
| 278 |
#include <linux/seccomp.h> |
| 279 |
#include <linux/serial.h> |
| 280 |
#include <linux/sock_diag.h> |
| 281 |
#include <linux/sockios.h> |
| 282 |
#include <linux/taskstats.h> |
| 283 |
#include <linux/tipc.h> |
| 284 |
#include <linux/vm_sockets.h> |
| 285 |
#include <linux/wait.h> |
| 286 |
#include <linux/watchdog.h> |
| 287 |
#include <linux/wireguard.h> |
| 288 |
|
| 289 |
#include <mtd/ubi-user.h> |
| 290 |
#include <mtd/mtd-user.h> |
| 291 |
#include <net/route.h> |
| 292 |
|
| 293 |
#if defined(__sparc__) |
| 294 |
// On sparc{,64}, the kernel defines struct termios2 itself which clashes with the |
| 295 |
// definition in glibc. As only the error constants are needed here, include the |
| 296 |
// generic termibits.h (which is included by termbits.h on sparc). |
| 297 |
#include <asm-generic/termbits.h> |
| 298 |
#else |
| 299 |
#include <asm/termbits.h> |
| 300 |
#endif |
| 301 |
|
| 302 |
#ifndef PTRACE_GETREGS |
| 303 |
#define PTRACE_GETREGS 0xc |
| 304 |
#endif |
| 305 |
|
| 306 |
#ifndef PTRACE_SETREGS |
| 307 |
#define PTRACE_SETREGS 0xd |
| 308 |
#endif |
| 309 |
|
| 310 |
#ifdef SOL_BLUETOOTH |
| 311 |
// SPARC includes this in /usr/include/sparc64-linux-gnu/bits/socket.h |
| 312 |
// but it is already in bluetooth_linux.go |
| 313 |
#undef SOL_BLUETOOTH |
| 314 |
#endif |
| 315 |
|
| 316 |
// Certain constants are missing from the fs/crypto UAPI |
| 317 |
#define FS_KEY_DESC_PREFIX "fscrypt:" |
| 318 |
#define FS_KEY_DESC_PREFIX_SIZE 8 |
| 319 |
#define FS_MAX_KEY_SIZE 64 |
| 320 |
|
| 321 |
// The code generator produces -0x1 for (~0), but an unsigned value is necessary |
| 322 |
// for the tipc_subscr timeout __u32 field. |
| 323 |
#undef TIPC_WAIT_FOREVER |
| 324 |
#define TIPC_WAIT_FOREVER 0xffffffff |
| 325 |
|
| 326 |
// Copied from linux/netfilter/nf_nat.h |
| 327 |
// Including linux/netfilter/nf_nat.h here causes conflicts between linux/in.h |
| 328 |
// and netinet/in.h. |
| 329 |
#define NF_NAT_RANGE_MAP_IPS (1 << 0) |
| 330 |
#define NF_NAT_RANGE_PROTO_SPECIFIED (1 << 1) |
| 331 |
#define NF_NAT_RANGE_PROTO_RANDOM (1 << 2) |
| 332 |
#define NF_NAT_RANGE_PERSISTENT (1 << 3) |
| 333 |
#define NF_NAT_RANGE_PROTO_RANDOM_FULLY (1 << 4) |
| 334 |
#define NF_NAT_RANGE_PROTO_OFFSET (1 << 5) |
| 335 |
#define NF_NAT_RANGE_NETMAP (1 << 6) |
| 336 |
#define NF_NAT_RANGE_PROTO_RANDOM_ALL \ |
| 337 |
(NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PROTO_RANDOM_FULLY) |
| 338 |
#define NF_NAT_RANGE_MASK \ |
| 339 |
(NF_NAT_RANGE_MAP_IPS | NF_NAT_RANGE_PROTO_SPECIFIED | \ |
| 340 |
NF_NAT_RANGE_PROTO_RANDOM | NF_NAT_RANGE_PERSISTENT | \ |
| 341 |
NF_NAT_RANGE_PROTO_RANDOM_FULLY | NF_NAT_RANGE_PROTO_OFFSET | \ |
| 342 |
NF_NAT_RANGE_NETMAP) |
| 343 |
|
| 344 |
// Copied from linux/hid.h. |
| 345 |
// Keep in sync with the size of the referenced fields. |
| 346 |
#define _HIDIOCGRAWNAME_LEN 128 // sizeof_field(struct hid_device, name) |
| 347 |
#define _HIDIOCGRAWPHYS_LEN 64 // sizeof_field(struct hid_device, phys) |
| 348 |
#define _HIDIOCGRAWUNIQ_LEN 64 // sizeof_field(struct hid_device, uniq) |
| 349 |
|
| 350 |
#define _HIDIOCGRAWNAME HIDIOCGRAWNAME(_HIDIOCGRAWNAME_LEN) |
| 351 |
#define _HIDIOCGRAWPHYS HIDIOCGRAWPHYS(_HIDIOCGRAWPHYS_LEN) |
| 352 |
#define _HIDIOCGRAWUNIQ HIDIOCGRAWUNIQ(_HIDIOCGRAWUNIQ_LEN) |
| 353 |
|
| 354 |
// Renamed in v6.16, commit c6d732c38f93 ("net: ethtool: remove duplicate defines for family info") |
| 355 |
#define ETHTOOL_FAMILY_NAME ETHTOOL_GENL_NAME |
| 356 |
#define ETHTOOL_FAMILY_VERSION ETHTOOL_GENL_VERSION |
| 357 |
|
| 358 |
// Removed in v6.17, commit 760e6f7befba ("futex: Remove support for IMMUTABLE") |
| 359 |
#define PR_FUTEX_HASH_GET_IMMUTABLE 3 |
| 360 |
' |
| 361 |
|
| 362 |
includes_NetBSD=' |
| 363 |
#include <sys/types.h> |
| 364 |
#include <sys/param.h> |
| 365 |
#include <sys/event.h> |
| 366 |
#include <sys/extattr.h> |
| 367 |
#include <sys/mman.h> |
| 368 |
#include <sys/mount.h> |
| 369 |
#include <sys/sched.h> |
| 370 |
#include <sys/select.h> |
| 371 |
#include <sys/socket.h> |
| 372 |
#include <sys/sockio.h> |
| 373 |
#include <sys/sysctl.h> |
| 374 |
#include <sys/termios.h> |
| 375 |
#include <sys/ttycom.h> |
| 376 |
#include <sys/wait.h> |
| 377 |
#include <net/bpf.h> |
| 378 |
#include <net/if.h> |
| 379 |
#include <net/if_types.h> |
| 380 |
#include <net/route.h> |
| 381 |
#include <netinet/in.h> |
| 382 |
#include <netinet/in_systm.h> |
| 383 |
#include <netinet/ip.h> |
| 384 |
#include <netinet/ip_mroute.h> |
| 385 |
#include <netinet/if_ether.h> |
| 386 |
|
| 387 |
// Needed since <sys/param.h> refers to it... |
| 388 |
#define schedppq 1 |
| 389 |
' |
| 390 |
|
| 391 |
includes_OpenBSD=' |
| 392 |
#include <sys/types.h> |
| 393 |
#include <sys/param.h> |
| 394 |
#include <sys/event.h> |
| 395 |
#include <sys/mman.h> |
| 396 |
#include <sys/mount.h> |
| 397 |
#include <sys/select.h> |
| 398 |
#include <sys/sched.h> |
| 399 |
#include <sys/socket.h> |
| 400 |
#include <sys/sockio.h> |
| 401 |
#include <sys/stat.h> |
| 402 |
#include <sys/sysctl.h> |
| 403 |
#include <sys/termios.h> |
| 404 |
#include <sys/ttycom.h> |
| 405 |
#include <sys/unistd.h> |
| 406 |
#include <sys/wait.h> |
| 407 |
#include <net/bpf.h> |
| 408 |
#include <net/if.h> |
| 409 |
#include <net/if_types.h> |
| 410 |
#include <net/if_var.h> |
| 411 |
#include <net/route.h> |
| 412 |
#include <netinet/in.h> |
| 413 |
#include <netinet/in_systm.h> |
| 414 |
#include <netinet/ip.h> |
| 415 |
#include <netinet/ip_mroute.h> |
| 416 |
#include <netinet/if_ether.h> |
| 417 |
#include <net/if_bridge.h> |
| 418 |
|
| 419 |
// We keep some constants not supported in OpenBSD 5.5 and beyond for |
| 420 |
// the promise of compatibility. |
| 421 |
#define EMUL_ENABLED 0x1 |
| 422 |
#define EMUL_NATIVE 0x2 |
| 423 |
#define IPV6_FAITH 0x1d |
| 424 |
#define IPV6_OPTIONS 0x1 |
| 425 |
#define IPV6_RTHDR_STRICT 0x1 |
| 426 |
#define IPV6_SOCKOPT_RESERVED1 0x3 |
| 427 |
#define SIOCGIFGENERIC 0xc020693a |
| 428 |
#define SIOCSIFGENERIC 0x80206939 |
| 429 |
#define WALTSIG 0x4 |
| 430 |
' |
| 431 |
|
| 432 |
includes_SunOS=' |
| 433 |
#include <limits.h> |
| 434 |
#include <sys/types.h> |
| 435 |
#include <sys/select.h> |
| 436 |
#include <sys/socket.h> |
| 437 |
#include <sys/sockio.h> |
| 438 |
#include <sys/stat.h> |
| 439 |
#include <sys/stream.h> |
| 440 |
#include <sys/mman.h> |
| 441 |
#include <sys/wait.h> |
| 442 |
#include <sys/ioctl.h> |
| 443 |
#include <sys/mkdev.h> |
| 444 |
#include <net/bpf.h> |
| 445 |
#include <net/if.h> |
| 446 |
#include <net/if_arp.h> |
| 447 |
#include <net/if_types.h> |
| 448 |
#include <net/route.h> |
| 449 |
#include <netinet/icmp6.h> |
| 450 |
#include <netinet/in.h> |
| 451 |
#include <netinet/ip.h> |
| 452 |
#include <netinet/ip_mroute.h> |
| 453 |
#include <termios.h> |
| 454 |
' |
| 455 |
|
| 456 |
|
| 457 |
includes=' |
| 458 |
#include <sys/types.h> |
| 459 |
#include <sys/file.h> |
| 460 |
#include <fcntl.h> |
| 461 |
#include <dirent.h> |
| 462 |
#include <sys/socket.h> |
| 463 |
#include <netinet/in.h> |
| 464 |
#include <netinet/ip.h> |
| 465 |
#include <netinet/ip6.h> |
| 466 |
#include <netinet/tcp.h> |
| 467 |
#include <errno.h> |
| 468 |
#include <sys/signal.h> |
| 469 |
#include <signal.h> |
| 470 |
#include <sys/resource.h> |
| 471 |
#include <time.h> |
| 472 |
' |
| 473 |
ccflags="$@" |
| 474 |
|
| 475 |
# Write go tool cgo -godefs input. |
| 476 |
( |
| 477 |
echo package unix |
| 478 |
echo |
| 479 |
echo '/*' |
| 480 |
indirect="includes_$(uname)" |
| 481 |
echo "${!indirect} $includes" |
| 482 |
echo '*/' |
| 483 |
echo 'import "C"' |
| 484 |
echo 'import "syscall"' |
| 485 |
echo |
| 486 |
echo 'const (' |
| 487 |
|
| 488 |
# The gcc command line prints all the #defines |
| 489 |
# it encounters while processing the input |
| 490 |
echo "${!indirect} $includes" | $CC -x c - -E -dM $ccflags | |
| 491 |
awk ' |
| 492 |
$1 != "#define" || $2 ~ /\(/ || $3 == "" {next} |
| 493 |
|
| 494 |
$2 ~ /^E([ABCD]X|[BIS]P|[SD]I|S|FL)$/ {next} # 386 registers |
| 495 |
$2 ~ /^(SIGEV_|SIGSTKSZ|SIGRT(MIN|MAX))/ {next} |
| 496 |
$2 ~ /^(SCM_SRCRT)$/ {next} |
| 497 |
$2 ~ /^(MAP_FAILED)$/ {next} |
| 498 |
$2 ~ /^ELF_.*$/ {next}# <asm/elf.h> contains ELF_ARCH, etc. |
| 499 |
|
| 500 |
$2 ~ /^EXTATTR_NAMESPACE_NAMES/ || |
| 501 |
$2 ~ /^EXTATTR_NAMESPACE_[A-Z]+_STRING/ {next} |
| 502 |
|
| 503 |
$2 !~ /^ECCAPBITS/ && |
| 504 |
$2 !~ /^ETH_/ && |
| 505 |
$2 !~ /^EPROC_/ && |
| 506 |
$2 !~ /^EQUIV_/ && |
| 507 |
$2 !~ /^EXPR_/ && |
| 508 |
$2 !~ /^EVIOC/ && |
| 509 |
$2 ~ /^E[A-Z0-9_]+$/ || |
| 510 |
$2 ~ /^B[0-9_]+$/ || |
| 511 |
$2 ~ /^(OLD|NEW)DEV$/ || |
| 512 |
$2 == "BOTHER" || |
| 513 |
$2 ~ /^CI?BAUD(EX)?$/ || |
| 514 |
$2 == "IBSHIFT" || |
| 515 |
$2 ~ /^V[A-Z0-9]+$/ || |
| 516 |
$2 ~ /^CS[A-Z0-9]/ || |
| 517 |
$2 ~ /^I(SIG|CANON|CRNL|UCLC|EXTEN|MAXBEL|STRIP|UTF8)$/ || |
| 518 |
$2 ~ /^IGN/ || |
| 519 |
$2 ~ /^IX(ON|ANY|OFF)$/ || |
| 520 |
$2 ~ /^IN(LCR|PCK)$/ || |
| 521 |
$2 !~ "X86_CR3_PCID_NOFLUSH" && |
| 522 |
$2 ~ /(^FLU?SH)|(FLU?SH$)/ || |
| 523 |
$2 ~ /^C(LOCAL|READ|MSPAR|RTSCTS)$/ || |
| 524 |
$2 == "BRKINT" || |
| 525 |
$2 == "HUPCL" || |
| 526 |
$2 == "PENDIN" || |
| 527 |
$2 == "TOSTOP" || |
| 528 |
$2 == "XCASE" || |
| 529 |
$2 == "ALTWERASE" || |
| 530 |
$2 == "NOKERNINFO" || |
| 531 |
$2 == "NFDBITS" || |
| 532 |
$2 ~ /^PAR/ || |
| 533 |
$2 ~ /^SIG[^_]/ || |
| 534 |
$2 ~ /^O[CNPFPL][A-Z]+[^_][A-Z]+$/ || |
| 535 |
$2 ~ /^(NL|CR|TAB|BS|VT|FF)DLY$/ || |
| 536 |
$2 ~ /^(NL|CR|TAB|BS|VT|FF)[0-9]$/ || |
| 537 |
$2 ~ /^(DT|EI|ELF|EV|NN|NT|PF|SHF|SHN|SHT|STB|STT|VER)_/ || |
| 538 |
$2 ~ /^O?XTABS$/ || |
| 539 |
$2 ~ /^TC[IO](ON|OFF)$/ || |
| 540 |
$2 ~ /^IN_/ || |
| 541 |
$2 ~ /^KCM/ || |
| 542 |
$2 ~ /^LANDLOCK_/ || |
| 543 |
$2 ~ /^LOCK_(SH|EX|NB|UN)$/ || |
| 544 |
$2 ~ /^LO_(KEY|NAME)_SIZE$/ || |
| 545 |
$2 ~ /^LOOP_(CLR|CTL|GET|SET)_/ || |
| 546 |
$2 == "LOOP_CONFIGURE" || |
| 547 |
$2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|MCAST|EVFILT|NOTE|SHUT|PROT|MAP|MREMAP|MFD|T?PACKET|MSG|SCM|MCL|DT|MADV|PR|LOCAL|TCPOPT|UDP)_/ || |
| 548 |
$2 ~ /^NFC_(GENL|PROTO|COMM|RF|SE|DIRECTION|LLCP|SOCKPROTO)_/ || |
| 549 |
$2 ~ /^NFC_.*_(MAX)?SIZE$/ || |
| 550 |
$2 ~ /^PTP_/ || |
| 551 |
$2 ~ /^RAW_PAYLOAD_/ || |
| 552 |
$2 ~ /^[US]F_/ || |
| 553 |
$2 ~ /^TP_STATUS_/ || |
| 554 |
$2 ~ /^FALLOC_/ || |
| 555 |
$2 ~ /^ICMPV?6?_(FILTER|SEC)/ || |
| 556 |
$2 == "SOMAXCONN" || |
| 557 |
$2 == "NAME_MAX" || |
| 558 |
$2 == "IFNAMSIZ" || |
| 559 |
$2 ~ /^CTL_(HW|KERN|MAXNAME|NET|QUERY)$/ || |
| 560 |
$2 ~ /^KERN_(HOSTNAME|OS(RELEASE|TYPE)|VERSION)$/ || |
| 561 |
$2 ~ /^HW_MACHINE$/ || |
| 562 |
$2 ~ /^SYSCTL_VERS/ || |
| 563 |
$2 !~ "MNT_BITS" && |
| 564 |
$2 ~ /^(MS|MNT|MOUNT|UMOUNT)_/ || |
| 565 |
$2 ~ /^NS_GET_/ || |
| 566 |
$2 ~ /^TUN(SET|GET|ATTACH|DETACH)/ || |
| 567 |
$2 ~ /^(O|F|[ES]?FD|NAME|S|PTRACE|PT|PIOD|TFD)_/ || |
| 568 |
$2 ~ /^KEXEC_/ || |
| 569 |
$2 ~ /^LINUX_REBOOT_CMD_/ || |
| 570 |
$2 ~ /^LINUX_REBOOT_MAGIC[12]$/ || |
| 571 |
$2 ~ /^MODULE_INIT_/ || |
| 572 |
$2 !~ "NLA_TYPE_MASK" && |
| 573 |
$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ && |
| 574 |
$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ || |
| 575 |
$2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ || |
| 576 |
$2 ~ /^(CONNECT|SAE)_/ || |
| 577 |
$2 ~ /^FIORDCHK$/ || |
| 578 |
$2 ~ /^SIOC/ || |
| 579 |
$2 ~ /^TIOC/ || |
| 580 |
$2 ~ /^TCGET/ || |
| 581 |
$2 ~ /^TCSET/ || |
| 582 |
$2 ~ /^TC(FLSH|SBRKP?|XONC)$/ || |
| 583 |
$2 !~ "RTF_BITS" && |
| 584 |
$2 ~ /^(IFF|IFT|NET_RT|RTM(GRP)?|RTF|RTV|RTA|RTAX)_/ || |
| 585 |
$2 ~ /^BIOC/ || |
| 586 |
$2 ~ /^DIOC/ || |
| 587 |
$2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || |
| 588 |
$2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|LOCKS|MEMLOCK|MSGQUEUE|NICE|NOFILE|NPROC|RSS|RTPRIO|RTTIME|SIGPENDING|STACK)|RLIM_INFINITY/ || |
| 589 |
$2 ~ /^PRIO_(PROCESS|PGRP|USER)/ || |
| 590 |
$2 ~ /^CLONE_[A-Z_]+/ || |
| 591 |
$2 !~ /^(BPF_TIMEVAL|BPF_FIB_LOOKUP_[A-Z]+|BPF_F_LINK)$/ && |
| 592 |
$2 ~ /^(BPF|DLT)_/ || |
| 593 |
$2 ~ /^AUDIT_/ || |
| 594 |
$2 ~ /^(CLOCK|TIMER)_/ || |
| 595 |
$2 ~ /^CAN_/ || |
| 596 |
$2 ~ /^CAP_/ || |
| 597 |
$2 ~ /^CP_/ || |
| 598 |
$2 ~ /^CPUSTATES$/ || |
| 599 |
$2 ~ /^CTLIOCGINFO$/ || |
| 600 |
$2 ~ /^ALG_/ || |
| 601 |
$2 ~ /^FI(CLONE|DEDUPERANGE)/ || |
| 602 |
$2 ~ /^FS_(POLICY_FLAGS|KEY_DESC|ENCRYPTION_MODE|[A-Z0-9_]+_KEY_SIZE)/ || |
| 603 |
$2 ~ /^FS_IOC_.*(ENCRYPTION|VERITY|[GS]ETFLAGS)/ || |
| 604 |
$2 ~ /^FS_VERITY_/ || |
| 605 |
$2 ~ /^FSCRYPT_/ || |
| 606 |
$2 ~ /^DM_/ || |
| 607 |
$2 ~ /^GRND_/ || |
| 608 |
$2 ~ /^RND/ || |
| 609 |
$2 ~ /^KEY_(SPEC|REQKEY_DEFL)_/ || |
| 610 |
$2 ~ /^KEYCTL_/ || |
| 611 |
$2 ~ /^PERF_/ || |
| 612 |
$2 ~ /^SECCOMP_/ || |
| 613 |
$2 ~ /^SEEK_/ || |
| 614 |
$2 ~ /^SCHED_/ || |
| 615 |
$2 ~ /^SPLICE_/ || |
| 616 |
$2 ~ /^SYNC_FILE_RANGE_/ || |
| 617 |
$2 !~ /IOC_MAGIC/ && |
| 618 |
$2 ~ /^[A-Z][A-Z0-9_]+_MAGIC2?$/ || |
| 619 |
$2 ~ /^(VM|VMADDR)_/ || |
| 620 |
$2 ~ /^(IOCTL_VM_SOCKETS_|IOCTL_MEI_)/ || |
| 621 |
$2 ~ /^(TASKSTATS|TS)_/ || |
| 622 |
$2 ~ /^CGROUPSTATS_/ || |
| 623 |
$2 ~ /^GENL_/ || |
| 624 |
$2 ~ /^STATX_/ || |
| 625 |
$2 ~ /^RENAME/ || |
| 626 |
$2 ~ /^UBI_IOC[A-Z]/ || |
| 627 |
$2 ~ /^UTIME_/ || |
| 628 |
$2 ~ /^XATTR_(CREATE|REPLACE|NO(DEFAULT|FOLLOW|SECURITY)|SHOWCOMPRESSION)/ || |
| 629 |
$2 ~ /^ATTR_(BIT_MAP_COUNT|(CMN|VOL|FILE)_)/ || |
| 630 |
$2 ~ /^FSOPT_/ || |
| 631 |
$2 ~ /^WDIO[CFS]_/ || |
| 632 |
$2 ~ /^NFN/ || |
| 633 |
$2 !~ /^NFT_META_IIFTYPE/ && |
| 634 |
$2 ~ /^NFT_/ || |
| 635 |
$2 ~ /^NF_NAT_/ || |
| 636 |
$2 ~ /^XDP_/ || |
| 637 |
$2 ~ /^RWF_/ || |
| 638 |
$2 ~ /^(HDIO|WIN|SMART)_/ || |
| 639 |
$2 ~ /^CRYPTO_/ || |
| 640 |
$2 ~ /^TIPC_/ || |
| 641 |
$2 !~ "DEVLINK_RELOAD_LIMITS_VALID_MASK" && |
| 642 |
$2 ~ /^DEVLINK_/ || |
| 643 |
$2 ~ /^ETHTOOL_/ || |
| 644 |
$2 ~ /^LWTUNNEL_IP/ || |
| 645 |
$2 ~ /^ITIMER_/ || |
| 646 |
$2 !~ "WMESGLEN" && |
| 647 |
$2 ~ /^W[A-Z0-9]+$/ || |
| 648 |
$2 ~ /^P_/ || |
| 649 |
$2 ~/^PPPIOC/ || |
| 650 |
$2 ~ /^FAN_|FANOTIFY_/ || |
| 651 |
$2 == "HID_MAX_DESCRIPTOR_SIZE" || |
| 652 |
$2 ~ /^_?HIDIOC/ || |
| 653 |
$2 ~ /^BUS_(USB|HIL|BLUETOOTH|VIRTUAL)$/ || |
| 654 |
$2 ~ /^MTD/ || |
| 655 |
$2 ~ /^OTP/ || |
| 656 |
$2 ~ /^MEM/ || |
| 657 |
$2 ~ /^WG/ || |
| 658 |
$2 ~ /^FIB_RULE_/ || |
| 659 |
$2 ~ /^BLK[A-Z]*(GET$|SET$|BUF$|PART$|SIZE|IOMIN$|IOOPT$|ALIGNOFF$|DISCARD|ROTATIONAL$|ZEROOUT$|GETDISKSEQ$)/ {printf("\t%s = C.%s\n", $2, $2)} |
| 660 |
$2 ~ /^__WCOREFLAG$/ {next} |
| 661 |
$2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} |
| 662 |
|
| 663 |
{next} |
| 664 |
' | sort |
| 665 |
|
| 666 |
echo ')' |
| 667 |
) >_const.go |
| 668 |
|
| 669 |
# Pull out the error names for later. |
| 670 |
errors=$( |
| 671 |
echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
| 672 |
awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print $2 }' | |
| 673 |
sort |
| 674 |
) |
| 675 |
|
| 676 |
# Pull out the signal names for later. |
| 677 |
signals=$( |
| 678 |
echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
| 679 |
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print $2 }' | |
| 680 |
grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | |
| 681 |
sort |
| 682 |
) |
| 683 |
|
| 684 |
# Again, writing regexps to a file. |
| 685 |
echo '#include <errno.h>' | $CC -x c - -E -dM $ccflags | |
| 686 |
awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 687 |
sort >_error.grep |
| 688 |
echo '#include <signal.h>' | $CC -x c - -E -dM $ccflags | |
| 689 |
awk '$1=="#define" && $2 ~ /^SIG[A-Z0-9]+$/ { print "^\t" $2 "[ \t]*=" }' | |
| 690 |
grep -E -v '(SIGSTKSIZE|SIGSTKSZ|SIGRT|SIGMAX64)' | |
| 691 |
sort >_signal.grep |
| 692 |
|
| 693 |
echo '// mkerrors.sh' "$@" |
| 694 |
echo '// Code generated by the command above; see README.md. DO NOT EDIT.' |
| 695 |
echo |
| 696 |
echo "//go:build ${GOARCH} && ${GOOS}" |
| 697 |
echo |
| 698 |
go tool cgo -godefs -- "$@" _const.go >_error.out |
| 699 |
cat _error.out | grep -vf _error.grep | grep -vf _signal.grep |
| 700 |
echo |
| 701 |
echo '// Errors' |
| 702 |
echo 'const (' |
| 703 |
cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= syscall.Errno(\1)/' |
| 704 |
echo ')' |
| 705 |
|
| 706 |
echo |
| 707 |
echo '// Signals' |
| 708 |
echo 'const (' |
| 709 |
cat _error.out | grep -f _signal.grep | sed 's/=\(.*\)/= syscall.Signal(\1)/' |
| 710 |
echo ')' |
| 711 |
|
| 712 |
# Run C program to print error and syscall strings. |
| 713 |
( |
| 714 |
echo -E " |
| 715 |
#include <stdio.h> |
| 716 |
#include <stdlib.h> |
| 717 |
#include <errno.h> |
| 718 |
#include <ctype.h> |
| 719 |
#include <string.h> |
| 720 |
#include <signal.h> |
| 721 |
|
| 722 |
#define nelem(x) (sizeof(x)/sizeof((x)[0])) |
| 723 |
|
| 724 |
enum { A = 'A', Z = 'Z', a = 'a', z = 'z' }; // avoid need for single quotes below |
| 725 |
|
| 726 |
struct tuple { |
| 727 |
int num; |
| 728 |
const char *name; |
| 729 |
}; |
| 730 |
|
| 731 |
struct tuple errors[] = { |
| 732 |
" |
| 733 |
for i in $errors |
| 734 |
do |
| 735 |
echo -E ' {'$i', "'$i'" },' |
| 736 |
done |
| 737 |
|
| 738 |
echo -E " |
| 739 |
}; |
| 740 |
|
| 741 |
struct tuple signals[] = { |
| 742 |
" |
| 743 |
for i in $signals |
| 744 |
do |
| 745 |
echo -E ' {'$i', "'$i'" },' |
| 746 |
done |
| 747 |
|
| 748 |
# Use -E because on some systems bash builtin interprets \n itself. |
| 749 |
echo -E ' |
| 750 |
}; |
| 751 |
|
| 752 |
static int |
| 753 |
tuplecmp(const void *a, const void *b) |
| 754 |
{ |
| 755 |
return ((struct tuple *)a)->num - ((struct tuple *)b)->num; |
| 756 |
} |
| 757 |
|
| 758 |
int |
| 759 |
main(void) |
| 760 |
{ |
| 761 |
int i, e; |
| 762 |
char buf[1024], *p; |
| 763 |
|
| 764 |
printf("\n\n// Error table\n"); |
| 765 |
printf("var errorList = [...]struct {\n"); |
| 766 |
printf("\tnum syscall.Errno\n"); |
| 767 |
printf("\tname string\n"); |
| 768 |
printf("\tdesc string\n"); |
| 769 |
printf("} {\n"); |
| 770 |
qsort(errors, nelem(errors), sizeof errors[0], tuplecmp); |
| 771 |
for(i=0; i<nelem(errors); i++) { |
| 772 |
e = errors[i].num; |
| 773 |
if(i > 0 && errors[i-1].num == e) |
| 774 |
continue; |
| 775 |
strncpy(buf, strerror(e), sizeof(buf) - 1); |
| 776 |
buf[sizeof(buf) - 1] = '\0'; |
| 777 |
// lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 778 |
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 779 |
buf[0] += a - A; |
| 780 |
printf("\t{ %d, \"%s\", \"%s\" },\n", e, errors[i].name, buf); |
| 781 |
} |
| 782 |
printf("}\n\n"); |
| 783 |
|
| 784 |
printf("\n\n// Signal table\n"); |
| 785 |
printf("var signalList = [...]struct {\n"); |
| 786 |
printf("\tnum syscall.Signal\n"); |
| 787 |
printf("\tname string\n"); |
| 788 |
printf("\tdesc string\n"); |
| 789 |
printf("} {\n"); |
| 790 |
qsort(signals, nelem(signals), sizeof signals[0], tuplecmp); |
| 791 |
for(i=0; i<nelem(signals); i++) { |
| 792 |
e = signals[i].num; |
| 793 |
if(i > 0 && signals[i-1].num == e) |
| 794 |
continue; |
| 795 |
strncpy(buf, strsignal(e), sizeof(buf) - 1); |
| 796 |
buf[sizeof(buf) - 1] = '\0'; |
| 797 |
// lowercase first letter: Bad -> bad, but STREAM -> STREAM. |
| 798 |
if(A <= buf[0] && buf[0] <= Z && a <= buf[1] && buf[1] <= z) |
| 799 |
buf[0] += a - A; |
| 800 |
// cut trailing : number. |
| 801 |
p = strrchr(buf, ":"[0]); |
| 802 |
if(p) |
| 803 |
*p = '\0'; |
| 804 |
printf("\t{ %d, \"%s\", \"%s\" },\n", e, signals[i].name, buf); |
| 805 |
} |
| 806 |
printf("}\n\n"); |
| 807 |
|
| 808 |
return 0; |
| 809 |
} |
| 810 |
|
| 811 |
' |
| 812 |
) >_errors.c |
| 813 |
|
| 814 |
$CC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _signal.grep _error.out |