Avoid fixing the tty_info() buffer size in tty.h.

Different compilation units may otherwise get a different view of the
layout of struct tty depending on whether they include opt_printf.h.
This caused a blowup in the number of types defined in the kernel's
CTF file after r339468; thanks to dim@ for bisecting down to that
revision.

PR:		232675
Reported by:	dim
Reviewed by:	cem (previous version)
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D17877
This commit is contained in:
Mark Johnston 2018-11-06 23:41:44 +00:00
parent 6ad8a6eaa4
commit f8a222010f
3 changed files with 13 additions and 8 deletions

View File

@ -33,6 +33,7 @@
__FBSDID("$FreeBSD$");
#include "opt_capsicum.h"
#include "opt_printf.h"
#include <sys/param.h>
#include <sys/capsicum.h>
@ -106,6 +107,12 @@ SYSCTL_INT(_kern, OID_AUTO, tty_drainwait, CTLFLAG_RWTUN,
#define TTYBUF_MAX 65536
#ifdef PRINTF_BUFR_SIZE
#define TTY_PRBUF_SIZE PRINTF_BUFR_SIZE
#else
#define TTY_PRBUF_SIZE 256
#endif
/*
* Allocate buffer space if necessary, and set low watermarks, based on speed.
* Note that the ttyxxxq_setsize() functions may drop and then reacquire the tty
@ -1051,7 +1058,9 @@ tty_alloc_mutex(struct ttydevsw *tsw, void *sc, struct mtx *mutex)
PATCH_FUNC(busy);
#undef PATCH_FUNC
tp = malloc(sizeof(struct tty), M_TTY, M_WAITOK|M_ZERO);
tp = malloc(sizeof(struct tty) + TTY_PRBUF_SIZE, M_TTY,
M_WAITOK | M_ZERO);
tp->t_prbufsz = TTY_PRBUF_SIZE;
tp->t_devsw = tsw;
tp->t_devswsoftc = sc;
tp->t_flags = tsw->tsw_flags;

View File

@ -271,7 +271,7 @@ tty_info(struct tty *tp)
if (tty_checkoutq(tp) == 0)
return;
(void)sbuf_new(&sb, tp->t_prbuf, sizeof(tp->t_prbuf), SBUF_FIXEDLEN);
(void)sbuf_new(&sb, tp->t_prbuf, tp->t_prbufsz, SBUF_FIXEDLEN);
sbuf_set_drain(&sb, sbuf_tty_drain, tp);
/* Print load average. */

View File

@ -133,12 +133,8 @@ struct tty {
void *t_hooksoftc; /* (t) Soft config, for hooks. */
struct cdev *t_dev; /* (c) Primary character device. */
#ifndef PRINTF_BUFR_SIZE
#define TTY_PRINTF_SIZE 256
#else
#define TTY_PRINTF_SIZE PRINTF_BUFR_SIZE
#endif
char t_prbuf[TTY_PRINTF_SIZE]; /* (t) */
size_t t_prbufsz; /* (t) SIGINFO buffer size. */
char t_prbuf[]; /* (t) SIGINFO buffer. */
};
/*