Commit Graph

1234 Commits

Author SHA1 Message Date
chao an
d12ddf56df arm/arm: sync ARM_THUMB support from cortex-a
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-05 01:09:31 +08:00
chao an
4b70e4ff77 arm/cortex-r: sync ARM_THUMB support from cortex-a
Signed-off-by: chao an <anchao@xiaomi.com>
2022-12-04 20:12:31 +08:00
jihandong
965566d2e8 libc/stdio: add total_len back
"The number of characters written if successful or negative value if an error occurred.
If the resulting string gets truncated due to buf_size limit, function returns the total
number of characters (not including the terminating null-byte) which would have been written,
if the limit was not imposed." --- https://en.cppreference.com/w/c/io/vfprintf

Signed-off-by: jihandong <jihandong@xiaomi.com>
2022-12-04 17:27:49 +08:00
zouboan
eaea38e0f2 libc and mm/Makefile:Fix an error caused by backslash in Windows native build
libc and mm/Makefile:Fix an error caused by backslash in Windows native build
2022-12-01 01:47:46 +08:00
flyingfish89
fa59db8cea Add Hexadecimal parsing for strtof
solve:
  almost the Hexadecimal string string->float
such as:
  code:float num;
       const char *s= "0x123p32lala";
       char *p;
       num=strtof(s,&p);
       printf("num is %f\n",num);
       printf("str is %s\n",p);
  output:num is 1249835483136.000000
         str is lala

but if the input number is much big;
like:
  code:const char *s2= "0x999999p100";
       num=strtof(s2,&p);
       printf("num is %f\n",num);
       printf("str is %s\n",p);
  corrent : num is 12760587998944832242938906880669384704.000000
  real:     num is 12760587998944800000000000000000000000.000000
it didn't have enough precision
2022-11-30 19:03:07 +08:00
flyingfish89
bb040befee optimize the code of the printf 2022-11-29 17:27:02 +08: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
田昕
9d48d86606 libc/stream:add putc interface for mtd/blk stream.
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-11-28 16:37:01 +08:00
ligd
092c78d636 signal: correct signal() return value & errno
Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-28 14:15:21 +08:00
ligd
eef619fc46 signal: correct sigset() return value & errno
ref:
https://man7.org/linux/man-pages/man3/sigset.3.html
The dispositions for SIGKILL and SIGSTOP cannot be changed.

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-28 14:15:21 +08:00
Xiang Xiao
7c7ab96b53 libc/stdio: Remove putc macro from lib_libvsprintf.c
call lib_stream_put directly instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-27 22:59:21 +01:00
Xiang Xiao
7568a0df22 libc/stdio: Don't count the output length repeatly in vsprintf_internal
let's reuse the counting from lib_outstream_s::nput instead

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-27 22:59:21 +01:00
Xiang Xiao
33e35c6ce3 libc/stdio: Don't set FL_[LONG|SHORT] repeatly in vsprintf_internal
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-27 22:59:21 +01:00
Xiang Xiao
df6666ab5e libc/stream: Rename lib_stream_[put|get]c to lib_stream_[put|get]
keep the macro consistent with the callback name

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-27 22:59:21 +01:00
Xiang Xiao
6d30726a1b Remove the unnecessary "return;" at the end of function
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-27 22:23:50 +01:00
yinshengkai
377bf97613 stream: replace the stream function pointer with a macro
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-11-25 21:41:51 +08:00
Xiang Xiao
9bfc91e6f1 libc/stream: Remove \n special handle from syslogstream_putc
since \r\n process is already done in up_putc or serial driver level

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-25 09:10:05 +01:00
Xiang Xiao
5fd1379d3f syslog: Move syslog stream to libc like other stream implementation
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-25 01:46:31 +08:00
flyingfish89
4b87a8b079 lib_libvsprintf: fix the float point print bug
such as code: double value = +0x1.000000000000080000000000p-600;
              printf("Hello, World!! %.7g:f64\n", value);
expected output : Hello, World!! 2.40992e-181:f64
but real output : Hello, World!! 2.40992e-B1:f64
the reason: we want printf "18", but the flag of character is 'B'
            and 'B' is '0'+18,so printf 'B';
