@@ -68,7 +68,7 @@ typedef enum {
/* This is the data structure we pass over the socket for OP_COMPARE
* and OP_TESTEND. It is a simplified and reduced subset of what can
- * be obtained with a ucontext_t*, and is architecture specific
+ * be obtained with a ucontext_t, and is architecture specific
* (defined in risu_reginfo_*.h).
*/
struct reginfo;
@@ -93,14 +93,14 @@ void send_response_byte(int sock, int resp);
/* Interface provided by CPU-specific code: */
-/* Move the PC past this faulting insn by adjusting ucontext. */
-void advance_pc(void *uc);
+/* Move the PC past this faulting insn by adjusting signal context. */
+void advance_pc(host_context_t *hc);
-/* Set the parameter register in a ucontext_t to the specified value.
+/*
+ * Set the parameter register in a host_context_t to the specified value.
* (32-bit targets can ignore high 32 bits.)
- * vuc is a ucontext_t* cast to void*.
*/
-void set_ucontext_paramreg(void *vuc, uint64_t value);
+void set_ucontext_paramreg(host_context_t *hc, uint64_t value);
/* Return the value of the parameter register from a reginfo. */
uint64_t get_reginfo_paramreg(struct reginfo *ri);
@@ -114,8 +114,8 @@ RisuOp get_risuop(struct reginfo *ri);
/* Return the PC from a reginfo */
uintptr_t get_pc(struct reginfo *ri);
-/* initialize structure from a ucontext */
-void reginfo_init(struct reginfo *ri, ucontext_t *uc, void *siaddr);
+/* initialize structure from a host_context_t. */
+void reginfo_init(struct reginfo *ri, host_context_t *hc, void *siaddr);
/* return true if structs are equal, false otherwise. */
bool reginfo_is_eq(struct reginfo *r1, struct reginfo *r2);
@@ -15,6 +15,8 @@
#include <signal.h>
+typedef ucontext_t host_context_t;
+
/* The kernel headers set this based on future arch extensions.
The current arch maximum is 16. Save space below. */
#undef SVE_VQ_MAX
@@ -13,6 +13,8 @@
#ifndef RISU_REGINFO_ARM_H
#define RISU_REGINFO_ARM_H
+typedef ucontext_t host_context_t;
+
struct reginfo {
uint64_t fpregs[32];
uint32_t faulting_insn;
@@ -12,6 +12,8 @@
#ifndef RISU_REGINFO_I386_H
#define RISU_REGINFO_I386_H
+typedef ucontext_t host_context_t;
+
struct avx512_reg {
uint64_t q[8];
};
@@ -12,6 +12,9 @@
#ifndef RISU_REGINFO_LOONGARCH64_H
#define RISU_REGINFO_LOONGARCH64_H
+/* From kernel <asm/ucontext.h> not libc <ucontext.h>. */
+typedef struct ucontext host_context_t;
+
struct reginfo {
uint64_t regs[32];
uint64_t pc;
@@ -9,6 +9,8 @@
#ifndef RISU_REGINFO_M68K_H
#define RISU_REGINFO_M68K_H
+typedef ucontext_t host_context_t;
+
struct reginfo {
uint32_t faulting_insn;
uint32_t pc;
@@ -14,6 +14,8 @@
#ifndef RISU_REGINFO_PPC64LE_H
#define RISU_REGINFO_PPC64LE_H
+typedef ucontext_t host_context_t;
+
struct reginfo {
uint32_t faulting_insn;
uint32_t prev_insn;
@@ -12,6 +12,8 @@
#ifndef RISU_REGINFO_S390X_H
#define RISU_REGINFO_S390X_H
+typedef ucontext_t host_context_t;
+
struct reginfo {
uint64_t psw_mask;
uint64_t pc_offset;
@@ -12,15 +12,13 @@
#include "risu.h"
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.pc += 4;
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.regs[0] = value;
}
@@ -38,16 +38,13 @@ int insnsize(ucontext_t *uc)
return 4;
}
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.arm_pc += insnsize(uc);
}
-
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.arm_r0 = value;
}
@@ -16,10 +16,8 @@
#include "risu.h"
#include "risu_reginfo_i386.h"
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
- ucontext_t *uc = (ucontext_t *) vuc;
-
/*
* We assume that this is UD1 as per get_risuop below.
* This would need tweaking if we want to test expected undefs.
@@ -27,9 +25,8 @@ void advance_pc(void *vuc)
uc->uc_mcontext.gregs[REG_E(IP)] += 3;
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = (ucontext_t *) vuc;
uc->uc_mcontext.gregs[REG_E(AX)] = value;
}
@@ -15,15 +15,13 @@
#include "risu.h"
-void advance_pc(void *vuc)
+void advance_pc(host_context_t *uc)
{
- struct ucontext *uc = vuc;
uc->uc_mcontext.sc_pc += 4;
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(host_context_t *uc, uint64_t value)
{
- struct ucontext *uc = vuc;
uc->uc_mcontext.sc_regs[4] = value;
}
@@ -8,15 +8,13 @@
#include "risu.h"
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
- ucontext_t *uc = (ucontext_t *) vuc;
uc->uc_mcontext.gregs[R_PC] += 4;
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.gregs[R_A0] = value;
}
@@ -14,15 +14,13 @@
#include "risu.h"
#include <sys/user.h>
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
- ucontext_t *uc = (ucontext_t *) vuc;
uc->uc_mcontext.regs->nip += 4;
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.gp_regs[0] = value;
}
@@ -97,10 +97,9 @@ static int parse_extcontext(struct sigcontext *sc, struct extctx_layout *extctx)
}
/* reginfo_init: initialize with a ucontext */
-void reginfo_init(struct reginfo *ri, ucontext_t *context, void *siaddr)
+void reginfo_init(struct reginfo *ri, host_context_t *uc, void *siaddr)
{
int i;
- struct ucontext *uc = (struct ucontext *)context;
struct extctx_layout extctx;
memset(&extctx, 0, sizeof(struct extctx_layout));
@@ -13,7 +13,7 @@
#include "risu.h"
-void advance_pc(void *vuc)
+void advance_pc(ucontext_t *uc)
{
/*
* Note: The PSW address already points to the next instruction
@@ -21,9 +21,8 @@ void advance_pc(void *vuc)
*/
}
-void set_ucontext_paramreg(void *vuc, uint64_t value)
+void set_ucontext_paramreg(ucontext_t *uc, uint64_t value)
{
- ucontext_t *uc = vuc;
uc->uc_mcontext.gregs[0] = value;
}
Most hosts pass ucontext_t as the third parameter of signal handlers. In one existing usage, loongarch64 is using the kernel's struct ucontext instead of libc's ucontext_t. This is probably a simple mistake that could be fixed, but the structure member names differ, so the change would not be completely mechanical. However, due to a sequence of historical mistakes, sparc64 linux does not pass any kind of ucontext_t to the signal handler, but uses struct sigcontext instead. Prepare for that by adding a new indirection typedef. This allows us to clean up existing usage with void*. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> --- risu.h | 16 ++++++++-------- risu_reginfo_aarch64.h | 2 ++ risu_reginfo_arm.h | 2 ++ risu_reginfo_i386.h | 2 ++ risu_reginfo_loongarch64.h | 3 +++ risu_reginfo_m68k.h | 2 ++ risu_reginfo_ppc64.h | 2 ++ risu_reginfo_s390x.h | 2 ++ risu_aarch64.c | 6 ++---- risu_arm.c | 7 ++----- risu_i386.c | 7 ++----- risu_loongarch64.c | 6 ++---- risu_m68k.c | 6 ++---- risu_ppc64.c | 6 ++---- risu_reginfo_loongarch64.c | 3 +-- risu_s390x.c | 5 ++--- 16 files changed, 38 insertions(+), 39 deletions(-)