[PATCH] sysinfo fix for 2.2.x binary compatability

From: Erik Andersen (andersen@codepoet.org)
Date: Mon Aug 21 2000 - 13:15:12 EST


On Mon Aug 21, 2000 at 11:37:36AM -0600, Erik Andersen wrote:
> >
> > (More detail: for a sum of n terms, it breaks (for example) for equal
> > terms between max/(n-1) as lower and 2*max/n as upper bound. For n=2, this
> > is empty; for n=3, it's between 1/2*max and 2/3*max, for n=4 it'd be
> > between 1/3*max and 1/2*max, and so on.)
>
> Sigh. And it seemed like such a good heuristic at the time. I even spent 5
> whole minutes trying to find cases that broke it. Missed that one. Oh well.
> Guess I'll have to check for overflow the hard way... Patch soon follows,

This updated patch now correctly checks for overflow, where the previous
patch missed some cases,

 -Erik

--
Erik B. Andersen   email:  andersee@debian.org
--This message was written using 73% post-consumer electrons--

--- linux-2.4.0-test6.virgin/kernel/info.c Mon Aug 23 12:15:53 1999 +++ linux/kernel/info.c Mon Aug 21 11:03:14 2000 @@ -32,6 +32,42 @@ si_meminfo(&val); si_swapinfo(&val); + { + /* If the sum of all the available memory (i.e. ram + swap + + * highmem) is less then can be stored in a 32 bit unsigned long + * then we can be binary compatable with 2.2.x kernels. If not, + * well, who cares since in that case 2.2.x was broken anyways... + * + * -Erik Andersen <andersee@debian.org> */ + + unsigned long mem_total = val.totalram + val.totalswap; + if ( !(mem_total < val.totalram || mem_total < val.totalswap)) { + unsigned long mem_total2 = mem_total + val.totalhigh; + if (!(mem_total2 < mem_total || mem_total2 < val.totalhigh)) + { + /* If mem_total did not overflow. Divide all memory values by + * mem_unit and set mem_unit=1. This leaves things compatable with + * 2.2.x, and also retains compatability with earlier 2.4.x + * kernels... */ + + int bitcount = 0; + while (val.mem_unit > 1) + { + bitcount++; + val.mem_unit >>= 1; + } + val.totalram <<= bitcount; + val.freeram <<= bitcount; + val.sharedram <<= bitcount; + val.bufferram <<= bitcount; + val.totalswap <<= bitcount; + val.freeswap <<= bitcount; + val.totalhigh <<= bitcount; + val.freehigh <<= bitcount; + } + } + } + if (copy_to_user(info, &val, sizeof(struct sysinfo))) return -EFAULT; return 0; - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Wed Aug 23 2000 - 21:00:05 EST