jingfei195887 opened a new pull request, #22544:
URL: https://github.com/apache/nuttx/pull/22544

   ## Summary
   
   Kernel builds wrap `syslog()` in a function-like macro. Conditional 
directives
   inside its argument list have undefined behavior and fail strict 
preprocessing.
   Select the optional backtrace and sequence-number fields outside the 
diagnostic
   calls in the FD table, memory pool, default heap and TLSF heap 
implementations.
   
   ## Impact
   
   This fixes compiler portability of diagnostic code. Public APIs, allocation
   behavior, configuration options and printed fields are unchanged. There are 
no
   board, build-system or documentation-interface changes.
   
   ## Testing
   
   Linux x86-64, GCC 13 and Clang 21.1.8. The strict Clang syntax matrix 
compiles
   all four actual translation units with `-Werror=embedded-directive` and the
   kernel `syslog` macro enabled. It combines MM backtrace depths -1/0/4,
   sequence numbers off/on where supported, and FD backtrace depths 0/4.
   Of 40 baseline compilations, 34 fail with the embedded-directive diagnostic;
   all 40 compilations on this branch pass.
   These are ten generated-header variants, not ten complete image builds.
   
   Paired optimized `sim:nsh` builds use identical configurations and the same
   fixture for the default heap and TLSF. FD, heap, pool and free-dump text is
   identical after replacing addresses. The changed diagnostic functions' 
generated
   machine-code sections are byte-for-byte identical. Both builds have a
   **0 / 0 / 0 byte text/data/bss difference**.
   
   The default-heap fixture verifies that the opened descriptor and allocated
   heap/pool addresses appear. TLSF's existing heap-dump dispatch omits the 
requested
   heap allocation on both revisions, so that runtime check fails on both and is
   not claimed as coverage of its allocation formatter. Its generated formatter
   code is identical; its strict syntax checks pass after this change.
   
   Protected `qemu-armv7r:pnsh` and kernel `qemu-armv8a:knsh` builds include 
the FD
   and MM diagnostic symbols. The first kernel test configuration omitted
   `FRAME_POINTER`, which the ARM64 backtrace implementation requires, and 
failed
   to link `up_backtrace`. Enabling that test option fixes the build without any
   additional source changes. Local Make, CMake and OSTest validation passes.
   No native MSVC, hardware, protected/kernel runtime or SMP test was performed.
   This is a compiler regression; the runtime fixture is attached rather than
   adding a permanent application test for unchanged output.
   
   Baseline: `f9d3eb13c3f412426a2658227f2b332e21e3a526`; tested head: 
