aboutsummaryrefslogtreecommitdiff
path: root/sys/kern/subr_prf.c
Commit message (Collapse)AuthorAgeFilesLines
* kvprintf(): Fix '+' conversion handlingSebastian Huber2024-09-061-14/+13
| | | | | | | | | | | | | | | | | For example, printf("%+i", 1) prints "+1". However, kvprintf() did print just "1" for this example. According to PRINTF(3): A sign must always be placed before a number produced by a signed conversion. For "%+r" radix conversions, keep the "+" handling as it is, since this is a non-standard conversion. For "%+p" pointer conversions, continue to ignore the sign modifier to be in line with libc. This change allows to support the ' conversion modifier in the future. Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/1310
* Fix "%hhi" conversion for kvprintf()Sebastian Huber2024-06-281-1/+1
| | | | | | | The signedness of "char" is implementation-dependent. Reviewed by: imp,zlei,nightquick@proton.me Pull Request: https://github.com/freebsd/freebsd-src/pull/1290
* Abstract UIO allocation and deallocation.Alfredo Mazzinghi2024-02-101-1/+1
| | | | | | | | | | | | | Introduce the allocuio() and freeuio() functions to allocate and deallocate struct uio. This hides the actual allocator interface, so it is easier to modify the sub-allocation layout of struct uio and the corresponding iovec array. Obtained from: CheriBSD Reviewed by: kib, markj MFC after: 2 weeks Sponsored by: CHaOS, EPSRC grant EP/V000292/1 Differential Revision: https://reviews.freebsd.org/D43711
* sys: Remove ancient SCCS tags.Warner Losh2023-11-271-2/+0
| | | | | | | | Remove ancient SCCS tags from the tree, automated scripting, with two minor fixup to keep things compiling. All the common forms in the tree were removed with a perl script. Sponsored by: Netflix
* Replace random sbuf_printf() with cheaper cat/putc.Alexander Motin2023-11-221-7/+7
|
* prf: add setting of msgbuftrigger in paths where it is missingChuck Silvers2023-10-131-2/+6
| | | | | | | | | Logging things to msgbuf is supposed to set msgbuftrigger so that syslogd will notice that there is more to read from /dev/klog, but several paths do not do that. Add the missing trigger. Reviewed by: imp, kib Differential Revision: https://reviews.freebsd.org/D42173
* sys: Remove $FreeBSD$: one-line .c patternWarner Losh2023-08-161-2/+0
| | | | Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
* Revert "Revert "tslog: Annotate some early boot functions""Colin Percival2023-06-051-0/+3
| | | | | | | | Now that <sys/tslog.h> is wrapped in #ifdef _KERNEL, it's safe to have tslog annotations in files which might be built from userland (i.e. in subr_boot.c, which is built as part of the boot loader). This reverts commit 59588a546f55523d6fd37ab42eb08b719311d7d6.
* Revert "tslog: Annotate some early boot functions"Colin Percival2023-06-041-3/+0
| | | | | | | | | | | | The change to subr_boot.c broke the libsa build because the TSLOG macros have their own definitions for the boot loader -- I didn't realize that the loader code used subr_boot.c. I'm currently testing a fix and I'll revert this revert once I'm satisfied that everything works, but I don't want to leave the tree broken for too long. This reverts commit 469cfa3c30ee7a5ddeb597d0a8c3e7cac909b27a.
* tslog: Annotate some early boot functionsColin Percival2023-06-041-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Booting an amd64 kernel on Firecracker with 1 CPU and 128 MB of RAM, hammer_time takes roughly 2740 us: * 55 us in xen_pvh_parse_preload_data * 20 us in boot_parse_cmdline_delim * 20 us in boot_env_to_howto * 15 us in identify_hypervisor * 1320 us in link_elf_reloc * 1310 us in relocate_file1 handling ef->rela * 25 us in init_param1 * 30 us in dpcpu_init * 355 us in initializecpu * 255 us in initializecpu calling load_cr4 * 425 us in getmemsize * 280 us in pmap_bootstrap * 205 us in create_pagetables * 10 us in init_param2 * 25 us in pci_early_quirks * 60 us in cninit * 90 us in kdb_init * 105 us in msgbufinit * 20 us in fpuinit * 205 us elsewhere in hammer_time Some of these are unavoidable (e.g. identify_hypervisor uses CPUID and load_cr4 loads the CR4 register, both of which trap to the hypervisor) but others may deserve attention. Sponsored by: https://www.patreon.com/cperciva Differential Revision: https://reviews.freebsd.org/D40325
* ddb: annotate some commands with DB_CMD_MEMSAFEMitchell Horne2022-07-181-1/+1
| | | | | | | | | | This is not completely exhaustive, but covers a large majority of commands in the tree. Reviewed by: markj Sponsored by: Juniper Networks, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D35583
* dmesg: detect wrapped msgbuf on the kernel side and if so, skip first lineGleb Smirnoff2022-02-051-3/+20
| | | | | | | | | | | | | | Since 59f256ec35d3 dmesg(8) will always skip first line of the message buffer, cause it might be incomplete. The problem is that in most cases it is complete, valid and contains the "---<<BOOT>>---" marker. This skip can be disabled with '-a', but that would also unhide all non-kernel messages. Move this functionality from dmesg(8) to kernel, since kernel actually knows if wrap has happened or not. The main motivation for the change is not actually the value of the "---<<BOOT>>---" marker. The problem breaks unit tests, that clear message buffer, perform a test and then check the message buffer for a result. Example of such test is sys/kern/sonewconn_overflow.
* Unify console output.Alexander Motin2021-09-041-14/+21
| | | | | | | Without this change when virtual console enabled depending on buffer presence and state different parts of output go to different consoles. MFC after: 1 month
* kvprintf(9): add missing FALLTHROUGHMarius Strobl2021-01-211-0/+1
| | | | | Reported by: Coverity CID: 1005166
* Emit uprintf() output for initproc if there is no controlling terminalAlex Richardson2021-01-201-0/+8
| | | | | | | | This patch helped me debug why /sbin/init was not being loaded after making changes to the image activator in CheriBSD. Reviewed By: jhb (earlier version), kib Differential Revision: https://reviews.freebsd.org/D28121
* remove %n support from printf(9)Ed Maste2020-05-091-7/+11
| | | | | | | | | | | | It can be dangerous and there is no need for it in the kernel. Inspired by Kees Cook's change in Linux, and later OpenBSD. Reviewed by: cem, gordon, philip Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D24760 Notes: svn path=/head/; revision=360849
* Add KERNEL_PANICKED macro for use in place of direct panicstr testsMateusz Guzik2020-01-121-3/+3
| | | | Notes: svn path=/head/; revision=356655
* device_printf: Use sbuf for more coherent prints on SMPConrad Meyer2019-05-071-0/+41
| | | | | | | | | | | | | | | | | device_printf does multiple calls to printf allowing other console messages to be inserted between the device name, and the rest of the message. This change uses sbuf to compose to two into a single buffer, and prints it all at once. It exposes an sbuf drain function (drain-to-printf) for common use. Update documentation to match; some unit tests included. Submitted by: jmg Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D16690 Notes: svn path=/head/; revision=347229
* Replace ttyprintf with sbuf_printf and tty drain routineConrad Meyer2018-10-201-21/+0
| | | | | | | | | | | Add string variants of cnputc and tty_putchar, and use them from the tty sbuf drain routine. Suggested by: ed@ Sponsored by: Dell EMC Isilon Notes: svn path=/head/; revision=339468
* Add a new jail permission, allow.read_msgbuf. When true, jailed processesJamie Gritton2018-10-171-10/+3
| | | | | | | | | | | | | | | | | can see the dmesg buffer (this is the current behavior). When false (the new default), dmesg will be unavailable to jailed users, whether root or not. The security.bsd.unprivileged_read_msgbuf sysctl still works as before, controlling system-wide whether non-root users can see the buffer. PR: 211580 Submitted by: bz Approved by: re@ (kib@) MFC after: 3 days Notes: svn path=/head/; revision=339409
* subr_prf: Don't write kern.boot_tag if it's emptyKyle Evans2018-08-171-1/+1
| | | | | | | | | | | | | | This change allows one to set kern.boot_tag="" and not get a blank line preceding other boot messages. While this isn't super critical- blank lines are easy to filter out both mentally and in processing dmesg later- it allows for a mode of operation that matches previous behavior. I intend to MFC this whole series to stable/11 by the end of the month with boot_tag empty by default to make this effectively a nop in the stable branch. Notes: svn path=/head/; revision=337952
* subr_prf: remove think-o that had returned to local patchKyle Evans2018-08-101-2/+1
| | | | | | | Reported by: cognet Notes: svn path=/head/; revision=337580
* boot tagging: minor fixesKyle Evans2018-08-101-2/+6
| | | | | | | | | | | | | | msgbufinit may be called multiple times as we initialize the msgbuf into a progressively larger buffer. This doesn't happen as of now on head, but it may happen in the future and we generally support this. As such, only print the boot tag if we've just initialized the buffer for the first time. The boot tag also now has a newline appended to it for better visibility, and has been switched to a normal printf, by requesto f bde, after we've denoted that the msgbuf is mapped. Notes: svn path=/head/; revision=337579
* subr_prf: style(9) the sizeofKyle Evans2018-08-091-1/+1
| | | | | | | Reported by: jkim, ian Notes: svn path=/head/; revision=337548
* subr_prf: Use "sizeof current_boot_tag" insteadKyle Evans2018-08-091-1/+1
| | | | Notes: svn path=/head/; revision=337546
* BOOT_TAG: Make a config(5) option, expose as sysctl and loader tunableKyle Evans2018-08-091-1/+17
| | | | | | | | | | | | | | | | | | | | BOOT_TAG lived shortly in sys/msgbuf.h, but this wasn't necessarily great for changing it or removing it. Move it into subr_prf.c and add options for it to opt_printf.h. One can specify both the BOOT_TAG and BOOT_TAG_SZ (really, size of the buffer that holds the BOOT_TAG). We expose it as kern.boot_tag and also add a loader tunable by the same name that we'll fetch upon initialization of the msgbuf. This allows for flexibility and also ensures that there's a consistent way to figure out the boot tag of the running kernel, rather than relying on headers to be in-sync. Prodded super-super-lightly by: imp Notes: svn path=/head/; revision=337545
* msgbuf: Light detailing (const'ify and bool'itize)Kyle Evans2018-08-091-2/+2
| | | | Notes: svn path=/head/; revision=337544
* kern: Add a BOOT_TAG marker at the beginning of boot dmesgKyle Evans2018-08-091-0/+1
| | | | | | | | | | | | | | | | | | | | | From the "newly licensed to drive" PR department, add a BOOT_TAG marker (by default, --<<BOOT>>--, to the beginning of each boot's dmesg. This makes it easier to do textproc magic to locate the start of each boot and, of particular interest to some, the dmesg of the current boot. The PR has a dmesg(8) component as well that I've opted not to include for the moment- it was the more contentious part of this PR. bde@ also made the statement that this boot tag should be written with an ordinary printf, which I've- for the moment- declined to change about this patch to keep it more transparent to observer of the boot process. PR: 43434 Submitted by: dak <aurelien.nephtali@wanadoo.fr> (basically rewritten) MFC after: maybe never Notes: svn path=/head/; revision=337518
* Add a FALLTHROUGH comment to kvprintf().Mark Johnston2018-07-171-0/+1
| | | | | | | | Submitted by: Sebastian Huber <sebastian.huber@embedded-brains.de> MFC after: 3 days Notes: svn path=/head/; revision=336417
* fix uninitialized variable warningMatt Macy2018-05-191-0/+1
| | | | Notes: svn path=/head/; revision=333829
* Use the TSLOG framework to record entry/exit timestamps for DELAY andColin Percival2017-12-311-0/+2
| | | | | | | | _vprintf; these functions are called in many places and can contribute meaningfully to the total time spent booting. Notes: svn path=/head/; revision=327432
* Move instantiation of msgbufp from 9 MD files to subr_prf.c.Bruce Evans2017-12-071-0/+1
| | | | | | | | | | | | | | | This variable should be pure MI except possibly for reading it in MD dump routines. Its initialization was pure MD in 4.4BSD, but FreeBSD changed this in r36441 in 1998. There were many imperfections in r36441. This commit fixes only a small one, to simplify fixing the others 1 arch at a time. (r47678 added support for special/early/multiple message buffer initialization which I want in a more general form, but this was too fragile to use because hacking on the msgbufp global corrupted it, and was only used for 5 hours in -current...) Notes: svn path=/head/; revision=326656
* sys: further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326023
* kvprintf %b enhancementsRyan Libby2017-07-121-24/+29
| | | | | | | | | | | | | | Make the %b formatter accept number formatting flags. It will now accept alternate form, precision, and length modifiers. It also now partially supports field width (but forces left justification). Reviewed by: markj Approved by: markj (mentor) Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D11284 Notes: svn path=/head/; revision=320908
* Remove stray return.Konstantin Belousov2017-06-131-1/+0
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=319916
* Provide a comment on why stdio.h needs to be included.Scott Long2017-02-281-0/+7
| | | | Notes: svn path=/head/; revision=314420
* Include stdio.h to fix libsbuf build.Jung-uk Kim2017-02-281-0/+1
| | | | | | | Reviewed by: scottl Notes: svn path=/head/; revision=314419
* Implement sbuf_prf(), which takes an sbuf and outputs itScott Long2017-02-281-12/+34
| | | | | | | | | | | | | | | | | to stdout in the non-kernel case and to the console+log in the kernel case. For the kernel case it hooks the putbuf() machinery underneath printf(9) so that the buffer is written completely atomically and without a copy into another temporary buffer. This is useful for fixing compound console/log messages that become broken and interleaved when multiple threads are competing for the console. Reviewed by: ken, imp Sponsored by: Netflix Notes: svn path=/head/; revision=314397
* Include <stdarg.h> instead of <machine/stdarg.h> when compiled asMarcel Moolenaar2016-10-241-0/+4
| | | | | | | | part of libsbuf. The former is the standard header, and allows us to compile libsbuf on macOS/linux. Notes: svn path=/head/; revision=307873
* Renumber license clauses in sys/kern to avoid skipping #3Ed Maste2016-09-151-1/+1
| | | | Notes: svn path=/head/; revision=305832
* Hide counted_warning(9) under #ifdef _KERNEL braces, to allow buildingKonstantin Belousov2016-07-211-0/+2
| | | | | | | | | | subr_prf.c in userspace for libsbuf. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=303155
* Provide counter_warning(9) KPI which allows to issue limited number ofKonstantin Belousov2016-07-211-0/+19
| | | | | | | | | | | | | | | warnings for some kernel events, mostly intended for the use of obsoleted or otherwise undersired interfaces. This is an abstracted and race-expelled code from compat pty driver. Requested and reviewed by: jhb Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D7270 Notes: svn path=/head/; revision=303151
* kvprintf: Pad %*c to width, like %*sConrad Meyer2016-06-091-0/+8
| | | | | | | Sponsored by: EMC / Isilon Storage Division Notes: svn path=/head/; revision=301750
* Add vlog(9).Mark Johnston2015-11-191-1/+7
| | | | | | | | | Reviewed by: cem, jhb MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D4183 Notes: svn path=/head/; revision=291058
* Add support for reading MAM attributes to camcontrol(8) and libcam(3).Kenneth D. Merry2015-06-091-0/+63
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MAM is Medium Auxiliary Memory and is most commonly found as flash chips on tapes. This includes support for reading attributes and decoding most known attributes, but does not yet include support for writing attributes or reporting attributes in XML format. libsbuf/Makefile: Add subr_prf.c for the new sbuf_hexdump() function. This function is essentially the same function. libsbuf/Symbol.map: Add a new shared library minor version, and include the sbuf_hexdump() function. libsbuf/Version.def: Add version 1.4 of the libsbuf library. libutil/hexdump.3: Document sbuf_hexdump() alongside hexdump(3), since it is essentially the same function. camcontrol/Makefile: Add attrib.c. camcontrol/attrib.c: Implementation of READ ATTRIBUTE support for camcontrol(8). camcontrol/camcontrol.8: Document the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.c: Add the new 'camcontrol attrib' subcommand. camcontrol/camcontrol.h: Add a function prototype for scsiattrib(). share/man/man9/sbuf.9: Document the existence of sbuf_hexdump() and point users to the hexdump(3) man page for more details. sys/cam/scsi/scsi_all.c: Add a table of known attributes, text descriptions and handler functions. Add a new scsi_attrib_sbuf() function along with a number of other related functions that help decode attributes. scsi_attrib_ascii_sbuf() decodes ASCII format attributes. scsi_attrib_int_sbuf() decodes binary format attributes, and will pass them off to scsi_attrib_hexdump_sbuf() if they're bigger than 8 bytes. scsi_attrib_vendser_sbuf() decodes the vendor and drive serial number attribute. scsi_attrib_volcoh_sbuf() decodes the Volume Coherency Information attribute that LTFS writes out. sys/cam/scsi/scsi_all.h: Add a number of attribute-related structure definitions and other defines. Add function prototypes for all of the functions added in scsi_all.c. sys/kern/subr_prf.c: Add a new function, sbuf_hexdump(). This is the same as the existing hexdump(9) function, except that it puts the result in an sbuf. This also changes subr_prf.c so that it can be compiled in userland for includsion in libsbuf. We should work to change this so that the kernel hexdump implementation is a wrapper around sbuf_hexdump() with a statically allocated sbuf with a drain. That will require a drain function that goes to the kernel printf() buffer that can take a non-NUL terminated string as input. That is because an sbuf isn't NUL-terminated until it is finished, and we don't want to finish it while we're still using it. We should also work to consolidate the userland hexdump and kernel hexdump implemenatations, which are currently separate. This would also mean making applications that currently link in libutil link in libsbuf. sys/sys/sbuf.h: Add the prototype for sbuf_hexdump(), and add another copy of the hexdump flag values if they aren't already defined. Ideally the flags should be defined in one place but the implemenation makes it difficult to do properly. (See above.) Sponsored by: Spectra Logic Corporation MFC after: 1 week Notes: svn path=/head/; revision=284192
* Always send log(9) messages to the message buffer.Eric van Gyzen2015-04-201-1/+1
| | | | | | | | | | | | | | | | | | It is truer to the semantics of logging for messages to *always* go to the message buffer, where they can eventually be collected and, in fact, be put into a log file. This restores the behavior prior to r70239, which seems to have changed it inadvertently. Submitted by: Eric Badger <eric@badgerio.us> Reviewed by: jhb Approved by: kib (mentor) Obtained from: Dell Inc. MFC after: 1 week Notes: svn path=/head/; revision=281785
* Add a nulterm byte to the returned sysctl string.Ian Lepore2015-03-151-1/+1
| | | | | | | PR: 195668 Notes: svn path=/head/; revision=280016
* Fix usage example in kvprintf(9) and its copy in libstand(3): trailing '\n'Alexey Dokuchaev2015-01-231-2/+2
| | | | | | | | | | | | | | | | in bitfield argument is wrong, as it will be treated as bit 10, causing any code printing >=10 bits with bit 10 on as having a trailing comma. Newline (intended one) should be part of the format string (already present in the examples). Also fix grammar and kill EOL whitespace in comment while here. PR: 195005 Approved by: bdrewery Notes: svn path=/head/; revision=277560
* Pull in r267961 and r267973 again. Fix for issues reported will follow.Hans Petter Selasky2014-06-281-13/+10
| | | | Notes: svn path=/head/; revision=267992
* Revert r267961, r267973:Glen Barber2014-06-271-10/+13
| | | | | | | | | | | | | These changes prevent sysctl(8) from returning proper output, such as: 1) no output from sysctl(8) 2) erroneously returning ENOMEM with tools like truss(1) or uname(1) truss: can not get etype: Cannot allocate memory Notes: svn path=/head/; revision=267985