1
0
Fork 0

check validity of MCBs on resize and free memory functions

Imported-from: https://svn.code.sf.net/p/dosbox/code-0/dosbox/trunk@2252
This commit is contained in:
Sebastian Strohhäcker 2005-07-29 19:57:58 +00:00
parent 206a21502e
commit c6f68033c5

View file

@ -134,8 +134,17 @@ bool DOS_AllocateMemory(Bit16u * segment,Bit16u * blocks) {
bool DOS_ResizeMemory(Bit16u segment,Bit16u * blocks) {
DOS_CompressMemory();
if (segment < MEM_START+1) {
LOG(LOG_DOSMISC,LOG_ERROR)("Program resizes %X, take care",segment);
}
DOS_MCB mcb(segment-1);
if ((mcb.GetType()!=0x4d) && (mcb.GetType()!=0x5a)) {
DOS_SetError(DOSERR_MCB_DESTROYED);
return false;
}
DOS_CompressMemory();
Bit16u total=mcb.GetSize();
DOS_MCB mcb_next(segment+total);
if (*blocks<=total) {
@ -188,12 +197,17 @@ bool DOS_ResizeMemory(Bit16u segment,Bit16u * blocks) {
bool DOS_FreeMemory(Bit16u segment) {
//TODO Check if allowed to free this segment
if ((segment-1) < MEM_START){
if (segment < MEM_START+1) {
LOG(LOG_DOSMISC,LOG_ERROR)("Program tried to free %X ---ERROR",segment);
DOS_SetError(DOSERR_MB_ADDRESS_INVALID);
return false;
}
DOS_MCB mcb(segment-1);
if ((mcb.GetType()!=0x4d) && (mcb.GetType()!=0x5a)) {
DOS_SetError(DOSERR_MB_ADDRESS_INVALID);
return false;
}
mcb.SetPSPSeg(MCB_FREE);
DOS_CompressMemory();
return true;