Commit Graph

481 Commits

Author SHA1 Message Date
anjiahao 60796a7063 coredump:add const to memory region struct ptr
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-10-01 20:40:28 +08:00
xuxingliang 7044b10c88 task: use get_task_name where possible
Signed-off-by: xuxingliang <xuxingliang@xiaomi.com>
2024-10-01 20:38:06 +08:00
anjiahao 29e4e71167 modlib/dlfcn:unify same code
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-09-29 15:06:54 +08:00
dongjiuzhu1 1f1d90de1c binfmt/modlib: support loading each sections to different memory for Relocate object
The feature depends on ARCH_USE_SEPARATED_SECTION
the different memory area has different access speed and cache
capability, so the arch can custom allocate them based on
section names to achieve performance optimization

test:
sim:elf
sim:sotest

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2024-09-29 15:06:54 +08:00
xuxin19 1d3dd328dd modify BUILD_LOADABLE to MODULES which backwards-compatible Kernel
maintains the same semantics as Kernel’s module build
and compatible with Kconfiglib implementation.

The problem of kconfiglib not being able to use tri-states is this:
linux is here torvalds/linux@6dd85ff
The module option is extracted from one of the triate three states into a MODULE keyword.
Kconfiglib supports the default implementation of module to be MODULE for compatibility with the linux kernel, and triate degenerates into bool two states
Refer to this code: 061e71f7d7/kconfiglib.py (L4274-L4284)

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-19 08:32:03 +08:00
wanggang26 584931aa0d fix two typos
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2024-09-16 11:25:10 -03:00
Masayuki Ishikawa df298c186f Revert "build depend:Revert Make.dep intermediate ddc file"
This reverts commit ddc3119c4e.
2024-09-15 19:29:47 +08:00
xuxin19 ddc3119c4e build depend:Revert Make.dep intermediate ddc file
Revert "Parallelize depend file generation"
This reverts commit d5b6ec450f.

parallel depend ddc does not significantly speed up compilation,
intermediately generated .ddc files can cause problems if compilation is interrupted unexpectedly

Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2024-09-15 10:01:58 +08:00
hujun5 908df725ad arch: use up_current_regs/up_set_current_regs replace CURRENT_REGS
reason:
1 On different architectures, we can utilize more optimized strategies
  to implement up_current_regs/up_set_current_regs.
eg. use interrupt registersor percpu registers.

code size
before
    text    data     bss     dec     hex filename
 262848   49985   63893  376726   5bf96 nuttx

after
       text    data     bss     dec     hex filename
 262844   49985   63893  376722   5bf92 nuttx

size change -4

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-09-13 23:18:58 +08:00
Alin Jerpelea 61a4ab8966 binfmt: 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-09-10 11:34:18 +08:00
Petro Karashchenko 1528b8dcca nuttx: resolve various 'FAR' and 'CODE' issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-26 10:21:03 +08:00
Petro Karashchenko d499ac9d58 nuttx: fix multiple 'FAR', 'CODE' and style issues
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2024-08-25 19:22:15 +08:00
cuiziwei e21885b84a nuttx/boards:Uniform initialization format for init_array.
(1) Keep the `.init_array` and `.ctors` symbols and sort them according to their initialization priority.
(2) Exclude symbols ending with crtend.* and crtbegin.* to support c++
application.if we not exclude crtend.* crtbegin.* frame_dummy will be
added when enable any c++ application with global variables, this symbol
execution is problematic, removing it does not affect the application.

Signed-off-by: cuiziwei <cuiziwei@xiaomi.com>
2024-08-19 19:48:32 +08:00
anjiahao 5f4c1721ff coredump:support coredump aligned access registers
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2024-08-12 02:02:25 +08:00
Ville Juven 9da9d3ea8c binfmt/elf_loadfile: Set sh_addr even if SHF_ALLOC == 0
Set sh_addr for regions that are not allocated. Some relocations might
depend on this.

The fault in my case occurs when setting CONFIG_HAVE_CXX=y. In this case,
the .ctor and .dtor sections do not get allocated, but the crt code
depends on linker defined symbols _sctors/_ectors etc. These generate PC
relative relocations and thus, the .ctor and .dtor output sections need
an output VMA even though nothing is there. Otherwise the relocations will
point to god knows where (in my case to address 0).

The problem results in full system crash later:
elf_symvalue: Other: 00000000+00000001=00000001
up_relocateadd: PCREL_HI20 at c00002dc [00000417] to sym=0x80409e80 st_value=1
_calc_imm: offset=-3221226203: hi=-786432 lo=-731
up_relocateadd: ERROR: PCREL_HI20 at c00002dc bad:ffffffff40000000
elf_relocateadd: ERROR: Section 2 reloc 52: Relocation failed: -22

