aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crypto/openssh/uidswap.c15
-rw-r--r--lib/libc/amd64/string/memrchr.S224
-rw-r--r--lib/libpam/modules/pam_ksu/pam_ksu.c31
-rw-r--r--lib/msun/bsdsrc/b_tgamma.c2
-rw-r--r--lib/msun/src/s_ccosh.c23
-rw-r--r--lib/msun/src/s_ccoshf.c18
-rw-r--r--lib/msun/src/s_csinh.c23
-rw-r--r--lib/msun/src/s_csinhf.c18
-rw-r--r--sbin/geom/core/geom.c2
-rw-r--r--share/man/man7/simd.743
-rw-r--r--share/mk/bsd.mkopt.mk68
-rw-r--r--sys/compat/linuxkpi/common/include/asm/topology.h54
-rw-r--r--sys/compat/linuxkpi/common/include/linux/bitops.h8
-rw-r--r--sys/compat/linuxkpi/common/include/linux/gfp.h1
-rw-r--r--sys/compat/linuxkpi/common/include/linux/idr.h7
-rw-r--r--sys/compat/linuxkpi/common/include/linux/ioport.h1
-rw-r--r--sys/compat/linuxkpi/common/include/linux/printk.h6
-rw-r--r--sys/compat/linuxkpi/common/include/linux/refcount.h1
-rw-r--r--sys/compat/linuxkpi/common/include/linux/seq_file.h15
-rw-r--r--sys/compat/linuxkpi/common/include/linux/sysfs.h57
-rw-r--r--sys/compat/linuxkpi/common/include/linux/topology.h35
-rw-r--r--sys/compat/linuxkpi/common/src/linux_seq_file.c9
-rw-r--r--sys/kern/sys_timerfd.c1
-rw-r--r--sys/kern/vfs_syscalls.c17
-rw-r--r--sys/netinet/tcp_input.c7
-rw-r--r--sys/netinet/tcp_stacks/bbr.c4
-rw-r--r--sys/netinet/tcp_stacks/rack.c4
-rw-r--r--sys/netinet/tcp_subr.c8
-rw-r--r--sys/powerpc/powerpc/busdma_machdep.c1
-rw-r--r--sys/riscv/riscv/busdma_bounce.c1
-rw-r--r--sys/rpc/rpcsec_gss/rpcsec_gss.c2
-rw-r--r--sys/rpc/rpcsec_gss/rpcsec_gss_int.h2
-rw-r--r--sys/rpc/rpcsec_gss/svc_rpcsec_gss.c2
-rw-r--r--sys/sys/param.h2
-rw-r--r--sys/sys/unistd.h9
-rw-r--r--sys/sys/vnode.h17
-rw-r--r--sys/x86/x86/busdma_bounce.c1
-rwxr-xr-xtools/build/options/makeman4
-rw-r--r--usr.bin/top/machine.c155
-rw-r--r--usr.bin/top/machine.h7
-rw-r--r--usr.bin/top/top.c29
-rw-r--r--usr.bin/top/utils.c21
-rw-r--r--usr.bin/top/utils.h1
-rw-r--r--usr.sbin/autofs/common.c2
-rw-r--r--usr.sbin/bhyve/pci_xhci.c35
-rw-r--r--usr.sbin/bhyve/usb_emul.h4
-rw-r--r--usr.sbin/bhyve/usb_mouse.c13
47 files changed, 677 insertions, 333 deletions
diff --git a/crypto/openssh/uidswap.c b/crypto/openssh/uidswap.c
index 6ed3024d0180..0143f4994611 100644
--- a/crypto/openssh/uidswap.c
+++ b/crypto/openssh/uidswap.c
@@ -14,6 +14,9 @@
#include "includes.h"
+#ifdef __FreeBSD__
+#include <assert.h>
+#endif
#include <errno.h>
#include <pwd.h>
#include <string.h>
@@ -121,8 +124,20 @@ temporarily_use_uid(struct passwd *pw)
fatal("setgroups: %.100s", strerror(errno));
#ifndef SAVED_IDS_WORK_WITH_SETEUID
/* Propagate the privileged gid to all of our gids. */
+#ifdef __FreeBSD__
+ /*
+ * FreeBSD traditionally includes the egid as the first element. If we
+ * use getegid() here then we effectively propagate user_groups[0],
+ * which is probably pw->pw_gid. Fix it to work as intended by using
+ * the egid we already have stashed off.
+ */
+ assert(saved_egroupslen > 0);
+ if (setgid(saved_egroups[0]) == -1)
+ debug("setgid %u: %.100s", (u_int) saved_egroups[0], strerror(errno));
+#else
if (setgid(getegid()) == -1)
debug("setgid %u: %.100s", (u_int) getegid(), strerror(errno));
+#endif
/* Propagate the privileged uid to all of our uids. */
if (setuid(geteuid()) == -1)
debug("setuid %u: %.100s", (u_int) geteuid(), strerror(errno));
diff --git a/lib/libc/amd64/string/memrchr.S b/lib/libc/amd64/string/memrchr.S
index 4f6c5a238daa..80fb306af2a3 100644
--- a/lib/libc/amd64/string/memrchr.S
+++ b/lib/libc/amd64/string/memrchr.S
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2023 Robert Clausecker
+ * Copyright (c) 2023, 2025 Robert Clausecker <fuz@FreeBSD.org>
*/
#include <machine/asm.h>
@@ -16,150 +16,142 @@ ARCHFUNCS(memrchr)
ENDARCHFUNCS(memrchr)
ARCHENTRY(memrchr, scalar)
- xor %eax, %eax # prospective return value
- sub $4, %rdx # 4 bytes left to process?
- jb 1f
+ lea -1(%rdi, %rdx, 1), %rax # point to last char in buffer
+ sub $4, %rdx # 4 bytes left to process?
+ jb .Ltail
ALIGN_TEXT
-0: xor %r8, %r8
- lea 2(%rdi), %r10
- cmp %sil, 2(%rdi)
- cmovne %r8, %r10 # point to null if no match
+0: cmp %sil, (%rax) # match at last entry?
+ je 1f
- cmp %sil, (%rdi)
- cmove %rdi, %r8 # point to first char if match
+ cmp %sil, -1(%rax) # match at second to last entry?
+ je 2f
- lea 1(%rdi), %r9
- cmp %sil, 1(%rdi)
- cmovne %r8, %r9 # point to first result if no match in second
+ cmp %sil, -2(%rax) # match at third to last entry?
+ je 3f
- lea 3(%rdi), %r11
- cmp %sil, 3(%rdi)
- cmovne %r10, %r11
+ cmp %sil, -3(%rax) # match at fourth to last entry?
+ je 4f
- test %r11, %r11
- cmovz %r9, %r11 # take first pair match if none in second
+ sub $4, %rax
+ sub $4, %rdx
+ jae 0b
- test %r11, %r11
- cmovnz %r11, %rax # take match in current set if any
+.Ltail: cmp $-3, %edx # at least one character left to process?
+ jb .Lnotfound
- add $4, %rdi
- sub $4, %rdx
- jae 0b
+ cmp %sil, (%rax)
+ je 1f
-1: cmp $-3, %edx # a least one character left to process?
- jb 2f
+ cmp $-2, %edx # at least two characters left to process?
+ jb .Lnotfound
- cmp %sil, (%rdi)
- cmove %rdi, %rax
+ cmp %sil, -1(%rax)
+ je 2f
- lea 1(%rdi), %rcx
- cmp $-2, %edx # at least two characters left to process?
- jb 2f
+ cmp $-1, %edx # at least three characters left to process?
+ jb .Lnotfound
- cmp %sil, 1(%rdi)
- cmove %rcx, %rax
+ cmp %sil, -2(%rax)
+ je 3f
- lea 2(%rdi), %rcx
- cmp $-1, %edx # at least three character left to process?
- jb 2f
-
- cmp %sil, 2(%rdi)
- cmove %rcx, %rax
+.Lnotfound:
+ xor %eax, %eax
+ ret
-2: ret
+ /* match found -- adjust rax to point to matching byte */
+4: dec %rax
+3: dec %rax
+2: dec %rax
+1: ret
ARCHEND(memrchr, scalar)
ARCHENTRY(memrchr, baseline)
- movd %esi, %xmm4
- test %rdx, %rdx # empty buffer?
- jz .L0 # if yes, return immediately
+ test %rdx, %rdx # empty input?
+ je .Lnomatchb
+
+
+ lea (%rdi, %rdx, 1), %ecx # pointer to end of buffer
+ lea -1(%rdi, %rdx, 1), %rdx # pointer to last char in buffer
+ movd %esi, %xmm2
+ and $~0x1f, %rdx # pointer to final 32 buffer bytes
+ movdqa (%rdx), %xmm0 # load last 32 bytes
+ movdqa 16(%rdx), %xmm1
+
+ punpcklbw %xmm2, %xmm2 # c -> cc
- punpcklbw %xmm4, %xmm4 # c -> cc
- mov %edi, %ecx
- punpcklwd %xmm4, %xmm4 # cc -> cccc
- and $~0xf, %rdi # align source pointer
- pshufd $0, %xmm4, %xmm4 # cccc -> cccccccccccccccc
- and $0xf, %ecx
- movdqa %xmm4, %xmm0
mov $-1, %r8d
- pcmpeqb (%rdi), %xmm0 # compare aligned head
- shl %cl, %r8d # mask of bytes in the head of the buffer
- pmovmskb %xmm0, %eax
+ neg %ecx
+ mov %r8d, %r9d
+ shr %cl, %r8d # mask with zeroes after the string
- sub $16, %rcx
- and %r8d, %eax # match mask
- add %rcx, %rdx # advance past head
- cmc
- jbe .Lrunt # did the string end in the buffer?
+ punpcklwd %xmm2, %xmm2 # cc -> cccc
- mov %rdi, %rsi # pointer to matching chunk
- add $16, %rdi
- sub $16, %rdx # enough left for another round?
- jbe 1f
+ mov %edi, %ecx
+ mov %r9d, %eax
+ shl %cl, %r9d # mask with zeroes before the string
- /* main loop unrolled twice */
- ALIGN_TEXT
-0: movdqa %xmm4, %xmm0
- pcmpeqb (%rdi), %xmm0
- pmovmskb %xmm0, %r8d
+ pshufd $0, %xmm2, %xmm2 # cccc -> cccccccccccccccc
- cmp $16, %rdx # enough left for second chunk?
- jbe 2f
+ cmp %rdx, %rdi # tail is beginning of buffer?
+ cmovae %r9d, %eax # if yes, do combined head/tail processing
+ and %r8d, %eax # mak of bytes in tail part of string
- movdqa %xmm4, %xmm0
- pcmpeqb 16(%rdi), %xmm0
+ /* process tail */
+ pcmpeqb %xmm2, %xmm1
+ pcmpeqb %xmm2, %xmm0
+ pmovmskb %xmm1, %esi
pmovmskb %xmm0, %ecx
+ shl $16, %esi
+ or %esi, %ecx # locations of matches
+ and %ecx, %eax # any match inside buffer?
+ jnz .Lprecisematchb
- lea 16(%rdi), %r9
- test %ecx, %ecx # match found in second chunk?
- cmovz %r8d, %ecx # if not, use match data from first chunk
- cmovz %rdi, %r9
-
- test %ecx, %ecx # any match found?
- cmovnz %ecx, %eax # if yes, overwrite previously found match
- cmovnz %r9, %rsi
-
- add $32, %rdi # advance to next iteration
- sub $32, %rdx # advance to next chunks
- ja 0b
-
- /* process remaining 1--16 bytes */
-1: pcmpeqb (%rdi), %xmm4
- mov $0xffff, %r8d
- xor %ecx, %ecx
- sub %edx, %ecx # number of bytes to be masked out
- pmovmskb %xmm4, %r9d
- shr %cl, %r8d # mask of bytes to be kept in the buffer
- and %r9d, %r8d
- cmovnz %r8d, %eax
- cmovnz %rdi, %rsi
- bsr %eax, %eax
- lea (%rsi, %rax, 1), %rsi # pointer to match (or junk)
- cmovnz %rsi, %rax # if any match was found, return it
- ret
+ cmp %rdx, %rdi # did the buffer begin here?
+ jae .Lnomatchb # if yes, we are done
- /* end of chunk reached within first half iteration */
-2: test %r8d, %r8d # match in previous chunk?
- cmovnz %r8d, %eax # if yes, overwrite previous chunks
- cmovnz %rdi, %rsi
- add $16, %rdi # point to tail
- sub $16, %edx
- jmp 1b # handle tail the same otherwise
-
- /* runt: string ends within head, edx has negated amount of invalid head bytes */
-.Lrunt: mov $0xffff, %r8d
- xor %ecx, %ecx
- sub %edx, %ecx
- shr %cl, %r8d
- and %r8d, %eax
- bsr %eax, %eax
- lea (%rdi, %rax, 1), %rdi
- cmovnz %rdi, %rax
+ /* main loop */
+ ALIGN_TEXT
+0: movdqa -32(%rdx), %xmm0 # load previous string chunk
+ movdqa -16(%rdx), %xmm1
+ sub $32, %rdx # beginning of string reached?
+ cmp %rdx, %rdi
+ jae .Ltailb
+
+ pcmpeqb %xmm2, %xmm0
+ pcmpeqb %xmm2, %xmm1
+ por %xmm1, %xmm0 # match in either half?
+ pmovmskb %xmm0, %eax
+ test %eax, %eax
+ jz 0b
+
+.Lmatchb:
+ pcmpeqb (%rdx), %xmm2 # redo comparison of first 16 bytes
+ pmovmskb %xmm1, %ecx
+ pmovmskb %xmm2, %eax
+ shl $16, %ecx
+ or %ecx, %eax # location of matches
+
+.Lprecisematchb:
+ bsr %eax, %eax # find location of match
+ add %rdx, %rax # point to matching byte
ret
- /* empty buffer: return a null pointer */
-.L0: xor %eax, %eax
+.Ltailb:
+ pcmpeqb %xmm2, %xmm1
+ pcmpeqb %xmm2, %xmm0
+ pmovmskb %xmm1, %ecx
+ pmovmskb %xmm0, %eax
+ shl $16, %ecx
+ or %ecx, %eax # location of matches
+ and %r9d, %eax # mask out matches before buffer
+ bsr %eax, %edi # location of match
+ lea (%rdx, %rdi, 1), %rdx # pointer to match (if any)
+ cmovnz %rdx, %rax # point to match if present,
+ ret # else null pointer
+
+.Lnomatchb:
+ xor %eax, %eax # return null pointer
ret
ARCHEND(memrchr, baseline)
diff --git a/lib/libpam/modules/pam_ksu/pam_ksu.c b/lib/libpam/modules/pam_ksu/pam_ksu.c
index 002613188d8c..04c276a423d3 100644
--- a/lib/libpam/modules/pam_ksu/pam_ksu.c
+++ b/lib/libpam/modules/pam_ksu/pam_ksu.c
@@ -58,24 +58,13 @@ static int auth_krb5(pam_handle_t *, krb5_context, const char *,
#define KRB5_DEFAULT_CCFILE_ROOT "/tmp/krb5cc_"
#define KRB5_DEFAULT_CCROOT "FILE:" KRB5_DEFAULT_CCFILE_ROOT
-/*
- * XXX We will replace krb5_build_principal_va() with
- * XXX krb5_build_principal_alloc_va() when Heimdal is finally
- * XXX removed.
- */
-krb5_error_code KRB5_CALLCONV
-krb5_build_principal_va(krb5_context context,
- krb5_principal princ,
- unsigned int rlen,
- const char *realm,
- va_list ap);
typedef char *heim_general_string;
typedef heim_general_string Realm;
typedef Realm krb5_realm;
typedef const char *krb5_const_realm;
static krb5_error_code
-krb5_make_principal(krb5_context context, krb5_principal principal,
+krb5_make_principal(krb5_context context, krb5_principal *principal,
krb5_const_realm realm, ...)
{
krb5_realm temp_realm = NULL;
@@ -88,15 +77,9 @@ krb5_make_principal(krb5_context context, krb5_principal principal,
realm=temp_realm;
}
va_start(ap, realm);
- /*
- * XXX Ideally we should be using krb5_build_principal_alloc_va()
- * XXX here because krb5_build_principal_va() is deprecated. But,
- * XXX this would require changes elsewhere in the calling code
- * XXX to call krb5_free_principal() elsewhere to free the
- * XXX principal. We can do that after Heimdal is removed from
- * XXX our tree.
- */
- rc = krb5_build_principal_va(context, principal, strlen(realm), realm, ap);
+
+ rc = krb5_build_principal_alloc_va(context, principal, strlen(realm),
+ realm, ap);
va_end(ap);
if (temp_realm)
free(temp_realm);
@@ -273,13 +256,7 @@ get_su_principal(krb5_context context, const char *target_user, const char *curr
if (rv != 0)
return (errno);
if (default_principal == NULL) {
-#ifdef MK_MITKRB5
- /* For MIT KRB5. */
- rv = krb5_make_principal(context, default_principal, NULL, current_user, NULL);
-#else
- /* For Heimdal. */
rv = krb5_make_principal(context, &default_principal, NULL, current_user, NULL);
-#endif
if (rv != 0) {
PAM_LOG("Could not determine default principal name.");
return (rv);
diff --git a/lib/msun/bsdsrc/b_tgamma.c b/lib/msun/bsdsrc/b_tgamma.c
index 8369477c18b7..a7e97bc777c3 100644
--- a/lib/msun/bsdsrc/b_tgamma.c
+++ b/lib/msun/bsdsrc/b_tgamma.c
@@ -259,7 +259,7 @@ small_gam(double x)
static double
smaller_gam(double x)
{
- double d, rhi, rlo, t, xhi, xlo;
+ double d, t, xhi, xlo;
struct Double r;
if (x < x0 + left) {
diff --git a/lib/msun/src/s_ccosh.c b/lib/msun/src/s_ccosh.c
index 3d46c993c6f1..14a8931742dc 100644
--- a/lib/msun/src/s_ccosh.c
+++ b/lib/msun/src/s_ccosh.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static const double huge = 0x1p1023;
double complex
ccosh(double complex z)
{
- double x, y, h;
+ double c, h, s, x, y;
int32_t hx, hy, ix, iy, lx, ly;
x = creal(z);
@@ -64,14 +64,16 @@ ccosh(double complex z)
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
return (CMPLX(cosh(x), x * y));
+
+ sincos(y, &s, &c);
if (ix < 0x40360000) /* |x| < 22: normal case */
- return (CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)));
+ return (CMPLX(cosh(x) * c, sinh(x) * s));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
- h = exp(fabs(x)) * 0.5;
- return (CMPLX(h * cos(y), copysign(h, x) * sin(y)));
+ h = exp(fabs(x)) / 2;
+ return (CMPLX(h * c, copysign(h, x) * s));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@ ccosh(double complex z)
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
- return (CMPLX(h * h * cos(y), h * sin(y)));
+ return (CMPLX(h * h * c, h * s));
}
}
@@ -129,7 +131,9 @@ ccosh(double complex z)
if (ix == 0x7ff00000 && lx == 0) {
if (iy >= 0x7ff00000)
return (CMPLX(INFINITY, x * (y - y)));
- return (CMPLX(INFINITY * cos(y), x * sin(y)));
+
+ sincos(y, &s, &c);
+ return (CMPLX(INFINITY * c, x * s));
}
/*
@@ -154,3 +158,8 @@ ccos(double complex z)
/* ccos(z) = ccosh(I * z) */
return (ccosh(CMPLX(-cimag(z), creal(z))));
}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(ccosh, ccoshl);
+__weak_reference(ccos, ccosl);
+#endif
diff --git a/lib/msun/src/s_ccoshf.c b/lib/msun/src/s_ccoshf.c
index aeb2dec23677..fa41fdf4c4ea 100644
--- a/lib/msun/src/s_ccoshf.c
+++ b/lib/msun/src/s_ccoshf.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ static const float huge = 0x1p127;
float complex
ccoshf(float complex z)
{
- float x, y, h;
+ float c, h, s, x, y;
int32_t hx, hy, ix, iy;
x = crealf(z);
@@ -55,14 +55,16 @@ ccoshf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
return (CMPLXF(coshf(x), x * y));
+
+ sincosf(y, &s, &c);
if (ix < 0x41100000) /* |x| < 9: normal case */
- return (CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)));
+ return (CMPLXF(coshf(x) * c, sinhf(x) * s));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
- h = expf(fabsf(x)) * 0.5F;
- return (CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)));
+ h = expf(fabsf(x)) / 2;
+ return (CMPLXF(h * c, copysignf(h, x) * s));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@ ccoshf(float complex z)
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
- return (CMPLXF(h * h * cosf(y), h * sinf(y)));
+ return (CMPLXF(h * h * c, h * s));
}
}
@@ -86,7 +88,9 @@ ccoshf(float complex z)
if (ix == 0x7f800000) {
if (iy >= 0x7f800000)
return (CMPLXF(INFINITY, x * (y - y)));
- return (CMPLXF(INFINITY * cosf(y), x * sinf(y)));
+
+ sincosf(y, &s, &c);
+ return (CMPLXF(INFINITY * c, x * s));
}
return (CMPLXF(((long double)x * x) * (y - y),
diff --git a/lib/msun/src/s_csinh.c b/lib/msun/src/s_csinh.c
index e7ed10e7d885..11c2ec345094 100644
--- a/lib/msun/src/s_csinh.c
+++ b/lib/msun/src/s_csinh.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -48,7 +48,7 @@ static const double huge = 0x1p1023;
double complex
csinh(double complex z)
{
- double x, y, h;
+ double c, h, s, x, y;
int32_t hx, hy, ix, iy, lx, ly;
x = creal(z);
@@ -64,14 +64,16 @@ csinh(double complex z)
if (ix < 0x7ff00000 && iy < 0x7ff00000) {
if ((iy | ly) == 0)
return (CMPLX(sinh(x), y));
+
+ sincos(y, &s, &c);
if (ix < 0x40360000) /* |x| < 22: normal case */
- return (CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)));
+ return (CMPLX(sinh(x) * c, cosh(x) * s));
/* |x| >= 22, so cosh(x) ~= exp(|x|) */
if (ix < 0x40862e42) {
/* x < 710: exp(|x|) won't overflow */
- h = exp(fabs(x)) * 0.5;
- return (CMPLX(copysign(h, x) * cos(y), h * sin(y)));
+ h = exp(fabs(x)) / 2;
+ return (CMPLX(copysign(h, x) * c, h * s));
} else if (ix < 0x4096bbaa) {
/* x < 1455: scale to avoid overflow */
z = __ldexp_cexp(CMPLX(fabs(x), y), -1);
@@ -79,7 +81,7 @@ csinh(double complex z)
} else {
/* x >= 1455: the result always overflows */
h = huge * x;
- return (CMPLX(h * cos(y), h * h * sin(y)));
+ return (CMPLX(h * c, h * h * s));
}
}
@@ -128,7 +130,9 @@ csinh(double complex z)
if (ix == 0x7ff00000 && lx == 0) {
if (iy >= 0x7ff00000)
return (CMPLX(x, y - y));
- return (CMPLX(x * cos(y), INFINITY * sin(y)));
+
+ sincos(y, &s, &c);
+ return (CMPLX(x * c, INFINITY * s));
}
/*
@@ -154,3 +158,8 @@ csin(double complex z)
z = csinh(CMPLX(cimag(z), creal(z)));
return (CMPLX(cimag(z), creal(z)));
}
+
+#if (LDBL_MANT_DIG == 53)
+__weak_reference(csinh, csinhl);
+__weak_reference(csin, csinl);
+#endif
diff --git a/lib/msun/src/s_csinhf.c b/lib/msun/src/s_csinhf.c
index c4392755c482..fcfc011a2484 100644
--- a/lib/msun/src/s_csinhf.c
+++ b/lib/msun/src/s_csinhf.c
@@ -1,7 +1,7 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
- * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl
+ * Copyright (c) 2005-2025 Bruce D. Evans and Steven G. Kargl
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -40,7 +40,7 @@ static const float huge = 0x1p127;
float complex
csinhf(float complex z)
{
- float x, y, h;
+ float c, h, s, x, y;
int32_t hx, hy, ix, iy;
x = crealf(z);
@@ -55,14 +55,16 @@ csinhf(float complex z)
if (ix < 0x7f800000 && iy < 0x7f800000) {
if (iy == 0)
return (CMPLXF(sinhf(x), y));
+
+ sincosf(y, &s, &c);
if (ix < 0x41100000) /* |x| < 9: normal case */
- return (CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)));
+ return (CMPLXF(sinhf(x) * c, coshf(x) * s));
/* |x| >= 9, so cosh(x) ~= exp(|x|) */
if (ix < 0x42b17218) {
/* x < 88.7: expf(|x|) won't overflow */
- h = expf(fabsf(x)) * 0.5F;
- return (CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)));
+ h = expf(fabsf(x)) / 2;
+ return (CMPLXF(copysignf(h, x) * c, h * s));
} else if (ix < 0x4340b1e7) {
/* x < 192.7: scale to avoid overflow */
z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1);
@@ -70,7 +72,7 @@ csinhf(float complex z)
} else {
/* x >= 192.7: the result always overflows */
h = huge * x;
- return (CMPLXF(h * cosf(y), h * h * sinf(y)));
+ return (CMPLXF(h * c, h * h * s));
}
}
@@ -86,7 +88,9 @@ csinhf(float complex z)
if (ix == 0x7f800000) {
if (iy >= 0x7f800000)
return (CMPLXF(x, y - y));
- return (CMPLXF(x * cosf(y), INFINITY * sinf(y)));
+
+ sincosf(y, &s, &c);
+ return (CMPLXF(x * c, INFINITY * s));
}
return (CMPLXF(((long double)x + x) * (y - y),
diff --git a/sbin/geom/core/geom.c b/sbin/geom/core/geom.c
index 950f6790b1a8..b78021194ddd 100644
--- a/sbin/geom/core/geom.c
+++ b/sbin/geom/core/geom.c
@@ -249,7 +249,7 @@ static void
set_option(struct gctl_req *req, struct g_option *opt, const char *val)
{
const char *optname;
- uint64_t number;
+ int64_t number;
void *ptr;
if (G_OPT_ISMULTI(opt)) {
diff --git a/share/man/man7/simd.7 b/share/man/man7/simd.7
index d5092348d9b3..2c3ed3de411e 100644
--- a/share/man/man7/simd.7
+++ b/share/man/man7/simd.7
@@ -24,7 +24,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE
.
-.Dd November 18, 2024
+.Dd July 29, 2025
.Dt SIMD 7
.Os
.Sh NAME
@@ -50,48 +50,43 @@ can be used to override this mechanism.
.Pp
Enhanced functions are present for the following architectures:
.Bl -column FUNCTION_________ aarch64_ arm_ amd64_ i386_ ppc64_ -offset indent
-.It Em FUNCTION Ta Em AARCH64 Ta Em ARM Ta Em AMD64 Ta Em I386 Ta Em PPC64
-.It bcmp Ta A Ta Ta S1 Ta S
-.It bcopy Ta A Ta S Ta S Ta S Ta SV
-.It bzero Ta A Ta S Ta S Ta S
-.It div Ta Ta Ta S Ta S
+.It Em FUNCTION Ta Em AARCH64 Ta Em ARM Ta Em AMD64 Ta Em PPC64
+.It bcmp Ta A Ta Ta S1
+.It bcopy Ta A Ta S Ta S Ta SV
+.It bzero Ta A Ta S Ta S
+.It div Ta Ta Ta S
.It index Ta A Ta Ta S1
-.It ldiv Ta Ta Ta S Ta S
+.It ldiv Ta Ta Ta S
.It lldiv Ta Ta Ta S
.It memchr Ta A Ta Ta S1
-.It memcmp Ta A Ta S Ta S1 Ta S
+.It memcmp Ta A Ta S Ta S1
.It memccpy Ta A Ta Ta S1
-.It memcpy Ta A Ta S Ta S Ta S Ta SV
-.It memmove Ta A Ta S Ta S Ta S Ta SV
+.It memcpy Ta A Ta S Ta S Ta SV
+.It memmove Ta A Ta S Ta S Ta SV
.It memrchr Ta A Ta Ta S1
-.It memset Ta A Ta S Ta S Ta S
-.It rindex Ta A Ta Ta S1 Ta S
+.It memset Ta A Ta S Ta S
+.It rindex Ta A Ta Ta S1
.It stpcpy Ta A Ta Ta S1
.It stpncpy Ta Ta Ta S1
-.It strcat Ta A Ta Ta S1 Ta S
-.It strchr Ta A Ta Ta S1 Ta S
+.It strcat Ta A Ta Ta S1
+.It strchr Ta A Ta Ta S1
.It strchrnul Ta A Ta Ta S1
-.It strcmp Ta A Ta S Ta S1 Ta S
-.It strcpy Ta A Ta Ta S1 Ta S Ta S2
+.It strcmp Ta A Ta S Ta S1
+.It strcpy Ta A Ta Ta S1 Ta S2
.It strcspn Ta S Ta Ta S2
.It strlcat Ta A Ta Ta S1
.It strlcpy Ta A Ta Ta S1
.It strlen Ta A Ta S Ta S1
.It strncat Ta A Ta Ta S1
-.It strncmp Ta A Ta S Ta S1 Ta S
-.It strncpy Ta Ta Ta S1 Ta Ta S2
+.It strncmp Ta A Ta S Ta S1
+.It strncpy Ta Ta Ta S1 Ta S2
.It strnlen Ta A Ta Ta S1
-.It strrchr Ta A Ta Ta S1 Ta S
+.It strrchr Ta A Ta Ta S1
.It strpbrk Ta S Ta Ta S2
.It strsep Ta S Ta Ta S2
.It strspn Ta S Ta Ta S2
-.It swab Ta Ta Ta Ta S
.It timingsafe_bcmp Ta A Ta Ta S1
.It timingsafe_memcmp Ta S Ta Ta S
-.It wcschr Ta Ta Ta Ta S
-.It wcscmp Ta Ta Ta Ta S
-.It wcslen Ta Ta Ta Ta S
-.It wmemchr Ta Ta Ta Ta S
.El
.Pp
.Sy S Ns :\ scalar (non-SIMD),
diff --git a/share/mk/bsd.mkopt.mk b/share/mk/bsd.mkopt.mk
index f93101544bf7..4d67ba04294d 100644
--- a/share/mk/bsd.mkopt.mk
+++ b/share/mk/bsd.mkopt.mk
@@ -19,14 +19,6 @@
# If both WITH_FOO and WITHOUT_FOO are defined, WITHOUT_FOO wins and
# MK_FOO is set to "no" regardless of which list it was in.
#
-# All of __DEFAULT_YES_OPTIONS, __DEFAULT_NO_OPTIONS and
-# __DEFAULT_DEPENDENT_OPTIONS are undef'd after all this processing,
-# allowing this file to be included multiple times with different lists.
-#
-# Other parts of the build system will set BROKEN_OPTIONS to a list
-# of options that are broken on this platform. This will not be unset
-# before returning. Clients are expected to always += this variable.
-#
# Users should generally define WITH_FOO or WITHOUT_FOO, but the build
# system should use MK_FOO={yes,no} when it needs to override the
# user's desires or default behavior.
@@ -35,6 +27,19 @@
# defined and __FOO_DEFAULT if not. Valid values for FOO are specified
# by __FOO_OPTIONS.
#
+# All of __REQUIRED_OPTIONS, __DEFAULT_DEPENDENT_OPTIONS,
+# __DEFAULT_YES_OPTIONS, __DEFAULT_NO_OPTIONS, and __SINGLE_OPTIONS
+# are undef'd after all this processing, allowing this file to be
+# included multiple times with different lists. However, we keep
+# deduplicated lists of these options in similarly-named variables
+# without the leading underscores (i.e. FOO_OPTIONS is the complete
+# deduplicated list of all values of __FOO_OPTIONS across all
+# invokations of this file).
+#
+# Other parts of the build system will set BROKEN_OPTIONS to a list
+# of options that are broken on this platform. This will not be unset
+# before returning. Clients are expected to always += this variable.
+#
# Other parts of the build system will set BROKEN_SINGLE_OPTIONS to a
# list of 3-tuples of the form: "OPTION broken_value replacment_value".
# This will not be unset before returning. Clients are expected to
@@ -42,6 +47,33 @@
#
#
+# These variables accumulate all the options from our possibly
+# multiple callers so they're available to build tools such as
+# tools/build/options/makeman.
+#
+DEFAULT_NO_OPTIONS+=${__DEFAULT_NO_OPTIONS}
+DEFAULT_NO_OPTIONS:=${DEFAULT_NO_OPTIONS:O:u}
+DEFAULT_YES_OPTIONS+=${__DEFAULT_YES_OPTIONS}
+DEFAULT_YES_OPTIONS:=${DEFAULT_YES_OPTIONS:O:u}
+DEFAULT_DEPENDENT_OPTIONS+=${__DEFAULT_DEPENDENT_OPTIONS}
+DEFAULT_DEPENDENT_OPTIONS:=${DEFAULT_DEPENDENT_OPTIONS:O:u}
+REQUIRED_OPTIONS+=${__REQUIRED_OPTIONS}
+REQUIRED_OPTIONS:=${REQUIRED_OPTIONS:O:u}
+SINGLE_OPTIONS+=${__SINGLE_OPTIONS}
+SINGLE_OPTIONS:=${SINGLE_OPTIONS:O:u}
+
+#
+# All options defined by our caller; we will undef this before
+# returning.
+#
+__ALL_OPTIONS:= \
+ ${__DEFAULT_NO_OPTIONS} \
+ ${__DEFAULT_YES_OPTIONS} \
+ ${__REQUIRED_OPTIONS} \
+ ${__DEFAULT_DEPENDENT_OPTIONS:H} \
+ ${__SINGLE_OPTIONS}
+
+#
# MK_* options which default to "yes".
#
.for var in ${__DEFAULT_YES_OPTIONS}
@@ -72,6 +104,7 @@ MK_${var}:= yes
.endif
MK_${var}:= yes
.endfor
+.undef __REQUIRED_OPTIONS
#
# MK_* options which default to "no".
@@ -142,3 +175,22 @@ MK_${vv:H}?= ${MK_${vv:T}}
MK_${vv:H}:= ${MK_${vv:H}}
.endfor
.undef __DEFAULT_DEPENDENT_OPTIONS
+
+#
+# Define SRC_OPT_DEFS and SRC_OPT_LIST
+#
+SRC_OPT_DEFS?=-D__${MACHINE_ARCH}__
+SRC_OPT_LIST?=TARGET=${MACHINE} TARGET_ARCH=${MACHINE_ARCH}
+.for option in ${__ALL_OPTIONS:O:u}
+.if defined(OPT_${option})
+SRC_OPT_DEFS+=-D${option}=${OPT_${option}:Q}
+SRC_OPT_LIST+=${option}=${OPT_${option}:Q}
+.elif ${MK_${option}} == yes
+SRC_OPT_DEFS+=-D${option}
+SRC_OPT_LIST+=WITH_${option}=1
+.elif ${MK_${option}} == no
+SRC_OPT_DEFS+=-U${option}
+SRC_OPT_LIST+=WITHOUT_${option}=1
+.endif
+.endfor
+.undef __ALL_OPTIONS
diff --git a/sys/compat/linuxkpi/common/include/asm/topology.h b/sys/compat/linuxkpi/common/include/asm/topology.h
new file mode 100644
index 000000000000..f334d3253cfb
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/asm/topology.h
@@ -0,0 +1,54 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUXKPI_ASM_TOPOLOGY_H_
+#define _LINUXKPI_ASM_TOPOLOGY_H_
+
+#if defined(__i386__) || defined(__amd64__)
+#include <sys/smp.h>
+
+/*
+ * The following functions are defined in `arch/x86/include/asm/topology.h`
+ * and thus are specific to i386 and amd64.
+ */
+
+static inline unsigned int
+topology_num_cores_per_package(void)
+{
+ return (mp_ncores);
+}
+
+static inline unsigned int
+topology_num_threads_per_package(void)
+{
+ return (mp_ncpus);
+}
+#endif
+
+#endif /* _LINUXKPI_ASM_TOPOLOGY_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/bitops.h b/sys/compat/linuxkpi/common/include/linux/bitops.h
index bc776a0db9c4..00dd1f9a1ec0 100644
--- a/sys/compat/linuxkpi/common/include/linux/bitops.h
+++ b/sys/compat/linuxkpi/common/include/linux/bitops.h
@@ -62,10 +62,10 @@
#define hweight64(x) bitcount64(x)
#define hweight_long(x) bitcountl(x)
-#define HWEIGHT8(x) (bitcount8((uint8_t)(x)))
-#define HWEIGHT16(x) (bitcount16(x))
-#define HWEIGHT32(x) (bitcount32(x))
-#define HWEIGHT64(x) (bitcount64(x))
+#define HWEIGHT8(x) (__builtin_popcountg((uint8_t)(x)))
+#define HWEIGHT16(x) (__builtin_popcountg((uint16_t)(x)))
+#define HWEIGHT32(x) (__builtin_popcountg((uint32_t)(x)))
+#define HWEIGHT64(x) (__builtin_popcountg((uint64_t)(x)))
static inline int
__ffs(int mask)
diff --git a/sys/compat/linuxkpi/common/include/linux/gfp.h b/sys/compat/linuxkpi/common/include/linux/gfp.h
index 4c4caa621789..7a32e7862338 100644
--- a/sys/compat/linuxkpi/common/include/linux/gfp.h
+++ b/sys/compat/linuxkpi/common/include/linux/gfp.h
@@ -34,6 +34,7 @@
#include <sys/malloc.h>
#include <linux/page.h>
+#include <linux/topology.h>
#include <vm/vm_param.h>
#include <vm/vm_object.h>
diff --git a/sys/compat/linuxkpi/common/include/linux/idr.h b/sys/compat/linuxkpi/common/include/linux/idr.h
index 535d8ce07fb4..06850c94a5e9 100644
--- a/sys/compat/linuxkpi/common/include/linux/idr.h
+++ b/sys/compat/linuxkpi/common/include/linux/idr.h
@@ -147,6 +147,13 @@ ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp)
return (ida_simple_get(ida, 0, max, gfp));
}
+static inline int
+ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, gfp_t gfp)
+{
+
+ return (ida_simple_get(ida, min, max, gfp));
+}
+
static inline int ida_alloc(struct ida *ida, gfp_t gfp)
{
return (ida_alloc_max(ida, ~0u, gfp));
diff --git a/sys/compat/linuxkpi/common/include/linux/ioport.h b/sys/compat/linuxkpi/common/include/linux/ioport.h
index 444f3ad94602..763af2de7c4f 100644
--- a/sys/compat/linuxkpi/common/include/linux/ioport.h
+++ b/sys/compat/linuxkpi/common/include/linux/ioport.h
@@ -40,6 +40,7 @@
struct resource {
resource_size_t start;
resource_size_t end;
+ const char *name;
};
static inline resource_size_t
diff --git a/sys/compat/linuxkpi/common/include/linux/printk.h b/sys/compat/linuxkpi/common/include/linux/printk.h
index da9d45122d4d..d2d197682782 100644
--- a/sys/compat/linuxkpi/common/include/linux/printk.h
+++ b/sys/compat/linuxkpi/common/include/linux/printk.h
@@ -94,4 +94,10 @@ print_hex_dump_bytes(const char *prefix_str, const int prefix_type,
0; \
})
+#define FW_BUG "[Firmware Bug]: "
+#define FW_WARN "[Firmware Warn]: "
+#define FW_INFO "[Firmware Info]: "
+#define HW_ERR "[Hardware Error]: "
+#define DEPRECATED "[Deprecated]: "
+
#endif /* _LINUXKPI_LINUX_PRINTK_H_ */
diff --git a/sys/compat/linuxkpi/common/include/linux/refcount.h b/sys/compat/linuxkpi/common/include/linux/refcount.h
index 02a7eda3f4a9..46e501a65396 100644
--- a/sys/compat/linuxkpi/common/include/linux/refcount.h
+++ b/sys/compat/linuxkpi/common/include/linux/refcount.h
@@ -30,6 +30,7 @@
#define _LINUXKPI_LINUX_REFCOUNT_H
#include <linux/atomic.h>
+#include <linux/spinlock.h>
typedef atomic_t refcount_t;
diff --git a/sys/compat/linuxkpi/common/include/linux/seq_file.h b/sys/compat/linuxkpi/common/include/linux/seq_file.h
index 876ef9e8dfe5..47da16ab8688 100644
--- a/sys/compat/linuxkpi/common/include/linux/seq_file.h
+++ b/sys/compat/linuxkpi/common/include/linux/seq_file.h
@@ -55,6 +55,21 @@ static const struct file_operations __name ## _fops = { \
.release = single_release, \
}
+#define DEFINE_SHOW_STORE_ATTRIBUTE(__name) \
+static int __name ## _open(struct inode *inode, struct linux_file *file) \
+{ \
+ return single_open(file, __name ## _show, inode->i_private); \
+} \
+ \
+static const struct file_operations __name ## _fops = { \
+ .owner = THIS_MODULE, \
+ .open = __name ## _open, \
+ .read = seq_read, \
+ .write = __name ## _write, \
+ .llseek = seq_lseek, \
+ .release = single_release, \
+}
+
struct seq_file {
struct sbuf *buf;
size_t size;
diff --git a/sys/compat/linuxkpi/common/include/linux/sysfs.h b/sys/compat/linuxkpi/common/include/linux/sysfs.h
index 65e023031bb2..470c224a9778 100644
--- a/sys/compat/linuxkpi/common/include/linux/sysfs.h
+++ b/sys/compat/linuxkpi/common/include/linux/sysfs.h
@@ -189,6 +189,50 @@ sysfs_create_file(struct kobject *kobj, const struct attribute *attr)
return (0);
}
+static inline struct kobject *
+__sysfs_lookup_group(struct kobject *kobj, const char *group)
+{
+ int found;
+ struct sysctl_oid *group_oidp;
+ struct kobject *group_kobj;
+
+ found = 0;
+ if (group != NULL) {
+ SYSCTL_FOREACH(group_oidp, SYSCTL_CHILDREN(kobj->oidp)) {
+ if (strcmp(group_oidp->oid_name, group) != 0)
+ continue;
+ found = 1;
+ break;
+ }
+ } else {
+ found = 1;
+ group_oidp = kobj->oidp;
+ }
+
+ if (!found)
+ return (NULL);
+
+ group_kobj = group_oidp->oid_arg1;
+
+ return (group_kobj);
+}
+
+static inline int
+sysfs_add_file_to_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+ int ret;
+ struct kobject *group_kobj;
+
+ group_kobj = __sysfs_lookup_group(kobj, group);
+ if (group_kobj == NULL)
+ return (-ENOENT);
+
+ ret = sysfs_create_file(group_kobj, attr);
+
+ return (ret);
+}
+
static inline void
sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
{
@@ -197,6 +241,19 @@ sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)
sysctl_remove_name(kobj->oidp, attr->name, 1, 1);
}
+static inline void
+sysfs_remove_file_from_group(struct kobject *kobj,
+ const struct attribute *attr, const char *group)
+{
+ struct kobject *group_kobj;
+
+ group_kobj = __sysfs_lookup_group(kobj, group);
+ if (group_kobj == NULL)
+ return;
+
+ sysfs_remove_file(group_kobj, attr);
+}
+
static inline int
sysctl_handle_bin_attr(SYSCTL_HANDLER_ARGS)
{
diff --git a/sys/compat/linuxkpi/common/include/linux/topology.h b/sys/compat/linuxkpi/common/include/linux/topology.h
new file mode 100644
index 000000000000..16baffc024d1
--- /dev/null
+++ b/sys/compat/linuxkpi/common/include/linux/topology.h
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2025 The FreeBSD Foundation
+ * Copyright (c) 2025 Jean-Sébastien Pédron
+ *
+ * This software was developed by Jean-Sébastien Pédron under sponsorship
+ * from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUXKPI_LINUX_TOPOLOGY_H_
+#define _LINUXKPI_LINUX_TOPOLOGY_H_
+
+#include <asm/topology.h>
+
+#endif /* _LINUXKPI_LINUX_TOPOLOGY_H_ */
diff --git a/sys/compat/linuxkpi/common/src/linux_seq_file.c b/sys/compat/linuxkpi/common/src/linux_seq_file.c
index 8b426825cc78..9c06fe27bebe 100644
--- a/sys/compat/linuxkpi/common/src/linux_seq_file.c
+++ b/sys/compat/linuxkpi/common/src/linux_seq_file.c
@@ -64,13 +64,10 @@ seq_read(struct linux_file *f, char *ubuf, size_t size, off_t *ppos)
return (-EINVAL);
size = min(rc - *ppos, size);
- rc = strscpy(ubuf, sbuf_data(sbuf) + *ppos, size + 1);
+ memcpy(ubuf, sbuf_data(sbuf) + *ppos, size);
+ *ppos += size;
- /* add 1 for null terminator */
- if (rc > 0)
- rc += 1;
-
- return (rc);
+ return (size);
}
int
diff --git a/sys/kern/sys_timerfd.c b/sys/kern/sys_timerfd.c
index ab7e048a2ab1..565ab3ad6ee6 100644
--- a/sys/kern/sys_timerfd.c
+++ b/sys/kern/sys_timerfd.c
@@ -206,7 +206,6 @@ retry:
mtx_unlock(&tfd->tfd_lock);
return (EAGAIN);
}
- td->td_rtcgen = atomic_load_acq_int(&rtc_generation);
error = mtx_sleep(&tfd->tfd_count, &tfd->tfd_lock,
PCATCH, "tfdrd", 0);
if (error == 0) {
diff --git a/sys/kern/vfs_syscalls.c b/sys/kern/vfs_syscalls.c
index c64618036733..b805e147bd62 100644
--- a/sys/kern/vfs_syscalls.c
+++ b/sys/kern/vfs_syscalls.c
@@ -5050,11 +5050,12 @@ kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd,
size_t retlen;
void *rl_rcookie, *rl_wcookie;
off_t inoff, outoff, savinoff, savoutoff;
- bool foffsets_locked;
+ bool foffsets_locked, foffsets_set;
infp = outfp = NULL;
rl_rcookie = rl_wcookie = NULL;
foffsets_locked = false;
+ foffsets_set = false;
error = 0;
retlen = 0;
@@ -5122,6 +5123,8 @@ kern_copy_file_range(struct thread *td, int infd, off_t *inoffp, int outfd,
}
foffset_lock_pair(infp1, &inoff, outfp1, &outoff, 0);
foffsets_locked = true;
+ } else {
+ foffsets_set = true;
}
savinoff = inoff;
savoutoff = outoff;
@@ -5180,11 +5183,12 @@ out:
vn_rangelock_unlock(invp, rl_rcookie);
if (rl_wcookie != NULL)
vn_rangelock_unlock(outvp, rl_wcookie);
+ if ((foffsets_locked || foffsets_set) &&
+ (error == EINTR || error == ERESTART)) {
+ inoff = savinoff;
+ outoff = savoutoff;
+ }
if (foffsets_locked) {
- if (error == EINTR || error == ERESTART) {
- inoff = savinoff;
- outoff = savoutoff;
- }
if (inoffp == NULL)
foffset_unlock(infp, inoff, 0);
else
@@ -5193,6 +5197,9 @@ out:
foffset_unlock(outfp, outoff, 0);
else
*outoffp = outoff;
+ } else if (foffsets_set) {
+ *inoffp = inoff;
+ *outoffp = outoff;
}
if (outfp != NULL)
fdrop(outfp, td);
diff --git a/sys/netinet/tcp_input.c b/sys/netinet/tcp_input.c
index d58cc69b7625..d392cbe09950 100644
--- a/sys/netinet/tcp_input.c
+++ b/sys/netinet/tcp_input.c
@@ -1134,7 +1134,7 @@ tfo_socket_result:
V_tcp_sc_rst_sock_fail ?
"sending RST" : "try again");
if (V_tcp_sc_rst_sock_fail) {
- rstreason = BANDLIM_UNLIMITED;
+ rstreason = BANDLIM_TCP_RST;
goto dropwithreset;
} else
goto dropunlock;
@@ -1568,7 +1568,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th,
*/
if ((tp->t_state == TCPS_SYN_SENT) && (thflags & TH_ACK) &&
(SEQ_LEQ(th->th_ack, tp->iss) || SEQ_GT(th->th_ack, tp->snd_max))) {
- rstreason = BANDLIM_UNLIMITED;
+ rstreason = BANDLIM_TCP_RST;
tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT);
goto dropwithreset;
}
@@ -2218,7 +2218,6 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th,
SEQ_LT(th->th_seq, tp->last_ack_sent + tp->rcv_wnd)) {
tcp_log_end_status(tp, TCP_EI_STATUS_RST_IN_FRONT);
tp = tcp_drop(tp, ECONNRESET);
- rstreason = BANDLIM_UNLIMITED;
} else {
tcp_ecn_input_syn_sent(tp, thflags, iptos);
tcp_send_challenge_ack(tp, th, m);
@@ -2347,7 +2346,7 @@ tcp_do_segment(struct tcpcb *tp, struct mbuf *m, struct tcphdr *th,
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
tp = tcp_close(tp);
TCPSTAT_INC(tcps_rcvafterclose);
- rstreason = BANDLIM_UNLIMITED;
+ rstreason = BANDLIM_TCP_RST;
goto dropwithreset;
}
diff --git a/sys/netinet/tcp_stacks/bbr.c b/sys/netinet/tcp_stacks/bbr.c
index ce4e9f30020c..f2960ab9c636 100644
--- a/sys/netinet/tcp_stacks/bbr.c
+++ b/sys/netinet/tcp_stacks/bbr.c
@@ -7863,7 +7863,7 @@ nothing_left:
/* tcp_close will kill the inp pre-log the Reset */
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
tp = tcp_close(tp);
- ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, tlen);
+ ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, tlen);
BBR_STAT_INC(bbr_dropped_af_data);
return (1);
}
@@ -9405,7 +9405,7 @@ close_now:
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
tp = tcp_close(tp);
KMOD_TCPSTAT_INC(tcps_rcvafterclose);
- ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, (*tlen));
+ ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, (*tlen));
return (1);
}
if (sbavail(&so->so_snd) == 0)
diff --git a/sys/netinet/tcp_stacks/rack.c b/sys/netinet/tcp_stacks/rack.c
index d6bbfeb886d9..2dfcad84ad99 100644
--- a/sys/netinet/tcp_stacks/rack.c
+++ b/sys/netinet/tcp_stacks/rack.c
@@ -12038,7 +12038,7 @@ rack_process_ack(struct mbuf *m, struct tcphdr *th, struct socket *so,
/* tcp_close will kill the inp pre-log the Reset */
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
tp = tcp_close(tp);
- ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, tlen);
+ ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, tlen);
return (1);
}
}
@@ -13518,7 +13518,7 @@ rack_check_data_after_close(struct mbuf *m,
tcp_log_end_status(tp, TCP_EI_STATUS_SERVER_RST);
tp = tcp_close(tp);
KMOD_TCPSTAT_INC(tcps_rcvafterclose);
- ctf_do_dropwithreset(m, tp, th, BANDLIM_UNLIMITED, (*tlen));
+ ctf_do_dropwithreset(m, tp, th, BANDLIM_TCP_RST, (*tlen));
return (1);
}
if (sbavail(&so->so_snd) == 0)
diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c
index 26e7e53d540c..1fce7c591639 100644
--- a/sys/netinet/tcp_subr.c
+++ b/sys/netinet/tcp_subr.c
@@ -82,6 +82,7 @@
#include <netinet/ip.h>
#include <netinet/ip_icmp.h>
#include <netinet/ip_var.h>
+#include <netinet/icmp_var.h>
#ifdef INET6
#include <netinet/icmp6.h>
#include <netinet/ip6.h>
@@ -2156,6 +2157,13 @@ tcp_send_challenge_ack(struct tcpcb *tp, struct tcphdr *th, struct mbuf *m)
sbintime_t now;
bool send_challenge_ack;
+ /*
+ * The sending of a challenge ACK could be triggered by a blind attacker
+ * to detect an existing TCP connection. To mitigate that, increment
+ * also the global counter which would be incremented if the attacker
+ * would have guessed wrongly.
+ */
+ (void)badport_bandlim(BANDLIM_TCP_RST);
if (V_tcp_ack_war_time_window == 0 || V_tcp_ack_war_cnt == 0) {
/* ACK war protection is disabled. */
send_challenge_ack = true;
diff --git a/sys/powerpc/powerpc/busdma_machdep.c b/sys/powerpc/powerpc/busdma_machdep.c
index 65f90aa4affa..65a07c7ebc39 100644
--- a/sys/powerpc/powerpc/busdma_machdep.c
+++ b/sys/powerpc/powerpc/busdma_machdep.c
@@ -648,6 +648,7 @@ _bus_dmamap_load_buffer(bus_dma_tag_t dmat,
sgsize = MIN(buflen, PAGE_SIZE - (curaddr & PAGE_MASK));
if (map->pagesneeded != 0 && must_bounce(dmat, curaddr)) {
sgsize = roundup2(sgsize, dmat->alignment);
+ sgsize = MIN(sgsize, buflen);
curaddr = add_bounce_page(dmat, map, kvaddr, curaddr,
sgsize);
}
diff --git a/sys/riscv/riscv/busdma_bounce.c b/sys/riscv/riscv/busdma_bounce.c
index f652f08bf5dc..9d9556fc72f9 100644
--- a/sys/riscv/riscv/busdma_bounce.c
+++ b/sys/riscv/riscv/busdma_bounce.c
@@ -672,6 +672,7 @@ bounce_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
map->pagesneeded != 0 &&
addr_needs_bounce(dmat, curaddr)) {
sgsize = roundup2(sgsize, dmat->common.alignment);
+ sgsize = MIN(sgsize, buflen);
curaddr = add_bounce_page(dmat, map, kvaddr, curaddr,
sgsize);
} else if ((dmat->bounce_flags & BF_COHERENT) == 0) {
diff --git a/sys/rpc/rpcsec_gss/rpcsec_gss.c b/sys/rpc/rpcsec_gss/rpcsec_gss.c
index 53770d139c61..89d1c56f7cc2 100644
--- a/sys/rpc/rpcsec_gss/rpcsec_gss.c
+++ b/sys/rpc/rpcsec_gss/rpcsec_gss.c
@@ -858,7 +858,7 @@ rpc_gss_init(AUTH *auth, rpc_gss_options_ret_t *options_ret)
if (maj_stat == GSS_S_COMPLETE)
my_krb_imp = KRBIMP_MIT;
else
- my_krb_imp = KRBIMP_HESIOD1;
+ my_krb_imp = KRBIMP_HEIMDALV1;
}
/* GSS context establishment loop. */
diff --git a/sys/rpc/rpcsec_gss/rpcsec_gss_int.h b/sys/rpc/rpcsec_gss/rpcsec_gss_int.h
index 02a7767220de..ba200ee3aeb7 100644
--- a/sys/rpc/rpcsec_gss/rpcsec_gss_int.h
+++ b/sys/rpc/rpcsec_gss/rpcsec_gss_int.h
@@ -75,7 +75,7 @@ struct rpc_gss_init_res {
enum krb_imp {
KRBIMP_UNKNOWN,
- KRBIMP_HESIOD1,
+ KRBIMP_HEIMDALV1,
KRBIMP_MIT
};
diff --git a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
index e047c557c712..35c904560836 100644
--- a/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
+++ b/sys/rpc/rpcsec_gss/svc_rpcsec_gss.c
@@ -937,7 +937,7 @@ svc_rpc_gss_accept_sec_context(struct svc_rpc_gss_client *client,
if (maj_stat == GSS_S_COMPLETE)
my_krb_imp = KRBIMP_MIT;
else
- my_krb_imp = KRBIMP_HESIOD1;
+ my_krb_imp = KRBIMP_HEIMDALV1;
min_stat = 0;
}
diff --git a/sys/sys/param.h b/sys/sys/param.h
index 72061bd8134e..b9942c7bc2fd 100644
--- a/sys/sys/param.h
+++ b/sys/sys/param.h
@@ -74,7 +74,7 @@
* cannot include sys/param.h and should only be updated here.
*/
#undef __FreeBSD_version
-#define __FreeBSD_version 1500058
+#define __FreeBSD_version 1500059
/*
* __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,
diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h
index 7ab2f021e408..5743dc1c8033 100644
--- a/sys/sys/unistd.h
+++ b/sys/sys/unistd.h
@@ -216,6 +216,15 @@
#define CLOSE_RANGE_CLOEXEC (1<<2)
#define CLOSE_RANGE_CLOFORK (1<<3)
+/*
+ * copy_file_range flags visible to user space.
+ * High order 8 bits reserved for kernel flags.
+ * Allocate from bit 23 down, to try and avoid conflicts with
+ * future Linux flags.
+ */
+#define COPY_FILE_RANGE_CLONE 0x00800000 /* Require cloning. */
+#define COPY_FILE_RANGE_USERFLAGS (COPY_FILE_RANGE_CLONE)
+
#endif /* __BSD_VISIBLE */
#endif /* !_SYS_UNISTD_H_ */
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 8080e9edd8c3..074769d55c2d 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -397,21 +397,8 @@ struct vattr {
*/
#define VLKTIMEOUT (hz / 20 + 1)
-/* copy_file_range flags */
-#define COPY_FILE_RANGE_KFLAGS 0xff000000
-
-/*
- * copy_file_range flags visible to user space.
- * Allocate high bits first, to try and avoid conflicting with Linux.
- */
-#define COPY_FILE_RANGE_CLONE 0x00800000 /* Require cloning. */
-#define COPY_FILE_RANGE_USERFLAGS (COPY_FILE_RANGE_CLONE)
-
#ifdef _KERNEL
-/* copy_file_range flags only usable in the kernel */
-#define COPY_FILE_RANGE_TIMEO1SEC 0x01000000 /* Return after 1sec. */
-
#ifdef MALLOC_DECLARE
MALLOC_DECLARE(M_VNODE);
#endif
@@ -634,6 +621,10 @@ typedef void vop_getpages_iodone_t(void *, vm_page_t *, int, int);
#define VN_OPEN_INVFS 0x00000008
#define VN_OPEN_WANTIOCTLCAPS 0x00000010
+/* copy_file_range kernel flags */
+#define COPY_FILE_RANGE_KFLAGS 0xff000000
+#define COPY_FILE_RANGE_TIMEO1SEC 0x01000000 /* Return after 1sec. */
+
/*
* Public vnode manipulation functions.
*/
diff --git a/sys/x86/x86/busdma_bounce.c b/sys/x86/x86/busdma_bounce.c
index 040174113104..e86279aa9c98 100644
--- a/sys/x86/x86/busdma_bounce.c
+++ b/sys/x86/x86/busdma_bounce.c
@@ -726,6 +726,7 @@ bounce_bus_dmamap_load_buffer(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
map->pagesneeded != 0 &&
must_bounce(dmat, curaddr)) {
sgsize = roundup2(sgsize, dmat->common.alignment);
+ sgsize = MIN(sgsize, buflen);
curaddr = add_bounce_page(dmat, map, kvaddr, curaddr, 0,
sgsize);
}
diff --git a/tools/build/options/makeman b/tools/build/options/makeman
index e0980d3be607..ddd08443e61c 100755
--- a/tools/build/options/makeman
+++ b/tools/build/options/makeman
@@ -127,8 +127,8 @@ show()
exit 1
;;
esac
- requireds=`env -i ${make} -f ${srcdir}/share/mk/src.opts.mk \
- -V '${__REQUIRED_OPTIONS:ts,}'`
+ requireds=$(env -i ${make} -f ${srcdir}/share/mk/src.opts.mk \
+ -V 'REQUIRED_OPTIONS:ts,')
env -i ${make} .MAKE.MODE=normal "$@" showconfig __MAKE_CONF=/dev/null \
SRCCONF=/dev/null |
while read var _ val ; do
diff --git a/usr.bin/top/machine.c b/usr.bin/top/machine.c
index 8c035b5df383..1f70ee9281e8 100644
--- a/usr.bin/top/machine.c
+++ b/usr.bin/top/machine.c
@@ -190,15 +190,6 @@ static int pageshift; /* log base 2 of the pagesize */
#define ki_swap(kip) \
((kip)->ki_swrss > (kip)->ki_rssize ? (kip)->ki_swrss - (kip)->ki_rssize : 0)
-/*
- * Sorting orders. The first element is the default.
- */
-static const char *ordernames[] = {
- "cpu", "size", "res", "time", "pri", "threads",
- "total", "read", "write", "fault", "vcsw", "ivcsw",
- "jid", "swap", "pid", NULL
-};
-
/* Per-cpu time states */
static int maxcpu;
static int maxid;
@@ -214,6 +205,18 @@ static int *pcpu_cpu_states;
static int battery_units;
static int battery_life;
+static int compare_cpu(const void *a, const void *b);
+static int compare_size(const void *a, const void *b);
+static int compare_res(const void *a, const void *b);
+static int compare_time(const void *a, const void *b);
+static int compare_prio(const void *a, const void *b);
+static int compare_threads(const void *a, const void *b);
+static int compare_iototal(const void *a, const void *b);
+static int compare_ioread(const void *a, const void *b);
+static int compare_iowrite(const void *a, const void *b);
+static int compare_iofault(const void *a, const void *b);
+static int compare_vcsw(const void *a, const void *b);
+static int compare_ivcsw(const void *a, const void *b);
static int compare_swap(const void *a, const void *b);
static int compare_jid(const void *a, const void *b);
static int compare_pid(const void *a, const void *b);
@@ -225,6 +228,77 @@ static void update_layout(void);
static int find_uid(uid_t needle, int *haystack);
static int cmd_matches(struct kinfo_proc *, const char *);
+/*
+ * Sorting orders. The first element is the default.
+ */
+
+typedef int (compare_fn)(const void *arg1, const void *arg2);
+static const struct sort_info {
+ const char *si_name;
+ compare_fn *si_compare;
+} sortdata[] = {
+ {
+ .si_name = "cpu",
+ .si_compare = &compare_cpu,
+ },
+ {
+ .si_name = "size",
+ .si_compare = &compare_size,
+ },
+ {
+ .si_name = "res",
+ .si_compare = &compare_res,
+ },
+ {
+ .si_name = "time",
+ .si_compare = &compare_time,
+ },
+ {
+ .si_name = "pri",
+ .si_compare = &compare_prio,
+ },
+ {
+ .si_name = "threads",
+ .si_compare = &compare_threads,
+ },
+ {
+ .si_name = "total",
+ .si_compare = &compare_iototal,
+ },
+ {
+ .si_name = "read",
+ .si_compare = &compare_ioread,
+ },
+ {
+ .si_name = "write",
+ .si_compare = &compare_iowrite,
+ },
+ {
+ .si_name = "fault",
+ .si_compare = &compare_iofault,
+ },
+ {
+ .si_name = "vcsw",
+ .si_compare = &compare_vcsw,
+ },
+ {
+ .si_name = "ivcsw",
+ .si_compare = &compare_ivcsw,
+ },
+ {
+ .si_name = "jid",
+ .si_compare = &compare_jid,
+ },
+ {
+ .si_name = "swap",
+ .si_compare = &compare_swap,
+ },
+ {
+ .si_name = "pid",
+ .si_compare = &compare_pid,
+ },
+};
+
static int
find_uid(uid_t needle, int *haystack)
{
@@ -353,7 +427,6 @@ machine_init(struct statics *statics)
statics->swap_names = swapnames;
else
statics->swap_names = NULL;
- statics->order_names = ordernames;
/* Allocate state for per-CPU stats. */
GETSYSCTL("kern.smp.maxcpus", maxcpu);
@@ -742,7 +815,7 @@ static struct handle handle;
void *
get_process_info(struct system_info *si, struct process_select *sel,
- int (*compare)(const void *, const void *))
+ const struct sort_info *sort_info)
{
int i;
int total_procs;
@@ -753,6 +826,9 @@ get_process_info(struct system_info *si, struct process_select *sel,
struct kinfo_proc **prefp;
struct kinfo_proc *pp;
struct timespec previous_proc_uptime;
+ compare_fn *compare;
+
+ compare = sort_info->si_compare;
/*
* If thread state was toggled, don't cache the previous processes.
@@ -899,6 +975,43 @@ get_process_info(struct system_info *si, struct process_select *sel,
return (&handle);
}
+/*
+ * Returns the sort info associated with the specified order. Currently, that's
+ * really only the comparator that we'll later use. Specifying a NULL ordername
+ * will return the default comparator.
+ */
+const struct sort_info *
+get_sort_info(const char *ordername)
+{
+ const struct sort_info *info;
+ size_t idx;
+
+ if (ordername == NULL)
+ return (&sortdata[0]);
+
+ for (idx = 0; idx < nitems(sortdata); idx++) {
+ info = &sortdata[idx];
+
+ if (strcmp(info->si_name, ordername) == 0)
+ return (info);
+ }
+
+ return (NULL);
+}
+
+void
+dump_sort_names(FILE *fp)
+{
+ const struct sort_info *info;
+ size_t idx;
+
+ for (idx = 0; idx < nitems(sortdata); idx++) {
+ info = &sortdata[idx];
+
+ fprintf(fp, " %s", info->si_name);
+ }
+}
+
static int
cmd_matches(struct kinfo_proc *proc, const char *term)
{
@@ -1559,26 +1672,6 @@ compare_ivcsw(const void *arg1, const void *arg2)
return (flp2 - flp1);
}
-int (*compares[])(const void *arg1, const void *arg2) = {
- compare_cpu,
- compare_size,
- compare_res,
- compare_time,
- compare_prio,
- compare_threads,
- compare_iototal,
- compare_ioread,
- compare_iowrite,
- compare_iofault,
- compare_vcsw,
- compare_ivcsw,
- compare_jid,
- compare_swap,
- compare_pid,
- NULL
-};
-
-
static int
swapmode(int *retavail, int *retfree)
{
diff --git a/usr.bin/top/machine.h b/usr.bin/top/machine.h
index 57f2846cdba5..b4f2f1a8bd50 100644
--- a/usr.bin/top/machine.h
+++ b/usr.bin/top/machine.h
@@ -89,10 +89,15 @@ void get_system_info(struct system_info *si);
int machine_init(struct statics *statics);
/* non-int routines typically used by the machine dependent module */
+struct sort_info;
+
extern struct process_select ps;
void *
get_process_info(struct system_info *si, struct process_select *sel,
- int (*compare)(const void *, const void *));
+ const struct sort_info *);
+
+const struct sort_info *get_sort_info(const char *name);
+void dump_sort_names(FILE *fp);
#endif /* MACHINE_H */
diff --git a/usr.bin/top/top.c b/usr.bin/top/top.c
index 856ad838dc1c..f0458a4037af 100644
--- a/usr.bin/top/top.c
+++ b/usr.bin/top/top.c
@@ -252,7 +252,7 @@ main(int argc, const char *argv[])
char no_command = 1;
struct timeval timeout;
char *order_name = NULL;
- int order_index = 0;
+ const struct sort_info *sort_info = NULL;
fd_set readfds;
char *nptr;
@@ -505,21 +505,18 @@ main(int argc, const char *argv[])
/* determine sorting order index, if necessary */
if (order_name != NULL)
{
- if ((order_index = string_index(order_name, statics.order_names)) == -1)
- {
- const char * const *pp;
-
+ if ((sort_info = get_sort_info(order_name)) == NULL) {
warnx("'%s' is not a recognized sorting order.", order_name);
fprintf(stderr, "\tTry one of these:");
- pp = statics.order_names;
- while (*pp != NULL)
- {
- fprintf(stderr, " %s", *pp++);
- }
+ dump_sort_names(stderr);
fputc('\n', stderr);
exit(1);
}
}
+ else
+ {
+ sort_info = get_sort_info(NULL);
+ }
/* initialize termcap */
init_termcap(interactive);
@@ -602,17 +599,13 @@ restart:
while ((displays == -1) || (displays-- > 0))
{
- int (*compare)(const void * const, const void * const);
-
/* get the current stats */
get_system_info(&system_info);
- compare = compares[order_index];
-
/* get the current set of processes */
processes =
- get_process_info(&system_info, &ps, compare);
+ get_process_info(&system_info, &ps, sort_info);
/* display the load averages */
(*d_loadave)(system_info.last_pid,
@@ -1047,7 +1040,9 @@ restart:
"Order to sort: ");
if (readline(tempbuf2, sizeof(tempbuf2), false) > 0)
{
- if ((i = string_index(tempbuf2, statics.order_names)) == -1)
+ const struct sort_info *new_sort_info;
+
+ if ((new_sort_info = get_sort_info(tempbuf2)) == NULL)
{
new_message(MT_standout,
" %s: unrecognized sorting order", tempbuf2);
@@ -1055,7 +1050,7 @@ restart:
}
else
{
- order_index = i;
+ sort_info = new_sort_info;
}
putchar('\r');
}
diff --git a/usr.bin/top/utils.c b/usr.bin/top/utils.c
index cde89a211b53..a8ddb3eb63a0 100644
--- a/usr.bin/top/utils.c
+++ b/usr.bin/top/utils.c
@@ -117,27 +117,6 @@ digits(int val)
}
/*
- * string_index(string, array) - find string in array and return index
- */
-
-int
-string_index(const char *string, const char * const *array)
-{
- size_t i = 0;
-
- while (*array != NULL)
- {
- if (strcmp(string, *array) == 0)
- {
- return(i);
- }
- array++;
- i++;
- }
- return(-1);
-}
-
-/*
* argparse(line, cntp) - parse arguments in string "line", separating them
* out into an argv-like array, and setting *cntp to the number of
* arguments encountered. This is a simple parser that doesn't understand
diff --git a/usr.bin/top/utils.h b/usr.bin/top/utils.h
index a730e339d200..bbc63803b6e1 100644
--- a/usr.bin/top/utils.h
+++ b/usr.bin/top/utils.h
@@ -19,6 +19,5 @@ const char **argparse(char *, int *);
long percentages(int, int *, long *, long *, long *);
const char *format_time(long);
char *format_k(int64_t);
-int string_index(const char *string, const char * const *array);
int find_pid(pid_t pid);
diff --git a/usr.sbin/autofs/common.c b/usr.sbin/autofs/common.c
index 18756752876c..6b98214162ae 100644
--- a/usr.sbin/autofs/common.c
+++ b/usr.sbin/autofs/common.c
@@ -149,7 +149,7 @@ create_directory(const char *path)
error = mkdir(partial, 0755);
if (error != 0 && errno != EEXIST) {
log_warn("cannot create %s", partial);
- return;
+ break;
}
}
diff --git a/usr.sbin/bhyve/pci_xhci.c b/usr.sbin/bhyve/pci_xhci.c
index 0871bbb87fe5..ff12e40359e2 100644
--- a/usr.sbin/bhyve/pci_xhci.c
+++ b/usr.sbin/bhyve/pci_xhci.c
@@ -406,7 +406,7 @@ pci_xhci_usbcmd_write(struct pci_xhci_softc *sc, uint32_t cmd)
* XHCI 4.19.3 USB2 RxDetect->Polling,
* USB3 Polling->U0
*/
- if (dev->dev_ue->ue_usbver == 2)
+ if (dev->hci.hci_usbver == 2)
port->portsc |=
XHCI_PS_PLS_SET(UPS_PORT_LS_POLL);
else
@@ -2590,7 +2590,7 @@ pci_xhci_reset_port(struct pci_xhci_softc *sc, int portn, int warm)
port->portsc |= XHCI_PS_PED |
XHCI_PS_SPEED_SET(dev->hci.hci_speed);
- if (warm && dev->dev_ue->ue_usbver == 3) {
+ if (warm && dev->hci.hci_usbver == 3) {
port->portsc |= XHCI_PS_WRC;
}
@@ -2620,7 +2620,7 @@ pci_xhci_init_port(struct pci_xhci_softc *sc, int portn)
port->portsc = XHCI_PS_CCS | /* connected */
XHCI_PS_PP; /* port power */
- if (dev->dev_ue->ue_usbver == 2) {
+ if (dev->hci.hci_usbver == 2) {
port->portsc |= XHCI_PS_PLS_SET(UPS_PORT_LS_POLL) |
XHCI_PS_SPEED_SET(dev->hci.hci_speed);
} else {
@@ -2785,8 +2785,8 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
cookie = NULL;
while ((name = nvlist_next(slots_nvl, &type, &cookie)) != NULL) {
- if (usb2_port == ((sc->usb2_port_start) + XHCI_MAX_DEVS/2) ||
- usb3_port == ((sc->usb3_port_start) + XHCI_MAX_DEVS/2)) {
+ if (usb2_port == ((sc->usb2_port_start) + XHCI_MAX_DEVS / 2) ||
+ usb3_port == ((sc->usb3_port_start) + XHCI_MAX_DEVS / 2)) {
WPRINTF(("pci_xhci max number of USB 2 or 3 "
"devices reached, max %d", XHCI_MAX_DEVS/2));
goto bad;
@@ -2834,12 +2834,25 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
dev->hci.hci_intr = pci_xhci_dev_intr;
dev->hci.hci_event = pci_xhci_dev_event;
dev->hci.hci_speed = USB_SPEED_MAX;
+ dev->hci.hci_usbver = -1;
- if (ue->ue_usbver == 2) {
+ devsc = ue->ue_probe(&dev->hci, nvl);
+ if (devsc == NULL) {
+ free(dev);
+ goto bad;
+ }
+ dev->dev_sc = devsc;
+
+ if (dev->hci.hci_usbver == -1)
+ dev->hci.hci_usbver = ue->ue_usbver;
+
+ if (dev->hci.hci_usbver == 2) {
if (usb2_port == sc->usb2_port_start +
XHCI_MAX_DEVS / 2) {
WPRINTF(("pci_xhci max number of USB 2 devices "
"reached, max %d", XHCI_MAX_DEVS / 2));
+ free(dev->dev_sc);
+ free(dev);
goto bad;
}
dev->hci.hci_port = usb2_port;
@@ -2849,6 +2862,8 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
XHCI_MAX_DEVS / 2) {
WPRINTF(("pci_xhci max number of USB 3 devices "
"reached, max %d", XHCI_MAX_DEVS / 2));
+ free(dev->dev_sc);
+ free(dev);
goto bad;
}
dev->hci.hci_port = usb3_port;
@@ -2857,13 +2872,10 @@ pci_xhci_parse_devices(struct pci_xhci_softc *sc, nvlist_t *nvl)
XHCI_DEVINST_PTR(sc, dev->hci.hci_port) = dev;
dev->hci.hci_address = 0;
- devsc = ue->ue_init(&dev->hci, nvl);
- if (devsc == NULL) {
+ if (ue->ue_init(dev->dev_sc))
goto bad;
- }
dev->dev_ue = ue;
- dev->dev_sc = devsc;
if (dev->hci.hci_speed == USB_SPEED_MAX)
dev->hci.hci_speed = ue->ue_usbspeed;
@@ -2885,6 +2897,8 @@ portsfinal:
bad:
for (i = 1; i <= XHCI_MAX_DEVS; i++) {
+ if (XHCI_DEVINST_PTR(sc, i) != NULL)
+ free(XHCI_DEVINST_PTR(sc, i)->dev_sc);
free(XHCI_DEVINST_PTR(sc, i));
}
@@ -3232,6 +3246,7 @@ pci_xhci_snapshot(struct vm_snapshot_meta *meta)
SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_address, meta, ret, done);
SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_port, meta, ret, done);
SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_speed, meta, ret, done);
+ SNAPSHOT_VAR_OR_LEAVE(dev->hci.hci_usbver, meta, ret, done);
}
SNAPSHOT_VAR_OR_LEAVE(sc->usb2_port_start, meta, ret, done);
diff --git a/usr.sbin/bhyve/usb_emul.h b/usr.sbin/bhyve/usb_emul.h
index 85dedfeacd3b..43b6b53b5205 100644
--- a/usr.sbin/bhyve/usb_emul.h
+++ b/usr.sbin/bhyve/usb_emul.h
@@ -52,7 +52,8 @@ struct usb_devemu {
int ue_usbspeed; /* usb device speed */
/* instance creation */
- void *(*ue_init)(struct usb_hci *hci, nvlist_t *nvl);
+ void *(*ue_probe)(struct usb_hci *hci, nvlist_t *nvl);
+ int (*ue_init)(void *sc);
/* handlers */
int (*ue_request)(void *sc, struct usb_data_xfer *xfer);
@@ -86,6 +87,7 @@ struct usb_hci {
int hci_address;
int hci_port;
int hci_speed;
+ int hci_usbver;
};
/*
diff --git a/usr.sbin/bhyve/usb_mouse.c b/usr.sbin/bhyve/usb_mouse.c
index a37941c0cd9d..82b1159d5f61 100644
--- a/usr.sbin/bhyve/usb_mouse.c
+++ b/usr.sbin/bhyve/usb_mouse.c
@@ -295,20 +295,28 @@ umouse_event(uint8_t button, int x, int y, void *arg)
}
static void *
-umouse_init(struct usb_hci *hci, nvlist_t *nvl __unused)
+umouse_probe(struct usb_hci *hci, nvlist_t *nvl __unused)
{
struct umouse_softc *sc;
sc = calloc(1, sizeof(struct umouse_softc));
sc->hci = hci;
+ return (sc);
+}
+
+static int
+umouse_init(void *scarg)
+{
+ struct umouse_softc *sc = (struct umouse_softc *)scarg;
+
sc->hid.protocol = 1; /* REPORT protocol */
pthread_mutex_init(&sc->mtx, NULL);
pthread_mutex_init(&sc->ev_mtx, NULL);
console_ptr_register(umouse_event, sc, 10);
- return (sc);
+ return (0);
}
#define UREQ(x,y) ((x) | ((y) << 8))
@@ -811,6 +819,7 @@ static struct usb_devemu ue_mouse = {
.ue_emu = "tablet",
.ue_usbver = 3,
.ue_usbspeed = USB_SPEED_HIGH,
+ .ue_probe = umouse_probe,
.ue_init = umouse_init,
.ue_request = umouse_request,
.ue_data = umouse_data_handler,