summaryrefslogtreecommitdiff
path: root/sys/src/9/port/fault.c
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@rei2.9hal>2012-02-16 11:38:50 +0100
committercinap_lenrek <cinap_lenrek@rei2.9hal>2012-02-16 11:38:50 +0100
commit083612b34eb152ea20b31aa5d7fbef1c11e4173e (patch)
tree8e6ad445c9c1e89043066dc8fa928b60b8ed9fc0 /sys/src/9/port/fault.c
parent739846b45263c16a817e9288ec87f371dacc443e (diff)
kernel: duppage checking
Diffstat (limited to 'sys/src/9/port/fault.c')
-rw-r--r--sys/src/9/port/fault.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/sys/src/9/port/fault.c b/sys/src/9/port/fault.c
index 5ab0c9f2e..b5c59d80f 100644
--- a/sys/src/9/port/fault.c
+++ b/sys/src/9/port/fault.c
@@ -140,14 +140,20 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
lkp = *pg;
lock(lkp);
-
+ if(lkp->ref <= 0)
+ panic("fault: lkp->ref %d <= 0", lkp->ref);
if(lkp->image == &swapimage)
ref = lkp->ref + swapcount(lkp->daddr);
else
ref = lkp->ref;
- if(ref > 1) {
- unlock(lkp);
+ if(ref == 1 && lkp->image){
+ /* save a copy of the original for the image cache */
+ duppage(lkp);
+ ref = lkp->ref;
+ }
+ unlock(lkp);
+ if(ref > 1){
new = newpage(0, &s, addr);
if(s == 0)
return -1;
@@ -155,13 +161,6 @@ fixfault(Segment *s, ulong addr, int read, int doputmmu)
copypage(lkp, *pg);
putpage(lkp);
}
- else {
- /* save a copy of the original for the image cache */
- if(lkp->image)
- duppage(lkp);
-
- unlock(lkp);
- }
mmuphys = PPN((*pg)->pa) | PTEWRITE | PTEVALID;
(*pg)->modref = PG_MOD|PG_REF;
break;