History log of /freebsd-current/sys/kern/subr_prf.c
Revision Date Author Comments
# 61cc4830 18-Jan-2024 Alfredo Mazzinghi <am2419@cl.cam.ac.uk>

Abstract UIO allocation and deallocation.

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


# 29363fb4 23-Nov-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove ancient SCCS tags.

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


# 0a713948 22-Nov-2023 Alexander Motin <mav@FreeBSD.org>

Replace random sbuf_printf() with cheaper cat/putc.


# c545a7b2 13-Oct-2023 Chuck Silvers <chs@FreeBSD.org>

prf: add setting of msgbuftrigger in paths where it is missing

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


# 685dc743 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: one-line .c pattern

Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/


# 9d6ae1e3 04-Jun-2023 Colin Percival <cperciva@FreeBSD.org>

Revert "Revert "tslog: Annotate some early boot functions""

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.


# 59588a54 04-Jun-2023 Colin Percival <cperciva@FreeBSD.org>

Revert "tslog: Annotate some early boot functions"

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.


# 469cfa3c 22-May-2023 Colin Percival <cperciva@FreeBSD.org>

tslog: Annotate some early boot functions

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


# c84c5e00 18-Jul-2022 Mitchell Horne <mhorne@FreeBSD.org>

ddb: annotate some commands with DB_CMD_MEMSAFE

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


# c999e348 05-Feb-2022 Gleb Smirnoff <glebius@FreeBSD.org>

dmesg: detect wrapped msgbuf on the kernel side and if so, skip first line

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.


# a264594d 03-Sep-2021 Alexander Motin <mav@FreeBSD.org>

Unify console output.

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


# 679e4cda 21-Jan-2021 Marius Strobl <marius@FreeBSD.org>

kvprintf(9): add missing FALLTHROUGH

Reported by: Coverity
CID: 1005166


# 7e99c034 20-Jan-2021 Alex Richardson <arichardson@FreeBSD.org>

Emit uprintf() output for initproc if there is no controlling terminal

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


# 937b352e 09-May-2020 Ed Maste <emaste@FreeBSD.org>

remove %n support from printf(9)

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


# 879e0604 11-Jan-2020 Mateusz Guzik <mjg@FreeBSD.org>

Add KERNEL_PANICKED macro for use in place of direct panicstr tests


# 7d7db529 07-May-2019 Conrad Meyer <cem@FreeBSD.org>

device_printf: Use sbuf for more coherent prints on SMP

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


# 6858c2cc 20-Oct-2018 Conrad Meyer <cem@FreeBSD.org>

Replace ttyprintf with sbuf_printf and tty drain routine

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


# b19d66fd 17-Oct-2018 Jamie Gritton <jamie@FreeBSD.org>

Add a new jail permission, allow.read_msgbuf. When true, jailed processes
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


# 45625675 16-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

subr_prf: Don't write kern.boot_tag if it's empty

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.


# 0915d9d0 10-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

subr_prf: remove think-o that had returned to local patch

Reported by: cognet


# 170bc291 10-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

boot tagging: minor fixes

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.


# 240fcda1 09-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

subr_prf: style(9) the sizeof

Reported by: jkim, ian


# 4c793b68 09-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

subr_prf: Use "sizeof current_boot_tag" instead


# 2a4650cc 09-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

BOOT_TAG: Make a config(5) option, expose as sysctl and loader tunable

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


# 21aa6e83 09-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

msgbuf: Light detailing (const'ify and bool'itize)


# 2834d612 08-Aug-2018 Kyle Evans <kevans@FreeBSD.org>

kern: Add a BOOT_TAG marker at the beginning of boot dmesg

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


# 9295517a 17-Jul-2018 Mark Johnston <markj@FreeBSD.org>

Add a FALLTHROUGH comment to kvprintf().

Submitted by: Sebastian Huber <sebastian.huber@embedded-brains.de>
MFC after: 3 days


# b2037136 18-May-2018 Matt Macy <mmacy@FreeBSD.org>

fix uninitialized variable warning


# d5d7606c 31-Dec-2017 Colin Percival <cperciva@FreeBSD.org>

Use the TSLOG framework to record entry/exit timestamps for DELAY and
_vprintf; these functions are called in many places and can contribute
meaningfully to the total time spent booting.


# fb3cc1c3 07-Dec-2017 Bruce Evans <bde@FreeBSD.org>

Move instantiation of msgbufp from 9 MD files to subr_prf.c.

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...)


# 51369649 20-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys: further adoption of SPDX licensing ID tags.

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.


# 808a9c86 12-Jul-2017 Ryan Libby <rlibby@FreeBSD.org>

kvprintf %b enhancements

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


# 81c3737d 13-Jun-2017 Konstantin Belousov <kib@FreeBSD.org>

Remove stray return.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 38e41e66 28-Feb-2017 Scott Long <scottl@FreeBSD.org>

Provide a comment on why stdio.h needs to be included.


# c4e92994 28-Feb-2017 Jung-uk Kim <jkim@FreeBSD.org>

Include stdio.h to fix libsbuf build.

Reviewed by: scottl


# 388f3ce6 28-Feb-2017 Scott Long <scottl@FreeBSD.org>

Implement sbuf_prf(), which takes an sbuf and outputs it
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


# 07f862a7 24-Oct-2016 Marcel Moolenaar <marcel@FreeBSD.org>

Include <stdarg.h> instead of <machine/stdarg.h> when compiled as
part of libsbuf. The former is the standard header, and allows us
to compile libsbuf on macOS/linux.


# 69a28758 15-Sep-2016 Ed Maste <emaste@FreeBSD.org>

Renumber license clauses in sys/kern to avoid skipping #3


# 492fe1b7 21-Jul-2016 Konstantin Belousov <kib@FreeBSD.org>

Hide counted_warning(9) under #ifdef _KERNEL braces, to allow building
subr_prf.c in userspace for libsbuf.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week


# 9837947b 21-Jul-2016 Konstantin Belousov <kib@FreeBSD.org>

Provide counter_warning(9) KPI which allows to issue limited number of
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


# dd6ea7f7 09-Jun-2016 Conrad Meyer <cem@FreeBSD.org>

kvprintf: Pad %*c to width, like %*s

Sponsored by: EMC / Isilon Storage Division


# 07713dde 18-Nov-2015 Mark Johnston <markj@FreeBSD.org>

Add vlog(9).

Reviewed by: cem, jhb
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D4183


# 5672fac9 09-Jun-2015 Kenneth D. Merry <ken@FreeBSD.org>

Add support for reading MAM attributes to camcontrol(8) and libcam(3).

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


# c207ff93 20-Apr-2015 Eric van Gyzen <vangyzen@FreeBSD.org>

Always send log(9) messages to the message buffer.

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


# e5197e3a 14-Mar-2015 Ian Lepore <ian@FreeBSD.org>

Add a nulterm byte to the returned sysctl string.

PR: 195668


