-cleaned up code more, set clear priority to alloc in which

memory region
This commit is contained in:
fix94.1 2012-05-12 21:08:43 +00:00
parent d669a1a17e
commit 49a31c4f25
22 changed files with 43 additions and 69 deletions

View File

@ -81,7 +81,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include <ctype.h> #include <ctype.h>
#include "MD5.h" #include "MD5.h"

View File

@ -26,7 +26,6 @@
* for wiiflow 2010 * for wiiflow 2010
***************************************************************************/ ***************************************************************************/
#include <malloc.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>

View File

@ -14,7 +14,6 @@
******************************************************************************/ ******************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>

View File

@ -29,7 +29,6 @@
#include <stdio.h> #include <stdio.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#include <cstdlib> #include <cstdlib>
#include <stdarg.h> #include <stdarg.h>

View File

@ -2,7 +2,6 @@
#define _NAND_H_ #define _NAND_H_
#include <gccore.h> #include <gccore.h>
#include <malloc.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>

View File

@ -23,7 +23,7 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <malloc.h>
#include <unistd.h> #include <unistd.h>
#include <string.h> #include <string.h>
#include <ogc/mutex.h> #include <ogc/mutex.h>

View File

@ -32,6 +32,7 @@
#include "WiiMovie.hpp" #include "WiiMovie.hpp"
#include "musicplayer.h" #include "musicplayer.h"
#include "gecko.h" #include "gecko.h"
#include "mem2.hpp"
#define SND_BUFFERS 8 #define SND_BUFFERS 8
#define FRAME_BUFFERS 8 #define FRAME_BUFFERS 8
@ -75,7 +76,7 @@ WiiMovie::WiiMovie(const char * filepath)
} }
PlayThreadStack = NULL; PlayThreadStack = NULL;
ThreadStack = (u8 *) memalign(32, 32768); ThreadStack = (u8 *)MEM2_alloc(32768);
if (!ThreadStack) if (!ThreadStack)
return; return;
@ -111,7 +112,7 @@ WiiMovie::~WiiMovie()
} }
if (ThreadStack != NULL) if (ThreadStack != NULL)
{ {
SAFE_FREE(ThreadStack); MEM2_free(ThreadStack);
ThreadStack = NULL; ThreadStack = NULL;
} }
@ -129,7 +130,7 @@ bool WiiMovie::Play(bool loop)
gprintf("Start playing video\n"); gprintf("Start playing video\n");
PlayThreadStack = (u8 *) memalign(32, 32768); PlayThreadStack = (u8 *)MEM2_alloc(32768);
if (PlayThreadStack == NULL) return false; if (PlayThreadStack == NULL) return false;
Playing = true; Playing = true;
@ -156,7 +157,7 @@ void WiiMovie::Stop()
PlayThread = LWP_THREAD_NULL; PlayThread = LWP_THREAD_NULL;
gprintf("Playing thread stopped\n"); gprintf("Playing thread stopped\n");
SAFE_FREE(PlayThreadStack); MEM2_free(PlayThreadStack);
} }
void WiiMovie::SetVolume(int vol) void WiiMovie::SetVolume(int vol)

View File

@ -9,7 +9,6 @@ More info : http://frontier-dev.net
********************************************************************************************/ ********************************************************************************************/
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <malloc.h>
#include "pngu.h" #include "pngu.h"
#include "png.h" #include "png.h"

View File