The RISC-V elf64 linker does not like the uninitialized PC relative
relocation entries, as the relocation offset cannot be reached with
with the RV64 instruction set.

More about this issue can be found here:
https://github.com/apache/nuttx/pull/11322
2024-08-07 08:45:50 +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
chao an e456c88c09 Revert "sched: replace some global variables to macro"
sched implementation not depends on macro abstraction, so revert below commit:

This reverts commit 4e62d0005a
This reverts commit 0f0c370520
This reverts commit ad0efd04ee

Signed-off-by: chao an <anchao@lixiang.com>
2024-06-06 22:00:25 +08:00
Mingjie Shen 99109b8d79 all: Fix accessing uninitialized local variables
Prior to this commit, in elf_emit() and elf_emit_align(),
ret was uninitialized if total was 0.

Signed-off-by: Mingjie Shen <shen497@purdue.edu>
2024-04-04 11:51:54 +08:00
chao an 4e62d0005a sched: replace some global variables to macro
replace to macro will help to extend the scheduling implementation

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-21 18:51:25 +08:00
chao an 6843b26a66 binfmt/loadmodule: replace kmm_free() to lib_free()
replace kmm_free() to lib_free() unify alloc and free method

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-14 01:00:25 -04:00
chao an 2b7742fc08 binfmt/task/member: remove invaild membership reverse
As long as the process id reversed between parent and child,
the process member ship will automatically reversed.

Fix Regression by PR #11848:

| commit ec08031e4b
| Author: chao an <anchao@lixiang.com>
| Date:   Wed Mar 6 10:13:47 2024 +0800
|
|     sched/group: change type of task group member to single queue
|
|     Change the type of task group member to single list chain to
|     avoid accessing the memory allocator to improve the performance
|
|     Signed-off-by: chao an <anchao@lixiang.com>

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-07 22:53:19 +08:00
chao an ec08031e4b sched/group: change type of task group member to single queue
Change the type of task group member to single list chain to
avoid accessing the memory allocator to improve the performance

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-07 12:39:29 +08:00
chao an 9489953230 sched/tcb: add free tcb flag to support static tcb
Add support for static tcb, applications in some special case can
initialize system resources in advance through static tcb.

|  static struct task_tcb_s g_tcb;
|
|  memset(&g_tcb, 0, sizeof(struct task_tcb_s));
|  g_tcb.cmn.flags = TCB_FLAG_TTYPE_KERNEL;
|  nxtask_init(&g_tcb, "PTCB", 101, NULL, 1024, ptcb_task, NULL, NULL, NULL);
|
|  ...
|  nxtask_activate(&g_tcb.cmn);

Signed-off-by: chao an <anchao@lixiang.com>
2024-03-04 20:05:11 +08:00
Yanfeng Liu 675f775494 log messages of binfmt are very much.
this is to adjust levels of a few of them based on debugging
experiences. These non-critical logs were marked as errors. So we
likely can adjust them as warnings so that real errors can
stand out easily.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2023-12-29 17:36:47 +08:00
Ville Juven 996625ec58 riscv/arch_elf.c: Handle PCREL_HI20/LO12_I/S relocations correctly
There is a problem with the current elf loader for risc-v: when a pair of
PCREL_HI20 / LO12 relocations are encountered, it is assumed that these
will follow each other immediately, as follows:

label:
	auipc      a0, %pcrel_hi(symbol)    // R_RISCV_PCREL_HI20
	load/store a0, %pcrel_lo(label)(a0) // R_RISCV_PCREL_LO12_I/S

With this assumption, the hi/lo relocations are both done when a hi20
relocation entry is encountered, first to the current instruction (addr)
and to the next instruction (addr + 4).

However, this assumption is wrong. There is nothing in the elf relocation
specification[1] that mandates this. Thus, the hi/lo relocation always
needs to first fixup the hi-part, and when the lo-part is encountered, it
needs to find the corresponding hi relocation entry, via the given "label".
This necessitates (re-)visiting the relocation entries for the current
section as well as looking for "label" in the symbol table.

The NuttX elf loader does not allow such operations to be done in the
machine specific part, so this patch fixes the relocation issue by
introducing an architecture specific cache for the hi20 relocation and
symbol table entries. When a lo12 relocation is encountered, the cache
can be consulted to find the hi20 part.