# c5f282da 23-Jan-2015 Alexey Dokuchaev <danfe@FreeBSD.org>

Fix usage example in kvprintf(9) and its copy in libstand(3): trailing '\n'
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


# af3b2549 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Pull in r267961 and r267973 again. Fix for issues reported will follow.


# 37a107a4 27-Jun-2014 Glen Barber <gjb@FreeBSD.org>

Revert r267961, r267973:

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


# 3da1cf1e 27-Jun-2014 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the meaning of the CTLFLAG_TUN flag to automatically check if
there is an environment variable which shall initialize the SYSCTL
during early boot. This works for all SYSCTL types both statically and
dynamically created ones, except for the SYSCTL NODE type and SYSCTLs
which belong to VNETs. A new flag, CTLFLAG_NOFETCH, has been added to
be used in the case a tunable sysctl has a custom initialisation
function allowing the sysctl to still be marked as a tunable. The
kernel SYSCTL API is mostly the same, with a few exceptions for some
special operations like iterating childrens of a static/extern SYSCTL
node. This operation should probably be made into a factored out
common macro, hence some device drivers use this. The reason for
changing the SYSCTL API was the need for a SYSCTL parent OID pointer
and not only the SYSCTL parent OID list pointer in order to quickly
generate the sysctl path. The motivation behind this patch is to avoid
parameter loading cludges inside the OFED driver subsystem. Instead of
adding special code to the OFED driver subsystem to post-load tunables
into dynamically created sysctls, we generalize this in the kernel.

Other changes:
- Corrected a possibly incorrect sysctl name from "hw.cbb.intr_mask"
to "hw.pcic.intr_mask".
- Removed redundant TUNABLE statements throughout the kernel.
- Some minor code rewrites in connection to removing not needed
TUNABLE statements.
- Added a missing SYSCTL_DECL().
- Wrapped two very long lines.
- Avoid malloc()/free() inside sysctl string handling, in case it is
called to initialize a sysctl from a tunable, hence malloc()/free() is
not ready when sysctls from the sysctl dataset are registered.
- Bumped FreeBSD version to indicate SYSCTL API change.

MFC after: 2 weeks
Sponsored by: Mellanox Technologies


# 2809a6df 22-Apr-2014 Bryan Drewery <bdrewery@FreeBSD.org>

Fix grammar error and trailing newline.

Submitted by: danfe
MFC after: 3 days


# ae8959dd 13-Mar-2014 Bryan Drewery <bdrewery@FreeBSD.org>

Combine similar code from vprintf(9) and log(9).

MFC after: 2 weeks


# 42c8459b 11-Feb-2014 Ian Lepore <ian@FreeBSD.org>

Rework the EARLY_PRINTF mechanism. Instead of defining a special eprintf()
routine, now a platform can provide a pointer to an early_putc() routine
which is used instead of cn_putc(). Control can be handed off from early
printf support to standard console support by NULLing out the pointer
during standard console init.

This leverages all the existing error reporting that uses printf calls,
such as panic() which can now be usefully employed even in early
platform init code (useful at least to those who maintain that code and
build kernels with EARLY_PRINTF defined).

Reviewed by: imp, eadler


# 26fbe13c 22-Jan-2014 Warner Losh <imp@FreeBSD.org>

Implement generic support for early printf. Thought I can't find the
paper trail now, this patch is similar to one posted for one of the
preliminary versions of a new armv6 port. I took them and made them
more generic. Option not enabled by default since each board/port has
to provide its own eputc, and possibly do other things as well...


# 8740a711 13-Sep-2013 Konstantin Belousov <kib@FreeBSD.org>

Reduce the scope of the proctree_lock. If several processes cause
continuous calls to the uprintf(9), the proctree_lock could be
shared-locked for indefinite amount of time, starving exclusive
requests. Since proctree_lock is needed for fork() and exit(), this
effectively stops the machine.

While there, do the similar reduction for tprintf(9).

Reported and tested by: pho
Reviewed by: ed
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Approved by: re (glebius)


# 34c916c6 07-Sep-2013 Navdeep Parhar <np@FreeBSD.org>

Add a vtprintf. It is to tprintf what vprintf is to printf.

Reviewed by: kib


# 80f1c58b 16-Oct-2011 Marcel Moolenaar <marcel@FreeBSD.org>

Fix double vision syndrome (read: double output) when in the
debugger without a panic.


# 5e319c48 06-Jun-2011 Kenneth D. Merry <ken@FreeBSD.org>

Set pca.p_bufr to NULL when we haven't allocated a buffer.

Otherwise, p_bufr is set to garbage on the stack, and if that garbage
happens to be non-NULL, and the TOLOG or TOCONS flag is set, putbuf()
will get called and attempt to fill the non-existent buffer.

This is really only relevant for tprintf() (and only when the priority is
not -1), but set it in uprintf() and ttyprintf() for completeness.

The next step, to avoid log buffer scrambling, would be to add the
PRINTF_BUFR_SIZE code to tprintf(), but this should prevent panics.

Submitted by: rmacklem
Found by: pho


# d42a4eb5 31-May-2011 Kenneth D. Merry <ken@FreeBSD.org>

Fix apparent garbage in the message buffer.

While we have had a fix in place (options PRINTF_BUFR_SIZE=128) to fix
scrambled console output, the message buffer and syslog were still getting
log messages one character at a time. While all of the characters still
made it into the log (courtesy of atomic operations), they were often
interleaved when there were multiple threads writing to the buffer at the
same time.

This fixes message buffer accesses to use buffering logic as well, so that
strings that are less than PRINTF_BUFR_SIZE will be put into the message
buffer atomically. So now dmesg output should look the same as console
output.

subr_msgbuf.c: Convert most message buffer calls to use a new spin
lock instead of atomic variables in some places.

Add a new routine, msgbuf_addstr(), that adds a
NUL-terminated string to a message buffer. This
takes a priority argument, which allows us to
eliminate some races (at least in the the string
at a time case) that are present in the
implementation of msglogchar(). (dangling and
lastpri are static variables, and are subject to
races when multiple callers are present.)

msgbuf_addstr() also allows the caller to request
that carriage returns be stripped out of the
string. This matches the behavior of msglogchar(),
but in testing so far it doesn't appear that any
newlines are being stripped out. So the carriage
return removal functionality may be a candidate
for removal later on if further analysis shows
that it isn't necessary.

subr_prf.c: Add a new msglogstr() routine that calls
msgbuf_logstr().

Rename putcons() to putbuf(). This now handles
buffered output to the message log as well as
the console. Also, remove the logic in putcons()
(now putbuf()) that added a carriage return before
a newline. The console path was the only path that
needed it, and cnputc() (called by cnputs())
already adds a carriage return. So this
duplication resulted in kernel-generated console
output lines ending in '\r''\r''\n'.

Refactor putchar() to handle the new buffering
scheme.

Add buffering to log().

