Commit Graph

1222 Commits

Author SHA1 Message Date
msaitoh 70816a3c4f s/descriminated/discriminated/ in comment. 2024-05-12 23:52:57 +00:00
chs 779666e6a0 radixtree: allocate memory with KM_NOSLEEP to prevent pagedaemon hangs
Revert the part of rev 1.32 (reapplying "Do away with separate pool_cache
for some kernel objects") that changed the memory allocation for radixtree
nodes from PR_NOWAIT to KM_SLEEP as part of changing from a pool to kmem.
uvm_pageinsert_tree() calls into the radixtree code while holding
the object's vmobjlock, but that same lock is taken by the pagedaemon
in the process of reclaiming pages, and if the pagedaemon happens to
choose the same object to reclaim from that uvm_pageinsert_tree()
is being called on, then these two threads will deadlock.
The previous code already handled memory allocation failures
in uvm_pageinsert_tree() so we can simply change it back to nosleep.

Fixes a hang reported by simonb@, and the fix was also tested by him.
2024-05-04 17:58:24 +00:00
rillig b5be0901e3 snprintb: reject empty bit descriptions and wrongly placed defaults 2024-04-07 15:20:16 +00:00
rillig 442f4c6c59 snprintb: reject combinations of 'f' with ':' as well as 'F' with '='
These combinations would lead to garbled output.
2024-04-07 12:05:23 +00:00
rillig 864a50a39a snprintb: reject empty descriptions
In cases where the snprintb output is garbled, it is not trustworthy, so
make sure the mistakes in the bitfmt are fixed early.
2024-04-07 10:10:54 +00:00
rillig 24a52b6ecd snprintb: remove redundant memset in kernel mode
The provided buffer is already null-terminated by finish_buffer, even in
error cases, there is no need to repeat the same work.
2024-04-01 08:53:42 +00:00
andvar 3282d009d0 s/Westley/Wesley/ in a book reference (in comments). 2024-03-30 22:03:39 +00:00
rillig b050579e9d snprintb: mark the end of the buffer if the buffer is too small
This avoids confusion in case the buffer ends with an incomplete number.
2024-03-25 20:39:26 +00:00
rillig c4ea73f5bf snprintb: shrink code size, both in source and binary 2024-03-05 07:37:08 +00:00
rillig e572db3830 snprintb: error out on unknown new-style formatting directive 2024-03-04 21:35:28 +00:00
rillig 4734052d82 snprintb: clean up
Use consistent data types for buffer positions and lengths, to avoid
type casts.
2024-02-24 12:44:11 +00:00
rillig e7ed3a67af snprintb: allow non-ASCII descriptions on all platforms
Previously, these descriptions were only allowed on platforms where
plain 'char' is unsigned. On platforms where plain 'char' is signed,
they invoked undefined behavior or terminated the output early.
2024-02-24 12:40:00 +00:00
christos c68df8acc1 fix static unused issue until lint understands attributes better. 2024-02-23 13:32:28 +00:00
rillig 69c5b3b0c1 snprintb: always null-terminate output
Always null-terminate the output in the buffer, even in error cases. The
wording in the manual page has been promising this since 2008. For
snprintb_m, ensure that the output is terminated with two null
characters, to gracefully handle situations in which the caller does not
check whether snprintb returned an error.

If the buffer size is zero, allow the buffer to be a null pointer,
analogous to snprintf.

Fix an out-of-bounds memory read if the bitfmt ends with a '*' directive
(since today).

In the tests, merge the helper functions for snprintb, snprintb_m, as
they were similar enough.

Fix a few 'line_max exceeded' tests, ensuring that they output a '#'
marker, and that the 'complete' tests don't.
2024-02-22 21:04:23 +00:00
rillig d101133e9b snprintb: error out on out-of-bounds bit shifts
Previously, these invoked undefined behavior, now they lead to an early
return. An example of out-of-bounds bit number is in SCZ_PCICTRL_BITS.
Bit fields that extend beyond the msb are still allowed.

Allow 'f' and 'F' to have fields that are 64 bits wide. This only makes
sense when the field starts at bit 0.

Remove the unused 'val_len', it was only needed before snprintb.c 1.20.
2024-02-22 18:26:15 +00:00
rillig 12034681d8 snprintb_m: limit length of generated strings
The manual page promises that the 'max' argument limits the length of
the generated strings, so don't generate any strings that are longer
than that limit. Mark incomplete strings with a trailing '#' to make
them easily recognizable.
2024-02-20 20:31:56 +00:00
rillig 8f391120f6 snprintb: fix how named bit-fields are split into multiple lines 2024-02-19 23:30:56 +00:00
rillig f48e1c68b4 snprintb: convert macros to local functions
Let the compiler decide whether to inline the functions; allow stepping
through the code in a debugger.
2024-02-17 10:23:30 +00:00
rillig e8d4427725 snprintb: do not modify bufsize when producing multiple lines 2024-02-16 21:25:46 +00:00
rillig 0b94bf4814 snprintb: eliminate two local variables, allow zero-size buffer
Like snprintf, the buffer size may be zero. Unlike snprintf, the buffer
must not be NULL.
2024-02-16 19:53:40 +00:00
rillig 9d8f0ef5b5 snprintb: use size_t for buffer sizes and positions 2024-02-16 19:31:25 +00:00
rillig c277ab1882 snprintb: fix integer overflow when writing past a small buffer
Previously, snprintb returned -1 in this case, assuming that the
snprintf used in FMTSTR validates against an overly large buffer size.
2024-02-16 19:20:38 +00:00
rillig 8fe8a849c2 snprintb: use unsigned integers for parsing the bitfmt 2024-02-16 18:17:10 +00:00
rillig 889b1738f6 snprintb: fix '=' and ':' for 8-bit values on platforms with signed char
Previously, '=' and ':' worked only on platforms where plain 'char' is
unsigned. On platforms where plain 'char' is signed, only 7-bit values
worked.
2024-02-16 18:09:15 +00:00
rillig 8548878b97 snprintb: eliminate a few local variables 2024-02-16 18:03:16 +00:00
rillig 798cb1a74f snprintb: rename local variables
The single-letter variables 't', 's', 'l' and 'c' were too hard to
decipher.

The variable 'f_len' was used for two independent purposes.

Use a narrow scope for some variables, to avoid having to keep track of
22 individual variables at the same time.

No binary change.
2024-02-16 17:42:49 +00:00
rillig 64ace9d638 snprintb: clean up
Remove redundant parentheses and casts.

Indent statement-like macros consistently, use separate lines for each
statement, add parentheses to macro definitions.

Remove CONSTCOND comments as lint doesn't need them anymore.

No binary change.
2024-02-16 01:57:50 +00:00
rillig 26844513e8 snprintb: fix string termination (since today)
In the previous commit, I had accidentally only run the tests for
snprintb_m but not those for snprintb, thereby missing a newly
introduced bug that would not null-terminate the resulting strings.

Add more tests to cover similar situations in which the buffer is too
small to contain the complete output.
2024-02-15 23:48:51 +00:00
rillig 6f937561f5 snprintb: rename buflen to bufsize, following the wording in snprintf 2024-02-15 22:48:58 +00:00
rillig 795d5f45da snprintb: fix out-of-bounds write 2024-02-15 22:37:10 +00:00
christos d231a5d255 sprinkle unused. 2024-02-14 18:00:02 +00:00
andvar 1cd43426d5 Fix various typos in comments, log messages and documentation. 2024-02-10 18:43:51 +00:00
andvar d378954346 fix misplaced or missing "e" in words with "ment" ending (argument, implement,
increment, decrement, alignment), in comments, documentation, log messages.
2024-02-08 20:51:24 +00:00
msaitoh 90313c06e6 Remove ryo@'s mail addresses. 2024-02-07 04:20:25 +00:00
andvar 82bba4e936 fix various typos in comments. 2024-02-05 21:46:04 +00:00
christos 70a4c69411 mark unused argument 2024-02-04 16:19:12 +00:00
christos a3cd843f2a sprinkle argsused 2024-01-29 16:09:45 +00:00
thorpej 5be0c2a9f6 Catch up with revision 1.5 of atomic_init_cas.c. Fixes building libc
on sun2, and probably others.
2024-01-21 03:42:08 +00:00
christos f1987b28c8 PR/57828: Alejandro Colomar: Prioritize test for ERANGE before testing for
fully consuming the string. Adjust strtonum(3) to behave as before. Document
the order of the tests and sync the man pages (I should really autogenerate
one of the two man pages...)
2024-01-20 16:13:39 +00:00
christos 12ddec6097 Add __UNCONST 2024-01-20 14:55:11 +00:00
christos 1ab7ad1313 move local decls to headers 2024-01-20 14:55:02 +00:00
kre 3f351f34c6 Compensate for src/common/lib/libc/atomic/atomic_init_cas.c losing
the extern declaration of __libc_atomic_init() and instead using a
new one added to src/lib/libc/include/extern.h

That file is outside src/common and src/sys so is unavailable to
kernel builds, so instead make a new include file in src/common
which the kernel can read which contains the needed extern decl
for __libc_atomic_init()

This seems to fix the evbarm builds (maybe others) - but it is
all MUCH TOO UGLY to keep.   Someone please make a better fix,
even if that just means reverting rev 1.5 of
	src/common/lib/libc/atomic/atomic_init_cas.c
and all of the changes here (the addition to libc/include/extern.h
should be harmless to keep).
2024-01-20 11:04:53 +00:00
christos 6b87cd2642 make decls consistent 2024-01-19 19:33:49 +00:00
christos 52c89f6234 use size_t 2024-01-19 19:32:42 +00:00
andvar 84176bea91 s/miltiple/multiple/ in comment. 2023-12-07 07:10:44 +00:00
thorpej fc5ee90beb In _prop_string_instantiate(), when we de-dup a non-MUTABLE string, make
sure we free the provided string buffer if NOCOPY is not set.  Fixes
a memory leak reported by M. Boerschig.

While we're at it, also change _prop_string_instantiate() to free the
provided string buffer in the not-NOCOPY case when string object allocation
fails (this was previously handled by _prop_string_instantiate()'s
callers).

PR lib/57699
2023-11-17 21:29:33 +00:00
skrll 7ada0067d3 Define __HAVE_ATOMIC_CAS_64_UP and provide __sync_val_compare_and_swap_8
The new santizer code in gcc12 needs this.
2023-10-29 08:04:18 +00:00
ad 996c09cd17 kmem_free() -> kmem_intr_free(). Spotted by rin@. 2023-09-23 19:17:38 +00:00
ad 59e0001f2c Repply this change with a couple of bugs fixed:
- Do away with separate pool_cache for some kernel objects that have no special
  requirements and use the general purpose allocator instead. On one of my
  test systems this makes for a small (~1%) but repeatable reduction in system
  time during builds presumably because it decreases the kernel's cache /
  memory bandwidth footprint a little.
- vfs_lockf: cache a pointer to the uidinfo and put mutex in the data segment.
2023-09-23 18:21:11 +00:00
ad ef0f79c8d1 Back out recent change to replace pool_cache with then general allocator.
Will return to this when I have time again.
2023-09-12 16:17:21 +00:00