@ -1,3 +1,6 @@
#include <ogc/machine/processor.h>
#include "DeviceHandler.hpp" #include "DeviceHandler.hpp"
#include "wdvd.h" #include "wdvd.h"
#include "disc.h" #include "disc.h"
@ -6,10 +9,6 @@
#include "alt_ios.h" #include "alt_ios.h"
#include "sys.h" #include "sys.h"
#include "wbfs.h" #include "wbfs.h"
#include <malloc.h>
#include <ogc/machine/processor.h>
#include "gecko.h" #include "gecko.h"
extern "C" {extern u8 currentPartition;} extern "C" {extern u8 currentPartition;}
@ -77,37 +76,18 @@ bool loadIOS(int ios, bool launch_game)
WDVD_Close(); WDVD_Close();
USBStorage_Deinit(); USBStorage_Deinit();
//gprintf("AHBPROT state before reloading: %s\n", HAVE_AHBPROT ? "enabled" : "disabled");
//IOSPATCH_AHBPROT();
/* void *backup = MEM1_alloc(0x200000); // 0x126CA0 bytes were needed last time i checked. But take more just in case.
if (backup != 0)
{
memcpy(backup, &__Arena2Lo, 0x200000);
DCFlushRange(backup, 0x200000);
} */
bool iosOK = IOS_ReloadIOS(ios) == 0; bool iosOK = IOS_ReloadIOS(ios) == 0;
/* if (backup != 0)
{
memcpy(&__Arena2Lo, backup, 0x200000);
DCFlushRange(&__Arena2Lo, 0x200000);
free(backup);
} */
gprintf("%s, Current IOS: %i\n", iosOK ? "OK" : "FAILED!", IOS_GetVersion()); gprintf("%s, Current IOS: %i\n", iosOK ? "OK" : "FAILED!", IOS_GetVersion());
//IOSPATCH_AHBPROT(); if(launch_game)
//gprintf("Current AHBPROT state: %s\n", HAVE_AHBPROT ? "enabled" : "disabled");
if (launch_game)
{ {
DeviceHandler::Instance()->MountAll(); DeviceHandler::Instance()->MountAll();
DeviceHandler::Instance()->Open_WBFS(currentPartition); DeviceHandler::Instance()->Open_WBFS(currentPartition);
Disc_Init(); Disc_Init();
} }
else Open_Inputs(); else
Open_Inputs();
return iosOK; return iosOK;
} }

View File

@ -24,7 +24,6 @@
* distribution. * distribution.
***************************************************************************/ ***************************************************************************/
#include <gctypes.h> #include <gctypes.h>
#include <malloc.h> #include <malloc.h>
#include <cstdio> #include <cstdio>
@ -100,4 +99,4 @@ iosinfo_t *cIOSInfo::GetInfo(u8 ios)
SAFE_FREE(buffer); SAFE_FREE(buffer);
return iosinfo; return iosinfo;
} }

View File

@ -277,7 +277,8 @@ out:
int set_frag_list(u8 *id) int set_frag_list(u8 *id)
{ {
if (frag_list == NULL) return -2; if (frag_list == NULL)
return -2;
// (+1 for header which is same size as fragment) // (+1 for header which is same size as fragment)
int size = sizeof(Fragment) * (frag_list->num + 1); int size = sizeof(Fragment) * (frag_list->num + 1);
@ -289,10 +290,11 @@ int set_frag_list(u8 *id)
int ret = WDVD_SetFragList(wbfsDev, frag_list, size); int ret = WDVD_SetFragList(wbfsDev, frag_list, size);
free(frag_list); MEM2_free(frag_list);
frag_list = NULL; frag_list = NULL;
if (ret) return ret; if(ret)
return ret;
// verify id matches // verify id matches
char discid[32] ATTRIBUTE_ALIGN(32); char discid[32] ATTRIBUTE_ALIGN(32);

View File

@ -1,7 +1,6 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>

View File

@ -3,7 +3,6 @@
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include <ogcsys.h> #include <ogcsys.h>
#include <dirent.h> #include <dirent.h>
#include <sys/types.h> #include <sys/types.h>

View File

@ -1,7 +1,9 @@
#include <gccore.h> #include <gccore.h>
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "mem2.hpp"
#include "utils.h" //SAFE_CLOSE #include "utils.h" //SAFE_CLOSE
#include "gecko.h" #include "gecko.h"
@ -106,12 +108,13 @@ int load_wip_patches(u8 *dir, u8 *gameid)
u32 srcaddress = (u32) strtoul(line+9, NULL, 16); u32 srcaddress = (u32) strtoul(line+9, NULL, 16);
u32 dstaddress = (u32) strtoul(line+18, NULL, 16); u32 dstaddress = (u32) strtoul(line+18, NULL, 16);
if(!CodeList) CodeList = malloc(sizeof(WIP_Code)); if(!CodeList)
CodeList = MEM2_alloc(sizeof(WIP_Code));
WIP_Code * tmp = realloc(CodeList, (CodesCount+1)*sizeof(WIP_Code)); WIP_Code *tmp = MEM2_realloc(CodeList, (CodesCount+1)*sizeof(WIP_Code));
if(!tmp) if(!tmp)
{ {
SAFE_FREE(CodeList); MEM2_free(CodeList);
SAFE_CLOSE(fp); SAFE_CLOSE(fp);
return -1; return -1;
} }

View File

@ -1039,7 +1039,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr)); struct gc_discHdr *gcHeader = (struct gc_discHdr *)MEM2_alloc(sizeof(struct gc_discHdr));
Disc_ReadGCHeader(gcHeader); Disc_ReadGCHeader(gcHeader);
memcpy(hdr->hdr.id, gcHeader->id, 6); memcpy(hdr->hdr.id, gcHeader->id, 6);
SAFE_FREE(gcHeader); MEM2_free(gcHeader);
/* Launching GC Game */ /* Launching GC Game */
_launchGC(hdr, false); _launchGC(hdr, false);
} }
@ -1050,7 +1050,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd)
Disc_ReadHeader(header); Disc_ReadHeader(header);
for (int i = 0;i < 6; i++) for (int i = 0;i < 6; i++)
id[i] = header->id[i]; id[i] = header->id[i];
SAFE_FREE(header); MEM2_free(header);
} }
bool vipatch = m_gcfg2.testOptBool(id, "vipatch", m_cfg.getBool("GENERAL", "vipatch", false)); bool vipatch = m_gcfg2.testOptBool(id, "vipatch", m_cfg.getBool("GENERAL", "vipatch", false));
bool cheat = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("GAMES", "cheat", false)); bool cheat = m_gcfg2.testOptBool(id, "cheat", m_cfg.getBool("GAMES", "cheat", false));

