In order to support the compilation of third-party library, we encounter
some situations where the macro is not defined, refer to the common
implementation of other systems and add relevant definitions.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
In order to support the compilation of third-party library, we encounter
some situations where the macro is not defined, refer to the common
implementation of other systems and add relevant definitions.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
In order to support the compilation of third-party library, we encounter
some situations where the macro is not defined, refer to the common
implementation of other systems and add relevant definitions.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
In order to support the compilation of third-party library, we encounter
some situations where the macro is not defined, refer to the common
implementation of other systems and add relevant definitions.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
If cancellation points are enabled, then the following logic is activated in sem_wait(). This causes ECANCELED to be returned every time that sem_wait is called.
int sem_wait(FAR sem_t *sem)
{
...
/* sem_wait() is a cancellation point */
if (enter_cancellation_point())
{
#ifdef CONFIG_CANCELLATION_POINTS
/* If there is a pending cancellation, then do not perform
* the wait. Exit now with ECANCELED.
*/
errcode = ECANCELED;
goto errout_with_cancelpt;
#endif
}
...
Normally this works fine. sem_wait() is the OS API called by the application and will cancel the thread just before it returns to the application. Since it is cancellation point, it should never be called from within the OS.
There there is is one perverse cases where sem_wait() may be nested within another cancellation point. If open() is called, it will attempt to lock a VFS data structure and will eventually call nxmutex_lock(). nxmutex_lock() waits on a semaphore:
int nxmutex_lock(FAR mutex_t *mutex)
{
...
for (; ; )
{
/* Take the semaphore (perhaps waiting) */
ret = _SEM_WAIT(&mutex->sem);
if (ret >= 0)
{
mutex->holder = _SCHED_GETTID();
break;
}
ret = _SEM_ERRVAL(ret);
if (ret != -EINTR && ret != -ECANCELED)
{
break;
}
}
...
}
In the FLAT build, _SEM_WAIT expands to sem_wait(). That causes the error in the logic: It should always expand to nxsem_wait(). That is because sem_wait() is cancellation point and should never be called from with the OS or the C library internally.
The failure occurs because the cancellation point logic in sem_wait() returns -ECANCELED (via _SEM_ERRVAL) because sem_wait() is nested; it needs to return the -ECANCELED error to the outermost cancellation point which is open() in this case. Returning -ECANCELED then causes an infinite loop to occur in nxmutex_lock().
The correct behavior in this case is to call nxsem_wait() instead of sem_wait(). nxsem_wait() is identical to sem_wait() except that it is not a cancelation point. It will return -ECANCELED if the thread is canceled, but only once. So no infinite loop results.
In addition, an nxsem_wait() system call was added to support the call from nxmutex_lock().
This resolves Issue #9695
* libs/libc/machine/arm/armv7-m/arch_elf.c
- Fix cast of error message parameters
* build-globals.sh
- Build the modlib_globals.S file used to resolve symbols when dynamically loading
* libs/libc/modlib/Make.defs
- Build modlib_globals.S for all targets
* libs/libc/modlib/modlib_load.c
- Calculate sizes and text/data addresses based on program headers rather than section headers
- Handle objects with no program headers
* libs/libc/modlib/modlib_bind.c
- Call modlib_readsym with pointer to symbol table
- Add modlib_relocatedyn to manage relocation of symbols with shared object (ET_DYN)
- Differentiate between ET_REL and ET_DYN objects
- Use arch independent symbol ELF_R_SYM
- Cast sizes to avoid warnings
* libs/libc/modlib/modlib_load.c
- Cast sizes to avoid warnings
* include/elf.h
- Add definitions that may be found in shared objects
* include/nuttx/lib/modlib.h
- Add parameter to modlib_readsym prototype
- Add prototypes for:
- modlib_insertsymtab
- modlib_findglobal
- Define Elf_Dyn and Elf_Off according to the elf architecture
- Add fields to mod_loadifno_s:
- Program headers
- Exported symbols
- Data section address
- Padding requirement
- Section index for dynamic symbol table
- Number of symbols exported
- Add prottotype for modlib_freesymtab
* libs/libc/dlfcn/lib_dlclose.c
- Free the symbol table when the dll is closed
* libs/libc/dlfcn/lib_dlopen.c
- Add dump of program headers to debug routine
- Differentiate between ET_REL and ET_DYN objects
* libs/libc/machine/arm/armv7-m/arch_elf.c
- Add handling of R_ARM_RELATIVE and R_ARM_JUMP slot relocation types
* libs/libc/modlib/modlib_loadshdrs.c
- Rename modlib_loadshdrs.c to modlib_loadhdrs.c
- Rename modlib_loadshdrs to modlib_loadhdrs
- Add code to load program headers
* libs/libc/modlib/modlib_symbols.c
- Define entry point structure
- Add offset parameter to modlib_symname() and use to find symbol names
- Add symtab section header parameter to modlib_readsym()
- Add offset parameter to modlib_symvalue() to locate symbol names
- Add modlib_insertsyntab() to create a symbol table for exporting and resolution
- Add findEP() to resolve a symbol in the modlib_global table
- Add modlib_findglobal() to find symbol in the modlib_global table
- Add modlib_freesymtab() to free the symbol table
* libs/libc/modlib/modlib_uninit.c
- Free header and sections from a module_loadinfo_s control block
* libs/libc/modlib/modlib_verify.c
- Handle ET_DYN shared objects
* libs/libc/modlib/modlib_globals.S
- Multi-target global table
- Define library APIs that may be resolved when loading a shared object
EALREADY:
Both Linux(asm-generic/errno.h) and FreeBSD(sys/sys/errno.h) regard it as "Operation already in progress"
ESTALE:
Linux specifically removed the "NFS" description, and we may not only use it for NFS
0ca4343518
The ECANCELED and EOWNERDEAD also use different strings from Linux's header, but their meanings are same, and NuttX's description are more likely to obey POSIX 1003.1-2008, so not changing them.
Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
There is no need to use global spinlock to protect netdev
specific data counters. Allocate per-netdev specific spinlock
to get better locking granularity.
Move C/C++ atomic support checking to compiler.h
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
LED effects must be implemented in the lower-half of the LED driver.
The interface is designed to supports the following LED effects:
- intenisty (PWM)
- Bling (Timer)
- Fade in, Fade out (Ramp)
1. the killpg function can make all the
ltp/open_posix_testsuite/killpg testcaes passed
2. Nuttx do not support process group, so we use kill process instead
3. the implementation are referred to:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/killpg.html
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
since symbols defined in arch/elf.h is also used in other case, for example:
CC: pthread/pthread_testcancel.c machine/arm/gnu_unwind_find_exidx.c:32:8: error: unknown type name '__EIT_entry'
32 | static __EIT_entry *__exidx_start_elf;
| ^~~~~~~~~~~
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
1. the getpgrp function can help to pass the ltp/open_posix_teststuite/killpg related testcases
2. Nuttx do not support process group, so we use getpid to implement this
3. the implementation are referred to: https://pubs.opengroup.org/onlinepubs/9699919799/functions/getpgrp.html
Signed-off-by: guoshichao <guoshichao@xiaomi.com>
It is used to write the log message to the channel immediately
when the log message is generated in the interrupt context, which
is faster than the normal force callback.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
syslog_force is used to force the syslog output to the
console in interrupt context, but we can use syslog_write
to do the same(and more) thing.
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This function will use gcc's function
__builtin_dynamic_object_size and __builtin_object_size
Its function is to obtain the size of the object through compilation,
so as to judge whether there are out-of-bounds operations in commonly used functions.
It should be noted that the option -O2 and above is required to enable this function
Signed-off-by: anjiahao <1090959677@qq.com>
When asserting, automatically analyze whether
there is a deadlock in the thread, and if there
is a deadlock, print out the deadlocked thread.
The principle is to analyze whether there is
a lock ring through the tcb holder.
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This PR is a modification that optimizes priority inheritance
for only one holder. After the above modifications are completed,
the mutex lock->unlock process that supports priority inheritance
can be optimized by 200 cycles.
Before modify: 2000 cycle
After modify: 1742 cycle
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
because NuttX doesn't have the device number, so we're not assigning a
valid value here. just memset to zero.
Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
Resolving the issue with the ltp_interfaces_pthread_join_6_2 test case.
In SMP mode, the pthread may still be in the process of exiting when
pthread_join returns, and calling pthread_join again at this time will
result in an error. The error code returned should be ESRCH.
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>