Пример #1
0
void 
ClosePacket(BPTR fhb)
{
    FileHandle *fh = BTOC(fhb);

    DoSyncPacket(fh->fh_Type, ACTION_END, fh->fh_Arg1, 0, 0, 0);
    DosFree(fh);
}
Пример #2
0
void cleanup(void)
{
  int i;

  /* free any memory that was allocated to prevent the program from using it */
  for (i = 0; i < allocatedBlocks; i++)
    DosFree(block[i]);

  /* free dynamic arrays */
  free(umbRegion);
  free(block);
  free(optL);

  /* Restore UMB link state and DOS malloc strategy to their
   * original values. */

  DosSetUMBLink(old_link);
  DosSetStrategy(old_strat);
}
Пример #3
0
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));
    }
}
Пример #4
0
void
FreeDosFileLock(FileLock *flock)
{
    DosFree(flock);
}
Пример #5
0
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;
}