`194f8345c02880ef290fc25721df94e40083466e`.
   
   For a strict preprocessor check, generate the sim configuration headers with
   `make context` after enabling the options below, then run this from the NuttX
   source root with Clang 21 and its matching resource directory:
   
   ```sh
   clang -E -Werror=embedded-directive -D__KERNEL__ \
     -Iinclude -Isched -Ifs -Imm -Imm/tlsf -Iarch/sim/src \
     fs/inode/fs_files.c -o /dev/null
   ```
   
   <details>
   <summary>Strict syntax matrix results</summary>
   
   ```json
   {
     "baseline": {
       "translation_units": 40,
       "pass": 6,
       "fail": 34,
       "embedded_errors": 141
     },
     "branch": {
       "translation_units": 40,
       "pass": 40,
       "fail": 0,
       "embedded_errors": 0
     }
   }
   ```
   </details>
   
   <details>
   <summary>Baseline example: actual FD source diagnostics</summary>
   
   ```text
   fs/inode/fs_files.c:478:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     478 | #if CONFIG_FS_BACKTRACE > 0
         |  ^
   fs/inode/fs_files.c:480:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     480 | #endif
         |  ^
   fs/inode/fs_files.c:518:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     518 | #if CONFIG_FS_BACKTRACE > 0
         |  ^
   fs/inode/fs_files.c:520:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     520 | #endif
         |  ^
   fs/inode/fs_files.c:524:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     524 | #if CONFIG_FS_BACKTRACE > 0
         |  ^
   fs/inode/fs_files.c:526:2: error: embedding a directive within macro 
arguments has undefined behavior [-Werror,-Wembedded-directive]
     526 | #endif
         |  ^
   6 errors generated.
   ```
   </details>
   
   <details>
   <summary>Branch strict preprocessing results</summary>
   
   ```json
   [
     {
       "file": "fs/inode/fs_files.c",
       "rc": 0,
       "embedded_diagnostics": 0,
       "other_error": false,
       "command": [
         
"/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21",
         "-E",
         "-Werror=embedded-directive",
         "-D__KERNEL__",
         
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
         "-Iinclude",
         "-Isched",
         "-Ifs",
         "-Imm",
         "-Imm/tlsf",
         "-Iarch/sim/src",
         "fs/inode/fs_files.c",
         "-o",
         "/dev/null"
       ]
     },
     {
       "file": "mm/mempool/mempool.c",
       "rc": 0,
       "embedded_diagnostics": 0,
       "other_error": false,
       "command": [
         
"/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21",
         "-E",
         "-Werror=embedded-directive",
         "-D__KERNEL__",
         
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
         "-Iinclude",
         "-Isched",
         "-Ifs",
         "-Imm",
         "-Imm/tlsf",
         "-Iarch/sim/src",
         "mm/mempool/mempool.c",
         "-o",
         "/dev/null"
       ]
     },
     {
       "file": "mm/mm_heap/mm_memdump.c",
       "rc": 0,
       "embedded_diagnostics": 0,
       "other_error": false,
       "command": [
         
"/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21",
         "-E",
         "-Werror=embedded-directive",
         "-D__KERNEL__",
         
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
         "-Iinclude",
         "-Isched",
         "-Ifs",
         "-Imm",
         "-Imm/tlsf",
         "-Iarch/sim/src",
         "mm/mm_heap/mm_memdump.c",
         "-o",
         "/dev/null"
       ]
     }
   ]
   ```
   </details>
   
   <details>
   <summary>Local validation</summary>
   
   ```text
   target   : nuttx
   branch   : fs/syslog-arguments
   head     : 194f8345c02880ef290fc25721df94e40083466e
   subject  : mm fs sim: move #ifdef out of syslog() argument lists
   commits  : 1
   base     : f9d3eb13c3 (merge-base with upstream/master)
   behind   : 0 commits of upstream/master
   nuttx    : 194f8345c0
   apps     : 0a37af9866
   options  : CONFIG_SCHED_DUMP_FDLIST CONFIG_SCHED_BACKTRACE 
CONFIG_FS_BACKTRACE=4 CONFIG_MM_BACKTRACE=4 CONFIG_MM_BACKTRACE_DEFAULT 
CONFIG_EXAMPLES_LOGPORTCHECK
   host     : Linux x86_64, gcc (Ubuntu 13.1.0-8ubuntu1~22.04) 13.1.0
   checkpatch: rc=0
   signer   : jingfei <[email protected]>
   commits missing your Signed-off-by: 0
   make build: rc=0
   warnings in changed files: 0
   ostest: Exiting with status 0
   cmake reconfigure: rc=0
   cmake build: rc=0
   worktree tracked changes after: 0
   RESULT: PASS
   ```
   </details>
   
   <details>
   <summary>Protected/kernel build results</summary>
   
   ```text
   qemu-armv7r:pnsh build PASS; MM library diagnostic symbols verified
   qemu-armv8a:knsh build PASS; FRAME_POINTER=y; FD/MM diagnostics and 
up_backtrace verified
   ```
   </details>
   
   <details>
   <summary>Size and generated-code comparison</summary>
   
   ```json
   [
     {
       "baseline": "baseline-mm-v2",
       "branch": "branch-mm",
       "config_identical": true,
       "diagnostic_machine_code_identical": {
         "fs_files.fdlist_dump": 463,
         "mempool.mempool_memdump_callback": 275,
         "mm_memdump.memdump_allocnode": 139,
         "mm_memdump.mm_memdump": 715
       },
       "runtime_sections_identical_after_address_normalization": true,
       "text_data_bss_delta": [
         0,
         0,
         0
       ],
       "heap_allocation_row_observed": true
     },
     {
       "baseline": "baseline-tlsf-v2",
       "branch": "branch-tlsf",
       "config_identical": true,
       "diagnostic_machine_code_identical": {
         "fs_files.fdlist_dump": 463,
         "mempool.mempool_memdump_callback": 275,
         "mm_tlsf.memdump_allocnode": 127
       },
       "runtime_sections_identical_after_address_normalization": true,
       "text_data_bss_delta": [
         0,
         0,
         0
       ],
       "heap_allocation_row_observed": false
     }
   ]
   ```
   </details>
   
   <details>
   <summary>baseline-mm-v2 runtime log</summary>
   
   ```text
   LOGPORT STRICT [{"file": "fs/inode/fs_files.c", "rc": 1, 
"embedded_diagnostics": 6, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"fs/inode/fs_files.c", "-o", "/dev/null"]}, {"file": "mm/mempool/mempool.c", 
"rc": 1, "embedded_diagnostics": 4, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mempool/mempool.c", "-o", "/dev/null"]}, {"file": 
"mm/mm_heap/mm_memdump.c", "rc": 1, "embedded_diagnostics": 8, "other_error": 
false, "command": ["/home/mi
 /dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", "-E", 
"-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mm_heap/mm_memdump.c", "-o", "/dev/null"]}]
   nsh> logportcheck
   LOGPORT FD BEGIN fd=3 path=/dev/null
   PID FD  FLAGS   TYPE POS       PATH           BACKTRACE
   8   0   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   1   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   2   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   3   2       1    0         /dev/null      0x000000004001637e 
0x00000000400183ff 0x0000000040018753 0x0000000040035c46 
   LOGPORT FD END
   LOGPORT HEAP BEGIN expected=0x400902d0
   Memdump task ALL
      PID        Size Overhead    Sequence            Address Backtrace
        8          64       64         147         0x40090290 
0x000000004000f64a 0x0000000040035c7b 0x000000004000b541 0x0000000040003d3e 
        8         144       64         151         0x400902d0 
0x0000000040035cba 0x000000004000b541 0x0000000040003d3e 
        8          64       64         148         0x4009fcd0 
0x000000004000f64a 0x0000000040035c7b 0x000000004000b541 0x0000000040003d3e 
     Total Blks  Total Size
              3         272
   LOGPORT HEAP END
   LOGPORT POOL BEGIN expected=0x7df056b25a80
        8         112       48         150     0x7df056b25a80 
   LOGPORT POOL END
   LOGPORT FREE BEGIN
   Dump all free memory node info
      PID        Size Overhead    Sequence            Address Backtrace
          64000       56         0x400902d0
     Total Blks  Total Size
              1       64000
            112       48     0x7df056b25a80
            112       48     0x7df056b25a10
            112       48     0x7df056b259a0
   LOGPORT FREE END
   LOGPORT RESULT PASS
   nsh> echo LOGPORT STATUS $?
   LOGPORT STATUS 0
   nsh> poweroff
   ```
   </details>
   
   <details>
   <summary>branch-mm runtime log</summary>
   
   ```text
   LOGPORT STRICT [{"file": "fs/inode/fs_files.c", "rc": 0, 
"embedded_diagnostics": 0, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"fs/inode/fs_files.c", "-o", "/dev/null"]}, {"file": "mm/mempool/mempool.c", 
"rc": 0, "embedded_diagnostics": 0, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mempool/mempool.c", "-o", "/dev/null"]}, {"file": 
"mm/mm_heap/mm_memdump.c", "rc": 0, "embedded_diagnostics": 0, "other_error": 
false, "command": ["/home/mi
 /dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", "-E", 
"-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mm_heap/mm_memdump.c", "-o", "/dev/null"]}]
   nsh> logportcheck
   LOGPORT FD BEGIN fd=3 path=/dev/null
   PID FD  FLAGS   TYPE POS       PATH           BACKTRACE
   8   0   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   1   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   2   2       1    0         /dev/console   0x0000000040015aa6 
0x000000004001652a 0x0000000040005406 0x00000000400034da 
   8   3   2       1    0         /dev/null      0x000000004001637e 
0x00000000400183ff 0x0000000040018753 0x0000000040035c46 
   LOGPORT FD END
   LOGPORT HEAP BEGIN expected=0x400902d0
   Memdump task ALL
      PID        Size Overhead    Sequence            Address Backtrace
        8          64       64         147         0x40090290 
0x000000004000f64a 0x0000000040035c7b 0x000000004000b541 0x0000000040003d3e 
        8         144       64         151         0x400902d0 
0x0000000040035cba 0x000000004000b541 0x0000000040003d3e 
        8          64       64         148         0x4009fcd0 
0x000000004000f64a 0x0000000040035c7b 0x000000004000b541 0x0000000040003d3e 
     Total Blks  Total Size
              3         272
   LOGPORT HEAP END
   LOGPORT POOL BEGIN expected=0x789083325a80
        8         112       48         150     0x789083325a80 
   LOGPORT POOL END
   LOGPORT FREE BEGIN
   Dump all free memory node info
      PID        Size Overhead    Sequence            Address Backtrace
          64000       56         0x400902d0
     Total Blks  Total Size
              1       64000
            112       48     0x789083325a80
            112       48     0x789083325a10
            112       48     0x7890833259a0
   LOGPORT FREE END
   LOGPORT RESULT PASS
   nsh> echo LOGPORT STATUS $?
   LOGPORT STATUS 0
   nsh> poweroff
   ```
   </details>
   
   <details>
   <summary>baseline-tlsf-v2 runtime log</summary>
   
   ```text
   LOGPORT STRICT [{"file": "fs/inode/fs_files.c", "rc": 1, 
"embedded_diagnostics": 6, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"fs/inode/fs_files.c", "-o", "/dev/null"]}, {"file": "mm/mempool/mempool.c", 
"rc": 1, "embedded_diagnostics": 4, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mempool/mempool.c", "-o", "/dev/null"]}, {"file": "mm/tlsf/mm_tlsf.c", 
"rc": 1, "embedded_diagnostics": 4, "other_error": false, "command": 
["/home/mi/dev-s
 ystem_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", "-E", 
"-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/tlsf/mm_tlsf.c", "-o", "/dev/null"]}]
   nsh> logportcheck
   LOGPORT FD BEGIN fd=3 path=/dev/null
   PID FD  FLAGS   TYPE POS       PATH           BACKTRACE
   8   0   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   1   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   2   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   3   2       1    0         /dev/null      0x0000000040015c8e 
0x0000000040017d0f 0x0000000040018063 0x0000000040035536 
   LOGPORT FD END
   LOGPORT HEAP BEGIN expected=0x4008f6e8
   Memdump task ALL
      PID        Size    Sequence            Address Backtrace
     Total Blks  Total Size
              0           0
   LOGPORT HEAP END
   LOGPORT POOL BEGIN expected=0x7b20f1f26488
        8         112       48         146     0x7b20f1f26488 
   LOGPORT POOL END
   LOGPORT FREE BEGIN
   Dump all free memory node info
      PID        Size    Sequence            Address Backtrace
     Total Blks  Total Size
              0           0
            112       48     0x7b20f1f26488
            112       48     0x7b20f1f26418
            112       48     0x7b20f1f263a8
   LOGPORT FREE END
   LOGPORT RESULT PASS
   nsh> echo LOGPORT STATUS $?
   LOGPORT STATUS 0
   nsh> poweroff
   ```
   </details>
   
   <details>
   <summary>branch-tlsf runtime log</summary>
   
   ```text
   LOGPORT STRICT [{"file": "fs/inode/fs_files.c", "rc": 0, 
"embedded_diagnostics": 0, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"fs/inode/fs_files.c", "-o", "/dev/null"]}, {"file": "mm/mempool/mempool.c", 
"rc": 0, "embedded_diagnostics": 0, "other_error": false, "command": 
["/home/mi/dev-system_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", 
"-E", "-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/mempool/mempool.c", "-o", "/dev/null"]}, {"file": "mm/tlsf/mm_tlsf.c", 
"rc": 0, "embedded_diagnostics": 0, "other_error": false, "command": 
["/home/mi/dev-s
 ystem_car/prebuilts/clang/clang/linux-x86_64/bin/clang-21", "-E", 
"-Werror=embedded-directive", "-D__KERNEL__", 
"-resource-dir=/home/mi/dev-system_car/prebuilts/clang/arm/linux-x86_64/lib/clang/21",
 "-Iinclude", "-Isched", "-Ifs", "-Imm", "-Imm/tlsf", "-Iarch/sim/src", 
"mm/tlsf/mm_tlsf.c", "-o", "/dev/null"]}]
   nsh> logportcheck
   LOGPORT FD BEGIN fd=3 path=/dev/null
   PID FD  FLAGS   TYPE POS       PATH           BACKTRACE
   8   0   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   1   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   2   2       1    0         /dev/console   0x00000000400153b6 
0x0000000040015e3a 0x0000000040005406 0x00000000400034da 
   8   3   2       1    0         /dev/null      0x0000000040015c8e 
0x0000000040017d0f 0x0000000040018063 0x0000000040035536 
   LOGPORT FD END
   LOGPORT HEAP BEGIN expected=0x4008f6e8
   Memdump task ALL
      PID        Size    Sequence            Address Backtrace
     Total Blks  Total Size
              0           0
   LOGPORT HEAP END
   LOGPORT POOL BEGIN expected=0x740f62926488
        8         112       48         146     0x740f62926488 
   LOGPORT POOL END
   LOGPORT FREE BEGIN
   Dump all free memory node info
      PID        Size    Sequence            Address Backtrace
     Total Blks  Total Size
              0           0
            112       48     0x740f62926488
            112       48     0x740f62926418
            112       48     0x740f629263a8
   LOGPORT FREE END
   LOGPORT RESULT PASS
   nsh> echo LOGPORT STATUS $?
   LOGPORT STATUS 0
   nsh> poweroff
   ```
   </details>
   
   The fixture belongs in `apps/examples/logportcheck`; enable 