Change log_console() to use msglogstr() instead of
msglogchar(). Don't add extra newlines by default
in log_console(). Hide that behavior behind a
tunable/sysctl (kern.log_console_add_linefeed) for
those who would like the old behavior. The old
behavior led to the insertion of extra newlines
for log output for programs that print out a
string, and then a trailing newline on a separate
write. (This is visible with dmesg -a.)

msgbuf.h: Add a prototype for msgbuf_addstr().

Add three new fields to struct msgbuf, msg_needsnl,
msg_lastpri and msg_lock. The first two are needed
for log message functionality previously handled
by msglogchar(). (Which is still active if
buffering isn't enabled.)

Include sys/lock.h and sys/mutex.h for the new
mutex.

Reviewed by: gibbs


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 4a82f108 12-Jul-2010 Jung-uk Kim <jkim@FreeBSD.org>

Use type-specific inline function imax() instead of deprecated macro MAX().

Prodded by: bde


# 4624e08a 08-Jul-2010 Jung-uk Kim <jkim@FreeBSD.org>

Implement optional 'precision' for numbers. Previously, it was parsed but
ignored. Some third-party modules (e.g., APCICA) prefer this format over
zero padding flag '0'.


# ca1d2f65 03-Nov-2009 Ed Schouten <ed@FreeBSD.org>

Make /dev/klog and kern.msgbuf* MPSAFE.

Normally msgbufp is locked using Giant. Switch it to use the
msgbuf_lock. Instead of changing the tsleep() calls to msleep(), just
convert it to condvar(9).

In my opinion the locking around msgbuf_peekbytes() still remains
questionable. It looks like locks are dropped while performing copies of
multiple blocks to userspace, which may cause the msgbuf to be reset in
the mean time. At least getting it underneath from Giant should make it
a little easier for us to figure out how to solve that.

Reminded by: rdivacky


# 91c3cbfe 27-Feb-2009 Ed Schouten <ed@FreeBSD.org>

Remove redundant code in printf() and vprintf().

printf() and vprintf() are exactly the same, except the way arguments
are passed. Just like we see in other pieces of code (i.e. libc's
printf()), implement printf() using vprintf().

Submitted by: Christoph Mallon <christoph mallon gmx de>


# ff7b7d90 26-Feb-2009 Ed Schouten <ed@FreeBSD.org>

Revert previous commit to subr_prf.c and make it more tidy.

As mentioned by bz and bde, the change I made wasn't the proper way to
fix. Inspired by bde's patch, perform some small cleanups to uprintf().

Reviewed by: bz


# 2bbada90 25-Feb-2009 Ed Schouten <ed@FreeBSD.org>

Remove redundant assignment of `p'.

`p' is already initialized with `td->td_proc'. Because td is always
curthread, it is safe to initialize it without any locks.

Found by: LLVM's scan-build


# 4592c621 03-Feb-2009 Warner Losh <imp@FreeBSD.org>

Use NULL in preference to 0 for pointers.


# 3a4d0c86 21-Dec-2008 Ed Schouten <ed@FreeBSD.org>

Revert r185891.

In r185891 I removed the newlines from messages written to /dev/console,
because it made startup messages from rc-scripts harder to read. This,
unfortunately, causes the kernel message that is printed after a
non-terminated log message to be concatenated.

This could be fixed, but on short term it's better to just revert the
change.

Reported by: Jaakko Heinonen <jh saunalahti fi>


# d16ebcd4 10-Dec-2008 Ed Schouten <ed@FreeBSD.org>

Remove added newlines from logged messages written to /dev/console.

The /dev/console device node logs all strings that are written to it.
When the string does not contain a trailing newline, it appends one. I
can imagine this was useful a long time ago, but with our current
rc-scripts, it generates a whole bunch of messages that look like:

| Configuring syscons:
| blanktime
| .

By not appending the newlines, the output of `dmesg -a' is now (almost?)
exactly the same as what the user will see on the console device
(syscons, uart).


# e1088cdc 17-Nov-2008 Xin LI <delphij@FreeBSD.org>

Obey signedness flag in %z case.

MFC after: 2 months


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# bc093719 20-Aug-2008 Ed Schouten <ed@FreeBSD.org>

Integrate the new MPSAFE TTY layer to the FreeBSD operating system.

The last half year I've been working on a replacement TTY layer for the
FreeBSD kernel. The new TTY layer was designed to improve the following:

- Improved driver model:

The old TTY layer has a driver model that is not abstract enough to
make it friendly to use. A good example is the output path, where the
device drivers directly access the output buffers. This means that an
in-kernel PPP implementation must always convert network buffers into
TTY buffers.

If a PPP implementation would be built on top of the new TTY layer
(still needs a hooks layer, though), it would allow the PPP
implementation to directly hand the data to the TTY driver.

- Improved hotplugging:

With the old TTY layer, it isn't entirely safe to destroy TTY's from
the system. This implementation has a two-step destructing design,
where the driver first abandons the TTY. After all threads have left
the TTY, the TTY layer calls a routine in the driver, which can be
used to free resources (unit numbers, etc).

The pts(4) driver also implements this feature, which means
posix_openpt() will now return PTY's that are created on the fly.

- Improved performance:

One of the major improvements is the per-TTY mutex, which is expected
to improve scalability when compared to the old Giant locking.
Another change is the unbuffered copying to userspace, which is both
used on TTY device nodes and PTY masters.

Upgrading should be quite straightforward. Unlike previous versions,
existing kernel configuration files do not need to be changed, except
when they reference device drivers that are listed in UPDATING.

Obtained from: //depot/projects/mpsafetty/...
Approved by: philip (ex-mentor)
Discussed: on the lists, at BSDCan, at the DevSummit
Sponsored by: Snow B.V., the Netherlands
dcons(4) fixed by: kan


# 486a9414 07-Mar-2007 Julian Elischer <julian@FreeBSD.org>

Instead of doing comparisons using the pcpu area to see if
a thread is an idle thread, just see if it has the IDLETD
flag set. That flag will probably move to the pflags word
as it's permenent and never chenges for the life of the
system so it doesn't need locking.


# d4fbc81d 30-Nov-2006 John Birrell <jb@FreeBSD.org>

Flushing the buffer is conditional on actually using the buffer. Oops.


# e0b65125 29-Nov-2006 John Birrell <jb@FreeBSD.org>

Turn console printf buffering into a kernel option and only on
by default for sun4v where it is absolutely required.

This change moves the buffer from struct pcpu to the stack to avoid
using the critical section which created a LOR in a couple of cases
due to interaction with the tty code and kqueue. The LOR can't be
fixed with the critical section and the pcpu buffer can't be used
without the critical section.

Putting the buffer on the stack was my initial solution, but it was
pointed out that the stress on the stack might cause problems
depending on the call path. We don't have a way of creating tests
for those possible cases, so it's best to leave this as an option
for the time being. In time we may get enough data to enable this
option more generally.


# acd3428b 06-Nov-2006 Robert Watson <rwatson@FreeBSD.org>

Sweep kernel replacing suser(9) calls with priv(9) calls, assigning
specific privilege names to a broad range of privileges. These may
require some future tweaking.

Sponsored by: nCircle Network Security, Inc.
Obtained from: TrustedBSD Project
Discussed on: arch@
Reviewed (at least in part) by: mlaier, jmg, pjd, bde, ceri,
Alex Lyashkov <umka at sevcity dot net>,
Skip Ford <skip dot ford at verizon dot net>,
Antoine Brodin <antoine dot brodin at laposte dot net>


# 3d068827 31-Oct-2006 John Birrell <jb@FreeBSD.org>

Add a cnputs() function to write a string to the console with
a lock to prevent interspersed strings written from different CPUs
at the same time.

To avoid putting a buffer on the stack or having to malloc one,
space is incorporated in the per-cpu structure. The buffer
size if 128 bytes; chosen because it's the next power of 2 size
up from 80 characters.

String writes to the console are buffered up the end of the line
or until the buffer fills. Then the buffer is flushed to all
console devices.

Existing low level console output via cnputc() is unaffected by
this change. ithread calls to log() are also unaffected to avoid
blocking those threads.

A minor change to the behaviour in a panic situation is that
console output will still be buffered, but won't be written to
a tty as before. This should prevent interspersed panic output
as a number of CPUs panic before we end up single threaded
running ddb.

Reviewed by: scottl, jhb
MFC after: 2 weeks


# 5702e096 17-Sep-2006 Robert Watson <rwatson@FreeBSD.org>

Declare security and security.bsd sysctl hierarchies in sysctl.h along
with other commonly used sysctl name spaces, rather than declaring them
all over the place.

MFC after: 1 month
Sponsored by: nCircle Network Security, Inc.


# 19e9205a 12-Jul-2006 John Baldwin <jhb@FreeBSD.org>

Simplify the pager support in DDB. Allowing different db commands to
install custom pager functions didn't actually happen in practice (they
all just used the simple pager and passed in a local quit pointer). So,
just hardcode the simple pager as the only pager and make it set a global
db_pager_quit flag that db commands can check when the user hits 'q' (or a
suitable variant) at the pager prompt. Also, now that it's easy to do so,
enable paging by default for all ddb commands. Any command that wishes to
honor the quit flag can do so by checking db_pager_quit. Note that the
pager can also be effectively disabled by setting $lines to 0.

Other fixes:
- 'show idt' on i386 and pc98 now actually checks the quit flag and
terminates early.
- 'show intr' now actually checks the quit flag and terminates early.


# 0d84d9eb 09-Mar-2006 Jung-uk Kim <jkim@FreeBSD.org>

Implement printf 'X' conversion for both libstand and kernel.


# 6ec6fb9b 25-Feb-2006 Scott Long <scottl@FreeBSD.org>

Always print a newline char at the end of the line.


# 329c75a7 26-Sep-2005 Robert Watson <rwatson@FreeBSD.org>

Acquire Giant in uprintf() and tprintf() rather than asserting it. In
the vast majority of cases, these functions are called without mutexes
held, meaning that in all but two cases, there will be no ordering
issues with doing this, and it will eliminate the need for changes in
the caller. In two cases, mutexes are held, so Giant must be acquired
before those mutexes such that uprintf() and tprintf() recurse Giant
rather than generating a lock order reversal.

Suggested by: bde


# 5580b0b1 20-Sep-2005 Robert Watson <rwatson@FreeBSD.org>

Correct an incorrect comment from the dawn of time: neither tprintf()
nor uprintf() is believed to perform tsleep() or msleep() as written,
as ttycheckoutq() is called with '0' as its sleep argument.

Remove recently added WITNESS warnings for sleep as the comment was
incorrect. This should silence a warning from the nfs_timer() code.

Discussed with: bde


# 84d2b7df 19-Sep-2005 Robert Watson <rwatson@FreeBSD.org>

Add GIANT_REQUIRED and WITNESS sleep warnings to uprintf() and tprintf(),
as they both interact with the tty code (!MPSAFE) and may sleep if the
tty buffer is full (per comment).

Modify all consumers of uprintf() and tprintf() to hold Giant around
calls into these functions. In most cases, this means adding an
acquisition of Giant immediately around the function. In some cases
(nfs_timer()), it means acquiring Giant higher up in the callout.

With these changes, UFS no longer panics on SMP when either blocks are
exhausted or inodes are exhausted under load due to races in the tty
code when running without Giant.

NB: Some reduction in calls to uprintf() in the svr4 code is probably
desirable.

NB: In the case of nfs_timer(), calling uprintf() while holding a mutex,
or even in a callout at all, is a bad idea, and will generate warnings
and potential upset. This needs to be fixed, but was a problem before
this change.

NB: uprintf()/tprintf() sleeping is generally a bad ideas, as is having
non-MPSAFE tty code.

MFC after: 1 week


# 5248ef8a 04-Sep-2005 Xin LI <delphij@FreeBSD.org>

When padding with zero, do pad after prefixes rather than padding
before prefixes.

Use cases:
printf("%05d", -42); --> "00-42" (should be "-0042")
printf("%#05x", 12); --> "000xc" (should be "0x00c")

Submitted by: Oliver Fromme
PR: kern/85520
MFC After: 1 week


# 1e7d2c47 03-Sep-2005 Poul-Henning Kamp <phk@FreeBSD.org>

If we ignore an unknown % sequence, we must stop interpreting the
remaining % arguments because the varargs are now out of sync and
there is a risk that we might for instance dereference an integer
in a %s argument.

Sponsored by: Napatech.com


# 4a30c508 06-Jun-2005 Doug White <dwhite@FreeBSD.org>

Make "show msgbuf" use the pager instead of blasting the whole thing out.

MFC after: 3 days


# 30a1695b 06-Apr-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Constify hexdump() harder.


# 572b4402 17-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

In stange circumstances we may end up being the last reference to a
session in tprintf(). SESSRELE() needs to properly dispose of the
sessions mutex.

Add sessrele() which does the proper cleanup and have SESSRELE() call it.

Use SESSRELE also in pgdelete().

Found by: Coverity (ID:526)


# 82ebaee7 10-Jul-2004 Marcel Moolenaar <marcel@FreeBSD.org>

Update for the KDB framework:
o Check kdb_active instead of db_active and do so unconditionally.


# 552afd9c 10-Jul-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Clean up and wash struct iovec and struct uio handling.

Add copyiniov() which copies a struct iovec array in from userland into
a malloc'ed struct iovec. Caller frees.

Change uiofromiov() to malloc the uio (caller frees) and name it
copyinuio() which is more appropriate.

Add cloneuio() which returns a malloc'ed copy. Caller frees.

Use them throughout.


# 8e1b7974 18-Jun-2004 Brian Feldman <green@FreeBSD.org>

Add a sysctl/tunable, "kern.always_console_output", that lets you set
output to permanently (not ephemerally) go to the console. It is also
sent to any other console specified by TIOCCONS as normal.

While I'm here, document the kern.log_console_output sysctl.


# 7f8a436f 05-Apr-2004 Warner Losh <imp@FreeBSD.org>

Remove advertising clause from University of California Regent's license,
per letter dated July 22, 1999.

Approved by: core


# 32869e71 18-Feb-2004 Nate Lawson <njl@FreeBSD.org>

Add support for 'h' and 'hh' modifiers for printf(9).

Submitted by: Bruno Ducrot <ducrot AT poupinou.org>
Reviewed by: bde


# 77411499 06-Dec-2003 Scott Long <scottl@FreeBSD.org>

Re-arrange and consolidate some random debugging stuff


# 68f2d20b 22-Jul-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Revert stuff which accidentally ended up in the previous commit.


# 55d1d703 22-Jul-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Don't attempt to inline large functions mb_alloc() and mb_free(),
it more than doubles the text size of this file.

GCC has wisely ignored us on this previously


# adef9265 21-Jun-2003 Ian Dowse <iedowse@FreeBSD.org>

When DDB is active, always send printf() output directly to the
console, even if there is a TIOCCONS console tty. We were already
doing this after a panic, but it's also useful when entering DDB
for some other reason too.


# d29bf12f 21-Jun-2003 Ian Dowse <iedowse@FreeBSD.org>

Use a new message buffer `consmsgbuf' to forward messages to a
TIOCCONS console (e.g. xconsole) via a timeout routine instead of
calling into the tty code directly from printf(). This fixes a
number of cases where calling printf() at the wrong time (such as
with locks held) would cause a panic if xconsole is running.

The TIOCCONS message buffer is 8k in size by default, but this can
be changed with the kern.consmsgbuf_size sysctl. By default, messages
are checked for 5 times per second. The timer runs and the buffer
memory remains allocated only at times when a TIOCCONS console is
active.

Discussed on: freebsd-arch


# 4784a469 21-Jun-2003 Ian Dowse <iedowse@FreeBSD.org>

Replace the code for reading and writing the kernel message buffer
with a new implementation that has a mostly reentrant "addchar"
routine, supports multiple message buffers in the kernel, and hides
the implementation details from callers.

The new code uses a kind of sequence number to represend the current
read and write positions in the buffer. This approach (suggested
mainly by bde) permits the read and write pointers to be maintained
separately, which reduces the number of atomic operations that are
required. The "mostly reentrant" above refers to the way that while
it is now always safe to have any number of concurrent writers,
readers could see the message buffer after a writer has advanced
the pointers but before it has witten the new character.

Discussed on: freebsd-arch


# 677b542e 10-Jun-2003 David E. O'Brien <obrien@FreeBSD.org>

Use __FBSDID().


# 74f1af01 31-May-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unused variable(s).
Remove break after goto

Found by: FlexeLint


# b5a2bad1 17-Apr-2003 John Baldwin <jhb@FreeBSD.org>

Don't assume that p_session hasn't changed out from under us after unlocking
the process and session. Instead, cache a true reference to the session
when we do the hold and release our reference on that session. This avoids
the need for the proc lock when dropping the reference.


# 6205bf31 27-Mar-2003 Ian Dowse <iedowse@FreeBSD.org>

Add a checksum to the kernel message buffer, and update it every
time a character is written. Use this at boot time to reject the
existing buffer contents if they are corrupt. This fixes a problem
seen on some hardware (especially laptops) where the message buffer
gets partially corrupted during a short power cycle or reset, but
the msgbuf structure is left intact so it gets reused, resulting
in random junk and control characters appearing in dmesg and
/var/log/messages.

PR: kern/28497


# b4b138c2 18-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Including <sys/stdint.h> is (almost?) universally only to be able to use
%j in printfs, so put a newsted include in <sys/systm.h> where the printf
prototype lives and save everybody else the trouble.


# a163d034 18-Feb-2003 Warner Losh <imp@FreeBSD.org>

Back out M_* changes, per decision of the TRB.

Approved by: trb


# 8751a8c7 04-Feb-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Add vsnrprintf() which is just like vsnprintf() but takes a "radix"
argument for the kernel-special %r format.


# 44956c98 21-Jan-2003 Alfred Perlstein <alfred@FreeBSD.org>

Remove M_TRYWAIT/M_WAITOK/M_WAIT. Callers should use 0.
Merge M_NOWAIT/M_DONTWAIT into a single flag M_NOWAIT.


# 377a66bc 07-Jan-2003 John Baldwin <jhb@FreeBSD.org>

Cast the integer read as the first argument for %b to an unsigned integer
so it's value is not sign extended when assigned to the uintmax_t variable
used internally by printf. For example, if bit 31 is set in the cpuid
feature word, then %b would print out the initial value as a 16 character
hexadecimal value. Now it only prints out an 8 character value.

Reviewed by: bde


# 3ae59505 04-Jan-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Move #include of ddb/ddb.h up with the rest.


# 01ee4395 14-Nov-2002 Thomas Moestl <tmm@FreeBSD.org>

Make the msg_size, msg_bufx and msg_bufr memebers of struct msgbuf
signed, since they describe a ring buffer and signed arithmetic is
performed on them. This avoids some evilish casts.

Since this changes all but two members of this structure, style(9)
those remaining ones, too.

Requested by: bde
Reviewed by: bde (earlier version)


# 2bb95458 13-Nov-2002 Maxime Henrion <mux@FreeBSD.org>

Add support for the C99 %t format modifier.


# 4578a2e6 25-Oct-2002 Maxime Henrion <mux@FreeBSD.org>

- Rename the DDB specific %z printf format to %y.
- Make DDB use %y instead of %z.
- Teach GCC about %y.
- Implement support for the C99 %z format modifier.

Approved by: re@
Reviewed by: peter
Tested on: i386, sparc64


# 85594430 11-Oct-2002 John Baldwin <jhb@FreeBSD.org>

Fix %z to always print values as signed like it is supposed to.

Reviewed by: bde
Tested on: i386 in ddb


# 2f9752e9 28-Sep-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Change a return to a break so the local buffers get properly freeed.

Spotte by: FlexeLint

Reviewed by: rwatson


# af338bea 11-Aug-2002 David Malone <dwmalone@FreeBSD.org>

Make kern.log_console_output a tuneable aswell as a sysctl.

MFC after: 1 week


# e0b74464 05-Jul-2002 Warner Losh <imp@FreeBSD.org>

dd %i as an alias for %d for greater compatibility with our *BSD bretheren

Obtained from: NetBSD
Reviewed by: jake, rwatson, bosko


# 80208239 28-Jun-2002 Alfred Perlstein <alfred@FreeBSD.org>

More caddr_t removal.
Change struct knote's kn_hook from caddr_t to void *.


# f16a5176 02-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

ANSIfy the one remaining K&R function.


# e89efc02 02-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Whitespace nits.


# 3b1f7e7d 02-Jun-2002 Dag-Erling Smørgrav <des@FreeBSD.org>

Add support for 'j' flag. Simplify the size modifier code and reduce code
duplication. Also add support for 'n' specifier.

Reviewed by: bde


# dbe620d3 29-Apr-2002 David Malone <dwmalone@FreeBSD.org>

Add a sysctl which disables the logging of console output.

Approved by: phk
MFC after: 2 weeks


# 44731cab 01-Apr-2002 John Baldwin <jhb@FreeBSD.org>

Change the suser() API to take advantage of td_ucred as well as do a
general cleanup of the API. The entire API now consists of two functions
similar to the pre-KSE API. The suser() function takes a thread pointer
as its only argument. The td_ucred member of this thread must be valid
so the only valid thread pointers are curthread and a few kernel threads
such as thread0. The suser_cred() function takes a pointer to a struct
ucred as its first argument and an integer flag as its second argument.
The flag is currently only used for the PRISON_ROOT flag.

Discussed on: smp@


# 4d77a549 19-Mar-2002 Alfred Perlstein <alfred@FreeBSD.org>

Remove __P.


# 183ccde6 11-Mar-2002 Seigo Tanimura <tanimura@FreeBSD.org>

Stop abusing the pgrpsess_lock.


# f591779b 23-Feb-2002 Seigo Tanimura <tanimura@FreeBSD.org>

Lock struct pgrp, session and sigio.

New locks are:

- pgrpsess_lock which locks the whole pgrps and sessions,
- pg_mtx which protects the pgrp members, and
- s_mtx which protects the session members.

Please refer to sys/proc.h for the coverage of these locks.

Changes on the pgrp/session interface:

- pgfind() needs the pgrpsess_lock held.

- The caller of enterpgrp() is responsible to allocate a new pgrp and
session.

- Call enterthispgrp() in order to enter an existing pgrp.

- pgsignal() requires a pgrp lock held.

Reviewed by: jhb, alfred
Tested on: cvsup.jp.FreeBSD.org
(which is a quad-CPU machine running -current)


# 58a24f79 10-Feb-2002 Poul-Henning Kamp <phk@FreeBSD.org>

Style(9) nits.

Obtained from: ~bde/sys.dif.gz


# d0615c64 15-Jan-2002 Andrew R. Reiter <arr@FreeBSD.org>

- Attempt to help declutter kern. sysctl by moving security out from
beneath it.

Reviewed by: rwatson


# 6f3933fa 30-Nov-2001 Robert Watson <rwatson@FreeBSD.org>

o Introduce kern.security.bsd.unprivileged_read_msgbuf, which allows
the administrator to restrict access to the kernel message buffer.
It defaults to '1', which permits access, but if set to '0', requires
that the process making the sysctl() have appropriate privilege.
o Note that for this to be effective, access to this data via system
logs derived from /dev/klog must also be limited.

Obtained from: TrustedBSD Project
Sponsored by: DARPA, NAI Labs


# cca8f980 09-Nov-2001 Ian Dowse <iedowse@FreeBSD.org>

Properly sanity-check the old msgbuf structure before we accept it
as being valid. Previously only the magic number and the virtual
address were checked, but it makes little sense to require that
the virtual address is the same (the message buffer is located at
the end of physical memory), and checks on the msg_bufx and msg_bufr
indices were missing.

Submitted by: Bodo Rueskamp <br@clabsms.de>
Tripped over during a kernel debugging tutorial given by: grog
Reviewed by: grog, dwmalone
MFC after: 1 week


# b40ce416 12-Sep-2001 Julian Elischer <julian@FreeBSD.org>

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


# 948d3d94 03-Jul-2001 Thomas Moestl <tmm@FreeBSD.org>

Make the code to read the kernel message buffer via sysctl machine-
independent and rename the corresponding sysctls from machdep.msgbuf and
machdep.msgbuf_clear (i386 only) to kern.msgbuf and kern.msgbuf_clear.


# ef73ae4b 09-Jan-2001 Jake Burkholder <jake@FreeBSD.org>

Use PCPU_GET, PCPU_PTR and PCPU_SET to access all per-cpu variables
other then curproc.


# 661f2768 23-Dec-2000 Matt Jacob <mjacob@FreeBSD.org>

Make sure we have a non-null proc pointer before referring to fields
off of it.


# b80e3b41 20-Dec-2000 Poul-Henning Kamp <phk@FreeBSD.org>

A last minute brucification resulted in syntax errors in the previous commit.


# e2a09b26 20-Dec-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Replace logwakeup() with "int msgbuftrigger". There is little
point in calling a function just to set a flag.

Keep better track of the syslog FAC/PRI code and try to DTRT if
they mingle.

Log all writes to /dev/console to syslog with <console.info>
priority. The formatting is not preserved, there is no robust,
way of doing it. (Ideas with patches welcome).


# a52585d7 26-Nov-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Simplify the tprintf() API.

Loose the special <sys/tprintf.h> #include file.


# 4d88c459 26-Nov-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Make log(-1, ...) do what addlog(...) did.

Replace all uses of addlog(...) with log(-1, ...)

Remove bogus "register" keywords in subr_prf.c

Make log() return void.


# aa998012 02-Oct-2000 Mike Smith <msmith@FreeBSD.org>

Treat %X the same as %x (not entirely correct, but close enough).


# 0384fff8 06-Sep-2000 Jason Evans <jasone@FreeBSD.org>

Major update to the way synchronization is done in the kernel. Highlights
include:

* Mutual exclusion is used instead of spl*(). See mutex(9). (Note: The
alpha port is still in transition and currently uses both.)

* Per-CPU idle processes.

* Interrupts are run in their own separate kernel threads and can be
preempted (i386 only).

Partially contributed by: BSDi (BSD/OS)
Submissions by (at least): cp, dfr, dillon, grog, jake, jhb, sheldonh


# 7c3fdf6b 29-Apr-2000 Peter Wemm <peter@FreeBSD.org>

Do not fault if curproc is null.


# c3aac50f 27-Aug-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# ce9edcf5 09-Aug-1999 Poul-Henning Kamp <phk@FreeBSD.org>

Merge the cons.c and cons.h to the best of my ability. alpha may or
may not compile, I can't test it.


# 301ca4ff 07-Aug-1999 Brian Feldman <green@FreeBSD.org>

Make long longs ("%ll" format) work.

Reviewed by: msmith


# f1550d9d 24-Jul-1999 Doug Rabson <dfr@FreeBSD.org>

This makes the in kernel printf routines conform to the documented
behavior of their userland counterparts with respect to return values.

Submitted by: Matthew N. Dodd <winter@jurai.net>


# 341c6159 14-Jul-1999 Peter Wemm <peter@FreeBSD.org>

Oops, missed out one chunk of the last patch. (*blush*)

Submitted by: Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp>
Submitted by: "Matthew N. Dodd" <winter@jurai.net>


# 82941964 10-Jul-1999 Peter Wemm <peter@FreeBSD.org>

Fixes for a couple of problems in last commit:
1. Printing large quads in small bases overflowed the buffer if
sizeof(u_quad_t) > sizeof(u_long).
2. The sharpflag checks had operator precedence bugs due to excessive
parentheses in all the wrong places.
3. The explicit 0L was bogus in the quad_t comparison and useless in
the long comparision.
4. There was some more bitrot in the comment about ksprintn(). Our
ksprintn() handles bases up to 36 as well as down to 2.

Bruce has other complaints about using %q in kernel and would rather
we went towards using the C9X style %ll and/or %j. (I agree for that
matter, as long as gcc/egcs know how to deal with that.)

Submitted by: bde


# 7d921a01 09-Jul-1999 Peter Wemm <peter@FreeBSD.org>

Implement the %q prefix for the integer types. Note that egcs on the
Alpha believes that %q is for long long, whereas our quad_t and int64_t
is only just a plain long. long long on the alpha is the same size (64
bit) as a long. It was requested, but I have not implemented yet, support
for C9X style %lld - it should be pretty easy though.


# 05292ba2 07-Jun-1999 Archie Cobbs <archie@FreeBSD.org>

ksprintn() may be called with base=2, so redefine MAXNBUF accordingly.
Other brucification tweaks.

Obtained from: bde@freebsd.org


# ad4f8dbd 05-Jun-1999 Archie Cobbs <archie@FreeBSD.org>

The function ksprintn(), which is used to convert numbers to ASCII, is not
reentrant because it returns a static buffer. This results in a race condition
when/if an interrupt handler calls log(), printf() etc. Fix this.


# eb9d435a 01-Jun-1999 Jonathan Lemon <jlemon@FreeBSD.org>

Unifdef VM86.

Reviewed by: silence on on -current


# 8245f3f5 02-Dec-1998 Archie Cobbs <archie@FreeBSD.org>

Add snprintf(3) and vsnprintf(3) capability to the kernel.
Reviewed by: bde


# 99237364 06-Sep-1998 Andrey A. Chernov <ache@FreeBSD.org>

Store formatted panic string in static buffer to make it available later
for savecore.
Previous code give only panic format to savecore


# c41141b0 10-Aug-1998 Bruce Evans <bde@FreeBSD.org>

Fixed the formatting of some tables (mainly the one produced by ps
in ddb) which I broke by changing %8[l]x to %8p. Hacked the central
printf routine to not add an "0x" prefix for %p formats if the field
width is nonzero. The tables are still horribly misformatted on
64-bit machines.

Use %p instead of %8p to print pointers when the field width isn't
important.


# a23d65bf 14-Jul-1998 Bruce Evans <bde@FreeBSD.org>

Cast pointers to uintptr_t/intptr_t instead of to u_long/long,
respectively. Most of the longs should probably have been
u_longs, but this changes is just to prevent warnings about
casts between pointers and integers of different sizes, not
to fix poorly chosen types.


# e0c38587 08-Jul-1998 Bruce Evans <bde@FreeBSD.org>

Fixed (un)sign extension bugs in %+n format. -4 became
(long)(u_long)(u_int)-4 = 0x00000000fffffffc on machines with 32-bit
ints and 64-bit longs.

Restored %z format for printing signed hex. %+x shouldn't have been
used since it is an error in userland.

Prepared to nuke %n format by cloning it to %r. %n shouldn't have
been used because it means something completely different in
userland. Now %+r is equivalent to ddb's original %r, and %r is
equivalent to ddb's original %n.

Ignore '+' flag in combination with unsigned formats %{o,p,u,x}.


# e796e00d 28-May-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Some cleanups related to timecounters and weird ifdefs in <sys/time.h>.

Clean up (or if antipodic: down) some of the msgbuf stuff.

Use an inline function rather than a macro for timecounter delta.

Maintain process "on-cpu" time as 64 bits of microseconds to avoid
needless second rollover overhead.

Avoid calling microuptime the second time in mi_switch() if we do
not pass through _idle in cpu_switch()

This should reduce our context-switch overhead a bit, in particular
on pre-P5 and SMP systems.

WARNING: Programs which muck about with struct proc in userland
will have to be fixed.

Reviewed, but found imperfect by: bde


# 58067a99 19-May-1998 Poul-Henning Kamp <phk@FreeBSD.org>

Make the size of the msgbuf (dmesg) a "normal" option.


# f82057be 27-Dec-1997 Bruce Evans <bde@FreeBSD.org>

Handle "%...p" as "%#...x" instead of "0x%...x". This is a quick fix
for field widths being 2 larger than specified for "%<number>p". Only
printing of null pointers is "wrong" now (it is actually "right", but
inconsistent with printf(3)).


# a1c995b6 12-Oct-1997 Poul-Henning Kamp <phk@FreeBSD.org>

Last major round (Unless Bruce thinks of somthing :-) of malloc changes.

Distribute all but the most fundamental malloc types. This time I also
remembered the trick to making things static: Put "static" in front of
them.

A couple of finer points by: bde


# e4ba6a82 02-Sep-1997 Bruce Evans <bde@FreeBSD.org>

Removed unused #includes.


# 6875d254 22-Feb-1997 Peter Wemm <peter@FreeBSD.org>

Back out part 1 of the MCFH that changed $Id$ to $FreeBSD$. We are not
ready for it yet.


# 1130b656 14-Jan-1997 Jordan K. Hubbard <jkh@FreeBSD.org>

Make the long-awaited change from $Id$ to $FreeBSD$

This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore. This update would have been
insane otherwise.


# e0c95ed9 31-Aug-1996 Bruce Evans <bde@FreeBSD.org>

Fixed the easy cases of const poisoning in the kernel. Cosmetic.


# 269fb9d7 19-Aug-1996 Julian Elischer <julian@FreeBSD.org>

Collect all the functioons concerned with rebooting into one place
also add the at_shutdown callout list, and change the one user of
the present (broken) method (the vn driver) to use the new scheme.


# 4e31a37b 09-May-1996 Gary Palmer <gpalmer@FreeBSD.org>

Correct a comment. There is no fn `kprintf'


# 6ddbf1e2 07-May-1996 Gary Palmer <gpalmer@FreeBSD.org>

Clean up various compiler warnings. Most (if not all) were benign

Reviewed by: bde


# a8c5fef5 02-May-1996 Poul-Henning Kamp <phk@FreeBSD.org>

KGDB is dead. It may come back one day if somebody does it.


# 2438fbba 25-Mar-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Bill Fenner <fenner@parc.xerox.com> comes up with a better fix to the
debugger_on_panic stuff.


# 60743d0a 23-Mar-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Ok, now this is correct (even simple fixes sometimes ain't so simple :)


# 3ab332ee 23-Mar-1996 Jordan K. Hubbard <jkh@FreeBSD.org>

Fix bogus last commit - debugger_on_panic was referenced even when
not defined. Another change clearly committed without testing! :-(


# 924dfd98 23-Mar-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Remove all traces of KADB
add sysctl
debug.debugger_on_panic: 1
if DDB or KGDB is defined.

Requested by: davidg


# edbfedac 11-Mar-1996 Peter Wemm <peter@FreeBSD.org>

Import 4.4BSD-Lite2 onto the vendor branch, note that in the kernel, all
files are off the vendor branch, so this should not change anything.

A "U" marker generally means that the file was not changed in between
the 4.4Lite and Lite-2 releases, and does not need a merge. "C" generally
means that there was a change.
[note new unused (in this form) syscalls.conf, to be 'cvs rm'ed]


# 5ccab2af 28-Feb-1996 Gary Palmer <gpalmer@FreeBSD.org>

Add a new option: DDB_UNATTENDED. Stops machine dropping into DDB
when it panics, but leaving activation of DDB from the console
unaffected.


# 65ed8cbd 28-Jan-1996 Justin T. Gibbs <gibbs@FreeBSD.org>

Kernel printf now returns int.


# bf124e25 24-Jan-1996 Bruce Evans <bde@FreeBSD.org>

Restored newline at the end of panic messages.


# 120f0783 24-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Remove %r hack, we have vprintf() now.
Add %D for "dumping" data. Good for ethernet/MAC addresses and such.
Handle 1 < radix < 37.


# b4b2f81e 22-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

bounds check the radix, just in case.


# ed71c342 19-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Imake %.*s really work. :-(


# fe96d47d 19-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Make result of sprintf zero terminated. Fix %r for sprintf case.


# 4f20e4b1 18-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Make %.*s work.


# 4830092a 16-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Add support for %.{int|*}s


# 791d77e0 15-Jan-1996 Poul-Henning Kamp <phk@FreeBSD.org>

Get rid of two and a half printf in the kernel.
Add more features to the one remaining to handle the job:
+ signed quantity.
# alternate format
- left padding
* read width as next arg.
n numeric in (argument specified) default radix.

Fix the DDB debugger to use these.
Use vprintf in debug routine in pcvt.

The warnings from gcc may become more wrong and intolerable because
of this.

Warning: I have not checked the entire source for unsupported or
changed constructs, but generally belive that there are only a few.

Suggested by: bde


# 0e41ee30 04-Jan-1996 Garrett Wollman <wollman@FreeBSD.org>

Convert DDB to new-style option.


# 87b6de2b 14-Dec-1995 Poul-Henning Kamp <phk@FreeBSD.org>

A Major staticize sweep. Generates a couple of warnings that I'll deal
with later.
A number of unused vars removed.
A number of unused procs removed or #ifdefed.


# 229296b0 23-Aug-1995 David Greenman <dg@FreeBSD.org>

Killed some gratuitous #include's.


# b4224c9c 07-Aug-1995 David Greenman <dg@FreeBSD.org>

Woops, I committed the wrong version of the diff in the last rev.


# 6c8897cf 07-Aug-1995 David Greenman <dg@FreeBSD.org>

Made msgbuf range checking more robust and clean.


# 02d5c7b1 06-Aug-1995 David Greenman <dg@FreeBSD.org>

Restore check for msg_bufx being negative. Changed if() expression to be
in Lite2 style.


# f53dbe97 14-Jun-1995 Bruce Evans <bde@FreeBSD.org>

Convert %p to 0x%x instead of to 0x%8x. The latter gives blank padding
in the wrong place. Blank padding in the right place or zero padding
would be inconsistent with user mode.

Put case 'p' in alphabetical order.

Implement %p in sprintf() too. I'd like only a single, more complete
printf() core, perhaps one based on vsnprintf().


# 4fb0b0de 08-Apr-1995 Joerg Wunsch <joerg@FreeBSD.org>

Implement a simple hook (or hack?) to allow graphics device console
drivers to protect DDB from being invoked while the console is in
process-controlled (i.e., graphics) mode.

Implement the logic to use this hook from within pcvt. (I'm sure
Søren will do the syscons part RSN).

I've still got one occasion where the system stalled, but my attempts
to trigger the situation artificially resulted int the expected
behaviour. It's hard to track bugs without the console and DDB
available. :-/


# 76e2642c 01-Apr-1995 Joerg Wunsch <joerg@FreeBSD.org>

subr_prf.c used to provide an exported function kprintf(), but only had
a private declaration for it. Declare the function publically instead.


# b5e8ce9f 16-Mar-1995 Bruce Evans <bde@FreeBSD.org>

Add and move declarations to fix all of the warnings from `gcc -Wimplicit'
(except in netccitt, netiso and netns) and most of the warnings from
`gcc -Wnested-externs'. Fix all the bugs found. There were no serious
ones.


# a3f4face 19-Feb-1995 Bruce Evans <bde@FreeBSD.org>

Don't flush the message buffer when it fills up.


# 2336b9d7 29-Dec-1994 Bruce Evans <bde@FreeBSD.org>

Print "(null)" instead of "<null>" for NULL string args for consistency
with the libc and ddb printf's.

Print "(fmt null)\n" for NULL formats.


# 8f5067ba 27-Dec-1994 David Greenman <dg@FreeBSD.org>

Make printf() a bit more robust and allow NULL strings (print them as
"<null>"). It bad to have diagnostic printfs cause panics when they are
trying to tell you about another problem.


# 797f2d22 02-Oct-1994 Poul-Henning Kamp <phk@FreeBSD.org>

All of this is cosmetic. prototypes, #includes, printfs and so on. Makes
GCC a lot more silent.


# 12d17f65 28-Sep-1994 Poul-Henning Kamp <phk@FreeBSD.org>

Added a %p to printf & friends, same thing as 0x%08x but more with the
potiential to make a warning from gcc more useful.


# 8a129cae 27-Aug-1994 David Greenman <dg@FreeBSD.org>

1) Changed ddb into a option rather than a pseudo-device (use options DDB
in your kernel config now).
2) Added ps ddb function from 1.1.5. Cleaned it up a bit and moved into its
own file.
3) Added \r handing in db_printf.
4) Added missing memory usage stats to statclock().
5) Added dummy function to pseudo_set so it will be emitted if there
are no other pseudo declarations.


# 0e427608 13-Aug-1994 David Greenman <dg@FreeBSD.org>

Made the kernel compile cleanly with gcc 2.6.0. Thanks go to Bruce
Evans for suggesting a method to detect various versions of gcc.


# 3c4dd356 02-Aug-1994 David Greenman <dg@FreeBSD.org>

Added $Id$


# 26f9a767 25-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

The big 4.4BSD Lite to FreeBSD 2.0.0 (Development) patch.

Reviewed by: Rodney W. Grimes
Submitted by: John Dyson and David Greenman


# df8bae1d 24-May-1994 Rodney W. Grimes <rgrimes@FreeBSD.org>

BSD 4.4 Lite Kernel Sources