Commit Graph

1805 Commits

Author SHA1 Message Date
guohao15
3ced80c743 basename: return path address instead of "/" when path="/"
Signed-off-by: guohao15 <guohao15@xiaomi.com>
2024-08-22 01:50:37 +08:00
chenrun1
900e713cd0 atomic:Add more interfaces
Summary:
  1. add atomic_flag_test_and_set and atomic_flag_clear
  2. add typedef memory_order
  3. add atomic_flag

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:44:29 +08:00
chenrun1
8e1a042eef nuttx/atomic.h:Fix missing type declarations at compile time
Summary:
  1.Modify the conditions for entering different include header files
  2.Added pre-definition for _Atomic _Bool when it is missing
  3.Added nuttx for stdatomic implementation. When toolchain does not support atomic, use lib/stdatomic to implement it

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-22 01:44:29 +08:00
Karel Kočí
c4d8d937d5 libs/libc/obstack: correctly append null byte at the end of string
obstack_printf and obstack_vprintf should terminate the C string with
null byte but lib_vsprintf doesn't do it. It must be done on top of
that unless we get unterminated string.

This is fix to be consistent with GlibC behavior.

This also includes minor tweak to use obstack_1grow directly instead of
calling obstack_puts.
2024-08-21 10:21:50 -03: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
guoshichao
ddc6e31740 libc/fputwc: fix the return value truncated from stdio interface
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao
d74e37d9db wchar/wcsstr: fix the variable overflow bug
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao
ca1e007a22 wchar/lib_ungetwc: fix the array access out of bounds error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao
9876b0b615 wchar/fgetwc: fix the return value truncate error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
guoshichao
390275f867 wchar/putwc: fix the putwc return value truncate error
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-21 02:57:43 +08:00
chenrun1
96abb51562 lib_getcwd:Fix the Name in the function description.
Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-21 02:52:45 +08:00
chenrun1
5bf24a15b5 lib_getnprocs:add #include <sys/types.h> instead of ifdef
Summary:
  Since there is a default definition for CONFIG_SMP_NCPUS in sys/types.h, we can remove #ifdef and return CONFIG_SMP_NCPUS directly.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-21 02:04:15 +08:00
