Commit Graph

1646 Commits

Author SHA1 Message Date
yangshuyong
0b8b5da851 fixed the unused variable caused warnning in lib_gethostbyaddrr
lib_gethostbyaddrr.c: warning: label 'out_copyname' defined but not used [-Wunused-label] 204 | out_copyname:

Signed-off-by: yangshuyong <yangshuyong@xiaomi.com>
2023-08-21 13:01:41 +08:00
fangxinyong
6c8b0ba9f3 libc/netdb: add dependence to net ip config
avoid to invalid enabled if no net ip config

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-21 13:01:04 +08:00
Xiang Xiao
339fc96f1f .gitignore: Add libsamplerate
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-20 14:32:25 +03:00
Petro Karashchenko
075738cf14 net/ip: print ip addresses using ip4_addrN macro
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-19 13:28:21 -03:00
chenrun1
fb74c46e4d arm64/gnu:Set arch_* optimizations to be on by default.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2023-08-19 18:43:08 +08:00
zhanghongyu
88ef7e164c getifaddrs: set sin6_scope_id when IPv6 enable
ifindex is also returned when obtain NIC information through getifaddrs.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-08-19 01:53:24 +08:00
anjiahao
19d1e022de lib_psfa_adddup2:fix mem leak when failed
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-19 01:23:20 +08:00
fangxinyong
903e87a7bd builtin: support uid/gid config for binfs app
Implement I_SUID/I_SGID feature for binfs in the POSIX compliant way.
If set-user-ID bit is set in the file permissions, then the effective
user ID of process shall be set to UID of the new process image file.

test case:
hello example emulates to set uid and file set-user-ID bit, and call
geteuid and getegid API.
UID  = 2000
GID  = 3000
MODE = 06555

nsh> ls -l /bin/hello
 -r-sr-sr-x    2000    3000       0 hello
nsh> hello
geteuid:2000
getegid:3000

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-14 01:37:00 +08:00
yangyalei
50428979d0 fix wait after vfork return error
Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-08-11 09:30:45 -06:00
anjiahao
fa676f264f gdbstub:fix typo
CC:  umm_heap/umm_zalloc.c gdbstub/lib_gdbstub.c:599:12: error: conflicting types for ‘gdb_hex2bin’; have ‘int(void *, size_t,  const void *, size_t)’ {aka ‘int(void *, long unsigned int,  const void *, long unsigned int)’}
  599 | static int gdb_hex2bin(FAR void *buf, size_t buf_len,
      |            ^~~~~~~~~~~
gdbstub/lib_gdbstub.c:102:16: note: previous declaration of ‘gdb_hex2bin’ with type ‘ssize_t(void *, size_t,  const void *, size_t)’ {aka ‘long int(void *, long unsigned int,  const void *, long unsigned int)’}
  102 | static ssize_t gdb_hex2bin(FAR void *buf, size_t buf_len,
      |                ^~~~~~~~~~~
gdbstub/lib_gdbstub.c: In function ‘gdb_write_memory’:
gdbstub/lib_gdbstub.c:1079:38: warning: passing argument 6 of ‘gdb_put_memory’ from incompatible pointer type [-Wincompatible-pointer-types]
 1079 |                        addr, length, gdb_hex2bin);
      |                                      ^~~~~~~~~~~
      |                                      |
      |                                      int (*)(void *, size_t,  const void *, size_t) {aka int (*)(void *, long unsigned int,  const void *, long unsigned int)}
gdbstub/lib_gdbstub.c:743:49: note: expected ‘gdb_format_func_t’ {aka ‘long int (*)(void *, long unsigned int,  const void *, long unsigned int)’} but argument is of type ‘int (*)(void *, size_t,  const void *, size_t)’ {aka ‘int (*)(void *, long unsigned int,  const void *, long unsigned int)’}
  743 |                               gdb_format_func_t format)
      |                               ~~~~~~~~~~~~~~~~~~^~~~~~
gdbstub/lib_gdbstub.c: In function ‘gdb_query’:
gdbstub/lib_gdbstub.c:1223:60: warning: format ‘%d’ expects argument of type ‘int’, but argument 7 has type ‘size_t’ {aka ‘long unsigned int’} [-Wformat=]
 1223 |                "Name: %s, State: %s, Priority: %d, Stack: %d",
      |                                                           ~^
      |                                                            |
      |                                                            int
      |                                                           %ld
 1224 |                 tcb->name, thread_state, tcb->sched_priority,
 1225 |                 tcb->adj_stack_size);
      |                 ~~~~~~~~~~~~~~~~~~~
      |                    |
      |                    size_t {aka long unsigned int}

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-08-11 20:16:17 +08:00
chao an
60c4d61c02 libs/libc/hex2bin: enhance 64-bit compatibility
Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-11 19:43:37 +08:00
xuxin19
b3678b1454 cmake:support nxlib cmake compilation
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-08-10 23:18:56 +08:00
xuxin19
4668b5fa22 cmake:fix cmake nxlib build break
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-08-10 23:18:56 +08:00
liaoao
74dddfe92b fdt: add libfdt support
Signed-off-by: liaoao <liaoao@xiaomi.com>
2023-08-10 20:47:37 +08:00
zhangyuan21
b705103f23 arm64: save and restore fpu regs in jmp when ARCH_FPU enabled
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-10 13:12:16 +08:00
fangxinyong
896f34fde9 sched: implement effective uid and gid interfaces
Implement 'effective' setuid, getuid, setgid, and getgid interfaces.
These will be inheritance by all child task groups. These definitons
are explicitly specified here:
https://pubs.opengroup.org/onlinepubs/000095399/functions/geteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/getegid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/seteuid.html
https://pubs.opengroup.org/onlinepubs/000095399/functions/setegid.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-09 17:07:58 +08:00
yanghuatao
3ccc5f0f76 libm/newlib: fix newlib build error
Fix error :
nuttx/libs/libm/newlib/include/math.h:89:8: error: ‘_Thread_local’ does not name a type; did you mean ‘thread_local’?
   89 | extern _Thread_local int _tls_gamma_signgam;
      |        ^~~~~~~~~~~~~
      |        thread_local