`EXAMPLES_LOGPORTCHECK`, `SCHED_DUMP_FDLIST` and the selected backtrace 
options, then run `logportcheck` in NSH.
   
   <details>
   <summary>Fixture: Kconfig</summary>
   
   ```text
   config EXAMPLES_LOGPORTCHECK
        tristate "Diagnostic log portability check"
        default n
   ```
   </details>
   
   <details>
   <summary>Fixture: Make.defs</summary>
   
   ```make
   ifneq ($(CONFIG_EXAMPLES_LOGPORTCHECK),)
   CONFIGURED_APPS += $(APPDIR)/examples/logportcheck
   endif
   ```
   </details>
   
   <details>
   <summary>Fixture: Makefile</summary>
   
   ```make
   include $(APPDIR)/Make.defs
   PROGNAME = logportcheck
   PRIORITY = SCHED_PRIORITY_DEFAULT
   STACKSIZE = 8192
   MODULE = $(CONFIG_EXAMPLES_LOGPORTCHECK)
   MAINSRC = logportcheck_main.c
   include $(APPDIR)/Application.mk
   ```
   </details>
   
   <details>
   <summary>Fixture: CMakeLists.txt</summary>
   
   ```cmake
   if(CONFIG_EXAMPLES_LOGPORTCHECK)
     nuttx_add_application(NAME logportcheck STACKSIZE 8192 SRCS 
logportcheck_main.c)
   endif()
   ```
   </details>
   
   <details>
   <summary>Fixture: logportcheck_main.c</summary>
   
   ```c
   /****************************************************************************
    * apps/examples/logportcheck/logportcheck_main.c
    *
    * SPDX-License-Identifier: Apache-2.0
    *
    
****************************************************************************/
   
   /****************************************************************************
    * Included Files
    
****************************************************************************/
   
   #include <nuttx/config.h>
   
   #include <fcntl.h>
   #include <limits.h>
   #include <stdio.h>
   #include <string.h>
   #include <syslog.h>
   #include <unistd.h>
   
   #include <nuttx/fs/fs.h>
   #include <nuttx/mm/mm.h>
   #include <nuttx/mm/mempool.h>
   #include <nuttx/sched.h>
   
   /****************************************************************************
    * Private Data
    
****************************************************************************/
   
   static char g_storage[65536] aligned_data(MM_ALIGN);
   
   /****************************************************************************
    * Public Functions
    
****************************************************************************/
   
   int main(int argc, FAR char *argv[])
   {
     struct mm_memdump_s request =
       {
         .pid = PID_MM_ALLOC,
   #if CONFIG_MM_BACKTRACE >= 0
         .seqmax = ULONG_MAX,
   #endif
       };
   
     struct mempool_s pool =
       {
         .name = "logport",
         .blocksize = 64,
         .initialsize = 3 * MEMPOOL_REALBLOCKSIZE(64) + MEMPOOL_HEADER_SIZE,
         .expandsize = 3 * MEMPOOL_REALBLOCKSIZE(64) + MEMPOOL_HEADER_SIZE,
       };
   
     FAR struct mm_heap_s *heap;
     FAR struct tcb_s *tcb;
     FAR void *block;
     FAR void *allocation;
     int fd;
   
     setlogmask(LOG_UPTO(LOG_INFO));
     fd = open("/dev/null", O_RDWR);
     heap = mm_initialize("logport", g_storage, sizeof(g_storage));
     if (fd < 0 || heap == NULL || mempool_init(&pool) < 0)
       {
         printf("LOGPORT FAIL setup\n");
         return 1;
       }
   
     block = mempool_allocate(&pool, 0);
     allocation = mm_malloc(heap, 80);
     if (block == NULL || allocation == NULL)
       {
         printf("LOGPORT FAIL allocation\n");
         return 1;
       }
   
     memset(block, 0x35, 64);
     memset(allocation, 0x56, 80);
     tcb = nxsched_get_tcb(gettid());
     syslog(LOG_INFO, "LOGPORT FD BEGIN fd=%d path=/dev/null\n", fd);
     fdlist_dump(&tcb->group->tg_fdlist);
     syslog(LOG_INFO, "LOGPORT FD END\n");
     syslog(LOG_INFO, "LOGPORT HEAP BEGIN expected=%p\n", allocation);
     mm_memdump(heap, &request);
     syslog(LOG_INFO, "LOGPORT HEAP END\n");
     syslog(LOG_INFO, "LOGPORT POOL BEGIN expected=%p\n", block);
     mempool_memdump(&pool, &request);
     syslog(LOG_INFO, "LOGPORT POOL END\n");
     if (((FAR unsigned char *)block)[0] != 0x35 ||
         ((FAR unsigned char *)allocation)[0] != 0x56)
       {
         printf("LOGPORT FAIL contents\n");
         return 1;
       }
   
     mm_free(heap, allocation);
     mempool_release(&pool, block);
     request.pid = PID_MM_FREE;
     syslog(LOG_INFO, "LOGPORT FREE BEGIN\n");
     mm_memdump(heap, &request);
     mempool_memdump(&pool, &request);
     syslog(LOG_INFO, "LOGPORT FREE END\n");
     if (mempool_deinit(&pool) < 0 || close(fd) < 0)
       {
         printf("LOGPORT FAIL cleanup\n");
         return 1;
       }
   
     mm_uninitialize(heap);
     printf("LOGPORT RESULT PASS\n");
     return 0;
   }
   ```
   </details>
   
   ## PR verification Self-Check
   
   - [x] This PR introduces only one functional change.
   - [x] I have updated all required description fields above.
   - [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   - [ ] My PR is still work in progress (not ready for review).
   - [x] My PR is ready for review and can be safely merged into a codebase.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to