chenrun1
f3cf11dcb5 libc/msic:Implement get_nprocs API
Summary:
 1.Remove the macro definition of getnproc in sysinfo
 2.New get_nprocs_conf and get_nprocs interfaces, return CONFIG_SMP_NCPUS, return 1 when not defined

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-21 02:04:15 +08:00
wangchen
146767a8a2 netdb:netdb code support ffmpeg rtsp(getaddrinfo & getnameinfo)
Related Codes:
1.ffmpeg/libavformat/ip.c
struct addrinfo *ff_ip_resolve_host(void *log_ctx,
                                    const char *hostname, int port,
                                    int type, int family, int flags)
{
    struct addrinfo hints = { 0 }, *res = 0;
    int error;
    char sport[16];
    const char *node = 0, *service = "0";

    if (port > 0) {
        snprintf(sport, sizeof(sport), "%d", port);
        service = sport;
    }
    if ((hostname) && (hostname[0] != '\0') && (hostname[0] != '?')) {
        node = hostname;
    }
    hints.ai_socktype = type;
    hints.ai_family   = family;
    hints.ai_flags    = flags;
    if ((error = getaddrinfo(node, service, &hints, &res))) {
        res = NULL;
        av_log(log_ctx, AV_LOG_ERROR, "getaddrinfo(%s, %s): %s\n",
               node ? node : "unknown",
               service,
               gai_strerror(error));
    }

    return res;
}
2.ffmpeg/libavformat/rtsp.c
static int sdp_read_header(AVFormatContext *s)
{
    RTSPState *rt = s->priv_data;
    RTSPStream *rtsp_st;
    int i, err;
    char url[MAX_URL_SIZE];
    AVBPrint bp;

    if (!ff_network_init())
        return AVERROR(EIO);

    if (s->max_delay < 0) /* Not set by the caller */
        s->max_delay = DEFAULT_REORDERING_DELAY;
    if (rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)
        rt->lower_transport = RTSP_LOWER_TRANSPORT_CUSTOM;

    /* read the whole sdp file */
    av_bprint_init(&bp, 0, AV_BPRINT_SIZE_UNLIMITED);
    err = avio_read_to_bprint(s->pb, &bp, INT_MAX);
    if (err < 0 ) {
        ff_network_close();
        av_bprint_finalize(&bp, NULL);
        return err;
    }
    err = ff_sdp_parse(s, bp.str);
    av_bprint_finalize(&bp, NULL);
    if (err) goto fail;

    /* open each RTP stream */
    for (i = 0; i < rt->nb_rtsp_streams; i++) {
        char namebuf[50];
        rtsp_st = rt->rtsp_streams[i];

        if (!(rt->rtsp_flags & RTSP_FLAG_CUSTOM_IO)) {
            AVDictionary *opts = map_to_opts(rt);
            char buf[MAX_URL_SIZE];
            const char *p;

            err = getnameinfo((struct sockaddr*) &rtsp_st->sdp_ip,
                              sizeof(rtsp_st->sdp_ip),
                              namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST);
            if (err) {
                av_log(s, AV_LOG_ERROR, "getnameinfo: %s\n", gai_strerror(err));
                err = AVERROR(EIO);
                av_dict_free(&opts);
                goto fail;
            }
            ff_url_join(url, sizeof(url), "rtp", NULL,
                        namebuf, rtsp_st->sdp_port,
                        "?localport=%d&ttl=%d&connect=%d&write_to_source=%d",
                        rtsp_st->sdp_port, rtsp_st->sdp_ttl,
                        rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0,
                        rt->rtsp_flags & RTSP_FLAG_RTCP_TO_SOURCE ? 1 : 0);

            p = strchr(s->url, '?');
            if (p && av_find_info_tag(buf, sizeof(buf), "localaddr", p))
                av_strlcatf(url, sizeof(url), "&localaddr=%s", buf);
            else if (rt->localaddr && rt->localaddr[0])
                av_strlcatf(url, sizeof(url), "&localaddr=%s", rt->localaddr);
            append_source_addrs(url, sizeof(url), "sources",
                                rtsp_st->nb_include_source_addrs,
                                rtsp_st->include_source_addrs);
            append_source_addrs(url, sizeof(url), "block",
                                rtsp_st->nb_exclude_source_addrs,
                                rtsp_st->exclude_source_addrs);
            err = ffurl_open_whitelist(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ,
                           &s->interrupt_callback, &opts, s->protocol_whitelist, s->protocol_blacklist, NULL);

            av_dict_free(&opts);

            if (err < 0) {
                err = AVERROR_INVALIDDATA;
                goto fail;
            }
        }
        if ((err = ff_rtsp_open_transport_ctx(s, rtsp_st)))
            goto fail;
    }
    return 0;
fail:
    ff_rtsp_close_streams(s);
    ff_network_close();
    return err;
}

Signed-off-by: wangchen <wangchen41@xiaomi.com>
2024-08-20 10:33:18 -03:00
chenrun1
e15100543f lib_remove.c:fix code style error
Summary:
  Warning: /home/runner/work/nuttx/nuttx/nuttx/libs/libc/stdio/lib_remove.c:59:32: warning: Wrong column position of comment right of code

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-20 13:50:15 +08:00
chenrun1
0a4770b44a lib_remove:Repair the logical judgment
Summary:
  When the deleted path is a file, the return value of get_errno is -EISDIR, so in Condition Two
(get_errno() ! = EPERM && /* .... . try to remove it. */
       rmdir(path) ! = 0)
