[Bug #21150] macOS: Temporary workaround at unwinding coroutine

On arm64 macOS, libunwind (both of system library and homebrew
llvm-18) seems not to handle our coroutine switching code.
This commit is contained in:
Nobuyoshi Nakada 2025-02-21 17:53:16 +09:00
parent d97884a58b
commit 1bc57b5e0e
No known key found for this signature in database
GPG Key ID: 3582D74E1FEE4465
Notes: git 2025-02-21 10:17:54 +00:00
3 changed files with 20 additions and 1 deletions

View File

@ -296,9 +296,11 @@ fill_filename(int file, uint8_t format, uint16_t version, const char *include_di
for (i = 1; i <= file; i++) {
filename = p;
if (!*p) {
#ifndef __APPLE__
/* Need to output binary file name? */
kprintf("Unexpected file number %d in %s at %tx\n",
file, binary_filename, filenames - obj->mapped);
#endif
return;
}
while (*p) p++;

View File

@ -429,7 +429,12 @@ native_thread_check_and_create_shared(rb_vm_t *vm)
}
}
static COROUTINE
#ifdef __APPLE__
# define co_start ruby_coroutine_start
#else
static
#endif
COROUTINE
co_start(struct coroutine_context *from, struct coroutine_context *self)
{
#ifdef RUBY_ASAN_ENABLED

View File

@ -510,6 +510,15 @@ rb_vmdebug_thread_dump_state(FILE *errout, VALUE self)
# include <libunwind.h>
# include <sys/mman.h>
# undef backtrace
static bool
is_coroutine_start(unw_word_t ip)
{
struct coroutine_context;
extern void ruby_coroutine_start(struct coroutine_context *, struct coroutine_context *);
return ((void *)(ip) == (void *)ruby_coroutine_start);
}
int
backtrace(void **trace, int size)
{
@ -617,6 +626,9 @@ darwin_sigtramp:
// I wish I could use "ptrauth_strip()" but I get an error:
// "this target does not support pointer authentication"
trace[n++] = (void *)(ip & 0x7fffffffffffull);
// Apple's libunwind can't handle our coroutine switching code
if (is_coroutine_start(ip)) break;
}
return n;
# endif