Commit Graph

95 Commits

Author SHA1 Message Date
Alin Jerpelea 6b5dddd5d7 libs/libc: migrate to SPDX identifier
Most tools used for compliance and SBOM generation use SPDX identifiers
This change brings us a step closer to an easy SBOM generation.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-10-01 12:25:52 +08:00
wanggang26 f6d378e528 enable O_CLOEXEC explicitly to avoid fd leak
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-17 02:07:34 +08:00
dongjiuzhu1 7f99a15ccf libc/time: add g_lcl_lock to protect local context in localsub
0x0c1561f8 in localsub (tmp=0x3c887088, offset=0, timep=0x3c887078) at time/lib_localtime.c:1993
localtime_r (timep=0x3c887078, timep@entry=0x3c887088, tmp=0x3c887088, tmp@entry=0x3c887098) at time/lib_localtime.c:2819
0x0c1225c8 in nx_vsyslog (priority=7, fmt=0x2c6d9700 <error: Cannot access memory at address 0x2c6d9700>,
ap=0x3c887170, ap@entry=0x3c887178) at syslog/vsyslog.c:135
0x0c152068 in vsyslog (priority=priority@entry=7,
fmt=fmt@entry=0x2c6d9700 <error: Cannot access memory at address 0x2c6d9700>, ap=ap@entry=...) at syslog/lib_syslog.c:68
0x0c152098 in syslog (priority=priority@entry=7, fmt=0x2c6d9700 <error: Cannot access memory at address 0x2c6d9700>) at syslog/lib_syslog.c:100

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-16 10:35:17 +08:00
ligd f0d3c8ab2b usleep: use div_const to optimize the usleep
Signed-off-by: ligd <liguiding1@xiaomi.com>
2024-09-12 18:14:39 +08:00
chao an 85c39e96d6 global/variables: add g_ prefix to some global variables
Signed-off-by: chao an <anchao@lixiang.com>
2024-09-02 18:23:57 +08:00
Alin Jerpelea fe642f1cfd libc/time: remove lib_strptime
This code is licensed under BSD-4-Clause license which may render the OS unusable for some products.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2024-08-22 16:45:15 +08:00
anjiahao 3fdff878bc libc:Add macro restrictions to code that uses floating point numbers
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-21 13:33:45 +08:00
Xiang Xiao 7aad7eebff libc: Change errno to set_errno and get_errno
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-10-29 17:16:09 +02:00
dongjiuzhu1 fbd6484532 libc/localtime: fix the timezone error caused by minor error
align: https://github.com/eggert/tz/blob/main/localtime.c

correct timeone in test:

server> timedatectl set-timezone Pacific/Auckland
server> timedatectl
      TimeZone: NZDT, 46800
    Local time: Sat, Oct 21 21:47:34 2023 NZDT
Universal time: Sat, Oct 21 08:47:34 2023 UTC
      RTC time: Sat, Oct 21 08:47:35 2023

error timezone:

server> timedatectl set-timezone Pacific/Auckland
server> timedatectl
      TimeZone: NZST, 43200
    Local time: Sat, Oct 21 20:52:27 2023 NZST
Universal time: Sat, Oct 21 08:52:27 2023 UTC
      RTC time: Sat, Oct 21 08:52:27 2023

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 00:10:04 +08: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
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
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
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
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
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
chao an c839fc45af libc/settimeofday: correct prototype of settimeofday()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-03-21 11:16:30 -03:00
lilei19 38f64f559d change strcpy to strlcpy
Signed-off-by: lilei19 <lilei19@xiaomi.com>
2023-02-24 12:15:40 +08:00
chao an 3a0fdb019d nuttx: replace all ARRAY_SIZE()/ARRAYSIZE() to nitems()
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-09 20:05:44 +08:00
chao an 7625126c91 Remove the remain MIN/MAX like macro
Signed-off-by: chao an <anchao@xiaomi.com>
2023-02-03 23:22:41 +08:00
ligd 367fa640c1 asctime_r: add param check to asctime_r() 2023-01-28 23:23:12 +02:00
ligd f243e4f268 localtime: fix deadlock when print syslog in romfs
thread1:
romfs_seek -> take romfslock -> syslog -> tzset
thread2:
sylsog -> tzset -> tz_load -> romfs_open -> deadlock

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-28 18:04:38 +08:00
Petro Karashchenko 6908b6823c libs/libc/time: fix regression in clock_calendar2utc
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-10-28 10:21:05 +08:00
Petro Karashchenko fdff92fd19 libs/libc/time: mktime normalize struct tm
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-10-27 21:22:08 +08:00
Xavier Del Campo 8684814e09 strftime: Add support for the %T specifier 2022-10-26 00:54:59 +08:00
Xavier Del Campo 097faac22f strftime: Add support for the %R specifier 2022-10-26 00:54:59 +08:00
Fotis Panagiotopoulos ec93385dfa strftime: Added support for the %w format specifier. 2022-10-19 12:43:28 +08:00
Fotis Panagiotopoulos f9fd53cda1 gmtimer: Fixed range of tm_yday. 2022-10-19 12:39:04 +08:00
dongjiuzhu1 55106685fa libc/localtime: Update to consistent with mainline
https://github.com/eggert/tz

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-19 10:27:52 +08:00
dongjiuzhu1 7b2371f0ed libc/localtime: fix timegm return error when tz with isdst
testcase:
set TZ CEST
time_t t = time(NULL);
struct tm *ts = localtime(&t);
t = timegm(ts);
t will return (time_t)-1;

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-19 10:27:52 +08:00
Jiuzhu Dong 1b9ed5725b libc/time: Return failed when lock is already held to avoid deadlock
when enable LIBC_LOCALTIME and SYSLOG_TIMESTAMP_LOCALTIME
and zoneinfo/posixrulesi isn't exist

