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

   ## Summary
   
   * Replace Linux specific (and Linux built only) pseudo-terminal handling 
with portable POSIX code in the `posix/sim_hostuart.c:host_uart_openpty()`.
   * The Linux ioctls are replaced with the standard POSIX calls 
`posix_openpt()`, `grantpt()`, `unlockpt()` and `ptsname()`. These work on 
Linux, FreeBSD and macOS, so the `CONFIG_HOST_LINUX` / `-ENOSYS` guard is gone.
   * macOS gains pty support as a side effect.
   * `O_NONBLOCK` and `FD_CLOEXEC` are now set with `fcntl()` because FreeBSD’s 
`posix_openpt()` refuses `O_NONBLOCK`.
   * `_GNU_SOURCE` is defined on Linux only. glibc hides these calls without a 
feature macro, and the sim host build doesn’t define one.
   * The startup message now prints the real slave path from `ptsname()` 
instead of building `/dev/pts/%u` by hand.
   
   Here is the problematic code part being fixed / updated: 
https://github.com/apache/nuttx/blob/295bf8c3858f01002b533cc9ba21d57f3937d785/arch/sim/src/sim/posix/sim_hostuart.c#L148-L194
   
   Fixes: https://github.com/apache/nuttx/issues/22134.
   Assisted-by: Claude:claude-opus-5.5.
   
   ## Impact
   
   * `sim:nsh` and other UART related builds runs fine on more POSIX hosts 
outside Linux.
   
   ## Testing
   
   Tested on FreeBSD, macOS, and Linux.
   
   ### Before
   
   As reported in https://github.com/apache/nuttx/issues/22134:
   
   ```
   % uname -a
   FreeBSD hexagon 14.5-RELEASE-p4 FreeBSD 14.5-RELEASE-p4 
releng/14.5-n274932-1e85e58a3d48 GENERIC amd64
   
   % git reflog -3
   295bf8c385 (HEAD -> master, origin/master, origin/HEAD) HEAD@{0}: reset: 
moving to HEAD
   295bf8c385 (HEAD -> master, origin/master, origin/HEAD) HEAD@{1}: pull: 
Fast-forward
   80a052ff9c HEAD@{2}: pull: Fast-forward
   
   % ./tools/configure.sh -B sim:nsh
   
   % gmake V=1
   (..)
   gmake[1]: Entering directory '/XXX/nuttx.git/arch/sim/src'
   gmake -C board libboard.a EXTRAFLAGS="-D__KERNEL__ "
   gmake[2]: Entering directory '/XXX/nuttx.git/boards/sim/sim/sim/src'
   gmake[2]: 'libboard.a' is up to date.
   gmake[2]: Leaving directory '/XXX/nuttx.git/boards/sim/sim/sim/src'
   CC:  sim/posix/sim_hostuart.c
   "cc" -c  "-g" -fomit-frame-pointer -fprofile-arcs -ftest-coverage 
-fno-inline -fno-common -fvisibility=hidden -ffunction-sections -fdata-sections 
-Wall -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas 
-fno-pic -mcmodel=medium -no-pie  -D__KERNEL__  -D__SIM__ -fvisibility=default 
-I /XXX/nuttx.git/arch/sim/src -I /XXX/nuttx.git/arch/sim/src/chip 
-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 sim/posix/sim_hostuart.c -o 
sim_hostuart.o
   cc: warning: argument unused during compilation: '-no-pie' 
[-Wunused-command-line-argument]
   sim/posix/sim_hostuart.c:174:19: error: use of undeclared identifier 
'TIOCSPTLCK'
     174 |   ret = ioctl(fd, TIOCSPTLCK, &lock);
         |                   ^~~~~~~~~~
   1 error generated.
   gmake[1]: *** [Makefile:433: sim_hostuart.o] Error 1
   gmake[1]: Leaving directory '/XXX/nuttx.git/arch/sim/src'
   gmake: *** [tools/Unix.mk:581: nuttx] Error 2
   ```
   
   ### After
   
   1. FreeBSD
   
   Builds this part, but there are other parts to be fixed to complete the 
