diff --git a/gc/ogc/system.h b/gc/ogc/system.h index 08aca2d1..5be7f46f 100644 --- a/gc/ogc/system.h +++ b/gc/ogc/system.h @@ -267,6 +267,7 @@ void SYS_Init(void); void* SYS_AllocateFramebuffer(GXRModeObj *rmode); +bool SYS_IsDMAAddress(const void *addr); void SYS_ProtectRange(u32 chan,void *addr,u32 bytes,u32 cntrl); void SYS_StartPMC(u32 mcr0val,u32 mcr1val); void SYS_DumpPMC(void); diff --git a/libogc/dvd.c b/libogc/dvd.c index f8fbc22b..e2725ae6 100644 --- a/libogc/dvd.c +++ b/libogc/dvd.c @@ -3172,7 +3172,7 @@ static bool __gcdvd_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) if(sector & ~0x7fffff) return false; if(numSectors & ~0x1fffff) return false; - if((u32)buffer & 0x1f) return false; + if(!SYS_IsDMAAddress(buffer)) return false; if(DVD_ReadAbs(&blk, buffer, numSectors << 11, sector << 11) < 0) return false; @@ -3233,7 +3233,7 @@ static bool __gcode_ReadSectors(sec_t sector,sec_t numSectors,void *buffer) if((u32)sector != sector) return false; if(numSectors & ~0x7fffff) return false; - if((u32)buffer & 0x1f) return false; + if(!SYS_IsDMAAddress(buffer)) return false; if(DVD_GcodeRead(&blk, buffer, numSectors << 9, sector) < 0) return false; @@ -3247,7 +3247,7 @@ static bool __gcode_WriteSectors(sec_t sector,sec_t numSectors,const void *buffe if((u32)sector != sector) return false; if((u32)numSectors != numSectors) return false; - if((u32)buffer & 0x1f) return false; + if(!SYS_IsDMAAddress(buffer)) return false; if(DVD_GcodeWrite(&blk, buffer, numSectors, sector) < 0) return false; diff --git a/libogc/gcsd.c b/libogc/gcsd.c index e98a83f6..c66f648d 100644 --- a/libogc/gcsd.c +++ b/libogc/gcsd.c @@ -84,6 +84,7 @@ static bool __gcsd_writeSectors(int n, sec_t sector, sec_t numSectors, const voi if((u32)sector != sector) return false; if((u32)numSectors != numSectors) return false; + if(!SYS_IsDMAAddress(buffer)) return false; if(numSectors == 1) ret = sdgecko_writeSector(n, buffer, sector); diff --git a/libogc/system.c b/libogc/system.c index 206c499f..13352b5d 100644 --- a/libogc/system.c +++ b/libogc/system.c @@ -1494,6 +1494,18 @@ void SYS_ProtectRange(u32 chan,void *addr,u32 bytes,u32 cntrl) } } +bool SYS_IsDMAAddress(const void *addr) +{ + if((u32)addr&0x1F) return false; + if((u32)addr>=0x80000000 && (u32)addr<0x84000000) return true; + if((u32)addr>=0xC0000000 && (u32)addr<0xC4000000) return true; +#if defined(HW_RVL) + if((u32)addr>=0x90000000 && (u32)addr<0xA0000000) return true; + if((u32)addr>=0xD0000000 && (u32)addr<0xE0000000) return true; +#endif + return false; +} + void* SYS_AllocateFramebuffer(GXRModeObj *rmode) { return memalign(32, VIDEO_GetFrameBufferSize(rmode)); diff --git a/libogc/wiisd.c b/libogc/wiisd.c index 9151a577..5af6547d 100644 --- a/libogc/wiisd.c +++ b/libogc/wiisd.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -539,7 +540,7 @@ static bool sdio_ReadSectors(sec_t sector, sec_t numSectors,void* buffer) if((u32)sector != sector) return false; if(numSectors & ~0x7fffff) return false; - if((u32)buffer & 0x1f) return false; + if(!SYS_IsDMAAddress(buffer)) return false; ret = __sd0_select(); if(ret<0) return false; @@ -558,7 +559,7 @@ static bool sdio_WriteSectors(sec_t sector, sec_t numSectors,const void* buffer) if((u32)sector != sector) return false; if(numSectors & ~0x7fffff) return false; - if((u32)buffer & 0x1f) return false; + if(!SYS_IsDMAAddress(buffer)) return false; ret = __sd0_select(); if(ret<0) return false;