Commit Graph

1120 Commits

Author SHA1 Message Date
Karel Kočí
6c7f99189b libs/libc/string: add memmem
This function is the GNU extension.
2022-07-22 19:04:11 +03:00
Xiang Xiao
4e92e32d7b libc/impure: Fix the inconsistence from the different toolchain
some toolchain provider remove const qualifier from global_impure_ptr
(e.g. Espressif) but other provider keep it(e.g. ARM or Cadence), so
let's define const to empty macro to pass the compile and more safety.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-22 11:02:48 +03:00
ligd
3db8c2b6a6 stdio: need also flush stdio when flushall
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-07-22 01:46:21 +03:00
Xiang Xiao
1d43b4a4eb libc/stdio: Enable LIBC_FLOATINGPOINT by default if ARCH_FPU is enabled
and DEFAULT_SMALL is false

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-21 09:53:09 -04:00
Xiang Xiao
63cb11cc72 libc/stdio: Support "long long" type if CONFIG_HAVE_LONG_LONG is enabled
but just format the low 32bits if CONFIG_LIBC_LONG_LONG isn't enabled to
avoid to expand the code space to much.
Note: the size will increase 192 bytes on stm32_tiny:nsh.
Before the change:
   text    data     bss     dec     hex filename
  41444     184    1656   43284    a914 nuttx
After the change:
   text    data     bss     dec     hex filename
  41636     184    1656   43476    a9d4 nuttx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-20 18:06:29 +03:00
Xiang Xiao
f9e3ef3464 Revert "libc/stdio: enable long long formating by CONFIG_HAVE_LONG_LONG"
This reverts commit b1c72c023c.
2022-07-20 18:06:29 +03:00
Xiang Xiao
2166c98809 Add printflike and scanflike to all printf/scanf like functions
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-18 14:14:36 +03:00
Gustavo Henrique Nihei
9b0e3ae9d2 libs: Convert DEBUGASSERT(false) into more intuitive DEBUGPANIC()
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-07-14 12:08:45 +08:00
Xiang Xiao
b1c72c023c libc/stdio: enable long long formating by CONFIG_HAVE_LONG_LONG
and remove CONFIG_LIBC_LONG_LONG option to simplify the usage.
note: the size will increase 668
before change:
   text    data     bss     dec     hex filename
 168440     348    4480  173268   2a4d4 nuttx

after change:
   text    data     bss     dec     hex filename
 169108     348    4480  173936   2a770 nuttx

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-07-13 09:50:38 -03:00
Nathan Hartman
1867bc2210 Fix compiler warnings (-Wunused-parameter) in various functions
Fixes the -Wunused-parameter warning in:
* group/group_signal.c: group_signal()
* irq/irq_unexpectedisr.c: irq_unexpected_isr()
* task/task_spawn.c: nxtask_spawn_proxy()
* timer/timer_getoverrun.c: timer_getoverrun()
* misc/dev_null.c: devnull_read(), devnull_write(), devnull_poll()
* misc/dev_zero.c: devzero_read(), devzero_write(), devzero_poll()
* syslog/syslog_channel.c: syslog_default_write()
* syslog/syslog_device.c: syslog_dev_flush()
* grp/lib_initgroups.c: initgroups()
* misc/lib_mknod.c: mknod()
* misc/lib_glob.c: ignore_err()
* pthread/pthread_barrierinit.c: pthread_barrier_init()
* pthread/pthread_atfork.c: pthread_atfork()
* semaphore/sem_init.c: nxsem_init()
* stream/lib_nullinstream.c: nullinstream_getc()
* stream/lib_nulloutstream.c: nulloutstream_putc()
* stream/lib_libnoflush.c: lib_noflush()
* stream/lib_libsnoflush.c: lib_snoflush()
* string/lib_strerror.c: strerror()
* time/lib_gettimeofday.c: gettimeofday()
* time/lib_settimeofday.c: settimeofday()
* unistd/lib_pathconf.c: fpathconf(), pathconf()
* unistd/lib_getrusage.c: getrusage()
* unistd/lib_setrlimit.c: setrlimit()
* unistd/lib_getrlimit.c: getrlimit()
* unistd/lib_setpriority.c: setpriority()
2022-07-12 11:42:34 +08:00
Nathan Hartman
849f760b77 Fix various typos 2022-07-08 02:15:54 +08:00
Nathan Hartman
bf91047f33 libc: Fix getrandom() bug: Didn't propagate read error
* libs/libc/misc/lib_getrandom.c, in function getrandom():
  We were assigning the return value of _NX_READ() to nbytes, a
  variable of the unsigned type size_t. Note that _NX_READ() resolves
  to either read() or nx_read(), both of which return the signed type
  ssize_t to indicate either the number of bytes read successfully
  (>= 0) or an error (< 0). Then we were testing for a negative
  size_t value, a condition that can never occur. The end result is
  that if an error occured in _NX_READ(), it would never be detected
  and getrandom() would return some large positive value. This bug is
  corrected by assigning the return value of _NX_READ() to a new local
  variable, ret, of size ssize_t.