[1] https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/master/riscv-elf.adoc
2023-12-12 17:32:36 -08:00
anjiahao 90517b9f11 coredump:support arm64 coredump
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-12-08 21:33:03 -03:00
chao an 42427e9e29 sched/taskfiles: skip unnecessary file open/close operations to improve performance
The task files should consult the "spawn action" and "O_CLOEXEC flags"
to determine further whether the file should be duplicated.

This PR will further optimize file list duplicating to avoid the performance
regression caused by additional file operations.

Signed-off-by: chao an <anchao@xiaomi.com>
2023-11-16 07:30:36 -08:00
dongjiuzhu1 18819b6b24 sched/task: close file descriptor with O_CLOEXEC before active task or exec
VELAPLATFO-18473

refs:
https://man7.org/linux/man-pages/man2/fcntl.2.html
If the FD_CLOEXEC bit is set, the file descriptor will automatically
be closed during a successful execve(2).
(If the execve(2) fails, the file descriptor is left open.)

modify:
1. Ensure that the child task copies all fds of the parent task,
   including those with O_CLOEXE.
2. Make sure spawn_file_action is executed under fd with O_CLOEXEC,
   otherwise it will fail.
3. When a new task is activated or exec is called, close all fds
   with O_CLOEXEC flags.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 21:15:07 +08:00
dongjiuzhu1 4068f11129 binfmt/elf: Select ARCH_USE_TEXT_HEAP if ARCH_HAVE_TEXT_HEAP
Using up_textheap_memalign to allocate memory if arch support textheap
for loading section.

The default system heap does not support execution permissions,
so up_textheap_memalign allocation is required.

this patch can fix issue about #11043

update esp32 elf config:
remove -CONFIG_ARCH_USE_TEXT_HEAP=y becuase ARCH_CHIP_ESP32 select
ARCH_HAVE_TEXT_HEAP

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-27 15:42:02 +09:00
dongjiuzhu1 e88a36fa92 libs/modlib: Adding architecture-specific memory allocator for dynamic data loading
Arch can specific the memory allocator for data to optimize access speed.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2023-10-26 01:53:38 +08:00
Ville Juven ab78e3817a sched/task_[posix]spawn: Simplify how spawn attributes are handled
Handle task spawn attributes as task spawn file actions are handled.

Why? This removes the need for sched_lock() when the task is being
spawned. When loading the new task from a file the scheduler can be
locked for a VERY LONG time, in the order of hundreds of milliseconds!

This is unacceptable for real time operation.

Also fixes a latent bug in exec_module, spawn_file_actions is executed
at a bad location; when CONFIG_ARCH_ADDRENV=y actions will point to the
new process's address environment (as it is temporarily instantiated at
that point). Fix this by moving it to after addrenv_restore.
2023-10-25 11:55:44 -03:00
wanggang26 e930476b4b enable O_CLOEXEC explicit
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-09-22 13:51:00 +08:00
yangyalei 3017cc4402 Exec: Support run exec in current task
There is a problem when vfork() calls execv() (or execl()) to start a new application:
When the parent thread calls vfork() it receives and gets the pid of the vforked task,
and not the pid of the desired execv'ed application.
see issue #3334

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-09-20 16:53:30 +08:00
Ville Juven 0ef735f93a binfmt/binfmt_execmodule: Copy filename if CONFIG_BUILD_KERNEL and argv=NULL
The 'filename' parameter comes from user space and cannot be accessed
after calling ret = addrenv_select(binp->addrenv, &binp->oldenv); as
it changes the address environment and 'filename' points to who knows
where. In this case, calling nxtask_init(filename...) will cause a crash.

Solve this by making a local copy before changing address environment IF
argv = NULL. Why ? Because argv[0] contains the process name in this case
and the argument vector is already copied into kernel memory, thus
passing argv[0] to nxtask_init(argv[0]...) is safe.
2023-09-16 14:41:52 +08:00
Masayuki Ishikawa 1b97c05ab5 Revert "Exec: Support run exec in current task"
This reverts commit 670c245ff2.
2023-09-16 07:22:32 +03:00
yangyalei 670c245ff2 Exec: Support run exec in current task
Fix the problem when vfork() calls execv() (or execl()) to start a new application:
When the parent thread calls vfork() it receives and gets the pid of the vforked task,
and not the pid of the desired execv'ed application.

issue #3334

Signed-off-by: yangyalei <yangyalei@xiaomi.com>
2023-09-14 22:37:44 +08:00
simbit18 b3973496cd Fix Kconfig style
Remove spaces from Kconfig
Add comments
2023-09-13 21:39:49 +08:00
wangjianyu3 0627b9970e binfmt: The program headers are optional.
Fix problems mentioned in:
https://github.com/apache/nuttx/pull/10462

