summaryrefslogtreecommitdiff
path: root/src/lib/libc/include
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/include')
-rw-r--r--src/lib/libc/include/namespace.h8
-rw-r--r--src/lib/libc/include/thread_private.h66
2 files changed, 69 insertions, 5 deletions
diff --git a/src/lib/libc/include/namespace.h b/src/lib/libc/include/namespace.h
index 8503de47be..cc83735b90 100644
--- a/src/lib/libc/include/namespace.h
+++ b/src/lib/libc/include/namespace.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: namespace.h,v 1.16 2023/10/29 14:26:13 millert Exp $ */ 1/* $OpenBSD: namespace.h,v 1.17 2025/10/23 19:06:10 miod Exp $ */
2 2
3#ifndef _LIBC_NAMESPACE_H_ 3#ifndef _LIBC_NAMESPACE_H_
4#define _LIBC_NAMESPACE_H_ 4#define _LIBC_NAMESPACE_H_
@@ -57,13 +57,13 @@
57#define DEF_WRAP(x) __weak_alias(x, WRAP(x)) 57#define DEF_WRAP(x) __weak_alias(x, WRAP(x))
58#define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x)) 58#define DEF_SYS(x) __strong_alias(_thread_sys_##x, HIDDEN(x))
59 59
60#if !defined(__clang__) && __GNUC__ != 3 60#if !defined(__clang__)
61/* our gcc 4.2 handles redirecting builtins via PROTO_NORMAL()'s asm() label */ 61/* our gcc 4.2 handles redirecting builtins via PROTO_NORMAL()'s asm() label */
62#define DEF_BUILTIN(x) DEF_STRONG(x) 62#define DEF_BUILTIN(x) DEF_STRONG(x)
63#define BUILTIN 63#define BUILTIN
64#else 64#else
65/* 65/*
66 * clang and gcc can't redirect builtins via asm() labels, so mark 66 * clang can't redirect builtins via asm() labels, so mark
67 * them protected instead. 67 * them protected instead.
68 */ 68 */
69#define DEF_BUILTIN(x) __asm("") 69#define DEF_BUILTIN(x) __asm("")
@@ -86,7 +86,7 @@ BUILTIN void *memmove(void *, const void *, __size_t);
86BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); 86BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t);
87BUILTIN void *memset(void *, int, __size_t); 87BUILTIN void *memset(void *, int, __size_t);
88BUILTIN void __stack_smash_handler(const char [], int __unused); 88BUILTIN void __stack_smash_handler(const char [], int __unused);
89#if !defined(__clang__) && __GNUC__ != 3 89#if !defined(__clang__)
90PROTO_NORMAL(memmove); 90PROTO_NORMAL(memmove);
91PROTO_NORMAL(memcpy); 91PROTO_NORMAL(memcpy);
92PROTO_NORMAL(memset); 92PROTO_NORMAL(memset);
diff --git a/src/lib/libc/include/thread_private.h b/src/lib/libc/include/thread_private.h
index 1ec1071161..3e1dbcdf6e 100644
--- a/src/lib/libc/include/thread_private.h
+++ b/src/lib/libc/include/thread_private.h
@@ -1,10 +1,13 @@
1/* $OpenBSD: thread_private.h,v 1.37 2024/08/18 02:25:51 guenther Exp $ */ 1/* $OpenBSD: thread_private.h,v 1.40 2025/08/04 01:44:33 dlg Exp $ */
2 2
3/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */ 3/* PUBLIC DOMAIN: No Rights Reserved. Marco S Hyman <marc@snafu.org> */
4 4
5#ifndef _THREAD_PRIVATE_H_ 5#ifndef _THREAD_PRIVATE_H_
6#define _THREAD_PRIVATE_H_ 6#define _THREAD_PRIVATE_H_
7 7
8#include <sys/types.h>
9#include <sys/gmon.h>
10
8extern int __isthreaded; 11extern int __isthreaded;
9 12
10#define _MALLOC_MUTEXES 32 13#define _MALLOC_MUTEXES 32
@@ -292,6 +295,12 @@ TAILQ_HEAD(pthread_queue, pthread);
292 295
293#ifdef FUTEX 296#ifdef FUTEX
294 297
298/*
299 * CAS based implementations
300 */
301
302#define __CMTX_CAS
303
295struct pthread_mutex { 304struct pthread_mutex {
296 volatile unsigned int lock; 305 volatile unsigned int lock;
297 int type; 306 int type;
@@ -312,6 +321,10 @@ struct pthread_rwlock {
312 321
313#else 322#else
314 323
324/*
325 * spinlock based implementations
326 */
327
315struct pthread_mutex { 328struct pthread_mutex {
316 _atomic_lock_t lock; 329 _atomic_lock_t lock;
317 struct pthread_queue lockers; 330 struct pthread_queue lockers;
@@ -336,6 +349,46 @@ struct pthread_rwlock {
336}; 349};
337#endif /* FUTEX */ 350#endif /* FUTEX */
338 351
352/* libc mutex */
353
354#define __CMTX_UNLOCKED 0
355#define __CMTX_LOCKED 1
356#define __CMTX_CONTENDED 2
357
358#ifdef __CMTX_CAS
359struct __cmtx {
360 volatile unsigned int lock;
361};
362
363#define __CMTX_INITIALIZER() { \
364 .lock = __CMTX_UNLOCKED, \
365}
366#else /* __CMTX_CAS */
367struct __cmtx {
368 _atomic_lock_t spin;
369 volatile unsigned int lock;
370};
371
372#define __CMTX_INITIALIZER() { \
373 .spin = _SPINLOCK_UNLOCKED, \
374 .lock = __CMTX_UNLOCKED, \
375}
376#endif /* __CMTX_CAS */
377
378/* libc recursive mutex */
379
380struct __rcmtx {
381 volatile pthread_t owner;
382 struct __cmtx mtx;
383 unsigned int depth;
384};
385
386#define __RCMTX_INITIALIZER() { \
387 .owner = NULL, \
388 .mtx = __CMTX_INITIALIZER(), \
389 .depth = 0, \
390}
391
339struct pthread_mutex_attr { 392struct pthread_mutex_attr {
340 int ma_type; 393 int ma_type;
341 int ma_protocol; 394 int ma_protocol;
@@ -390,6 +443,7 @@ struct pthread {
390 443
391 /* cancel received in a delayed cancel block? */ 444 /* cancel received in a delayed cancel block? */
392 int delayed_cancel; 445 int delayed_cancel;
446 struct gmonparam *gmonparam;
393}; 447};
394/* flags in pthread->flags */ 448/* flags in pthread->flags */
395#define THREAD_DONE 0x001 449#define THREAD_DONE 0x001
@@ -410,6 +464,16 @@ void _spinlock(volatile _atomic_lock_t *);
410int _spinlocktry(volatile _atomic_lock_t *); 464int _spinlocktry(volatile _atomic_lock_t *);
411void _spinunlock(volatile _atomic_lock_t *); 465void _spinunlock(volatile _atomic_lock_t *);
412 466
467void __cmtx_init(struct __cmtx *);
468int __cmtx_enter_try(struct __cmtx *);
469void __cmtx_enter(struct __cmtx *);
470void __cmtx_leave(struct __cmtx *);
471
472void __rcmtx_init(struct __rcmtx *);
473int __rcmtx_enter_try(struct __rcmtx *);
474void __rcmtx_enter(struct __rcmtx *);
475void __rcmtx_leave(struct __rcmtx *);
476
413void _rthread_debug(int, const char *, ...) 477void _rthread_debug(int, const char *, ...)
414 __attribute__((__format__ (printf, 2, 3))); 478 __attribute__((__format__ (printf, 2, 3)));
415pid_t _thread_dofork(pid_t (*_sys_fork)(void)); 479pid_t _thread_dofork(pid_t (*_sys_fork)(void));