svn commit: r339341 - in head/sys: kern sys

Mateusz Guzik mjg at FreeBSD.org
Fri Oct 12 23:48:11 UTC 2018


Author: mjg
Date: Fri Oct 12 23:48:10 2018
New Revision: 339341
URL: https://svnweb.freebsd.org/changeset/base/339341

Log:
  capsicum: provide cap_rights_fde_inline
  
  Reading caps is in the hot path (on each successful fd lookup), but
  completely unnecessarily requires a function call.
  
  Approved by:	re (gjb)
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/kern/kern_descrip.c
  head/sys/kern/sys_capability.c
  head/sys/sys/capsicum.h

Modified: head/sys/kern/kern_descrip.c
==============================================================================
--- head/sys/kern/kern_descrip.c	Fri Oct 12 22:57:52 2018	(r339340)
+++ head/sys/kern/kern_descrip.c	Fri Oct 12 23:48:10 2018	(r339341)
@@ -2560,7 +2560,7 @@ fget_cap_locked(struct filedesc *fdp, int fd, cap_righ
 	}
 
 #ifdef CAPABILITIES
-	error = cap_check(cap_rights_fde(fde), needrightsp);
+	error = cap_check(cap_rights_fde_inline(fde), needrightsp);
 	if (error != 0)
 		goto out;
 #endif
@@ -2651,7 +2651,7 @@ fget_unlocked(struct filedesc *fdp, int fd, cap_rights
 #ifdef CAPABILITIES
 		seq = seq_read(fd_seq(fdt, fd));
 		fde = &fdt->fdt_ofiles[fd];
-		haverights = *cap_rights_fde(fde);
+		haverights = *cap_rights_fde_inline(fde);
 		fp = fde->fde_file;
 		if (!seq_consistent(fd_seq(fdt, fd), seq))
 			continue;

Modified: head/sys/kern/sys_capability.c
==============================================================================
--- head/sys/kern/sys_capability.c	Fri Oct 12 22:57:52 2018	(r339340)
+++ head/sys/kern/sys_capability.c	Fri Oct 12 23:48:10 2018	(r339341)
@@ -208,7 +208,7 @@ const cap_rights_t *
 cap_rights_fde(const struct filedescent *fdep)
 {
 
-	return (&fdep->fde_rights);
+	return (cap_rights_fde_inline(fdep));
 }
 
 const cap_rights_t *

Modified: head/sys/sys/capsicum.h
==============================================================================
--- head/sys/sys/capsicum.h	Fri Oct 12 22:57:52 2018	(r339340)
+++ head/sys/sys/capsicum.h	Fri Oct 12 23:48:10 2018	(r339341)
@@ -465,7 +465,13 @@ u_char	cap_rights_to_vmprot(const cap_rights_t *havep)
 /*
  * For the purposes of procstat(1) and similar tools, allow kern_descrip.c to
  * extract the rights from a capability.
+ *
+ * Dereferencing fdep requires filedesc.h, but including it would cause
+ * significant pollution. Instead add a macro for consumers which want it,
+ * most notably kern_descrip.c.
  */
+#define cap_rights_fde_inline(fdep)	(&(fdep)->fde_rights)
+
 const cap_rights_t	*cap_rights_fde(const struct filedescent *fde);
 const cap_rights_t	*cap_rights(struct filedesc *fdp, int fd);
 


More information about the svn-src-all mailing list