瀏覽代碼

[Pal/Linux-SGX] Keep 8MB of enclave heap for internal PAL objects

This commit adds a hack to keep some heap (currently 8MB) for internal
PAL objects allocated at runtime (recall that LibOS does not keep track
of PAL memory, so without this hack it could overwrite internal PAL
memory). This hack is probabilistic and brittle, but sufficient for now.
Dmitrii Kuvaiskii 5 年之前
父節點
當前提交
50316ff984
共有 1 個文件被更改,包括 11 次插入1 次删除
  1. 11 1
      Pal/src/host/Linux-SGX/db_main.c

+ 11 - 1
Pal/src/host/Linux-SGX/db_main.c

@@ -63,8 +63,18 @@ void _DkGetAvailableUserAddressRange (PAL_PTR * start, PAL_PTR * end,
 {
 {
     *start = (PAL_PTR)pal_sec.heap_min;
     *start = (PAL_PTR)pal_sec.heap_min;
     *end   = (PAL_PTR)get_enclave_heap_top();
     *end   = (PAL_PTR)get_enclave_heap_top();
+
+    /* FIXME: hack to keep some heap for internal PAL objects allocated at runtime (recall that
+     * LibOS does not keep track of PAL memory, so without this hack it could overwrite internal
+     * PAL memory). This hack is probabilistic and brittle. */
+    *end = SATURATED_P_SUB(*end, 2 * 1024 * g_page_size, *start);  /* 8MB reserved for PAL stuff */
+    if (*end <= *start) {
+        SGX_DBG(DBG_E, "Not enough enclave memory, please increase enclave size!\n");
+        ocall_exit(1, /*is_exitgroup=*/true);
+    }
+
     *hole_start = SATURATED_P_SUB(pal_sec.exec_addr, MEMORY_GAP, *start);
     *hole_start = SATURATED_P_SUB(pal_sec.exec_addr, MEMORY_GAP, *start);
-    *hole_end = SATURATED_P_ADD(pal_sec.exec_addr + pal_sec.exec_size, MEMORY_GAP, *end);
+    *hole_end   = SATURATED_P_ADD(pal_sec.exec_addr + pal_sec.exec_size, MEMORY_GAP, *end);
 }
 }
 
 
 PAL_NUM _DkGetProcessId (void)
 PAL_NUM _DkGetProcessId (void)