2022-11-24 12:02:03 -03:00
田昕
28739b8b8a libc/stream:Add mtd backend stream.
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-11-24 12:07:10 +08:00
Ville Juven
4781379ee2 obstack/obstack_free: Fix incorrect usage of void* for arithmetics
Using void* for arithmetics is a GCC extension, and thus should not be
used for portable code.
2022-11-23 23:22:06 +08:00
Tiago Medicci Serrano
d3ffeb40a7 libc/machine/xtensa: make longjmp safe against context switch
In order to turn longjmp context-switch safe, it's necessary
to disable interrupts before modifying windowbase and windowstart.
Otherwise, after a context switch, windowstart and windowbase
would be different, leading to a wrongly set windowstart bit due to
longjmp writing it based on the windowbase before the context switch.
This corrupts the registers at the next window overflow reaching
that wrongly set bit.

*Background:*
This PR is related to an issue first observed on ESP-IDF
https://github.com/espressif/esp-idf/issues/5229 and it was, then,
checked on NuttX using a test application.

*The test application:*
To check if the problem affects ESP32, ESP32-S2 and ESP32-S3 on
NuttX, it was created an application based on:
https://en.cppreference.com/w/c/program/longjmp

The application creates 16 tasks (`#define NUMBER_OF_TASKS  16`)
that implements the following daemon:

```
static int setjmp_longjmp_daemon(int argc, char *argv[])
{
  for (int i = 0; i < NUMBER_OF_TASKS * 2; i++)
    {
      jmp_buf env;

      volatile int count = 0;
      if (setjmp(env) != UINT16_MAX)
        {
          foo(&env, ++count);
        }
    }

  sem_post(&g_sem);

  return EXIT_SUCCESS;
}
```

The main function also initializes a semaphore to avoid application
exiting before tasks return successfully:

```
  sem_init(&g_sem, 0, -NUMBER_OF_TASKS);
```

