Page MenuHomeFreeBSD

D35354.id106478.diff
No OneTemporary

D35354.id106478.diff

Index: lib/libsysdecode/Makefile
===================================================================
--- lib/libsysdecode/Makefile
+++ lib/libsysdecode/Makefile
@@ -5,6 +5,10 @@
LIB= sysdecode
SRCS= errno.c flags.c ioctl.c signal.c syscallnames.c utrace.c support.c
+.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" || \
+ ${MACHINE_CPUARCH} == "i386"
+SRCS+= linux.c
+.endif
INCS= sysdecode.h
CFLAGS+= -I${.OBJDIR}
@@ -106,7 +110,7 @@
sysdecode_mask.3 sysdecode_wait4_options.3 \
sysdecode_mask.3 sysdecode_wait6_options.3
-CLEANFILES= ioctl.c ioctl.c.tmp tables.h
+CLEANFILES= ioctl.c ioctl.c.tmp tables.h tables_linux.h
.if defined(COMPAT_32BIT)
CPP+= -m32
@@ -121,9 +125,11 @@
CFLAGS.gcc+= ${CFLAGS.gcc.${.IMPSRC}}
-DEPENDOBJS+= tables.h
+DEPENDOBJS+= tables.h tables_linux.h
tables.h: mktables
sh ${.CURDIR}/mktables ${SYSROOT:U${DESTDIR}}${INCLUDEDIR} ${.TARGET}
+tables_linux.h: mklinuxtables
+ sh ${.CURDIR}/mklinuxtables ${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.
@@ -139,7 +145,7 @@
mv -f ${.TARGET}.tmp ${.TARGET}; \
fi
-beforedepend: ioctl.c tables.h
+beforedepend: ioctl.c tables.h tables_linux.h
HAS_TESTS=
SUBDIR.${MK_TESTS}+= tests
Index: lib/libsysdecode/linux.c
===================================================================
--- /dev/null
+++ lib/libsysdecode/linux.c
@@ -0,0 +1,106 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2022 Dmitry Chagin <dchagin@FreeBSD.orf>
+ *
+ * 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.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <sys/proc.h>
+#include <stdbool.h>
+#include <stdio.h>
+
+#include "support.h"
+#include "sysdecode.h"
+
+#ifdef __aarch64__
+#include <arm64/linux/linux.h>
+#elif __i386__
+#include <i386/linux/linux.h>
+#elif __amd64__
+#ifdef COMPAT_32BIT
+#include <amd64/linux32/linux.h>
+#else
+#include <amd64/linux/linux.h>
+#endif
+#else
+#error "Unsupported Linux arch"
+#endif
+
+#include <compat/linux/linux.h>
+#include <compat/linux/linux_timer.h>
+
+#define X(a,b) { a, "a" },
+#define XEND { 0, NULL }
+
+#define TABLE_START(n) static struct name_table n[] = {
+#define TABLE_ENTRY X
+#define TABLE_END XEND };
+
+#include "tables_linux.h"
+
+#undef TABLE_START
+#undef TABLE_ENTRY
+#undef TABLE_END
+
+void
+sysdecode_linux_clockid(FILE *fp, clockid_t which)
+{
+ const char *str;
+ clockid_t ci;
+ pid_t pid;
+
+ if (which >= 0) {
+ str = lookup_value(clockids, which);
+ if (str == NULL)
+ fprintf(fp, "UNKNOWN(%d)", which);
+ else
+ fputs(str, fp);
+ goto pidp;
+ }
+ if ((which & LINUX_CLOCKFD_MASK) == LINUX_CLOCKFD_MASK) {
+ fputs("INVALID PERTHREAD|CLOCKFD", fp);
+ goto pidp;
+ }
+ ci = LINUX_CPUCLOCK_WHICH(which);
+ if (LINUX_CPUCLOCK_PERTHREAD(which) == true)
+ fputs("THREAD|", fp);
+ else
+ fputs("PROCESS|", fp);
+ str = lookup_value(clockcpuids, ci);
+ if (str != NULL)
+ fputs(str, fp);
+ else {
+ if (ci == LINUX_CLOCKFD)
+ fputs("CLOCKFD", fp);
+ else
+ fprintf(fp, "UNKNOWN(%d)", which);
+ }
+
+pidp:
+ pid = LINUX_CPUCLOCK_ID(which);
+ fprintf(fp, "(%d)", pid);
+}
Index: lib/libsysdecode/mklinuxtables
===================================================================
--- /dev/null
+++ lib/libsysdecode/mklinuxtables
@@ -0,0 +1,109 @@
+#!/bin/sh
+#
+# Copyright (c) 2006 "David Kirchner" <dpk@dpk.net>. 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 tables.h
+#
+
+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"
+ output_tmp=$(mktemp -u)
+ exec > "$output_tmp"
+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
+ cat <<_EOF_
+TABLE_START(${name})
+_EOF_
+ if [ -e "${include_dir}/${file}" ]; then
+ all_headers="${all_headers:+${all_headers} }${file}"
+ 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_ENTRY(LINUX_%s, %s)\n", $i, $i }'
+ fi
+cat <<_EOF_
+TABLE_END
+
+_EOF_
+}
+
+cat <<_EOF_
+/* This file is auto-generated. */
+
+_EOF_
+
+gen_table "clockids" "LINUX_CLOCK_[A-Z_]+[[:space:]]+[0-9]+" "compat/linux/linux_timer.h"
+gen_table "clockcpuids" "LINUX_CPUCLOCK_[A-Z_]+[[:space:]]+[0-9]+" "compat/linux/linux_timer.h" "_MASK|_MAX"
+
+# Generate a .depend file for our output file
+if [ -n "$output_file" ]; then
+ depend_tmp=$(mktemp -u)
+ {
+ echo "$output_file: \\"
+ echo "$all_headers" | tr ' ' '\n' | sort -u |
+ sed -e "s,^, $include_dir/," -e 's,$, \\,'
+ echo
+ } > "$depend_tmp"
+ if cmp -s "$output_tmp" "$output_file"; then
+ rm -f "$output_tmp" "$depend_tmp"
+ else
+ mv -f "$depend_tmp" ".depend.${output_file}"
+ mv -f "$output_tmp" "$output_file"
+ fi
+fi
Index: lib/libsysdecode/sysdecode.h
===================================================================
--- lib/libsysdecode/sysdecode.h
+++ lib/libsysdecode/sysdecode.h
@@ -134,4 +134,12 @@
const char *sysdecode_whence(int _whence);
bool sysdecode_shmflags(FILE *_fp, int _flags, int *_rem);
+#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__)
+
+#define LINUX_ABI_PRESENT
+
+void sysdecode_linux_clockid(FILE *_fp, clockid_t _which);
+
+#endif /* __i386__ || __amd64__ || __aarch64__ */
+
#endif /* !__SYSDECODE_H__ */

File Metadata

Mime Type
text/plain
Expires
Sat, Mar 1, 7:06 AM (14 h, 22 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16899942
Default Alt Text
D35354.id106478.diff (8 KB)

Event Timeline