<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re:Dynamic Memory Allocation in Intel® Software Guard Extensions (Intel® SGX)</title>
    <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1520184#M5903</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Could you share your hardware setup so that we can check the memory available in your hardware? &lt;/P&gt;&lt;P&gt;Sending us the logs would be beneficial as well.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Cordially,&lt;/P&gt;&lt;P&gt;Iffa&lt;/P&gt;&lt;BR /&gt;</description>
    <pubDate>Mon, 04 Sep 2023 07:29:39 GMT</pubDate>
    <dc:creator>Iffa_Intel</dc:creator>
    <dc:date>2023-09-04T07:29:39Z</dc:date>
    <item>
      <title>Dynamic Memory Allocation</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1519602#M5900</link>
      <description>&lt;P&gt;Hey,&lt;BR /&gt;&lt;BR /&gt;I'm trying to call the &lt;A href="https://crypto.stanford.edu/pbc/manual/" target="_self"&gt;PBC library&lt;/A&gt; in SGX Enclave to implement dynamic memory allocation of a 2D array of type element_t in PBC for use by later programs. Unfortunately, encountered some unknown program exits, so I am already struggling with creating the correct code.&lt;BR /&gt;&lt;BR /&gt;I have configured my SGX 2.0 environment after following the instructions &lt;A href="https://github.com/intel/sgx-emm/tree/main" target="_self"&gt;sgx_emm&lt;/A&gt; and tested the sgx_mm API successfully. the configuration file is as follows&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="xml"&gt;&amp;lt;EnclaveConfiguration&amp;gt;
  &amp;lt;ProdID&amp;gt;0&amp;lt;/ProdID&amp;gt;
  &amp;lt;ISVSVN&amp;gt;0&amp;lt;/ISVSVN&amp;gt;
  &amp;lt;TCSNum&amp;gt;3&amp;lt;/TCSNum&amp;gt;
  &amp;lt;TCSMinPool&amp;gt;1&amp;lt;/TCSMinPool&amp;gt;
  &amp;lt;TCSPolicy&amp;gt;1&amp;lt;/TCSPolicy&amp;gt;
  &amp;lt;TCSMaxNum&amp;gt;3&amp;lt;/TCSMaxNum&amp;gt;

  &amp;lt;StackMaxSize&amp;gt;0x1000000&amp;lt;/StackMaxSize&amp;gt;
  &amp;lt;StackMinSize&amp;gt;0x10000&amp;lt;/StackMinSize&amp;gt;
  &amp;lt;HeapMaxSize&amp;gt;0xF0000000&amp;lt;/HeapMaxSize&amp;gt;
  &amp;lt;HeapInitSize&amp;gt;0x9000&amp;lt;/HeapInitSize&amp;gt;
  &amp;lt;HeapMinSize&amp;gt;0x08000&amp;lt;/HeapMinSize&amp;gt;
  &amp;lt;UserRegionSize&amp;gt;0x90000000&amp;lt;/UserRegionSize&amp;gt;
  &amp;lt;DisableDebug&amp;gt;0&amp;lt;/DisableDebug&amp;gt;
  &amp;lt;MiscSelect&amp;gt;1&amp;lt;/MiscSelect&amp;gt;
  &amp;lt;MiscMask&amp;gt;0xFFFFFFFF&amp;lt;/MiscMask&amp;gt;
