8000 Crash on OpenBSD (amd64) · Issue #27 · edubart/minicoro · GitHub
[go: up one dir, main page]

Skip to content

Crash on OpenBSD (amd64) #27

Open
Open

Description

@markand

Hi,

First of all, I love minicoro and was able to play with it on various systems with many architectures. I tried on my favorite of choice, OpenBSD (amd64 for now) and unfortunately as secure as it is I guess the current assembly code is not compatible with.

Trying a very minimal example ends with:

[a.out]25923/502807 sp=3fbcd3a2388 inside 7b6448f83000-7b6449382fff: not MAP_STACK
Segmentation fault (core dumped)

The core dump does not provide any useful information though:

(lldb) bt
* thread #1, stop reason = signal SIGSEGV
  * frame #0: 0x00000fddd963b909 ld.so`_dl_bind(object=0x00000fde64344800, index=<unavailable>) at rtld_machine.c:352:13
    frame #1: 0x00000fddd9643421 ld.so`_dl_bind_start at ldasm.S:107
    frame #2: 0x00000fdb9d46ba98 a.out`entrypoint(self=0x00000fde7e04e000) at test.c:9:2
    frame #3: 0x00000fdb9d46bb78 a.out`_mco_main(co=0x00000fde7e04e000) at minicoro.h:622:3

I don't really know how to make context switch in assembly so I'll not be able to help. However, I've seen various others doing less performant alternatives based on setjmp/longjmp as last resort. Not sure if that could make for asymmetric coroutines but I'll have a look as temporary fix if possible

Activity

  1. markand commented on Jan 7, 2026

    @markand
    Author

    Okay, it was finally was easier than I thought. On OpenBSD mmap must be used and MAP_STACK provided as argument. I'm thinking of a diff like:

    --- a/minicoro.h  Wed Jan  7 13:18:48 2026
    +++ b/minicoro.h       Wed Jan  7 13:16:19 2026
    @@ -483,6 +483,14 @@
       #include <windows.h>
     #endif
    
    +#if defined(__OpenBSD__)
    +  #define MCO_USE_VMEM_ALLOCATOR
    +#else
    +  #if !defined(MAP_STACK)
    +    #define MAP_STACK 0
    +  #endif
    +#endif
    +
     #ifndef MCO_NO_DEFAULT_ALLOCATOR
       #if defined(MCO_USE_VMEM_ALLOCATOR) && defined(_WIN32)
         static void* mco_alloc(size_t size, void* allocator_data) {
    @@ -500,7 +508,7 @@
         #include <sys/mman.h>
         static void* mco_alloc(size_t size, void* allocator_data) {
           _MCO_UNUSED(allocator_data);
    -      void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
    +      void *ptr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_STACK | MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
           return ptr != MAP_FAILED ? ptr : NULL;
         }
         static void mco_dealloc(void* ptr, size_t size, void* allocator_data) {
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0