In file included from /mnt/nuttx/include/libcxx/math.h:300,
                 from /mnt/nuttx/include/libcxx/cmath:308,
                 from /mnt/nuttx/include/libcxx/charconv:79,
                 from libcxx/src/string.cpp:10:
/mnt/nuttx/libs/libm/newlib/include/math.h:89:8: error: ‘_Thread_local’ does not name a type; did you mean ‘thread_local’?
   89 | extern _Thread_local int _tls_gamma_signgam;

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-08-08 19:41:58 -03:00
Petro Karashchenko
aa3eeaa62a libs/libc: use _SCHED_GETPID in getpgrp implementation
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
Petro Karashchenko
d113722eb2 style: fix indentation issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
Petro Karashchenko
1b0baa8337 nuttx: use lib_free for memory de-allocation after strdup or asprintf
The memory allocated with strdup and asprintf is done via lib_malloc
so we need to use lib_free to deallocate memory otherwise the assertion
"Free memory from the wrong heap" is hit with flat mode and user separated
heap enabled mode.

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-08-08 11:58:29 -03:00
cuiziwei
7c8bb8c293 nuttx/tls: Remove the max key limiatation in task_tls_alloc and pthread_key_create
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
cuiziwei
5334c065b4 nuttx/tls:Setting the candidtate index to null prevents dangling pointers.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
cuiziwei
8ffde7cf16 nuttx/tls:Setting the candidtate index to null prevents dangling pointers.
Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2023-08-05 06:33:49 -07:00
zhangyuan21
699c401889 libc: update arm-m memset function
Use the memset function in bionic for better performance.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-03 21:15:50 -07:00
yinshengkai
26fc59bc35 libc/stdio: changed LIBC_NL_ARGMAX default value to 9
If LIBC_NL_ARGMAX is too large, the stack usage of printf family functions will increase

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-08-03 19:07:22 -07:00
zhangyuan21
a10cc49e67 Revert "newlib: libc: memcpy M-profile PACBTI-enablement"
This reverts commit 9fa097ab69.
2023-08-03 07:03:39 -07:00
fangxinyong
2bf434214e libc/sysconf: add _SC_REALTIME_SIGNALS
pass ltp case: open_posix_testsuite/conformance/interfaces/sigwait/7-1.c

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:57:28 -07:00
fangxinyong
da3a75da2c libc/net: compatible with Android for htonq/ntohq
Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-02 22:47:29 -07:00
zhangyuan21
3625385541 arch_memcpy: Optimize arch memcpy for armv7-m and armv8-m
Use ldm and stm instruction to optimize performance when
both src and dst are 32-bit aligned.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-08-02 16:52:25 +02:00
dongjiuzhu1
1920ff31d3 libs/libc/gpsutils/minmea: move minmea library from apps/gpsutils
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-08-01 23:09:46 -07:00
yangyalei
6a5cf6d3ff ltp: fix review questions
Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-08-01 09:35:36 -07:00
yangyalei
f40eee50d6 pwd: Add initial implementation of getpwent
fix ltp sigqueue testcase crash in getpwent:
nsh> ltp_sigqueue_3_1
core dumped

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-07-31 07:50:10 -07:00
yangyalei
4ecff53e2c sigaltstack: Add initial implementation of sigaltstack
fix ltp testcase compile error:
ltp/testcases/open_posix_testsuite/conformance/definitions/signal_h/31-1-buildonly.c:16:13: \
error: ‘sigaltstack’ undeclared (first use in this function)
   16 |  dummyvar = sigaltstack;
      |             ^~~~~~~~~~~

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-07-31 07:50:10 -07:00
yangyalei
ed705f9cb3 sysconf: add _SC_THREAD_THREADS_MAX response
fix ltp_pthread_create_s_c1 test get wrong PTHREAD_THREADS_MAX.

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-07-31 07:50:10 -07:00
dongjiuzhu1
5d09b4cbd0 libc/rand_r: support rand_r api
refs to https://pubs.opengroup.org/onlinepubs/7908799/xsh/rand.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-29 07:28:23 -07:00
dongjiuzhu1
afb473707f libc/pthread: add pthread_attr_set/getscope
refs to https://pubs.opengroup.org/onlinepubs/7908799/xsh/pthread_attr_setscope.html

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-07-28 20:55:22 -07:00
guoshichao
02153a2afb pthread_atfork: fix the incorrect description in comments
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-26 04:51:13 -07:00
guoshichao
9d7f349664 libs/pthread/pthread_atfork: fulfill implement pthread_atfork function
1. add the pthread_atfork implementation
2. the pthread_atfork implementation are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_atfork.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-26 10:41:52 +02:00
guoshichao
3524f4b9ce libs/libc/fork: add lib_fork implementation
1. add lib_fork api in libs/libc, we need a fork() api to implement the
fork relative method, such as pthread_atfork
2. rename the assembly fork entry function name to up_fork(), and rename
the up_fork() to arch specific name, such as
sim_fork()/arm_fork()/mips_fork() etc.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-26 10:41:52 +02:00
Xiang Xiao
f3269a6caa sched: Rename DEBUG_TCBINFO to ARCH_HAVE_TCBINFO
and select if the arch support to define g_tcbinfo variable

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-26 09:33:38 +02:00
Tiago Medicci Serrano
a5c92582a4 Rename CamelCase symbols to lowercase 2023-07-25 08:51:17 -07:00
Alan Carvalho de Assis
35ec548033 Remove empty lines with spaces found in the source code 2023-07-25 08:51:17 -07:00
Neale Ferguson
ed4f651bbd Fix modlib to get binary loading working again
This patch fixes the issue reported here:
https://github.com/apache/nuttx/issues/9845
2023-07-25 08:51:17 -07:00
Zhe Weng
9dc5a59d50 libc/netdb: Move dns query info and buffer out of the stack
The length of these buffers come from Kconfig, it isn't safe to allocate
them on the stack.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-07-25 06:17:48 -07:00
guoshichao
714926e6ea libs/libc/strftime: add modifier character support to strftime
1. make the ltp/open_posix_testsuite/strftime 2-1.c case
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-24 10:34:23 -07:00
guoshichao
0092b3e30f sched/signal/sig_nanosleep: fix the clock_nanosleep posix case
1. make the clock_nanosleep can pass
ltp/open_posix_testsuite/clock_nanosleep 13-1, 10-1, 9-1 cases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_nanosleep.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-23 22:02:03 -07:00
anjiahao
9f644579b3 fix sim register & tcb info typo
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-07-23 21:59:35 -07:00
chao an
4b94dc3092 toolchain/gcc: fix linker error if enable STACK_CANARIES/LTO at same time
If -fstack-protector-all is enabled, gcc linker will need GCC
SSP(Stack Smashing Protector) support, Since the implement of SSP
is related to the OS, most of embedded toolchain does not provide
ssp support, so an error will be reported when linking:

