shithub: riscv

Download patch

ref: 86eb8ea6bbbf031d71cf0fa58f468cd3ddc4e7f3
parent: 8d196aeec728fea0450c0b42db114127e85d64e0
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Aug 6 06:15:07 EDT 2015

kernel: change vmemchr() length argument to ulong and simplify

--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -332,18 +332,20 @@
  * &s[0] is known to be a valid address.
  */
 void*
-vmemchr(void *s, int c, int n)
+vmemchr(void *s, int c, ulong n)
 {
-	int m;
 	uintptr a;
+	ulong m;
 	void *t;
 
 	a = (uintptr)s;
-	while(PGROUND(a) != PGROUND(a+n-1)){
-		/* spans pages; handle this page */
+	for(;;){
 		m = BY2PG - (a & (BY2PG-1));
+		if(n <= m)
+			break;
+		/* spans pages; handle this page */
 		t = memchr((void*)a, c, m);
-		if(t)
+		if(t != nil)
 			return t;
 		a += m;
 		n -= m;
--- a/sys/src/9/port/portfns.h
+++ b/sys/src/9/port/portfns.h
@@ -368,7 +368,7 @@
 void		validname(char*, int);
 char*		validnamedup(char*, int);
 void		validstat(uchar*, int);
-void*		vmemchr(void*, int, int);
+void*		vmemchr(void*, int, ulong);
 Proc*		wakeup(Rendez*);
 int		walk(Chan**, char**, int, int, int*);
 void		wlock(RWlock*);
--- a/sys/src/9/port/syscallfmt.c
+++ b/sys/src/9/port/syscallfmt.c
@@ -44,7 +44,7 @@
 		return;
 	}
 	validaddr((uintptr)a, 1, 0);
-	n = ((char*)vmemchr(a, 0, 0x7fffffff) - a) + 1;
+	n = ((char*)vmemchr(a, 0, ~0) - a) + 1;
 	t = smalloc(n+1);
 	memmove(t, a, n);
 	t[n] = 0;
--- a/sys/src/9/port/sysproc.c
+++ b/sys/src/9/port/sysproc.c
@@ -390,7 +390,7 @@
 		if(((uintptr)argp&(BY2PG-1)) < BY2WD)
 			validaddr((uintptr)argp, BY2WD, 0);
 		validaddr((uintptr)a, 1, 0);
-		nbytes += ((char*)vmemchr(a, 0, 0x7FFFFFFF) - a) + 1;
+		nbytes += ((char*)vmemchr(a, 0, ~0) - a) + 1;
 		nargs++;
 	}
 	ssize = BY2WD*(nargs+1) + ((nbytes+(BY2WD-1)) & ~(BY2WD-1));