From da01fdae11e470bf839edd610522ab6e0a56a096 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Fri, 24 Aug 2012 15:46:21 +0200 Subject: [PATCH] guesscpuhz: add sanity checks for virtualbox (import from sources) --- sys/src/9/pc/i8253.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sys/src/9/pc/i8253.c b/sys/src/9/pc/i8253.c index 2e3ea2162..04af79edb 100644 --- a/sys/src/9/pc/i8253.c +++ b/sys/src/9/pc/i8253.c @@ -165,7 +165,7 @@ guesscpuhz(int aalcycles) cpufreq = (vlong)loops*((aalcycles*2*Freq)/x); m->loopconst = (cpufreq/1000)/aalcycles; /* AAM+LOOP's for 1 ms */ - if(m->havetsc){ + if(m->havetsc && a != b){ /* a == b means virtualbox has confused us */ /* counter goes up by 2*Freq */ b = (b-a)<<1; b *= Freq; @@ -185,6 +185,9 @@ guesscpuhz(int aalcycles) m->cpuhz = cpufreq; } + /* don't divide by zero in trap.c */ + if(m->cpumhz == 0) + panic("guesscpuhz: zero m->cpumhz"); i8253.hz = Freq<