diff options
Diffstat (limited to 'src/lib/libc')
24 files changed, 294 insertions, 158 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); | |||
| 86 | BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); | 86 | BUILTIN void *memcpy(void *__restrict, const void *__restrict, __size_t); |
| 87 | BUILTIN void *memset(void *, int, __size_t); | 87 | BUILTIN void *memset(void *, int, __size_t); |
| 88 | BUILTIN void __stack_smash_handler(const char [], int __unused); | 88 | BUILTIN void __stack_smash_handler(const char [], int __unused); |
| 89 | #if !defined(__clang__) && __GNUC__ != 3 | 89 | #if !defined(__clang__) |
| 90 | PROTO_NORMAL(memmove); | 90 | PROTO_NORMAL(memmove); |
| 91 | PROTO_NORMAL(memcpy); | 91 | PROTO_NORMAL(memcpy); |
| 92 | PROTO_NORMAL(memset); | 92 | PROTO_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 | |||
| 8 | extern int __isthreaded; | 11 | extern 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 | |||
| 295 | struct pthread_mutex { | 304 | struct 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 | |||
| 315 | struct pthread_mutex { | 328 | struct 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 | ||
| 359 | struct __cmtx { | ||
| 360 | volatile unsigned int lock; | ||
| 361 | }; | ||
| 362 | |||
| 363 | #define __CMTX_INITIALIZER() { \ | ||
| 364 | .lock = __CMTX_UNLOCKED, \ | ||
| 365 | } | ||
| 366 | #else /* __CMTX_CAS */ | ||
| 367 | struct __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 | |||
| 380 | struct __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 | |||
| 339 | struct pthread_mutex_attr { | 392 | struct 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 *); | |||
| 410 | int _spinlocktry(volatile _atomic_lock_t *); | 464 | int _spinlocktry(volatile _atomic_lock_t *); |
| 411 | void _spinunlock(volatile _atomic_lock_t *); | 465 | void _spinunlock(volatile _atomic_lock_t *); |
| 412 | 466 | ||
| 467 | void __cmtx_init(struct __cmtx *); | ||
| 468 | int __cmtx_enter_try(struct __cmtx *); | ||
| 469 | void __cmtx_enter(struct __cmtx *); | ||
| 470 | void __cmtx_leave(struct __cmtx *); | ||
| 471 | |||
| 472 | void __rcmtx_init(struct __rcmtx *); | ||
| 473 | int __rcmtx_enter_try(struct __rcmtx *); | ||
| 474 | void __rcmtx_enter(struct __rcmtx *); | ||
| 475 | void __rcmtx_leave(struct __rcmtx *); | ||
| 476 | |||
| 413 | void _rthread_debug(int, const char *, ...) | 477 | void _rthread_debug(int, const char *, ...) |
| 414 | __attribute__((__format__ (printf, 2, 3))); | 478 | __attribute__((__format__ (printf, 2, 3))); |
| 415 | pid_t _thread_dofork(pid_t (*_sys_fork)(void)); | 479 | pid_t _thread_dofork(pid_t (*_sys_fork)(void)); |
diff --git a/src/lib/libc/net/ether_aton.3 b/src/lib/libc/net/ether_aton.3 index 98562dc44c..83fe98880c 100644 --- a/src/lib/libc/net/ether_aton.3 +++ b/src/lib/libc/net/ether_aton.3 | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | .\" $OpenBSD: ether_aton.3,v 1.3 2022/09/11 06:38:10 jmc Exp $ | 1 | .\" $OpenBSD: ether_aton.3,v 1.4 2025/06/29 00:33:46 dlg Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Written by roland@frob.com. Public domain. | 3 | .\" Written by roland@frob.com. Public domain. |
| 4 | .\" | 4 | .\" |
| 5 | .Dd $Mdocdate: September 11 2022 $ | 5 | .Dd $Mdocdate: June 29 2025 $ |
| 6 | .Dt ETHER_ATON 3 | 6 | .Dt ETHER_ATON 3 |
| 7 | .Os | 7 | .Os |
| 8 | .Sh NAME | 8 | .Sh NAME |
| @@ -19,7 +19,7 @@ | |||
| 19 | .In netinet/in.h | 19 | .In netinet/in.h |
| 20 | .In netinet/if_ether.h | 20 | .In netinet/if_ether.h |
| 21 | .Ft char * | 21 | .Ft char * |
| 22 | .Fn ether_ntoa "struct ether_addr *e" | 22 | .Fn ether_ntoa "const struct ether_addr *e" |
| 23 | .Ft struct ether_addr * | 23 | .Ft struct ether_addr * |
| 24 | .Fn ether_aton "const char *s" | 24 | .Fn ether_aton "const char *s" |
| 25 | .Ft int | 25 | .Ft int |
diff --git a/src/lib/libc/net/ethers.c b/src/lib/libc/net/ethers.c index d62be1ca71..6edad5c5e5 100644 --- a/src/lib/libc/net/ethers.c +++ b/src/lib/libc/net/ethers.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: ethers.c,v 1.27 2019/01/25 00:19:25 millert Exp $ */ | 1 | /* $OpenBSD: ethers.c,v 1.28 2025/06/29 00:33:46 dlg Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1998 Todd C. Miller <millert@openbsd.org> | 4 | * Copyright (c) 1998 Todd C. Miller <millert@openbsd.org> |
| @@ -42,7 +42,7 @@ | |||
| 42 | static char * _ether_aton(const char *, struct ether_addr *); | 42 | static char * _ether_aton(const char *, struct ether_addr *); |
| 43 | 43 | ||
| 44 | char * | 44 | char * |
| 45 | ether_ntoa(struct ether_addr *e) | 45 | ether_ntoa(const struct ether_addr *e) |
| 46 | { | 46 | { |
| 47 | static char a[] = "xx:xx:xx:xx:xx:xx"; | 47 | static char a[] = "xx:xx:xx:xx:xx:xx"; |
| 48 | 48 | ||
diff --git a/src/lib/libc/net/freeaddrinfo.c b/src/lib/libc/net/freeaddrinfo.c index 154f70cd75..c06318fb75 100644 --- a/src/lib/libc/net/freeaddrinfo.c +++ b/src/lib/libc/net/freeaddrinfo.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: freeaddrinfo.c,v 1.9 2016/09/21 04:38:56 guenther Exp $ */ | 1 | /* $OpenBSD: freeaddrinfo.c,v 1.10 2025/12/08 13:30:08 jca Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, All rights reserved. | 4 | * Copyright (c) 1996, 1997, 1998, 1999, Craig Metz, All rights reserved. |
| @@ -40,11 +40,15 @@ freeaddrinfo(struct addrinfo *ai) | |||
| 40 | { | 40 | { |
| 41 | struct addrinfo *p; | 41 | struct addrinfo *p; |
| 42 | 42 | ||
| 43 | do { | 43 | /* |
| 44 | * Calling freeaddrinfo() with a NULL pointer is unspecified, | ||
| 45 | * but try to cope with it anyway for compatibility. | ||
| 46 | */ | ||
| 47 | while (ai != NULL) { | ||
| 44 | p = ai; | 48 | p = ai; |
| 45 | ai = ai->ai_next; | 49 | ai = ai->ai_next; |
| 46 | free(p->ai_canonname); | 50 | free(p->ai_canonname); |
| 47 | free(p); | 51 | free(p); |
| 48 | } while (ai); | 52 | } |
| 49 | } | 53 | } |
| 50 | DEF_WEAK(freeaddrinfo); | 54 | DEF_WEAK(freeaddrinfo); |
diff --git a/src/lib/libc/net/gai_strerror.3 b/src/lib/libc/net/gai_strerror.3 index d271f492c5..93d11aad09 100644 --- a/src/lib/libc/net/gai_strerror.3 +++ b/src/lib/libc/net/gai_strerror.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: gai_strerror.3,v 1.10 2017/05/03 01:58:33 deraadt Exp $ | 1 | .\" $OpenBSD: gai_strerror.3,v 1.11 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $ | 2 | .\" $KAME: gai_strerror.3,v 1.1 2005/01/05 03:04:47 itojun Exp $ |
| 3 | .\" | 3 | .\" |
| 4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | 4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") |
| @@ -16,7 +16,7 @@ | |||
| 16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | 16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 17 | .\" PERFORMANCE OF THIS SOFTWARE. | 17 | .\" PERFORMANCE OF THIS SOFTWARE. |
| 18 | .\" | 18 | .\" |
| 19 | .Dd $Mdocdate: May 3 2017 $ | 19 | .Dd $Mdocdate: June 13 2025 $ |
| 20 | .Dt GAI_STRERROR 3 | 20 | .Dt GAI_STRERROR 3 |
| 21 | .Os | 21 | .Os |
| 22 | .Sh NAME | 22 | .Sh NAME |
| @@ -26,7 +26,7 @@ | |||
| 26 | .In sys/types.h | 26 | .In sys/types.h |
| 27 | .In sys/socket.h | 27 | .In sys/socket.h |
| 28 | .In netdb.h | 28 | .In netdb.h |
| 29 | .Ft "const char *" | 29 | .Ft const char * |
| 30 | .Fn gai_strerror "int ecode" | 30 | .Fn gai_strerror "int ecode" |
| 31 | .Sh DESCRIPTION | 31 | .Sh DESCRIPTION |
| 32 | The | 32 | The |
diff --git a/src/lib/libc/net/getaddrinfo.3 b/src/lib/libc/net/getaddrinfo.3 index 780c7a409f..2df5fbe896 100644 --- a/src/lib/libc/net/getaddrinfo.3 +++ b/src/lib/libc/net/getaddrinfo.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: getaddrinfo.3,v 1.61 2022/09/11 06:38:10 jmc Exp $ | 1 | .\" $OpenBSD: getaddrinfo.3,v 1.62 2025/12/08 13:30:08 jca Exp $ |
| 2 | .\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ | 2 | .\" $KAME: getaddrinfo.3,v 1.36 2005/01/05 03:23:05 itojun Exp $ |
| 3 | .\" | 3 | .\" |
| 4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") | 4 | .\" Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") |
| @@ -16,7 +16,7 @@ | |||
| 16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR | 16 | .\" OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 17 | .\" PERFORMANCE OF THIS SOFTWARE. | 17 | .\" PERFORMANCE OF THIS SOFTWARE. |
| 18 | .\" | 18 | .\" |
| 19 | .Dd $Mdocdate: September 11 2022 $ | 19 | .Dd $Mdocdate: December 8 2025 $ |
| 20 | .Dt GETADDRINFO 3 | 20 | .Dt GETADDRINFO 3 |
| 21 | .Os | 21 | .Os |
| 22 | .Sh NAME | 22 | .Sh NAME |
| @@ -475,3 +475,7 @@ flag bit first appeared in Windows 7. | |||
| 475 | .%R RFC 4007 | 475 | .%R RFC 4007 |
| 476 | .%T IPv6 Scoped Address Architecture | 476 | .%T IPv6 Scoped Address Architecture |
| 477 | .Re | 477 | .Re |
| 478 | .Sh CAVEATS | ||
| 479 | The behavior of | ||
| 480 | .Fn freeaddrinfo "NULL" | ||
| 481 | is not specified and therefore not portable. | ||
diff --git a/src/lib/libc/net/getifaddrs.c b/src/lib/libc/net/getifaddrs.c index 069ee9afab..448e76097f 100644 --- a/src/lib/libc/net/getifaddrs.c +++ b/src/lib/libc/net/getifaddrs.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: getifaddrs.c,v 1.14 2021/11/29 03:20:37 deraadt Exp $ */ | 1 | /* $OpenBSD: getifaddrs.c,v 1.15 2025/11/13 10:34:32 deraadt Exp $ */ |
| 2 | 2 | ||
| 3 | /* | 3 | /* |
| 4 | * Copyright (c) 1995, 1999 | 4 | * Copyright (c) 1995, 1999 |
| @@ -25,10 +25,10 @@ | |||
| 25 | * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp | 25 | * BSDI getifaddrs.c,v 2.12 2000/02/23 14:51:59 dab Exp |
| 26 | */ | 26 | */ |
| 27 | 27 | ||
| 28 | #include <sys/param.h> /* ALIGN ALIGNBYTES */ | ||
| 29 | #include <sys/types.h> | 28 | #include <sys/types.h> |
| 30 | #include <sys/ioctl.h> | 29 | #include <sys/ioctl.h> |
| 31 | #include <sys/socket.h> | 30 | #include <sys/socket.h> |
| 31 | #include <sys/syslog.h> | ||
| 32 | #include <net/if.h> | 32 | #include <net/if.h> |
| 33 | #include <net/route.h> | 33 | #include <net/route.h> |
| 34 | #include <sys/sysctl.h> | 34 | #include <sys/sysctl.h> |
| @@ -38,35 +38,32 @@ | |||
| 38 | #include <ifaddrs.h> | 38 | #include <ifaddrs.h> |
| 39 | #include <stddef.h> | 39 | #include <stddef.h> |
| 40 | #include <stdlib.h> | 40 | #include <stdlib.h> |
| 41 | #include <stdint.h> | ||
| 41 | #include <string.h> | 42 | #include <string.h> |
| 42 | #include <unistd.h> | 43 | #include <unistd.h> |
| 44 | #include <stdio.h> | ||
| 43 | 45 | ||
| 44 | #define SALIGN (sizeof(long) - 1) | 46 | #define roundup(x, y) ((((uintptr_t)(x)+((y)-1))/(y))*(y)) |
| 45 | #define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : (SALIGN + 1)) | 47 | #define proundup(x, y) (void *)roundup(x,y) |
| 48 | |||
| 49 | #define SA_RLEN(sa) ((sa)->sa_len ? \ | ||
| 50 | roundup((sa)->sa_len, sizeof(long)) : \ | ||
| 51 | roundup(1, sizeof(long))) | ||
| 46 | 52 | ||
| 47 | int | 53 | int |
| 48 | getifaddrs(struct ifaddrs **pif) | 54 | getifaddrs(struct ifaddrs **pif) |
| 49 | { | 55 | { |
| 50 | int icnt = 1; | 56 | int icnt = 1, dcnt = 0, ncnt = 0, mib[6], i; |
| 51 | int dcnt = 0; | ||
| 52 | int ncnt = 0; | ||
| 53 | int mib[6]; | ||
| 54 | size_t needed; | 57 | size_t needed; |
| 55 | char *buf = NULL, *bufp; | 58 | char *buf = NULL, *bufp, *data, *names, *next, *p, *p0; |
| 56 | char *next; | 59 | struct ifaddrs *cif = 0, *ifa, *ift; |
| 57 | struct ifaddrs *cif = 0; | ||
| 58 | char *p, *p0; | ||
| 59 | struct rt_msghdr *rtm; | 60 | struct rt_msghdr *rtm; |
| 60 | struct if_msghdr *ifm; | 61 | struct if_msghdr *ifm; |
| 61 | struct ifa_msghdr *ifam; | 62 | struct ifa_msghdr *ifam; |
| 62 | struct sockaddr_dl *dl; | 63 | struct sockaddr_dl *dl; |
| 63 | struct sockaddr *sa; | 64 | struct sockaddr *sa; |
| 64 | u_short index = 0; | 65 | u_short index = 0; |
| 65 | size_t len, alen, dlen; | 66 | size_t len, alen, dlen, dsize; |
| 66 | struct ifaddrs *ifa, *ift; | ||
| 67 | int i; | ||
| 68 | char *data; | ||
| 69 | char *names; | ||
| 70 | 67 | ||
| 71 | mib[0] = CTL_NET; | 68 | mib[0] = CTL_NET; |
| 72 | mib[1] = PF_ROUTE; | 69 | mib[1] = PF_ROUTE; |
| @@ -95,6 +92,7 @@ getifaddrs(struct ifaddrs **pif) | |||
| 95 | break; | 92 | break; |
| 96 | } | 93 | } |
| 97 | 94 | ||
| 95 | /* Calculate data buffer size */ | ||
| 98 | for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { | 96 | for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { |
| 99 | rtm = (struct rt_msghdr *)next; | 97 | rtm = (struct rt_msghdr *)next; |
| 100 | if (rtm->rtm_version != RTM_VERSION) | 98 | if (rtm->rtm_version != RTM_VERSION) |
| @@ -107,10 +105,15 @@ getifaddrs(struct ifaddrs **pif) | |||
| 107 | ++icnt; | 105 | ++icnt; |
| 108 | dl = (struct sockaddr_dl *)(next + | 106 | dl = (struct sockaddr_dl *)(next + |
| 109 | rtm->rtm_hdrlen); | 107 | rtm->rtm_hdrlen); |
| 110 | dcnt += SA_RLEN((struct sockaddr *)dl) + | ||
| 111 | ALIGNBYTES; | ||
| 112 | dcnt += sizeof(ifm->ifm_data); | ||
| 113 | ncnt += dl->sdl_nlen + 1; | 108 | ncnt += dl->sdl_nlen + 1; |
| 109 | |||
| 110 | /* sockaddr's need long alignment */ | ||
| 111 | dcnt = roundup(dcnt, sizeof(long)); | ||
| 112 | dcnt += SA_RLEN((struct sockaddr *)dl); | ||
| 113 | |||
| 114 | /* ifm_data[] needs long long alignment */ | ||
| 115 | dcnt = roundup(dcnt, sizeof(long long)); | ||
| 116 | dcnt += sizeof(ifm->ifm_data); | ||
| 114 | } else | 117 | } else |
| 115 | index = 0; | 118 | index = 0; |
| 116 | break; | 119 | break; |
| @@ -145,6 +148,8 @@ getifaddrs(struct ifaddrs **pif) | |||
| 145 | continue; | 148 | continue; |
| 146 | sa = (struct sockaddr *)p; | 149 | sa = (struct sockaddr *)p; |
| 147 | len = SA_RLEN(sa); | 150 | len = SA_RLEN(sa); |
| 151 | /* sockaddr's need long alignment */ | ||
| 152 | dcnt = roundup(dcnt, sizeof(long)); | ||
| 148 | if (i == RTAX_NETMASK && sa->sa_len == 0) | 153 | if (i == RTAX_NETMASK && sa->sa_len == 0) |
| 149 | dcnt += alen; | 154 | dcnt += alen; |
| 150 | else | 155 | else |
| @@ -155,23 +160,29 @@ getifaddrs(struct ifaddrs **pif) | |||
| 155 | } | 160 | } |
| 156 | } | 161 | } |
| 157 | 162 | ||
| 158 | if (icnt + dcnt + ncnt == 1) { | 163 | if (icnt + ncnt + dcnt == 1) { |
| 159 | *pif = NULL; | 164 | *pif = NULL; |
| 160 | free(buf); | 165 | free(buf); |
| 161 | return (0); | 166 | return (0); |
| 162 | } | 167 | } |
| 163 | data = malloc(sizeof(struct ifaddrs) * icnt + dcnt + ncnt); | 168 | |
| 169 | dsize = sizeof(struct ifaddrs) * icnt; | ||
| 170 | dsize += ncnt; | ||
| 171 | dsize = roundup(dsize, sizeof(long long)); | ||
| 172 | dsize += dcnt; | ||
| 173 | |||
| 174 | data = calloc(dsize, 1); | ||
| 164 | if (data == NULL) { | 175 | if (data == NULL) { |
| 165 | free(buf); | 176 | free(buf); |
| 166 | return(-1); | 177 | return(-1); |
| 167 | } | 178 | } |
| 168 | 179 | ||
| 169 | ifa = (struct ifaddrs *)data; | 180 | /* ifaddrs[], names, then if_data[] */ |
| 181 | ift = ifa = (struct ifaddrs *)data; | ||
| 170 | data += sizeof(struct ifaddrs) * icnt; | 182 | data += sizeof(struct ifaddrs) * icnt; |
| 171 | names = data + dcnt; | 183 | names = data; |
| 172 | 184 | data += ncnt; | |
| 173 | memset(ifa, 0, sizeof(struct ifaddrs) * icnt); | 185 | data = proundup(data, sizeof(long long)); |
| 174 | ift = ifa; | ||
| 175 | 186 | ||
| 176 | index = 0; | 187 | index = 0; |
| 177 | for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { | 188 | for (next = buf; next < buf + needed; next += rtm->rtm_msglen) { |
| @@ -193,19 +204,21 @@ getifaddrs(struct ifaddrs **pif) | |||
| 193 | names[dl->sdl_nlen] = 0; | 204 | names[dl->sdl_nlen] = 0; |
| 194 | names += dl->sdl_nlen + 1; | 205 | names += dl->sdl_nlen + 1; |
| 195 | 206 | ||
| 207 | data = proundup(data, sizeof(long)); | ||
| 196 | ift->ifa_addr = (struct sockaddr *)data; | 208 | ift->ifa_addr = (struct sockaddr *)data; |
| 197 | memcpy(data, dl, | 209 | memcpy(data, dl, |
| 198 | ((struct sockaddr *)dl)->sa_len); | 210 | ((struct sockaddr *)dl)->sa_len); |
| 199 | data += SA_RLEN((struct sockaddr *)dl); | 211 | data += SA_RLEN((struct sockaddr *)dl); |
| 200 | 212 | ||
| 201 | /* ifm_data needs to be aligned */ | 213 | /* if_data needs long long alignment */ |
| 202 | ift->ifa_data = data = (void *)ALIGN(data); | 214 | data = proundup(data, sizeof(long long)); |
| 215 | ift->ifa_data = data; | ||
| 203 | dlen = rtm->rtm_hdrlen - | 216 | dlen = rtm->rtm_hdrlen - |
| 204 | offsetof(struct if_msghdr, ifm_data); | 217 | offsetof(struct if_msghdr, ifm_data); |
| 205 | if (dlen > sizeof(ifm->ifm_data)) | 218 | if (dlen > sizeof(ifm->ifm_data)) |
| 206 | dlen = sizeof(ifm->ifm_data); | 219 | dlen = sizeof(ifm->ifm_data); |
| 207 | memcpy(data, &ifm->ifm_data, dlen); | 220 | memcpy(data, &ifm->ifm_data, dlen); |
| 208 | data += sizeof(ifm->ifm_data); | 221 | data += dlen; |
| 209 | 222 | ||
| 210 | ift = (ift->ifa_next = ift + 1); | 223 | ift = (ift->ifa_next = ift + 1); |
| 211 | } else | 224 | } else |
| @@ -245,12 +258,14 @@ getifaddrs(struct ifaddrs **pif) | |||
| 245 | len = SA_RLEN(sa); | 258 | len = SA_RLEN(sa); |
| 246 | switch (i) { | 259 | switch (i) { |
| 247 | case RTAX_IFA: | 260 | case RTAX_IFA: |
| 261 | data = proundup(data, sizeof(long)); | ||
| 248 | ift->ifa_addr = (struct sockaddr *)data; | 262 | ift->ifa_addr = (struct sockaddr *)data; |
| 249 | memcpy(data, p, len); | 263 | memcpy(data, p, len); |
| 250 | data += len; | 264 | data += len; |
| 251 | break; | 265 | break; |
| 252 | 266 | ||
| 253 | case RTAX_NETMASK: | 267 | case RTAX_NETMASK: |
| 268 | data = proundup(data, sizeof(long)); | ||
| 254 | ift->ifa_netmask = | 269 | ift->ifa_netmask = |
| 255 | (struct sockaddr *)data; | 270 | (struct sockaddr *)data; |
| 256 | if (sa->sa_len == 0) { | 271 | if (sa->sa_len == 0) { |
| @@ -263,6 +278,7 @@ getifaddrs(struct ifaddrs **pif) | |||
| 263 | break; | 278 | break; |
| 264 | 279 | ||
| 265 | case RTAX_BRD: | 280 | case RTAX_BRD: |
| 281 | data = proundup(data, sizeof(long)); | ||
| 266 | ift->ifa_broadaddr = | 282 | ift->ifa_broadaddr = |
| 267 | (struct sockaddr *)data; | 283 | (struct sockaddr *)data; |
| 268 | memcpy(data, p, len); | 284 | memcpy(data, p, len); |
| @@ -278,6 +294,17 @@ getifaddrs(struct ifaddrs **pif) | |||
| 278 | } | 294 | } |
| 279 | } | 295 | } |
| 280 | 296 | ||
| 297 | /* XXX temporary paranoia until we are sure it is bug free */ | ||
| 298 | if (dsize != (char *)data - (char *)ifa) { | ||
| 299 | char buf[1024]; | ||
| 300 | |||
| 301 | /* <10> is LOG_CRIT */ | ||
| 302 | snprintf(buf, sizeof buf, | ||
| 303 | "<10>%s: getifaddrs: allocated %lu used %lu\n", | ||
| 304 | __progname, dsize, (char *)data - (char *)ifa); | ||
| 305 | sendsyslog(buf, strlen(buf), LOG_CONS); | ||
| 306 | } | ||
| 307 | |||
| 281 | free(buf); | 308 | free(buf); |
| 282 | if (--ift >= ifa) { | 309 | if (--ift >= ifa) { |
| 283 | ift->ifa_next = NULL; | 310 | ift->ifa_next = NULL; |
diff --git a/src/lib/libc/net/if_indextoname.3 b/src/lib/libc/net/if_indextoname.3 index 25d2a2722f..9d00d66bd5 100644 --- a/src/lib/libc/net/if_indextoname.3 +++ b/src/lib/libc/net/if_indextoname.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: if_indextoname.3,v 1.16 2015/11/21 07:48:10 jmc Exp $ | 1 | .\" $OpenBSD: if_indextoname.3,v 1.17 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" Copyright (c) 1983, 1991, 1993 | 2 | .\" Copyright (c) 1983, 1991, 1993 |
| 3 | .\" The Regents of the University of California. All rights reserved. | 3 | .\" The Regents of the University of California. All rights reserved. |
| 4 | .\" | 4 | .\" |
| @@ -28,7 +28,7 @@ | |||
| 28 | .\" | 28 | .\" |
| 29 | .\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 | 29 | .\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93 |
| 30 | .\" | 30 | .\" |
| 31 | .Dd $Mdocdate: November 21 2015 $ | 31 | .Dd $Mdocdate: June 13 2025 $ |
| 32 | .Dt IF_NAMETOINDEX 3 | 32 | .Dt IF_NAMETOINDEX 3 |
| 33 | .Os | 33 | .Os |
| 34 | .Sh NAME | 34 | .Sh NAME |
| @@ -41,13 +41,13 @@ | |||
| 41 | .In sys/types.h | 41 | .In sys/types.h |
| 42 | .In sys/socket.h | 42 | .In sys/socket.h |
| 43 | .In net/if.h | 43 | .In net/if.h |
| 44 | .Ft "unsigned int" | 44 | .Ft unsigned int |
| 45 | .Fn if_nametoindex "const char *ifname" | 45 | .Fn if_nametoindex "const char *ifname" |
| 46 | .Ft "char *" | 46 | .Ft char * |
| 47 | .Fn if_indextoname "unsigned int ifindex" "char *ifname" | 47 | .Fn if_indextoname "unsigned int ifindex" "char *ifname" |
| 48 | .Ft "struct if_nameindex *" | 48 | .Ft struct if_nameindex * |
| 49 | .Fn if_nameindex "void" | 49 | .Fn if_nameindex "void" |
| 50 | .Ft "void" | 50 | .Ft void |
| 51 | .Fn if_freenameindex "struct if_nameindex *ptr" | 51 | .Fn if_freenameindex "struct if_nameindex *ptr" |
| 52 | .Sh DESCRIPTION | 52 | .Sh DESCRIPTION |
| 53 | These functions map interface indexes to interface names (such as | 53 | These functions map interface indexes to interface names (such as |
diff --git a/src/lib/libc/net/inet6_opt_init.3 b/src/lib/libc/net/inet6_opt_init.3 index 41ba842166..87244507a9 100644 --- a/src/lib/libc/net/inet6_opt_init.3 +++ b/src/lib/libc/net/inet6_opt_init.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: inet6_opt_init.3,v 1.8 2022/03/31 17:27:16 naddy Exp $ | 1 | .\" $OpenBSD: inet6_opt_init.3,v 1.9 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ | 2 | .\" $KAME: inet6_opt_init.3,v 1.7 2004/12/27 05:08:23 itojun Exp $ |
| 3 | .\" | 3 | .\" |
| 4 | .\" Copyright (C) 2004 WIDE Project. | 4 | .\" Copyright (C) 2004 WIDE Project. |
| @@ -28,7 +28,7 @@ | |||
| 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | .\" SUCH DAMAGE. | 29 | .\" SUCH DAMAGE. |
| 30 | .\" | 30 | .\" |
| 31 | .Dd $Mdocdate: March 31 2022 $ | 31 | .Dd $Mdocdate: June 13 2025 $ |
| 32 | .Dt INET6_OPT_INIT 3 | 32 | .Dt INET6_OPT_INIT 3 |
| 33 | .Os | 33 | .Os |
| 34 | .\" | 34 | .\" |
| @@ -44,19 +44,19 @@ | |||
| 44 | .\" | 44 | .\" |
| 45 | .Sh SYNOPSIS | 45 | .Sh SYNOPSIS |
| 46 | .In netinet/in.h | 46 | .In netinet/in.h |
| 47 | .Ft "int" | 47 | .Ft int |
| 48 | .Fn inet6_opt_init "void *extbuf" "socklen_t extlen" | 48 | .Fn inet6_opt_init "void *extbuf" "socklen_t extlen" |
| 49 | .Ft "int" | 49 | .Ft int |
| 50 | .Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" | 50 | .Fn inet6_opt_append "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t len" "u_int8_t align" "void **databufp" |
| 51 | .Ft "int" | 51 | .Ft int |
| 52 | .Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" | 52 | .Fn inet6_opt_finish "void *extbuf" "socklen_t extlen" "int offset" |
| 53 | .Ft "int" | 53 | .Ft int |
| 54 | .Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" | 54 | .Fn inet6_opt_set_val "void *databuf" "int offset" "void *val" "socklen_t vallen" |
| 55 | .Ft "int" | 55 | .Ft int |
| 56 | .Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" | 56 | .Fn inet6_opt_next "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t *typep" "socklen_t *lenp" "void **databufp" |
| 57 | .Ft "int" | 57 | .Ft int |
| 58 | .Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" | 58 | .Fn inet6_opt_find "void *extbuf" "socklen_t extlen" "int offset" "u_int8_t type" "socklen_t *lenp" "void **databufp" |
| 59 | .Ft "int" | 59 | .Ft int |
| 60 | .Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" | 60 | .Fn inet6_opt_get_val "void *databuf" "socklen_t offset" "void *val" "socklen_t vallen" |
| 61 | .\" | 61 | .\" |
| 62 | .Sh DESCRIPTION | 62 | .Sh DESCRIPTION |
diff --git a/src/lib/libc/net/inet6_rth_space.3 b/src/lib/libc/net/inet6_rth_space.3 index c40b45057e..7304266fe1 100644 --- a/src/lib/libc/net/inet6_rth_space.3 +++ b/src/lib/libc/net/inet6_rth_space.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: inet6_rth_space.3,v 1.8 2022/03/31 17:27:16 naddy Exp $ | 1 | .\" $OpenBSD: inet6_rth_space.3,v 1.9 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" $KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $ | 2 | .\" $KAME: inet6_rth_space.3,v 1.7 2005/01/05 03:00:44 itojun Exp $ |
| 3 | .\" | 3 | .\" |
| 4 | .\" Copyright (C) 2004 WIDE Project. | 4 | .\" Copyright (C) 2004 WIDE Project. |
| @@ -28,7 +28,7 @@ | |||
| 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | .\" SUCH DAMAGE. | 29 | .\" SUCH DAMAGE. |
| 30 | .\" | 30 | .\" |
| 31 | .Dd $Mdocdate: March 31 2022 $ | 31 | .Dd $Mdocdate: June 13 2025 $ |
| 32 | .Dt INET6_RTH_SPACE 3 | 32 | .Dt INET6_RTH_SPACE 3 |
| 33 | .Os | 33 | .Os |
| 34 | .\" | 34 | .\" |
| @@ -45,7 +45,7 @@ | |||
| 45 | .In netinet/in.h | 45 | .In netinet/in.h |
| 46 | .Ft socklen_t | 46 | .Ft socklen_t |
| 47 | .Fn inet6_rth_space "int" "int" | 47 | .Fn inet6_rth_space "int" "int" |
| 48 | .Ft "void *" | 48 | .Ft void * |
| 49 | .Fn inet6_rth_init "void *" "socklen_t" "int" "int" | 49 | .Fn inet6_rth_init "void *" "socklen_t" "int" "int" |
| 50 | .Ft int | 50 | .Ft int |
| 51 | .Fn inet6_rth_add "void *" "const struct in6_addr *" | 51 | .Fn inet6_rth_add "void *" "const struct in6_addr *" |
| @@ -53,7 +53,7 @@ | |||
| 53 | .Fn inet6_rth_reverse "const void *" "void *" | 53 | .Fn inet6_rth_reverse "const void *" "void *" |
| 54 | .Ft int | 54 | .Ft int |
| 55 | .Fn inet6_rth_segments "const void *" | 55 | .Fn inet6_rth_segments "const void *" |
| 56 | .Ft "struct in6_addr *" | 56 | .Ft struct in6_addr * |
| 57 | .Fn inet6_rth_getaddr "const void *" "int" | 57 | .Fn inet6_rth_getaddr "const void *" "int" |
| 58 | .\" | 58 | .\" |
| 59 | .Sh DESCRIPTION | 59 | .Sh DESCRIPTION |
diff --git a/src/lib/libc/stdlib/exit.3 b/src/lib/libc/stdlib/exit.3 index 22acade86c..ccb416ee82 100644 --- a/src/lib/libc/stdlib/exit.3 +++ b/src/lib/libc/stdlib/exit.3 | |||
| @@ -29,9 +29,9 @@ | |||
| 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 30 | .\" SUCH DAMAGE. | 30 | .\" SUCH DAMAGE. |
| 31 | .\" | 31 | .\" |
| 32 | .\" $OpenBSD: exit.3,v 1.18 2024/08/30 03:44:48 guenther Exp $ | 32 | .\" $OpenBSD: exit.3,v 1.19 2025/06/03 14:15:53 yasuoka Exp $ |
| 33 | .\" | 33 | .\" |
| 34 | .Dd $Mdocdate: August 30 2024 $ | 34 | .Dd $Mdocdate: June 3 2025 $ |
| 35 | .Dt EXIT 3 | 35 | .Dt EXIT 3 |
| 36 | .Os | 36 | .Os |
| 37 | .Sh NAME | 37 | .Sh NAME |
| @@ -54,9 +54,7 @@ Call the functions registered with the | |||
| 54 | .Xr atexit 3 | 54 | .Xr atexit 3 |
| 55 | function, in the reverse order of their registration. | 55 | function, in the reverse order of their registration. |
| 56 | .It | 56 | .It |
| 57 | Flush all open output streams. | 57 | Flush and close all open streams. |
| 58 | .It | ||
| 59 | Close all open streams. | ||
| 60 | .It | 58 | .It |
| 61 | Unlink all files created with the | 59 | Unlink all files created with the |
| 62 | .Xr tmpfile 3 | 60 | .Xr tmpfile 3 |
| @@ -79,6 +77,7 @@ function never returns. | |||
| 79 | .Sh SEE ALSO | 77 | .Sh SEE ALSO |
| 80 | .Xr _exit 2 , | 78 | .Xr _exit 2 , |
| 81 | .Xr atexit 3 , | 79 | .Xr atexit 3 , |
| 80 | .Xr fflush 3 , | ||
| 82 | .Xr intro 3 , | 81 | .Xr intro 3 , |
| 83 | .Xr sysexits 3 , | 82 | .Xr sysexits 3 , |
| 84 | .Xr tmpfile 3 | 83 | .Xr tmpfile 3 |
| @@ -86,7 +85,7 @@ function never returns. | |||
| 86 | The | 85 | The |
| 87 | .Fn exit | 86 | .Fn exit |
| 88 | function conforms to | 87 | function conforms to |
| 89 | .St -isoC-99 . | 88 | .St -p1003.1-2024 . |
| 90 | .Sh HISTORY | 89 | .Sh HISTORY |
| 91 | An | 90 | An |
| 92 | .Fn exit | 91 | .Fn exit |
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index bea5575bf8..ee13b01bd4 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -30,9 +30,9 @@ | |||
| 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
| 32 | .\" | 32 | .\" |
| 33 | .\" $OpenBSD: malloc.3,v 1.142 2024/08/03 20:09:24 guenther Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.147 2025/06/04 00:38:01 yasuoka Exp $ |
| 34 | .\" | 34 | .\" |
| 35 | .Dd $Mdocdate: August 3 2024 $ | 35 | .Dd $Mdocdate: June 4 2025 $ |
| 36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
| 37 | .Os | 37 | .Os |
| 38 | .Sh NAME | 38 | .Sh NAME |
| @@ -69,7 +69,8 @@ | |||
| 69 | .Fn malloc_conceal "size_t size" | 69 | .Fn malloc_conceal "size_t size" |
| 70 | .Ft void * | 70 | .Ft void * |
| 71 | .Fn calloc_conceal "size_t nmemb" "size_t size" | 71 | .Fn calloc_conceal "size_t nmemb" "size_t size" |
| 72 | .Vt char *malloc_options ; | 72 | .Vt const char * const |
| 73 | .Va malloc_options ; | ||
| 73 | .Sh DESCRIPTION | 74 | .Sh DESCRIPTION |
| 74 | The standard functions | 75 | The standard functions |
| 75 | .Fn malloc , | 76 | .Fn malloc , |
| @@ -268,7 +269,15 @@ next checks the environment for a variable called | |||
| 268 | and finally looks at the global variable | 269 | and finally looks at the global variable |
| 269 | .Va malloc_options | 270 | .Va malloc_options |
| 270 | in the program. | 271 | in the program. |
| 271 | Each is scanned for the flags documented below. | 272 | Since |
| 273 | .Fn malloc | ||
| 274 | might already get called before the beginning of | ||
| 275 | .Fn main , | ||
| 276 | either initialize | ||
| 277 | .Va malloc_options | ||
| 278 | to a string literal at file scope or do not declare it at all. | ||
| 279 | .Pp | ||
| 280 | Each of the three strings is scanned for the flags documented below. | ||
| 272 | Unless otherwise noted uppercase means on, lowercase means off. | 281 | Unless otherwise noted uppercase means on, lowercase means off. |
| 273 | During initialization, flags occurring later modify the behaviour | 282 | During initialization, flags occurring later modify the behaviour |
| 274 | that was requested by flags processed earlier. | 283 | that was requested by flags processed earlier. |
| @@ -363,18 +372,9 @@ Use with | |||
| 363 | to get a verbose dump of malloc's internal state. | 372 | to get a verbose dump of malloc's internal state. |
| 364 | .It Cm X | 373 | .It Cm X |
| 365 | .Dq xmalloc . | 374 | .Dq xmalloc . |
| 366 | Rather than return failure, | 375 | Rather than return failure to handle out-of-memory conditions gracefully, |
| 367 | .Xr abort 3 | 376 | .Xr abort 3 |
| 368 | the program with a diagnostic message on stderr. | 377 | the program with a diagnostic message on stderr. |
| 369 | It is the intention that this option be set at compile time by | ||
| 370 | including in the source: | ||
| 371 | .Bd -literal -offset indent | ||
| 372 | extern char *malloc_options; | ||
| 373 | malloc_options = "X"; | ||
| 374 | .Ed | ||
| 375 | .Pp | ||
| 376 | Note that this will cause code that is supposed to handle | ||
| 377 | out-of-memory conditions gracefully to abort instead. | ||
| 378 | .It Cm < | 378 | .It Cm < |
| 379 | .Dq Halve the cache size . | 379 | .Dq Halve the cache size . |
| 380 | Decrease the size of the free page cache by a factor of two. | 380 | Decrease the size of the free page cache by a factor of two. |
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c index cad8e5d6a1..f067dd1f37 100644 --- a/src/lib/libc/stdlib/malloc.c +++ b/src/lib/libc/stdlib/malloc.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: malloc.c,v 1.297 2024/09/20 02:00:46 jsg Exp $ */ | 1 | /* $OpenBSD: malloc.c,v 1.300 2025/10/23 18:49:46 miod Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> | 3 | * Copyright (c) 2008, 2010, 2011, 2016, 2023 Otto Moerbeek <otto@drijf.net> |
| 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> | 4 | * Copyright (c) 2012 Matthew Dempsky <matthew@openbsd.org> |
| @@ -31,7 +31,6 @@ | |||
| 31 | #include <sys/queue.h> | 31 | #include <sys/queue.h> |
| 32 | #include <sys/mman.h> | 32 | #include <sys/mman.h> |
| 33 | #include <sys/sysctl.h> | 33 | #include <sys/sysctl.h> |
| 34 | #include <uvm/uvmexp.h> | ||
| 35 | #include <errno.h> | 34 | #include <errno.h> |
| 36 | #include <stdarg.h> | 35 | #include <stdarg.h> |
| 37 | #include <stdint.h> | 36 | #include <stdint.h> |
| @@ -264,7 +263,8 @@ static union { | |||
| 264 | __attribute__((section(".openbsd.mutable"))); | 263 | __attribute__((section(".openbsd.mutable"))); |
| 265 | #define mopts malloc_readonly.mopts | 264 | #define mopts malloc_readonly.mopts |
| 266 | 265 | ||
| 267 | char *malloc_options; /* compile-time options */ | 266 | /* compile-time options */ |
| 267 | const char *const malloc_options __attribute__((weak)); | ||
| 268 | 268 | ||
| 269 | static __dead void wrterror(struct dir_info *d, char *msg, ...) | 269 | static __dead void wrterror(struct dir_info *d, char *msg, ...) |
| 270 | __attribute__((__format__ (printf, 2, 3))); | 270 | __attribute__((__format__ (printf, 2, 3))); |
| @@ -501,7 +501,8 @@ omalloc_parseopt(char opt) | |||
| 501 | static void | 501 | static void |
| 502 | omalloc_init(void) | 502 | omalloc_init(void) |
| 503 | { | 503 | { |
| 504 | char *p, *q, b[16]; | 504 | const char *p; |
| 505 | char *q, b[16]; | ||
| 505 | int i, j; | 506 | int i, j; |
| 506 | const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; | 507 | const int mib[2] = { CTL_VM, VM_MALLOC_CONF }; |
| 507 | size_t sb; | 508 | size_t sb; |
| @@ -1090,24 +1091,6 @@ err: | |||
| 1090 | return NULL; | 1091 | return NULL; |
| 1091 | } | 1092 | } |
| 1092 | 1093 | ||
| 1093 | #if defined(__GNUC__) && __GNUC__ < 4 | ||
| 1094 | static inline unsigned int | ||
| 1095 | lb(u_int x) | ||
| 1096 | { | ||
| 1097 | #if defined(__m88k__) | ||
| 1098 | __asm__ __volatile__ ("ff1 %0, %0" : "=r" (x) : "0" (x)); | ||
| 1099 | return x; | ||
| 1100 | #else | ||
| 1101 | /* portable version */ | ||
| 1102 | unsigned int count = 0; | ||
| 1103 | while ((x & (1U << (sizeof(int) * CHAR_BIT - 1))) == 0) { | ||
| 1104 | count++; | ||
| 1105 | x <<= 1; | ||
| 1106 | } | ||
| 1107 | return (sizeof(int) * CHAR_BIT - 1) - count; | ||
| 1108 | #endif | ||
| 1109 | } | ||
| 1110 | #else | ||
| 1111 | /* using built-in function version */ | 1094 | /* using built-in function version */ |
| 1112 | static inline unsigned int | 1095 | static inline unsigned int |
| 1113 | lb(u_int x) | 1096 | lb(u_int x) |
| @@ -1115,7 +1098,6 @@ lb(u_int x) | |||
| 1115 | /* I need an extension just for integer-length (: */ | 1098 | /* I need an extension just for integer-length (: */ |
| 1116 | return (sizeof(int) * CHAR_BIT - 1) - __builtin_clz(x); | 1099 | return (sizeof(int) * CHAR_BIT - 1) - __builtin_clz(x); |
| 1117 | } | 1100 | } |
| 1118 | #endif | ||
| 1119 | 1101 | ||
| 1120 | /* https://pvk.ca/Blog/2015/06/27/linear-log-bucketing-fast-versatile-simple/ | 1102 | /* https://pvk.ca/Blog/2015/06/27/linear-log-bucketing-fast-versatile-simple/ |
| 1121 | via Tony Finch */ | 1103 | via Tony Finch */ |
diff --git a/src/lib/libc/stdlib/mkstemp.c b/src/lib/libc/stdlib/mkstemp.c index 75a9d27d1a..760575005f 100644 --- a/src/lib/libc/stdlib/mkstemp.c +++ b/src/lib/libc/stdlib/mkstemp.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: mkstemp.c,v 1.1 2024/01/19 19:45:02 millert Exp $ */ | 1 | /* $OpenBSD: mkstemp.c,v 1.2 2025/08/04 04:59:31 guenther Exp $ */ |
| 2 | /* | 2 | /* |
| 3 | * Copyright (c) 2024 Todd C. Miller | 3 | * Copyright (c) 2024 Todd C. Miller |
| 4 | * | 4 | * |
| @@ -20,7 +20,8 @@ | |||
| 20 | #include <fcntl.h> | 20 | #include <fcntl.h> |
| 21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
| 22 | 22 | ||
| 23 | #define MKOSTEMP_FLAGS (O_APPEND | O_CLOEXEC | O_DSYNC | O_RSYNC | O_SYNC) | 23 | #define MKOSTEMP_FLAGS \ |
| 24 | (O_APPEND | O_CLOEXEC | O_CLOFORK | O_DSYNC | O_RSYNC | O_SYNC) | ||
| 24 | 25 | ||
| 25 | static int | 26 | static int |
| 26 | mkstemp_cb(const char *path, int flags) | 27 | mkstemp_cb(const char *path, int flags) |
diff --git a/src/lib/libc/stdlib/mktemp.3 b/src/lib/libc/stdlib/mktemp.3 index 83b7c9eb30..a967358164 100644 --- a/src/lib/libc/stdlib/mktemp.3 +++ b/src/lib/libc/stdlib/mktemp.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: mktemp.3,v 1.2 2024/03/01 21:30:40 millert Exp $ | 1 | .\" $OpenBSD: mktemp.3,v 1.4 2025/08/04 14:11:37 schwarze Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 1989, 1991, 1993 | 3 | .\" Copyright (c) 1989, 1991, 1993 |
| 4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
| @@ -27,17 +27,17 @@ | |||
| 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 29 | .\" | 29 | .\" |
| 30 | .Dd $Mdocdate: March 1 2024 $ | 30 | .Dd $Mdocdate: August 4 2025 $ |
| 31 | .Dt MKTEMP 3 | 31 | .Dt MKTEMP 3 |
| 32 | .Os | 32 | .Os |
| 33 | .Sh NAME | 33 | .Sh NAME |
| 34 | .Nm mktemp , | 34 | .Nm mktemp , |
| 35 | .Nm mkstemp , | 35 | .Nm mkstemp , |
| 36 | .Nm mkostemp , | ||
| 37 | .Nm mkstemps , | 36 | .Nm mkstemps , |
| 38 | .Nm mkostemps , | ||
| 39 | .Nm mkdtemp , | 37 | .Nm mkdtemp , |
| 40 | .Nm mkdtemps | 38 | .Nm mkdtemps , |
| 39 | .Nm mkostemp , | ||
| 40 | .Nm mkostemps | ||
| 41 | .Nd make temporary file name (unique) | 41 | .Nd make temporary file name (unique) |
| 42 | .Sh SYNOPSIS | 42 | .Sh SYNOPSIS |
| 43 | .In stdlib.h | 43 | .In stdlib.h |
| @@ -119,6 +119,8 @@ system call: | |||
| 119 | Append on each write. | 119 | Append on each write. |
| 120 | .It Dv O_CLOEXEC | 120 | .It Dv O_CLOEXEC |
| 121 | Set the close-on-exec flag on the new file descriptor. | 121 | Set the close-on-exec flag on the new file descriptor. |
| 122 | .It Dv O_CLOFORK | ||
| 123 | Set the close-on-fork flag on the new file descriptor. | ||
| 122 | .It Dv O_SYNC | 124 | .It Dv O_SYNC |
| 123 | Perform synchronous I/O operations. | 125 | Perform synchronous I/O operations. |
| 124 | .El | 126 | .El |
| @@ -163,8 +165,8 @@ functions return a pointer to the template on success and | |||
| 163 | on failure. | 165 | on failure. |
| 164 | The | 166 | The |
| 165 | .Fn mkstemp , | 167 | .Fn mkstemp , |
| 166 | .Fn mkostemp , | ||
| 167 | .Fn mkstemps , | 168 | .Fn mkstemps , |
| 169 | .Fn mkostemp , | ||
| 168 | and | 170 | and |
| 169 | .Fn mkostemps | 171 | .Fn mkostemps |
| 170 | functions return \-1 if no suitable file could be created. | 172 | functions return \-1 if no suitable file could be created. |
| @@ -253,9 +255,9 @@ of | |||
| 253 | The | 255 | The |
| 254 | .Fn mktemp , | 256 | .Fn mktemp , |
| 255 | .Fn mkstemp , | 257 | .Fn mkstemp , |
| 256 | .Fn mkostemp , | 258 | .Fn mkdtemp , |
| 257 | and | 259 | and |
| 258 | .Fn mkdtemp | 260 | .Fn mkostemp |
| 259 | functions may set | 261 | functions may set |
| 260 | .Va errno | 262 | .Va errno |
| 261 | to one of the following values: | 263 | to one of the following values: |
| @@ -318,8 +320,8 @@ function. | |||
| 318 | .Pp | 320 | .Pp |
| 319 | The | 321 | The |
| 320 | .Fn mkstemp , | 322 | .Fn mkstemp , |
| 321 | .Fn mkostemp , | ||
| 322 | .Fn mkstemps , | 323 | .Fn mkstemps , |
| 324 | .Fn mkostemp , | ||
| 323 | and | 325 | and |
| 324 | .Fn mkostemps | 326 | .Fn mkostemps |
| 325 | functions may also set | 327 | functions may also set |
| @@ -345,18 +347,16 @@ function. | |||
| 345 | .Xr tmpnam 3 | 347 | .Xr tmpnam 3 |
| 346 | .Sh STANDARDS | 348 | .Sh STANDARDS |
| 347 | The | 349 | The |
| 348 | .Fn mkdtemp | 350 | .Fn mkstemp , |
| 351 | .Fn mkdtemp , | ||
| 349 | and | 352 | and |
| 350 | .Fn mkstemp | 353 | .Fn mkostemp |
| 351 | functions conform to the | 354 | functions conform to the |
| 352 | .St -p1003.1-2008 | 355 | .St -p1003.1-2024 |
| 353 | specification. | 356 | specification. |
| 354 | The ability to specify more than six | 357 | The ability to specify more than six |
| 355 | .Em X Ns s | 358 | .Em X Ns s |
| 356 | is an extension to that standard. | 359 | is an extension to that standard. |
| 357 | The | ||
| 358 | .Fn mkostemp | ||
| 359 | function is expected to conform to a future revision of that standard. | ||
| 360 | .Pp | 360 | .Pp |
| 361 | The | 361 | The |
| 362 | .Fn mktemp | 362 | .Fn mktemp |
| @@ -368,9 +368,9 @@ it is no longer a part of the standard. | |||
| 368 | .Pp | 368 | .Pp |
| 369 | The | 369 | The |
| 370 | .Fn mkstemps , | 370 | .Fn mkstemps , |
| 371 | .Fn mkostemps , | 371 | .Fn mkdtemps , |
| 372 | and | 372 | and |
| 373 | .Fn mkdtemps | 373 | .Fn mkostemps |
| 374 | functions are non-standard and should not be used if portability is required. | 374 | functions are non-standard and should not be used if portability is required. |
| 375 | .Sh HISTORY | 375 | .Sh HISTORY |
| 376 | A | 376 | A |
| @@ -378,14 +378,14 @@ A | |||
| 378 | function appeared in | 378 | function appeared in |
| 379 | .At v7 . | 379 | .At v7 . |
| 380 | The | 380 | The |
| 381 | .Fn mkdtemp | ||
| 382 | function appeared in | ||
| 383 | .Ox 2.2 . | ||
| 384 | The | ||
| 385 | .Fn mkstemp | 381 | .Fn mkstemp |
| 386 | function appeared in | 382 | function appeared in |
| 387 | .Bx 4.3 . | 383 | .Bx 4.3 . |
| 388 | The | 384 | The |
| 385 | .Fn mkdtemp | ||
| 386 | function appeared in | ||
| 387 | .Ox 2.2 . | ||
| 388 | The | ||
| 389 | .Fn mkstemps | 389 | .Fn mkstemps |
| 390 | function appeared in | 390 | function appeared in |
| 391 | .Ox 2.3 . | 391 | .Ox 2.3 . |
diff --git a/src/lib/libc/stdlib/ptsname.3 b/src/lib/libc/stdlib/ptsname.3 index 98705528f5..eea36a5a02 100644 --- a/src/lib/libc/stdlib/ptsname.3 +++ b/src/lib/libc/stdlib/ptsname.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: ptsname.3,v 1.2 2012/12/04 18:42:16 millert Exp $ | 1 | .\" $OpenBSD: ptsname.3,v 1.3 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 2002 The FreeBSD Project, Inc. | 3 | .\" Copyright (c) 2002 The FreeBSD Project, Inc. |
| 4 | .\" All rights reserved. | 4 | .\" All rights reserved. |
| @@ -32,7 +32,7 @@ | |||
| 32 | .\" | 32 | .\" |
| 33 | .\" $FreeBSD: head/lib/libc/stdlib/ptsname.3 240412 2012-09-12 17:54:09Z emaste $ | 33 | .\" $FreeBSD: head/lib/libc/stdlib/ptsname.3 240412 2012-09-12 17:54:09Z emaste $ |
| 34 | .\" | 34 | .\" |
| 35 | .Dd $Mdocdate: December 4 2012 $ | 35 | .Dd $Mdocdate: June 13 2025 $ |
| 36 | .Dt PTSNAME 3 | 36 | .Dt PTSNAME 3 |
| 37 | .Os | 37 | .Os |
| 38 | .Sh NAME | 38 | .Sh NAME |
| @@ -44,7 +44,7 @@ | |||
| 44 | .In stdlib.h | 44 | .In stdlib.h |
| 45 | .Ft int | 45 | .Ft int |
| 46 | .Fn grantpt "int fildes" | 46 | .Fn grantpt "int fildes" |
| 47 | .Ft "char *" | 47 | .Ft char * |
| 48 | .Fn ptsname "int fildes" | 48 | .Fn ptsname "int fildes" |
| 49 | .Ft int | 49 | .Ft int |
| 50 | .Fn unlockpt "int fildes" | 50 | .Fn unlockpt "int fildes" |
diff --git a/src/lib/libc/stdlib/rand48.3 b/src/lib/libc/stdlib/rand48.3 index fa7a7179bc..02e1999db9 100644 --- a/src/lib/libc/stdlib/rand48.3 +++ b/src/lib/libc/stdlib/rand48.3 | |||
| @@ -9,9 +9,9 @@ | |||
| 9 | .\" of any kind. I shall in no event be liable for anything that happens | 9 | .\" of any kind. I shall in no event be liable for anything that happens |
| 10 | .\" to anyone/anything when using this software. | 10 | .\" to anyone/anything when using this software. |
| 11 | .\" | 11 | .\" |
| 12 | .\" $OpenBSD: rand48.3,v 1.21 2019/12/20 19:16:40 tb Exp $ | 12 | .\" $OpenBSD: rand48.3,v 1.22 2025/06/13 18:34:00 schwarze Exp $ |
| 13 | .\" | 13 | .\" |
| 14 | .Dd $Mdocdate: December 20 2019 $ | 14 | .Dd $Mdocdate: June 13 2025 $ |
| 15 | .Dt DRAND48 3 | 15 | .Dt DRAND48 3 |
| 16 | .Os | 16 | .Os |
| 17 | .Sh NAME | 17 | .Sh NAME |
| @@ -46,9 +46,9 @@ | |||
| 46 | .Fn srand48 "long seed" | 46 | .Fn srand48 "long seed" |
| 47 | .Ft void | 47 | .Ft void |
| 48 | .Fn srand48_deterministic "long seed" | 48 | .Fn srand48_deterministic "long seed" |
| 49 | .Ft "unsigned short *" | 49 | .Ft unsigned short * |
| 50 | .Fn seed48 "unsigned short xseed[3]" | 50 | .Fn seed48 "unsigned short xseed[3]" |
| 51 | .Ft "unsigned short *" | 51 | .Ft unsigned short * |
| 52 | .Fn seed48_deterministic "unsigned short xseed[3]" | 52 | .Fn seed48_deterministic "unsigned short xseed[3]" |
| 53 | .Ft void | 53 | .Ft void |
| 54 | .Fn lcong48 "unsigned short p[7]" | 54 | .Fn lcong48 "unsigned short p[7]" |
diff --git a/src/lib/libc/stdlib/realpath.3 b/src/lib/libc/stdlib/realpath.3 index 1dec10fef4..1f932e3bb5 100644 --- a/src/lib/libc/stdlib/realpath.3 +++ b/src/lib/libc/stdlib/realpath.3 | |||
| @@ -28,9 +28,9 @@ | |||
| 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 28 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 29 | .\" SUCH DAMAGE. | 29 | .\" SUCH DAMAGE. |
| 30 | .\" | 30 | .\" |
| 31 | .\" $OpenBSD: realpath.3,v 1.26 2021/10/13 15:04:53 kn Exp $ | 31 | .\" $OpenBSD: realpath.3,v 1.27 2025/06/13 18:34:00 schwarze Exp $ |
| 32 | .\" | 32 | .\" |
| 33 | .Dd $Mdocdate: October 13 2021 $ | 33 | .Dd $Mdocdate: June 13 2025 $ |
| 34 | .Dt REALPATH 3 | 34 | .Dt REALPATH 3 |
| 35 | .Os | 35 | .Os |
| 36 | .Sh NAME | 36 | .Sh NAME |
| @@ -39,7 +39,7 @@ | |||
| 39 | .Sh SYNOPSIS | 39 | .Sh SYNOPSIS |
| 40 | .In limits.h | 40 | .In limits.h |
| 41 | .In stdlib.h | 41 | .In stdlib.h |
| 42 | .Ft "char *" | 42 | .Ft char * |
| 43 | .Fn realpath "const char *pathname" "char *resolved" | 43 | .Fn realpath "const char *pathname" "char *resolved" |
| 44 | .Sh DESCRIPTION | 44 | .Sh DESCRIPTION |
| 45 | The | 45 | The |
diff --git a/src/lib/libc/string/Makefile.inc b/src/lib/libc/string/Makefile.inc index 204ca1b266..f8b6330453 100644 --- a/src/lib/libc/string/Makefile.inc +++ b/src/lib/libc/string/Makefile.inc | |||
| @@ -1,13 +1,13 @@ | |||
| 1 | # $OpenBSD: Makefile.inc,v 1.40 2024/07/14 09:51:18 jca Exp $ | 1 | # $OpenBSD: Makefile.inc,v 1.41 2025/10/24 11:30:06 claudio Exp $ |
| 2 | 2 | ||
| 3 | # string sources | 3 | # string sources |
| 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string | 4 | .PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/string ${LIBCSRCDIR}/string |
| 5 | 5 | ||
| 6 | SRCS+= explicit_bzero.c memccpy.c memmem.c memrchr.c stpcpy.c stpncpy.c \ | 6 | SRCS+= explicit_bzero.c ffsl.c ffsll.c memccpy.c memmem.c memrchr.c \ |
| 7 | strcasecmp.c strcasecmp_l.c strcasestr.c strcoll.c strcoll_l.c \ | 7 | stpcpy.c stpncpy.c strcasecmp.c strcasecmp_l.c strcasestr.c \ |
| 8 | strdup.c strerror.c strerror_l.c strerror_r.c strmode.c \ | 8 | strcoll.c strcoll_l.c strdup.c strerror.c strerror_l.c strerror_r.c \ |
| 9 | strndup.c strnlen.c strsignal.c strtok.c strxfrm.c strxfrm_l.c \ | 9 | strmode.c strndup.c strnlen.c strsignal.c strtok.c strxfrm.c \ |
| 10 | timingsafe_bcmp.c timingsafe_memcmp.c \ | 10 | strxfrm_l.c timingsafe_bcmp.c timingsafe_memcmp.c \ |
| 11 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ | 11 | wcscat.c wcschr.c wcscmp.c wcscpy.c wcscspn.c wcslcat.c wcslcpy.c \ |
| 12 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcsnlen.c wcspbrk.c wcsrchr.c \ | 12 | wcslen.c wcsncat.c wcsncmp.c wcsncpy.c wcsnlen.c wcspbrk.c wcsrchr.c \ |
| 13 | wcsspn.c wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c \ | 13 | wcsspn.c wcsstr.c wcstok.c wcswcs.c wcswidth.c wmemchr.c wmemcmp.c \ |
diff --git a/src/lib/libc/string/ffs.3 b/src/lib/libc/string/ffs.3 index e78ab99e8f..0b78fbfd33 100644 --- a/src/lib/libc/string/ffs.3 +++ b/src/lib/libc/string/ffs.3 | |||
| @@ -27,24 +27,33 @@ | |||
| 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 27 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | .\" SUCH DAMAGE. | 28 | .\" SUCH DAMAGE. |
| 29 | .\" | 29 | .\" |
| 30 | .\" $OpenBSD: ffs.3,v 1.11 2019/08/30 18:35:03 deraadt Exp $ | 30 | .\" $OpenBSD: ffs.3,v 1.13 2025/11/06 17:19:11 schwarze Exp $ |
| 31 | .\" | 31 | .\" |
| 32 | .Dd $Mdocdate: August 30 2019 $ | 32 | .Dd $Mdocdate: November 6 2025 $ |
| 33 | .Dt FFS 3 | 33 | .Dt FFS 3 |
| 34 | .Os | 34 | .Os |
| 35 | .Sh NAME | 35 | .Sh NAME |
| 36 | .Nm ffs | 36 | .Nm ffs , |
| 37 | .Nm ffsl , | ||
| 38 | .Nm ffsll | ||
| 37 | .Nd find first bit set in a bit string | 39 | .Nd find first bit set in a bit string |
| 38 | .Sh SYNOPSIS | 40 | .Sh SYNOPSIS |
| 39 | .In strings.h | 41 | .In strings.h |
| 40 | .Ft int | 42 | .Ft int |
| 41 | .Fn ffs "int value" | 43 | .Fn ffs "int value" |
| 44 | .Ft int | ||
| 45 | .Fn ffsl "long value" | ||
| 46 | .Ft int | ||
| 47 | .Fn ffsll "long long value" | ||
| 42 | .Sh DESCRIPTION | 48 | .Sh DESCRIPTION |
| 43 | The | 49 | The |
| 44 | .Fn ffs | 50 | .Fn ffs , |
| 45 | function finds the first bit set in | 51 | .Fn ffsl , |
| 52 | and | ||
| 53 | .Fn ffsll | ||
| 54 | functions find the first bit set in | ||
| 46 | .Fa value | 55 | .Fa value |
| 47 | and returns the index of that bit. | 56 | and return the index of that bit. |
| 48 | Bits are numbered starting from 1, starting at the rightmost bit. | 57 | Bits are numbered starting from 1, starting at the rightmost bit. |
| 49 | A return value of 0 means that the argument was zero. | 58 | A return value of 0 means that the argument was zero. |
| 50 | .Sh SEE ALSO | 59 | .Sh SEE ALSO |
| @@ -54,8 +63,20 @@ The | |||
| 54 | .Fn ffs | 63 | .Fn ffs |
| 55 | function conforms to | 64 | function conforms to |
| 56 | .St -p1003.1-2008 . | 65 | .St -p1003.1-2008 . |
| 66 | The | ||
| 67 | .Fn ffsl | ||
| 68 | and | ||
| 69 | .Fn ffsll | ||
| 70 | functions conform to | ||
| 71 | .St -p1003.1-2024 . | ||
| 57 | .Sh HISTORY | 72 | .Sh HISTORY |
| 58 | The | 73 | The |
| 59 | .Fn ffs | 74 | .Fn ffs |
| 60 | function first appeared in | 75 | function first appeared in |
| 61 | .Bx 4.2 . | 76 | .Bx 4.2 . |
| 77 | The | ||
| 78 | .Fn ffsl | ||
| 79 | and | ||
| 80 | .Fn ffsll | ||
| 81 | functions first appeared in | ||
| 82 | .Ox 7.9 . | ||
diff --git a/src/lib/libc/string/ffsl.c b/src/lib/libc/string/ffsl.c new file mode 100644 index 0000000000..182318c3d6 --- /dev/null +++ b/src/lib/libc/string/ffsl.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /* $OpenBSD: ffsl.c,v 1.1 2025/10/24 11:30:06 claudio Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain. | ||
| 5 | * Written by Claudio Jeker. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <strings.h> | ||
| 9 | |||
| 10 | /* | ||
| 11 | * ffs -- find the first (least significant) bit set | ||
| 12 | */ | ||
| 13 | int | ||
| 14 | ffsl(long mask) | ||
| 15 | { | ||
| 16 | return (mask ? __builtin_ctzl(mask) + 1 : 0); | ||
| 17 | } | ||
diff --git a/src/lib/libc/string/ffsll.c b/src/lib/libc/string/ffsll.c new file mode 100644 index 0000000000..9370c5ae41 --- /dev/null +++ b/src/lib/libc/string/ffsll.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | /* $OpenBSD: ffsll.c,v 1.1 2025/10/24 11:30:06 claudio Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Public domain. | ||
| 5 | * Written by Claudio Jeker. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <strings.h> | ||
| 9 | |||
| 10 | /* | ||
| 11 | * ffs -- find the first (least significant) bit set | ||
| 12 | */ | ||
| 13 | int | ||
| 14 | ffsll(long long mask) | ||
| 15 | { | ||
| 16 | return (mask ? __builtin_ctzll(mask) + 1 : 0); | ||
| 17 | } | ||
diff --git a/src/lib/libc/string/memmem.3 b/src/lib/libc/string/memmem.3 index de62d738de..eeb621f8f6 100644 --- a/src/lib/libc/string/memmem.3 +++ b/src/lib/libc/string/memmem.3 | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | .\" $OpenBSD: memmem.3,v 1.4 2024/08/03 20:13:23 guenther Exp $ | 1 | .\" $OpenBSD: memmem.3,v 1.5 2025/06/13 18:34:00 schwarze Exp $ |
| 2 | .\" | 2 | .\" |
| 3 | .\" Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com> | 3 | .\" Copyright (c) 2005 Pascal Gloor <pascal.gloor@spale.com> |
| 4 | .\" | 4 | .\" |
| @@ -26,7 +26,7 @@ | |||
| 26 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 26 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 27 | .\" SUCH DAMAGE. | 27 | .\" SUCH DAMAGE. |
| 28 | .\" | 28 | .\" |
| 29 | .Dd $Mdocdate: August 3 2024 $ | 29 | .Dd $Mdocdate: June 13 2025 $ |
| 30 | .Dt MEMMEM 3 | 30 | .Dt MEMMEM 3 |
| 31 | .Os | 31 | .Os |
| 32 | .Sh NAME | 32 | .Sh NAME |
| @@ -34,7 +34,7 @@ | |||
| 34 | .Nd locate a byte substring in a byte string | 34 | .Nd locate a byte substring in a byte string |
| 35 | .Sh SYNOPSIS | 35 | .Sh SYNOPSIS |
| 36 | .In string.h | 36 | .In string.h |
| 37 | .Ft "void *" | 37 | .Ft void * |
| 38 | .Fo memmem | 38 | .Fo memmem |
| 39 | .Fa "const void *big" "size_t big_len" | 39 | .Fa "const void *big" "size_t big_len" |
| 40 | .Fa "const void *little" "size_t little_len" | 40 | .Fa "const void *little" "size_t little_len" |
