18#ifndef __VSF_LINUX_INTERNAL_H__
19#define __VSF_LINUX_INTERNAL_H__
30#if VSF_USE_LINUX == ENABLED
32#if VSF_LINUX_CFG_RELATIVE_PATH == ENABLED
46#if defined(__VSF_LINUX_CLASS_IMPLEMENT)
47# define __VSF_CLASS_IMPLEMENT__
48#elif defined(__VSF_LINUX_CLASS_INHERIT__)
49# define __VSF_CLASS_INHERIT__
60#if VSF_KERNEL_CFG_EDA_SUPPORT_ON_TERMINATE != ENABLED
61# error VSF_KERNEL_CFG_EDA_SUPPORT_ON_TERMINATE MUST be enabled to use vsf_linux
64#if VSF_USE_SIMPLE_STREAM != ENABLED
65# error VSF_USE_SIMPLE_STREAM MUST be enabled to use vsf_linux
68#if VSF_USE_HEAP != ENABLED
69# error VSF_USE_HEAP MUST be enabled to use vsf_linux
72#ifndef VSF_LINUX_CFG_STACKSIZE
73# if defined(VSF_KERNEL_CFG_THREAD_STACK_PAGE_SIZE) && defined(VSF_KERNEL_CFG_THREAD_STACK_GUARDIAN_SIZE)
74# if (VSF_KERNEL_CFG_THREAD_STACK_PAGE_SIZE + VSF_KERNEL_CFG_THREAD_STACK_GUARDIAN_SIZE) < 1024
75# define VSF_LINUX_CFG_STACKSIZE 1024
77# define VSF_LINUX_CFG_STACKSIZE (VSF_KERNEL_CFG_THREAD_STACK_PAGE_SIZE + VSF_KERNEL_CFG_THREAD_STACK_GUARDIAN_SIZE)
80# define VSF_LINUX_CFG_STACKSIZE 1024
83#if VSF_LINUX_CFG_STACKSIZE > 0xFFFF
84# if VSF_KERNEL_CFG_THREAD_STACK_LARGE != ENABLED
85# error stacks should be 16-bit if VSF_KERNEL_CFG_THREAD_STACK_LARGE is not enabled
88#if (VSF_LINUX_CFG_STACKSIZE < (VSF_KERNEL_CFG_THREAD_STACK_PAGE_SIZE + VSF_KERNEL_CFG_THREAD_STACK_GUARDIAN_SIZE))\
89 || (VSF_LINUX_CFG_STACKSIZE & (VSF_KERNEL_CFG_THREAD_STACK_PAGE_SIZE - 1))
90# error invalid VSF_LINUX_CFG_STACKSIZE
95#define vsf_linux_thread_get_priv(__thread) (void *)(&(((vsf_linux_thread_t *)(__thread))[1]))
133#if VSF_LINUX_CFG_PLS_NUM > 0 || VSF_LINUX_CFG_TLS_NUM > 0
134typedef struct vsf_linux_localstorage_t {
136 void (*destructor)(
void *
data);
137} vsf_linux_localstorage_t;
139typedef struct vsf_linux_dynlib_mod_t {
145 void (*init)(
void *ctx);
146} vsf_linux_dynlib_mod_t;
148typedef struct vsf_linux_dynlib_t {
162#if VSF_LINUX_CFG_SUPPORT_SIG == ENABLED
171#if VSF_LINUX_CFG_PLS_NUM > 0
175#if VSF_LINUX_CFG_TLS_NUM > 0
181 implement(vsf_thread_t)
182 implement(vsf_thread_cb_t)
195#if VSF_LINUX_CFG_SUPPORT_SIG == ENABLED
198#if VSF_LINUX_CFG_TLS_NUM > 0
201#if VSF_ARCH_USE_THREAD_REG == ENABLED \
202 && VSF_LINUX_USE_SIMPLE_LIBC == ENABLED && VSF_LINUX_USE_SIMPLE_STDLIB == ENABLED\
203 && VSF_LINUX_APPLET_USE_LIBC_STDLIB == ENABLED && !defined(__VSF_APPLET__)
207 } process_reg_backup;
217 unsigned short wantval;
240#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
252#if VSF_LINUX_USE_SIMPLE_LIBC == ENABLED && VSF_LINUX_USE_SIMPLE_STDLIB == ENABLED\
253 && VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED
261#if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR_TRACE_CALLER == ENABLED
270# if VSF_LINUX_SIMPLE_STDLIB_HEAP_MONITOR_MAX == ENABLED
282#if VSF_LINUX_LIBC_USE_ENVIRON == ENABLED
285#if VSF_LINUX_USE_VFORK == ENABLED
286 jmp_buf __vfork_jmpbuf;
291#
if VSF_ARCH_USE_THREAD_REG ==
ENABLED
304#if VSF_KERNEL_CFG_EDA_SUPPORT_TIMER == ENABLED
308#if VSF_LINUX_USE_SIMPLE_LIBC == ENABLED && VSF_LINUX_USE_SIMPLE_STDLIB == ENABLED\
309 && VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED
316#define __VSF_LINUX_PROCESS_HAS_PATH (VSF_LINUX_USE_PROCFS == ENABLED || VSF_LINUX_USE_APPLET == ENABLED || VSF_LINUX_USE_SCRIPT == ENABLED)
317#if __VSF_LINUX_PROCESS_HAS_PATH
321#if VSF_USE_LOADER == ENABLED
337#if VSF_LINUX_CFG_SUPPORT_SIG == ENABLED
351#if VSF_LINUX_USE_VFORK == ENABLED
355#if VSF_LINUX_CFG_PLS_NUM > 0
357 vsf_bitmap(vsf_linux_pls_bitmap) dynlib_bitmap;
362#if VSF_LINUX_CFG_TLS_NUM > 0
374#if VSF_LINUX_USE_APPLET == ENABLED
378#if VSF_LINUX_CFG_PLS_NUM > 0
386# ifndef __VSF_APPLET__
391#if defined(__VSF_APPLET__) && (defined(__VSF_APPLET_LIB__) || defined(__VSF_APPLET_LINUX_FUNDMENTAL_LIB__))\
392 && VSF_APPLET_CFG_ABI_PATCH != ENABLED && VSF_LINUX_USE_APPLET == ENABLED
394#ifndef VSF_LINUX_APPLET_FUNDMENTAL_VPLT
395# if VSF_LINUX_USE_APPLET == ENABLED
396# define VSF_LINUX_APPLET_FUNDMENTAL_VPLT \
397 ((vsf_linux_fundmental_vplt_t *)(VSF_LINUX_APPLET_VPLT->fundmental_vplt))
399# define VSF_LINUX_APPLET_FUNDMENTAL_VPLT \
400 ((vsf_linux_fundmental_vplt_t *)vsf_vplt((void *)0))
404#define VSF_LINUX_APPLET_FUNDMENTAL_ENTRY(__NAME) \
405 VSF_APPLET_VPLT_ENTRY_FUNC_ENTRY(VSF_LINUX_APPLET_FUNDMENTAL_VPLT, __NAME)
406#define VSF_LINUX_APPLET_FUNDMENTAL_IMP(...) \
407 VSF_APPLET_VPLT_ENTRY_FUNC_IMP(VSF_LINUX_APPLET_FUNDMENTAL_VPLT, __VA_ARGS__)
409#if VSF_LINUX_CFG_PLS_NUM > 0
410VSF_LINUX_APPLET_FUNDMENTAL_IMP(vsf_linux_dynlib_ctx_get,
void *,
const vsf_linux_dynlib_mod_t *mod) {
412 return VSF_LINUX_APPLET_FUNDMENTAL_ENTRY(vsf_linux_dynlib_ctx_get)(mod);
414VSF_LINUX_APPLET_FUNDMENTAL_IMP(vsf_linux_dynlib_ctx_set,
int,
const vsf_linux_dynlib_mod_t *mod,
void *ctx) {
416 return VSF_LINUX_APPLET_FUNDMENTAL_ENTRY(vsf_linux_dynlib_ctx_set)(mod, ctx);
424# if VSF_USE_LOADER == ENABLED
433#if VSF_LINUX_CFG_PLS_NUM > 0
434extern void * vsf_linux_dynlib_ctx_get(
const vsf_linux_dynlib_mod_t *mod);
435extern int vsf_linux_dynlib_ctx_set(
const vsf_linux_dynlib_mod_t *mod,
void *ctx);
438#define vsf_linux_dynlib_ctx vsf_linux_dynlib_ctx_get
443# if VSF_USE_LOADER == ENABLED
465#if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR == ENABLED
467# if VSF_LINUX_SIMPLE_STDLIB_CFG_HEAP_MONITOR_TRACE_CALLER == ENABLED
468# define __malloc_ex(__process, __size) ____malloc_ex((__process), (__size), __FILE__, __FUNCTION__, __LINE__)
469# define __calloc_ex(__process, __n, __size) ____calloc_ex((__process), (__n), (__size), __FILE__, __FUNCTION__, __LINE__)
470# define __realloc_ex(__process, __ptr, __size) ____realloc_ex((__process), (__ptr), (__size), __FILE__, __FUNCTION__, __LINE__)
471# define __strdup_ex(__process, __str) ____strdup_ex((__process), (char *)(__str), __FILE__, __FUNCTION__, __LINE__)
473# define __malloc_ex(__process, __size) ____malloc_ex((__process), (__size), NULL, NULL, 0)
474# define __calloc_ex(__process, __n, __size) ____calloc_ex((__process), (__n), (__size), NULL, NULL, 0)
475# define __realloc_ex(__process, __ptr, __size) ____realloc_ex((__process), (__ptr), (__size), NULL, NULL, 0)
476# define __strdup_ex(__process, __str) ____strdup_ex((__process), (char *)(__str), NULL, NULL, 0)
479# define __malloc_ex(__process, __size) vsf_linux_process_heap_malloc((__process), (__size))
480# define __calloc_ex(__process, __n, __size) vsf_linux_process_heap_calloc((__process), (__n), (__size))
481# define __free_ex(__process, __ptr) vsf_linux_process_heap_free((__process), (__ptr))
482# define __realloc_ex(__process, __ptr, __size) vsf_linux_process_heap_realloc((__process), (__ptr), (__size))
483# define __strdup_ex(__process, __str) vsf_linux_process_heap_strdup((__process), (char *)(__str))
498#if VSF_LINUX_CFG_PLS_NUM > 0
499extern vsf_err_t vsf_linux_library_init(
int *lib_idx,
void *lib_ctx,
void (*destructor)(
void *));
500extern void * vsf_linux_library_ctx(
int lib_idx);
502extern vsf_err_t vsf_linux_dynlib_init(
int *lib_idx,
int module_num,
int bss_size);
506#if VSF_LINUX_CFG_PLS_NUM > 0
507extern int vsf_linux_pls_alloc(
void);
508extern void vsf_linux_pls_free(
int idx);
509extern vsf_linux_localstorage_t * vsf_linux_pls_get(
int idx);
512#if defined(__VSF_LINUX_CLASS_IMPLEMENT) || defined(__VSF_LINUX_CLASS_INHERIT__)
513# if VSF_LINUX_CFG_TLS_NUM > 0
514extern int vsf_linux_tls_alloc(
void (*destructor)(
void *));
515extern void vsf_linux_tls_free(
int idx);
516extern vsf_linux_localstorage_t * vsf_linux_tls_get(
int idx);
523#define __vsf_linux_start_process_internal3(__entry, __argv, __stack_size, __prio)\
524 __vsf_linux_start_process_internal((__entry), (__argv), (__stack_size), (__prio))
525#define __vsf_linux_start_process_internal2(__entry, __argv, __stack_size) \
526 __vsf_linux_start_process_internal3((__entry), (__argv), (__stack_size), VSF_LINUX_CFG_PRIO_LOWEST)
527#define __vsf_linux_start_process_internal1(__entry, __argv) \
528 __vsf_linux_start_process_internal2((__entry), (__argv), 0)
529#define __vsf_linux_start_process_internal0(__entry) \
530 __vsf_linux_start_process_internal1(__entry, NULL)
533#define vsf_linux_start_process_internal(__entry, ...) \
534 __PLOOC_EVAL(__vsf_linux_start_process_internal, __VA_ARGS__)((__entry), ##__VA_ARGS__)
546#if VSF_ARCH_USE_THREAD_REG == ENABLED
557 int stack_size,
void *stack);
589#undef __VSF_LINUX_CLASS_IMPLEMENT
590#undef __VSF_LINUX_CLASS_INHERIT__
#define ENABLED
Definition __type.h:28
vsf_err_t
Definition __type.h:42
Definition vsf_heap.h:114
Definition vsf_linux.h:278
Definition vsf_linux.h:179
Definition vsf_linux.h:158
Definition vsf_simple_stream.h:254
uint64_t vsf_systimer_tick_t
Definition cortex_a_generic.h:73
struct ieee80211_ext_chansw_ie data
Definition ieee80211.h:80
__le16 timeout
Definition ieee80211.h:94
int pid_t
Definition types.h:85
int key_t
Definition types.h:84
#define PATH_MAX
Definition limits.h:11
unsigned short uint16_t
Definition lvgl.h:41
unsigned int uint32_t
Definition lvgl.h:43
unsigned char uint8_t
Definition lvgl.h:40
#define vsf_dcl_class
Definition ooc_class.h:46
#define vsf_class(__name)
Definition ooc_class.h:48
void(* sighandler_t)(int)
Definition signal.h:40
uint32_t uintptr_t
Definition stdint.h:38
unsigned int uint_fast32_t
Definition stdint.h:27
Definition vsf_list.h:888
Definition vsf_list.h:883
Definition vsf_linux.h:375
vsf_vplt_info_t info
Definition vsf_linux.h:376
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_linux_get_cur_process)
VSF_APPLET_VPLT_ENTRY_FUNC_DEF(vsf_linux_loader_keep_ram)
Definition vsf_linux.h:268
vsf_dlist_t list
Definition vsf_linux.h:274
size_t usage
Definition vsf_linux.h:269
size_t max_usage
Definition vsf_linux.h:271
int balance
Definition vsf_linux.h:273
Definition vsf_linux.h:128
vsf_dlist_node_t node
Definition vsf_linux.h:129
key_t key
Definition vsf_linux.h:130
Definition vsf_linux.h:109
int argc
Definition vsf_linux.h:110
char const ** argv
Definition vsf_linux.h:111
Definition vsf_linux.h:123
vsf_linux_process_arg_t arg
Definition vsf_linux.h:124
vsf_linux_main_entry_t entry
Definition vsf_linux.h:125
Definition vsf_linux.h:223
void(* sigaction_handler)(int, siginfo_t *, void *)
Definition vsf_linux.h:230
vsf_dlist_node_t node
Definition vsf_linux.h:224
uint8_t sig
Definition vsf_linux.h:225
sighandler_t sighandler
Definition vsf_linux.h:229
sigset_t mask
Definition vsf_linux.h:227
uint32_t flags
Definition vsf_linux.h:226
Definition vsf_linux.h:234
vsf_stream_t * err
Definition vsf_linux.h:237
vsf_stream_t * out
Definition vsf_linux.h:236
vsf_stream_t * in
Definition vsf_linux.h:235
Definition vsf_linux.h:117
void(* on_run)(vsf_thread_cb_t *cb)
Definition vsf_linux.h:119
int priv_size
Definition vsf_linux.h:118
void(* on_terminate)(vsf_linux_thread_t *thread)
Definition vsf_linux.h:120
Definition vsf_linux.h:241
int overrun
Definition vsf_linux.h:244
struct itimerspec value
Definition vsf_linux.h:242
vsf_systimer_tick_t start
Definition vsf_linux.h:246
vsf_callback_timer_t timer
Definition vsf_linux.h:245
struct sigevent evt
Definition vsf_linux.h:243
Definition vsf_linux.h:255
const char * file
Definition vsf_linux.h:263
int line
Definition vsf_linux.h:262
size_t size
Definition vsf_linux.h:259
vsf_dlist_node_t node
Definition vsf_linux.h:256
const char * func
Definition vsf_linux.h:264
void * ptr
Definition vsf_linux.h:258
@ ITIMER_NUM
Definition time.h:39
#define _exit
Definition unistd.h:91
#define dcl_vsf_bitmap(__name, __bit_size)
Definition vsf_bitmap.h:98
#define vsf_bitmap(__name)
Definition vsf_bitmap.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_DEF(__NAME)
Definition vsf_cfg.h:156
#define __VSF_VPLT_DECORATOR__
Definition vsf_cfg.h:93
#define VSF_APPLET_VPLT_ENTRY_FUNC_TRACE()
Definition vsf_cfg.h:165
@ VSF_EVT_USER
Definition vsf_eda.h:621
VSF_KERNEL_TIMEOUT_TICK_T vsf_timeout_tick_t
Definition vsf_eda.h:592
uint_fast32_t alignment
Definition vsf_heap.h:135
vsf_prio_t
Definition vsf_kernel_common.h:37
uintptr_t vsf_linux_set_process_reg(uintptr_t reg)
Definition vsf_linux.c:1577
int vsf_linux_trigger_signal(vsf_linux_trigger_t *trig, int sig)
Definition vsf_linux.c:694
int vsf_linux_start_process(vsf_linux_process_t *process)
Definition vsf_linux.c:1371
VSF_CAL_NO_RETURN void vsf_linux_exit_process(int status, bool _exit)
Definition vsf_linux.c:1455
vsf_linux_process_t * vsf_linux_create_process(int stack_size, int heap_size, int priv_size)
Definition vsf_linux.c:1341
int vsf_linux_trigger_pend(vsf_linux_trigger_t *trig, vsf_timeout_tick_t timeout)
Definition vsf_linux.c:714
void vsf_linux_cleanup_process(vsf_linux_process_t *process)
Definition vsf_linux.c:1380
void vsf_linux_thread_on_terminate(vsf_linux_thread_t *thread)
Definition vsf_linux.c:1812
vsf_linux_process_t * __vsf_linux_start_process_internal(vsf_linux_main_entry_t entry, char *const *argv, int stack_size, vsf_prio_t prio)
Definition vsf_linux.c:1583
void vsf_linux_trigger_init(vsf_linux_trigger_t *trig)
Definition vsf_linux.c:685
vsf_linux_process_t * vsf_linux_get_process(pid_t pid)
Definition vsf_linux.c:1604
int vsf_linux_wait_thread(int tid, int *retval)
Definition vsf_linux.c:1875
int vsf_linux_merge_env(vsf_linux_process_t *process, char **env)
Definition vsf_linux.c:653
bool vsf_linux_is_inited(void)
Definition vsf_linux.c:991
int __vsf_linux_process_parse_arg(vsf_linux_process_t *process, vsf_linux_process_arg_t *arg, char *const *argv)
Definition vsf_linux.c:861
void __vsf_linux_process_free_arg(vsf_linux_process_t *process)
Definition vsf_linux.c:848
void vsf_linux_free_env(vsf_linux_process_t *process)
Definition vsf_linux.c:672
vsf_linux_process_t * vsf_linux_get_real_process(vsf_linux_process_t *process)
Definition vsf_linux.c:351
vsf_linux_thread_t * vsf_linux_get_thread(pid_t pid, int tid)
Definition vsf_linux.c:1617
void vsf_linux_detach_process(vsf_linux_process_t *process)
Definition vsf_linux.c:1852
void vsf_linux_detach_thread(vsf_linux_thread_t *thread)
Definition vsf_linux.c:1863
void vsf_linux_delete_process(vsf_linux_process_t *process)
Definition vsf_linux.c:1445
int vsf_linux_fs_get_executable(const char *pathname, vsf_linux_main_entry_t *entry)
Definition vsf_linux.c:2949
int vsf_linux_start_thread(vsf_linux_thread_t *thread, vsf_prio_t priority)
Definition vsf_linux.c:1181
vsf_linux_thread_t * vsf_linux_create_thread(vsf_linux_process_t *process, const vsf_linux_thread_op_t *op, int stack_size, void *stack)
Definition vsf_linux.c:1162
int(* vsf_linux_main_entry_t)(int, char **)
Definition vsf_linux.h:114
void * vsf_linux_process_heap_malloc_aligned(vsf_linux_process_t *process, uint_fast32_t size, uint_fast32_t alignment)
Definition vsf_linux.c:1226
int(* vsf_linux_process_arg_parser_t)(vsf_linux_process_arg_t *arg)
Definition vsf_linux.h:115
void * vsf_linux_malloc_res(size_t size)
Definition vsf_linux.c:966
int vsf_linux_chdir(vsf_linux_process_t *process, char *working_dir)
Definition vsf_linux_fs.c:1596
void * vsf_linux_process_heap_malloc(vsf_linux_process_t *process, size_t size)
Definition vsf_linux.c:1236
void vsf_linux_set_errno(int err)
int vsf_linux_get_errno(void)
vsf_systimer_tick_t vsf_linux_sleep(vsf_timeout_tick_t ticks)
Definition vsf_linux.c:3014
char * vsf_linux_process_heap_strdup(vsf_linux_process_t *process, char *str)
Definition vsf_linux.c:1272
vsf_eda_t * vsf_linux_get_kernel_task(void)
Definition vsf_linux.c:918
void * vsf_linux_process_heap_realloc(vsf_linux_process_t *process, void *buffer, uint_fast32_t size)
Definition vsf_linux.c:1206
int vsf_linux_fs_bind_executable(char *path, vsf_linux_main_entry_t entry)
Definition vsf_linux.c:2978
int vsf_linux_fd_bind_executable(int fd, vsf_linux_main_entry_t entry)
Definition vsf_linux.c:2969
@ __VSF_EVT_LINUX_EVENTFD_INC
Definition vsf_linux.h:102
@ __VSF_EVT_LINUX_TERM_RX
Definition vsf_linux.h:103
void vsf_linux_free_res(void *ptr)
Definition vsf_linux.c:971
int vsf_linux_expandenv(const char *str, char *output, size_t bufflen)
Definition vsf_linux.c:4389
void vsf_linux_loader_keep_ram(void)
Definition vsf_linux.c:4499
size_t vsf_linux_process_heap_size(vsf_linux_process_t *process, void *buffer)
Definition vsf_linux.c:1196
int vsf_linux_generate_path(char *path_out, int path_out_lenlen, char *dir, char *path_in)
Definition vsf_linux.c:781
__VSF_VPLT_DECORATOR__ vsf_linux_fundmental_vplt_t vsf_linux_fundmental_vplt
Definition vsf_linux.c:4735
vsf_linux_process_t * vsf_linux_get_cur_process(void)
Definition vsf_linux.c:1655
void __free_ex(vsf_linux_process_t *process, void *ptr)
Definition vsf_linux_glibc_stdlib.c:122
void vsf_linux_process_heap_free(vsf_linux_process_t *process, void *buffer)
Definition vsf_linux.c:1259
vsf_linux_thread_t * vsf_linux_get_cur_thread(void)
Definition vsf_linux.c:1646
vsf_err_t vsf_linux_init(vsf_linux_stdio_stream_t *stdio_stream)
Definition vsf_linux.c:1004
vsf_linux_process_t * vsf_linux_resources_process(void)
Definition vsf_linux.c:960
void * vsf_linux_process_heap_calloc(vsf_linux_process_t *process, size_t n, size_t size)
Definition vsf_linux.c:1247
#define VSF_LINUX_CFG_FD_BITMAP_SIZE
Definition vsf_linux_cfg.h:38
#define VSF_LINUX_CFG_TLS_NUM
Definition vsf_linux_cfg.h:53
#define VSF_LINUX_CFG_ATEXIT_NUM
Definition vsf_linux_cfg.h:73
#define VSF_LINUX_CFG_PLS_NUM
Definition vsf_linux_cfg.h:49
uint32_t size
Definition vsf_memfs.h:50
uint8_t status
Definition vsf_tgui.h:139
int sig
Definition vsf_thread.h:421