  
  extern "C" int enter_enclave(int index, void *ms, void *tcs, int cssa) __attribute__((section(".nipx")));
  
-@@ -87,13 +65,25 @@
+@@ -87,13 +66,33 @@
          return error;
      }
  
 -    if(cssa == 0)
++    // Increase the count if an ecall enters an enclave. The ocalls returning to
++    // the enclave shouldn't be counted in, since the ecall that invokes them is
++    // still active.
++    if (index != ECMD_ORET)
++    {
++        increase_ecall_count();
++    }
++
 +    // Check whether the incoming ecall is a user exception. If index is within
 +    // range of the ecall table size, the is_exception field will be true for
 +    // user exceptions.

diff -Nur sdk/trts/trts_util.cpp sdk/trts/trts_util.cpp
--- sdk/trts/trts_util.cpp
+++ sdk/trts/trts_util.cpp
@@ -34,6 +34,7 @@
 #include "global_data.h"
 #include "util.h"
 #include "thread_data.h"
+#include "trts_internal.h"
 
 // No need to check the state of enclave or thread.
 // The functions should be called within an ECALL, so the enclave and thread must be initialized at that time.
@@ -72,6 +73,47 @@
     return heap_size;
 }
 

+ *      (data/bss/heap) and for current tcs(thread data/stack).
+ */
+void SGXAPI sgx_memory_layout(struct SgxMemoryLayout *memory_layout);
+
+/* sgx_get_active_enclave_entries()
+ * Return Value - the number of active ecalls inside the enclave.
+ */
+int SGXAPI sgx_get_active_enclave_entries();
+
 #ifdef __cplusplus
 }
