mips: Reorganise code deduplication macros
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Feb 2024 21:12:19 +0000 (16:12 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 28 Feb 2024 21:54:25 +0000 (16:54 -0500)
Introduce RSEQ_ASM_U64_PTR() which expresses the type and instance
of the defined variable.

Separate the RSEQ_ASM_LONG* macros from the 64-bit pointer types, as
those two are unrelated. Having them in the same vincinity is
misleading.

Test on RSEQ_BITS_PER_LONG rather than _MIPS_SZLONG to make it
consistent across architectures.

Use both __BYTE_ORDER and __BIG_ENDIAN to detect byte order.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I1a65210e9ab0c00a5625c9feba7971081eb34c35

include/rseq/arch/mips.h

index dd877c1da000464da59ea295600eaa1489a15db0..9bb00f5525ba856986d3636e985edc3e5250f7cb 100644 (file)
 #error "Never use <rseq/arch/mips.h> directly; include <rseq/rseq.h> instead."
 #endif
 
+#include <asm/byteorder.h>
+
 /*
  * RSEQ_ASM_*() macro helpers are internal to the librseq headers. Those
  * are not part of the public API.
  */
 
+#if (RSEQ_BITS_PER_LONG != 64) && (RSEQ_BITS_PER_LONG != 32)
+# error unsupported RSEQ_BITS_PER_LONG
+#endif
+
 /*
  * RSEQ_SIG uses the break instruction. The instruction pattern is:
  *
@@ -80,29 +86,35 @@ do {                                                                        \
 } while (0)
 
 /*
- * Helper macros to define and access a variable of pointer type stored
- * in a 64-bit integer. Only used internally in rseq headers.
+ * Helper macros to define and access a variable of long integer type.
+ * Only used internally in rseq headers.
  */
-#if _MIPS_SZLONG == 64
+#if RSEQ_BITS_PER_LONG == 64
 # define RSEQ_ASM_LONG                 ".dword"
 # define RSEQ_ASM_LONG_LA              "dla"
 # define RSEQ_ASM_LONG_L               "ld"
 # define RSEQ_ASM_LONG_S               "sd"
 # define RSEQ_ASM_LONG_ADDI            "daddiu"
-# define RSEQ_ASM_U32_U64_PAD(x)       x
-#elif _MIPS_SZLONG == 32
+#else
 # define RSEQ_ASM_LONG                 ".word"
 # define RSEQ_ASM_LONG_LA              "la"
 # define RSEQ_ASM_LONG_L               "lw"
 # define RSEQ_ASM_LONG_S               "sw"
 # define RSEQ_ASM_LONG_ADDI            "addiu"
-# ifdef __BIG_ENDIAN
-#  define RSEQ_ASM_U32_U64_PAD(x)      "0x0, " x
+#endif
+
+/*
+ * Helper macros to define a variable of pointer type stored in a 64-bit
+ * integer. Only used internally in rseq headers.
+ */
+#if RSEQ_BITS_PER_LONG == 64
+# define RSEQ_ASM_U64_PTR(x)           ".dword " x
+#else
+# if defined(__BYTE_ORDER) ? (__BYTE_ORDER == __BIG_ENDIAN) : defined(__BIG_ENDIAN)
+#  define RSEQ_ASM_U64_PTR(x)          ".word 0x0, " x
 # else
-#  define RSEQ_ASM_U32_U64_PAD(x)      x ", 0x0"
+#  define RSEQ_ASM_U64_PTR(x)          ".word " x ", 0x0"
 # endif
-#else
-# error unsupported _MIPS_SZLONG
 #endif
 
 /* Only used in RSEQ_ASM_DEFINE_TABLE. */
@@ -112,12 +124,12 @@ do {                                                                      \
                ".balign 32\n\t" \
                __rseq_str(label) ":\n\t" \
                ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(post_commit_offset)) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(abort_ip)) "\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_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(label) "b") "\n\t" \
+               RSEQ_ASM_U64_PTR(__rseq_str(label) "b") "\n\t" \
                ".popsection\n\t"
 
 /*
@@ -159,8 +171,8 @@ do {                                                                        \
  */
 #define RSEQ_ASM_DEFINE_EXIT_POINT(start_ip, exit_ip) \
                ".pushsection __rseq_exit_point_array, \"aw\"\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(exit_ip)) "\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"
 
 /* Only used in RSEQ_ASM_DEFINE_ABORT. */
@@ -170,9 +182,9 @@ do {                                                                        \
                ".balign 32\n\t" \
                __rseq_str(table_label) ":\n\t" \
                ".word " __rseq_str(version) ", " __rseq_str(flags) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(start_ip)) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(post_commit_offset)) "\n\t" \
-               RSEQ_ASM_LONG " " RSEQ_ASM_U32_U64_PAD(__rseq_str(abort_ip)) "\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" \
                ".word " __rseq_str(RSEQ_SIG) "\n\t" \
                __rseq_str(label) ":\n\t" \
                teardown \
This page took 0.02784 seconds and 4 git commands to generate.