enable CONFIG_LTO_FULL && CONFIG_STACK_CANARIES

arm-none-eabi/bin/ld: cannot find -lssp_nonshared: No such file or directory
arm-none-eabi/bin/ld: cannot find -lssp: No such file or directory

https://github.com/gcc-mirror/gcc/blob/master/gcc/gcc.cc#L983-L985

Since nuttx has already implemented SSP related hook functions,
so in this PR, we filter out this option in the link phase to ensure that
the implementation of lssp/lssp_nonshared will not be referenced

Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-21 01:13:34 +08:00
zhanghongyu
3c359da8b9 dns: print dns server address when query failed
When debugging the actual dns resolution failure encountered, it is found
that if you know the address of dnsserver, the difficulty of debugging the
problem is reduced.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-07-20 08:11:57 +02:00
Xiang Xiao
a51be33a41 libc/tls: Change the default value of TLS_NELEM to zero
to ensure the default config as small as possible.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-20 08:11:30 +02:00
Xiang Xiao
abfe082a6f Kconfig: Simplify the conditional default statement
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 14:39:20 -03:00
Xiang Xiao
e031a73aef Kconfig: Change some "default y" to "default !DEFAULT_SMALL"
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 14:39:20 -03:00
Xiang Xiao
120c4a1660 modlib: Move modlib_allocbuffer to modlib_sectname and modlib_symname
it's better to allocate the buffer just before really use it.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 14:17:07 +03:00
Xiang Xiao
45cdb3efa4 libc/basename: Change len type from int to size_t
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-16 00:35:35 +03:00
chao an
f10b54a081 cmake: fix CMake build break
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-15 23:32:36 +08:00
anjiahao
b956495c5e libs/libc:Support gdb rsp protocol
you can debug nuttx through any transport layer (serial port, network etc.),
currently supports the following functions:
1. Read and write registers
2. Read and write memory
3. Switch thread and read stack information

Future support plans:
1. Support breakpoint, watch point (requires architecture support).

related information:
https://sourceware.org/gdb/onlinedocs/gdb/Remote-Protocol.html

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-07-15 01:57:11 +08:00
raiden00pl
24c44b35d5 cmake: support arm specific libm 2023-07-14 21:33:53 +08:00
yinshengkai
fe9251b546 libc: export lib_sprintf_internal function
This function does not take numbered arguments in printf

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-07-14 00:22:11 +03:00
yinshengkai
135959eb83 libc/printf: fix "%pS" length error
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-07-14 00:22:11 +03:00
chao an
8277229f53 nxstyle: covert utf-8 to ascii
libs/libc/stdio/lib_libgetstreams.c: C source, UTF-8 Unicode text
->
libs/libc/stdio/lib_libgetstreams.c: C source, ASCII text

Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-14 01:24:50 +08:00
guoshichao
79af1cdfe6 libs/libc/getpgid: add getpgid implementation
1. the getpgid function can help to pass the
ltp/open_posix_testsuite/killpg related testcases
2. NuttX do not support process group, so we use the process id as
process group id
3. the implementation are referred to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgid.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-13 19:37:35 +08:00
Neale Ferguson
878384fef0 Fix and improve dynamic loader
This patch fixes some issues found by Mark Stevens and
improve the dynamic loader.
2023-07-13 10:11:58 +08:00
fangxinyong
ffa084f3d2 signal: SIGKILL or SIGSTOP cannot be caught
pass ltp signal test cases, for posix spec, SIGKILL and SIGSTOP cannot be caught.

https://pubs.opengroup.org/onlinepubs/9699919799/functions/signal.html
https://pubs.opengroup.org/onlinepubs/007904875/functions/sigset.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-12 21:27:06 +08:00
yanghuatao
980462bf27 set CONFIG_PTHREAD_STACK_MIN as DEFAULT_MM_PGSIZE`s default value and
sysconf add param _SC_THREAD_STACK_MIN deal

make the pthread_exit pass the ltp/open_posix_testsuite/pthread_exit/1-2.c testcase
(1) in pthread_exit/1-2.c testcase, if sysconf(_SC_THREAD_STACK_MIN) % sysconf(_SC_PAGESIZE) is not zero, will report error and test failed, so set CONFIG_PTHREAD_STACK_MIN as DEFAULT_MM_PGSIZE`s default value.
(2) in function sysconf add param _SC_THREAD_STACK_MIN deal.

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-07-12 03:32:26 +08:00
guoshichao
c33d1c9c97 sched/task/fork: add fork implementation
1. as we can use fork to implement vfork, so we rename the vfork to
fork, and use the fork method as the base to implement vfork method
2. create the vfork function as a libc function based on fork
function

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-12 02:27:37 +08:00
yanghuatao
24e3cdf0c0 libc/pthread: remove unsed compare code in pthread_rwlock_init()
In nuttx function pthread_rwlock_init param attr is useless, so remove it to make rwlock_init pass rwlock_init/1-1.c and rwlock_init/3-1.c testcases.

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-07-11 13:29:37 +08:00
Xiang Xiao
9dc59e9109 Fix error: Mixed case identifier found
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-10 23:03:17 +03:00
Xiang Xiao
ebcb03dce9 libc/symtab: Don't include symtab.h in the header files
to unify the inclusion of symtab.h only from the source files

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-10 23:03:17 +03:00
yanghuatao
cd5e1169df libm/libmcs: Fix undefined symbol `fesetround'
Fix build error:apps/interpreters/quickjs/quickjs/quickjs.c:11852:(.text.js_ecvt1.constprop.0+0xfc): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `fesetround'

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-07-11 00:25:16 +08:00
Xiang Xiao
813b652ba5 elf: Move 32/64bit generic mapping from risc-v/arch_elf.c to elfxx.h
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-10 13:09:47 -03:00
Xiang Xiao
5849cf71d8 libc/symtab: Move SYMTAB_XXX from unistd/Kconfig to symtab/Kconfig
Make code and config in the same location

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-10 13:09:47 -03:00
Sunny
2a5f48c3fd libs/libc/stdlib: fix strtoul,strtoull bugs when value outside range
Prototype:
  unsigned long strtoul(FAR const char *nptr, FAR char **endptr, int base);
  unsigned long long strtoull(FAR const char *nptr,  FAR char **endptr, int base);

