diff options
Diffstat (limited to 'src/pkg/syscall/mkerrors.sh')
| -rwxr-xr-x | src/pkg/syscall/mkerrors.sh | 123 |
1 files changed, 78 insertions, 45 deletions
diff --git a/src/pkg/syscall/mkerrors.sh b/src/pkg/syscall/mkerrors.sh index 9936b11ac..9a50cdf8b 100755 --- a/src/pkg/syscall/mkerrors.sh +++ b/src/pkg/syscall/mkerrors.sh @@ -15,6 +15,46 @@ GCC=gcc uname=$(uname) +includes_Darwin=' +#define _DARWIN_C_SOURCE +#define KERNEL +#define _DARWIN_USE_64_BIT_INODE +#include <sys/types.h> +#include <sys/event.h> +#include <sys/ptrace.h> +#include <sys/socket.h> +#include <sys/sockio.h> +#include <sys/sysctl.h> +#include <sys/mman.h> +#include <sys/wait.h> +#include <net/bpf.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/route.h> +#include <netinet/in.h> +#include <netinet/ip.h> +#include <netinet/ip_mroute.h> +#include <termios.h> +' + +includes_FreeBSD=' +#include <sys/types.h> +#include <sys/event.h> +#include <sys/socket.h> +#include <sys/sockio.h> +#include <sys/sysctl.h> +#include <sys/wait.h> +#include <sys/ioctl.h> +#include <net/bpf.h> +#include <net/if.h> +#include <net/if_types.h> +#include <net/route.h> +#include <netinet/in.h> +#include <termios.h> +#include <netinet/ip.h> +#include <netinet/ip_mroute.h> +' + includes_Linux=' #define _LARGEFILE_SOURCE #define _LARGEFILE64_SOURCE @@ -27,6 +67,7 @@ includes_Linux=' #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/mount.h> +#include <sys/prctl.h> #include <sys/stat.h> #include <sys/types.h> #include <linux/if_addr.h> @@ -44,44 +85,25 @@ includes_Linux=' #include <netpacket/packet.h> ' -includes_Darwin=' -#define _DARWIN_C_SOURCE -#define KERNEL -#define _DARWIN_USE_64_BIT_INODE -#include <sys/types.h> -#include <sys/event.h> -#include <sys/ptrace.h> -#include <sys/socket.h> -#include <sys/sockio.h> -#include <sys/sysctl.h> -#include <sys/mman.h> -#include <sys/wait.h> -#include <net/bpf.h> -#include <net/if.h> -#include <net/if_types.h> -#include <net/route.h> -#include <netinet/in.h> -#include <netinet/ip.h> -#include <netinet/ip_mroute.h> -#include <termios.h> -' - -includes_FreeBSD=' +includes_NetBSD=' #include <sys/types.h> +#include <sys/param.h> #include <sys/event.h> #include <sys/socket.h> #include <sys/sockio.h> #include <sys/sysctl.h> +#include <sys/termios.h> +#include <sys/ttycom.h> #include <sys/wait.h> -#include <sys/ioctl.h> #include <net/bpf.h> #include <net/if.h> #include <net/if_types.h> #include <net/route.h> #include <netinet/in.h> -#include <termios.h> +#include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/ip_mroute.h> +#include <netinet/if_ether.h> ' includes_OpenBSD=' @@ -108,6 +130,7 @@ includes_OpenBSD=' includes=' #include <sys/types.h> +#include <sys/file.h> #include <fcntl.h> #include <dirent.h> #include <sys/socket.h> @@ -118,26 +141,22 @@ includes=' #include <errno.h> #include <sys/signal.h> #include <signal.h> +#include <sys/resource.h> ' -ccflags="" -next=false -for i -do - if $next; then - ccflags="$ccflags $i" - next=false - elif [ "$i" = "-f" ]; then - next=true - fi -done +ccflags="$@" -# Write godefs input. +# Write cgo -godefs input. ( + echo package syscall + echo + echo '/*' indirect="includes_$(uname)" echo "${!indirect} $includes" + echo '*/' + echo 'import "C"' echo - echo 'enum {' + echo 'const (' # The gcc command line prints all the #defines # it encounters while processing the input @@ -157,7 +176,8 @@ done $2 ~ /^E[A-Z0-9_]+$/ || $2 ~ /^SIG[^_]/ || $2 ~ /^IN_/ || - $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|EVFILT|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV)_/ || + $2 ~ /^LOCK_(SH|EX|NB|UN)$/ || + $2 ~ /^(AF|SOCK|SO|SOL|IPPROTO|IP|IPV6|TCP|EVFILT|NOTE|EV|SHUT|PROT|MAP|PACKET|MSG|SCM|MCL|DT|MADV|PR)_/ || $2 == "SOMAXCONN" || $2 == "NAME_MAX" || $2 == "IFNAMSIZ" || @@ -174,18 +194,20 @@ done $2 ~ /^TIOC/ || $2 ~ /^(IFF|IFT|NET_RT|RTM|RTF|RTV|RTA|RTAX)_/ || $2 ~ /^BIOC/ || + $2 ~ /^RUSAGE_(SELF|CHILDREN|THREAD)/ || + $2 ~ /^RLIMIT_(AS|CORE|CPU|DATA|FSIZE|NOFILE|STACK)|RLIM_INFINITY/ || $2 !~ /^(BPF_TIMEVAL)$/ && $2 ~ /^(BPF|DLT)_/ || $2 !~ "WMESGLEN" && - $2 ~ /^W[A-Z0-9]+$/ {printf("\t$%s = %s,\n", $2, $2)} + $2 ~ /^W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", $2, $2)} $2 ~ /^__WCOREFLAG$/ {next} - $2 ~ /^__W[A-Z0-9]+$/ {printf("\t$%s = %s,\n", substr($2,3), $2)} + $2 ~ /^__W[A-Z0-9]+$/ {printf("\t%s = C.%s\n", substr($2,3), $2)} {next} ' | sort - echo '};' -) >_const.c + echo ')' +) >_const.go # Pull out just the error names for later. errors=$( @@ -194,10 +216,21 @@ errors=$( sort ) +# Again, writing regexps to a file. +echo '#include <errno.h>' | $GCC -x c - -E -dM $ccflags | + awk '$1=="#define" && $2 ~ /^E[A-Z0-9_]+$/ { print "^\t" $2 "[ \t]*=" }' | + sort >_error.grep + echo '// mkerrors.sh' "$@" echo '// MACHINE GENERATED BY THE COMMAND ABOVE; DO NOT EDIT' echo -godefs -c $GCC "$@" -gsyscall "$@" _const.c +cgo -godefs -- "$@" _const.go >_error.out +cat _error.out | grep -vf _error.grep +echo +echo '// Errors' +echo 'const (' +cat _error.out | grep -f _error.grep | sed 's/=\(.*\)/= Errno(\1)/' +echo ')' # Run C program to print error strings. ( @@ -255,4 +288,4 @@ main(void) ' ) >_errors.c -$GCC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.c +$GCC $ccflags -o _errors _errors.c && $GORUN ./_errors && rm -f _errors.c _errors _const.go _error.grep _error.out |
