Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Nov 2018 23:41:45 +0000 (UTC)
From:      Mark Johnston <markj@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r340208 - in head/sys: kern sys
Message-ID:  <201811062341.wA6NfjYY066444@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Tue Nov  6 23:41:44 2018
New Revision: 340208
URL: https://svnweb.freebsd.org/changeset/base/340208

Log:
  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

Modified:
  head/sys/kern/tty.c
  head/sys/kern/tty_info.c
  head/sys/sys/tty.h

Modified: head/sys/kern/tty.c
==============================================================================
--- head/sys/kern/tty.c	Tue Nov  6 22:50:50 2018	(r340207)
+++ head/sys/kern/tty.c	Tue Nov  6 23:41:44 2018	(r340208)
@@ -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_RWT
 
 #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
 	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;

Modified: head/sys/kern/tty_info.c
==============================================================================
--- head/sys/kern/tty_info.c	Tue Nov  6 22:50:50 2018	(r340207)
+++ head/sys/kern/tty_info.c	Tue Nov  6 23:41:44 2018	(r340208)
@@ -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. */

Modified: head/sys/sys/tty.h
==============================================================================
--- head/sys/sys/tty.h	Tue Nov  6 22:50:50 2018	(r340207)
+++ head/sys/sys/tty.h	Tue Nov  6 23:41:44 2018	(r340208)
@@ -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. */
 };
 
 /*



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201811062341.wA6NfjYY066444>