Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
tavianator committed May 16, 2024
1 parent 5fd4fa2 commit 5e8a7a8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/bfstd.c
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,21 @@ int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *
#endif
}

long xsysconf(int name) {
#if __FreeBSD__ && SANITIZE_MEMORY
// Work around https://github.com/llvm/llvm-project/issues/88163
__msan_scoped_disable_interceptor_checks();
#endif

long ret = sysconf(name);

#if __FreeBSD__ && SANITIZE_MEMORY
__msan_scoped_enable_interceptor_checks();
#endif

return ret;
}

size_t asciilen(const char *str) {
return asciinlen(str, strlen(str));
}
Expand Down
5 changes: 5 additions & 0 deletions src/bfstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ char *xconfstr(int name);
*/
int xstrtofflags(const char **str, unsigned long long *set, unsigned long long *clear);

/**
* Wrapper for sysconf() that works around an MSan bug.
*/
long xsysconf(int name);

#include <wchar.h>

/**
Expand Down
3 changes: 2 additions & 1 deletion src/ctx.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "ctx.h"
#include "alloc.h"
#include "bfstd.h"
#include "color.h"
#include "diag.h"
#include "expr.h"
Expand All @@ -22,7 +23,7 @@

/** Get the initial value for ctx->threads (-j). */
static int bfs_nproc(void) {
long nproc = sysconf(_SC_NPROCESSORS_ONLN);
long nproc = xsysconf(_SC_NPROCESSORS_ONLN);

if (nproc < 1) {
nproc = 1;
Expand Down
4 changes: 2 additions & 2 deletions src/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static size_t bfs_exec_arg_size(const char *arg) {

/** Determine the maximum argv size. */
static size_t bfs_exec_arg_max(const struct bfs_exec *execbuf) {
long arg_max = sysconf(_SC_ARG_MAX);
long arg_max = xsysconf(_SC_ARG_MAX);
bfs_exec_debug(execbuf, "ARG_MAX: %ld according to sysconf()\n", arg_max);
if (arg_max < 0) {
arg_max = BFS_EXEC_ARG_MAX;
Expand All @@ -82,7 +82,7 @@ static size_t bfs_exec_arg_max(const struct bfs_exec *execbuf) {

// Assume arguments are counted with the granularity of a single page,
// so allow a one page cushion to account for rounding up
long page_size = sysconf(_SC_PAGESIZE);
long page_size = xsysconf(_SC_PAGESIZE);
if (page_size < 4096) {
page_size = 4096;
}
Expand Down

0 comments on commit 5e8a7a8

Please sign in to comment.