[Devel] [PATCH] Add script to, given a kernel source tree, automatically write the cr.h
Matt Helsley
matthltc at us.ibm.com
Tue Aug 4 16:43:08 PDT 2009
Signed-off-by: Matt Helsley <matthltc at us.ibm.com>
---
cr.h | 92 +++++++++++++++++++++++++++++++++++++++++++------
rewrite-cr-header.sh | 64 ++++++++++++++++++++++++++++++++++
2 files changed, 144 insertions(+), 12 deletions(-)
create mode 100755 rewrite-cr-header.sh
diff --git a/cr.h b/cr.h
index d89e113..f24b7b0 100644
--- a/cr.h
+++ b/cr.h
@@ -1,27 +1,95 @@
-#if __i386__
+/* AUTOMATICALLY GENERATED by rewrite-cr-header.sh */
+
+#define _LINUX_CHECKPOINT_H_
+/*
+ * Generic checkpoint-restart
+ *
+ * Copyright (C) 2008-2009 Oren Laadan
+ *
+ * This file is subject to the terms and conditions of the GNU General Public
+ * License. See the file COPYING in the main directory of the Linux
+ * distribution for more details.
+ */
+
+#define CHECKPOINT_VERSION 1
+
+/* checkpoint user flags */
+#define CHECKPOINT_SUBTREE 0x1
+
+/* restart user flags */
+#define RESTART_TASKSELF 0x1
+#define RESTART_FROZEN 0x2
+
+
+
+
+
+
+
+
+
+
-#ifndef __NR_checkpoint
-#define __NR_checkpoint 335
-#endif
-#ifndef __NR_restart
-#define __NR_restart 336
-#endif
-#elif __s390x__
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+/* alpha unsupported. */
+/* arm unsupported. */
+/* avr32 unsupported. */
+/* blackfin unsupported. */
+/* cris unsupported. */
+/* cris unsupported. */
+/* cris unsupported. */
+/* frv unsupported. */
+/* h8300 unsupported. */
+/* ia64 unsupported. */
+/* m32r unsupported. */
+/* m68k unsupported. */
+/* microblaze unsupported. */
+/* mips unsupported. */
+/* mn10300 unsupported. */
+/* parisc unsupported. */
+/* powerpc unsupported. */
+#if __s390x__
#ifndef __NR_checkpoint
#define __NR_checkpoint 332
#endif
+
#ifndef __NR_restart
-#define __NR_restart 333
+#define __NR_restart 333
#endif
-#elif __powerpc__
+/* sh unsupported. */
+/* sh unsupported. */
+/* sh unsupported. */
+/* sparc unsupported. */
+#elif __i386__
#ifndef __NR_checkpoint
-#define __NR_checkpoint 322
+#define __NR_checkpoint 338
#endif
+
#ifndef __NR_restart
-#define __NR_restart 323
+#define __NR_restart 339
#endif
+
+/* x86_64 unsupported. */
+/* x86_64 unsupported. */
+/* xtensa unsupported. */
+#else
+#error "Architecture does not have definitons for __NR_(checkpoint|restart)"
#endif
diff --git a/rewrite-cr-header.sh b/rewrite-cr-header.sh
new file mode 100755
index 0000000..22f92c7
--- /dev/null
+++ b/rewrite-cr-header.sh
@@ -0,0 +1,64 @@
+#!/bin/bash
+#
+# Rewrite the contents of cr.h
+#
+
+KERNELSRC=../oren
+
+################################################################################
+
+[ -z "${KERNELSRC}" ] && exit -1
+mv cr.h cr.h.bak || exit -1
+
+(
+COND='#if'
+set -e
+echo '/* AUTOMATICALLY GENERATED by rewrite-cr-header.sh */'
+
+#
+# Include non-__KERNEL__ sections of include/linux/checkpoint.h using
+# cpp to expand only the directives of the kernel header.
+#
+# The first 6 lines of cpp output write some trashy #define/#undef lines
+# we don't want. Would it be better to throw everything away until we see
+# "#define _LINUX_CHECKPOINT_H_" ??
+#
+cpp -CC -P -U__KERNEL__ -undef -nostdinc -fdirectives-only ${KERNELSRC}/include/linux/checkpoint.h | tail -n '+6'
+
+find ${KERNELSRC}/arch -name 'unistd*.h' -print | sort | \
+while read UNISTDH ; do
+ REGEX='[[:space:]]*#[[:space:]]*define[[:space:]]+__NR_(checkpoint|restart)[[:space:]]+[[:digit:]]+'
+
+ [ -z "${UNISTDH}" ] && continue
+ KARCH=$(echo "${UNISTDH}" | sed -e 's|.*/arch/\([^/]\+\)/.*|\1|')
+ BITNESS=$(basename "${UNISTDH}" | sed -e 's/unistd_*\([12346]\+\)\.h/\1/')
+
+ # Map KARCH to something suitable for CPP e.g. __i386__
+ case "${KARCH}" in
+ x86) if [ "${BITNESS}" == "32" ]; then
+ CPPARCH=i386
+ else
+ CPPARCH=x86_64
+ fi
+ ;;
+ s390*) CPPARCH=s390x ;;
+ *) CPPARCH="${KARCH}" ;;
+ esac
+
+ grep -q -E "${REGEX}" ${UNISTDH} || {
+ echo '/* '"${CPPARCH}"' unsupported. */'
+ continue
+ }
+
+ echo -e "${COND} __${CPPARCH}__\\n"
+ grep -E "${REGEX}" ${UNISTDH} | \
+ sed -e 's/^[[:space:]]*#define[[:space:]]\+__NR_\([^[:space:]]\+\)[[:space:]]\+\([^[:space:]]\+\).*$/#ifndef __NR_\1\n#define __NR_\1 \2\n#endif\n/'
+ COND='#elif'
+done
+echo -e '#else\n#error "Architecture does not have definitons for __NR_(checkpoint|restart)"\n#endif'
+) > cr.h || {
+ mv -f cr.h.bak cr.h
+ exit -1
+}
+
+rm -f cr.h.bak
--
1.5.6.3
_______________________________________________
Containers mailing list
Containers at lists.linux-foundation.org
https://lists.linux-foundation.org/mailman/listinfo/containers
More information about the Devel
mailing list