The judgment holds directly, so it can't actually execute to rmdir

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-20 13:50:15 +08:00
chenrun1
97338c9f3d idr:New idr_find interface
Different from idr_get_next, if idr_find directly when could not find the node id return an error

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-19 11:05:40 -03:00
chenrun1
a1ccf15e39 idr:Tool for associating discrete ids with addresses
This is a tool for associating discrete IDs with addresses.
This tool is implemented through the red-black tree method provided by <sys/tree.h>, and the time complexity when calling, searching, and deleting is optimized to O(logn)
The implementation is the moving node operation of two red-black trees
1. When applying for a node, it will first check whether there is an available node in the "removed" tree. If so, the memory address of the node will be reused and moved to the "alloced" tree.
2. If the "removed" tree is an "empty tree", then the node will be requested from the memory and added to the "alloced" tree
3. Similarly, when removing a node, we set the address pointed to in the node to "NULL" and move it to the "removed" tree. Next time we alloc the node, we can reduce the overhead caused by memory application
For now, we still have something that can be optimized, and that is the memory elimination mechanism of the "removed tree". The current implementation will only release all the content under the "removed" tree when the idtree is destroyed.

Signed-off-by: chenrun1 <chenrun1@xiaomi.com>
2024-08-19 11:05:40 -03:00
meijian
a8843a073f getrlimit:implement RLIMIT_STACK return limit stack size
Signed-off-by: meijian <meijian@xiaomi.com>
2024-08-19 19:55:59 +08:00
yanghuatao
681122bc23 toolchain/ghs: Fix green hills toolchain build Vela MIN_MANT error
"stdio/lib_dtoa_engine.c", line 102: error #166: invalid floating constant
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 102: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 102: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        if (x < MIN_MANT)
                ^

"stdio/lib_dtoa_engine.c", line 107: error #166: invalid floating constant
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 107: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 107: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
                if (y < MAX_MANT)
                        ^

"stdio/lib_dtoa_engine.c", line 119: error #166: invalid floating constant
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 119: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 119: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
                if (y >= MIN_MANT)
                         ^

"stdio/lib_dtoa_engine.c", line 144: error #166: invalid floating constant
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 144: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 144: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        if (x >= MAX_MANT)
                 ^

"stdio/lib_dtoa_engine.c", line 153: error #166: invalid floating constant
        uint64_t decimal = MIN_MANT_INT;
                           ^

"stdio/lib_dtoa_engine.c", line 153: warning #1626-D: concatenation with "("
          in macro "PASTE" does not create a valid token
        uint64_t decimal = MIN_MANT_INT;
                           ^

