PERFORCE change 143144 for review

John Birrell jb at FreeBSD.org
Mon Jun 9 02:47:05 UTC 2008


http://perforce.freebsd.org/chv.cgi?CH=143144

Change 143144 by jb at freebsd3 on 2008/06/09 02:46:25

	Add the generation of the functions required by the systrace kernel
	module, better known as the DTrace syscall provider.
	
	Note that this requires the kernel option BREAK_SYSENT_ABI at the
	moment because it requires extra fields in struct sysent which 
	affects ABI compatibility.
	
	It might be possible to find an ABI-compatible implementation
	at the expense of performance, but this is compilicated by the
	way that syscalls are hooked into struct proc.

Affected files ...

.. //depot/projects/dtrace6/src/sys/kern/makesyscalls.sh#2 edit
.. //depot/projects/dtrace6/src/sys/kern/syscalls.c#3 edit
.. //depot/projects/dtrace6/src/sys/sys/syscall.h#3 edit
.. //depot/projects/dtrace6/src/sys/sys/syscall.mk#3 edit
.. //depot/projects/dtrace6/src/sys/sys/sysent.h#2 edit
.. //depot/projects/dtrace6/src/sys/sys/sysproto.h#3 edit

Differences ...

==== //depot/projects/dtrace6/src/sys/kern/makesyscalls.sh#2 (text+ko) ====

@@ -18,6 +18,7 @@
 syscallprefix="SYS_"
 switchname="sysent"
 namesname="syscallnames"
+systrace="systrace_args.c"
 
 # tmp files:
 sysdcl="sysent.dcl.$$"
@@ -29,10 +30,11 @@
 sysinc="sysinc.switch.$$"
 sysarg="sysarg.switch.$$"
 sysprotoend="sysprotoend.$$"
+systracetmp="systrace.$$"
 
-trap "rm $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $sysent $sysinc $sysarg $sysprotoend" 0
+trap "rm $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $sysent $sysinc $sysarg $sysprotoend  $systracetmp" 0
 
-touch $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $sysent $sysinc $sysarg $sysprotoend
+touch $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp
 
 case $# in
     0)	echo "usage: $0 input-file <config-file>" 1>&2
@@ -73,6 +75,8 @@
 		sysnames = \"$sysnames\"
 		syshdr = \"$syshdr\"
 		sysmk = \"$sysmk\"
+		systrace = \"$systrace\"
+		systracetmp = \"$systracetmp\"
 		compat = \"$compat\"
 		compat4 = \"$compat4\"
 		syscallprefix = \"$syscallprefix\"
@@ -102,6 +106,10 @@
 		printf "# FreeBSD system call names.\n" > sysmk
 		printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
 		printf "# $%s$\n", "FreeBSD" > sysmk
