          switch(ret)
          {
              //If CreateEnclave failed due to power transition, we retry it.
+@@ -788,7 +801,7 @@
+     //set memory protection for segments
+     if(m_parser.set_memory_protection((uint64_t)m_start_addr, is_after_initialization) != true)
+     {
+-        return SGX_ERROR_UNEXPECTED;
++        return SGX_ERROR_MEMORY_MAP_CONFLICT;
+     }
+ 
+     if (is_after_initialization &&
+@@ -859,7 +872,7 @@
+                          (uint64_t)m_start_addr + layout->entry.rva + delta, 
+                          (uint64_t)layout->entry.page_count << SE_PAGE_SHIFT, 
+                           prot);
+-                return SGX_ERROR_UNEXPECTED;
++                return SGX_ERROR_MEMORY_MAP_CONFLICT;
+             }
+         }
+         else
 diff -Nur psw/urts/loader.h psw/urts/loader.h
 --- psw/urts/loader.h
 +++ psw/urts/loader.h

    {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0, 0, 0}, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 0, {{{0, 0, 0, 0, 0, 0, 0}}}};
 uint32_t g_enclave_state __attribute__((section(".nipd"))) = ENCLAVE_INIT_NOT_STARTED;
 
@@ -197,7 +198,7 @@
     else
 #endif
     {

+    }
     ocall_context_t *context = reinterpret_cast<ocall_context_t*>(thread_data->last_sp);
     if(context->ocall_flag != OCALL_FLAG)
     {
@@ -109,7 +114,7 @@
     *addr = const_cast<void *>(g_ecall_table.ecall_table[ordinal].ecall_addr);
     if(!sgx_is_within_enclave(*addr, 0))
     {
-        return SGX_ERROR_UNEXPECTED;
+        return SGX_ERROR_INVALID_STATE;
     }
 
     return SGX_SUCCESS;
@@ -328,7 +333,7 @@
 
     if(0 != GET_TLS_INFO(&__ImageBase, &tls_addr, &tdata_size))
     {
-        return SGX_ERROR_UNEXPECTED;
+        return SGX_ERROR_INVALID_PARAMETER;
     }
     if(tls_addr)
     {
@@ -339,7 +344,7 @@
     return SGX_SUCCESS;