2022-07-01 11:51:53 +08:00
Gustavo Henrique Nihei
470287fe5c libs: Remove "0x" prefix preceding "%p" specifier on format string
The "p" format specifier already prepends the pointer address with
"0x" when printing.

Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2022-06-30 22:08:58 +03:00
Nimish Telang
903a186304 Use builtins for byteswapping
Make use of XCHG/BSWAP on x86, REV16 and REV on ARMv6-m and above,
and whatever other optimized instructions on other platforms.

Defines extra CONFIG variables, and removes the unused functions for
endian-swapping. Fixes some oversights in using the macros.
2022-06-29 11:32:59 +08:00
Juha Niskanen
449cf4d076 getrandom: fix comment contradicting code
Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2022-06-15 11:18:04 -03:00
Petro Karashchenko
02682af759 getrandom: use _NX_XXXX interface to remove cancelation point for kernel
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-06-13 22:27:19 +08:00
chao.an
644283c8ff libc/ipc: add ftok(3) support
https://man.openbsd.org/ftok.3

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-06-09 18:19:48 +03:00
Xiang Xiao
11c8f3125d sched/tls: Wrap up_info_size into tls_info_size
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-08 19:07:33 +09:00
Xiang Xiao
2707ba58d2 sched/tls: Shouldn't get tls info directly from sp in kernel space
since the stack may switch to the kernel or interrupt stack

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-08 08:56:04 +09:00
Xiang Xiao
f1236da21c fs: Make the binary(no process) mode as the default
POSIX require file system shouldn't enable the \r and \n conversion by default
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:22:26 +03:00
Xiang Xiao
df0e9da1ba libc/stdio: Support 'e'(O_CLOEXEC) in lib_mode2oflags
follow BSD and Linux convention:
https://man.openbsd.org/fopen
https://www.man7.org/linux/man-pages/man3/fopen.3.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:22:26 +03:00
Xiang Xiao
d8aa41de7b libc/stdio: Add FLAG_KEEP to avoid the duplication of (O_BINARY | O_EXCL)
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:22:26 +03:00
Xiang Xiao
49834c9151 libc/stdio: Check 'x' instead 'X' in lib_mode2oflags
follow BSD and Linux convention:
https://man.openbsd.org/fopen
https://www.man7.org/linux/man-pages/man3/fopen.3.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:22:26 +03:00
Xiang Xiao
3357b0b15f libc/stdio: Remove the unused flags(MODE_[PLUS|B|X|T) in lib_mode2oflags
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:22:26 +03:00
Xiang Xiao
5b165a2294 libc/stdio: Generate the dummy atexit and on_exit
since the compiler may generate the code call atexit automatically

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-07 20:14:34 +03:00
anjiahao
e0c3bf64a0 libc:Optimize the behavior of fwrite
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-06-07 22:28:00 +08:00
zhuyanlin
3455002ffd libc:xtensa:arch_memmove: fix warning
warning: 'SIM_CHECKS_ALIGNMENT' macro redefined
[-Wmacro-redefined] #define SIM_CHECKS_ALIGNMENT 1

Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-06-07 11:09:57 +03:00
Xiang Xiao
3e32b605fe libc/tls: Make tls_get_info as the pulibc function instead up_tls_info
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao
bd76e69f8d tls: Merge tls_xxx into pthread_keyxxx
it's always better to provide the standard api directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 23:56:50 +03:00
Xiang Xiao
c19d37adf0 libc/wchar: Call mbsnrtowcs in mbrtowc to handle the partial sequence correctly
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 22:25:49 +03:00
Xiang Xiao
4c34075d10 libc/wchar: Remove the unnecessary cast
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-03 22:25:49 +03:00
Xiang Xiao
406e1effed libc: Always compile ___cxa_atexit
since libsupc++ depends on it unconditionally

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-02 10:54:23 +03:00
Xiang Xiao
1a3e57fe86 libc: Remove weak_function from __aeabi_atexit
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-06-02 10:54:23 +03:00
Xiang Xiao
88fd6210f6 libc/wchar: Fix the minor style issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-31 07:59:34 +09:00
anjiahao
b88a8cf39f use rmutex inside of all repeated implementation
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-05-30 19:43:48 +08:00
Ville Juven
a54c3d13f9 sched: Remove SCHED_ATEXIT / SCHED_ONEXIT
Remove the kernel side implementations altogether. These will be
replaced by user land implementations.
2022-05-25 15:28:43 +08:00
Ville Juven
622677d4a1 libc: Implement exit, atexit, on_exit and cxa_exit on the user side
For CONFIG_BUILD_KERNEL using the sched/task/task_exithook implementation
will just not work. It calls user code with kernel privileges which is
a bit of a security issue.
2022-05-25 15:28:43 +08:00
Abdelatif Guettouche
4896623be2 build: Fix dependencies of kernel targets.
Targets build during the kernel phase did not have their dependencies
specified and thus they were not rebuilt after their dependencies have
changed, for example by changing options in menuconfig.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2022-05-24 10:45:39 +08:00
Xiang Xiao
ba6ee2a407 pthread/spinlock: Call up_testsest directly in the flat build
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-20 09:51:53 -03:00
Xiang Xiao
b39d70fe25 libxxmini: Fix error: use of undeclared identifier 'nullptr'
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-19 23:23:01 +03:00
zhuyanlin
1c977e97d2 pthread_mutexinit: fix deadcode in pthread_mutexinit
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-05-16 10:20:52 +03:00
Xiang Xiao
51cf7ba05a Remove FAR from arm/risc-v/xtensa/sim/x86
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-15 13:55:58 +03:00
Xiang Xiao
f7f8a21486 libs: Move aeabi_atexit from libxx/ to libc/machine/arm/
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-13 00:13:03 +03:00
Ville Juven
fb1c1bfe6c libc: Rename lib_Exit lib__Exit
Naming collision with lib_exit on some systems
2022-05-12 14:24:18 +03:00
Masayuki Ishikawa
5c3d6bba6d libs: risc-v: Add R_RISCV_JAL support to arch_elf.c
Summary:
- This commit adds R_RISCV_JAL support to arch_elf.c
- The code only checks the immediate value but does not relocate it
  because it is done by the compiler.

Impact:
- None

Testing:
- Tested with rv-virt:knsh64 (not merged yet)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-05-12 10:36:03 +08:00
zhuyanlin
38f8032e31 libc:xtensa: move syscall to swint call
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-05-11 10:48:53 +02:00
Juha Niskanen
a17bfec43d libc/string: simplify strrchr
Do not call strlen() here. Old implementation iterated
over string twice, if searched for position was at the
beginning. This commit changes strrchr() to scan string
only once, regardless of input.

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
2022-05-10 23:29:23 +08:00
Xiang Xiao
4ae7f4c1f6 libs: Move libxx_impure.cxx from libs/libxx/ to libs/libc/misc/
to fix the gcov link error:
arm-none-eabi-ld: /home/xiaoxiang/vela/prebuilts/gcc/linux/arm/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m/nofp/libgcov.a(_gcov.o): in function `gcov_error_exit':
libgcov-driver.c:(.text+0x7c): undefined reference to `_impure_ptr'
arm-none-eabi-ld: /home/xiaoxiang/vela/prebuilts/gcc/linux/arm/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m/nofp/libgcov.a(_gcov.o): in function `get_gcov_error_file':
libgcov-driver.c:(.text+0x1e0): undefined reference to `_impure_ptr'
arm-none-eabi-ld: /home/xiaoxiang/vela/prebuilts/gcc/linux/arm/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v7e-m/nofp/libgcov.a(_gcov.o): in function `gcov_exit_open_gcda_file.isra.0':
libgcov-driver.c:(.text+0x660): undefined reference to `_impure_ptr'

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-06 14:43:57 -03:00
Xiang Xiao
1e0f3ba4da libc: Remove C99_BOOL8 from libs/libxx/Kconfig
since it can be detected automatically by __STDC_VERSION__

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-05 16:23:32 -03:00
Xiang Xiao
577f301a2c libc: Move cxx_initialize.c from libc/sched/ to libc/misc
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-05-04 08:58:43 +02:00