build.. more PR incoming warning ;-)
   
   ```
   % uname -a
   FreeBSD hexagon 14.5-RELEASE-p4 FreeBSD 14.5-RELEASE-p4 
releng/14.5-n274932-1e85e58a3d48 GENERIC amd64
   
   % ./tools/configure.sh -B sim:nsh
   (..)
   
   % gmake -j V=1 | grep -A5 -B5 sim_hostuart
   (..)
   CC:  sim/posix/sim_hostuart.c
   "cc" -c  "-g" -fomit-frame-pointer -fprofile-arcs -ftest-coverage 
-fno-inline -fno-common -fvisibility=hidden -ffunction-sections -fdata-sections 
-Wall -Wstrict-prototypes -Wshadow -Wundef -Wno-attributes -Wno-unknown-pragmas 
-fno-pic -mcmodel=medium -no-pie  -D__KERNEL__  -D__SIM__ -fvisibility=default 
-I /zraid/data/cederom/work/CeDeROM/lab/embedded/nuttx/nuttx.git/arch/sim/src 
-I 
/zraid/data/cederom/work/CeDeROM/lab/embedded/nuttx/nuttx.git/arch/sim/src/chip 
-D_FILE_OFFSET_BITS=64 -D_TIME_BITS=64 sim/posix/sim_hostuart.c -o 
sim_hostuart.o
   (..)
   ```
   
   2. macOS
   
   ```
   % uname -a
   Darwin XXX.local 27.2.0 Darwin Kernel Version 27.2.0: Thu Oct 15 00:00:57 
PDT 2026; root:xnu-13432.41.4~25/RELEASE_ARM64_T6020 arm64
   
   % ./tools/configure.sh -m sim:nsh
     Copy files
     Select CONFIG_HOST_MACOS=y
     Select CONFIG_HOST_ARM64=y
   (..)
   #
   # configuration written to .config
   #
   
   % make -j
   (..)
   LD:  nuttx
   ld: warning: -ld_classic is no longer supported and will be ignored
   ld: warning: -ld_classic is no longer supported and will be ignored
   
   % ./nuttx
   nsh> uname -a
   NuttX 13.1.1-RC0 1c72f8a5fa Nov 21 2026 03:25:40 sim sim
   nsh> help
   help usage:  help [-v] [<cmd>]
   
       .           dirname     free        mount       set         umount
       [           date        help        mv          kill        unset
       ?           df          hexdump     pidof       pkill       uptime
       alias       dmesg       losetup     poweroff    sleep       watch
       unalias     echo        ln          quit        usleep      xd
       basename    env         ls          printf      source      wait
       break       exec        du          ps          test
       cat         exit        mkdir       pwd         time
       cd          expr        mkfatfs     readlink    true
       cp          false       mkfifo      rm          truncate
       cmp         fdinfo      mkrd        rmdir       uname
   
   Builtin Apps:
       dd           gpio         init         ostest
       dumpstack    hello        nsh          sh
   nsh> free
         total       used       free    maxused    maxfree  nused  nfree name
      67108856    1860024   65248832    1860720   65189184    106      3 Umem
   nsh> ostest
   stdio_test: write fd=1
   stdio_test: Standard I/O Check: printf
   stdio_test: write fd=2
   stdio_test: Standard I/O Check: fprintf to stderr
   ostest_main: putenv(Variable1=BadValue3)
   ostest_main: setenv(Variable1, GoodValue1, TRUE)
   ostest_main: setenv(Variable2, BadValue1, FALSE)
   ostest_main: setenv(Variable2, GoodValue2, TRUE)
   ostest_main: setenv(Variable3, GoodValue3, FALSE)
   ostest_main: setenv(Variable3, BadValue2, FALSE)
   show_variable: Variable=Variable1 has value=GoodValue1
   show_variable: Variable=Variable2 has value=GoodValue2
   show_variable: Variable=Variable3 has value=GoodValue3
   ostest_main: Started user_main at PID=9
   (..)
   End of test memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena     3fffff8  3fffff8
   ordblks         8        8
   mxordblk  3e08d20  3e08d20
   uordblks   1e9718   1e9718
   fordblks  3e168e0  3e168e0
   
   user_main: nxevent test
   
   End of test memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena     3fffff8  3fffff8
   ordblks         8        8
   mxordblk  3e08d20  3e08d20
   uordblks   1e9718   1e9718
   fordblks  3e168e0  3e168e0
   
   Final memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena     3fffff8  3fffff8
   ordblks         3        8
   mxordblk  3e08d20  3e08d20
   uordblks   1e93a8   1e9718
   fordblks  3e16c50  3e168e0
   user_main: Exiting
   ostest_main: Exiting with status 0
   ```
   
   
   3. Linux
   
   ```
   $ uname -a
   Linux hexagon 5.15.0 FreeBSD 14.5-RELEASE-p4 
releng/14.5-n274932-1e85e58a3d48 GENERIC x86_64 GNU/Linux
   
   $ ./tools/configure.sh sim:nsh
     Copy files
     Select CONFIG_HOST_LINUX=y
     Refreshing...
   (..)
   #
   # configuration written to .config
   #
   cederom@hexagon:~/cederom/work/CeDeROM/lab/embedded/nuttx/nuttx.git$ make -j
   (..)
   LD:  nuttx
   Pac SIM with dynamic libs..
   '/lib/x86_64-linux-gnu/libz.so.1' -> 'sim-pac/libs/libz.so.1'
   '/lib/x86_64-linux-gnu/libc.so.6' -> 'sim-pac/libs/libc.so.6'
   '/lib64/ld-linux-x86-64.so.2' -> 'sim-pac/ld-linux-x86-64.so.2'
   SIM elf with dynamic libs archive in nuttx.tgz
   cederom@hexagon:~/cederom/work/CeDeROM/lab/embedded/nuttx/nuttx.git$ ./nuttx
   nsh> uname -a
   NuttX 13.1.1-RC0 1c72f8a5fa Nov 21 2026 03:48:48 sim sim
   nsh> help
   help usage:  help [-v] [<cmd>]
   
       .           dirname     free        mount       set         umount
       [           date        help        mv          kill        unset
       ?           df          hexdump     pidof       pkill       uptime
       alias       dmesg       losetup     poweroff    sleep       watch
       unalias     echo        ln          quit        usleep      xd
       basename    env         ls          printf      source      wait
       break       exec        du          ps          test
       cat         exit        mkdir       pwd         time
       cd          expr        mkfatfs     readlink    true
       cp          false       mkfifo      rm          truncate
       cmp         fdinfo      mkrd        rmdir       uname
   
   Builtin Apps:
       dd           gcov         hello        nsh          sh
       dumpstack    gpio         init         ostest
   nsh> free
         total       used       free    maxused    maxfree  nused  nfree name
      67108856    1859320   65249536    1860016   65189888    106      3 Umem
   nsh> ostest
   (..)
   Final memory usage:
   VARIABLE  BEFORE   AFTER
   ======== ======== ========
   arena     3fffff8  3fffff8
   ordblks         3        8
   mxordblk  3e08fe0  3e08fe0
   uordblks   1e8f88   1e92f8
   fordblks  3e17070  3e16d00
   user_main: Exiting
   ostest_main: Exiting with status 0
   ```
   


-- 
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