Commit Graph

397 Commits

Author SHA1 Message Date
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
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
Xiang Xiao 69575975f4 binfmt: elf_addrenv_free select addrenv before up_addrenv_destroy
to avoid up_addrenv_destroy delete the current task page table
this patch fix the below panic due to elf contain the unresolved symbol:
qemu-system-arm -s -S -semihosting -M sabrelite -m 1024 -smp 4 -kernel nuttx -nographic -net nic -net user,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:10021-10.0.2.15:21,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=tcp:127.0.0.1:15555-10.0.2.15:5555
ABDGHIJKNOPQ
[    0.470000] elf_relocate: Section 2 reloc 163: Failed to get value of symbol[1505]: -2
[    0.530000] arm_dataabort: Data abort. PC: 108323de DFAR: 80202778 DFSR: 00000005
[    0.530000] up_assert: Assertion failed at file:armv7-a/arm_dataabort.c line: 161 task: /system/bin/init
[    0.530000] arm_registerdump: R0: 10845820 R1: 80202778 R2: 00000001  R3: 80202778
[    0.530000] arm_registerdump: R4: 80202624 R5: 80202634 R6: 80200330  FP: 80202628
[    0.530000] arm_registerdump: R8: 802026b4 SB: 00000000 SL: 8000dbfe R11: 00000000
[    0.530000] arm_registerdump: IP: 108453e0 SP: 108456b0 LR: 1082b091  PC: 108323de
[    0.530000] arm_registerdump: CPSR: a000007f
[    0.530000] arm_dump_stack: IRQ Stack:
[    0.530000] arm_dump_stack: sp:     10845510
[    0.530000] arm_dump_stack:   base: 108397c0
[    0.530000] arm_dump_stack:   size: 00000800
[    0.530000] arm_dump_stack: ERROR: IRQ Stack pointer is not within the stack
[    0.530000] arm_stackdump: 10839f00: deadbeef 00adbeef 00000001 10844990 00000000 00000000 80300000 1082f2ef
[    0.530000] arm_stackdump: 10839f20: deadbeef 00000000 deadbeef 10844990 80200000 1082f2ff 1083d980 1082f311
[    0.530000] arm_stackdump: 10839f40: 00000002 10814659 00000004 00000002 deadbeef 1081469b 00000001 00000000
[    0.530000] arm_stackdump: 10839f60: 10845460 00000057 10844a90 00000002 deadbeef 10808d1b 10845460 00000057
[    0.530000] arm_stackdump: 10839f80: 00dfbeef 00000057 00000000 00000002 deadbeef 10801d1f 10845460 00000057
[    0.530000] arm_stackdump: 10839fa0: 00000000 10800fc5 deadbeef 10845460 00000057 00000057 deadbeef 108000a0
[    0.530000] arm_dump_stack: User Stack:
[    0.530000] arm_dump_stack: sp:     108456b0
[    0.530000] arm_dump_stack:   base: 80202038
[    0.530000] arm_dump_stack:   size: 000007c8
[    0.530000] arm_dump_stack: ERROR: User Stack pointer is not within the stack
[    0.530000] arm_dump_stack: Kernel Stack:
[    0.530000] arm_dump_stack: sp:     108456b0
[    0.530000] arm_dump_stack:   base: 10844c10
[    0.530000] arm_dump_stack:   size: 00000c00
[    0.530000] arm_stackdump: 108456a0: 00000000 108453e0 108323de a000007f 80202778 10845820 00000000 10812aa9
[    0.530000] arm_stackdump: 108456c0: 00000000 1083ff90 10845838 00000000 001f001e 10812b2f 10840008 1083ff90
[    0.530000] arm_stackdump: 108456e0: 10845840 10812fab 10845840 1083ff90 005f0000 10844990 10845818 10845ff8
[    0.530000] arm_stackdump: 10845700: 10845ff8 10845838 10845840 10812017 fffffffe 10845820 80202624 1082b091
[    0.530000] arm_stackdump: 10845720: 00000000 00000000 80202778 10841d40 00000000 10845840 10845820 fffffffe
[    0.530000] arm_stackdump: 10845740: 00000000 1082998b 00000000 80200330 802026b4 80202778 10845788 0084578c
[    0.530000] arm_stackdump: 10845760: 10841d40 10844990 00000000 108306fb 00000000 80202634 802026b4 80202634
[    0.530000] arm_stackdump: 10845780: 80202778 80202628 00000000 00000000 00000000 00000000 00000000 1083085f
[    0.530000] arm_stackdump: 108457a0: 80200330 00000000 00000000 00000000 80202634 80202624 80202778 80202628
[    0.530000] arm_stackdump: 108457c0: 00000000 00000000 00000000 80202614 80202624 1080f26b 802026b4 80200330
[    0.530000] arm_stackdump: 108457e0: 80202624 80202778 80202628 0000001f 00000000 80202634 802026b4 108012c3
[    0.530000] arm_showtasks:    PID    PRI     STACK      USED   FILLED    COMMAND
[    0.530000] arm_showtasks:   ----   ----      2048       188     9.1%    irq
[    0.530000] arm_dump_task:      0      0      2024      1240    61.2%    Idle Task
[    0.530000] arm_dump_task:      1    224      1992       504    25.3%    hpwork 0x1083e0f8
[    0.530000] arm_dump_task:      2    100      1992       504    25.3%    lpwork 0x1083e110
after apply this patch, nsh report error instead of crash:
qemu-system-arm -s -S -semihosting -M sabrelite -m 1024 -smp 4 -kernel nuttx -nographic -net nic -net user,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:10021-10.0.2.15:21,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001,hostfwd=tcp:127.0.0.1:15555-10.0.2.15:5555
ABDGHIJKNOPQ
[    0.440000] elf_relocate: Section 2 reloc 163: Failed to get value of symbol[1505]: -2
telnetd [4:100]