&amp;lt;/EnclaveConfiguration&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I need to call the PBC crypto library (already compiled lib_tpbc.a in /opt/intel/sgxsdk/lib64) in SGX Enclave to implement the dynamic memory allocation of a 2D array of type element_t, here is my function implementation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="cpp"&gt;//动态分配二维数组
void initialize_sets(int numSets, int sizeSet) 
{
    void *addr = 0;
    //const size_t ALLOC_SIZE = 0x10000000; // 256M
    size_t totalSize = numSets * sizeSet * sizeof(element_t);//1800B
    const size_t alignedSize = calculate_aligned_size(totalSize);

    int ret = sgx_mm_alloc(NULL, alignedSize, SGX_EMA_COMMIT_NOW, NULL, NULL, &amp;amp;addr);
    printf("sgx_mm_alloc = %d\n", ret); //0

    e_sets = (element_t **) (&amp;amp;addr);

    for (int i = 0; i &amp;lt; numSets; i++)
    {
        *(e_sets + i) = (element_t *)(addr + i * sizeSet * sizeof(element_t));
        for (int j = 0; j &amp;lt; sizeSet; j++)
        {
            element_init_Zr(e_sets[i][j], pairing);
            element_random(e_sets[i][j]);
            printf("initilize sets[%d][%d]\n", i, j);
        }
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Execute ./app&amp;nbsp; and the result is as follows:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wendychao_0-1693550682499.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/45185i3007E4DB601845A0/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="wendychao_0-1693550682499.png" alt="wendychao_0-1693550682499.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="wendychao_1-1693550731137.png" style="width: 400px;"&gt;&lt;img src="https://community.intel.com/t5/image/serverpage/image-id/45186i226C2E1C7E1799A9/image-size/medium/is-moderation-mode/true?v=v2&amp;amp;px=400&amp;amp;whitelist-exif-data=Orientation%2CResolution%2COriginalDefaultFinalSize%2CCopyright" role="button" title="wendychao_1-1693550731137.png" alt="wendychao_1-1693550731137.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My problem is that even though I call &lt;A href="https://github.com/intel/sgx-emm/blob/main/design_docs/SGX_EMM.md#sgx_mm_alloc" target="_self"&gt;sgx_mm_alloc&lt;/A&gt; to allocate large enough memory dynamically, it still can't initialize e_sets correctly, e.g., it can allocate 256M of memory successfully, but when numSets =8, sizeSet=15, alignedSize=4KB, the function can only initialize the array up to e_sets[7][6] and exits, and it doesn't report an error, so it's hard for me to locate the error.&lt;LI-EMOJI id="lia_crying-face" title=":crying_face:"&gt;&lt;/LI-EMOJI&gt;&amp;nbsp;I don't know what the problem is, please help me to solve this problem.&lt;BR /&gt;&lt;BR /&gt;Thanks for your help very much!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 06:49:47 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1519602#M5900</guid>
      <dc:creator>wendychao</dc:creator>
      <dc:date>2023-09-01T06:49:47Z</dc:date>
    </item>
    <item>
      <title>Re:Dynamic Memory Allocation</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1520184#M5903</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Could you share your hardware setup so that we can check the memory available in your hardware? &lt;/P&gt;&lt;P&gt;Sending us the logs would be beneficial as well.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Cordially,&lt;/P&gt;&lt;P&gt;Iffa&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 04 Sep 2023 07:29:39 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1520184#M5903</guid>
      <dc:creator>Iffa_Intel</dc:creator>
      <dc:date>2023-09-04T07:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Re:Dynamic Memory Allocation</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1520477#M5905</link>
      <description>&lt;P&gt;hi Iffa,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response.&lt;BR /&gt;&lt;BR /&gt;Here's some of my hardware setup info.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;root@ecsgx:~# lshw -short
H/W path      Device     Class          Description
===================================================
                         system         Alibaba Cloud ECS
/0                       bus            Motherboard
/0/400                   processor      Intel(R) Xeon(R) Platinum 8369B CPU @ 2.70GHz
/0/1000                  memory         4GiB System Memory
/0/1000/0                memory         4GiB DIMM RAM
/0/0                     memory         96KiB BIOS
/0/100                   bridge         440FX - 82441FX PMC [Natoma]
/0/100/1                 bridge         82371SB PIIX3 ISA [Natoma/Triton II]
/0/100/1.3               bridge         82371AB/EB/MB PIIX4 ACPI
/0/100/2                 display        GD 5446
/0/100/3                 communication  Virtio console
/0/100/3/0               generic        Virtual I/O device
/0/100/4                 storage        Virtio block device
/0/100/4/0    /dev/vda   disk           42GB Virtual I/O device
/0/100/4/0/1  /dev/vda1  volume         1023KiB BIOS Boot partition
/0/100/4/0/2  /dev/vda2  volume         190MiB Windows FAT volume
/0/100/4/0/3  /dev/vda3  volume         39GiB EXT4 volume
/0/100/5                 network        Virtio network device
/0/100/5/0    eth0       network        Ethernet interface
/0/100/6                 generic        Virtio memory balloon
/0/100/6/0               generic        Virtual I/O device
/0/1                     system         PnP device PNP0b00
/0/2                     input          PnP device PNP0303
/0/3                     input          PnP device PNP0f13
/0/4                     storage        PnP device PNP0700
/0/5                     communication  PnP device PNP0501&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="bash"&gt;root@ecsgx:~# free -m
              总计         已用        空闲      共享    缓冲/缓存    可用
内存：        3746        2439         872          85         434         993
交换：           0           0           0
root@ecsgx:~# cat /proc/meminfo
MemTotal:        3836180 kB
MemFree:          888676 kB
MemAvailable:    1013912 kB
Buffers:           12172 kB
Cached:           391224 kB
SwapCached:            0 kB
Active:           184008 kB
Inactive:        2477356 kB
Active(anon):       4984 kB
Inactive(anon):  2349032 kB
Active(file):     179024 kB
Inactive(file):   128324 kB
Unevictable:       21336 kB
Mlocked:           18504 kB
SwapTotal:             0 kB
SwapFree:              0 kB
Zswap:                 0 kB
Zswapped:              0 kB
Dirty:               444 kB
Writeback:             0 kB
AnonPages:       2279308 kB
Mapped:           320328 kB
Shmem:             87864 kB
KReclaimable:      42720 kB
Slab:             121240 kB
SReclaimable:      42720 kB
SUnreclaim:        78520 kB
KernelStack:       15364 kB
PageTables:        35768 kB
SecPageTables:         0 kB
NFS_Unstable:          0 kB
Bounce:                0 kB
WritebackTmp:          0 kB
CommitLimit:     1918088 kB
Committed_AS:    9041968 kB
VmallocTotal:   34359738367 kB
VmallocUsed:       66472 kB
VmallocChunk:          0 kB
Percpu:             1824 kB
HardwareCorrupted:     0 kB
AnonHugePages:         0 kB
ShmemHugePages:        0 kB
ShmemPmdMapped:        0 kB
FileHugePages:         0 kB
FilePmdMapped:         0 kB
HugePages_Total:       0
HugePages_Free:        0
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
Hugetlb:               0 kB
DirectMap4k:      140568 kB
DirectMap2M:     2838528 kB
DirectMap1G:     1048576 kB&lt;/LI-CODE&gt;&lt;P&gt;I am looking forward to your reply, thanks again!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards，&lt;/P&gt;&lt;P&gt;wendychao&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2023 00:06:32 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1520477#M5905</guid>
      <dc:creator>wendychao</dc:creator>
      <dc:date>2023-09-05T00:06:32Z</dc:date>
    </item>
    <item>
      <title>Re:Dynamic Memory Allocation</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1523938#M5928</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;We require you to create a debug enclave and use gdb to set breakpoints in the enclave and verify everything is as it should be stepping through.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;This is the best way to find the source of your issue &amp;amp; debug it.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Cordially,&lt;/P&gt;&lt;P&gt;Iffa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Fri, 15 Sep 2023 00:23:41 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1523938#M5928</guid>
      <dc:creator>Iffa_Intel</dc:creator>
      <dc:date>2023-09-15T00:23:41Z</dc:date>
    </item>
    <item>
      <title>Re:Dynamic Memory Allocation</title>
      <link>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1529265#M5951</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri, sans-serif; font-size: 11pt;"&gt;Thank you for your question.&amp;nbsp;If you need any additional information from Intel, please submit a new question as Intel is no longer monitoring this thread.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri, sans-serif; font-size: 11pt;"&gt;Cordially,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: Calibri, sans-serif; font-size: 11pt;"&gt;Iffa&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 02 Oct 2023 00:30:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-Software-Guard-Extensions/Dynamic-Memory-Allocation/m-p/1529265#M5951</guid>
      <dc:creator>Iffa_Intel</dc:creator>
      <dc:date>2023-10-02T00:30:58Z</dc:date>
    </item>
  </channel>
</rss>

