aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>2024-02-29 09:55:05 -0500
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>2024-02-29 09:55:05 -0500
commited21bf6d5b04c58c7aeed3822d21ddc635dbe76d (patch)
tree5b8d929f7e198669fba194429e9424292eb7f946
parent789519210ac24ec1b5a4b5b677c0bf6f40b555c0 (diff)
downloadlibrseq-ed21bf6d5b04c58c7aeed3822d21ddc635dbe76d.tar.gz
Introduce common generic header file
Move: - RSEQ_ASM_DEFINE_TABLE, - __RSEQ_ASM_DEFINE_TABLE, - RSEQ_ASM_DEFINE_EXIT_POINT. to a generic common header file now that those are exact copy across all architectures. Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Change-Id: I1f27e8889b13d263467a1bab92b272cc80aa0743
-rw-r--r--include/Makefile.am1
-rw-r--r--include/rseq/arch/aarch64.h60
-rw-r--r--include/rseq/arch/arm.h60
-rw-r--r--include/rseq/arch/generic/common.h70
-rw-r--r--include/rseq/arch/mips.h60
-rw-r--r--include/rseq/arch/ppc.h98
-rw-r--r--include/rseq/arch/riscv.h60
-rw-r--r--include/rseq/arch/s390.h60
-rw-r--r--include/rseq/arch/x86.h114
9 files changed, 131 insertions, 452 deletions
diff --git a/include/Makefile.am b/include/Makefile.am
index dd540fe..bc27c39 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -6,6 +6,7 @@ nobase_include_HEADERS = \
rseq/arch/aarch64.h \
rseq/arch/arm/bits.h \
rseq/arch/arm.h \
+ rseq/arch/generic/common.h \
rseq/arch/generic/thread-pointer.h \
rseq/arch/mips/bits.h \
rseq/arch/mips.h \
diff --git a/include/rseq/arch/aarch64.h b/include/rseq/arch/aarch64.h
index e2ae825..cd1d4de 100644
--- a/include/rseq/arch/aarch64.h
+++ b/include/rseq/arch/aarch64.h
@@ -115,64 +115,8 @@ do { \
#define RSEQ_ASM_TMP_REG "x15"
#define RSEQ_ASM_TMP_REG_2 "x14"
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
- post_commit_offset, abort_ip) \
- " .pushsection __rseq_cs, \"aw\"\n" \
- " .balign 32\n" \
- __rseq_str(label) ":\n" \
- " " RSEQ_ASM_U32(__rseq_str(version)) "\n" \
- " " RSEQ_ASM_U32(__rseq_str(flags)) "\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n" \
- " .popsection\n\t" \
- " .pushsection __rseq_cs_ptr_array, \"aw\"\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n" \
- " .popsection\n"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- " .pushsection __rseq_exit_point_array, \"aw\"\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n" \
- " " RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n" \
- " .popsection\n"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/*
* Define a critical section abort handler.
diff --git a/include/rseq/arch/arm.h b/include/rseq/arch/arm.h
index 6030d4f..d675c97 100644
--- a/include/rseq/arch/arm.h
+++ b/include/rseq/arch/arm.h
@@ -107,64 +107,8 @@ do { \
#define RSEQ_ASM_U32(x) ".word " x
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
- post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n\t" \
- ".balign 32\n\t" \
- __rseq_str(label) ":\n\t" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
- ".popsection\n\t"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/*
* Store the address of the critical section descriptor structure at
diff --git a/include/rseq/arch/generic/common.h b/include/rseq/arch/generic/common.h
new file mode 100644
index 0000000..a34e286
--- /dev/null
+++ b/include/rseq/arch/generic/common.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: MIT */
+/* SPDX-FileCopyrightText: 2024 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> */
+
+/*
+ * rseq/arch/generic/common.h: Common architecture support macros.
+ */
+
+#ifndef _RSEQ_GENERIC_COMMON_H
+#define _RSEQ_GENERIC_COMMON_H
+
+/* Only used in RSEQ_ASM_DEFINE_TABLE. */
+#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
+ start_ip, post_commit_offset, abort_ip) \
+ ".pushsection __rseq_cs, \"aw\"\n\t" \
+ ".balign 32\n\t" \
+ __rseq_str(label) ":\n\t" \
+ RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
+ RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
+ ".popsection\n\t" \
+ ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
+ ".popsection\n\t"
+
+/*
+ * Define an rseq critical section structure of version 0 with no flags.
+ *
+ * @label:
+ * Local label for the beginning of the critical section descriptor
+ * structure.
+ * @start_ip:
+ * Pointer to the first instruction of the sequence of consecutive assembly
+ * instructions.
+ * @post_commit_ip:
+ * Pointer to the instruction after the last instruction of the sequence of
+ * consecutive assembly instructions.
+ * @abort_ip:
+ * Pointer to the instruction where to move the execution flow in case of
+ * abort of the sequence of consecutive assembly instructions.
+ */
+#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
+ __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
+ (post_commit_ip) - (start_ip), abort_ip)
+
+/*
+ * Define the @exit_ip pointer as an exit point for the sequence of consecutive
+ * assembly instructions at @start_ip.
+ *
+ * @start_ip:
+ * Pointer to the first instruction of the sequence of consecutive assembly
+ * instructions.
+ * @exit_ip:
+ * Pointer to an exit point instruction.
+ *
+ * Exit points of a rseq critical section consist of all instructions outside
+ * of the critical section where a critical section can either branch to or
+ * reach through the normal course of its execution. The abort IP and the
+ * post-commit IP are already part of the __rseq_cs section and should not be
+ * explicitly defined as additional exit points. Knowing all exit points is
+ * useful to assist debuggers stepping over the critical section.
+ */
+#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
+ ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
+ RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
+ ".popsection\n\t"
+
+#endif
diff --git a/include/rseq/arch/mips.h b/include/rseq/arch/mips.h
index 641b278..d369f91 100644
--- a/include/rseq/arch/mips.h
+++ b/include/rseq/arch/mips.h
@@ -119,64 +119,8 @@ do { \
#define RSEQ_ASM_U32(x) ".word " x
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
- post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n\t" \
- ".balign 32\n\t" \
- __rseq_str(label) ":\n\t" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
- ".popsection\n\t"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/* Only used in RSEQ_ASM_DEFINE_ABORT. */
#define __RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label, \
diff --git a/include/rseq/arch/ppc.h b/include/rseq/arch/ppc.h
index 8c7566e..d1b25cf 100644
--- a/include/rseq/arch/ppc.h
+++ b/include/rseq/arch/ppc.h
@@ -92,6 +92,27 @@ do { \
#define RSEQ_ASM_U32(x) ".long " x
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
+
+/*
+ * Define a critical section abort handler.
+ *
+ * @label:
+ * Local label to the abort handler.
+ * @teardown:
+ * Sequence of instructions to run on abort.
+ * @abort_label:
+ * C label to jump to at the end of the sequence.
+ */
+#define RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label) \
+ ".pushsection __rseq_failure, \"ax\"\n\t" \
+ RSEQ_ASM_U32(__rseq_str(RSEQ_SIG)) "\n\t" \
+ __rseq_str(label) ":\n\t" \
+ teardown \
+ "b %l[" __rseq_str(abort_label) "]\n\t" \
+ ".popsection\n\t"
+
/*
* Store the address of the critical section descriptor structure at
* @cs_label into the @rseq_cs pointer and emit the label @label, which
@@ -125,83 +146,6 @@ do { \
__rseq_str(label) ":\n\t"
#endif
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
- start_ip, post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n\t" \
- ".balign 32\n\t" \
- __rseq_str(label) ":\n\t" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define a critical section abort handler.
- *
- * @label:
- * Local label to the abort handler.
- * @teardown:
- * Sequence of instructions to run on abort.
- * @abort_label:
- * C label to jump to at the end of the sequence.
- */
-#define RSEQ_ASM_DEFINE_ABORT(label, teardown, abort_label) \
- ".pushsection __rseq_failure, \"ax\"\n\t" \
- RSEQ_ASM_U32(__rseq_str(RSEQ_SIG)) "\n\t" \
- __rseq_str(label) ":\n\t" \
- teardown \
- "b %l[" __rseq_str(abort_label) "]\n\t" \
- ".popsection\n\t"
-
/* Jump to local label @label when @cpu_id != @current_cpu_id. */
#define RSEQ_ASM_CBNE_CPU_ID(cpu_id, current_cpu_id, label) \
RSEQ_INJECT_ASM(2) \
diff --git a/include/rseq/arch/riscv.h b/include/rseq/arch/riscv.h
index 3cfb9ac..eceaf2f 100644
--- a/include/rseq/arch/riscv.h
+++ b/include/rseq/arch/riscv.h
@@ -86,64 +86,8 @@ do { \
#define RSEQ_ASM_TMP_REG_3 "t4"
#define RSEQ_ASM_TMP_REG_4 "t3"
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, start_ip, \
- post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n" \
- ".balign 32\n" \
- __rseq_str(label) ":\n" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n" \
- ".popsection\n"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n" \
- ".popsection\n"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/*
* Define a critical section abort handler.
diff --git a/include/rseq/arch/s390.h b/include/rseq/arch/s390.h
index 0b11116..9804b9d 100644
--- a/include/rseq/arch/s390.h
+++ b/include/rseq/arch/s390.h
@@ -85,64 +85,8 @@ do { \
#define RSEQ_ASM_U32(x) ".long " x
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
- start_ip, post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n\t" \
- ".balign 32\n\t" \
- __rseq_str(label) ":\n\t" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
- ".popsection\n\t"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/*
* Define a critical section abort handler.
diff --git a/include/rseq/arch/x86.h b/include/rseq/arch/x86.h
index 1385dc4..8b61cf9 100644
--- a/include/rseq/arch/x86.h
+++ b/include/rseq/arch/x86.h
@@ -90,91 +90,8 @@ do { \
#define RSEQ_ASM_U32(x) ".long " x
-/*
- * Store the address of the critical section descriptor structure at
- * @cs_label into the @rseq_cs pointer and emit the label @label, which
- * is the beginning of the sequence of consecutive assembly instructions.
- *
- * @label:
- * Local label to the beginning of the sequence of consecutive assembly
- * instructions.
- * @cs_label:
- * Source local label to the critical section descriptor structure.
- * @rseq_cs:
- * Destination pointer where to store the address of the critical
- * section descriptor structure.
- */
-#ifdef RSEQ_ARCH_AMD64
-#define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
- RSEQ_INJECT_ASM(1) \
- "leaq " __rseq_str(cs_label) "(%%rip), %%rax\n\t" \
- "movq %%rax, " __rseq_str(rseq_cs) "\n\t" \
- __rseq_str(label) ":\n\t"
-#else
-# define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
- RSEQ_INJECT_ASM(1) \
- "movl $" __rseq_str(cs_label) ", " __rseq_str(rseq_cs) "\n\t" \
- __rseq_str(label) ":\n\t"
-#endif
-
-/* Only used in RSEQ_ASM_DEFINE_TABLE. */
-#define __RSEQ_ASM_DEFINE_TABLE(label, version, flags, \
- start_ip, post_commit_offset, abort_ip) \
- ".pushsection __rseq_cs, \"aw\"\n\t" \
- ".balign 32\n\t" \
- __rseq_str(label) ":\n\t" \
- RSEQ_ASM_U32(__rseq_str(version)) "\n\t" \
- RSEQ_ASM_U32(__rseq_str(flags)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(post_commit_offset)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(abort_ip)) "\n\t" \
- ".popsection\n\t" \
- ".pushsection __rseq_cs_ptr_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
- ".popsection\n\t"
-
-/*
- * Define an rseq critical section structure of version 0 with no flags.
- *
- * @label:
- * Local label for the beginning of the critical section descriptor
- * structure.
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @post_commit_ip:
- * Pointer to the instruction after the last instruction of the sequence of
- * consecutive assembly instructions.
- * @abort_ip:
- * Pointer to the instruction where to move the execution flow in case of
- * abort of the sequence of consecutive assembly instructions.
- */
-#define RSEQ_ASM_DEFINE_TABLE(label, start_ip, post_commit_ip, abort_ip) \
- __RSEQ_ASM_DEFINE_TABLE(label, 0x0, 0x0, start_ip, \
- (post_commit_ip) - (start_ip), abort_ip)
-
-/*
- * Define the @exit_ip pointer as an exit point for the sequence of consecutive
- * assembly instructions at @start_ip.
- *
- * @start_ip:
- * Pointer to the first instruction of the sequence of consecutive assembly
- * instructions.
- * @exit_ip:
- * Pointer to an exit point instruction.
- *
- * Exit points of a rseq critical section consist of all instructions outside
- * of the critical section where a critical section can either branch to or
- * reach through the normal course of its execution. The abort IP and the
- * post-commit IP are already part of the __rseq_cs section and should not be
- * explicitly defined as additional exit points. Knowing all exit points is
- * useful to assist debuggers stepping over the critical section.
- */
-#define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
- ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(start_ip)) "\n\t" \
- RSEQ_ASM_U64_PTR(__rseq_str(exit_ip)) "\n\t" \
- ".popsection\n\t"
+/* Common architecture support macros. */
+#include "rseq/arch/generic/common.h"
/*
* Define a critical section abort handler.
@@ -217,6 +134,33 @@ do { \
"jmp %l[" __rseq_str(target_label) "]\n\t" \
".popsection\n\t"
+/*
+ * Store the address of the critical section descriptor structure at
+ * @cs_label into the @rseq_cs pointer and emit the label @label, which
+ * is the beginning of the sequence of consecutive assembly instructions.
+ *
+ * @label:
+ * Local label to the beginning of the sequence of consecutive assembly
+ * instructions.
+ * @cs_label:
+ * Source local label to the critical section descriptor structure.
+ * @rseq_cs:
+ * Destination pointer where to store the address of the critical
+ * section descriptor structure.
+ */
+#ifdef RSEQ_ARCH_AMD64
+#define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
+ RSEQ_INJECT_ASM(1) \
+ "leaq " __rseq_str(cs_label) "(%%rip), %%rax\n\t" \
+ "movq %%rax, " __rseq_str(rseq_cs) "\n\t" \
+ __rseq_str(label) ":\n\t"
+#else
+# define RSEQ_ASM_STORE_RSEQ_CS(label, cs_label, rseq_cs) \
+ RSEQ_INJECT_ASM(1) \
+ "movl $" __rseq_str(cs_label) ", " __rseq_str(rseq_cs) "\n\t" \
+ __rseq_str(label) ":\n\t"
+#endif
+
/* Jump to local label @label when @cpu_id != @current_cpu_id. */
#define RSEQ_ASM_CBNE_CPU_ID(cpu_id, current_cpu_id, label) \
RSEQ_INJECT_ASM(2) \