Brief:
rv-virt:knsh64, qemu-7.2.4
qemu-system-riscv64 -semihosting -nographic -cpu rv64 -smp 8 -M virt,aclint=on -bios none -kernel nuttx
```
[    0.006000] _assert: Current Version: NuttX  12.0.0 8a13da322d Sep  4 2023 14:31:15 risc-v
[    0.006000] _assert: Assertion failed : at file: init/nx_bringup.c:302 task: Idle_Task 0x800017fc
```

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2023-09-05 12:31:31 +08:00
wangjianyu3 8a13da322d binfmt: Support arch copy section by self for dynamic code loading
This option enables architecture-specific memory copy for dynamic code loading.

For example, Ambiq has MRAM regions for instruction which can't load by
the memcpy directly.

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2023-09-04 12:23:26 +08:00
wangjianyu3 c749e4bfbd binfmt: ELF support load to LMA
Load all sections to LMA not VMA, so the startup code(e.g. start.S) need
relocate .data section to the final address(VMA) and zero .bss section by self.

For example, SiFli and Actions: Background: Device with small sram,
Bootloader run in sram and psram, need boot to Application, with memory overlap
and without XIP. VMA of .data is in "psram" and LMA in "rom", if not enable
`ELF_LOADTO_LMA`, ELF loader will load the section to VMA (will fill bootloader
itself).

Signed-off-by: wangjianyu3 <wangjianyu3@xiaomi.com>
2023-09-04 12:23:26 +08:00
chao an 664927c86e mm/alloc: remove all unnecessary cast for alloc
Fix the minor style issue and remove unnecessary cast

Signed-off-by: chao an <anchao@xiaomi.com>
2023-08-30 14:34:20 +08:00
Xiang Xiao cb8df39207 binfmt/elf: Fix the minor style issue
and remove the unused macros and unnecessary cast

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-27 18:46:40 -03:00
xuxin19 f2f0d7fbad cmake:fix drivers build block during cmake reforming
Signed-off-by: xuxin19 <xuxin19@xiaomi.com>
2023-08-16 22:38:52 +08:00
fangxinyong 903e87a7bd builtin: support uid/gid config for binfs app
Implement I_SUID/I_SGID feature for binfs in the POSIX compliant way.
If set-user-ID bit is set in the file permissions, then the effective
user ID of process shall be set to UID of the new process image file.

test case:
hello example emulates to set uid and file set-user-ID bit, and call
geteuid and getegid API.
UID  = 2000
GID  = 3000
MODE = 06555

nsh> ls -l /bin/hello
 -r-sr-sr-x    2000    3000       0 hello
nsh> hello
geteuid:2000
getegid:3000

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-14 01:37:00 +08:00
fangxinyong 2d73e86b47 binfmt: support euid of process set from the file system
From posix spec, if set-user-ID bit is set in the file permissions,
then the effective user ID of the new process shall be set to the
user ID of the new process image file.
Let's ignore whether ST_NOSUID is set on the mounted file system.

https://pubs.opengroup.org/onlinepubs/007904875/functions/exec.html

test step:
hello example build as a module and call geteuid and getegid API.
then set file binary set-user-ID bit on the host.

$ chmod +s apps/bin/hello

nsh> mount -t hostfs -o fs=. /data
nsh> ls -l /data/apps/bin/hello
 -rwsrwsr-x    1000    1000    9264 /data/apps/bin/hello
nsh> /data/apps/bin/hello
geteuid:1000
getegid:1000

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
2023-08-12 02:18:25 +08:00
hujun5 b185f8d889 binfmt: add enter_critical_section
adding enter_critical_section to ensure non preemption in smp
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-08-10 20:46:59 +08:00
Xiang Xiao 6b4e5c0d15 binfmt: Change the default of BINFMT_DISABLE to DEFAULT_SMALL
to optimize the image size when and DEFAULT_SMALL is enabled
and refresh the defconfig in boards/

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-08-10 11:35:41 +03:00
hujun5 9f1cb4135b binfmt/elf: bss section should init to zero
Signed-off-by: hujun5 <hujun5@xiaomi.com>
2023-07-29 06:54:25 -07:00
wanggang26 abc1cade35 binfmt/elf: Support to load ET_EXEC in flat mode
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-07-28 08:35:27 -07:00
wanggang26 9d67c7b6ac binfmt/elf: both regular file and non-regular file (such as /dev/node) should be accessible
Signed-off-by: wanggang26 <wanggang26@xiaomi.com>
2023-07-28 07:52:37 -07:00