NuttShell (NSH) NuttX-11.0.0
nsh> nsh: telnetd: command not found

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-11-03 00:08:12 +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
anjiahao d7b4e91dda Call nxsem_destroy or nxmutex_destry in the error path
1.Don't check the return value of nxsem_init or nxmutex_init
2.Fix some style issue

Signed-off-by: anjiahao <anjiahao@xiaomi.com>
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-30 13:56:52 +01:00
Xiang Xiao 9f4bb7da97 binfmt: Let binfmt_copyargv return error code
so the caller can distinguish the empty argument and out of memory quickly

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-19 08:22:56 +09:00
Ville Juven 7c003162a6 libelf/libelf_symbols.c: Fix compilation warning about void* arithmetics
Fixes minor issue with a trace (build failure with -Werror):
libelf/libelf_symbols.c:310:41: error: pointer of type 'void *' used in arithmetic [-Werror=pointer-arith]
  310 |               (uintptr_t)(sym->st_value + symbol->sym_value));
2022-09-28 20:35:31 +08:00
xiangdong6 4cd4303c32 binfmt: Check return pointer.
Function builtin_for_index may return NULL.
We must check this to prevent visit invalid address.

Signed-off-by: xiangdong6 <xiangdong6@xiaomi.com>
2022-09-03 19:39:51 +08:00
Masayuki Ishikawa 0cef7b765e binfmt: Fix memory leak in ELF loader
Summary:
- I noticed that the hello (ELF) application causes a memory leak.
- Finally, I found that the data section is not deallocated.
- This commit fixes this issue.

Impact:
- ELF loader with CONFIG_ARCH_ADDRENV=n

Testing:
- Tested with the following configs
  - sprensense:elf, esp32-devkitc:elf, sabre-6quad:elf
  - spresense:wifi_smp, rv-virt:nsh64, sabre-6quad:netnsh

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-07-23 14:34:27 +08:00
Masayuki Ishikawa aecdcb316b Revert "binfmt: Fix memory leak in ELF loader"
This reverts commit 23d57be21b.
2022-07-20 15:34:58 +03:00
Masayuki Ishikawa 23d57be21b binfmt: Fix memory leak in ELF loader
Summary:
- I noticed that the hello (ELF) application causes a memory leak.
- Finally, I found that the data section is not deallocated.
- This commit fixes this issue.

Impact:
- None

Testing:
- Tested with spresense:wifi_smp, rv-virt:nsh64, sabre-6quad:netnsh

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-07-20 14:56:37 +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
Ville Juven 47e85b68fe arch/addrenv: Change text write enable/disable to generic mprot
Implement a generic access rights modification procedure instead
of the procedures that only do one thing (enable/disable write)
to one section (text).
2022-05-12 22:28:31 +08:00
Ville Juven fdef3a7b92 binfmt/libelf: Fix function description field
Copy&paste error, wrong description field used
2022-05-04 10:34:24 +03:00
Ville Juven 9af8b740e6 Elf loader: give temporary write access to user .text memory
When the .elf file is loaded from disk, the kernel must be given write
access to the allocated .text section in the task's address environment.

The access is removed after the elf is loaded and relocations are done.

NOTE:
The reason this works for the ARM implementation, is that the ARM MMU
can be configured to give write access for the privileged mode, but
revoke write access for the user mode.