[ EMERG] [ap] backtrace:
[ EMERG] [ap] [20] [<0xc1cc3c4>] arm_switchcontext+0xc/0x10
[ EMERG] [ap] [20] [<0xc1ac67a>] sem_wait+0x5a/0xc0
[ EMERG] [ap] [20] [<0xc1c4588>] tzset.part.0+0x8/0x160
[ EMERG] [ap] [20] [<0xc1c58de>] localtime_r+0xc6/0x114
[ EMERG] [ap] [20] [<0xc1a910a>] clock_gettime+0x16/0xa8
[ EMERG] [ap] [20] [<0xc1b7622>] nx_vsyslog+0x9e/0xc0
[ EMERG] [ap] [20] [<0xc4ba7e0>] romfs_stat+0xa4/0xf4
[ EMERG] [ap] [20] [<0xc4b47bc>] inode_semtake+0x24/0x5c
[ EMERG] [ap] [20] [<0xc1c0102>] bsearch+0x26/0x6c
[ EMERG] [ap] [20] [<0xc1c265a>] vsyslog+0x16/0x24
[ EMERG] [ap] [20] [<0xc1c2676>] syslog+0xe/0x1c
[ EMERG] [ap] [20] [<0xc4bae12>] romfs_open+0xee/0x178  <--- err log
[ EMERG] [ap] [20] [<0xc4b68ae>] file_vopen+0x116/0x144
[ EMERG] [ap] [20] [<0xc4b6ac8>] open+0x20/0x60
[ EMERG] [ap] [20] [<0xc1c3df4>] tzload+0x84/0x810
[ EMERG] [ap] [20] [<0xc1c6ef4>] mm_zalloc+0x10/0x18
[ EMERG] [ap] [20] [<0xc4bb426>] romfs_checkmount+0x22/0x58
[ EMERG] [ap] [20] [<0xc4bad74>] romfs_open+0x50/0x178
[ EMERG] [ap] [20] [<0xc1c392c>] tzparse+0x2c/0x470
[ EMERG] [ap] [20] [<0xc1ac5da>] nxsem_wait_uninterruptible+0x8a/0xd0
[ EMERG] [ap] [20] [<0xc1ac690>] sem_wait+0x70/0xc0
[ EMERG] [ap] [20] [<0xc4b47bc>] inode_semtake+0x24/0x5c
[ EMERG] [ap] [20] [<0xc4b481c>] inode_semgive+0x28/0x58
[ EMERG] [ap] [20] [<0xc4b58b4>] file_close+0x18/0x44
[ EMERG] [ap] [20] [<0xc4b4690>] close+0x80/0xb4
[ EMERG] [ap] [20] [<0xc1c43f4>] tzload+0x684/0x810
[ EMERG] [ap] [20] [<0xc1c4616>] tzset.part.0+0x96/0x160
[ EMERG] [ap] [20] [<0xc1c58de>] localtime_r+0xc6/0x114
[ EMERG] [ap] [20] [<0xc1a910a>] clock_gettime+0x16/0xa8
[ EMERG] [ap] [20] [<0xc1ea692>] cmd_date+0x276/0x37c

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-19 10:27:52 +08:00
wangbowen6 8b84d19771 lib_localtime: gmtime_r should get right time in OS init process
Enable CONFIG_LIBC_LOCALTIME,CONFIG_RTC and CONFIG_SCHED_TICKLESS
In os clock init process, clock_initialize() --> ... -->
sim_rtc_rdtime() --> gmtime_r() --> gmtsub() --> return NULL
get the error rtctime.

Signed-off-by: wangbowen6 <wangbowen6@xiaomi.com>
2022-10-19 10:27:52 +08:00
Jiuzhu Dong 0bff62e3e8 libc/time: don't take semaphore in idle task
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-10-19 10:27:52 +08:00
anjiahao d1d46335df Replace nxsem API when used as a lock with nxmutex API
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-17 15:59:46 +09:00
Xiang Xiao bdeaea3742 Remove the unnessary empty line after label
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-09-30 17:54:56 +02:00
Junbo Zheng 74ab851ac4 nuttx/libs/libc/time: fix runtime error by UBSan
Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
2022-09-05 14:55:25 +08:00
Huang Qi e4e3208180 Replace all strncpy with strlcpy for safety
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2022-08-25 13:38:36 +08: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
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
anjiahao e6f77aeb9a libc/lib_strptime:change code format & add notes
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-13 10:16:42 +08:00
Xiang Xiao 96ea9b71ed libc/strptime: fix warning unused-value
warning: value computed is not used [-Wunused-value]
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-13 10:16:42 +08:00
anjiahao 6d3f14d41d libc/strptime:_conv_num skip space
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-13 10:16:42 +08:00
liuhaitao 366c25682c libc/time: add strptime porting support
lib_strptime.c copies from android bionic/libc/tzcode.

