예제 #1
0
  /**
   * Initializes page tables for this process so that the executable can be demand-paged.
   *
   * @return <tt>true</tt> if successful.
   */
  protected boolean loadSections() {
    UserKernel.memoryLock.acquire();
    pageTable = new TranslationEntry[numPages];

    for (int vpn = 0; vpn < numPages; vpn++) {
      pageTable[vpn] = new TranslationEntry(vpn, -1, false, false, false, false);
    }

    UserKernel.memoryLock.release();

    // load sections

    for (int s = 0; s < coff.getNumSections(); s++) {
      CoffSection section = coff.getSection(s);

      Lib.debug(
          dbgProcess,
          "\tinitializing " + section.getName() + " section (" + section.getLength() + " pages)");

      for (int i = 0; i < section.getLength(); i++) {
        int vpn = section.getFirstVPN() + i;

        pageTable[vpn].readOnly = section.isReadOnly();
        // section.loadPage(i, pinVirtualPage(vpn, false));
      }
    }

    return true;
  }
예제 #2
0
  /**
   * Allocates memory for this process, and loads the COFF sections into memory. If this returns
   * successfully, the process will definitely be run (this is the last step in process
   * initialization that can fail).
   *
   * @return <tt>true</tt> if the sections were successfully loaded.
   */
  protected boolean loadSections() {
    if (numPages > Machine.processor().getNumPhysPages()) {
      coff.close();
      Lib.debug(dbgProcess, "\tinsufficient physical memory");
      return false;
    }
    pageTable = new TranslationEntry[numPages];

    for (int i = 0; i < numPages; i++) {
      int physPage = UserKernel.allocatePage();
      if (physPage < 0) {
        Lib.debug(dbgProcess, "\tunable to allocate pages; tried " + numPages + ", did " + i);
        for (int j = 0; j < i; j++) {
          if (pageTable[j].valid) {
            UserKernel.deallocatePage(pageTable[j].ppn);
            pageTable[j].valid = false;
          }
        }
        coff.close();
        return false;
      }
      pageTable[i] = new TranslationEntry(i, physPage, true, false, false, false);
    }

    // load sections
    for (int s = 0; s < coff.getNumSections(); s++) {
      CoffSection section = coff.getSection(s);

      Lib.debug(
          dbgProcess,
          "\tinitializing " + section.getName() + " section (" + section.getLength() + " pages)");

      for (int i = 0; i < section.getLength(); i++) {
        int vpn = section.getFirstVPN() + i;

        // for now, just assume virtual addresses=physical addresses
        int ppn = pageTable[vpn].ppn;
        section.loadPage(i, ppn);
        if (section.isReadOnly()) {
          pageTable[vpn].readOnly = true;
        }
      }
    }

    coff.close();
    return true;
  }