+
+		printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
+		printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
+		printf " * $%s$\n", "FreeBSD" > systrace
 	}
 	NR == 1 {
 		gsub("[$]FreeBSD: ", "", $0)
@@ -110,6 +118,11 @@
 		printf " * created from%s\n */\n\n", $0 > syssw
 
 		printf "\n/* The casts are bogus but will do for now. */\n" > sysent
+		printf "#ifdef BREAK_SYSENT_ABI\n" > sysent
+		printf "#define SYSTRACE_EXTRA , NULL, 0, 0\n" > sysent
+		printf "#else\n" > sysent
+		printf "#define SYSTRACE_EXTRA\n" > sysent
+		printf "#endif\n" > sysent
 		printf "struct sysent %s[] = {\n",switchname > sysent
 
 		printf " * created from%s\n */\n\n", $0 > sysarg
@@ -140,6 +153,13 @@
 
 		printf "# created from%s\nMIASM = ", $0 > sysmk
 
+		printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
+		printf "static void\nsystrace_args(int sysnum, void *params, u_int64_t *uarg, int *n_args)\n{\n" > systrace
+		printf "\tint64_t *iarg  = (int64_t *) uarg;\n" > systrace
+		printf "\tswitch (sysnum) {\n" > systrace
+
+		printf "static void\nsystrace_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
+		printf "\tswitch (sysnum) {\n" > systracetmp
 		next
 	}
 	NF == 0 || $1 ~ /^;/ {
@@ -323,6 +343,30 @@
 	$3 == "STD" || $3 == "NODEF" || $3 == "NOARGS"  || $3 == "NOPROTO" \
 	    || $3 == "NOIMPL" || $3 == "NOSTD" {
 		parseline()
+		printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
+		printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
+		if (argc > 0) {
+			printf("\t\tswitch(ndx) {\n") > systracetmp
+			printf("\t\tstruct %s *p = params;\n", argalias) > systrace
+			for (i = 1; i <= argc; i++) {
+				printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, argtype[i]) > systracetmp
+				if (index(argtype[i], "*") > 0 || argtype[i] == "caddr_t")
+					printf("\t\tuarg[%d] = (intptr_t) p->%s; /* %s */\n", \
+					     i - 1, \
+					     argname[i], argtype[i]) > systrace
+				else if (substr(argtype[i], 1, 1) == "u" || argtype[i] == "size_t")
+					printf("\t\tuarg[%d] = p->%s; /* %s */\n", \
+					     i - 1, \
+					     argname[i], argtype[i]) > systrace
+				else
+					printf("\t\tiarg[%d] = p->%s; /* %s */\n", \
+					     i - 1, \
+					     argname[i], argtype[i]) > systrace
+			}
+			printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
+		}
+		printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
+		printf("\t\tbreak;\n") > systracetmp
 		if ((!nosys || funcname != "nosys") && \
 		    (funcname != "lkmnosys") && (funcname != "lkmressys")) {
 			if (argc != 0 && $3 != "NOARGS" && $3 != "NOPROTO") {
@@ -355,13 +399,13 @@
 		printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
 		column = 8 + 2 + length(mpsafe) + length(argssize) + 15
 		if ($3 == "NOIMPL") {
-			printf("%s },", "nosys, AUE_NULL") > sysent
+			printf("%s SYSTRACE_EXTRA },", "nosys, AUE_NULL") > sysent
 			column = column + length("nosys") + 3
 		} else if ($3 == "NOSTD") {
-			printf("%s },", "lkmressys, AUE_NULL") > sysent
+			printf("%s SYSTRACE_EXTRA },", "lkmressys, AUE_NULL") > sysent
 			column = column + length("lkmressys") + 3
 		} else {
-			printf("%s, %s },", funcname, auditev) > sysent
+			printf("%s, %s SYSTRACE_EXTRA },", funcname, auditev) > sysent
 			column = column + length(funcname) + length(auditev) + 3
 		} 
 		align_sysent_comment(column)
@@ -406,7 +450,7 @@
 			    argalias) > sysarg
 		printf("%s\t%s%s(struct thread *, struct %s *);\n",
 		    rettype, prefix, funcname, argalias) > outdcl
-		printf("\t{ %s(%s%s,%s), %s },",
+		printf("\t{ %s(%s%s,%s), %s SYSTRACE_EXTRA },",
 		    wrap, mpsafe, argssize, funcname, auditev) > sysent
 		align_sysent_comment(8 + 9 + length(mpsafe) + \
 		    length(argssize) + 1 + length(funcname) + length(auditev) + 4)
@@ -422,7 +466,7 @@
 		ncompat++
 		parseline()
 		printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
-		printf("\t{ compat(%s%s,%s), %s },",
+		printf("\t{ compat(%s%s,%s), %s SYSTRACE_EXTRA },",
 		    mpsafe, argssize, funcname, auditev) > sysent
 		align_sysent_comment(8 + 9 + length(mpsafe) + \
 		    length(argssize) + 1 + length(funcname) + length(auditev) + 4)
@@ -436,7 +480,7 @@
 		next
 	}
 	$3 == "OBSOL" {
-		printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL },") > sysent
+		printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL SYSTRACE_EXTRA },") > sysent
 		align_sysent_comment(34)
 		printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
 		printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
@@ -447,7 +491,7 @@
 		next
 	}
 	$3 == "UNIMPL" {
-		printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL },\t\t\t/* %d = %s */\n",
+		printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL SYSTRACE_EXTRA },\t\t\t/* %d = %s */\n",
 		    syscall, comment) > sysent
 		printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
 		    syscall, syscall, comment) > sysnames
