summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorHanhui <sylixos@gmail.com>2019-07-15 14:39:06 (GMT)
committer Hanhui <sylixos@gmail.com>2019-07-15 14:39:06 (GMT)
commit679ac04af33953f2715790b8d2ea90cdb60ba444 (patch)
tree68157f1200368058329f1f91103eef4e6fa5999b
parent946f661290dede97e5e6008d3c6f42d5a8f20828 (diff)
parent0c7a4d0f4e368ecbcd85efb75e81a9454b5b9f15 (diff)
downloadAIC-OS-679ac04af33953f2715790b8d2ea90cdb60ba444.zip
Merge branch 'AIC-OS'
-rw-r--r--SylixOS/CHANGELOG3
-rw-r--r--SylixOS/arch/arm/dbg/armDbg.c2
-rw-r--r--SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S12
-rw-r--r--SylixOS/arch/arm64/dbg/arm64Dbg.c2
-rw-r--r--SylixOS/arch/c6x/dbg/c6xDbg.c2
-rw-r--r--SylixOS/arch/csky/dbg/cskyDbg.c2
-rw-r--r--SylixOS/arch/mips/common/mipsExc.c22
-rw-r--r--SylixOS/arch/mips/dbg/mipsDbg.c2
-rw-r--r--SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c5
-rw-r--r--SylixOS/arch/ppc/dbg/ppcDbg.c2
-rw-r--r--SylixOS/arch/riscv/dbg/riscvDbg.c2
-rw-r--r--SylixOS/arch/sparc/dbg/sparcDbg.c2
-rw-r--r--SylixOS/arch/x86/dbg/x86Dbg.c2
-rw-r--r--SylixOS/config/loader/loader_cfg.h1
-rw-r--r--SylixOS/config/net/net_tools_cfg.h1
-rw-r--r--SylixOS/debug/dtrace/dtrace.c12
-rw-r--r--SylixOS/debug/gdb/gdbserver.c4
-rw-r--r--SylixOS/include/arch/arm/asm/assembler.h24
-rw-r--r--SylixOS/kernel/core/_EventSetBlock.c1
-rw-r--r--SylixOS/kernel/core/_ReadyRing.c2
-rw-r--r--SylixOS/kernel/core/_ThreadAffinity.c63
-rw-r--r--SylixOS/kernel/core/_ThreadInit.c7
-rw-r--r--SylixOS/kernel/include/k_class.h3
-rw-r--r--SylixOS/kernel/include/k_const.h16
-rw-r--r--SylixOS/kernel/include/k_internal.h2
-rw-r--r--SylixOS/kernel/include/k_kernel.h2
-rw-r--r--SylixOS/kernel/interface/CpuPerf.c3
-rw-r--r--SylixOS/kernel/interface/KernelParam.c10
-rw-r--r--SylixOS/kernel/interface/RmsPeriod.c1
-rw-r--r--SylixOS/kernel/interface/ThreadAffinity.c37
-rw-r--r--SylixOS/kernel/vmm/pageLib.c2
-rw-r--r--SylixOS/kernel/vmm/pageTable.c9
-rw-r--r--SylixOS/kernel/vmm/virPage.c6
-rw-r--r--SylixOS/kernel/vmm/vmm.c4
-rw-r--r--SylixOS/kernel/vmm/vmm.h4
-rw-r--r--SylixOS/kernel/vmm/vmmAbort.c37
-rw-r--r--SylixOS/kernel/vmm/vmmMalloc.c49
-rw-r--r--SylixOS/kernel/vmm/vmmSwap.h5
-rw-r--r--SylixOS/loader/elf/elf_loader.c15
-rw-r--r--SylixOS/loader/include/loader_lib.h12
-rw-r--r--SylixOS/loader/src/loader.c97
-rw-r--r--SylixOS/loader/src/loader_malloc.c16
-rw-r--r--SylixOS/loader/src/loader_shell.c10
-rw-r--r--SylixOS/loader/src/loader_vpthread.c28
-rw-r--r--SylixOS/mktemp/cl6x.mk4
-rw-r--r--SylixOS/mktemp/common.mk12
-rw-r--r--SylixOS/net/lwip/src/api/api_msg.c4
-rw-r--r--SylixOS/net/lwip/tools/ftp/lwip_ftpd.c4
-rw-r--r--SylixOS/shell/ttinyShell/ttinyShellLib.c6
-rw-r--r--SylixOS/vpmpdm/arch/c6x/libc.c17
50 files changed, 415 insertions, 175 deletions
diff --git a/SylixOS/CHANGELOG b/SylixOS/CHANGELOG
index a29e14e..99fb109 100644
--- a/SylixOS/CHANGELOG
+++ b/SylixOS/CHANGELOG
@@ -4,6 +4,9 @@ HISTORY
++ New features:
+ 2019-07-26: han.hui
+ 加入 TEXT 段保护与调试断点协同工作支持.
+
2019-07-15: han.hui
加入 mmap 匿名映射的内存预分配机制, 提高 AI 运算效率.
diff --git a/SylixOS/arch/arm/dbg/armDbg.c b/SylixOS/arch/arm/dbg/armDbg.c
index 28a94e8..2d9153c 100644
--- a/SylixOS/arch/arm/dbg/armDbg.c
+++ b/SylixOS/arch/arm/dbg/armDbg.c
@@ -198,7 +198,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S b/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
index 19f60c3..d169c49 100644
--- a/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
+++ b/SylixOS/arch/arm/mm/cache/armCacheCommonAsm.S
@@ -189,17 +189,9 @@ FUNC_DEF(armDCacheInvalidate)
;/*********************************************************************************************************
; 将指定虚拟地址的 DCACHE 回写 R0=void *start; R1=void *end; R2=cache line size
-; MMU 初始化写页表映射关系时也会调用此函数, 此时 CACHE 并未使能, ARM1176 会卡死, 所以这里加入使能判断.
;*********************************************************************************************************/
FUNC_DEF(armDCacheFlush)
-#if __SYLIXOS_ARM_ARCH__ == 6
- MRC p15, 0, R3, c1, c0, 0
- AND R3, R3, #P15_R1_C
- CMP R3, #0
- BEQ dcache_not_en
-#endif
-
ARM_DSB()
ARM_ISB()
1:
@@ -209,10 +201,6 @@ FUNC_DEF(armDCacheFlush)
BCC 1b
ARM_DSB()
ARM_ISB()
-
-#if __SYLIXOS_ARM_ARCH__ == 6
-LINE_LABEL(dcache_not_en)
-#endif
BX LR
FUNC_END()
diff --git a/SylixOS/arch/arm64/dbg/arm64Dbg.c b/SylixOS/arch/arm64/dbg/arm64Dbg.c
index 19df355..3828ffb 100644
--- a/SylixOS/arch/arm64/dbg/arm64Dbg.c
+++ b/SylixOS/arch/arm64/dbg/arm64Dbg.c
@@ -178,7 +178,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/c6x/dbg/c6xDbg.c b/SylixOS/arch/c6x/dbg/c6xDbg.c
index 9481c91..44c6f5d 100644
--- a/SylixOS/arch/c6x/dbg/c6xDbg.c
+++ b/SylixOS/arch/c6x/dbg/c6xDbg.c
@@ -178,7 +178,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/csky/dbg/cskyDbg.c b/SylixOS/arch/csky/dbg/cskyDbg.c
index 13e3adf..bf4988c 100644
--- a/SylixOS/arch/csky/dbg/cskyDbg.c
+++ b/SylixOS/arch/csky/dbg/cskyDbg.c
@@ -173,7 +173,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/mips/common/mipsExc.c b/SylixOS/arch/mips/common/mipsExc.c
index 4c68836..42e070f 100644
--- a/SylixOS/arch/mips/common/mipsExc.c
+++ b/SylixOS/arch/mips/common/mipsExc.c
@@ -708,6 +708,26 @@ static VOID archDefaultExceptHandle (addr_t ulRetAddr, addr_t ulAbortAddr)
API_VmmAbortIsr(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur);
}
/*********************************************************************************************************
+** 函数名称: archExecInhibitExceptHandle
+** 功能描述: 执行禁止的异常处理
+** 输 入 : ulRetAddr 返回地址
+** ulAbortAddr 终止地址
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+static VOID archExecInhibitExceptHandle (addr_t ulRetAddr, addr_t ulAbortAddr)
+{
+ PLW_CLASS_TCB ptcbCur;
+ LW_VMM_ABORT abtInfo;
+
+ LW_TCB_GET_CUR(ptcbCur);
+
+ abtInfo.VMABT_uiMethod = LW_VMM_ABORT_METHOD_EXEC;
+ abtInfo.VMABT_uiType = LW_VMM_ABORT_TYPE_PERM;
+ API_VmmAbortIsr(ulRetAddr, ulAbortAddr, &abtInfo, ptcbCur);
+}
+/*********************************************************************************************************
** 函数名称: archMachineCheckExceptHandle
** 功能描述: 机器检查异常处理
** 输 入 : ulRetAddr 返回地址
@@ -760,7 +780,7 @@ static MIPS_EXCEPT_HANDLE _G_mipsExceptHandle[32] = {
* 读阻止例外没使能, 执行阻止例外复用 TLBL 例外
*/
[EXCCODE_TLBRI] = (PVOID)archDefaultExceptHandle, /* TLB Read-Inhibit exception */
- [EXCCODE_TLBXI] = (PVOID)archDefaultExceptHandle, /* TLB Exec-Inhibit exception */
+ [EXCCODE_TLBXI] = (PVOID)archExecInhibitExceptHandle, /* TLB Exec-Inhibit exception */
[EXCCODE_MSADIS] = (PVOID)archDefaultExceptHandle, /* MSA disabled exception */
[EXCCODE_MDMX] = (PVOID)archDefaultExceptHandle, /* MDMX unusable exception */
[EXCCODE_WATCH] = (PVOID)archDefaultExceptHandle, /* Watch address reference */
diff --git a/SylixOS/arch/mips/dbg/mipsDbg.c b/SylixOS/arch/mips/dbg/mipsDbg.c
index 9a88f55..ff586c3 100644
--- a/SylixOS/arch/mips/dbg/mipsDbg.c
+++ b/SylixOS/arch/mips/dbg/mipsDbg.c
@@ -175,7 +175,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
index c78fa5f..977fa72 100644
--- a/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
+++ b/SylixOS/arch/mips/mm/mmu/mipsMmuCommon.c
@@ -215,8 +215,9 @@ static INT mipsMmuGlobalInit (CPCHAR pcMachineName)
#if LW_CFG_CPU_WORD_LENGHT == 64
PG_ELPA | /* 支持 48 位物理地址 */
#endif
- PG_XIE); /* 使能 EntryLo 执行阻止位 */
- /* 执行阻止例外复用 TLBL 例外 */
+ PG_XIE | /* 使能 EntryLo 执行阻止位 */
+ PG_IEC); /* 执行阻止例外在 TLBXI 例外 */
+
/*
* 目前为了通用性, 并没有使能个别处理器(GS264, GS464E, 华睿, 君正)才有的读阻止 RI 位,
* 而是使用 ENTRYLO_V 位来判断映射是否有效
diff --git a/SylixOS/arch/ppc/dbg/ppcDbg.c b/SylixOS/arch/ppc/dbg/ppcDbg.c
index 47df447..78b7e51 100644
--- a/SylixOS/arch/ppc/dbg/ppcDbg.c
+++ b/SylixOS/arch/ppc/dbg/ppcDbg.c
@@ -193,7 +193,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/riscv/dbg/riscvDbg.c b/SylixOS/arch/riscv/dbg/riscvDbg.c
index 01ab183..fd4286d 100644
--- a/SylixOS/arch/riscv/dbg/riscvDbg.c
+++ b/SylixOS/arch/riscv/dbg/riscvDbg.c
@@ -173,7 +173,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/sparc/dbg/sparcDbg.c b/SylixOS/arch/sparc/dbg/sparcDbg.c
index 1eeeca3..0627154 100644
--- a/SylixOS/arch/sparc/dbg/sparcDbg.c
+++ b/SylixOS/arch/sparc/dbg/sparcDbg.c
@@ -175,7 +175,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/arch/x86/dbg/x86Dbg.c b/SylixOS/arch/x86/dbg/x86Dbg.c
index 897505f..fe5f45c 100644
--- a/SylixOS/arch/x86/dbg/x86Dbg.c
+++ b/SylixOS/arch/x86/dbg/x86Dbg.c
@@ -174,7 +174,7 @@ UINT archDbgTrapType (addr_t ulAddr, PVOID pvArch)
if (API_CacheGetOption() & CACHE_TEXT_UPDATE_MP) {
ulCPUId = LW_CPU_GET_CUR_ID();
if (ulLastBpAddr[ulCPUId] == ulAddr) { /* 不是断点的停止 */
- ulLastBpAddr[ulCPUId] = (addr_t)PX_ERROR; /* 同一地址连续失效 */
+ ulLastBpAddr[ulCPUId] = LW_GDB_ADDR_INVAL; /* 同一地址连续失效 */
return (LW_TRAP_INVAL);
} else {
diff --git a/SylixOS/config/loader/loader_cfg.h b/SylixOS/config/loader/loader_cfg.h
index 0424370..6c2fada 100644
--- a/SylixOS/config/loader/loader_cfg.h
+++ b/SylixOS/config/loader/loader_cfg.h
@@ -44,6 +44,7 @@
#define LW_CFG_MODULELOADER_GCOV_EN 1 /* 内核模块代码覆盖率分析接口 */
#define LW_CFG_MODULELOADER_ATEXIT_EN 0 /* 是否允许内核模块 atexit() */
#define LW_CFG_MODULELOADER_FPUCHK_EN 0 /* 是否强行检查 FPU 设置兼容性 */
+#define LW_CFG_MODULELOADER_TEXT_RO_EN 0 /* TEXT 段写保护 */
#define LW_CFG_MODULELOADER_RMMOD_ATREBOOT_EN 0 /* 重启时卸载所有模块 */
#define LW_CFG_MODULELOADER_STRONGSYM_FIRST_EN 0 /* 搜索模块符号时是否优先强符号*/
/* 建议为 0 与其他操作系统一致 */
diff --git a/SylixOS/config/net/net_tools_cfg.h b/SylixOS/config/net/net_tools_cfg.h
index 4653ca0..f6f0e18 100644
--- a/SylixOS/config/net/net_tools_cfg.h
+++ b/SylixOS/config/net/net_tools_cfg.h
@@ -99,6 +99,7 @@
#endif
/* ftp 线程堆栈 */
#define LW_CFG_NET_FTPD_MAX_LINKS 10 /* ftp 最大客户机连接数 */
+#define LW_CFG_NET_FTPD_AUTO_SYNC 0 /* 每次文件写保证 sync (效率低)*/
#define LW_CFG_NET_FTPC_EN 1 /* 是否使能 ftp 客户机 */
/* 推荐使用 ncftp 这样的客户机 */
/*********************************************************************************************************
diff --git a/SylixOS/debug/dtrace/dtrace.c b/SylixOS/debug/dtrace/dtrace.c
index 5cca0ec..fdfd533 100644
--- a/SylixOS/debug/dtrace/dtrace.c
+++ b/SylixOS/debug/dtrace/dtrace.c
@@ -269,7 +269,7 @@ INT API_DtraceBreakTrap (addr_t ulAddr, UINT uiBpType)
if (uiBpType == LW_TRAP_ABORT) { /* 恢复终止点指令 */
archDbgApRemove(ulAddr, ptcbCur->TCB_ulAbortPointInst);
ptcbCur->TCB_ulAbortPointInst = 0;
- ptcbCur->TCB_ulAbortPointAddr = 0;
+ ptcbCur->TCB_ulAbortPointAddr = LW_GDB_ADDR_INVAL;
}
dtm.DTM_ulAddr = ulAddr;
@@ -1145,7 +1145,7 @@ ULONG API_DtraceDelBreakInfo (PVOID pvDtrace,
if (ulThread) {
if (__dtraceReadMsgEx(pdtrace, &dtm, LW_TRUE, ulThread) == ERROR_NONE) {
if ((ulBreakAddr == dtm.DTM_ulAddr) ||
- ((ulBreakAddr == (addr_t)PX_ERROR) && (dtm.DTM_uiType == LW_TRAP_ISTEP))) {
+ ((ulBreakAddr == LW_GDB_ADDR_INVAL) && (dtm.DTM_uiType == LW_TRAP_ISTEP))) {
__dtraceReadMsgEx(pdtrace, &dtm, LW_FALSE, ulThread);
if (bContinue) {
API_ThreadContinue(ulThread);
@@ -1313,7 +1313,7 @@ ULONG API_DtraceThreadStepSet (PVOID pvDtrace, LW_OBJECT_HANDLE ulThread, add
return (EINVAL);
}
- if (ulAddr != (addr_t)PX_ERROR) {
+ if (ulAddr != LW_GDB_ADDR_INVAL) {
archDbgBpPrefetch(ulAddr); /* 预先产生相关页面中断 */
}
@@ -1336,7 +1336,7 @@ ULONG API_DtraceThreadStepSet (PVOID pvDtrace, LW_OBJECT_HANDLE ulThread, add
ptcb = _K_ptcbTCBIdTable[usIndex];
#ifdef __DTRACE_DEBUG
- if (ulAddr == (addr_t)PX_ERROR) {
+ if (ulAddr == LW_GDB_ADDR_INVAL) {
__DTRACE_MSG("[DTRACE] <GDB> Pre-Clear thread 0x%lx Step-Breakpoint @ 0x%08lx.\r\n",
ulThread, ptcb->TCB_ulStepAddr);
@@ -1417,7 +1417,7 @@ VOID API_DtraceSchedHook (LW_OBJECT_HANDLE ulThreadOld, LW_OBJECT_HANDLE ulTh
usIndex = _ObjectGetIndex(ulThreadOld);
ptcb = __GET_TCB_FROM_INDEX(usIndex);
- if (ptcb && (ptcb->TCB_ulStepAddr != (addr_t)PX_ERROR) && !ptcb->TCB_bStepClear) {
+ if (ptcb && (ptcb->TCB_ulStepAddr != LW_GDB_ADDR_INVAL) && !ptcb->TCB_bStepClear) {
archDbgBpRemove(ptcb->TCB_ulStepAddr, sizeof(addr_t),
ptcb->TCB_ulStepInst, (LW_CFG_GDB_SMP_TU_LAZY) ? LW_TRUE : LW_FALSE);
ptcb->TCB_bStepClear = LW_TRUE; /* 单步断点已经被清除 */
@@ -1427,7 +1427,7 @@ VOID API_DtraceSchedHook (LW_OBJECT_HANDLE ulThreadOld, LW_OBJECT_HANDLE ulTh
usIndex = _ObjectGetIndex(ulThreadNew);
ptcb = __GET_TCB_FROM_INDEX(usIndex);
- if ((ptcb->TCB_ulStepAddr != (addr_t)PX_ERROR) && ptcb->TCB_bStepClear) {
+ if ((ptcb->TCB_ulStepAddr != LW_GDB_ADDR_INVAL) && ptcb->TCB_bStepClear) {
archDbgBpInsert(ptcb->TCB_ulStepAddr, sizeof(addr_t),
&ptcb->TCB_ulStepInst, LW_TRUE); /* 仅更新本地 I-CACHE */
ptcb->TCB_bStepClear = LW_FALSE; /* 单步断点生效 */
diff --git a/SylixOS/debug/gdb/gdbserver.c b/SylixOS/debug/gdb/gdbserver.c
index f77fb34..fa1cced 100644
--- a/SylixOS/debug/gdb/gdbserver.c
+++ b/SylixOS/debug/gdb/gdbserver.c
@@ -191,7 +191,7 @@ static VOID gdbClearStepMode (LW_GDB_PARAM *pparam, LW_OBJECT_HANDLE ulThread)
API_DtraceThreadStepSet(pparam->GDB_pvDtrace, ulThread, LW_FALSE);
#else
- API_DtraceThreadStepSet(pparam->GDB_pvDtrace, ulThread, (addr_t)PX_ERROR);
+ API_DtraceThreadStepSet(pparam->GDB_pvDtrace, ulThread, LW_GDB_ADDR_INVAL);
#endif /* LW_DTRACE_HW_ISTEP */
}
/*********************************************************************************************************
@@ -238,7 +238,7 @@ static BOOL gdbIsStepBp (LW_GDB_PARAM *pparam, PLW_DTRACE_MSG pdmsg)
static VOID gdbRemoveStepBp (LW_GDB_PARAM *pparam, LW_OBJECT_HANDLE ulThread)
{
#ifdef LW_DTRACE_HW_ISTEP
- API_DtraceDelBreakInfo(pparam->GDB_pvDtrace, ulThread, (addr_t)PX_ERROR, LW_TRUE);
+ API_DtraceDelBreakInfo(pparam->GDB_pvDtrace, ulThread, LW_GDB_ADDR_INVAL, LW_TRUE);
#else
addr_t addrNP;
diff --git a/SylixOS/include/arch/arm/asm/assembler.h b/SylixOS/include/arch/arm/asm/assembler.h
index 1c7ec89..ac723cb 100644
--- a/SylixOS/include/arch/arm/asm/assembler.h
+++ b/SylixOS/include/arch/arm/asm/assembler.h
@@ -172,7 +172,7 @@ func
MOV Rm, Rm
/*********************************************************************************************************
- arm memory barrier
+ armv7 or later memory barrier
*********************************************************************************************************/
#if __SYLIXOS_ARM_ARCH__ >= 7
@@ -180,19 +180,27 @@ func
# define ARM_DSB() DSB
# define ARM_DMB() DMB
+/*********************************************************************************************************
+ armv6 memory barrier (warning: use R3 register)
+*********************************************************************************************************/
+
#elif __SYLIXOS_ARM_ARCH__ == 6
# define ARM_ISB() \
- MOV R0, #0; \
- MCR p15, 0, R0, c7, c5, 4;
+ MOV R3, #0; \
+ MCR p15, 0, R3, c7, c5, 4;
# define ARM_DSB() \
- MOV R0, #0; \
- MCR p15, 0, R0, c7, c10, 4;
+ MOV R3, #0; \
+ MCR p15, 0, R3, c7, c10, 4;
# define ARM_DMB() \
- MOV R0, #0; \
- MCR p15, 0, R0, c7, c10, 5;
-
+ MOV R3, #0; \
+ MCR p15, 0, R3, c7, c10, 5;
+
+/*********************************************************************************************************
+ armv4-5 memory barrier
+*********************************************************************************************************/
+
#else
# define ARM_ISB()
# define ARM_DSB()
diff --git a/SylixOS/kernel/core/_EventSetBlock.c b/SylixOS/kernel/core/_EventSetBlock.c
index d63efbe..62d735f 100644
--- a/SylixOS/kernel/core/_EventSetBlock.c
+++ b/SylixOS/kernel/core/_EventSetBlock.c
@@ -72,7 +72,6 @@ VOID _EventSetBlock (PLW_CLASS_EVENTSET pes,
_List_Line_Add_Ahead(&pesn->EVENTSETNODE_lineManage, &pes->EVENTSET_plineWaitList);
ppcb = _GetPcb(ptcbCur);
-
__DEL_FROM_READY_RING(ptcbCur, ppcb); /* 从就绪环中删除 */
}
diff --git a/SylixOS/kernel/core/_ReadyRing.c b/SylixOS/kernel/core/_ReadyRing.c
index 85efeb4..47a4470 100644
--- a/SylixOS/kernel/core/_ReadyRing.c
+++ b/SylixOS/kernel/core/_ReadyRing.c
@@ -64,8 +64,6 @@ VOID _AddTCBToReadyRing (PLW_CLASS_TCB ptcb, PLW_CLASS_PCB ppcb, BOOL bIsHea
}
break;
}
-
- return;
}
/*********************************************************************************************************
** 函数名称: _DelTCBFromReadyRing
diff --git a/SylixOS/kernel/core/_ThreadAffinity.c b/SylixOS/kernel/core/_ThreadAffinity.c
index 702431d..4b80fbb 100644
--- a/SylixOS/kernel/core/_ThreadAffinity.c
+++ b/SylixOS/kernel/core/_ThreadAffinity.c
@@ -28,43 +28,80 @@
#if LW_CFG_SMP_EN > 0
/*********************************************************************************************************
** 函数名称: _ThreadSetAffinity
-** 功能描述: 将线程锁定到指定的 CPU 运行. (进入内核被调用且目标任务已经被停止)
+** 功能描述: 将线程锁定到指定的 CPU 运行. (进入内核被调用)
** 输 入 : ptcb 线程控制块
** stSize CPU 掩码集内存大小
** pcpuset CPU 掩码
-** 输 出 : NONE
+** 输 出 : ERROR CODE
** 全局变量:
** 调用模块:
** 注 意 : LW_CPU_ZERO(pcpuset) 可以解除 CPU 锁定.
*********************************************************************************************************/
-VOID _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_CPUSET pcpuset)
+ULONG _ThreadSetAffinity (PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_CPUSET pcpuset)
{
- ULONG i;
- ULONG ulNumChk;
-
+ INTREG iregInterLevel;
+ ULONG i;
+ ULONG ulNumChk;
+ ULONG ulError;
+ PLW_CLASS_TCB ptcbCur;
+ PLW_CLASS_PCB ppcb;
+
ulNumChk = ((ULONG)stSize << 3);
ulNumChk = (ulNumChk > LW_NCPUS) ? LW_NCPUS : ulNumChk;
for (i = 0; i < ulNumChk; i++) {
if (ptcb->TCB_ulOption & LW_OPTION_THREAD_AFFINITY_ALWAYS) {
if (LW_CPU_ISSET(i, pcpuset)) {
- ptcb->TCB_ulCPULock = i;
- ptcb->TCB_bCPULock = LW_TRUE; /* 锁定执行 CPU */
- return;
+ break; /* 锁定执行 CPU */
}
} else {
if (LW_CPU_ISSET(i, pcpuset) &&
LW_CPU_IS_ACTIVE(LW_CPU_GET(i)) &&
!(LW_CPU_GET_IPI_PEND(i) & LW_IPI_DOWN_MSK)) { /* 必须激活并且没有要被停止 */
- ptcb->TCB_ulCPULock = i;
- ptcb->TCB_bCPULock = LW_TRUE; /* 锁定执行 CPU */
- return;
+ break; /* 锁定执行 CPU */
}
}
}
- ptcb->TCB_bCPULock = LW_FALSE; /* 关闭 CPU 锁定 */
+ LW_TCB_GET_CUR(ptcbCur);
+
+ if (ptcbCur == ptcb) {
+ if (i >= ulNumChk) {
+ ptcb->TCB_bCPULock = LW_FALSE; /* 关闭 CPU 锁定 */
+
+ } else {
+ iregInterLevel = KN_INT_DISABLE();
+ ppcb = _GetPcb(ptcbCur);
+ __DEL_FROM_READY_RING(ptcbCur, ppcb); /* 从就绪表中删除 */
+
+ ptcbCur->TCB_ulCPULock = i;
+ ptcbCur->TCB_bCPULock = LW_TRUE; /* 锁定执行 CPU */
+
+ ptcbCur->TCB_ucSchedActivate = LW_SCHED_ACT_INTERRUPT; /* 中断激活方式 */
+ ppcb = _GetPcb(ptcbCur);
+ __ADD_TO_READY_RING(ptcbCur, ppcb); /* 加入到相对优先级就绪环 */
+ KN_INT_ENABLE(iregInterLevel);
+ }
+
+ } else {
+ ulError = _ThreadStop(ptcb);
+ if (ulError) {
+ return (ulError);
+ }
+
+ if (i >= ulNumChk) {
+ ptcb->TCB_bCPULock = LW_FALSE; /* 关闭 CPU 锁定 */
+
+ } else {
+ ptcb->TCB_ulCPULock = i;
+ ptcb->TCB_bCPULock = LW_TRUE; /* 锁定执行 CPU */
+ }
+
+ _ThreadContinue(ptcb, LW_FALSE); /* 唤醒目标 */
+ }
+
+ return (ERROR_NONE);
}
/*********************************************************************************************************
** 函数名称: _ThreadGetAffinity
diff --git a/SylixOS/kernel/core/_ThreadInit.c b/SylixOS/kernel/core/_ThreadInit.c
index 7a1876c..152c420 100644
--- a/SylixOS/kernel/core/_ThreadInit.c
+++ b/SylixOS/kernel/core/_ThreadInit.c
@@ -296,9 +296,10 @@ VOID _TCBBuild (UINT8 ucPriority,
#endif
#if LW_CFG_GDB_EN > 0
- ptcb->TCB_ulStepAddr = (addr_t)PX_ERROR;
- ptcb->TCB_ulStepInst = 0ul;
- ptcb->TCB_bStepClear = LW_TRUE;
+ ptcb->TCB_ulStepAddr = LW_GDB_ADDR_INVAL;
+ ptcb->TCB_ulStepInst = 0ul;
+ ptcb->TCB_bStepClear = LW_TRUE;
+ ptcb->TCB_ulAbortPointAddr = LW_GDB_ADDR_INVAL;
#endif /* LW_CFG_GDB_EN > 0 */
#if LW_CFG_THREAD_NOTE_PAD_EN > 0 /* 任务记事本 */
diff --git a/SylixOS/kernel/include/k_class.h b/SylixOS/kernel/include/k_class.h
index 03c9966..6ba4cd9 100644
--- a/SylixOS/kernel/include/k_class.h
+++ b/SylixOS/kernel/include/k_class.h
@@ -694,12 +694,13 @@ typedef struct __lw_tcb {
*********************************************************************************************************/
#if LW_CFG_GDB_EN > 0
+#define LW_GDB_ADDR_INVAL ((addr_t)PX_ERROR) /* 无效地址 */
addr_t TCB_ulStepAddr; /* 单步地址,-1 表示非单步模式 */
ULONG TCB_ulStepInst; /* 单步地址指令备份 */
BOOL TCB_bStepClear; /* 单步断点是否被清除 */
addr_t TCB_ulAbortPointAddr; /* 终止点地址 */
ULONG TCB_ulAbortPointInst; /* 终止点地址指令备份 */
-#endif
+#endif /* LW_CFG_GDB_EN > 0 */
/*********************************************************************************************************
TCB 权限管理扩展
diff --git a/SylixOS/kernel/include/k_const.h b/SylixOS/kernel/include/k_const.h
index e656c4f..25472c3 100644
--- a/SylixOS/kernel/include/k_const.h
+++ b/SylixOS/kernel/include/k_const.h
@@ -76,6 +76,8 @@
#define LW_KERN_FLAG_AUTO_REC_TCB 0x0100 /* 自动回收 TCB 兼容 1.9.7 之前*/
/* 版本, 非 detach 线程删除后 */
/* 立即释放 TCB */
+#define LW_KERN_FLAG_TEXT_RO 0x0200 /* 内核 TEXT 只读 */
+
/*********************************************************************************************************
内核是否支持浮点状态
*********************************************************************************************************/
@@ -205,6 +207,20 @@
#define LW_KERN_AUTO_REC_TCB_GET() (_K_ulKernFlags & LW_KERN_FLAG_AUTO_REC_TCB)
/*********************************************************************************************************
+ 内核代码段只读
+*********************************************************************************************************/
+
+#define LW_KERN_TEXT_RO_SET(en) \
+ do { \
+ if (en) { \
+ _K_ulKernFlags |= LW_KERN_FLAG_TEXT_RO; \
+ } else { \
+ _K_ulKernFlags &= ~LW_KERN_FLAG_TEXT_RO; \
+ } \
+ } while (0)
+#define LW_KERN_TEXT_RO_GET() (_K_ulKernFlags & LW_KERN_FLAG_TEXT_RO)
+
+/*********************************************************************************************************
系统状态
*********************************************************************************************************/
diff --git a/SylixOS/kernel/include/k_internal.h b/SylixOS/kernel/include/k_internal.h
index cec6154..83f46c4 100644
--- a/SylixOS/kernel/include/k_internal.h
+++ b/SylixOS/kernel/include/k_internal.h
@@ -543,7 +543,7 @@ INT _ThreadSched(PLW_CLASS_TCB ptcbCur);
*********************************************************************************************************/
#if LW_CFG_SMP_EN > 0
-VOID _ThreadSetAffinity(PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_CPUSET pcpuset);
+ULONG _ThreadSetAffinity(PLW_CLASS_TCB ptcb, size_t stSize, const PLW_CLASS_CPUSET pcpuset);
VOID _ThreadGetAffinity(PLW_CLASS_TCB ptcb, size_t stSize, PLW_CLASS_CPUSET pcpuset);
VOID _ThreadOffAffinity(PLW_CLASS_CPU pcpu);
#endif /* LW_CFG_SMP_EN */
diff --git a/SylixOS/kernel/include/k_kernel.h b/SylixOS/kernel/include/k_kernel.h
index ed44732..846c71f 100644
--- a/SylixOS/kernel/include/k_kernel.h
+++ b/SylixOS/kernel/include/k_kernel.h
@@ -51,7 +51,7 @@
#define __SYLIXOS_MAJOR_VER 1
#define __SYLIXOS_MINOR_VER 10
-#define __SYLIXOS_PATCH_VER 2
+#define __SYLIXOS_PATCH_VER 6
#define __SYLIXOS_PATCH_PAD 0
/*********************************************************************************************************
diff --git a/SylixOS/kernel/interface/CpuPerf.c b/SylixOS/kernel/interface/CpuPerf.c
index beb6160..2cbe74e 100644
--- a/SylixOS/kernel/interface/CpuPerf.c
+++ b/SylixOS/kernel/interface/CpuPerf.c
@@ -110,8 +110,7 @@ ULONG API_CpuBogoMips (ULONG ulCPUId, ULONG *pulKInsPerSec)
API_ThreadGetAffinity(ulMe, sizeof(pcpusetOld), &pcpusetOld);
LW_CPU_ZERO(&pcpusetNew);
LW_CPU_SET(ulCPUId, &pcpusetNew); /* 锁定 CPU */
- API_ThreadSetAffinity(ulMe, sizeof(pcpusetNew), &pcpusetNew);
- API_TimeSleep(1); /* 确保进入指定的 CPU 运行 */
+ API_ThreadSetAffinity(ulMe, sizeof(pcpusetNew), &pcpusetNew);
_CpuBogoMipsCalc(ulCPUId);
API_ThreadSetAffinity(ulMe, sizeof(pcpusetOld), &pcpusetOld);
}
diff --git a/SylixOS/kernel/interface/KernelParam.c b/SylixOS/kernel/interface/KernelParam.c
index dfc67f1..bb60de2 100644
--- a/SylixOS/kernel/interface/KernelParam.c
+++ b/SylixOS/kernel/interface/KernelParam.c
@@ -57,6 +57,7 @@ extern LW_API INT API_RootFsMapInit(CPCHAR pcMap);
建议 Lite 类型处理器可采用 simple 转换法.
netlockfifo=no 网络互斥锁使用 FIFO 顺序等待.
autorectcb=no POSIX 非 detach 线程删除后, 是否不等待 join 或 detach 自动删除 TCB
+ textro=no Kernel TEXT 端只读
rfsmap=/boot:[*],/:[*],... 这是根文件系统映射关系选项, 用逗号隔开,
/boot /etc /tmp /apps ... 为可选映射,
@@ -246,8 +247,15 @@ ULONG API_KernelStartParam (CPCHAR pcParam)
} else {
LW_KERN_AUTO_REC_TCB_SET(LW_TRUE);
}
+
+ } else if (lib_strncmp(pcTok, "textro=", 7) == 0) { /* 自动删除 TCB */
+ if (pcTok[7] == 'n') {
+ LW_KERN_TEXT_RO_SET(LW_FALSE);
+ } else {
+ LW_KERN_TEXT_RO_SET(LW_TRUE);
+ }
}
-
+
#if LW_CFG_DEVICE_EN > 0
else if (lib_strncmp(pcTok, "rfsmap=", 7) == 0) { /* 根文件系统映射 */
API_RootFsMapInit(&pcTok[7]);
diff --git a/SylixOS/kernel/interface/RmsPeriod.c b/SylixOS/kernel/interface/RmsPeriod.c
index 04b9317..9e41771 100644
--- a/SylixOS/kernel/interface/RmsPeriod.c
+++ b/SylixOS/kernel/interface/RmsPeriod.c
@@ -130,7 +130,6 @@ ULONG API_RmsPeriod (LW_OBJECT_HANDLE ulId, ULONG ulPeriod)
* 当前线程开始睡眠
*/
ppcb = _GetPcb(ptcbCur);
-
__DEL_FROM_READY_RING(ptcbCur, ppcb); /* 从就绪表中删除 */
ptcbCur->TCB_ulDelay = ulWaitTime;
diff --git a/SylixOS/kernel/interface/ThreadAffinity.c b/SylixOS/kernel/interface/ThreadAffinity.c
index ca08a05..4088f9b 100644
--- a/SylixOS/kernel/interface/ThreadAffinity.c
+++ b/SylixOS/kernel/interface/ThreadAffinity.c
@@ -42,7 +42,8 @@ ULONG API_ThreadSetAffinity (LW_OBJECT_HANDLE ulId, size_t stSize, const PLW_
{
REGISTER UINT16 usIndex;
REGISTER PLW_CLASS_TCB ptcb;
- ULONG ulError;
+ PLW_CLASS_TCB ptcbCur;
+ ULONG ulMaxLock;
usIndex = _ObjectGetIndex(ulId);
@@ -66,33 +67,29 @@ ULONG API_ThreadSetAffinity (LW_OBJECT_HANDLE ulId, size_t stSize, const PLW_
return (EPERM);
}
- if (ulId == API_ThreadIdSelf()) { /* 设置自己 */
- LW_TCB_GET_CUR_SAFE(ptcb);
- if (__THREAD_LOCK_GET(ptcb)) { /* 当前任务被锁定 */
- _ErrorHandle(EPERM);
- return (EPERM);
- }
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadSetAffinity(ptcb, stSize, pcpuset);
- __KERNEL_EXIT(); /* 退出内核 */
- return (ERROR_NONE);
- }
-
- ulError = API_ThreadStop(ulId); /* 首先停止目标线程 */
- if (ulError) {
- return (ulError);
- }
-
__KERNEL_ENTER(); /* 进入内核 */
if (_Thread_Invalid(usIndex)) {
__KERNEL_EXIT(); /* 退出内核 */
_ErrorHandle(ERROR_KERNEL_HANDLE_NULL);
return (ERROR_KERNEL_HANDLE_NULL);
}
-
+
ptcb = _K_ptcbTCBIdTable[usIndex];
+ if (ptcb->TCB_iDeleteProcStatus) { /* 在删除和重启的过程中 */
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(ERROR_THREAD_NULL);
+ return (ERROR_THREAD_NULL);
+ }
+
+ LW_TCB_GET_CUR(ptcbCur);
+ ulMaxLock = (ptcb == ptcbCur) ? 1 : 0;
+ if (__THREAD_LOCK_GET(ptcb) > ulMaxLock) { /* 任务被锁定 */
+ __KERNEL_EXIT(); /* 退出内核 */
+ _ErrorHandle(EBUSY);
+ return (EBUSY);
+ }
+
_ThreadSetAffinity(ptcb, stSize, pcpuset); /* 设置 */
- _ThreadContinue(ptcb, LW_FALSE); /* 唤醒目标 */
__KERNEL_EXIT(); /* 退出内核 */
return (ERROR_NONE);
diff --git a/SylixOS/kernel/vmm/pageLib.c b/SylixOS/kernel/vmm/pageLib.c
index c4add0b..c1b2f3c 100644
--- a/SylixOS/kernel/vmm/pageLib.c
+++ b/SylixOS/kernel/vmm/pageLib.c
@@ -649,7 +649,7 @@ ULONG __pageExpand (PLW_VMM_PAGE pvmpage,
}
/*********************************************************************************************************
** 函数名称: __pageSplit
-** 功能描述: 将一个虚拟页面控制块分离成两个
+** 功能描述: 将一个连续页面控制块分离成两个
** 输 入 : pvmpage 主页面控制块
** ppvmpageSplit 被分离出的页面控制块
** ulPageNum pvmpage 需要保留的页面个数, 剩余部分将分配给 pvmpageSplit.
diff --git a/SylixOS/kernel/vmm/pageTable.c b/SylixOS/kernel/vmm/pageTable.c
index cbacf74..d5171d5 100644
--- a/SylixOS/kernel/vmm/pageTable.c
+++ b/SylixOS/kernel/vmm/pageTable.c
@@ -230,6 +230,13 @@ static INT __vmmLibGlobalMap (PLW_MMU_CONTEXT pmmuctx, LW_MMU_PHYSICAL_DESC
INT i;
ULONG ulError;
ULONG ulPageNum;
+ ULONG ulTextFlags;
+
+ if (LW_KERN_TEXT_RO_GET()) {
+ ulTextFlags = LW_VMM_FLAG_EXEC | LW_VMM_FLAG_READ;
+ } else {
+ ulTextFlags = LW_VMM_FLAG_EXEC | LW_VMM_FLAG_RDWR;
+ }
for (i = 0; pphydesc[i].PHYD_stSize; i++) {
if ((pphydesc[i].PHYD_uiType == LW_PHYSICAL_MEM_BUSPOOL) ||
@@ -253,7 +260,7 @@ static INT __vmmLibGlobalMap (PLW_MMU_CONTEXT pmmuctx, LW_MMU_PHYSICAL_DESC
case LW_PHYSICAL_MEM_TEXT:
ulError = __vmmLibPageMap(pphydesc[i].PHYD_ulPhyAddr,
pphydesc[i].PHYD_ulVirMap,
- ulPageNum, LW_VMM_FLAG_EXEC | LW_VMM_FLAG_RDWR);
+ ulPageNum, ulTextFlags);
break;
case LW_PHYSICAL_MEM_DATA:
diff --git a/SylixOS/kernel/vmm/virPage.c b/SylixOS/kernel/vmm/virPage.c
index cc689bd..26bb0b8 100644
--- a/SylixOS/kernel/vmm/virPage.c
+++ b/SylixOS/kernel/vmm/virPage.c
@@ -47,7 +47,7 @@ static LW_VMM_ZONE _G_vmzoneVirDev;
/*********************************************************************************************************
切换通道
*********************************************************************************************************/
-static addr_t _G_ulVmmSwitchAddr = (addr_t)PX_ERROR;
+static addr_t _G_ulVmmSwitchAddr = PAGE_MAP_ADDR_INV;
/*********************************************************************************************************
** 函数名称: __vmmVirtualDesc
** 功能描述: 获得虚拟空间区域.
@@ -171,7 +171,7 @@ ULONG __vmmVirtualCreate (LW_MMU_VIRTUAL_DESC pvirdes[])
/* 目前不支持 NULL 起始地址 */
if (ulZone < LW_CFG_VMM_VIR_NUM) {
_G_vmvirDescApp[ulZone] = pvirdes[i];
- if (_G_ulVmmSwitchAddr == (addr_t)PX_ERROR) {
+ if (_G_ulVmmSwitchAddr == PAGE_MAP_ADDR_INV) {
_G_ulVmmSwitchAddr = pvirdes[i].VIRD_ulVirAddr;
ulAddr = _G_ulVmmSwitchAddr + LW_CFG_VMM_PAGE_SIZE;
@@ -216,7 +216,7 @@ ULONG __vmmVirtualCreate (LW_MMU_VIRTUAL_DESC pvirdes[])
}
}
- _BugHandle((_G_ulVmmSwitchAddr == (addr_t)PX_ERROR), LW_TRUE,
+ _BugHandle((_G_ulVmmSwitchAddr == PAGE_MAP_ADDR_INV), LW_TRUE,
"virtual switich page invalidate.\r\n");
return (ERROR_NONE);
diff --git a/SylixOS/kernel/vmm/vmm.c b/SylixOS/kernel/vmm/vmm.c
index 5f3fec0..e5f3b66 100644
--- a/SylixOS/kernel/vmm/vmm.c
+++ b/SylixOS/kernel/vmm/vmm.c
@@ -250,7 +250,7 @@ ULONG API_VmmLibAddPhyRam (addr_t ulPhyRam, size_t stSize)
ulPageNum = (ULONG)(stSize >> LW_CFG_VMM_PAGE_SHIFT);
phydesc[0].PHYD_ulPhyAddr = ulPhyRam;
- phydesc[0].PHYD_ulVirMap = (addr_t)PX_ERROR;
+ phydesc[0].PHYD_ulVirMap = PAGE_MAP_ADDR_INV;
phydesc[0].PHYD_stSize = stSize;
phydesc[0].PHYD_uiType = LW_PHYSICAL_MEM_APP;
phydesc[1].PHYD_stSize = 0;
@@ -828,7 +828,7 @@ ULONG API_VmmZoneStatus (ULONG ulZoneIndex,
}
if (pulPgd) {
#if LW_CFG_VMM_L4_HYPERVISOR_EN > 0
- *pulPgd = (addr_t)PX_ERROR;
+ *pulPgd = PAGE_MAP_ADDR_INV;
#else
*pulPgd = (addr_t)pmmuctx->MMUCTX_pgdEntry;
#endif /* !LW_CFG_VMM_L4_HYPERVISOR_EN */
diff --git a/SylixOS/kernel/vmm/vmm.h b/SylixOS/kernel/vmm/vmm.h
index 37f7dc5..2de94c3 100644
--- a/SylixOS/kernel/vmm/vmm.h
+++ b/SylixOS/kernel/vmm/vmm.h
@@ -216,6 +216,10 @@ LW_API ULONG API_VmmSetFiller(PVOID pvVirtualMem, FUNCPTR pfuncFiller,
/* 设置填充函数 */
LW_API ULONG API_VmmSetFindShare(PVOID pvVirtualMem, PVOIDFUNCPTR pfuncFindShare, PVOID pvArg);
/* 设置查询共享函数 */
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+LW_API ULONG API_VmmSetProtect(PVOID pvVirtualMem, PVOID pvSubMem, size_t stSize);
+#endif /* 设置禁止 copy-on-write 区 */
+
LW_API ULONG API_VmmPreallocArea(PVOID pvVirtualMem,
PVOID pvSubMem,
size_t stSize,
diff --git a/SylixOS/kernel/vmm/vmmAbort.c b/SylixOS/kernel/vmm/vmmAbort.c
index 3781c3d..042daa2 100644
--- a/SylixOS/kernel/vmm/vmmAbort.c
+++ b/SylixOS/kernel/vmm/vmmAbort.c
@@ -263,22 +263,47 @@ static INT __vmmAbortCopyOnWrite (PLW_VMM_PAGE pvmpageVirtual, addr_t ulAbort
** 函数名称: __vmmAbortWriteProtect
** 功能描述: 发生写保护中止
** 输 入 : pvmpageVirtual 虚拟空间
-** ulAbortAddrAlign 异常的地址
+** ulAbortAddr 异常的地址
** ulFlag 页面属性
+** ptcbCur 当前任务控制块
** 输 出 : 是否成功
** 全局变量:
** 调用模块:
** 注 意 :
*********************************************************************************************************/
-static INT __vmmAbortWriteProtect (PLW_VMM_PAGE pvmpageVirtual,
- addr_t ulAbortAddrAlign,
- ULONG ulFlag)
+static INT __vmmAbortWriteProtect (PLW_VMM_PAGE pvmpageVirtual,
+ addr_t ulAbortAddr,
+ ULONG ulFlag,
+ PLW_CLASS_TCB ptcbCur)
{
+ addr_t ulAbortAddrAlign = ulAbortAddr & LW_CFG_VMM_PAGE_MASK;
+
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ PLW_VMM_PAGE_PRIVATE pvmpagep;
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
if (ulFlag & LW_VMM_FLAG_WRITABLE) {
return (ERROR_NONE); /* 可能其他任务同时访问此地址 */
}
if (pvmpageVirtual->PAGE_ulFlags & LW_VMM_FLAG_WRITABLE) { /* 虚拟空间允许写操作 */
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ pvmpagep = (PLW_VMM_PAGE_PRIVATE)pvmpageVirtual->PAGE_pvAreaCb;
+ if (pvmpagep && pvmpagep->PAGEP_stPtSize) {
+ if ((ulAbortAddr >= pvmpagep->PAGEP_ulPtStart) ||
+ (ulAbortAddr < (pvmpagep->PAGEP_ulPtStart + pvmpagep->PAGEP_stPtSize))) {
+ if (ptcbCur->TCB_pvVProcessContext) { /* 进程内修改保护段 */
+#if LW_CFG_GDB_EN > 0
+ if (ptcbCur->TCB_ulAbortPointAddr == LW_GDB_ADDR_INVAL)
+#endif /* LW_CFG_GDB_EN */
+ {
+ return (PX_ERROR); /* 杀死任务, 内存不可写 */
+ }
+ }
+ }
+ }
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
return (__vmmAbortCopyOnWrite(pvmpageVirtual,
ulAbortAddrAlign)); /* copy-on-write */
}
@@ -623,8 +648,8 @@ static VOID __vmmAbortShell (PLW_VMM_PAGE_FAIL_CTX pvmpagefailctx)
if (__PAGEFAILCTX_ABORT_METHOD(pvmpagefailctx) ==
LW_VMM_ABORT_METHOD_WRITE) { /* 写入异常 */
if (__vmmAbortWriteProtect(pvmpageVirtual, /* 尝试 copy-on-write 处理 */
- ulVirtualPageAlign,
- ulError) == ERROR_NONE) { /* 进入写保护处理 */
+ ulAbortAddr,
+ ulFlag, ptcbCur) == ERROR_NONE) {/* 进入写保护处理 */
__VMM_UNLOCK();
goto __abort_return;
}
diff --git a/SylixOS/kernel/vmm/vmmMalloc.c b/SylixOS/kernel/vmm/vmmMalloc.c
index 738f48b..ba6e234 100644
--- a/SylixOS/kernel/vmm/vmmMalloc.c
+++ b/SylixOS/kernel/vmm/vmmMalloc.c
@@ -493,6 +493,11 @@ PVOID API_VmmMallocAreaAlign (size_t stSize, size_t stAlign,
return (LW_NULL);
}
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ pvmpagep->PAGEP_ulPtStart = 0;
+ pvmpagep->PAGEP_stPtSize = 0;
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
pvmpagep->PAGEP_pfuncFiller = pfuncFiller;
pvmpagep->PAGEP_pvArg = pvArg;
@@ -925,6 +930,50 @@ ULONG API_VmmSetFindShare (PVOID pvVirtualMem, PVOIDFUNCPTR pfuncFindShare, P
return (ERROR_NONE);
}
/*********************************************************************************************************
+** 函数名称: API_VmmSetProtect
+** 功能描述: 设置虚拟空间受保护区域.
+** 输 入 : pvVirtualMem 连续虚拟地址 (必须为 vmmMallocArea 返回地址)
+** pvSubMem 当出现缺页时, 不允许 copy-on-write 的保护区起始地址
+** stSize 保护区大小.
+** 输 出 : ERROR CODE
+** 全局变量:
+** 调用模块:
+ API 函数
+*********************************************************************************************************/
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+
+LW_API
+ULONG API_VmmSetProtect (PVOID pvVirtualMem, PVOID pvSubMem, size_t stSize)
+{
+ REGISTER PLW_VMM_PAGE pvmpageVirtual;
+ REGISTER PLW_VMM_PAGE_PRIVATE pvmpagep;
+ addr_t ulAddr = (addr_t)pvVirtualMem;
+
+ __VMM_LOCK();
+ pvmpageVirtual = __areaVirtualSearchPage(ulAddr);
+ if (pvmpageVirtual == LW_NULL) {
+ __VMM_UNLOCK();
+ _ErrorHandle(ERROR_VMM_VIRTUAL_PAGE); /* 无法反向查询虚拟页面控制块 */
+ return (ERROR_VMM_VIRTUAL_PAGE);
+ }
+
+ pvmpagep = (PLW_VMM_PAGE_PRIVATE)pvmpageVirtual->PAGE_pvAreaCb;
+ if (!pvmpagep) {
+ __VMM_UNLOCK();
+ _ErrorHandle(ERROR_VMM_VIRTUAL_PAGE); /* 无法反向查询虚拟页面控制块 */
+ return (ERROR_VMM_VIRTUAL_PAGE);
+ }
+
+ pvmpagep->PAGEP_ulPtStart = (addr_t)pvSubMem;
+ pvmpagep->PAGEP_stPtSize = stSize;
+
+ __VMM_UNLOCK();
+
+ return (ERROR_NONE);
+}
+
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+/*********************************************************************************************************
** 函数名称: API_VmmPCountInArea
** 功能描述: API_VmmMallocAreaEx 分配的连续虚拟内存中包含的物理页面个数 (此物理内存为缺页中断分配)
** 输 入 : pvVirtualMem 连续虚拟地址 (必须为 vmmMallocArea?? 返回地址)
diff --git a/SylixOS/kernel/vmm/vmmSwap.h b/SylixOS/kernel/vmm/vmmSwap.h
index ddf5e85..6ba9788 100644
--- a/SylixOS/kernel/vmm/vmmSwap.h
+++ b/SylixOS/kernel/vmm/vmmSwap.h
@@ -61,6 +61,11 @@ typedef struct {
#define LW_VMM_PHY_PREALLOC 0x4 /* 物理内存预分配 */
INT PAGEP_iFlags; /* like mmap flags */
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ addr_t PAGEP_ulPtStart; /* 非缺页中断保护段 */
+ size_t PAGEP_stPtSize;
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
FUNCPTR PAGEP_pfuncFiller; /* 页面填充器 */
PVOID PAGEP_pvArg; /* 页面填充器参数 */
diff --git a/SylixOS/loader/elf/elf_loader.c b/SylixOS/loader/elf/elf_loader.c
index 582c4f9..883ffea 100644
--- a/SylixOS/loader/elf/elf_loader.c
+++ b/SylixOS/loader/elf/elf_loader.c
@@ -1472,6 +1472,13 @@ static INT elfPhdrRead (LW_LD_EXEC_MODULE *pmodule,
#endif
bCanExec = PF_X & pphdr->p_flags ? LW_TRUE : LW_FALSE; /* 是否可执行 */
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ if (!pmodule->EMOD_stCodeLen && bCanExec) { /* 记录代码段位置信息 */
+ pmodule->EMOD_ulCodeOft = dwMapOff;
+ pmodule->EMOD_stCodeLen = pphdr->p_memsz;
+ }
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
if (LW_LD_VMSAFEMAP_AREA(pmodule->EMOD_pvBaseAddr, dwMapOff, iFd, &stat64Buf,
pphdr->p_offset, pphdr->p_filesz,
bCanShare, bCanExec) != ERROR_NONE) {
@@ -2029,6 +2036,14 @@ INT __elfListLoad (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcPath)
if (elfPhdrBuildInitTable(pmodTemp, (ELF_DYN_DIR *)pmodTemp->EMOD_pvFormatInfo)) {
goto __out;
}
+
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ if (pmodTemp->EMOD_stCodeLen) { /* 保护代码段 */
+ LW_LD_VMSAFE_PROTECT(pmodTemp->EMOD_pvBaseAddr,
+ pmodTemp->EMOD_ulCodeOft,
+ pmodTemp->EMOD_stCodeLen);
+ }
+#endif /* LW_CFG_MODULELOADER_TEXT... */
}
#if LW_CFG_CACHE_EN > 0
API_CacheTextUpdate(pmodTemp->EMOD_pvBaseAddr, pmodTemp->EMOD_stLen);
diff --git a/SylixOS/loader/include/loader_lib.h b/SylixOS/loader/include/loader_lib.h
index 422bdfc..06b557b 100644
--- a/SylixOS/loader/include/loader_lib.h
+++ b/SylixOS/loader/include/loader_lib.h
@@ -155,6 +155,14 @@ typedef struct {
BOOL EMOD_bKoUnloadDisallow; /* 不允许卸载内核模块 */
LW_LIST_MONO_HEADER EMOD_pmonoAtexit; /* 内核模块 atexit */
+ dev_t EMOD_dev; /* 模块文件设备标识 */
+ ino_t EMOD_ino; /* 模块文件 inode 标识 */
+
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ size_t EMOD_stCodeLen; /* 模块代码段长度 */
+ ULONG EMOD_ulCodeOft; /* 模块代码段偏移 */
+#endif /* LW_CFG_MODULELOADER_TEXT... */
+
#ifdef LW_CFG_CPU_ARCH_ARM
size_t EMOD_stARMExidxCount; /* ARM.exidx 段长度 */
PVOID EMOD_pvARMExidx; /* ARM.exidx 段内存地址 */
@@ -299,10 +307,14 @@ INT __ldMmap(PVOID pvBase, size_t stAddrOft, INT iFd, struct stat64 *psta
VOID __ldShare(PVOID pvBase, size_t stLen, dev_t dev, ino64_t ino64);
VOID __ldShareAbort(dev_t dev, ino64_t ino64);
INT __ldShareConfig(BOOL bShareEn, BOOL *pbPrev);
+VOID __ldProtect(PVOID pvBase, size_t stAddrOft, size_t stLen);
#define LW_LD_VMSAFEMAP_AREA(base, addr_offset, fd, pstat64, file_offset, len, can_share, can_exec) \
__ldMmap(base, addr_offset, fd, pstat64, file_offset, len, can_share, can_exec)
+#define LW_LD_VMSAFE_PROTECT(base, addr_offset, len) \
+ __ldProtect(base, addr_offset, len)
+
#define LW_LD_VMSAFE_SHARE(base, len, dev, ino64) \
__ldShare(base, len, dev, ino64)
diff --git a/SylixOS/loader/src/loader.c b/SylixOS/loader/src/loader.c
index 5bd95ce..50d1f3c 100644
--- a/SylixOS/loader/src/loader.c
+++ b/SylixOS/loader/src/loader.c
@@ -92,7 +92,7 @@ extern void __cxa_module_finalize(void *pvBase, size_t stLen, BOOL bCall);
/*********************************************************************************************************
装载器判断文件是否可被装载 (进判断文件权限和类型, 不判断文件格式)
*********************************************************************************************************/
-extern BOOL __ldPathIsFile(CPCHAR pcName);
+extern BOOL __ldPathIsFile(CPCHAR pcName, struct stat *pstatFile);
/*********************************************************************************************************
** 函数名称: moduleCreate
** 功能描述: 创建并初始化模块结构.
@@ -103,19 +103,21 @@ extern BOOL __ldPathIsFile(CPCHAR pcName);
** pcExit 模块退出函数名
** pcEntry 模块入口函数名
** pcSection 仅从指定的 section 中导出符号表
+** pstatFile 文件 stat
** pvVProc 指向的进程主模块
** 输 出 : 创建好的模块指针,如果失败,输出NULL。
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static LW_LD_EXEC_MODULE *moduleCreate (CPCHAR pcPath,
- BOOL bExportSym,
- BOOL bIsGlobal,
- CPCHAR pcInit,
- CPCHAR pcExit,
- CPCHAR pcEntry,
- CPCHAR pcSection,
- PVOID pvVProc)
+static LW_LD_EXEC_MODULE *moduleCreate (CPCHAR pcPath,
+ BOOL bExportSym,
+ BOOL bIsGlobal,
+ CPCHAR pcInit,
+ CPCHAR pcExit,
+ CPCHAR pcEntry,
+ CPCHAR pcSection,
+ struct stat *pstatFile,
+ PVOID pvVProc)
{
LW_LD_EXEC_MODULE *pmodule = LW_NULL;
size_t stModuleSize = 0; /* 模块大小 */
@@ -179,6 +181,8 @@ static LW_LD_EXEC_MODULE *moduleCreate (CPCHAR pcPath,
pmodule->EMOD_bExportSym = bExportSym;
pmodule->EMOD_bIsGlobal = bIsGlobal;
pmodule->EMOD_pvFormatInfo = LW_NULL;
+ pmodule->EMOD_dev = pstatFile->st_dev;
+ pmodule->EMOD_ino = pstatFile->st_ino;
pmodule->EMOD_pvproc = (LW_LD_VPROC *)pvVProc;
if (pcInit) {
@@ -314,11 +318,13 @@ static INT moduleDelAndDestory (LW_LD_EXEC_MODULE *pmodule)
** pcPathBuffer 查找到的文件路径缓冲
** stMaxLen 缓冲区大小
** pcEnv 环境变量名
+** pstatFile 获取文件 stat
** 输 出 : 0
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-static INT moduleGetLibPath (CPCHAR pcFileName, PCHAR pcPathBuffer, size_t stMaxLen, CPCHAR pcEnv)
+static INT moduleGetLibPath (CPCHAR pcFileName, PCHAR pcPathBuffer,
+ size_t stMaxLen, CPCHAR pcEnv, struct stat *pstatFile)
{
CHAR cBuffer[MAX_FILENAME_LENGTH];
@@ -330,7 +336,7 @@ static INT moduleGetLibPath (CPCHAR pcFileName, PCHAR pcPathBuffer, size_t st
return (PX_ERROR);
}
- if (__ldPathIsFile(pcFileName)) { /* 在当前目录下 */
+ if (__ldPathIsFile(pcFileName, pstatFile)) { /* 在当前目录下 */
_PathGetFull(pcPathBuffer, stMaxLen, pcFileName); /* 保存绝对路径 */
return (ERROR_NONE);
@@ -351,10 +357,9 @@ static INT moduleGetLibPath (CPCHAR pcFileName, PCHAR pcPathBuffer, size_t st
*pcDiv = PX_EOS;
pcDiv++;
}
-
- snprintf(pcPathBuffer, stMaxLen, "%s/%s", pcStart, pcFileName);
/* 合并为完整的目录 */
- if (__ldPathIsFile(pcPathBuffer)) { /* 此文件可以被访问 */
+ snprintf(pcPathBuffer, stMaxLen, "%s/%s", pcStart, pcFileName);
+ if (__ldPathIsFile(pcPathBuffer, pstatFile)) { /* 此文件可以被访问 */
return (ERROR_NONE);
}
} while (pcDiv);
@@ -375,11 +380,11 @@ static INT moduleGetLibPath (CPCHAR pcFileName, PCHAR pcPathBuffer, size_t st
*********************************************************************************************************/
LW_LD_EXEC_MODULE *moduleLoadSub (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcLibName, BOOL bCreate)
{
+ struct stat statFile;
LW_LD_EXEC_MODULE *pmoduleNeed = LW_NULL;
CHAR cLibPath[MAX_FILENAME_LENGTH];
LW_LIST_RING *pringTemp;
CHAR *pcEntry;
- CHAR *pcFileName;
if (LW_NULL == pcLibName) {
_DebugHandle(__ERRORMESSAGE_LEVEL, "invalid parameter\r\n");
@@ -390,6 +395,20 @@ LW_LD_EXEC_MODULE *moduleLoadSub (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcLibName,
if (LW_NULL == pmodule) {
return (LW_NULL);
}
+
+ /*
+ * 获取动态链接库位置
+ */
+ if (ERROR_NONE != moduleGetLibPath(pcLibName, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH", &statFile)) {
+ if (ERROR_NONE != moduleGetLibPath(pcLibName, cLibPath, MAX_FILENAME_LENGTH, "PATH", &statFile)) {
+ if (bCreate) {
+ fprintf(stderr, "[ld]Can not find dependent library: %s\n", pcLibName);
+ _ErrorHandle(ERROR_LOADER_NO_MODULE);
+ }
+ return (LW_NULL);
+ }
+ }
+
/*
* 查找依赖链表中已经加载的库
*/
@@ -397,11 +416,10 @@ LW_LD_EXEC_MODULE *moduleLoadSub (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcLibName,
pringTemp = &pmodule->EMOD_ringModules;
do {
pmoduleNeed = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
-
- _PathLastName(pmoduleNeed->EMOD_pcModulePath, &pcFileName); /* 取出文件名 */
- if (pcFileName && (lib_strcmp(pcFileName, pcLibName) == 0)) {
+ if (pmoduleNeed->EMOD_dev == statFile.st_dev &&
+ pmoduleNeed->EMOD_ino == statFile.st_ino) { /* 如果已加载该模块,直接返回 */
LW_VP_UNLOCK(pmodule->EMOD_pvproc);
- return (pmoduleNeed); /* 如果已加载该模块,直接返回 */
+ return (pmoduleNeed);
}
pringTemp = _list_ring_get_next(pringTemp);
@@ -411,17 +429,6 @@ LW_LD_EXEC_MODULE *moduleLoadSub (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcLibName,
if (!bCreate) { /* 如果没有找到, 不需要创建 */
return (LW_NULL);
}
-
- /*
- * 获取动态链接库位置
- */
- if (ERROR_NONE != moduleGetLibPath(pcLibName, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH")) {
- if (ERROR_NONE != moduleGetLibPath(pcLibName, cLibPath, MAX_FILENAME_LENGTH, "PATH")) {
- fprintf(stderr, "[ld]Can not find dependent library: %s\n", pcLibName);
- _ErrorHandle(ERROR_LOADER_NO_MODULE);
- return (LW_NULL);
- }
- }
if (pmodule->EMOD_bIsSymbolEntry) {
pcEntry = LW_NULL; /* 已找到了进程入口, 不必找了 */
@@ -436,6 +443,7 @@ LW_LD_EXEC_MODULE *moduleLoadSub (LW_LD_EXEC_MODULE *pmodule, CPCHAR pcLibName,
pmodule->EMOD_pcExit,
pcEntry,
LW_NULL,
+ &statFile,
pmodule->EMOD_pvproc);
/* 创建模块 */
if (LW_NULL == pmoduleNeed) {
@@ -538,7 +546,7 @@ static INT __moduleArchCheck (LW_LD_EXEC_MODULE *pmodule)
}
pringTemp = _list_ring_get_next(pringTemp);
- } while (pringTemp != &pmodule->EMOD_ringModules); /* 查找 libvpmpdm.so fpu设置 */
+ } while (pringTemp != &pmodule->EMOD_ringModules); /* 查找 libvpmpdm.so fpu 设置 */
if (LW_NULL == ppcBaseFpuType) {
LW_VP_UNLOCK(pmodule->EMOD_pvproc);
@@ -656,7 +664,6 @@ static INT finiArrayCall (LW_LD_EXEC_MODULE *pmodule, BOOL bRunFini)
if (__moduleTreeFindSym(pmodTemp, "__c6x_call_internal_func",
&ulValue, LW_LD_SYM_FUNCTION, 20)) {
pfuncCallFunc = LW_NULL;
-
} else {
pfuncCallFunc = (VOIDFUNCPTR)ulValue; /* C6x 需要使用此函数析构 */
}
@@ -864,6 +871,7 @@ PVOID API_ModuleLoadEx (CPCHAR pcFile,
PVOID pvVProc)
{
CHAR cLibPath[MAX_FILENAME_LENGTH];
+ struct stat statFile;
LW_LD_EXEC_MODULE *pmodule = LW_NULL;
LW_LD_EXEC_MODULE *pmodVProc = LW_NULL;
LW_LD_VPROC *pvproc;
@@ -880,8 +888,6 @@ PVOID API_ModuleLoadEx (CPCHAR pcFile,
} else {
bIsGlobal = LW_FALSE;
}
-
- _PathLastName(pcFile, &pcFileName); /* 取出文件名 */
pvproc = (LW_LD_VPROC *)pvVProc;
if (LW_NULL == pvproc) { /* 内核模块 */
@@ -898,15 +904,13 @@ PVOID API_ModuleLoadEx (CPCHAR pcFile,
}
if (pmodVProc) {
+ _PathLastName(pcFile, &pcFileName); /* 取出文件名 */
pmodule = moduleLoadSub(pmodVProc, pcFileName, LW_FALSE); /* 查找进程已装载模块链表 */
}
- if (LW_NULL == pmodule) {
- /*
- * 获取动态链接库位置
- */
- if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH")) {
- if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "PATH")) {
+ if (LW_NULL == pmodule) { /* 获取动态链接库位置 */
+ if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH", &statFile)) {
+ if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "PATH", &statFile)) {
fprintf(stderr, "[ld]Can not find dependent library: %s\n", pcFile);
_ErrorHandle(ERROR_LOADER_NO_MODULE);
return (LW_NULL);
@@ -915,12 +919,13 @@ PVOID API_ModuleLoadEx (CPCHAR pcFile,
pmodule = moduleCreate(cLibPath, LW_TRUE, bIsGlobal,
pcInit, pcExit, pcEntry,
- pcSection, pvproc); /* 创建新子模块 */
+ pcSection, &statFile, pvproc); /* 创建新子模块 */
if (pmodule) {
LW_VP_LOCK(pmodule->EMOD_pvproc);
_List_Ring_Add_Last(&pmodule->EMOD_ringModules, &pvproc->VP_ringModules);
LW_VP_UNLOCK(pmodule->EMOD_pvproc);
}
+
} else {
if (bIsGlobal) { /* 只要一次global加载则为global*/
pmodule->EMOD_bIsGlobal = bIsGlobal;
@@ -1430,7 +1435,7 @@ ssize_t API_ModuleGetName (PVOID pvAddr, PCHAR pcFullPath, size_t stLen)
return (sstRet);
}
/*********************************************************************************************************
-** 函数名称: API_ModuleUpdate
+** 函数名称: API_ModuleGlobal
** 功能描述: 查找模块并更新模块相关设置.
** 输 入 : pcFile 模块文件
** iMode 装载模式 (全局还是局部)
@@ -1446,6 +1451,7 @@ PVOID API_ModuleGlobal (CPCHAR pcFile,
PVOID pvVProc)
{
CHAR cLibPath[MAX_FILENAME_LENGTH];
+ struct stat statFile;
BOOL bStart;
LW_LIST_RING *pringTemp;
LW_LD_EXEC_MODULE *pmodTemp;
@@ -1464,8 +1470,8 @@ PVOID API_ModuleGlobal (CPCHAR pcFile,
pvproc = (LW_LD_VPROC *)pvVProc;
}
- if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH")) {
- if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "PATH")) {
+ if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "LD_LIBRARY_PATH", &statFile)) {
+ if (ERROR_NONE != moduleGetLibPath(pcFile, cLibPath, MAX_FILENAME_LENGTH, "PATH", &statFile)) {
fprintf(stderr, "[ld]Can not find dependent library: %s\n", pcFile);
_ErrorHandle(ERROR_LOADER_NO_MODULE);
return (LW_NULL);
@@ -1478,7 +1484,8 @@ PVOID API_ModuleGlobal (CPCHAR pcFile,
pringTemp = _list_ring_get_next(pringTemp), bStart = LW_FALSE) {
pmodTemp = _LIST_ENTRY(pringTemp, LW_LD_EXEC_MODULE, EMOD_ringModules);
- if (lib_strcmp(pmodTemp->EMOD_pcModulePath, cLibPath) == 0) {
+ if (pmodTemp->EMOD_dev == statFile.st_dev &&
+ pmodTemp->EMOD_ino == statFile.st_ino) {
if ((pmodTemp->EMOD_bIsGlobal == LW_FALSE) &&
(iMode & LW_OPTION_LOADER_SYM_GLOBAL)) {
pmodTemp->EMOD_bIsGlobal = LW_TRUE; /* 可对外提供符号的模块 */
diff --git a/SylixOS/loader/src/loader_malloc.c b/SylixOS/loader/src/loader_malloc.c
index 0cb8e84..0556382 100644
--- a/SylixOS/loader/src/loader_malloc.c
+++ b/SylixOS/loader/src/loader_malloc.c
@@ -616,6 +616,22 @@ INT __ldMmap (PVOID pvBase, size_t stAddrOft, INT iFd, struct stat64 *pstat6
#endif /* LW_CFG_VMM_EN > 0 */
}
/*********************************************************************************************************
+** 函数名称: __ldProtect
+** 功能描述: 设置内存保护区, 不允许写.
+** 输 入 : pvBase __ldMallocArea 或者 __ldMallocAreaAlign 返回的地址 (__ldMmap 已经装载完成)
+** stAddrOft 起始偏移量
+** stLen 大小
+** 输 出 : NONE
+** 全局变量:
+** 调用模块:
+*********************************************************************************************************/
+VOID __ldProtect (PVOID pvBase, size_t stAddrOft, size_t stLen)
+{
+#if LW_CFG_MODULELOADER_TEXT_RO_EN > 0
+ API_VmmSetProtect(pvBase, (PVOID)((addr_t)pvBase + stAddrOft), stLen);
+#endif
+}
+/*********************************************************************************************************
** 函数名称: __ldShare
** 功能描述: 允许共享当前共享库
** 输 入 : pvBase __ldMallocArea 或者 __ldMallocAreaAlign 返回的地址 (__ldMmap 已经装载完成)
diff --git a/SylixOS/loader/src/loader_shell.c b/SylixOS/loader/src/loader_shell.c
index 2f5400b..f120681 100644
--- a/SylixOS/loader/src/loader_shell.c
+++ b/SylixOS/loader/src/loader_shell.c
@@ -99,16 +99,20 @@ static const CHAR _G_cVProcInfoHdr[] = "\n\
** 函数名称: __ldPathIsFile
** 功能描述: 判断文件的路径是否为文件
** 输 入 : pcParam 用户路径参数
+** pstatFile 获取文件 stat
** 输 出 : BOOL
** 全局变量:
** 调用模块:
*********************************************************************************************************/
-BOOL __ldPathIsFile (CPCHAR pcName)
+BOOL __ldPathIsFile (CPCHAR pcName, struct stat *pstatFile)
{
struct stat statFs;
if (stat(pcName, &statFs) >= 0) {
if (S_ISREG(statFs.st_mode)) {
+ if (pstatFile) {
+ *pstatFile = statFs;
+ }
return (LW_TRUE);
}
}
@@ -138,7 +142,7 @@ INT __ldGetFilePath (CPCHAR pcParam, PCHAR pcPathBuffer, size_t stMaxLen)
}
if (lib_strchr(pcParam, '/')) { /* 是一个路径 */
- if (__ldPathIsFile(pcParam)) { /* 直接使用参数即可 */
+ if (__ldPathIsFile(pcParam, LW_NULL)) { /* 直接使用参数即可 */
_PathGetFull(pcPathBuffer, stMaxLen, pcParam); /* 保存绝对路径 */
return (ERROR_NONE);
}
@@ -162,7 +166,7 @@ INT __ldGetFilePath (CPCHAR pcParam, PCHAR pcPathBuffer, size_t stMaxLen)
}
snprintf(pcPathBuffer, stMaxLen, "%s/%s", pcStart, pcParam);/* 合并为完整的目录 */
- if (__ldPathIsFile(pcPathBuffer)) { /* 此文件可以被访问 */
+ if (__ldPathIsFile(pcPathBuffer, LW_NULL)) { /* 此文件可以被访问 */
return (ERROR_NONE);
}
} while (pcDiv);
diff --git a/SylixOS/loader/src/loader_vpthread.c b/SylixOS/loader/src/loader_vpthread.c
index cbf8026..4ae0b61 100644
--- a/SylixOS/loader/src/loader_vpthread.c
+++ b/SylixOS/loader/src/loader_vpthread.c
@@ -249,15 +249,12 @@ INT vprocThreadAffinity (PVOID pvVProc, size_t stSize, const PLW_CLASS_CPUSET
LW_LD_VPROC *pvproc = (LW_LD_VPROC *)pvVProc;
PLW_LIST_LINE plineTemp;
PLW_CLASS_TCB ptcb;
- PLW_CLASS_TCB ptcbCur;
if (!pvproc) {
_ErrorHandle(ESRCH);
return (PX_ERROR);
}
-
- LW_TCB_GET_CUR_SAFE(ptcbCur);
-
+
LW_VP_LOCK(pvproc); /* 锁定当前进程 */
for (plineTemp = pvproc->VP_plineThread;
plineTemp != LW_NULL;
@@ -267,24 +264,13 @@ INT vprocThreadAffinity (PVOID pvVProc, size_t stSize, const PLW_CLASS_CPUSET
if (ptcb->TCB_iDeleteProcStatus) {
continue; /* 已经在删除过程中 */
}
-
- if (ptcb == ptcbCur) {
- if (!__THREAD_LOCK_GET(ptcb)) { /* 外部没有锁定此任务 */
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadSetAffinity(ptcb, stSize, pcpuset);
- __KERNEL_EXIT(); /* 退出内核 */
- }
-
- } else if (ptcb->TCB_iDeleteProcStatus == LW_TCB_DELETE_PROC_NONE) {
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadStop(ptcb);
- __KERNEL_EXIT(); /* 退出内核 (可能产生调度) */
-
- __KERNEL_ENTER(); /* 进入内核 */
- _ThreadSetAffinity(ptcb, stSize, pcpuset);
- _ThreadContinue(ptcb, LW_FALSE);
- __KERNEL_EXIT(); /* 退出内核 */
+ if (__THREAD_LOCK_GET(ptcb)) { /* 外部没有锁定此任务 */
+ continue; /* 线程被锁定 */
}
+
+ __KERNEL_ENTER(); /* 进入内核 */
+ _ThreadSetAffinity(ptcb, stSize, pcpuset);
+ __KERNEL_EXIT(); /* 退出内核 */
}
LW_VP_UNLOCK(pvproc); /* 解锁当前进程 */
diff --git a/SylixOS/mktemp/cl6x.mk b/SylixOS/mktemp/cl6x.mk
index 5841ba4..3600a33 100644
--- a/SylixOS/mktemp/cl6x.mk
+++ b/SylixOS/mktemp/cl6x.mk
@@ -86,14 +86,14 @@ TOOLCHAIN_LINK_SYLIXOS = -llibsylixos.a
TOOLCHAIN_LINK_GCOV =
TOOLCHAIN_LINK_GCOV_KO =
TOOLCHAIN_LINK_OMP =
-TOOLCHAIN_LINK_CXX = cplusplus
+TOOLCHAIN_LINK_CXX = --cplusplus
TOOLCHAIN_LINK_M =
TOOLCHAIN_LINK_GCC = -llibrts$(CPU_TYPE)_elf.a
TOOLCHAIN_LINK_GTEST =
TOOLCHAIN_LINK_PIC_GCOV =
TOOLCHAIN_LINK_PIC_OMP =
-TOOLCHAIN_LINK_PIC_CXX = cplusplus
+TOOLCHAIN_LINK_PIC_CXX = --cplusplus
TOOLCHAIN_LINK_PIC_M =
TOOLCHAIN_LINK_PIC_GCC = -llibrts$(CPU_TYPE)_elf_pic.a
diff --git a/SylixOS/mktemp/common.mk b/SylixOS/mktemp/common.mk
index cce026a..cd879f6 100644
--- a/SylixOS/mktemp/common.mk
+++ b/SylixOS/mktemp/common.mk
@@ -181,6 +181,17 @@ $(OBJPATH)/$(target)/%.o: %.asm
@-$(DEPFIX) $(__PP) $(__DEP)
@-rm -rf $(__PP)
+ifeq ($($(target)_USE_CXX), yes)
+$(OBJPATH)/$(target)/%.o: %.c
+ @if [ ! -d "$(dir $@)" ]; then \
+ mkdir -p "$(dir $@)"; fi
+ @if [ ! -d "$(dir $(__PP))" ]; then \
+ mkdir -p "$(dir $(__PP))"; fi
+ @-rm -rf $(__DEP)
+ $(CC) $($(__TARGET)_CFLAGS) --preproc_with_compile --cplusplus --preproc_dependency=$(__PP) $< -fe=$@
+ @-$(DEPFIX) $(__PP) $(__DEP)
+ @-rm -rf $(__PP)
+else
$(OBJPATH)/$(target)/%.o: %.c
@if [ ! -d "$(dir $@)" ]; then \
mkdir -p "$(dir $@)"; fi
@@ -190,6 +201,7 @@ $(OBJPATH)/$(target)/%.o: %.c
$(CC) $($(__TARGET)_CFLAGS) --preproc_with_compile --preproc_dependency=$(__PP) $< -fe=$@
@-$(DEPFIX) $(__PP) $(__DEP)
@-rm -rf $(__PP)
+endif
$(OBJPATH)/$(target)/%.o: %.cpp
@if [ ! -d "$(dir $@)" ]; then \
diff --git a/SylixOS/net/lwip/src/api/api_msg.c b/SylixOS/net/lwip/src/api/api_msg.c
index 233cc05..2cfc1d3 100644
--- a/SylixOS/net/lwip/src/api/api_msg.c
+++ b/SylixOS/net/lwip/src/api/api_msg.c
@@ -1020,8 +1020,8 @@ lwip_netconn_do_close_internal(struct netconn *conn WRITE_DELAYED_PARAM)
err = ERR_OK;
/* linger enabled/required at all? (i.e. is there untransmitted data left?) */
/* SylixOS Fixed listen conn do not need check linger */
- if ((conn->state != NETCONN_LISTEN) &&
- (conn->linger >= 0) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) {
+ if ((conn->linger >= 0) &&
+ (conn->pcb.tcp->state != LISTEN) && (conn->pcb.tcp->unsent || conn->pcb.tcp->unacked)) {
if ((conn->linger == 0)) {
/* data left but linger prevents waiting */
tcp_abort(tpcb);
diff --git a/SylixOS/net/lwip/tools/ftp/lwip_ftpd.c b/SylixOS/net/lwip/tools/ftp/lwip_ftpd.c
index af37dd3..61ac632 100644
--- a/SylixOS/net/lwip/tools/ftp/lwip_ftpd.c
+++ b/SylixOS/net/lwip/tools/ftp/lwip_ftpd.c
@@ -1145,6 +1145,10 @@ __recv_over:
__SHEAP_FREE(pcTransBuffer); /* 释放缓冲区 */
}
+#if LW_CFG_NET_FTPD_AUTO_SYNC > 0
+ sync(); /* 执行数据同步 */
+#endif /* LW_CFG_NET_FTPD_AUTO_SYNC */
+
__ftpdCloseSessionData(pftpds); /* 关闭数据连接 */
if (0 == iResult) {
diff --git a/SylixOS/shell/ttinyShell/ttinyShellLib.c b/SylixOS/shell/ttinyShell/ttinyShellLib.c
index 00f2216..7626bdd 100644
--- a/SylixOS/shell/ttinyShell/ttinyShellLib.c
+++ b/SylixOS/shell/ttinyShell/ttinyShellLib.c
@@ -152,7 +152,7 @@ static INT __tshellBgCreate(INT iFd,
装载器内部函数声明
*********************************************************************************************************/
#if LW_CFG_MODULELOADER_EN > 0
-extern BOOL __ldPathIsFile(CPCHAR pcName);
+extern BOOL __ldPathIsFile(CPCHAR pcName, struct stat *pstatFile);
/*********************************************************************************************************
** 函数名称: __tshellIsResCmd
** 功能描述: 是否为强制内建命令
@@ -190,7 +190,7 @@ static BOOL __tshellCheckFile (CPCHAR pcKeyword)
PCHAR pcDiv;
if (lib_strchr(pcKeyword, PX_DIVIDER)) { /* 是一个路径 */
- if (__ldPathIsFile(pcKeyword)) {
+ if (__ldPathIsFile(pcKeyword, LW_NULL)) {
return (LW_TRUE);
} else {
@@ -223,7 +223,7 @@ static BOOL __tshellCheckFile (CPCHAR pcKeyword)
snprintf(pcPathBuffer, MAX_FILENAME_LENGTH, "%s/%s",
pcStart, pcKeyword); /* 合并为完整的目录 */
- if (__ldPathIsFile(pcPathBuffer)) { /* 此文件可以被访问 */
+ if (__ldPathIsFile(pcPathBuffer, LW_NULL)) { /* 此文件可以被访问 */
__SHEAP_FREE(pcBuffer);
return (LW_TRUE);
}
diff --git a/SylixOS/vpmpdm/arch/c6x/libc.c b/SylixOS/vpmpdm/arch/c6x/libc.c
index c6577e2..b73c49b 100644
--- a/SylixOS/vpmpdm/arch/c6x/libc.c
+++ b/SylixOS/vpmpdm/arch/c6x/libc.c
@@ -131,5 +131,22 @@ wchar_t *_wcsdup (const wchar_t *str)
}
/*
+ * gcc library depend
+ */
+
+void __eprintf (const char *string, const char *expression,
+ unsigned int line, const char *filename)
+{
+ fprintf(stderr, string, expression, line, filename);
+ fflush(stderr);
+ lib_abort();
+}
+
+errno_t *__errno_location (void)
+{
+ return (__errno());
+}
+
+/*
* end
*/