Regardless, it would be smart to revoke write access even for the
kernel, when the kernel does not need it. This framework allows doing
that, if someone wishes to take up the task.
2022-05-03 21:25:25 +09:00
Ville Juven 9c5fb9ec8d binfmt_execmodule: Use heap size getter for print 2022-05-02 17:06:08 +08:00
Ville Juven b3baf95835 UMM: Implement getter for address environment heap start vaddr
Using the Kconfig macro does not work for RISC-V target, as there the
user heap follows .data/.bss and does not obey any Kconfig provided
boundary.

Added stubs for ARM and Z80 also.
2022-04-29 23:13:16 +08:00
Xiang Xiao 55b5561fdb sched/task: Implement execle and execve
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-22 10:40:31 +03:00
Xiang Xiao 76803f4a07 sched/environ: Replace get_environ_ptr with environ
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-04-21 22:55:47 +03:00
Ville Juven 1a7d81c942 binfmt_execmodule: If incoming envp is NULL get parent envp
This keeps backwards compatibility with apps that do not provide
envp. The old implementation passes NULL always and this change fixes
any regression caused by it.
2022-04-21 18:38:37 +08:00
Ville Juven 4c1b66246d env_dup: Fix copying of env between address environments
If address environments are in use, it is not possible to simply
memcpy from from one process to another. The current implementation
of env_dup does precisely this and thus, it fails at once when it is
attempted between two user processes.

The solution is to use the kernel's heap as an intermediate buffer.
This is a simple, effective and common way to do a fork().

Obviously this is not needed for kernel processes.
2022-04-21 18:38:37 +08:00
Ville Juven 6b1ee4c2e2 binfmt_execmodule: add errout_with_args exit point
Ensures that when errout_xx is taken, args are freed
2022-04-21 18:38:37 +08:00
Xiang Xiao cd516bd09d Fix libelf/libelf_coredump.c:234:7: warning: 'strncpy' output may be truncated copying 16 bytes from a string of length 31
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-03-22 08:37:33 +02:00
Ville Juven 75afe491ad RISC-V: Prepare for CONFIG_BUILD_KERNEL
- Thread context prior to system call needs to be preserved
- Allocate a kernel heap
2022-03-18 18:20:12 +08:00
Masayuki Ishikawa a44a0a08cd binfmt: Call umm_initialize() for BUILD_KERNEL & ADDRENV
Summary:
- I noticed that the user heap is not initialized correctly
  if BUILD_KERNEL=y and ADDRENV=y
- This commit fixes this issue

Impact:
- None

Testing:
- Tested with sabre-6quad:netknsh (not merged yet)

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-02-17 11:31:01 +01:00
Xiang Xiao 47e38eb70f binfmt: Decouple builtin from binfs file system
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-02-14 09:35:35 -03:00
YAMAMOTO Takashi e596d5bd5e binfmt/libelf: Implement sh_addralign handling
Basically, mirror the following two commits from modlib.
It's shame we have two copies of elf loaders.

```
commit 51490bad55
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Wed Apr 14 17:07:39 2021 +0900

    modlib: Implement sh_addralign handling

    I've seen a module with 16 bytes .rodata alignment for xmm operations.
    It was getting SEGV on sim/Linux because of the alignment issue.
    The same module binary seems working fine after applying this patch.

    Also, tested on sim/macOS and esp32 on qemu,
    using a module with an artificially large alignment. (64 bytes)
```

```
commit 418e11b8b3
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Thu Apr 15 11:33:48 2021 +0900

    modlib: Always use separate allocation for text and data

    Pros:

    * Reduce code differences
    * Smaller allocations for !CONFIG_ARCH_USE_MODULE_TEXT

    Cons:

    * Likely to use more memory for !CONFIG_ARCH_USE_MODULE_TEXT in total

    Tested with:

    * sim:module on macOS
    * esp32-devkit:nsh + CONFIG_MODULE on qemu
    * lm3s6965-ek:qemu-protected + CONFIG_EXAMPLES_SOTEST on qemu
```
2022-01-28 16:23:23 +08:00
Xiang Xiao f903a55102 sched/tcbinfo: Fix the compile warning
Update tcbinfo struct

armv8-m/arm_tcbinfo.c:109:3: warning: excess elements in struct initializer
  109 |   TCB_REG_OFF(REG_S31),
      |   ^~~~~~~~~~~
armv8-m/arm_tcbinfo.c:109:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:110:3: warning: excess elements in struct initializer
  110 |   0,
      |   ^
armv8-m/arm_tcbinfo.c:110:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:111:3: warning: excess elements in struct initializer
  111 |   TCB_REG_OFF(REG_FPSCR),
      |   ^~~~~~~~~~~
