Bug 187074

Summary: Crash cross compilation for MIPS
Product: Base System Reporter: misho
Component: kernAssignee: Gleb Smirnoff <glebius>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Unspecified   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
file.diff none

Description misho 2014-02-25 21:40:00 UTC
Cross compilation of kernel for MIPS architecture failed with this lines::

/home/fbsd_work.src/src/sys/netpfil/pf/pf_ioctl.c: In function 'pfioctl':
/home/fbsd_work.src/src/sys/netpfil/pf/pf_ioctl.c:1357: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
/home/fbsd_work.src/src/sys/netpfil/pf/pf_ioctl.c:1359: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
/home/fbsd_work.src/src/sys/netpfil/pf/pf_ioctl.c:1361: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]

Fix: Index: sys/netpfil/pf/pf_ioctl.c
===================================================================
--- sys/netpfil/pf/pf_ioctl.c	(revision 262482)
+++ sys/netpfil/pf/pf_ioctl.c	(working copy)
@@ -1353,12 +1353,12 @@
 		 * XXXGL: this is what happens when internal kernel
 		 * structures are used as ioctl API structures.
 		 */
-		pr->rule.states_cur =
-		    (counter_u64_t )counter_u64_fetch(rule->states_cur);
-		pr->rule.states_tot =
-		    (counter_u64_t )counter_u64_fetch(rule->states_tot);
-		pr->rule.src_nodes =
-		    (counter_u64_t )counter_u64_fetch(rule->src_nodes);
+		pr->rule.states_cur = (counter_u64_t) (uintptr_t) 
+			counter_u64_fetch(rule->states_cur);
+		pr->rule.states_tot = (counter_u64_t) (uintptr_t) 
+			counter_u64_fetch(rule->states_tot);
+		pr->rule.src_nodes = (counter_u64_t) (uintptr_t) 
+			counter_u64_fetch(rule->src_nodes);
 		if (pf_anchor_copyout(ruleset, rule, pr)) {
 			PF_RULES_WUNLOCK();
 			error = EBUSY;


Patch attached with submission follows:
How-To-Repeat: Try to cross compilation of kernel for MIPS
Comment 1 dfilter service freebsd_committer freebsd_triage 2014-03-05 00:40:11 UTC
Author: glebius
Date: Wed Mar  5 00:40:03 2014
New Revision: 262760
URL: http://svnweb.freebsd.org/changeset/base/262760

Log:
  Instead of playing games with casts simply add 3 more members to the
  structure pf_rule, that are used when the structure is passed via
  ioctl().
  
  PR:		187074

Modified:
  head/sbin/pfctl/pfctl.c
  head/sys/net/pfvar.h
  head/sys/netpfil/pf/pf_ioctl.c

Modified: head/sbin/pfctl/pfctl.c
==============================================================================
--- head/sbin/pfctl/pfctl.c	Wed Mar  5 00:26:25 2014	(r262759)
+++ head/sbin/pfctl/pfctl.c	Wed Mar  5 00:40:03 2014	(r262760)
@@ -50,7 +50,6 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <inttypes.h>
 #include <limits.h>
 #include <netdb.h>
 #include <stdio.h>
@@ -792,18 +791,17 @@ pfctl_print_rule_counters(struct pf_rule
 	}
 	if (opts & PF_OPT_VERBOSE) {
 		printf("  [ Evaluations: %-8llu  Packets: %-8llu  "
-			    "Bytes: %-10llu  States: %-6"PRIuPTR"]\n",
+			    "Bytes: %-10llu  States: %-6lu]\n",
 			    (unsigned long long)rule->evaluations,
 			    (unsigned long long)(rule->packets[0] +
 			    rule->packets[1]),
 			    (unsigned long long)(rule->bytes[0] +
-			    rule->bytes[1]),
-			    (uintptr_t)rule->states_cur);
+			    rule->bytes[1]), rule->u_states_cur);
 		if (!(opts & PF_OPT_DEBUG))
 			printf("  [ Inserted: uid %u pid %u "
-			    "State Creations: %-6"PRIuPTR"]\n",
+			    "State Creations: %-6lu]\n",
 			    (unsigned)rule->cuid, (unsigned)rule->cpid,
-			    (uintptr_t)rule->states_tot);
+			    rule->u_states_tot);
 	}
 }
 
@@ -905,7 +903,7 @@ pfctl_show_rules(int dev, char *path, in
 		case PFCTL_SHOW_LABELS:
 			if (pr.rule.label[0]) {
 				printf("%s %llu %llu %llu %llu"
-				    " %llu %llu %llu %"PRIuPTR"\n",
+				    " %llu %llu %llu %llu\n",
 				    pr.rule.label,
 				    (unsigned long long)pr.rule.evaluations,
 				    (unsigned long long)(pr.rule.packets[0] +
@@ -916,7 +914,7 @@ pfctl_show_rules(int dev, char *path, in
 				    (unsigned long long)pr.rule.bytes[0],
 				    (unsigned long long)pr.rule.packets[1],
 				    (unsigned long long)pr.rule.bytes[1],
-				    (uintptr_t)pr.rule.states_tot);
+				    (unsigned long long)pr.rule.u_states_tot);
 			}
 			break;
 		case PFCTL_SHOW_RULES:

Modified: head/sys/net/pfvar.h
==============================================================================
--- head/sys/net/pfvar.h	Wed Mar  5 00:26:25 2014	(r262759)
+++ head/sys/net/pfvar.h	Wed Mar  5 00:40:03 2014	(r262760)
@@ -580,6 +580,10 @@ struct pf_rule {
 		struct pf_addr		addr;
 		u_int16_t		port;
 	}			divert;
+
+	uint64_t		 u_states_cur;
+	uint64_t		 u_states_tot;
+	uint64_t		 u_src_nodes;
 };
 
 /* rule flags */

Modified: head/sys/netpfil/pf/pf_ioctl.c
==============================================================================
--- head/sys/netpfil/pf/pf_ioctl.c	Wed Mar  5 00:26:25 2014	(r262759)
+++ head/sys/netpfil/pf/pf_ioctl.c	Wed Mar  5 00:40:03 2014	(r262760)
@@ -1349,16 +1349,9 @@ DIOCADDRULE_error:
 			break;
 		}
 		bcopy(rule, &pr->rule, sizeof(struct pf_rule));
-		/*
-		 * XXXGL: this is what happens when internal kernel
-		 * structures are used as ioctl API structures.
-		 */
-		pr->rule.states_cur =
-		    (counter_u64_t )counter_u64_fetch(rule->states_cur);
-		pr->rule.states_tot =
-		    (counter_u64_t )counter_u64_fetch(rule->states_tot);
-		pr->rule.src_nodes =
-		    (counter_u64_t )counter_u64_fetch(rule->src_nodes);
+		pr->rule.u_states_cur = counter_u64_fetch(rule->states_cur);
+		pr->rule.u_states_tot = counter_u64_fetch(rule->states_tot);
+		pr->rule.u_src_nodes = counter_u64_fetch(rule->src_nodes);
 		if (pf_anchor_copyout(ruleset, rule, pr)) {
 			PF_RULES_WUNLOCK();
 			error = EBUSY;
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 2 Gleb Smirnoff freebsd_committer freebsd_triage 2014-03-05 00:40:37 UTC
State Changed
From-To: open->closed
Comment 3 Gleb Smirnoff freebsd_committer freebsd_triage 2014-03-05 00:40:37 UTC
Responsible Changed
From-To: freebsd-bugs->glebius

Fixed.