If endptr is not NULL, strtoul()/strtoull() should store the address of the first
invalid character in *endptr. And if the correct value is outside the range of
representable values, {ULONG_MAX} or {ULLONG_MAX} shall be returned and errno set
to [ERANGE].

With such code:
  strtoul("34592348345343453453455645765736575865767", &endptr, 10);

It indeed returns ULONG_MAX and sets errno to ERANGE. But after strtoul
return, endptr points to "3455645765736575865767", not NULL.

Signed-off-by: Sunny <zxcvbnm37425@gmail.com>
2023-07-10 19:07:27 +03:00
guoshichao
dc08798764 libs/libc/pthread: add the implementation of pthread_getcpuclockid
1. the implementation can pass the
ltp/open_posix_testsuite/pthread_getcpuclockid testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_getcpuclockid.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-10 13:40:49 +08:00
chao an
de7132c697 cmake/sched: fix build break based on mainline
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-10 13:26:21 +08:00
Sunny
9856eae61f libc/libvsprintf: fix vsnprintf bug with "%e"
For "%e" conversion, the exponent always contains at least two digits.
That means if the value is zero, the exponent is 00, not 0.

Such as code:
  printf(buffer, sizeof(buffer), "%e", 1.232323232323);
  printf(buffer, sizeof(buffer), "%e", 12.32323232323);
  printf(buffer, sizeof(buffer), "%e", 123.2323232323);

Expected output:
  1.232323e+00
  1.232323e+01
  1.232323e+02

But real output:
  1.232323e+0
  1.232323e+1
  1.232323e+2

Signed-off-by: Sunny <zxcvbnm37425@gmail.com>
2023-07-09 01:50:41 +08:00
chao an
6ee9ec7656 build: add initial cmake build system
1. Update all CMakeLists.txt to adapt to new layout
2. Fix cmake build break
3. Update all new file license
4. Fully compatible with current compilation environment(use configure.sh or cmake as you choose)

------------------

How to test

From within nuttx/. Configure:

cmake -B build -DBOARD_CONFIG=sim/nsh -GNinja
cmake -B build -DBOARD_CONFIG=sim:nsh -GNinja
cmake -B build -DBOARD_CONFIG=sabre-6quad/smp -GNinja
cmake -B build -DBOARD_CONFIG=lm3s6965-ek/qemu-flat -GNinja

(or full path in custom board) :
cmake -B build -DBOARD_CONFIG=$PWD/boards/sim/sim/sim/configs/nsh -GNinja

This uses ninja generator (install with sudo apt install ninja-build). To build:

$ cmake --build build

menuconfig:

$ cmake --build build -t menuconfig

--------------------------

2. cmake/build: reformat the cmake style by cmake-format

https://github.com/cheshirekow/cmake_format

$ pip install cmakelang

$ for i in `find -name CMakeLists.txt`;do cmake-format $i -o $i;done
$ for i in `find -name *\.cmake`;do cmake-format $i -o $i;done

Co-authored-by: Matias N <matias@protobits.dev>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:50:48 +08:00
Petro Karashchenko
558fa503d0 libs/libc/misc: fix alignment in fdcheck
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
Petro Karashchenko
85a46bf599 arch/sim: unify usage for SYMBOL macro
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
Petro Karashchenko
b8d3e32bdf sched/clock: move clock_getcpuclockid() and clock_getres() to libc
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-07 17:39:39 -03:00
Neale Ferguson
b5cd7c2a82 libs/libc/modlib: fix dynamic loader issues
* build-globals.sh
    - Macros for defining symbols etc. based on assembler in use
    - Use the System.map to get all the nuttx symbols

  * libs/libc/modlib/modlib_globals.S
    - Provide an empty skeleton. If the dynamic loading functions
      are required then run build-global.sh after a clean build
      using the skeleton. This will fill out the skeleton with the
      symbols to be available to dynamically loaded modules.

  * libs/libc/modlib/modlib_loadhdrs.c
    - Fix case where there are no program headers are avaiable
