diff options
author | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1997-07-19 20:44:20 +0000 |
---|---|---|
committer | Niklas Hallqvist <niklas@cvs.openbsd.org> | 1997-07-19 20:44:20 +0000 |
commit | 5cb42bec44cf087eb4e81c9af8ea7224afd6fbbe (patch) | |
tree | a800cc01f4dd1b6f1474c7a2f8ecc4dc8004b279 /sys | |
parent | a9deae940d4f7b65a33bf88b13da1e1d7d2d2f2b (diff) |
Protect against overlapping copies
Diffstat (limited to 'sys')
-rw-r--r-- | sys/arch/alpha/pci/pcs_bus_mem_common.c | 14 | ||||
-rw-r--r-- | sys/arch/alpha/tc/tc_bus_mem.c | 14 |
2 files changed, 20 insertions, 8 deletions
diff --git a/sys/arch/alpha/pci/pcs_bus_mem_common.c b/sys/arch/alpha/pci/pcs_bus_mem_common.c index 1e3d87bd42d..ac6a817b57d 100644 --- a/sys/arch/alpha/pci/pcs_bus_mem_common.c +++ b/sys/arch/alpha/pci/pcs_bus_mem_common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcs_bus_mem_common.c,v 1.7 1997/07/06 18:28:01 niklas Exp $ */ +/* $OpenBSD: pcs_bus_mem_common.c,v 1.8 1997/07/19 20:44:15 niklas Exp $ */ /* $NetBSD: pcs_bus_mem_common.c,v 1.15 1996/12/02 22:19:36 cgd Exp $ */ /* @@ -1006,9 +1006,15 @@ __C(__C(CHIP,_mem_copy_),BYTES)(v, h1, o1, h2, o2, c) \ return; \ } \ \ - for (i = 0, o = 0; i < c; i++, o += BYTES) \ - __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \ - __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o)); \ + /* Circumvent a common case of overlapping problems */ \ + if (h1 == h2 && o2 > o1) \ + for (i = 0, o = (c - 1) * BYTES; i < c; i++, o -= BYTES)\ + __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \ + __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o));\ + else \ + for (i = 0, o = 0; i < c; i++, o += BYTES) \ + __C(__C(CHIP,_mem_write_),BYTES)(v, h2, o2 + o, \ + __C(__C(CHIP,_mem_read_),BYTES)(v, h1, o1 + o));\ } CHIP_mem_copy_N(1) CHIP_mem_copy_N(2) diff --git a/sys/arch/alpha/tc/tc_bus_mem.c b/sys/arch/alpha/tc/tc_bus_mem.c index f5dfda85819..62b9aa23176 100644 --- a/sys/arch/alpha/tc/tc_bus_mem.c +++ b/sys/arch/alpha/tc/tc_bus_mem.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tc_bus_mem.c,v 1.9 1997/04/10 15:45:25 millert Exp $ */ +/* $OpenBSD: tc_bus_mem.c,v 1.10 1997/07/19 20:44:19 niklas Exp $ */ /* $NetBSD: tc_bus_mem.c,v 1.13 1996/12/02 22:19:34 cgd Exp $ */ /* @@ -630,9 +630,15 @@ __abs_c(tc_mem_copy_,BYTES)(v, h1, o1, h2, o2, c) \ return; \ } \ \ - for (i = 0, o = 0; i < c; i++, o += BYTES) \ - __abs_c(tc_mem_write_,BYTES)(v, h2, o2 + o, \ - __abs_c(tc_mem_read_,BYTES)(v, h1, o1 + o)); \ + /* Circumvent a common case of overlapping problems */ \ + if (h1 == h2 && o2 > o1) \ + for (i = 0, o = (c - 1) * BYTES; i < c; i++, o -= BYTES)\ + __abs_c(tc_mem_write_,BYTES)(v, h2, o2 + o, \ + __abs_c(tc_mem_read_,BYTES)(v, h1, o1 + o));\ + else \ + for (i = 0, o = 0; i < c; i++, o += BYTES) \ + __abs_c(tc_mem_write_,BYTES)(v, h2, o2 + o, \ + __abs_c(tc_mem_read_,BYTES)(v, h1, o1 + o));\ } tc_mem_copy_N(1) tc_mem_copy_N(2) |