View File

@ -23,9 +23,8 @@
* *
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <malloc.h> #include "mem2.hpp"
#include "BufferCircle.hpp" #include "BufferCircle.hpp"
#include "utils.h"
BufferCircle::BufferCircle() BufferCircle::BufferCircle()
{ {
@ -50,9 +49,9 @@ void BufferCircle::SetBufferBlockSize(int size)
for(int i = 0; i < Size(); i++) for(int i = 0; i < Size(); i++)
{ {
SAFE_FREE(SoundBuffer[i]); MEM1_free(SoundBuffer[i]);
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize)); SoundBuffer[i] = (u8 *)MEM1_memalign(32, BufferBlockSize);
BufferSize[i] = 0; BufferSize[i] = 0;
BufferReady[i] = false; BufferReady[i] = false;
} }
@ -72,7 +71,7 @@ void BufferCircle::Resize(int size)
for(int i = oldSize; i < Size(); i++) for(int i = oldSize; i < Size(); i++)
{ {
if(BufferBlockSize > 0) if(BufferBlockSize > 0)
SoundBuffer[i] = (u8 *) memalign(32, ALIGN32(BufferBlockSize)); SoundBuffer[i] = (u8 *)MEM1_memalign(32, BufferBlockSize);
else else
SoundBuffer[i] = NULL; SoundBuffer[i] = NULL;
BufferSize[i] = 0; BufferSize[i] = 0;
@ -85,7 +84,7 @@ void BufferCircle::RemoveBuffer(int pos)
if(!Valid(pos)) if(!Valid(pos))
return; return;
SAFE_FREE(SoundBuffer[pos]); MEM1_free(SoundBuffer[pos]);
SoundBuffer.erase(SoundBuffer.begin()+pos); SoundBuffer.erase(SoundBuffer.begin()+pos);
BufferSize.erase(BufferSize.begin()+pos); BufferSize.erase(BufferSize.begin()+pos);
@ -106,7 +105,7 @@ void BufferCircle::FreeBuffer()
{ {
for(int i = 0; i < Size(); i++) for(int i = 0; i < Size(); i++)
{ {
SAFE_FREE(SoundBuffer[i]); MEM1_free(SoundBuffer[i]);
BufferSize[i] = 0; BufferSize[i] = 0;
BufferReady[i] = false; BufferReady[i] = false;
} }

View File

@ -27,9 +27,10 @@
#include <string.h> #include <string.h>
#include <limits.h> #include <limits.h>
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include <math.h> #include <math.h>
#include "Mp3Decoder.hpp" #include "Mp3Decoder.hpp"
#include "mem2.hpp"
Mp3Decoder::Mp3Decoder(const char * filepath) Mp3Decoder::Mp3Decoder(const char * filepath)
: SoundDecoder(filepath) : SoundDecoder(filepath)
@ -73,13 +74,13 @@ Mp3Decoder::~Mp3Decoder()
mad_frame_finish(&Frame); mad_frame_finish(&Frame);
mad_stream_finish(&Stream); mad_stream_finish(&Stream);
SAFE_FREE(ReadBuffer); MEM2_free(ReadBuffer);
} }
void Mp3Decoder::OpenFile() void Mp3Decoder::OpenFile()
{ {
GuardPtr = NULL; GuardPtr = NULL;
ReadBuffer = (u8 *) memalign(32, SoundBlockSize*SoundBlocks); ReadBuffer = (u8 *)MEM2_alloc(SoundBlockSize * SoundBlocks);
if(!ReadBuffer) if(!ReadBuffer)
{ {
if(file_fd) if(file_fd)

View File

@ -24,7 +24,6 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include "OggDecoder.hpp" #include "OggDecoder.hpp"
extern "C" int ogg_read(void * punt, int bytes, int blocks, int *f) extern "C" int ogg_read(void * punt, int bytes, int blocks, int *f)

View File

@ -26,7 +26,6 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <gccore.h> #include <gccore.h>
#include <malloc.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include "SoundDecoder.hpp" #include "SoundDecoder.hpp"

View File

@ -24,7 +24,6 @@
* for WiiXplorer 2010 * for WiiXplorer 2010
***************************************************************************/ ***************************************************************************/
#include <unistd.h> #include <unistd.h>
#include <malloc.h>
#include "SoundHandler.hpp" #include "SoundHandler.hpp"
#include "Mp3Decoder.hpp" #include "Mp3Decoder.hpp"
#include "OggDecoder.hpp" #include "OggDecoder.hpp"
@ -33,6 +32,7 @@
#include "BNSDecoder.hpp" #include "BNSDecoder.hpp"
#include "gecko/gecko.h" #include "gecko/gecko.h"
#include "mem2.hpp"
SoundHandler * SoundHandler::instance = NULL; SoundHandler * SoundHandler::instance = NULL;
@ -43,7 +43,7 @@ SoundHandler::SoundHandler()
for(u32 i = 0; i < MAX_DECODERS; ++i) for(u32 i = 0; i < MAX_DECODERS; ++i)
DecoderList[i] = NULL; DecoderList[i] = NULL;
ThreadStack = (u8 *) memalign(32, 32768); ThreadStack = (u8 *)MEM1_memalign(32, 32768);
if(!ThreadStack) if(!ThreadStack)
return; return;
@ -59,7 +59,7 @@ SoundHandler::~SoundHandler()
ThreadSignal(); ThreadSignal();
LWP_JoinThread(SoundThread, NULL); LWP_JoinThread(SoundThread, NULL);
SoundThread = LWP_THREAD_NULL; SoundThread = LWP_THREAD_NULL;
SAFE_FREE(ThreadStack); MEM1_free(ThreadStack);
ClearDecoderList(); ClearDecoderList();
gprintf("SHND: Stopped sound thread\n"); gprintf("SHND: Stopped sound thread\n");

View File

@ -245,7 +245,7 @@ bool GuiSound::LoadSoundEffect(const u8 * snd, u32 len)
u8 * tmpsnd = (u8 *)MEM2_realloc(sound, done+4096); u8 * tmpsnd = (u8 *)MEM2_realloc(sound, done+4096);
if(!tmpsnd) if(!tmpsnd)
{ {
SAFE_FREE(sound); MEM2_free(sound);
return false; return false;
} }
@ -479,8 +479,8 @@ void GuiSound::UncompressSoundbin(const u8 * snd, u32 len, bool isallocated)
if(isallocated) if(isallocated)
{ {
void *p = (void *) snd; void *p = (void *)snd;
SAFE_FREE(p); MEM2_free(p);
} }
allocated = true; allocated = true;

View File

@ -32,7 +32,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <malloc.h>
#include "ZipFile.h" #include "ZipFile.h"
#include "miniunz.h" #include "miniunz.h"