Signed-off-by: liuhaitao <liuhaitao@xiaomi.com>
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-13 10:16:42 +08:00
anjiahao 49cd445114 lib_localtime:fix unsigned compare with zero
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-12 17:10:14 +08:00
anjiahao bb6279fe60 libc/lib_localtime:fix deadcode
isdst always is false

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-04-12 01:51:29 +08:00
Petro Karashchenko 2ac3e3c793 libs/libc/time: update description of strftime
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-03-28 00:30:53 +08:00
Xiang Xiao 4a16cf71f9 Fix -Werror=nonnull-compare and -Werror=format-truncation=
Error: module/mod_insmod.c:203:3: error: 'strncpy' specified bound 16 equals destination size [-Werror=stringop-truncation]
  203 |   strncpy(modp->modname, modname, MODLIB_NAMEMAX);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

wqueue/kwork_thread.c: In function 'work_start_lowpri':
Error: wqueue/kwork_thread.c:212:22: error: '%lx' directive output may be truncated writing between 1 and 16 bytes into a region of size 14 [-Werror=format-truncation=]
  212 |   snprintf(args, 16, "0x%" PRIxPTR, (uintptr_t)wqueue);

local/local_sockif.c: In function 'local_getsockname':
Error: local/local_sockif.c:392:11: error: 'strncpy' specified bound depends on the length of the source argument [-Werror=stringop-overflow=]
  392 |           strncpy(unaddr->sun_path, conn->lc_path, namelen);
      |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

chip/esp32_wifi_utils.c: In function 'esp_wifi_scan_event_parse':
Error: chip/esp32_wifi_utils.c:373:37: error: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to dereference it? [-Werror=sizeof-pointer-memaccess]
   memset(ap_list_buffer, 0x0, sizeof(ap_list_buffer));
                                     ^

stdio/lib_fputs.c: In function 'fputs':
Error: stdio/lib_fputs.c:99:9: error: nonnull argument 's' compared to NULL [-Werror=nonnull-compare]
   if (s == NULL || stream == NULL)
         ^
Error: stdio/lib_fputs.c:99:27: error: nonnull argument 'stream' compared to NULL [-Werror=nonnull-compare]
   if (s == NULL || stream == NULL)
                           ^

stdio/lib_vfprintf.c: In function 'vfprintf':
Error: stdio/lib_vfprintf.c:40:6: error: nonnull argument 'stream' compared to NULL [-Werror=nonnull-compare]
   if (stream)
      ^

string/lib_strdup.c: In function 'strdup':
Error: string/lib_strdup.c:39:6: error: nonnull argument 's' compared to NULL [-Werror=nonnull-compare]
   if (s)
      ^

string/lib_strndup.c: In function 'strndup':
Error: string/lib_strndup.c:56:6: error: nonnull argument 's' compared to NULL [-Werror=nonnull-compare]
   if (s)
      ^

string/lib_strpbrk.c: In function 'strpbrk':
Error: string/lib_strpbrk.c:39:7: error: nonnull argument 'str' compared to NULL [-Werror=nonnull-compare]
   if (!str || !charset)
       ^~~~
Error: string/lib_strpbrk.c:39:15: error: nonnull argument 'charset' compared to NULL [-Werror=nonnull-compare]
   if (!str || !charset)
               ^~~~~~~~

string/lib_strrchr.c: In function 'strrchr':
Error: string/lib_strrchr.c:40:6: error: nonnull argument 's' compared to NULL [-Werror=nonnull-compare]
   if (s)
      ^

Error: time/lib_asctimer.c:73:50: error: '%d' directive output may be truncated writing between 1 and 11 bytes into a region of size between 0 and 12 [-Werror=format-truncation=]
   snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
                                                  ^~
time/lib_asctimer.c:73:21: note: directive argument in the range [-2147481748, 2147483647]
   snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
time/lib_asctimer.c:73:3: note: 'snprintf' output between 17 and 68 bytes into a destination of size 26
   snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            g_wday_name[tp->tm_wday], g_mon_name[tp->tm_mon],
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            tp->tm_mday, tp->tm_hour, tp->tm_min, tp->tm_sec,
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            1900 + tp->tm_year);
            ~~~~~~~~~~~~~~~~~~~

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-02 15:55:38 +08:00
Xiang Xiao f1ed349dd9 sched/clock: Remove CLOCK_MONOTONIC option from Kconfig
here is the reason:
1.clock_systime_timespec(core function) always exist regardless the setting
2.CLOCK_MONOTONIC is a foundamental clock type required by many places

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-23 01:21:26 +08:00
Xiang Xiao 5025fbef8d Rename LIB_ to LIBC_ for all libc Kconfig
follow other libc component naming convention

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-08-05 19:45:24 +02:00