2023-07-07 13:43:20 -04:00
Gregory Nutt
8868c58720 Fix Deadloop in VFS if CONFIG_CANCELLATION_POINTS is enabled
If cancellation points are enabled, then the following logic is activated in sem_wait().  This causes ECANCELED to be returned every time that sem_wait is called.

    int sem_wait(FAR sem_t *sem)
    {
      ...

      /* sem_wait() is a cancellation point */

      if (enter_cancellation_point())
        {
    #ifdef CONFIG_CANCELLATION_POINTS
          /* If there is a pending cancellation, then do not perform
           * the wait.  Exit now with ECANCELED.
           */

          errcode = ECANCELED;
          goto errout_with_cancelpt;
    #endif
        }
      ...

Normally this works fine.  sem_wait() is the OS API called by the application and will cancel the thread just before it returns to the application.  Since it is cancellation point, it should never be called from within the OS.

There there is is one perverse cases where sem_wait() may be nested within another cancellation point.  If open() is called, it will attempt to lock a VFS data structure and will eventually call nxmutex_lock().  nxmutex_lock() waits on a semaphore:

   int nxmutex_lock(FAR mutex_t *mutex)
   {
     ...

     for (; ; )
       {
         /* Take the semaphore (perhaps waiting) */

         ret = _SEM_WAIT(&mutex->sem);
         if (ret >= 0)
           {
             mutex->holder = _SCHED_GETTID();
             break;
           }

         ret = _SEM_ERRVAL(ret);
         if (ret != -EINTR && ret != -ECANCELED)
           {
             break;
           }
       }
   ...
}

In the FLAT build, _SEM_WAIT expands to sem_wait().  That causes the error in the logic:  It should always expand to nxsem_wait().  That is because sem_wait() is cancellation point and should never be called from with the OS or the C library internally.

The failure occurs because the cancellation point logic in sem_wait() returns -ECANCELED (via _SEM_ERRVAL) because sem_wait() is nested; it needs to return the -ECANCELED error to the outermost cancellation point which is open() in this case.  Returning -ECANCELED then causes an infinite loop to occur in nxmutex_lock().

The correct behavior in this case is to call nxsem_wait() instead of sem_wait().  nxsem_wait() is identical to sem_wait() except that it is not a cancelation point.  It will return -ECANCELED if the thread is canceled, but only once.  So no infinite loop results.

In addition, an nxsem_wait() system call was added to support the call from nxmutex_lock().

This resolves Issue #9695
2023-07-06 14:20:29 -03:00
Alan Carvalho de Assis
bc62699c1d Fix coding style issues from PR #7202
Co-authored-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-07-06 14:08:08 -03:00
Xiang Xiao
8f38fa6062 symtab: Remove the unnessary inclusion of nuttx/symtab.h
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-06 09:24:02 -03:00
Xiang Xiao
935f43185f libc/modlib: Replace nx_stat with file_stat
to avoid searching the path twice

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-06 09:20:24 -03:00
Xiang Xiao
7bb97f7e22 elf: Replace {0x7f, 'E', 'L', 'F'} to EI_MAGIC
to avoid the duplication of the magic number.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-07-06 09:15:50 -03:00
Neale Ferguson
3cee81af6d * libs/libc/machine/arm/armv7-m/arch_elf.c
- Fix typo
2023-07-06 09:13:38 -03:00
Neale Ferguson
fec789047a Add support for the loading of ET_DYN objects
* libs/libc/machine/arm/armv7-m/arch_elf.c
      - Fix cast of error message parameters

    * build-globals.sh
      - Build the modlib_globals.S file used to resolve symbols when dynamically loading

    * libs/libc/modlib/Make.defs
      - Build modlib_globals.S for all targets

    * libs/libc/modlib/modlib_load.c
      - Calculate sizes and text/data addresses based on program headers rather than section headers
      - Handle objects with no program headers

    * libs/libc/modlib/modlib_bind.c
      - Call modlib_readsym with pointer to symbol table
      - Add modlib_relocatedyn to manage relocation of symbols with shared object (ET_DYN)
      - Differentiate between ET_REL and ET_DYN objects
      - Use arch independent symbol ELF_R_SYM
      - Cast sizes to avoid warnings

    * libs/libc/modlib/modlib_load.c
      - Cast sizes to avoid warnings

    * include/elf.h
      - Add definitions that may be found in shared objects

    * include/nuttx/lib/modlib.h
      - Add parameter to modlib_readsym prototype
      - Add prototypes for:
        - modlib_insertsymtab
        - modlib_findglobal
      - Define Elf_Dyn and Elf_Off according to the elf architecture
      - Add fields to mod_loadifno_s:
        - Program headers
        - Exported symbols
        - Data section address
        - Padding requirement
        - Section index for dynamic symbol table
        - Number of symbols exported
      - Add prottotype for modlib_freesymtab

    * libs/libc/dlfcn/lib_dlclose.c
      - Free the symbol table when the dll is closed

    * libs/libc/dlfcn/lib_dlopen.c
      - Add dump of program headers to debug routine
      - Differentiate between ET_REL and ET_DYN objects

    * libs/libc/machine/arm/armv7-m/arch_elf.c
      - Add handling of R_ARM_RELATIVE and R_ARM_JUMP slot relocation types

    * libs/libc/modlib/modlib_loadshdrs.c
      - Rename modlib_loadshdrs.c to modlib_loadhdrs.c
      - Rename modlib_loadshdrs to modlib_loadhdrs
      - Add code to load program headers

    * libs/libc/modlib/modlib_symbols.c
      - Define entry point structure
      - Add offset parameter to modlib_symname() and use to find symbol names
      - Add symtab section header parameter to modlib_readsym()
      - Add offset parameter to modlib_symvalue() to locate symbol names
      - Add modlib_insertsyntab() to create a symbol table for exporting and resolution
      - Add findEP() to resolve a symbol in the modlib_global table
      - Add modlib_findglobal() to find symbol in the modlib_global table
      - Add modlib_freesymtab() to free the symbol table

    * libs/libc/modlib/modlib_uninit.c
      - Free header and sections from a module_loadinfo_s control block

    * libs/libc/modlib/modlib_verify.c
      - Handle ET_DYN shared objects

    * libs/libc/modlib/modlib_globals.S
      - Multi-target global table
      - Define library APIs that may be resolved when loading a shared object
2023-07-06 09:13:38 -03:00
fangxinyong
dc7f8f136c signal: correct to const pointer for sigorset and sigandset
the two GNU functions, should use const input pointer parameter.

https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigorset.html
https://refspecs.linuxfoundation.org/LSB_1.3.0/gLSB/gLSB/baselib-sigandset.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-07-05 16:26:18 +08:00
Sunny
abfdffd879 libc/libvsprintf:fix vsnprintf bug with "%#.0f"
With double value=3.141593 initialized in va_list ap,
such code:
   vsnprintf(buffer, sizeof(buffer), "%#.0f", ap);
expected output string: "3."
but real output string: ".3"

Signed-off-by: Sunny <zxcvbnm37425@gmail.com>
2023-07-04 10:36:31 -03:00
guoshichao
42f8308423 sched/clock/clock_getres: add two CPUTIME_ID res support
1. make the clock_getres can pass the
ltp/open_posix_testsuite/clock_getres 7-1, 8-1 two cases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/clock_getres.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-03 23:11:00 +03:00
guoshichao
af53d7a178 libs/libc/aio/lio_listio: fix the heap use-after-free bug
1. the lio_sigsetup() method use a universal sighand instance across all
aiocb instances, but inside the lio_sighandler() method, if one aiocb is
handle finished, then this method will free the sighand instance that
come along with current aiocb instance. thus when handle next aiocb
instance, use-after-free crash will happen. in order to solve this
problem, we make each aiocb instance have their own sighand instance
2. make the lio_listio implementation can pass the
ltp/open_posix_testsuite/lio_listio testcases
3. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/lio_listio.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-03 13:37:34 +08:00
guoshichao
4af8c58b93 libs/libc/locale/langinfo: implement the nl_langinfo function
1. the nl_langinfo can help to pass the
ltp/open_posix_testsuite/strftime testcases
2. the implementation are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/nl_langinfo.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-07-02 13:57:36 +08:00
Junbo Zheng
0d3252ba06 libs/libc: fix locale/lib_iconv.c:538:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference] by -fanalyzer
CC:  signal/sig_queue.c locale/lib_iconv.c: In function ‘iconv’:
locale/lib_iconv.c:538:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference]
  538 |               if (!scd->state)
      |                    ~~~^~~~~~~
  ‘iconv’: events 1-5
    |
    |  413 |   x = 0;
    |      |   ~~^~~
    |      |     |
    |      |     (1) ‘scd’ is NULL
    |  414 |   scd = NULL;
    |  415 |   if (((size_t)cd & 1) == 0)
    |      |      ~
    |      |      |
    |      |      (2) following ‘false’ branch...
    |......
    |  421 |   to = extract_to(cd);
    |      |        ~~~~~~~~~~~~~~
    |      |        |
    |      |        (3) ...to here
    |......
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |      ~              ~~~
    |      |      |              |
    |      |      |              (5) ...to here
    |      |      (4) following ‘false’ branch (when ‘in’ is non-NULL)...
    |
  ‘iconv’: events 6-8
    |
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                  |              |  |
    |      |                  |              |  (7) ...to here
    |      |                  |              (8) following ‘false’ branch...
    |      |                  (6) following ‘false’ branch...
    |
  ‘iconv’: event 9
    |
    |cc1:
    | (9): ...to here
    |
  ‘iconv’: events 10-14
    |
    |  433 |   for (; *inb; *in += l, *inb -= l)
    |      |   ^~~
    |      |   |
    |      |   (10) following ‘true’ branch...
    |  434 |     {
    |  435 |       c = *(FAR unsigned char *)*in;
    |      |            ~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            |
    |      |            (11) ...to here
    |......
    |  438 |       switch (type)
    |      |       ~~~~~~
    |      |       |
    |      |       (12) following ‘case 200:’ branch...
    |......
    |  529 |           case UCS2:
    |      |           ~~~~
    |      |           |
    |      |           (13) ...to here
    |......
    |  538 |               if (!scd->state)
    |      |                    ~~~~~~~~~~
    |      |                       |
    |      |                       (14) dereference of NULL ‘scd’
    |
locale/lib_iconv.c:565:23: warning: dereference of NULL ‘scd’ [CWE-690] [-Wanalyzer-null-dereference]
  565 |               if (!scd->state)
      |                    ~~~^~~~~~~
  ‘iconv’: events 1-5
    |
    |  413 |   x = 0;
    |      |   ~~^~~
    |      |     |
    |      |     (1) ‘scd’ is NULL
    |  414 |   scd = NULL;
    |  415 |   if (((size_t)cd & 1) == 0)
    |      |      ~
    |      |      |
    |      |      (2) following ‘false’ branch...
    |......
    |  421 |   to = extract_to(cd);
    |      |        ~~~~~~~~~~~~~~
    |      |        |
    |      |        (3) ...to here
    |......
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |      ~              ~~~
    |      |      |              |
    |      |      |              (5) ...to here
    |      |      (4) following ‘false’ branch (when ‘in’ is non-NULL)...
    |
  ‘iconv’: events 6-8
    |
    |  428 |   if (in == NULL || *in == NULL || *inb == 0)
    |      |       ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
    |      |                  |              |  |
    |      |                  |              |  (7) ...to here
    |      |                  |              (8) following ‘false’ branch...
    |      |                  (6) following ‘false’ branch...
    |
  ‘iconv’: event 9
    |
    |cc1:
    | (9): ...to here
    |
  ‘iconv’: events 10-14
    |
    |  433 |   for (; *inb; *in += l, *inb -= l)
    |      |   ^~~
    |      |   |
    |      |   (10) following ‘true’ branch...
    |  434 |     {
    |  435 |       c = *(FAR unsigned char *)*in;
    |      |            ~~~~~~~~~~~~~~~~~~~~~~~~
    |      |            |
    |      |            (11) ...to here
    |......
    |  438 |       switch (type)
    |      |       ~~~~~~
    |      |       |
    |      |       (12) following ‘case 202:’ branch...
    |......
    |  557 |           case UTF_32:
    |      |           ~~~~
    |      |           |
    |      |           (13) ...to here
    |......
    |  565 |               if (!scd->state)
    |      |                    ~~~~~~~~~~
    |      |                       |
    |      |                       (14) dereference of NULL ‘scd’
    |

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2023-06-30 16:11:10 +08:00
guoshichao
083c11ef1a libs/libc/time/strftime: complete the strftime implementation
1. make the strftime implementation can pass the
ltp/open_posix_testsuite/strftime/1-1 testcase
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/strftime.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-30 12:02:23 +08:00
guoshichao
d5f45dc33b libs/libc/aio: fix aio_cancel compatible issue
1. make the aio_cancel implementation can pass the
ltp/open_posix_testsuite/aio_cancel testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_cancel.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-29 23:25:33 +08:00
Mingjie Shen
f5a2741ec2 libc/lib_remove: fix TOCTOU race condition
Separately checking the state of a file before operating on it may allow
an attacker to modify the file between the two operations.

Reference:
  CWE-367
  4290aed051/sysdeps/posix/remove.c (L29-L41)

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2023-06-29 18:15:06 +08:00
Huang Qi
f48a92810b libc.csv: Correct return type of strchr
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-06-28 18:23:52 +08:00
guoshichao
0d9e7be323 libs/libc/aio: fix aio_return compatible bug
1. make the aio_return implementation can pass the
ltp/open_posix_testsuite/aio_return testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_return.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-28 15:17:35 +08:00
Xiang Xiao
b64c029080 libc/pwd: Correct the geos related comment and ddd ROOT_GEOS macro
fix the minor issue in https://github.com/apache/nuttx/pull/7998

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-27 16:18:57 -03:00
Xiang Xiao
f1f33917f7 libc/pwd: Reuse g_passwd and g_passwd_buffer in getpwbuf
like other similar functions(e.g. getpwnam and getpwuid)

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-27 16:18:57 -03:00
guoshichao
6c60c7df07 libs/libc/aio: fix aio_error compatible bug
1. make the aio_error implementation can pass the
ltp/open_posix_testsuite/aio_error testcases
2. the modification are referred to https://pubs.opengroup.org/onlinepubs/9699919799/functions/aio_error.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-27 10:10:37 -03:00
guoshichao
037a6f5836 libs/libc/signal: add killpg function
1. the killpg function can make all the
ltp/open_posix_testsuite/killpg testcaes passed
2. Nuttx do not support process group, so we use kill process instead
3. the implementation are referred to:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-27 13:26:20 +08:00
Xiang Xiao
7f80b4aeba clock: Move the content of include/nuttx/time.h to include/nuttx/clock.h
and remove include/nuttx/time.h to reduce the nuttx specific header files

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-26 19:14:08 +03:00
Xiang Xiao
b5c48f3ed8 binfmt: Always include arch/elf.h in include/nuttx/elf.h
since symbols defined in arch/elf.h is also used in other case, for example:
CC:  pthread/pthread_testcancel.c machine/arm/gnu_unwind_find_exidx.c:32:8: error: unknown type name '__EIT_entry'
   32 | static __EIT_entry *__exidx_start_elf;
      |        ^~~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-25 19:02:53 -03:00
guoshichao
3821ad514d libs/libc/unistd: add getpgrp function
1. the getpgrp function can help to pass the ltp/open_posix_teststuite/killpg related testcases
2. Nuttx do not support process group, so we use getpid to implement this
3. the implementation are referred to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgrp.html

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-26 01:03:36 +08:00
anjiahao
1711a298a8 libc/semaphore:Set the flag need AND SEM_PRIO_MASK
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-06-22 16:08:03 +08:00
Alan Carvalho de Assis
9b8eedd218 lib_strftime: Also fix %l to avoid printing 0:xx AM/PM 2023-06-21 12:18:00 +08:00
Alan Carvalho de Assis
95f131c3c2 lib_strftime: Fix %I to avoid printing 00:xx AM/PM
Currently strftime is printing 00:00 AM and 00:00 PM instead of
12:00 AM and 12:00 PM when using %I.

This commit fixes this issue!
2023-06-21 12:18:00 +08:00
Xiang Xiao
1a06f7a2c9 libc: memfd_create should create /tmp/memfd/ before creating file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-20 20:14:20 +03:00
Xiang Xiao
43f9abf84f libc: Prefer to implement memfd on top of shm
since shm can work in protected and kernel mode too

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-20 20:14:20 +03:00
simbit18
f930b4f6f5 Fix Kconfig style
Remove TABs from Kconfig files
Replace help => ---help---
Add comments
2023-06-20 12:54:50 -03:00
Bowen Wang
8515294caa lib_syslograwstream: fix bug when iob alloc failed
Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
2023-06-17 19:33:41 +08:00
zhangyuan21
514e77b75e semaphore: Optimize priority inheritance with only one holder
This PR is a modification that optimizes priority inheritance
for only one holder. After the above modifications are completed,
the mutex lock->unlock process that supports priority inheritance
can be optimized by 200 cycles.

Before modify: 2000 cycle
After modify: 1742 cycle

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-06-17 08:26:46 +03:00
Xiang Xiao
14e5bcaf6e fs/fdcheck: Let FDCHECK depend on SCHED_HAVE_PARENT
since the implementation of fdcheck call getppid

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-16 18:08:05 +03:00
Xiang Xiao
c49bf046bd libc/fdcheck: Fix undefined reference to `getppid'
and change get[p]pid to  _SCHED_GET[P]PID

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-06-16 08:31:16 +03:00
zhanghongyu
b723e90356 fs: move memset to upper lever for statfs
if struct statfs add new members, such as f_fsid, no additional code
changes are required.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-16 11:10:25 +08:00
hujun5
b2ff151282 libc/fdcheck: if pid_expect is 0, fdcheck does not take effect
there are some user code like this:
  /* close all inherited fds */
  for (i = 3; i < maxfds; i++)
    func (i);

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-15 03:29:17 +08:00
hujun5
04db52612e libc/fdcheck: child process that uses the parent process'fd will crash
In many cases, it is legal for the child process to use the fd
created by the parent process,
so to improve compatibility, we allow the child process
to use the fd of the Parent process.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-15 03:29:17 +08:00
wangchen
693898d566 netdb/dns: fix dns wrong response ID error
In every dns query, we use the new socket to avoid receiving last response ID

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2023-06-15 03:20:46 +08:00
yanghuatao
29a336d6a8 sched/tls: remove PTHREAD_CLEANUP from Kconfig
use PTHREAD_CLEANUP_STACKSIZE to enable or disable interfaces pthread_cleanup_push() and pthread_cleanup_pop().
reasons:(1)same as TLS_TASK_NELEM (2)it is no need to use two variables

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2023-06-14 12:00:48 +08:00
zhanghongyu
d59a9ea189 inet_addr: return INADDR_NONE(-1) when input string is invalid
now:
inet_network("300.10.10.10"); return 0
inet_addr("300.10.10.10"); return 0

glibc and muscle both return INADDR_NONE or -1.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2023-06-13 13:31:37 +08:00
Alan Carvalho de Assis
69081a72d7 libdsp: Add average filter
This commit add average filter to DSP library
2023-06-12 08:39:38 +02:00
Petro Karashchenko
8d1a25f725 libs/libc/regex: add newline at the end of Make.defs
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:29 +08:00
Petro Karashchenko
187def2611 libs/libc/string: fix various style issues in code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-06-11 12:55:05 +08:00
hujun5
8fe8417ffb libc/fdcheck: add fdcheck module
In embedded development environments, due to the lack of address isolation between processes,
fd may be passed between processes and lead to misuse,

We have designed an fd cross-process automatic detection tool,
fdcheck_protect returns the fd containing the pid information,
indicating that the ownership of the current fd belongs to the pid and is not allowed to be used by other processes.
fdcheck_restore will obtain the true fd and check if the ownership of the fd is legal

For ease of understanding, let's give an example where
the following information is represented in 32-bit binary format

fd        00000000 00000000 00000000 10001010
pid       00000000 00000000 00000011 01010101
ret       00000000 00000011 01010101 10001010

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-06-10 02:19:58 +08:00
chao an
c1bcf59a85 libs/libc: fix build break on kernel mode
Signed-off-by: chao an <anchao@xiaomi.com>
2023-06-06 13:30:07 +08:00
guoshichao
441b51b706 libc/regex: provide a separate kconfig for regex
in the initial impl, the regex is depends on ALLOW_MIT_COMPONENTS, and
if other modules want to use regex, also needs to depends on
ALLOW_MIT_COMPONENTS, which is ambiguity, so we provide a seperate
kconfig option for regex: LIBC_REGEX, which is depends on
ALLOW_MIT_COMPONENTS, but is enabled by default. Thus if
ALLOW_MIT_COMPONENTS is enabled, then the LIBC_REGEX is also enabled
either automatically, and this is more clear than controlled by
ALLOW_MIT_COMPONENTS option only.

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2023-06-02 02:50:23 +08:00
Huang Qi
5606e77ee0 libc/wchar: Implement vswprintf
Implement vswprintf and let swprintf based on it.

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-06-01 14:34:01 +08:00
chao an
589d4a9f8e net/semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
chao an
fb9b41221d semantic/parser: fix compile warning found by sparse
Reference:
https://linux.die.net/man/1/sparse

Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-30 23:00:00 +08:00
hujun5
d70d406161 libc/fdsan: add fdsan protection for all file pointers
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-05-27 15:05:44 +08:00
Huang Qi
84c7a4dd69 libc.csv: Correct type of return value for strstr
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2023-05-25 20:09:27 +08:00
chao an
e51ec54c02 stream/hexdump: add hexdump stream to dump binary to syslog
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao
0203839fa1 stream: Add syslogstream implementation
which forward the output to syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
Xiang Xiao
20ea607bd0 stream: Rename syslogstream to syslograwstream
to prepare a new stream implementation of syslog

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an
f75adacea6 stream/syslog: remove unnecessary ifdef CONFIG_SYSLOG_BUFFER
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-25 15:22:04 +08:00
chao an
0455167457 stream/syslog: use internal buffer to decoupling syslog with iob
Signed-off-by: chao an <anchao@xiaomi.com>
2023-05-24 09:53:30 +08:00
Xiang Xiao
7990f90915 Indent the define statement by two spaces
follow the code style convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-21 09:52:08 -03:00
Petro Karashchenko
ede3e3e4c5 libs/libm/libmcs: add newline at the end of file
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko
c70b7f6b3d nuttx: improve C89 compatibility in common code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Petro Karashchenko
8d565fc0e3 libs/libc/string: remove redundant parenthesis
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2023-05-19 02:40:38 +08:00
Zhe Weng
e7043828a7 netdb: Regard hosts file prior to DNS when resolving
- Linux: What inside /etc/hosts comes first.
- NuttX: Even if we write a domain in /etc/hosts, we still use DNS
         result instead of hosts lines. This patch change this behavior.

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
2023-05-18 14:50:08 -03:00
Xiang Xiao
8d56a9bbcb Remove #warning if the code already return the error code or value
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
Xiang Xiao
bf391eaec2 libm/arm: Remove the compiler specific #warning
let ld report the error instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-18 15:44:28 +03:00
simbit18
ba94a24c8b libs\libc\stdlib\Kconfig: Fix indentation
Remove TABs
2023-05-18 15:43:22 +03:00
simbit18
3554c5f9a5 libs\libc\misc\Kconfig: Fix indentation
Remove TABs
2023-05-18 15:43:22 +03:00
simbit18
0b6d51a3b2 libs/libm/bin/Makefile: fix nxstyle
fix error: Relative file path does not match actual file
2023-05-18 19:31:12 +08:00
simbit18
3208519f93 libs/libm/kbin/Makefile: fix nxstyle
fix error: Relative file path does not match actual file
2023-05-18 19:31:12 +08:00
simbit18
a51412ea6e libs/libm/Makefile: fix nxstyle
fix error: Relative file path does not match actual file
2023-05-18 19:31:12 +08:00
Tiago Medicci Serrano
58e97e521c libc/string: prevent libc in the kernel/userspace optionally
Add the `LIBC_PREVENT_STRING_KERNEL` and `LIBC_PREVENT_STRING_USER`
that are meant to be selected by the chip if no libc implementation
is going to be built. If selected, neither NuttX's software version
of the libc nor any architecture-specific implementation will be
built in the kernel or in the userspace, respectively. In this
case, the linker may provide a ROM-defined version of the libc
functions instead.
2023-05-17 13:58:48 +08:00