文件描述符自动回收支持

This commit is contained in:
zhangzheng
2025-03-03 23:03:28 +08:00
parent c8a5262463
commit 543a618de9
23 changed files with 568 additions and 150 deletions

View File

@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.13)
# add_subdirectory(coremark)
# add_subdirectory(tinycc-arm-thumb)
add_subdirectory(test)
add_subdirectory(test2)
add_subdirectory(vi)
add_subdirectory(binutils-2.33.1)
# add_subdirectory(share_lib_test)

View File

@@ -0,0 +1,64 @@
cmake_minimum_required(VERSION 3.13)
file(
GLOB deps
*.c
)
add_executable(
tst2.elf
${deps}
${START_SRC}
)
target_link_libraries(
tst2.elf
PUBLIC
-Bstatic
${LIBC_NAME}
--whole-archive
${START_LIB}
libc_be
sys
sys_util
sys_svr
--no-whole-archive
${GCC_LIB_PATH}/libgcc.a
)
target_include_directories(
tst2.elf
PUBLIC
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys/inc
${CMAKE_SOURCE_DIR}/mkrtos_user/lib/sys_svr/inc
${CMAKE_CURRENT_SOURCE_DIR}/
${CMAKE_SOURCE_DIR}/mkrtos_user/user/drv/lib/mk_pin
${CMAKE_SOURCE_DIR}/mkrtos_user/user/drv/lib/mk_drv
${CMAKE_SOURCE_DIR}/mkrtos_user/user/drv/lib/mk_display
)
add_dependencies(
tst2.elf
${START_LIB}
sys
sys_util
)
set_target_properties(
tst2.elf PROPERTIES LINK_FLAGS
"-T ${CMAKE_CURRENT_LIST_DIR}/${ARCH_NAME}/link.lds ${CORTEX_M_LINK_FLAGS} --gc-section -no-dynamic-linker "
#--no-warn-rwx-segments
)
add_custom_target(
tst2_dump ALL
COMMAND
${CMAKE_OBJCOPY} -O binary -S tst2.elf tst2.bin
COMMAND
${CMAKE_SIZE} tst2.elf
COMMAND
${CMAKE_COMMAND} -E copy tst2.bin ${CMAKE_SOURCE_DIR}/build/output/cpio/tst2
COMMAND
cp tst2.elf ${CMAKE_SOURCE_DIR}/build/output/tst2.elf
)
add_dependencies(tst2_dump tst2.elf)

View File

@@ -0,0 +1,124 @@
ENTRY(_start_)
SECTIONS
{
.text : {
. = ALIGN(4);
__text_start__ = .;
KEEP(*(.first))
*(.text)
*(.text.*)
KEEP(*(.init))
KEEP(*(.fini))
/* .ctors */
*crtbegin.o(.ctors)
*crtbegin?.o(.ctors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors)
*(SORT(.ctors.*))
*(.ctors)
/* .dtors */
*crtbegin.o(.dtors)
*crtbegin?.o(.dtors)
*(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors)
*(SORT(.dtors.*))
*(.dtors)
*(SORT(.rodata.*))
*(.rodata)
KEEP(*(.eh_frame*))
. = ALIGN(4);
__rel_start__ = .;
*(.rel.data .rel.data.* .rel.gnu.linkonce.d.*)
__rel_end__ = .;
}
.ARM.exidx : {
. = ALIGN(4);
__exdix_start = .;
*(.ARM.exidx* .gnu.linkonce.armexidx.*)
/* This is used by the startup in order to initialize the .data secion */
__exdix_end = .;
}
.permissions_table : {
. = ALIGN(4);
__permissions_table_start__ = .;
KEEP(*(.permissions_table))
__permissions_table_end__ = .;
}
PROVIDE(__ram_size__ = __bss_end__ - __data_start__);
.data : {
. = ALIGN(4);
__data_start__ = .;
__got_start__ = .;
*(.got)
__got_end__ = .;
. = ALIGN(4);
*(.data)
*(.data.*)
*(vtable)
*(.data*)
. = ALIGN(4);
/* preinit data */
PROVIDE_HIDDEN (__preinit_array_start = .);
KEEP(*(.preinit_array))
PROVIDE_HIDDEN (__preinit_array_end = .);
. = ALIGN(4);
/* init data */
PROVIDE_HIDDEN (__init_array_start = .);
KEEP(*(SORT(.init_array.*)))
KEEP(*(.init_array))
PROVIDE_HIDDEN (__init_array_end = .);
. = ALIGN(4);
/* finit data */
PROVIDE_HIDDEN (__fini_array_start = .);
KEEP(*(SORT(.fini_array.*)))
KEEP(*(.fini_array))
PROVIDE_HIDDEN (__fini_array_end = .);
. = ALIGN(4);
_shell_command_start = .;
KEEP(*(shellCommand))
_shell_command_end = .;
. = ALIGN(4);
/* All data end */
__data_end__ = .;
}
PROVIDE(__heap_size__ = __heap_end__ - __heap_start__);
PROVIDE(__stack_size__ = __stack_end__ - __stack_start__);
.bss : {
. = ALIGN(4);
/* This is used by the startup in order to initialize the .bss secion */
__bss_start__ = .;
*(.bss)
*(COMMON)
. = ALIGN(4);
__heap_start__ = .;
KEEP(*(.bss.heap))
__heap_end__ = .;
. = ALIGN(4);
__stack_start__ = .;
KEEP(*(.bss.stack))
__stack_end__ = .;
*(.bss.*)
/* This is used by the startup in order to initialize the .bss secion */
. = ALIGN(4);
__bss_end__ = .;
}
_end = .;
}

View File

@@ -0,0 +1,17 @@
#define HEAP_SIZE (10*1024)
#define STACK_SIZE (1024 * 2)
#if defined(__CC_ARM)
#define HEAP_ATTR SECTION("HEAP") __attribute__((zero_init))
#define STACK_ATTR SECTION("STACK") __attribute__((zero_init))
#elif defined(__GNUC__)
#define HEAP_ATTR __attribute__((__section__(".bss.heap")))
#define STACK_ATTR __attribute__((__section__(".bss.stack")))
#elif defined(__IAR_SYSTEMS_ICC__)
#define HEAP_ATTR
#define STACK_ATTR
#endif
__attribute__((used)) HEAP_ATTR static char _____heap_____[HEAP_SIZE];
__attribute__((used)) STACK_ATTR static char _____stack_____[STACK_SIZE];

View File

@@ -0,0 +1,24 @@
#include "u_task.h"
#include <assert.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <u_sleep.h>
#include <u_vmam.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int fd;
task_set_obj_name(TASK_THIS, TASK_THIS, "tk_tst2");
task_set_obj_name(TASK_THIS, THREAD_MAIN, "th_tst2");
fd = open("/mnt/1.txt", O_RDWR | O_CREAT, 0777);
if (fd < 0) {
printf("open faile:%d.\n", fd);
return fd;
}
exit(-3333);
return 0;
}