  #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

  first ecall of the tcs and is prviate in `is_ecall_allowed`.
  `sdk/trts/trts_internal.h` add `uint8_t is_utility` to `struct
  ecall_addr_t`.
* Provide SGXAPI to expose enclave data/bss/stack/heap/thread address and size.
  `common/inc/sgx_trts.h` add a struct `MemoryLayout` that includes
  address and size for data, bss, heap, thread, and stack, also add a
  `sgx_memory_layout(struct MemoryLayout *memory_layout)` API.
  `common/inc/internal/global_data.h` add `sys_word_t` fileds
  `data_offset`, `data_size`, `bss_offset`, `bss_size` to `struct
  global_data_t`.
  `psw/urts/parser/elfparser.cpp` in `update_global_data`, read the
  section of `ELF_DATA` and `ELF_BSS`, save the corresponding address and size
  to `data`.
  `sdk/trts/init_enclave.cpp` add the 4 new fields initialization to
  `g_global_data`.
  `sdk/trts/trts.cpp` include `trts_util.h` header, and provide
  implementation for `sgx_memory_layout` by calling `get_memory_layout`.
  `sdk/trts/trts_util.h` provide declaration of `get_memory_layout`.
  `sdk/trts/trts_util.h` provide implementation for `get_memory_layout` by
  getting the address and size of data/bss/heap from `global_data`, and get
  thread and stack from `thread_data`.


--
diff -Nur common/inc/internal/elfheader/elf_common.h common/inc/internal/elfheader/elf_common.h
