From 720818293b1124c2378f115f446ecc73f69b441a Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 10 Nov 2025 07:20:14 +0000 Subject: [PATCH 1/2] change the inline asm and modify cp_ca[] to cap_x[0/1] --- .gitignore | 2 +- coroutine/ucontext/Context.h | 13 +++++++++++-- internal/gc.h | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6818cddb..b7c74037 100644 --- a/.gitignore +++ b/.gitignore @@ -169,7 +169,7 @@ lcov*.info !/coroutine/**/*.S # /enc/trans/ -/enc/trans/*.c +# /enc/trans/*.c /enc/trans/*.def /enc/trans/*.exp /enc/trans/*.lib diff --git a/coroutine/ucontext/Context.h b/coroutine/ucontext/Context.h index 9801e189..a35960f0 100644 --- a/coroutine/ucontext/Context.h +++ b/coroutine/ucontext/Context.h @@ -56,8 +56,17 @@ static inline void coroutine_initialize( context->state.uc_link = NULL; makecontext(&context->state, (void(*)(void))coroutine_trampoline, 2, (void*)start, (void*)context); - context->state.uc_mcontext.mc_capregs.cp_ca[0] = (__uintcap_t) start; - context->state.uc_mcontext.mc_capregs.cp_ca[1] = (__uintcap_t) context; +#if defined(__CHERI_PURE_CAPABILITY__) +#if defined(__riscv) + context->state.uc_mcontext.mc_capregs.cp_ca[0] = (__uintcap_t) start; + context->state.uc_mcontext.mc_capregs.cp_ca[1] = (__uintcap_t) context; +#elif defined(__aarch64__) + context->state.uc_mcontext.mc_capregs.cap_x[0] = (__uintcap_t) start; + context->state.uc_mcontext.mc_capregs.cap_x[1] = (__uintcap_t) context; +#else +#error "Unsupported CHERI architecture for coroutine arguments" +#endif +#endif } static inline struct coroutine_context * coroutine_transfer(struct coroutine_context * current, struct coroutine_context * target) diff --git a/internal/gc.h b/internal/gc.h index 949d193f..2e56511d 100644 --- a/internal/gc.h +++ b/internal/gc.h @@ -20,7 +20,9 @@ # define USE_MODULAR_GC 0 #endif -#if defined(__x86_64__) && !defined(_ILP32) && defined(__GNUC__) +#if defined(__CHERI_PURE_CAPABILITY__) && defined(__GNUC__) +#define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mov\t%0, csp" : "=C" (*(p))) +#elif defined(__x86_64__) && !defined(_ILP32) && defined(__GNUC__) #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("movq\t%%rsp, %0" : "=r" (*(p))) #elif defined(__i386) && defined(__GNUC__) #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("movl\t%%esp, %0" : "=r" (*(p))) @@ -32,8 +34,6 @@ #define SET_MACHINE_STACK_END(p) __asm__ volatile("mr %0, r1" : "=r" (*(p))) #elif defined(__aarch64__) && defined(__GNUC__) #define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("mov\t%0, sp" : "=r" (*(p))) -#elif defined(__CHERI_PURE_CAPABILITY__) -#define SET_MACHINE_STACK_END(p) __asm__ __volatile__ ("cmove\t%0, csp" : "=C" (*(p))) #else NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p)); #define SET_MACHINE_STACK_END(p) rb_gc_set_stack_end(p) From b9b8cb749f41707bbeb4ef5555de468adc9eb4ca Mon Sep 17 00:00:00 2001 From: Kai Date: Mon, 10 Nov 2025 07:30:21 +0000 Subject: [PATCH 2/2] add missing file --- enc/trans/transdb.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 enc/trans/transdb.c diff --git a/enc/trans/transdb.c b/enc/trans/transdb.c new file mode 100644 index 00000000..358a3f3f --- /dev/null +++ b/enc/trans/transdb.c @@ -0,0 +1,17 @@ +/********************************************************************** + + enc/trans/transdb.c - + + Copyright (C) 2008 Yukihiro Matsumoto + +**********************************************************************/ + +#include "ruby.h" + +void rb_declare_transcoder(const char *enc1, const char *enc2, const char *lib); + +void +Init_transdb(void) +{ +#include "transdb.h" +}