Index: lib/libsysdecode/Makefile =================================================================== --- lib/libsysdecode/Makefile +++ lib/libsysdecode/Makefile @@ -92,7 +92,7 @@ sysdecode_mask.3 sysdecode_wait4_options.3 \ sysdecode_mask.3 sysdecode_wait6_options.3 -CLEANFILES= ioctl.c tables.h +CLEANFILES= ioctl.c tables.h tables_linux.h .if defined(COMPAT_32BIT) CPP+= -m32 @@ -110,10 +110,13 @@ CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}} -DEPENDOBJS+= tables.h +DEPENDOBJS+= tables.h linux_tables.h tables.h: mktables sh ${.CURDIR}/mktables ${DESTDIR}${INCLUDEDIR} ${.TARGET} +tables_linux.h: mktables_linux + sh ${.CURDIR}/mktables_linux ${SRCTOP}/sys ${.TARGET} + # mkioctls runs find(1) for headers so needs to rebuild every time. This used # to be a hack only done in buildworld. .if !defined(_SKIP_BUILD) @@ -123,6 +126,6 @@ env CPP="${CPP}" \ /bin/sh ${.CURDIR}/mkioctls ${DESTDIR}${INCLUDEDIR} > ${.TARGET} -beforedepend: ioctl.c tables.h +beforedepend: ioctl.c tables.h tables_linux.h .include Index: lib/libsysdecode/flags.c =================================================================== --- lib/libsysdecode/flags.c +++ lib/libsysdecode/flags.c @@ -67,6 +67,11 @@ #include #include +#if defined(__i386__) || defined(__amd64__) +#include +#include +#endif + /* * This is taken from the xlat tables originally in truss which were * in turn taken from strace. @@ -77,16 +82,20 @@ }; #define X(a) { a, #a }, +#define XX(a,b) { a, #b }, #define XEND { 0, NULL } #define TABLE_START(n) static struct name_table n[] = { #define TABLE_ENTRY X +#define TABLE_LX_ENTRY XX #define TABLE_END XEND }; #include "tables.h" +#include "tables_linux.h" #undef TABLE_START #undef TABLE_ENTRY +#undef TABLE_LX_ENTRY #undef TABLE_END /* @@ -977,3 +986,47 @@ } } } + +#if defined(__i386__) || defined(__amd64__) +bool +sysdecode_linux_clone_flags(FILE *fp, int flags, int *rem) +{ + + return (print_mask_int(fp, linux_clone, flags, rem)); +} + +bool +sysdecode_linux_futex_op(FILE *fp, int flags, int *rem) +{ + const char *cop; + uintmax_t val; + int op, fl; + + op = flags & ~(LINUX_FUTEX_PRIVATE_FLAG|LINUX_FUTEX_CLOCK_REALTIME); + fl = flags & (LINUX_FUTEX_PRIVATE_FLAG|LINUX_FUTEX_CLOCK_REALTIME); + val = 0; + + cop = lookup_value(linux_futex_op, op); + if (cop != NULL) + fputs(cop, fp); + else { + fprintf(fp, "invalid<%d>", op); + val = op; + } + + if (fl != 0) { + fputc('|', fp); + if (fl & LINUX_FUTEX_PRIVATE_FLAG) + fputs("FUTEX_PRIVATE_FLAG", fp); + if (fl & LINUX_FUTEX_CLOCK_REALTIME) { + if (fl & LINUX_FUTEX_PRIVATE_FLAG) + fputs("|FUTEX_CLOCK_REALTIME", fp); + else + fputs("FUTEX_CLOCK_REALTIME", fp); + } + } + if (rem != NULL) + *rem = val; + return (true); +} +#endif Index: lib/libsysdecode/mktables_linux =================================================================== --- /dev/null +++ lib/libsysdecode/mktables_linux @@ -0,0 +1,102 @@ +#!/bin/sh +# +# Copyright (c) 2017 "Dmitry Chagin" . All rights reserved. +# Copyright (c) 2006 "David Kirchner" . All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $FreeBSD$ +# +# Generates linux_tables.h +# +# Originally this script was 'mksubr' for kdump which generated a complete +# C file along with function definitions. Now this script generates tables +# of constants and names extracted from header files. + +set -e + +LC_ALL=C; export LC_ALL + +if [ -z "$1" ] +then + echo "usage: sh $0 include-dir [output-file]" + exit 1 +fi +include_dir=$1 +if [ -n "$2" ]; then + output_file="$2" + exec > "$output_file" +fi + +all_headers= +# +# Generate a table C #definitions. The including file can define the +# TABLE_NAME(n), TABLE_ENTRY(x), and TABLE_END macros to define what +# the tables map to. +# +gen_table() +{ + local name grep file excl filter + name=$1 + grep=$2 + file=$3 + excl=$4 + + if [ -z "$excl" ]; then + filter="cat" + else + filter="egrep -v" + fi + all_headers="${all_headers:+${all_headers} }${file}" + cat <<_EOF_ +TABLE_START(${name}) +_EOF_ + egrep "^#[[:space:]]*define[[:space:]]+"${grep}"[[:space:]]*" \ + $include_dir/$file | ${filter} ${excl} | \ + awk '{ for (i = 1; i <= NF; i++) \ + if ($i ~ /define/) \ + break; \ + ++i; \ + sub(/LINUX_/,"",$i); \ + printf "TABLE_LX_ENTRY(%s, %s)\n", $(i+1), $i }' +cat <<_EOF_ +TABLE_END + +_EOF_ +} + +cat <<_EOF_ +/* This file is auto-generated. */ + +_EOF_ + +gen_table "linux_clone" "LINUX_CLONE_[A-Z_]+[[:space:]]+0x[0-9A-Fa-f]+" "compat/linux/linux_misc.h" +gen_table "linux_futex_op" "LINUX_FUTEX_[A-Z_]+[[:space:]]+[0-9]+" "compat/linux/linux_futex.h" + +# Generate a .depend file for our output file +if [ -n "$output_file" ]; then + echo "$output_file: \\" > ".depend.$output_file" + echo "$all_headers" | tr ' ' '\n' | sort -u | + sed -e "s,^, $include_dir/," -e 's,$, \\,' >> \ + ".depend.$output_file" + echo >> ".depend.$output_file" +fi Index: lib/libsysdecode/sysdecode.h =================================================================== --- lib/libsysdecode/sysdecode.h +++ lib/libsysdecode/sysdecode.h @@ -114,4 +114,10 @@ bool sysdecode_wait6_options(FILE *_fp, int _options, int *_rem); const char *sysdecode_whence(int _whence); +/* Linux emulation layer */ +#if defined(__i386__) || defined(__amd64__) +bool sysdecode_linux_clone_flags(FILE *_fp, int _flags, int *_rem); +bool sysdecode_linux_futex_op(FILE *_fp, int _flags, int *_rem); +#endif /* __i386__ || __amd64__ */ + #endif /* !__SYSDECODE_H__ */ Index: sys/compat/linux/linux_futex.h =================================================================== --- sys/compat/linux/linux_futex.h +++ sys/compat/linux/linux_futex.h @@ -36,8 +36,6 @@ #ifndef _LINUX_FUTEX_H #define _LINUX_FUTEX_H -extern LIST_HEAD(futex_list, futex) futex_list; -extern struct mtx futex_mtx; #define LINUX_FUTEX_WAIT 0 #define LINUX_FUTEX_WAKE 1 @@ -76,7 +74,12 @@ #define FUTEX_TID_MASK 0x3fffffff #define FUTEX_BITSET_MATCH_ANY 0xffffffff +#ifdef _KERNEL +extern LIST_HEAD(futex_list, futex) futex_list; +extern struct mtx futex_mtx; + void release_futexes(struct thread *, struct linux_emuldata *); +#endif #endif /* !_LINUX_FUTEX_H */ Index: sys/compat/linux/linux_misc.h =================================================================== --- sys/compat/linux/linux_misc.h +++ sys/compat/linux/linux_misc.h @@ -149,6 +149,7 @@ #define LINUX_GRND_NONBLOCK 0x0001 #define LINUX_GRND_RANDOM 0x0002 +#ifdef _KERNEL int linux_common_wait(struct thread *td, int pid, int *status, int options, struct rusage *ru); void linux_to_bsd_waitopts(int options, int *bsdopts); @@ -157,5 +158,6 @@ struct thread *linux_tdfind(struct thread *, lwpid_t, pid_t); int linux_sysctl_debug(SYSCTL_HANDLER_ARGS); +#endif #endif /* _LINUX_MISC_H_ */ Index: usr.bin/kdump/Makefile =================================================================== --- usr.bin/kdump/Makefile +++ usr.bin/kdump/Makefile @@ -7,7 +7,10 @@ PROG= kdump SRCS= kdump.c subr.c -CFLAGS+= -I${SRCTOP}/usr.bin/ktrace +CFLAGS+= -I${SRCTOP}/usr.bin/ktrace -I${SRCTOP}/sys +.if exists(${SRCTOP}/sys/${MACHINE_CPUARCH}/linux) +CFLAGS+= -I${SRCTOP}/sys/${MACHINE_CPUARCH} +.endif LIBADD= sysdecode .if ${MK_CASPER} != "no" Index: usr.bin/kdump/kdump.c =================================================================== --- usr.bin/kdump/kdump.c +++ usr.bin/kdump/kdump.c @@ -87,6 +87,13 @@ #include #endif +#if defined(__amd64__) || defined(__i386__) +#include +#ifdef __amd64__ +#include +#endif +#endif + u_int abidump(struct ktr_header *); int fetchprocinfo(struct ktr_header *, u_int *); int fread_tail(void *, int, int); @@ -1472,6 +1479,52 @@ break; } } +#if defined(__amd64__) + if (fancy && + (sv_flags & SV_ABI_MASK) == SV_ABI_LINUX && + (sv_flags & SV_ILP32) != 0) { + switch (ktr->ktr_code) { + case LINUX32_SYS_linux_clone: + putchar('('); + print_mask_arg(sysdecode_linux_clone_flags, *ip); + c = ','; + ip++; + narg--; + break; + case LINUX32_SYS_linux_sys_futex: + print_number(ip, narg, c); + putchar(','); + print_mask_arg(sysdecode_linux_futex_op, *ip); + c = ','; + ip++; + narg--; + break; + } + } else +#endif /* __amd64__ */ +#if defined(__amd64__) || defined(__i386__) + if (fancy && + (sv_flags & SV_ABI_MASK) == SV_ABI_LINUX) { + switch (ktr->ktr_code) { + case LINUX_SYS_linux_clone: + putchar('('); + print_mask_arg(sysdecode_linux_clone_flags, *ip); + c = ','; + ip++; + narg--; + break; + case LINUX_SYS_linux_sys_futex: + print_number(ip, narg, c); + putchar(','); + print_mask_arg(sysdecode_linux_futex_op, *ip); + c = ','; + ip++; + narg--; + break; + } + } +#endif /* __amd64__ || __i386__ */ + while (narg > 0) { print_number(ip, narg, c); }