예제 #1
0
/*
 * Function: freeSecureMemory()
 *
 * Description:
 *  Free a single page of secure memory.
 *
 * Inputs:
 *  p    - The first virtual address of the secure memory to free.
 *  size - The amount of secure memory to allocate measured in bytes.
 *
 */
void
freeSecureMemory (void) {
  /*
   * Get the current interrupt context; the arguments will be in it.
   */
  sva_icontext_t * icp = getCPUState()->newCurrentIC;

  /*
   * Get the pointer address and size out of the interrupt context.
   */
  unsigned char * p = (unsigned char *)(icp->rdi);
  uintptr_t size = icp->rsi;

  /*
   * Verify that the memory is within the secure memory portion of the
   * address space.
   */
  uintptr_t pint = (uintptr_t) p;
  if ((SECMEMSTART <= pint) &&
     (pint < SECMEMEND) &&
     (SECMEMSTART <= (pint + size)) &&
     ((pint + size) < SECMEMEND)) {
    /*
     * Zero out the memory.
     */
    memset (p, 0, size);

    /*
     * Get the physical address before unmapping the page.  We do this because
     * unmapping the page may remove page table pages that are no longer
     * needed for mapping secure pages.
     */
    uintptr_t paddr = getPhysicalAddr (p);

    /*
     * Unmap the memory from the secure memory virtual address space.
     */
    unmapSecurePage (get_pagetable(), p);

    /*
     * Release the memory to the operating system.  Note that we must first
     * get the physical address of the data page as that is what the OS is
     * expecting.
     */
    releaseSVAMemory (paddr, size);
  }

  return;
}
예제 #2
0
파일: secmem.c 프로젝트: XiaowanDong/SVA
/*
 * Function: release_frames()
 *
 * Description:
 *  Dequeue and free some number of frames in the frame cache queue.
 */
static inline void
release_frames(void) {
  int i, max_nframe, nframe;
  uintptr_t paddr;

  /*
   * Generate a suitable number not so big that triggers
   * fill_in_frames() when calling frame_dequeue().
   */
  max_nframe = frame_cache_used();
  if (vg_random) {
    /* A random number between 1 and current occupancy of frame cache queue */
    nframe = random() % max_nframe + 1;
  } else {
    /* Minimum of a constant and current occupancy of frame cache queue */
    nframe = max_nframe < MAX_FRAMES_PER_OP ? max_nframe : MAX_FRAMES_PER_OP;
  }

  for (i = 0; i < nframe; ++i) {
    paddr = frame_dequeue();
    releaseSVAMemory(paddr, X86_PAGE_SIZE);
  }
}