Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 11 Jan 2025 19:35:51 -0800
From:      Yuri <yuri@FreeBSD.org>
To:        Freebsd hackers list <freebsd-hackers@FreeBSD.org>
Subject:   pthread_mutex_trylock crashes because _get_curthread() returns null
Message-ID:  <cf547d6a-fcee-4629-87d4-41e0da63dd79@FreeBSD.org>

next in thread | raw e-mail | index | archive | help
I am trying to understand this crash:

614│ int
615│ __Tthr_mutex_trylock(pthread_mutex_t *mutex)
616│ {
617│         struct pthread *curthread;
618│         struct pthread_mutex *m;
619│         uint32_t id;
620│         int ret, robust;
621│
622│         ret = check_and_init_mutex(mutex, &m);
623│         if (ret != 0)
624│                 return (ret);
625│         curthread = _get_curthread();
626│         id = TID(curthread);
627│         if (m->m_flags & PMUTEX_FLAG_PRIVATE)
628├───────────────> THR_CRITICAL_ENTER(curthread);

Program received signal SIGSEGV, Segmentation fault.
Address not mapped to object.
__Tthr_mutex_trylock (mutex=<optimized out>) at 
/disk-samsung/freebsd-src/lib/libthr/thread/thr_mutex.c:628
628                     THR_CRITICAL_ENTER(curthread);

The crash occurs at the program startup within the 
pthread_mutex_trylock() function.

The immediate cause is that _get_curthread() returned null in curthread.


Testcase: the port databases/qdrant at rev. 
e7cee8d22daf5b6360238cad603ca9f96ecd87fd (at version 1.12.5).


How can it be that _get_curthread() returns null?

Shouldn't current thread be always defined?


14.2-STABLE


Thanks,

Yuri





Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?cf547d6a-fcee-4629-87d4-41e0da63dd79>