armv8-m/arm_tcbinfo.c:111:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:112:3: warning: excess elements in struct initializer
  112 |   0,
      |   ^
armv8-m/arm_tcbinfo.c:112:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:37:1: warning: missing braces around initializer [-Wmissing-braces]
   37 | {

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-01-27 17:36:27 +08:00
YAMAMOTO Takashi fd58398918 binfmt/elf.c: Fix syslog formats for ELF64
Loosely followed the copy in mod_insmod.c.
2022-01-27 10:57:48 +08:00
Petro Karashchenko 9551de7115 net: use HTONS, NTOHS, HTONL, NTOHL macro in kernel code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-01-18 10:59:47 +01:00
chao.an 47f9ec9c45 binfmt/coredump: remove the block fragmentation
Hide the segmentation details to backend implementation

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-01-14 23:07:05 +08:00
chao.an 7cbb8da692 binfmt/elf: add bare metal coredump support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-11-23 20:48:00 -06:00
Xiang Xiao 9e60c33d4d binfmt: Remove umm_initialize from elf_load
since umm_try_initialize will do it automatically

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-10-18 22:51:18 -03:00
chao.an 5ff4e33e3f binfmt/Makefile: remove the specified prefix from target variables
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-10-19 00:35:35 +02:00
Jiuzhu Dong 2cfda2bffd binfmt: remove file_ioctl and get filename by strrchr
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
2021-09-13 08:56:10 +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
jordi f3af6edf93 Kconfig: add quotes in source to clean warnings from setconfig
To avoid the setconfig warning "style: quotes recommended around xxx in
source xxx"
2021-07-23 02:32:19 -07:00
Xiang Xiao 841a4922aa binfmt: Replace all nx_ API with file_ API
since binfmt is a kernel component

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-06 11:18:13 +09:00
Abdelatif Guettouche af5e0c620f Rename MODULE_TEXT to TEXT_HEAP as the latter is more generic.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-06-18 07:14:17 -05:00
Xiang Xiao 34f31ff3f8 binfmt: Handle argv/argv[0] == NULL correctly in exec_module
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-15 13:55:01 -06:00
Xiang Xiao bec68ad8ea sched/posix_spawn: Don't insert name at the begin of argv
since the standard require the caller pass the name explicitly
https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html:
The argument argv is an array of character pointers to null-terminated strings.
The last member of this array shall be a null pointer and is not counted in argc.
These strings constitute the argument list available to the new process image.
The value in argv[0] should point to a filename that is associated with the
process image being started by the posix_spawn() or posix_spawnp() function.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-15 07:32:33 -06:00
Xiang Xiao 90f71bd017 Revert "sched/posix_spawn: Don't insert name at the begin of argv"
This reverts commit 032086870d.
2021-06-15 07:32:33 -06:00
Xiang Xiao 032086870d sched/posix_spawn: Don't insert name at the begin of argv
since the standard require the caller pass the name explicitly
https://pubs.opengroup.org/onlinepubs/009695399/functions/posix_spawn.html:
The argument argv is an array of character pointers to null-terminated strings.
The last member of this array shall be a null pointer and is not counted in argc.
These strings constitute the argument list available to the new process image.
The value in argv[0] should point to a filename that is associated with the
process image being started by the posix_spawn() or posix_spawnp() function.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Id79ffcc501ae9552dc4e908418ff555f498be7f1
2021-06-14 07:11:53 -06:00
Masayuki Ishikawa 304d72ed00 binfmt: Call up_module_text_free() in unload_module()
Summary:
- I noticed that up_module_text_free() is not called
  if CONFIG_ARCH_USE_MODULE_TEXT=y
- This commit fixes this issue

Impact:
- None

Testing:
- Tested with spresense

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-06-04 01:40:37 -05:00
Xiang Xiao 2e54df0f35 Don't include assert.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-03 08:36:03 -07:00
Masayuki Ishikawa 4d492104a7 binfmt: Introduce a separate text memory for ELF
Summary:
- This commit introduces a separate text memory for ELF
- The logic is similar to modlib

Impact:
- None

Testing:
- Tested with spresense:elf
- NOTE: needs separate commits

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-06-02 02:27:04 -05:00
Xiang Xiao bebdbc5c87 binfmt: Remove filename/exports/nexports from binary_s
to simplify the life cycle management

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-02 15:20:38 +09:00
Xiang Xiao cf78a5b6cf binfmt: Move argv copy into exec_module
and remove the related fields from struct binary_s

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-02 15:20:38 +09:00
Xiang Xiao d7f96003cf Don't include debug.h from public header file
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-06-01 06:42:02 +09:00