@@ -495,6 +539,8 @@
 		printf("};\n") > sysnames
 		printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
 		    > syshdr
+		printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
+		printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
 	} '
 
 cat $sysinc $sysent >> $syssw
@@ -502,4 +548,5 @@
 	$syscompat $syscompatdcl \
 	$syscompat4 $syscompat4dcl \
 	$sysprotoend > $sysproto
+cat $systracetmp >> $systrace
 

==== //depot/projects/dtrace6/src/sys/kern/syscalls.c#3 (text+ko) ====

@@ -2,7 +2,7 @@
  * System call names.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/kern/syscalls.c,v 1.181.2.6 2008/04/24 10:52:30 dfr Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.198.2.6 2008/04/24 10:46:19 dfr Exp 
  */
 

==== //depot/projects/dtrace6/src/sys/sys/syscall.h#3 (text+ko) ====

@@ -2,7 +2,7 @@
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/sys/syscall.h,v 1.178.2.6 2008/04/24 10:52:30 dfr Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.198.2.6 2008/04/24 10:46:19 dfr Exp 
  */
 

==== //depot/projects/dtrace6/src/sys/sys/syscall.mk#3 (text+ko) ====

@@ -1,6 +1,6 @@
 # FreeBSD system call names.
 # DO NOT EDIT-- this file is automatically generated.
-# $FreeBSD: src/sys/sys/syscall.mk,v 1.133.2.6 2008/04/24 10:52:30 dfr Exp $
+# $FreeBSD$
 # created from FreeBSD: src/sys/kern/syscalls.master,v 1.198.2.6 2008/04/24 10:46:19 dfr Exp 
 MIASM =  \
 	syscall.o \

==== //depot/projects/dtrace6/src/sys/sys/sysent.h#2 (text+ko) ====

@@ -35,14 +35,32 @@
 #include <bsm/audit.h>
 
 struct rlimit;
+struct sysent;
 struct thread;
 
 typedef	int	sy_call_t(struct thread *, void *);
 
+/* Used by the machine dependent syscall() code. */
+typedef	void (*systrace_probe_func_t)(u_int32_t, int, struct sysent *, void *);
+
+/*
+ * Used by loaded syscalls to convert arguments to a DTrace array
+ * of 64-bit arguments.
+ */
+typedef	void (*systrace_args_func_t)(void *, u_int64_t *, int *);
+
+extern systrace_probe_func_t	systrace_probe_func;
+
 struct sysent {		/* system call table */
 	int	sy_narg;	/* number of arguments */
 	sy_call_t *sy_call;	/* implementing function */
 	au_event_t sy_auevent;	/* audit event associated with syscall */
+#ifdef BREAK_SYSENT_ABI
+	systrace_args_func_t sy_systrace_args_func;
+				/* optional argument conversion function. */
+	u_int32_t sy_entry;	/* DTrace entry ID for systrace. */ 
+	u_int32_t sy_return;	/* DTrace return ID for systrace. */ 
+#endif
 };
 
 #define SYF_ARGMASK	0x0000FFFF
@@ -92,6 +110,9 @@
 extern struct sysentvec elf_freebsd_sysvec;
 extern struct sysentvec null_sysvec;
 extern struct sysent sysent[];
+#ifndef BREAK_SYSENT_ABI
+extern struct sysent_extra sysent_extra[];
+#endif
 
 #define NO_SYSCALL (-1)
 

==== //depot/projects/dtrace6/src/sys/sys/sysproto.h#3 (text+ko) ====

@@ -2,7 +2,7 @@
  * System call prototypes.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * $FreeBSD: src/sys/sys/sysproto.h,v 1.177.2.6 2008/04/24 10:52:30 dfr Exp $
+ * $FreeBSD$
  * created from FreeBSD: src/sys/kern/syscalls.master,v 1.198.2.6 2008/04/24 10:46:19 dfr Exp 
  */
 


More information about the p4-projects mailing list