  #include "sgx_error.h"
  #include "stddef.h"
  #include "sgx_defs.h"
+@@ -82,6 +83,36 @@
+ */
+ sgx_status_t SGXAPI sgx_read_rand(unsigned char *rand, size_t length_in_bytes);
+ 
++struct MemoryLayout {
++    // Base address of the initialized data section in the current enclave.
++    void *data_base;
++    // Size of the initialized data section in the current enclave.
++    size_t data_size;
++    // Base address of the uninitialized data section in the current enclave.
++    void *bss_base;
++    // Size of the uninitialized data section in the current enclave.
++    size_t bss_size;
++    // Base address of heap in the current enclave.
++    void *heap_base;
++    // size of heap in the current enclave.
++    size_t heap_size;
++    // Base address of the thread data for the current tcs.
++    void *thread_base;
++    // Size of the thread data for the current tcs.
++    size_t thread_size;
++    // Base address of the stack for the current tcs.
++    void *stack_base;
++    // Limit address of the stack for the current tcs.
++    void *stack_limit;
++};
++
++/* sgx_memory_layout()
++ * Parameters:
++ *      memory_layout - Receives the memory layout of the current enclave
++ *      (data/bss/heap) and for current tcs(thread data/stack).
++*/
++void SGXAPI sgx_memory_layout(struct MemoryLayout *memory_layout);
++
+ #ifdef __cplusplus
+ }
+ #endif
 diff -Nur common/inc/sgx_urts.h common/inc/sgx_urts.h
 --- common/inc/sgx_urts.h
 +++ common/inc/sgx_urts.h

diff -Nur sdk/trts/trts.cpp sdk/trts/trts.cpp
--- sdk/trts/trts.cpp
+++ sdk/trts/trts.cpp
@@ -39,6 +39,7 @@
 #include "global_data.h"
 #include "trts_internal.h"
 #include "internal/rts.h"
+#include "rts_config.h"
 
 #ifdef SE_SIM
 #include "t_instructions.h"    /* for `g_global_data_sim' */
diff -Nur sdk/trts/trts_ecall.cpp sdk/trts/trts_ecall.cpp
--- sdk/trts/trts_ecall.cpp
+++ sdk/trts/trts_ecall.cpp

 typedef uint8_t		Elf_Byte;
 
 typedef uint32_t	Elf32_Addr;	/* Unsigned program address */
diff -Nur common/inc/internal/global_data.h common/inc/internal/global_data.h
--- common/inc/internal/global_data.h
+++ common/inc/internal/global_data.h
@@ -50,6 +50,10 @@
     sys_word_t     enclave_size;
     sys_word_t     heap_offset;
     sys_word_t     heap_size;
+    sys_word_t     data_offset;
+    sys_word_t     data_size;
+    sys_word_t     bss_offset;
+    sys_word_t     bss_size;
     sys_word_t     thread_policy;
     thread_data_t  td_template;
     uint8_t        tcs_template[TCS_TEMPLATE_SIZE];
diff -Nur common/inc/internal/metadata.h common/inc/internal/metadata.h
--- common/inc/internal/metadata.h
+++ common/inc/internal/metadata.h
