int loadfix_prepare(void) { struct MCB far *mcb = MK_FP(umbRegion[0].start, 0); DosSetStrategy(0); while (FP_SEG(mcb) < 0x1000) { if (mcb->sig != 'M' && mcb->sig != 'Z') return err_mcb_chain; if (!mcb->owner) { WORD bl = DosAlloc(mcb->size); if (bl != FP_SEG(mcb) + 1) /* Did we get the block we wanted? */ return err_mcb_chain; block[allocatedBlocks++] = bl; if (bl + mcb->size > 0x1000) /* Don't allocate more than necessary */ DosResize(bl, 0x1000 - bl); } FP_SEG(mcb) += mcb->size + 1; } return OK; }
FileLock * MakeDosFileLock(GEntry *gentry, long mode) { FileLock *flock; if (flock = DosAlloc(sizeof(FileLock))) { flock->fl_Key = (long)gentry; flock->fl_Access = mode; flock->fl_Task = PktPort; flock->fl_Volume = CTOB(Dl); } return(flock); }
BPTR OpenPacket(BPTR lock, ubyte *name, short nameLen, long mode) { FileHandle *fh = DosAlloc(sizeof(FileHandle)); FileLock *flock = BTOC(lock); __aligned char buf[128]; long r; dbprintf(("open: %d '%.*s'\n", mode, nameLen, name)); makebstr(name, nameLen, buf); fh->fh_Port = (MsgPort *)DOS_FALSE; fh->fh_Type = flock->fl_Task; r = DoSyncPacket(flock->fl_Task, mode, CTOB(fh), lock, CTOB(buf), 0); if (r != DOS_TRUE) { DosFree(fh); return(0); } else { dbprintf(("open success fh=%08lx arg1=%08lx\n", fh, fh->fh_Arg1)); return(CTOB(fh)); } }
int loadhigh_prepare(void) { int i; struct UMBREGION far *region = umbRegion; WORD *availBlock; WORD availBlocks = 0; /* Set the UMB link and malloc strategy */ DosSetUMBLink(1); DosSetStrategy(0); if ((availBlock = malloc(256 * sizeof(*availBlock))) == NULL) return err_out_of_memory; /* Call to force DOS to catenate any successive free memory blocks */ DosAlloc(0xffff); /* This loop sets up each UMB region as specified: * If the 'L' switch was present on the command line, any memory * region not listed there will be disabled for the program. * * If a minimal size was specified, the memory region will only be * available to the program if it contains a free memory block of * at least this size. If the 'S' switch was present, the memory * region will be shrunk to the minimal size. * * When the loop finishes, the array 'block' will contain the memory * handles of every free memory block that the program was not * allowed to access. * * The array 'availBlock' will contain the memory handles of every * free memory block that the program can use. */ for (i = 0; i < umbRegions; i++, region++) { struct MCB far *mcb; WORD startBlock = allocatedBlocks; int found_one = 0; for (mcb = MK_FP(region->start, 0); FP_SEG(mcb) < region->end; FP_SEG(mcb) += mcb->size + 1) { if (!mcb->owner) { /* Found a free memory block: allocate it */ WORD bl = DosAlloc(mcb->size); if (bl != FP_SEG(mcb) + 1) /* Did we get the block we wanted? */ return err_mcb_chain; if (region->access) { if (region->minSize == 0xffff || (!optS && found_one) || (!(optS && found_one) && mcb->size >= region->minSize)) { availBlock[availBlocks++] = bl; if (optS) DosResize(bl, region->minSize); else if (allocatedBlocks > startBlock) { memcpy(availBlock + availBlocks, block + startBlock, (allocatedBlocks - startBlock) * sizeof(*block)); availBlocks += allocatedBlocks - startBlock; allocatedBlocks = startBlock; } found_one = 1; continue; } } block[allocatedBlocks++] = bl; /* no access to this block */ } } } /* Now, block[] contains the blocks that can't be used by the * program, and availBlock[] contains the blocks that can be used. * Those blocks will be released. */ for (i = 0; i < availBlocks; i++) DosFree(availBlock[i]); free(availBlock); /* If the program is to be loaded in upper memory, set the malloc * strategy to 'first fit high', otherwise to 'first fit low'. */ DosSetStrategy(upper_flag ? 0x80 : 0); return OK; }