<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html lang="en" style="--code-editor-font: var(--default-mono-font, "GitLab Mono"), JetBrains Mono, Menlo, DejaVu Sans Mono, Liberation Mono, Consolas, Ubuntu Mono, Courier New, andale mono, lucida console, monospace;">
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title>
GitLab
</title>
<style data-premailer="ignore" type="text/css">
a { color: #1068bf; }
</style>
<style>img {
max-width: 100%; height: auto;
}
body {
font-size: .875rem;
}
body {
-webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px;
}
body {
font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji"; font-size: inherit;
}
</style>
</head>
<body style="font-size: inherit; -webkit-text-shadow: rgba(255,255,255,.01) 0 0 1px; font-family: "GitLab Sans",-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans",Ubuntu,Cantarell,"Helvetica Neue",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";">
<div class="content">
<p style="color: #777777;">
<a href="https://gitlab.rtems.org/anshika_gupta">Anshika Gupta</a>
<a href="https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_143587">commented</a>:
</p>
<div class="md" style="position: relative; z-index: 1; color: #3a383f; word-wrap: break-word;">
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial"><a href="https://gitlab.rtems.org/gedare" title="Gedare Bloom" class="gfm gfm-project_member js-user-link" data-user="8" data-original="@gedare" data-container="body" data-placement="top" data-reference-type="user" style="color: #284779; background-color: #cbe2f9; border-radius: .25rem; margin-top: 0; padding: 0 2px;">@gedare</a> <a href="https://gitlab.rtems.org/chris" title="Chris Johns" class="gfm gfm-project_member js-user-link" data-user="3" data-original="@chris" data-container="body" data-placement="top" data-reference-type="user" style="color: #284779; background-color: #cbe2f9; border-radius: .25rem; padding: 0 2px;">@chris</a></p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">Yuh, I could locate that call of <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; margin-top: 0; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">_Heap_Get_Information()</code> and could see that it is calling <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">_Heap_Protection_free_all_delayed_blocks()</code>. I rebuilt the zynqmp_qemu with<code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;"> RTEMS_DEBUG = True</code> which <strong style="font-weight: 600;">enabled the Heap_Protection</strong> and changed my hello.c code such that I initially allocated memory and then freed it and printed the <code style="font-size: 90%; color: #18171d; word-wrap: break-word; background-color: #ececef; border-radius: .25rem; font-weight: inherit; overflow-wrap: break-word; white-space: break-spaces; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: keep-all; padding: 0.125rem 0.25rem;">delayed_free_block_count</code> which was equal to <strong style="font-weight: 600;">5</strong>. After calling malloc_info once, the <strong style="font-weight: 600;">delayed_free_block_count decreased to 0</strong> showing that malloc_info() is freeing the delayed blocks which I think recreates the issue of "malloc_info changes the state of the heap". Could you please confirm whether this counts as recreating the issue and should I start writing the proposal for this project?</p>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">My Output</p>
<div class="gl-relative markdown-code-block js-markdown-code">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">anshikagupta@Anshikas-MacBook-Pro hello % qemu-system-aarch64 \ </span>
<span id="LC2" class="line" lang="plaintext"> -machine xlnx-zcu102 \</span>
<span id="LC3" class="line" lang="plaintext"> -m 1024 \</span>
<span id="LC4" class="line" lang="plaintext"> -nographic \</span>
<span id="LC5" class="line" lang="plaintext"> -no-reboot \</span>
<span id="LC6" class="line" lang="plaintext"> -kernel build/aarch64-rtems7-zynqmp_qemu/hello.exe</span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">HEAP_PROTECTION is ENABLED</span>
<span id="LC9" class="line" lang="plaintext">delayed_free_block_count = 5</span>
<span id="LC10" class="line" lang="plaintext">Stats after first malloc_info</span>
<span id="LC11" class="line" lang="plaintext">Heap Information</span>
<span id="LC12" class="line" lang="plaintext"> Free blocks : 1</span>
<span id="LC13" class="line" lang="plaintext"> Free largest : 1071307712 bytes</span>
<span id="LC14" class="line" lang="plaintext"> Free total : 1071307712 bytes</span>
<span id="LC15" class="line" lang="plaintext"> Used blocks : 14</span>
<span id="LC16" class="line" lang="plaintext"> Used largest : 8384 bytes</span>
<span id="LC17" class="line" lang="plaintext"> Used total : 20640 bytes</span>
<span id="LC18" class="line" lang="plaintext">Heap Statistics</span>
<span id="LC19" class="line" lang="plaintext"> Lifetime alloc : 26160 bytes</span>
<span id="LC20" class="line" lang="plaintext"> Lifetime freed : 5520 bytes</span>
<span id="LC21" class="line" lang="plaintext"> Current free : 1071307712 bytes</span>
<span id="LC22" class="line" lang="plaintext"> Free blocks stat : 1</span>
<span id="LC23" class="line" lang="plaintext"> Used blocks stat : 14</span>
<span id="LC24" class="line" lang="plaintext">delayed_free_block_count = 0</span>
<span id="LC25" class="line" lang="plaintext">Stats after second malloc info</span>
<span id="LC26" class="line" lang="plaintext">Heap Information</span>
<span id="LC27" class="line" lang="plaintext"> Free blocks : 1</span>
<span id="LC28" class="line" lang="plaintext"> Free largest : 1071307712 bytes</span>
<span id="LC29" class="line" lang="plaintext"> Free total : 1071307712 bytes</span>
<span id="LC30" class="line" lang="plaintext"> Used blocks : 14</span>
<span id="LC31" class="line" lang="plaintext"> Used largest : 8384 bytes</span>
<span id="LC32" class="line" lang="plaintext"> Used total : 20640 bytes</span>
<span id="LC33" class="line" lang="plaintext">Heap Statistics</span>
<span id="LC34" class="line" lang="plaintext"> Lifetime alloc : 26160 bytes</span>
<span id="LC35" class="line" lang="plaintext"> Lifetime freed : 5520 bytes</span>
<span id="LC36" class="line" lang="plaintext"> Current free : 1071307712 bytes</span>
<span id="LC37" class="line" lang="plaintext"> Free blocks stat : 1</span>
<span id="LC38" class="line" lang="plaintext"> Used blocks stat : 14</span>
<span id="LC39" class="line" lang="plaintext">delayed_free_block_count = 0</span>
<span id="LC40" class="line" lang="plaintext"></span>
<span id="LC41" class="line" lang="plaintext">[ RTEMS shutdown ]</span>
<span id="LC42" class="line" lang="plaintext">RTEMS version: 7.0.0.e5eaa824202a3760d508012b13b9df45c43e670c</span>
<span id="LC43" class="line" lang="plaintext">RTEMS tools: 15.2.0 20250808 (RTEMS 7, RSB 424f142d70c97ca4e498e58d666d798c9de4a264, Newlib 038afec1)</span>
<span id="LC44" class="line" lang="plaintext">executing thread ID: 0x0a010001</span>
<span id="LC45" class="line" lang="plaintext">executing thread name: UI1 </span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
<p dir="auto" style="color: #3a383f; margin: 0 0 1rem;" align="initial">The hello.c code I used</p>
<div class="gl-relative markdown-code-block js-markdown-code" style="margin-bottom: 0;">
<pre class="code highlight js-syntax-highlight language-plaintext" v-pre="true" style="display: block; font-size: 14px; color: #3a383f; line-height: 1.6em; overflow-x: auto; border-radius: .25rem; position: relative; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; word-break: break-all; word-wrap: break-word; background-color: #fbfafd; margin: 0 0 1rem; padding: 12px; border: 1px solid #dcdcde;"><code style="font-size: inherit; color: inherit; word-wrap: normal; word-break: keep-all; background-color: inherit; border-radius: .25rem; white-space: pre; margin-top: 0; font-family: "GitLab Mono", "JetBrains Mono", "Menlo", "DejaVu Sans Mono", "Liberation Mono", "Consolas", "Ubuntu Mono", "Courier New", "andale mono", "lucida console", monospace; font-variant-ligatures: none; overflow-wrap: normal; padding: unset;"><span id="LC1" class="line" lang="plaintext" style="margin-top: 0;">#include <rtems/confdefs.h></span>
<span id="LC2" class="line" lang="plaintext">#include <rtems/malloc.h></span>
<span id="LC3" class="line" lang="plaintext">#include <rtems/libcsupport.h></span>
<span id="LC4" class="line" lang="plaintext">#include <rtems/score/heapinfo.h></span>
<span id="LC5" class="line" lang="plaintext">#include <rtems/score/heapimpl.h></span>
<span id="LC6" class="line" lang="plaintext"></span>
<span id="LC7" class="line" lang="plaintext"></span>
<span id="LC8" class="line" lang="plaintext">static void print_info(Heap_Information_block *info)</span>
<span id="LC9" class="line" lang="plaintext">{</span>
<span id="LC10" class="line" lang="plaintext"> printf("Heap Information\n");</span>
<span id="LC11" class="line" lang="plaintext"> printf(" Free blocks : %zu\n", info->Free.number);</span>
<span id="LC12" class="line" lang="plaintext"> printf(" Free largest : %zu bytes\n", info->Free.largest);</span>
<span id="LC13" class="line" lang="plaintext"> printf(" Free total : %zu bytes\n", info->Free.total);</span>
<span id="LC14" class="line" lang="plaintext"> printf(" Used blocks : %zu\n", info->Used.number);</span>
<span id="LC15" class="line" lang="plaintext"> printf(" Used largest : %zu bytes\n", info->Used.largest);</span>
<span id="LC16" class="line" lang="plaintext"> printf(" Used total : %zu bytes\n", info->Used.total);</span>
<span id="LC17" class="line" lang="plaintext"> </span>
<span id="LC18" class="line" lang="plaintext"> printf("Heap Statistics\n");</span>
<span id="LC19" class="line" lang="plaintext"> printf(" Lifetime alloc : %llu bytes\n",</span>
<span id="LC20" class="line" lang="plaintext"> info->Stats.lifetime_allocated);</span>
<span id="LC21" class="line" lang="plaintext"> printf(" Lifetime freed : %llu bytes\n",</span>
<span id="LC22" class="line" lang="plaintext"> info->Stats.lifetime_freed);</span>
<span id="LC23" class="line" lang="plaintext"> printf(" Current free : %zu bytes\n",</span>
<span id="LC24" class="line" lang="plaintext"> info->Stats.free_size);</span>
<span id="LC25" class="line" lang="plaintext"> printf(" Free blocks stat : %u\n",</span>
<span id="LC26" class="line" lang="plaintext"> info->Stats.free_blocks);</span>
<span id="LC27" class="line" lang="plaintext"> printf(" Used blocks stat : %u\n",</span>
<span id="LC28" class="line" lang="plaintext"> info->Stats.used_blocks);</span>
<span id="LC29" class="line" lang="plaintext">}</span>
<span id="LC30" class="line" lang="plaintext"></span>
<span id="LC31" class="line" lang="plaintext"> </span>
<span id="LC32" class="line" lang="plaintext">#ifdef HEAP_PROTECTION</span>
<span id="LC33" class="line" lang="plaintext">static void print_delayed()</span>
<span id="LC34" class="line" lang="plaintext">{</span>
<span id="LC35" class="line" lang="plaintext"> printf("delayed_free_block_count = %d\n", RTEMS_Malloc_Heap->Protection.delayed_free_block_count);</span>
<span id="LC36" class="line" lang="plaintext">}</span>
<span id="LC37" class="line" lang="plaintext">#endif</span>
<span id="LC38" class="line" lang="plaintext"></span>
<span id="LC39" class="line" lang="plaintext"> </span>
<span id="LC40" class="line" lang="plaintext">rtems_task Init(rtems_task_argument ignored) </span>
<span id="LC41" class="line" lang="plaintext">{</span>
<span id="LC42" class="line" lang="plaintext">#ifdef HEAP_PROTECTION</span>
<span id="LC43" class="line" lang="plaintext"> printf("HEAP_PROTECTION is ENABLED\n");</span>
<span id="LC44" class="line" lang="plaintext">#else</span>
<span id="LC45" class="line" lang="plaintext"> printf("HEAP_PROTECTION is NOT ENABLED\n");</span>
<span id="LC46" class="line" lang="plaintext">#endif</span>
<span id="LC47" class="line" lang="plaintext"> </span>
<span id="LC48" class="line" lang="plaintext"> void *ptrs[5];</span>
<span id="LC49" class="line" lang="plaintext"> Heap_Information_block before;</span>
<span id="LC50" class="line" lang="plaintext"> Heap_Information_block after;</span>
<span id="LC51" class="line" lang="plaintext"></span>
<span id="LC52" class="line" lang="plaintext"> for (int i = 0; i < 5; i++) {</span>
<span id="LC53" class="line" lang="plaintext"> ptrs[i] = malloc(1024);</span>
<span id="LC54" class="line" lang="plaintext"> }</span>
<span id="LC55" class="line" lang="plaintext"></span>
<span id="LC56" class="line" lang="plaintext"> for (int i = 0; i < 5; i++) {</span>
<span id="LC57" class="line" lang="plaintext"> free(ptrs[i]);</span>
<span id="LC58" class="line" lang="plaintext"> }</span>
<span id="LC59" class="line" lang="plaintext"></span>
<span id="LC60" class="line" lang="plaintext">#ifdef HEAP_PROTECTION</span>
<span id="LC61" class="line" lang="plaintext"> print_delayed();</span>
<span id="LC62" class="line" lang="plaintext">#endif</span>
<span id="LC63" class="line" lang="plaintext"></span>
<span id="LC64" class="line" lang="plaintext"> malloc_info(&before);</span>
<span id="LC65" class="line" lang="plaintext"> printf("Stats after first malloc_info\n");</span>
<span id="LC66" class="line" lang="plaintext"> print_info(&before); </span>
<span id="LC67" class="line" lang="plaintext"> </span>
<span id="LC68" class="line" lang="plaintext">#ifdef HEAP_PROTECTION</span>
<span id="LC69" class="line" lang="plaintext"> print_delayed();</span>
<span id="LC70" class="line" lang="plaintext">#endif</span>
<span id="LC71" class="line" lang="plaintext"></span>
<span id="LC72" class="line" lang="plaintext"> malloc_info(&after);</span>
<span id="LC73" class="line" lang="plaintext"> printf("Stats after second malloc info\n");</span>
<span id="LC74" class="line" lang="plaintext"> print_info(&after);</span>
<span id="LC75" class="line" lang="plaintext"></span>
<span id="LC76" class="line" lang="plaintext">#ifdef HEAP_PROTECTION</span>
<span id="LC77" class="line" lang="plaintext"> print_delayed();</span>
<span id="LC78" class="line" lang="plaintext">#endif</span>
<span id="LC79" class="line" lang="plaintext"></span>
<span id="LC80" class="line" lang="plaintext"> exit(0);</span>
<span id="LC81" class="line" lang="plaintext">}</span></code></pre>
<copy-code></copy-code><insert-code-snippet></insert-code-snippet>
</div>
</div>
</div>
<div class="footer" style="margin-top: 10px;">
<p style="font-size: small; color: #626168;">
—
<br>
<a href="https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_143587">View it on GitLab</a>.
<br>
You're receiving this email because of your account on <a target="_blank" rel="noopener noreferrer" href="https://gitlab.rtems.org">gitlab.rtems.org</a>. <a href="https://gitlab.rtems.org/-/sent_notifications/2-17s0vjppxqn93rthf0856axmf/unsubscribe" target="_blank" rel="noopener noreferrer">Unsubscribe</a> from this thread · <a href="https://gitlab.rtems.org/-/profile/notifications" target="_blank" rel="noopener noreferrer" class="mng-notif-link">Manage all notifications</a> · <a href="https://gitlab.rtems.org/help" target="_blank" rel="noopener noreferrer" class="help-link">Help</a>
<span style="color: transparent; font-size: 0; display: none; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0;">
Notification message regarding https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_143587 at 1772139314
</span>
<script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","action":{"@type":"ViewAction","name":"View Issue","url":"https://gitlab.rtems.org/rtems/programs/gsoc/-/issues/41#note_143587"}}</script>
</p>
</div>
</body>
</html>