Finally, the round-robin interval was lowered to 1ms to raise the
chances of the longjmp being interrupted by a context switch
(`CONFIG_RR_INTERVAL=1).

This setup was able to reproduce the problem prior to this patch
being applied.
2022-11-22 19:34:44 +01:00
Xiang Xiao
af2aa13873 phtread: Change stacksize type from long to size_t
follow the standard prototype:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_attr_getstack.html

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-22 08:23:37 +09:00
qinwei1
8021dfece6 sched/task/task_getpid: getpid should return process id not thread id
Summary:
   implement the right semantics:
1. getpid should return the main thread id
2. gettid should return the current thread id

Refer to:
 https://github.com/apache/incubator-nuttx/issues/2499
 https://github.com/apache/incubator-nuttx/pull/2518

Signed-off-by: qinwei1 <qinwei1@xiaomi.com>
2022-11-17 17:58:08 +08:00
anjiahao
d07792a343 Initialize global mutext/sem by NXMUTEX_INITIALIZER and SEM_INITIALIZER
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-14 09:34:04 +09:00
zhanghongyu
db4840564d dns: Reduce the dns_lock granularity
When a7 curl calls dns_query via usrsock, it will wait a usrsock
response with the dns lock held. If a7 rptun recv a dns_addnameserver
event from another core at this time, rptun waits the lock held by
curl in callback. Then curl will never get its usrsock response with
rptun blocked, so the deadlock occurs.

This change will break lock when do usrsock request.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2022-11-11 20:07:05 +08:00
anjiahao
634bdeaa5c pthread_barrier:don't destory when barrier used
this is fix a ltp test case and update
the error code of pthread_barrierdestroy

ltptcase is : apps/testing/ltp/ltp/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-11-11 08:56:48 +08:00
ligd
a9c647d418 semaphore: move param check to sem_xx level
for the speed improve

Signed-off-by: ligd <liguiding1@xiaomi.com>
2022-11-10 22:36:21 +08:00
Xiang Xiao
36abcda0d2 lib/netdb: Rename dns_sem[take|give] with dns_[lock|unlock]
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-09 21:38:10 +01:00
Xiang Xiao
898093a822 libc/stdio: Remove the one line mutex wrapper
and call nxmutex api directly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-09 21:38:10 +01:00
chao an
80a2d058b8 lib/atexit: correct return value of exitfunc lock
Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-07 18:14:30 +08:00
yinshengkai
85f727f232 tools: replace INCDIR to Makefile variable
In the past, header file paths were generated by the incdir command
Now they are generated by concatenating environment variables

In this way, when executing makefile, no shell command will be executed,
it will improve the speed of executing makfile
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-11-03 19:59:55 +08:00
yinshengkai
95d9abcf58 tools: replace DEFINE script to Makefile variable
In the past, predefined macros were generated by define.sh scripts
Now they are generated by concatenating environment variables

In this way, when executing makefile, no shell command will be executed,
it will improve the speed of executing makfile

Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-11-03 19:59:55 +08:00
Xiang Xiao
9e72fe9fab libc/spawn: Always build lib_psa_[get|set]stacksize.c
instead of lib_psa_[get|set]stackaddr.c since the later doesn't exist in kernel mode
regression by:
commit b9b032af72
Author: Xiang Xiao <xiaoxiang@xiaomi.com>
Date:   Thu Oct 20 03:10:23 2022 +0800

    sched/spawn: Support task_spawnattr_[set|get]stacksize in kernel mode

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-01 21:03:52 +01:00
Xiang Xiao
28947517ca sched/spawn: Rename task_spawnattr_[get|set]stack[size|addr] to posix_spawnattr_[get|set]stack[size|addr]
since they can be not only used in task_spawn but also in posix_spawn

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-01 09:51:18 +09:00
chao an
1550747400 sched/getprioritymax: handle invaild policy as posix style
modify the return value according to posix standard
------------
SCHED_GET_PRIORITY_MAX(2)

NAME
       sched_get_priority_max, sched_get_priority_min  - get static priority range

RETURN VALUE
       On success, sched_get_priority_max() and sched_get_priority_min() return the
                   maximum/minimum priority value for the named scheduling policy.
       On error, -1 is returned, and errno is set appropriately.

ERRORS
       EINVAL The argument policy does not identify a defined scheduling policy.

Signed-off-by: chao an <anchao@xiaomi.com>
2022-11-01 03:33:58 +08:00
Xiang Xiao
3e3364d1a9 Fix the format string mismatch warning
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-31 11:20:56 +01:00
Xiang Xiao
64e7833cbc sched/spawn: Support task_spawnattr_[set|get]stackaddr
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-31 12:46:58 +09:00
Xiang Xiao
b9b032af72 sched/spawn: Support task_spawnattr_[set|get]stacksize in kernel mode
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: chao an <anchao@xiaomi.com>
2022-10-31 12:46:58 +09:00
Xiang Xiao
f8d97aea9e libnx: Remove the unnecessary invocation of _SEM_SETPROTOCOL
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-29 21:12:40 +02: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
Xiang Xiao
19bded4738 fs: Remove the unused nx_pipe to prefer file_pipe for kernel
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-27 23:14:25 +02:00
Minh Nguyen
153060d34d Update errno to match asm-generic
Modify some comment.
2022-10-28 02:19:26 +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
Karel Kočí
61b1791584 libs/libc: add obstack 2022-10-26 09:11:52 +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
Miguel Herranz
819ebe7356 libc/stdio: Add stdio file locking functions
Add flockfile(), ftrylockfile() and funlockfile() functions [1].

[1] POSIX.1-2008 / System Interfaces / flockfile
    https://pubs.opengroup.org/onlinepubs/9699919799.2008edition/functions/flockfile.html

Signed-off-by: Miguel Herranz <miguel@midokura.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-22 23:34:45 +08:00
anjiahao
577e550698 libc/semaphore:sem_init change defult protocol
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2022-10-22 14:50:48 +08:00
YAMAMOTO Takashi
f100a4bb92 Implement fdopendir 2022-10-19 21:20:35 +08:00