Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 5 Oct 2014 19:40:30 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r272567 - in head/sys: kern sys
Message-ID:  <201410051940.s95JeUg7069798@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sun Oct  5 19:40:29 2014
New Revision: 272567
URL: https://svnweb.freebsd.org/changeset/base/272567

Log:
  filedesc: fix up breakage introduced in 272505
  
  Include sequence counter supports incoditionally [1]. This fixes reprted build
  problems with e.g. nvidia driver due to missing opt_capsicum.h.
  
  Replace fishy looking sizeof with offsetof. Make fde_seq the last member in
  order to simplify calculations.
  
  Suggested by:	kib [1]
  X-MFC:		with 272505

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/sys/filedesc.h

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Sun Oct  5 17:35:59 2014	(r272566)
+++ head/sys/kern/kern_descrip.c	Sun Oct  5 19:40:29 2014	(r272567)
@@ -295,7 +295,7 @@ _fdfree(struct filedesc *fdp, int fd, in
 	filecaps_free(&fde->fde_caps);
 	if (last)
 		return;
-	bzero(fde_change(fde), fde_change_size);
+	bzero(fde, fde_change_size);
 	fdunused(fdp, fd);
 #ifdef CAPABILITIES
 	seq_write_end(&fde->fde_seq);
@@ -894,7 +894,7 @@ do_dup(struct thread *td, int flags, int
 	seq_write_begin(&newfde->fde_seq);
 #endif
 	filecaps_free(&newfde->fde_caps);
-	memcpy(fde_change(newfde), fde_change(oldfde), fde_change_size);
+	memcpy(newfde, oldfde, fde_change_size);
 	filecaps_copy(&oldfde->fde_caps, &newfde->fde_caps);
 	if ((flags & DUP_CLOEXEC) != 0)
 		newfde->fde_flags = oldfde->fde_flags | UF_EXCLOSE;
@@ -2778,7 +2778,7 @@ dupfdopen(struct thread *td, struct file
 #ifdef CAPABILITIES
 		seq_write_begin(&newfde->fde_seq);
 #endif
-		memcpy(fde_change(newfde), fde_change(oldfde), fde_change_size);
+		memcpy(newfde, oldfde, fde_change_size);
 		filecaps_copy(&oldfde->fde_caps, &newfde->fde_caps);
 #ifdef CAPABILITIES
 		seq_write_end(&newfde->fde_seq);
@@ -2793,8 +2793,8 @@ dupfdopen(struct thread *td, struct file
 #ifdef CAPABILITIES
 		seq_write_begin(&newfde->fde_seq);
 #endif
-		memcpy(fde_change(newfde), fde_change(oldfde), fde_change_size);
-		bzero(fde_change(oldfde), fde_change_size);
+		memcpy(newfde, oldfde, fde_change_size);
+		bzero(oldfde, fde_change_size);
 		fdunused(fdp, dfd);
 #ifdef CAPABILITIES
 		seq_write_end(&newfde->fde_seq);

Modified: head/sys/sys/filedesc.h
==============================================================================
--- head/sys/sys/filedesc.h	Sun Oct  5 17:35:59 2014	(r272566)
+++ head/sys/sys/filedesc.h	Sun Oct  5 19:40:29 2014	(r272567)
@@ -33,10 +33,6 @@
 #ifndef _SYS_FILEDESC_H_
 #define	_SYS_FILEDESC_H_
 
-#ifdef _KERNEL
-#include "opt_capsicum.h"
-#endif
-
 #include <sys/caprights.h>
 #include <sys/queue.h>
 #include <sys/event.h>
@@ -55,24 +51,16 @@ struct filecaps {
 };
 
 struct filedescent {
-#ifdef CAPABILITIES
-	seq_t		 fde_seq;		/* if you need fde_file and fde_caps in sync */
-#endif
 	struct file	*fde_file;		/* file structure for open file */
 	struct filecaps	 fde_caps;		/* per-descriptor rights */
 	uint8_t		 fde_flags;		/* per-process open file flags */
+	seq_t		 fde_seq;		/* if you need fde_file and fde_caps in sync */
 };
 #define	fde_rights	fde_caps.fc_rights
 #define	fde_fcntls	fde_caps.fc_fcntls
 #define	fde_ioctls	fde_caps.fc_ioctls
 #define	fde_nioctls	fde_caps.fc_nioctls
-#ifdef CAPABILITIES
-#define	fde_change(fde)	((char *)(fde) + sizeof(seq_t))
-#define	fde_change_size	(sizeof(struct filedescent) - sizeof(seq_t))
-#else
-#define	fde_change(fde)	((fde))
-#define	fde_change_size	(sizeof(struct filedescent))
-#endif
+#define	fde_change_size	(offsetof(struct filedescent, fde_seq))
 
 /*
  * This structure is used for the management of descriptors.  It may be
@@ -97,9 +85,7 @@ struct filedesc {
 	int	fd_holdleaderscount;	/* block fdfree() for shared close() */
 	int	fd_holdleaderswakeup;	/* fdfree() needs wakeup */
 };
-#ifdef	CAPABILITIES
 #define	fd_seq(fdp, fd)	(&(fdp)->fd_ofiles[(fd)].fde_seq)
-#endif
 
 /*
  * Structure to keep track of (process leader, struct fildedesc) tuples.



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