<div dir="ltr"><div dir="ltr"><div class="gmail_default" style="font-size:small">Hi,</div><div class="gmail_default" style="font-size:small"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Jul 3, 2020 at 11:09 AM pravin <<a href="mailto:pravinraghul@zilogic.com" target="_blank">pravinraghul@zilogic.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail_default" style="font-size:small">...</span><br>
+/*<br>
+ * Test mmap() MAP_GROWSDOWN flag<br>
+ *<br>
+ * We assign the memory region allocated using MAP_GROWSDOWN to a thread,<br>
+ * as a stack, to test the effect of MAP_GROWSDOWN. This is because the<br>
+ * kernel only grows the memory region when the stack pointer, is within<br>
+ * guard page, when the guard page is touched.<br>
+ *<br>
+ * 1. Map an anyonymous memory region of size X, and unmap it.<br>
+ * 2. Split the unmapped memory region into two.<br>
+ * 3. The lower memory region is left unmapped.<br>
+ * 4. The higher memory region is mapped for use as stack, using<br>
+ *    MAP_FIXED | MAP_GROWSDOWN.<br>
+ * 5. The higher memory region is provided as stack to a thread, where<br>
+ *    a recursive function is invoked.<br>
+ * 6. The stack grows beyond the allocated region, into the lower memory area.<br>
+ * 7. If this results in the memory region being extended, into the<br>
+ *    unmapped region, the test is considered to have passed.<br>
+ */<br>
+<br>
+#include <unistd.h><br>
+#include <pthread.h><br>
+#include <sys/mman.h><br>
+#include <sys/wait.h><br>
+#include <sys/types.h><br>
+#include <stdlib.h><br>
+#include <stdbool.h><br>
+<br>
+#include "tst_test.h"<br>
+#include "tst_safe_pthread.h"<br>
+<br>
+#define UNITS(x) ((x) * PTHREAD_STACK_MIN)<br>
+<br>
+static void *stack;<br>
+<br>
+static bool check_stackgrow_up(int *local_var_1)<br>
+{<br>
+       int local_var_2;<br>
+<br>
+       return !(local_var_1 < &local_var_2);<br></blockquote><div><br></div><div><div class="gmail_default" style="font-size:small">Shouldn't local_var_1 less than local_var_2 on a stack grow up arch? why we return the reverse value here?</div><br></div><div><div class="gmail_default" style="font-size:small">And the worth to say that the optimization of GCC will break this rule in the compilation. </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small"> -O2  (ltp default gcc flag)</div><div class="gmail_default" style="font-size:small">mmap18.c:46: INFO: local_var_1 = 0x3ffd177dea0, loval_var_2 = 0x3ffd177dea4<br></div><div class="gmail_default" style="font-size:small"> -O0</div><div class="gmail_default" style="font-size:small">mmap18.c:46: INFO: local_var_1 = 0x3ffc86fe614, loval_var_2 = 0x3ffc86fe56c</div><br></div><div><div class="gmail_default" style="font-size:small">--------</div><br></div><div><div class="gmail_default" style="font-size:small">Apart from that, mmap18 also gets FAIL with s390x platform like:</div><div class="gmail_default" style="font-size:small"><br></div># ./mmap1<span class="gmail_default" style="font-size:small">8</span><br>tst_test.c:1247: INFO: Timeout per run is 0h 05m 00s<br>mmap18.c:46: INFO: local_var_1 = 0x3fff537e5d4, loval_var_2 = 0x3fff537e52c<br>mmap18.c:126: INFO: mem = 0x3ff8dd3a000, stack = 0x3ff8dd5a000<br>mmap18.c:136: FAIL: Child killed by SIGSEGV<br><div class="gmail_default" style="font-size:small"><br></div>Summary:<br>passed   0<br>failed   1<br>skipped  0<br>warnings 0<br><div class="gmail_default" style="font-size:small"></div></div></div><div><br></div>-- <br><div dir="ltr"><div dir="ltr"><div>Regards,<br></div><div>Li Wang<br></div></div></div>
</div>