Skip to content

zmq::thread_t::applySchedulingParameters() crash with musl-libc. #3162

Closed
@ilue

Description

@ilue

Issue description

zmq::thread_t::applySchedulingParameters() call to some pthread functions using the descriptor member, which may be uninitialized if the new thread start before pthread_create return (musl-libc's pthread_create set the descriptor after starting the thread, while glibc just works beacuse the descriptor was set before the thread starts). May be use pthread_set() instead for compatibility?

Environment

  • libzmq version (commit hash if unreleased): 4.2.5
  • OS: linux (with musl enabled gcc)
  • libzmq configure arguments: --build=x86_64-linux-gnu --host=x86_64-unknown-linux-musl --enable-static --disable-shared --disable-libunwind --without-docs CXXFLAGS='-static' LDFLAGS='--static'

Minimal test code / Steps to reproduce the issue

#include <zmq.h>

int main(int argc, char* argv[])
{
    void* ctx = zmq_ctx_new();
    void* s = zmq_socket(ctx, ZMQ_PUB);
    zmq_close(s);
    zmq_ctx_term(ctx);
    return 0;
}
compile with:
x86_64-unknown-linux-musl-g++ -static -Wall -O3 -g -I ~/zeromq-4.2.5/include test.cpp -L ~/zeromq-4.2.5/src/.libs -lzmq

What's the actual result? (include assertion message & call stack if applicable)

SIGSEGV.

#0  0x000000000050e4e5 in a_cas (s=-2147483647, t=0, p=0xd0)
    at /home/ilue/crosstool-ng/.build/x86_64-unknown-linux-musl/src/musl/arch/x86_64/atomic_arch.h:4
#1  __lock (l=l@entry=0xd0) at /home/ilue/crosstool-ng/.build/x86_64-unknown-linux-musl/src/musl/src/thread/__lock.c:23
#2  0x000000000050f38b in pthread_getschedparam (t=0x0, policy=0x7ffff7ff9d7c, param=0x7ffff7ff9d40)
    at /home/ilue/crosstool-ng/.build/x86_64-unknown-linux-musl/src/musl/src/thread/pthread_getschedparam.c:6
#3  0x0000000000436f68 in zmq::thread_t::applySchedulingParameters() ()
#4  0x0000000000436d6c in thread_routine ()
#5  0x000000000050ee87 in start (p=0x7ffff7ff9ee8)
    at /home/ilue/crosstool-ng/.build/x86_64-unknown-linux-musl/src/musl/src/thread/pthread_create.c:150
#6  0x000000000050fb73 in __clone ()
    at /home/ilue/crosstool-ng/.build/x86_64-unknown-linux-musl/src/musl/src/thread/x86_64/clone.s:21
#7  0x0000000000000001 in ?? ()
#8  0x00007ffff7ff9ed8 in ?? ()
#9  0x0000000000000000 in ?? ()

What's the expected result?

Exit normally.

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