"stdio/lib_dtoa_engine.c", line 153: error #109: expression preceding
          parentheses of apparent call must have (pointer-to-) function type
        uint64_t decimal = MIN_MANT_INT;

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-08-19 10:37:54 +08:00
yanghuatao
2ae4ea3f99 toolchain/ghs: Fix green hills toolchain build Vela link error
[elxr] (error #412) unresolved symbols:
 __builtin_signbit     from libc.a(lib_dtoa_engine.o)

Signed-off-by: yanghuatao <yanghuatao@xiaomi.com>
2024-08-19 10:37:54 +08:00
hujun5
08e6f56176 fdcheck: fix race condition in fdcheck
reason: ioctl will use the fl_lock file lock, causing context switching,
further leading to the failure of g_fdcheck_lock protection

Configuring NuttX and compile:
$ ./tools/configure.sh -l qemu-armv8a:nsh_smp
$ make
Running with qemu
$ qemu-system-aarch64 -cpu cortex-a53 -smp 4 -nographic \
   -machine virt,virtualization=on,gic-version=3 \
   -net none -chardev stdio,id=con,mux=on -serial chardev:con \
   -mon chardev=con,mode=readline -kernel ./nuttx

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2024-08-18 10:27:03 -03:00
fangxinyong
a6fa9db91e libs: fix the default value of process-shared attribute
pass ltp case: open_posix_testsuite/conformance/interfaces/pthread_condattr_getpshared/2-1.c

Reference:
https://pubs.opengroup.org/onlinepubs/009696899/functions/pthread_mutexattr_getpshared.html

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2024-08-18 19:44:56 +08:00
xuxin19
b64fb09e6c cmake:bugfix fix CMake LTO build block
it was wrong in https://github.com/apache/nuttx/pull/12423/files#r1618852245
EXTRA_FLAGS is useful in LTO for pass option tu lto linker

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-15 18:01:50 +08:00
chenxiaoyi
7c56e917e7 libc:add missing source to fix windows build error
nuttx_all.lib(netlib_setipv4dnsaddr.obj) : error LNK2019: unresolved external symbol _bzero referenced in function _netlib_set_ipv4dnsaddr

Co-authored-by: chenxiaoyi <chenxiaoyi@xiaomi.com>
Co-authored-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 22:36:57 +08:00
xuxin19
819685fbec cmake:bugfix enable ARCH_STRING_FUNCTION CMake build fail
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-14 20:58:59 +08:00
xuxin19
af10e1b470 lib_ustname:keep the incrementally compiled version time updated
fix phoney target mismatch issue, always rebuild ustname

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-08-13 19:42:32 +08:00
guoshichao
d76218e817 greenhills: fix the moblib asm compile error
CC:  assert/lib_assert.c [asarm] (error #2179) modlib/modlib_globals.S 61: unexpected token type (char) encountered; expected type (identifier)
  .size \ globalNames , . - \ globalNames
--------^

[asarm] (error #2179) modlib/modlib_globals.S 67: unexpected token type (char) encountered; expected type (identifier)
  .size \ nglobals , . - \ nglobals
--------^

[asarm] (error #2179) modlib/modlib_globals.S 72: unexpected token type (char) encountered; expected type (identifier)
  .size \ global_table , . - \ global_table
--------^

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-11 14:28:12 -03:00
guoshichao
ed9d57b501 greenhills: fix the arch_setjmp.S build error
CC:  bch/bchlib_read.c [asarm] (error #2067) machine/arm/gnu/arch_setjmp.S 34: unknown instruction
  .syntax unified
--^

[asarm] (error #2230) machine/arm/gnu/arch_setjmp.S 62: bad directive
  .type setjmp , function
-----------------^

[asarm] (error) errors during processing

Signed-off-by: guoshichao <guoshichao@xiaomi.com>
2024-08-11 14:28:12 -03:00
Daniel Jasinski
a09867df8c build: Fix libc/pwd CMakeLists.txt
This commit fixes erronous assignment of lib_pwd_globals.c
previously guarded by CONFIG_LIBC_PASSWD_FILE. Original
Make.defs file has this in CSRCS scope.

Signed-off-by: Daniel Jasinski <jasinskidaniel95szcz@gmail.com>
2024-08-07 08:45:19 +08:00
Yingwei Zheng
871cd306c5 libm/copysign: respect signed zero/NaN in copysign 2024-08-01 01:08:19 +08:00
Tiago Medicci Serrano
84d39a8d9a binfmt/libelf: Enable ELF loader if text heap read is word-aligned
The ELF loader needs to load the app into the memory before
executing it from the same location. As expected, this memory space
should be able to execute code. For architectures containing data
and instruction buses, the instruction bus may not be able to be
accessed in a non-aligned way, which is usually required when
copying data to that location. Eventually, this same memory space
can be accessed through the data bus, using different address
ranges. This commit enables accessing the memory through the data
bus to copy the app's data before executing it when
`CONFIG_ARCH_HAVE_TEXT_HEAP_WORD_ALIGNED_READ` is enabled.
2024-07-31 02:33:12 +08:00
Huang Qi
0228e52646 nxtk: Remove sapce between oprand and operator in nxtk_drawframe.c
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-07-27 03:11:39 +08:00
Huang Qi
f84d35de50 libc/net: Fix indent issue in lib_base64.c
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-07-27 03:11:39 +08:00
Huang Qi
09568c6147 dlfcn: Fix indent issue in lib_dlopen.c
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-07-27 03:11:39 +08:00
Huang Qi
f714669da4 dlfcn: Add stub for dladdr
Implement a stub for dladdr() to avoid build errors
with some applications that use dladdr().

The API definition is from:
1. https://man7.org/linux/man-pages/man3/dladdr.3.html
2. https://pubs.opengroup.org/onlinepubs/9799919799.2024edition/functions/dladdr.html

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-07-26 14:39:10 -03:00
Huang Qi
caa4c226bd dlfcn: Fix indent issue in lib_dlclose.c
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-07-26 16:34:41 +02:00
chao an
7780cfc5a6 tricore/cmake: add support of cmake build for tricore
Toolchain Upstream:
https://github.com/EEESlab/tricore-gcc-toolchain-11.3.0

CMake command:
$ cmake -B build -DBOARD_CONFIG=tc397/nsh -GNinja
$ cmake --build build

Signed-off-by: chao an <anchao@lixiang.com>
2024-07-18 13:40:49 +08:00
zhanghongyu
bcd64bf2bf libc/unistd: added an implementation of the lib_flock function
To solve some compilation issues encountered during the porting of
third-party libraries, this function has been added.

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-07-14 10:51:41 -03:00
p-szafonimateusz
53d112fa95 x86_64: add ELF support
add arch_elf64.c for x86_64, ported from sim/x86

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-07-03 17:40:53 +08:00
p-szafonimateusz
e6553eee5a libc/x86_64: port string functions from bionic
port optimized string functions for x86_64 from Bionic (BSD licensed)

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-07-02 23:59:18 +08:00
buxiasen
7445c97c77 libc: scanf, printf %z change switch const to if
switch const will cause a switch_selector_expr_is_constant
warning catched by coverity.

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-07-02 02:57:00 +08:00
buxiasen
b08d219849 mkstemp: permission 0666 to 0600
https://man7.org/linux/man-pages/man3/mkstemp.3.html
remove the read/write permission of other users for temp file

Signed-off-by: buxiasen <buxiasen@xiaomi.com>
2024-07-02 02:56:05 +08:00
fangpeina
242b50f921 libc/execinfo: extract a common backtrace format function
Add a common method to format backtrace to buffer, so it can be used by both mm, fs and other possoble modules.

Signed-off-by: fangpeina <fangpeina@xiaomi.com>
2024-06-29 22:44:39 +08:00
p-szafonimateusz
c932fe3045 libm/newlib: disable optimization for sincos
Disable sincos optimization for all functions in this file,
otherwise gcc would generate infinite calls.
Refer to gcc bug 46926.
-fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
but these two options do not work inside optimize pragma in-file.
Thus we just enforce -O0 when compiling this file.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-06-28 01:26:18 +08:00
p-szafonimateusz
23b2f96c9d libm/libm: disable optimization for sincos
Disable sincos optimization for all functions in this file,
otherwise gcc would generate infinite calls.
Refer to gcc bug 46926.
-fno-builtin-sin or -fno-builtin-cos can disable sincos optimization,
but these two options do not work inside optimize pragma in-file.
Thus we just enforce -O0 when compiling this file.

Signed-off-by: p-szafonimateusz <p-szafonimateusz@xiaomi.com>
2024-06-28 01:26:18 +08:00
Huang Qi
a14d94c548 gdbstub: Minor style fix
Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-06-26 10:19:14 -03:00
zhanghongyu
e14ae3e681 pthread: add pthread_self/pthread_gettid_np function
explicitly defined functions can support assignment as function pointers

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
2024-06-26 17:40:55 +08:00
anjiahao
1b2ad4ff7d gdbstub: fix typo
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-06-26 00:20:58 +08:00
Huang Qi
add8b71fee serial/gdbstub: Change GDBSTUB_ to GDB_
Fix nameing convention inconsistent

Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
2024-06-24 23:51:43 +08:00