Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
a2d3befc
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
464
Star
414
Fork
55
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
4
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
Kernel Liteos A
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
4
Issue
4
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a2d3befc
编写于
11月 05, 2020
作者:
O
openharmony_ci
提交者:
Gitee
11月 05, 2020
浏览文件
操作
浏览文件
下载
差异文件
!29 使用不规范的安全函数
Merge pull request !29 from zhushengle/zhushengle_20201105100528
上级
c383ba65
4ff3c4bf
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
140 addition
and
124 deletion
+140
-124
compat/posix/src/pthread.c
compat/posix/src/pthread.c
+3
-5
kernel/base/core/los_process.c
kernel/base/core/los_process.c
+96
-68
kernel/base/core/los_task.c
kernel/base/core/los_task.c
+32
-48
kernel/base/include/los_process_pri.h
kernel/base/include/los_process_pri.h
+1
-0
kernel/base/include/los_task_pri.h
kernel/base/include/los_task_pri.h
+2
-2
syscall/fs_syscall.c
syscall/fs_syscall.c
+6
-1
未找到文件。
compat/posix/src/pthread.c
浏览文件 @
a2d3befc
...
...
@@ -203,10 +203,9 @@ STATIC UINT32 InitPthreadData(pthread_t threadID, pthread_attr_t *userAttr,
return
LOS_NOK
;
}
userAttr
->
stacksize
=
taskCB
->
stackSize
;
err
=
memcpy_s
(
taskCB
->
taskName
,
OS_TCB_NAME_LEN
,
created
->
name
,
strlen
(
created
->
name
)
);
if
(
err
!=
E
OK
)
{
err
=
OsSetTaskName
(
taskCB
,
created
->
name
,
FALSE
);
if
(
err
!=
LOS_
OK
)
{
PRINT_ERR
(
"%s: %d, err: %d
\n
"
,
__FUNCTION__
,
__LINE__
,
err
);
taskCB
->
taskName
[
0
]
=
'\0'
;
return
LOS_NOK
;
}
#if (LOSCFG_KERNEL_SMP == YES)
...
...
@@ -224,7 +223,7 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
{
pthread_attr_t
userAttr
;
UINT32
ret
;
CHAR
name
[
PTHREAD_DATA_NAME_MAX
];
CHAR
name
[
PTHREAD_DATA_NAME_MAX
]
=
{
0
}
;
STATIC
UINT16
pthreadNumber
=
1
;
TSK_INIT_PARAM_S
taskInitParam
=
{
0
};
UINT32
taskHandle
;
...
...
@@ -236,7 +235,6 @@ int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
SetPthreadAttr
(
self
,
attr
,
&
userAttr
);
(
VOID
)
memset_s
(
name
,
sizeof
(
name
),
0
,
sizeof
(
name
));
(
VOID
)
snprintf_s
(
name
,
sizeof
(
name
),
sizeof
(
name
)
-
1
,
"pth%02d"
,
pthreadNumber
);
pthreadNumber
++
;
...
...
kernel/base/core/los_process.c
浏览文件 @
a2d3befc
...
...
@@ -555,9 +555,7 @@ STATIC UINT32 OsCreateIdleProcess(VOID)
#if (LOSCFG_KERNEL_SMP == YES)
OS_TCB_FROM_TID
(
*
idleTaskID
)
->
cpuAffiMask
=
CPUID_TO_AFFI_MASK
(
ArchCurrCpuid
());
#endif
(
VOID
)
memset_s
(
OS_TCB_FROM_TID
(
*
idleTaskID
)
->
taskName
,
OS_TCB_NAME_LEN
,
0
,
OS_TCB_NAME_LEN
);
(
VOID
)
memcpy_s
(
OS_TCB_FROM_TID
(
*
idleTaskID
)
->
taskName
,
OS_TCB_NAME_LEN
,
idleName
,
strlen
(
idleName
));
return
LOS_OK
;
return
(
UINT32
)
OsSetTaskName
(
OS_TCB_FROM_TID
(
*
idleTaskID
),
idleName
,
FALSE
);
}
LITE_OS_SEC_TEXT
VOID
OsProcessCBRecyleToFree
(
VOID
)
...
...
@@ -653,36 +651,35 @@ STATIC VOID OsDeInitPCB(LosProcessCB *processCB)
return
;
}
STATIC
UINT32
OsSetProcessName
(
LosProcessCB
*
processCB
,
const
CHAR
*
name
)
UINT32
OsSetProcessName
(
LosProcessCB
*
processCB
,
const
CHAR
*
name
)
{
errno_t
errRet
;
UINT32
len
;
if
(
processCB
==
NULL
)
{
return
LOS_EINVAL
;
}
if
(
name
!=
NULL
)
{
len
=
strlen
(
name
);
if
(
len
>=
OS_PCB_NAME_LEN
)
{
len
=
OS_PCB_NAME_LEN
-
1
;
/* 1: Truncate, reserving the termination operator for character turns */
}
errRet
=
memcpy_s
(
processCB
->
processName
,
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
,
name
,
len
);
if
(
errRet
!=
EOK
)
{
processCB
->
processName
[
0
]
=
'\0'
;
return
LOS_NOK
;
errRet
=
strncpy_s
(
processCB
->
processName
,
OS_PCB_NAME_LEN
,
name
,
OS_PCB_NAME_LEN
-
1
);
if
(
errRet
==
EOK
)
{
return
LOS_OK
;
}
processCB
->
processName
[
len
]
=
'\0'
;
return
LOS_OK
;
}
(
VOID
)
memset_s
(
processCB
->
processName
,
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
,
0
,
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
);
switch
(
processCB
->
processMode
)
{
case
OS_KERNEL_MODE
:
(
VOID
)
snprintf_s
(
processCB
->
processName
,
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
,
(
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
)
-
1
,
"KerProcess%u"
,
processCB
->
processID
);
errRet
=
snprintf_s
(
processCB
->
processName
,
OS_PCB_NAME_LEN
,
OS_PCB_NAME_LEN
-
1
,
"KerProcess%u"
,
processCB
->
processID
);
break
;
default:
(
VOID
)
snprintf_s
(
processCB
->
processName
,
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
,
(
sizeof
(
CHAR
)
*
OS_PCB_NAME_LEN
)
-
1
,
"UserProcess%u"
,
processCB
->
processID
);
errRet
=
snprintf_s
(
processCB
->
processName
,
OS_PCB_NAME_LEN
,
OS_PCB_NAME_LEN
-
1
,
"UserProcess%u"
,
processCB
->
processID
);
break
;
}
if
(
errRet
<
0
)
{
return
LOS_NOK
;
}
return
LOS_OK
;
}
...
...
@@ -715,12 +712,12 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
if
(
OsProcessIsUserMode
(
processCB
))
{
space
=
LOS_MemAlloc
(
m_aucSysMem0
,
sizeof
(
LosVmSpace
));
if
(
space
==
NULL
)
{
PRINT_ERR
(
"
%s %d, alloc space failed
\n
"
,
__FUNCTION__
,
__LINE__
);
PRINT_ERR
(
"
Init process struct, alloc space memory failed!
\n
"
);
return
LOS_ENOMEM
;
}
VADDR_T
*
ttb
=
LOS_PhysPagesAllocContiguous
(
1
);
if
(
ttb
==
NULL
)
{
PRINT_ERR
(
"
%s %d, alloc ttb or space failed
\n
"
,
__FUNCTION__
,
__LINE__
);
PRINT_ERR
(
"
Init process struct, alloc ttb failed!
\n
"
);
(
VOID
)
LOS_MemFree
(
m_aucSysMem0
,
space
);
return
LOS_ENOMEM
;
}
...
...
@@ -728,7 +725,7 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
retVal
=
OsUserVmSpaceInit
(
space
,
ttb
);
vmPage
=
OsVmVaddrToPage
(
ttb
);
if
((
retVal
==
FALSE
)
||
(
vmPage
==
NULL
))
{
PRINT_ERR
(
"
create space failed! ret: %d, vmPage: %#x
\n
"
,
retVal
,
vmPage
);
PRINT_ERR
(
"
Init process struct, create space failed!
\n
"
);
processCB
->
processStatus
=
OS_PROCESS_FLAG_UNUSED
;
(
VOID
)
LOS_MemFree
(
m_aucSysMem0
,
space
);
LOS_PhysPagesFreeContiguous
(
ttb
,
1
);
...
...
@@ -743,7 +740,6 @@ STATIC UINT32 OsInitPCB(LosProcessCB *processCB, UINT32 mode, UINT16 priority, U
#ifdef LOSCFG_SECURITY_VID
status
=
VidMapListInit
(
processCB
);
if
(
status
!=
LOS_OK
)
{
PRINT_ERR
(
"VidMapListInit failed!
\n
"
);
return
LOS_ENOMEM
;
}
#endif
...
...
@@ -839,7 +835,6 @@ STATIC UINT32 OsProcessCreateInit(LosProcessCB *processCB, UINT32 flags, const C
ret
=
LiteIpcPoolInit
(
&
(
processCB
->
ipcInfo
));
if
(
ret
!=
LOS_OK
)
{
ret
=
LOS_ENOMEM
;
PRINT_ERR
(
"LiteIpcPoolInit failed!
\n
"
);
goto
EXIT
;
}
}
...
...
@@ -1224,7 +1219,7 @@ WAIT_BACK:
return
LOS_OK
;
}
STATIC
INT32
OsWaitRecycleChildPorcess
(
const
LosProcessCB
*
childCB
,
UINT32
intSave
,
INT32
*
status
)
STATIC
U
INT32
OsWaitRecycleChildPorcess
(
const
LosProcessCB
*
childCB
,
UINT32
intSave
,
INT32
*
status
)
{
ProcessGroup
*
group
=
NULL
;
UINT32
pid
=
childCB
->
processID
;
...
...
@@ -1246,7 +1241,7 @@ STATIC INT32 OsWaitRecycleChildPorcess(const LosProcessCB *childCB, UINT32 intSa
return
pid
;
}
STATIC
INT32
OsWaitChildProcessCheck
(
LosProcessCB
*
processCB
,
INT32
pid
,
LosProcessCB
**
childCB
)
STATIC
U
INT32
OsWaitChildProcessCheck
(
LosProcessCB
*
processCB
,
INT32
pid
,
LosProcessCB
**
childCB
)
{
if
(
LOS_ListEmpty
(
&
(
processCB
->
childrenList
))
&&
LOS_ListEmpty
(
&
(
processCB
->
exitChildList
)))
{
return
LOS_ECHILD
;
...
...
@@ -1300,7 +1295,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
}
if
(
childCB
!=
NULL
)
{
return
OsWaitRecycleChildPorcess
(
childCB
,
intSave
,
status
);
return
(
INT32
)
OsWaitRecycleChildPorcess
(
childCB
,
intSave
,
status
);
}
if
((
options
&
LOS_WAIT_WNOHANG
)
!=
0
)
{
...
...
@@ -1325,7 +1320,7 @@ LITE_OS_SEC_TEXT INT32 LOS_Wait(INT32 pid, USER INT32 *status, UINT32 options, V
goto
ERROR
;
}
return
OsWaitRecycleChildPorcess
(
childCB
,
intSave
,
status
);
return
(
INT32
)
OsWaitRecycleChildPorcess
(
childCB
,
intSave
,
status
);
ERROR:
SCHEDULER_UNLOCK
(
intSave
);
...
...
@@ -1372,7 +1367,7 @@ STATIC UINT32 OsSetProcessGroupIDUnsafe(UINT32 pid, UINT32 gid, ProcessGroup **g
ProcessGroup
*
oldGroup
=
NULL
;
ProcessGroup
*
newGroup
=
NULL
;
LosProcessCB
*
processCB
=
OS_PCB_FROM_PID
(
pid
);
INT32
ret
=
OsSetProcessGroupCheck
(
processCB
,
gid
);
U
INT32
ret
=
OsSetProcessGroupCheck
(
processCB
,
gid
);
if
(
ret
!=
LOS_OK
)
{
return
ret
;
}
...
...
@@ -1445,7 +1440,7 @@ LITE_OS_SEC_TEXT INT32 LOS_GetProcessGroupID(UINT32 pid)
goto
EXIT
;
}
gid
=
processCB
->
group
->
groupID
;
gid
=
(
INT32
)
processCB
->
group
->
groupID
;
EXIT:
SCHEDULER_UNLOCK
(
intSave
);
...
...
@@ -1457,10 +1452,9 @@ LITE_OS_SEC_TEXT INT32 LOS_GetCurrProcessGroupID(VOID)
return
LOS_GetProcessGroupID
(
OsCurrProcessGet
()
->
processID
);
}
STATIC
VOID
*
OsUserInitStackAlloc
(
UINT32
processID
,
UINT32
*
size
)
STATIC
VOID
*
OsUserInitStackAlloc
(
LosProcessCB
*
processCB
,
UINT32
*
size
)
{
LosVmMapRegion
*
region
=
NULL
;
LosProcessCB
*
processCB
=
OS_PCB_FROM_PID
(
processID
);
UINT32
stackSize
=
ALIGN
(
OS_USER_TASK_STACK_SIZE
,
PAGE_SIZE
);
region
=
LOS_RegionAlloc
(
processCB
->
vmSpace
,
0
,
stackSize
,
...
...
@@ -1482,7 +1476,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
LosVmSpace
*
oldSpace
,
UINTPTR
oldFiles
)
{
UINT32
ret
;
errno_t
errRet
;
const
CHAR
*
processName
=
NULL
;
if
((
processCB
==
NULL
)
||
(
name
==
NULL
))
{
...
...
@@ -1492,20 +1485,14 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
processName
=
strrchr
(
name
,
'/'
);
processName
=
(
processName
==
NULL
)
?
name
:
(
processName
+
1
);
/* 1: Do not include '/' */
ret
=
OsSetProcessName
(
processCB
,
processName
);
ret
=
(
UINT32
)
OsSetTaskName
(
OsCurrTaskGet
(),
processName
,
TRUE
);
if
(
ret
!=
LOS_OK
)
{
return
ret
;
}
errRet
=
memcpy_s
(
OsCurrTaskGet
()
->
taskName
,
OS_TCB_NAME_LEN
,
processCB
->
processName
,
OS_PCB_NAME_LEN
);
if
(
errRet
!=
EOK
)
{
OsCurrTaskGet
()
->
taskName
[
0
]
=
'\0'
;
return
LOS_NOK
;
}
#if (LOSCFG_KERNEL_LITEIPC == YES)
ret
=
LiteIpcPoolInit
(
&
(
processCB
->
ipcInfo
));
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"LiteIpcPoolInit failed!
\n
"
);
return
LOS_NOK
;
}
#endif
...
...
@@ -1524,7 +1511,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
VidMapDestroy
(
processCB
);
ret
=
VidMapListInit
(
processCB
);
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"VidMapListInit failed!
\n
"
);
return
LOS_NOK
;
}
#endif
...
...
@@ -1538,7 +1524,6 @@ LITE_OS_SEC_TEXT UINT32 OsExecRecycleAndInit(LosProcessCB *processCB, const CHAR
LITE_OS_SEC_TEXT
UINT32
OsExecStart
(
const
TSK_ENTRY_FUNC
entry
,
UINTPTR
sp
,
UINTPTR
mapBase
,
UINT32
mapSize
)
{
LosProcessCB
*
processCB
=
NULL
;
LosTaskCB
*
taskCB
=
NULL
;
TaskContext
*
taskContext
=
NULL
;
UINT32
intSave
;
...
...
@@ -1556,10 +1541,8 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
}
SCHEDULER_LOCK
(
intSave
);
processCB
=
OsCurrProcessGet
();
taskCB
=
OsCurrTaskGet
();
processCB
->
threadGroupID
=
taskCB
->
taskID
;
taskCB
->
userMapBase
=
mapBase
;
taskCB
->
userMapSize
=
mapSize
;
taskCB
->
taskEntry
=
(
TSK_ENTRY_FUNC
)
entry
;
...
...
@@ -1573,68 +1556,114 @@ LITE_OS_SEC_TEXT UINT32 OsExecStart(const TSK_ENTRY_FUNC entry, UINTPTR sp, UINT
STATIC
UINT32
OsUserInitProcessStart
(
UINT32
processID
,
TSK_INIT_PARAM_S
*
param
)
{
UINT32
intSave
;
INT32
taskID
;
U
INT32
taskID
;
INT32
ret
;
taskID
=
OsCreateUserTask
(
processID
,
param
);
if
(
taskID
<
0
)
{
if
(
taskID
==
OS_INVALID_VALUE
)
{
return
LOS_NOK
;
}
ret
=
LOS_SetTaskScheduler
(
taskID
,
LOS_SCHED_RR
,
OS_TASK_PRIORITY_LOWEST
);
if
(
ret
<
0
)
{
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"User init process set scheduler failed! ERROR:%d
\n
"
,
ret
);
SCHEDULER_LOCK
(
intSave
);
(
VOID
)
OsTaskDeleteUnsafe
(
OS_TCB_FROM_TID
(
taskID
),
OS_PRO_EXIT_OK
,
intSave
);
return
-
ret
;
return
LOS_NOK
;
}
return
LOS_OK
;
}
LITE_OS_SEC_TEXT_INIT
UINT32
OsUserInitProcess
(
VOID
)
STATIC
UINT32
OsLoadUserInit
(
LosProcessCB
*
processCB
)
{
/* userInitTextStart -----
* | user text |
*
* | user data | initSize
* userInitBssStart ---
* | user bss | initBssSize
* userInitEnd --- -----
*/
errno_t
errRet
;
INT32
ret
;
UINT32
size
;
TSK_INIT_PARAM_S
param
=
{
0
};
VOID
*
stack
=
NULL
;
VOID
*
userText
=
NULL
;
CHAR
*
userInitTextStart
=
(
CHAR
*
)
&
__user_init_entry
;
CHAR
*
userInitBssStart
=
(
CHAR
*
)
&
__user_init_bss
;
CHAR
*
userInitEnd
=
(
CHAR
*
)
&
__user_init_end
;
UINT32
initBssSize
=
userInitEnd
-
userInitBssStart
;
UINT32
initSize
=
userInitEnd
-
userInitTextStart
;
VOID
*
userBss
=
NULL
;
VOID
*
userText
=
NULL
;
LosProcessCB
*
processCB
=
OS_PCB_FROM_PID
(
g_userInitProcess
);
ret
=
OsProcessCreateInit
(
processCB
,
OS_USER_MODE
,
"Init"
,
OS_PROCESS_USERINIT_PRIORITY
);
if
(
ret
!=
LOS_OK
)
{
return
ret
;
if
((
LOS_Align
((
UINTPTR
)
userInitTextStart
,
PAGE_SIZE
)
!=
(
UINTPTR
)
userInitTextStart
)
||
(
LOS_Align
((
UINTPTR
)
userInitEnd
,
PAGE_SIZE
)
!=
(
UINTPTR
)
userInitEnd
))
{
return
LOS_EINVAL
;
}
if
((
initSize
==
0
)
||
(
initSize
<=
initBssSize
))
{
return
LOS_EINVAL
;
}
userText
=
LOS_PhysPagesAllocContiguous
(
initSize
>>
PAGE_SHIFT
);
if
(
userText
==
NULL
)
{
ret
=
LOS_NOK
;
goto
ERROR
;
return
LOS_NOK
;
}
(
VOID
)
memcpy_s
(
userText
,
initSize
,
(
VOID
*
)
&
__user_init_load_addr
,
initSize
);
errRet
=
memcpy_s
(
userText
,
initSize
,
(
VOID
*
)
&
__user_init_load_addr
,
initSize
-
initBssSize
);
if
(
errRet
!=
EOK
)
{
PRINT_ERR
(
"Load user init text, data and bss failed! err : %d
\n
"
,
errRet
);
goto
ERROR
;
}
ret
=
LOS_VaddrToPaddrMmap
(
processCB
->
vmSpace
,
(
VADDR_T
)(
UINTPTR
)
userInitTextStart
,
LOS_PaddrQuery
(
userText
),
initSize
,
VM_MAP_REGION_FLAG_PERM_READ
|
VM_MAP_REGION_FLAG_PERM_WRITE
|
VM_MAP_REGION_FLAG_PERM_EXECUTE
|
VM_MAP_REGION_FLAG_PERM_USER
);
if
(
ret
<
0
)
{
PRINT_ERR
(
"Mmap user init text, data and bss failed! err : %d
\n
"
,
ret
);
goto
ERROR
;
}
(
VOID
)
memset_s
((
VOID
*
)((
UINTPTR
)
userText
+
userInitBssStart
-
userInitTextStart
),
initBssSize
,
0
,
initBssSize
);
/* The User init boot segment may not actually exist */
if
(
initBssSize
!=
0
)
{
userBss
=
(
VOID
*
)((
UINTPTR
)
userText
+
userInitBssStart
-
userInitTextStart
);
errRet
=
memset_s
(
userBss
,
initBssSize
,
0
,
initBssSize
);
if
(
errRet
!=
EOK
)
{
PRINT_ERR
(
"memset user init bss failed! err : %d
\n
"
,
errRet
);
goto
ERROR
;
}
}
return
LOS_OK
;
stack
=
OsUserInitStackAlloc
(
g_userInitProcess
,
&
size
);
ERROR:
(
VOID
)
LOS_PhysPagesFreeContiguous
(
userText
,
initSize
>>
PAGE_SHIFT
);
return
LOS_NOK
;
}
LITE_OS_SEC_TEXT_INIT
UINT32
OsUserInitProcess
(
VOID
)
{
UINT32
ret
;
UINT32
size
;
TSK_INIT_PARAM_S
param
=
{
0
};
VOID
*
stack
=
NULL
;
LosProcessCB
*
processCB
=
OS_PCB_FROM_PID
(
g_userInitProcess
);
ret
=
OsProcessCreateInit
(
processCB
,
OS_USER_MODE
,
"Init"
,
OS_PROCESS_USERINIT_PRIORITY
);
if
(
ret
!=
LOS_OK
)
{
return
ret
;
}
ret
=
OsLoadUserInit
(
processCB
);
if
(
ret
!=
LOS_OK
)
{
goto
ERROR
;
}
stack
=
OsUserInitStackAlloc
(
processCB
,
&
size
);
if
(
stack
==
NULL
)
{
PRINTK
(
"user init process malloc user stack failed!
\n
"
);
ret
=
LOS_NOK
;
PRINT_ERR
(
"Alloc user init process user stack failed!
\n
"
);
goto
ERROR
;
}
param
.
pfnTaskEntry
=
(
TSK_ENTRY_FUNC
)
userInitTextStart
;
param
.
pfnTaskEntry
=
(
TSK_ENTRY_FUNC
)
(
CHAR
*
)
&
__user_init_entry
;
param
.
userParam
.
userSP
=
(
UINTPTR
)
stack
+
size
;
param
.
userParam
.
userMapBase
=
(
UINTPTR
)
stack
;
param
.
userParam
.
userMapSize
=
size
;
...
...
@@ -1648,7 +1677,6 @@ LITE_OS_SEC_TEXT_INIT UINT32 OsUserInitProcess(VOID)
return
LOS_OK
;
ERROR:
(
VOID
)
LOS_PhysPagesFreeContiguous
(
userText
,
initSize
>>
PAGE_SHIFT
);
OsDeInitPCB
(
processCB
);
return
ret
;
}
...
...
@@ -1855,7 +1883,7 @@ STATIC UINT32 OsChildSetProcessGroupAndSched(LosProcessCB *child, LosProcessCB *
return
LOS_OK
;
}
STATIC
INT32
OsCopyProcessResources
(
UINT32
flags
,
LosProcessCB
*
child
,
LosProcessCB
*
run
)
STATIC
U
INT32
OsCopyProcessResources
(
UINT32
flags
,
LosProcessCB
*
child
,
LosProcessCB
*
run
)
{
UINT32
ret
;
...
...
kernel/base/core/los_task.c
浏览文件 @
a2d3befc
...
...
@@ -61,7 +61,7 @@
#if (LOSCFG_KERNEL_LITEIPC == YES)
#include "hm_liteipc.h"
#endif
#include "
user_copy
.h"
#include "
los_strncpy_from_user
.h"
#include "los_vm_syscall.h"
#ifdef LOSCFG_ENABLE_OOM_LOOP_TASK
#include "los_oom.h"
...
...
@@ -107,7 +107,6 @@ VOID OsSetMainTask()
{
UINT32
i
;
CHAR
*
name
=
"osMain"
;
errno_t
ret
;
for
(
i
=
0
;
i
<
LOSCFG_KERNEL_CORE_NUM
;
i
++
)
{
g_mainTask
[
i
].
taskStatus
=
OS_TASK_STATUS_UNUSED
;
...
...
@@ -117,10 +116,7 @@ VOID OsSetMainTask()
g_mainTask
[
i
].
lockDep
.
lockDepth
=
0
;
g_mainTask
[
i
].
lockDep
.
waitLock
=
NULL
;
#endif
ret
=
memcpy_s
(
g_mainTask
[
i
].
taskName
,
OS_TCB_NAME_LEN
,
name
,
strlen
(
name
));
if
(
ret
!=
EOK
)
{
g_mainTask
[
i
].
taskName
[
0
]
=
'\0'
;
}
(
VOID
)
strncpy_s
(
g_mainTask
[
i
].
taskName
,
OS_TCB_NAME_LEN
,
name
,
OS_TCB_NAME_LEN
-
1
);
LOS_ListInit
(
&
g_mainTask
[
i
].
lockList
);
}
}
...
...
@@ -702,7 +698,6 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
#endif
#if (LOSCFG_KERNEL_LITEIPC == YES)
LOS_ListInit
(
&
(
taskCB
->
msgListHead
));
(
VOID
)
memset_s
(
taskCB
->
accessMap
,
sizeof
(
taskCB
->
accessMap
),
0
,
sizeof
(
taskCB
->
accessMap
));
#endif
taskCB
->
policy
=
(
initParam
->
policy
==
LOS_SCHED_FIFO
)
?
LOS_SCHED_FIFO
:
LOS_SCHED_RR
;
taskCB
->
taskStatus
=
OS_TASK_STATUS_INIT
;
...
...
@@ -717,8 +712,8 @@ LITE_OS_SEC_TEXT_INIT STATIC VOID OsTaskCBInitBase(LosTaskCB *taskCB,
LOS_ListInit
(
&
taskCB
->
lockList
);
}
LITE_OS_SEC_TEXT_INIT
STATIC
UINT32
OsTaskCBInit
(
LosTaskCB
*
taskCB
,
const
TSK_INIT_PARAM_S
*
initParam
,
const
VOID
*
stackPtr
,
const
VOID
*
topStack
)
STATIC
UINT32
OsTaskCBInit
(
LosTaskCB
*
taskCB
,
const
TSK_INIT_PARAM_S
*
initParam
,
const
VOID
*
stackPtr
,
const
VOID
*
topStack
)
{
UINT32
intSave
;
UINT32
ret
;
...
...
@@ -749,20 +744,16 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsTaskCBInit(LosTaskCB *taskCB, const TSK_IN
processCB
->
threadCount
++
;
SCHEDULER_UNLOCK
(
intSave
);
if
(
initParam
->
pcName
==
NULL
)
{
(
VOID
)
memset_s
(
taskCB
->
taskName
,
sizeof
(
CHAR
)
*
OS_TCB_NAME_LEN
,
0
,
sizeof
(
CHAR
)
*
OS_TCB_NAME_LEN
);
(
VOID
)
snprintf_s
(
taskCB
->
taskName
,
sizeof
(
CHAR
)
*
OS_TCB_NAME_LEN
,
(
sizeof
(
CHAR
)
*
OS_TCB_NAME_LEN
)
-
1
,
"thread%u"
,
numCount
);
return
LOS_OK
;
}
if
(
mode
==
OS_KERNEL_MODE
)
{
ret
=
memcpy_s
(
taskCB
->
taskName
,
sizeof
(
CHAR
)
*
OS_TCB_NAME_LEN
,
initParam
->
pcName
,
strlen
(
initParam
->
pcName
));
if
(
ret
!=
EOK
)
{
taskCB
->
taskName
[
0
]
=
'\0'
;
if
(
initParam
->
pcName
!=
NULL
)
{
ret
=
(
UINT32
)
OsSetTaskName
(
taskCB
,
initParam
->
pcName
,
FALSE
);
if
(
ret
==
LOS_OK
)
{
return
LOS_OK
;
}
}
if
(
snprintf_s
(
taskCB
->
taskName
,
OS_TCB_NAME_LEN
,
OS_TCB_NAME_LEN
-
1
,
"thread%u"
,
numCount
)
<
0
)
{
return
LOS_NOK
;
}
return
LOS_OK
;
}
...
...
@@ -1644,54 +1635,46 @@ EXIT:
return
INT_NO_RESCH
;
}
LITE_OS_SEC_TEXT
INT32
OsSet
CurrTaskName
(
const
CHAR
*
n
ame
)
LITE_OS_SEC_TEXT
INT32
OsSet
TaskName
(
LosTaskCB
*
taskCB
,
const
CHAR
*
name
,
BOOL
setPN
ame
)
{
UINT32
intSave
;
UINT32
strLen
;
errno_t
err
;
LosTaskCB
*
runTask
=
NULL
;
LosProcessCB
*
runProcess
=
NULL
;
LosProcessCB
*
processCB
=
NULL
;
const
CHAR
*
namePtr
=
NULL
;
CHAR
nameBuff
[
OS_TCB_NAME_LEN
]
=
{
0
};
runTask
=
OsCurrTaskGet
();
runProcess
=
OS_PCB_FROM_PID
(
runTask
->
processID
);
if
(
runProcess
->
processMode
==
OS_USER_MODE
)
{
(
VOID
)
LOS_ArchCopyFromUser
(
nameBuff
,
(
const
VOID
*
)
name
,
OS_TCB_NAME_LEN
);
strLen
=
strnlen
(
nameBuff
,
OS_TCB_NAME_LEN
);
if
((
taskCB
==
NULL
)
||
(
name
==
NULL
))
{
return
EINVAL
;
}
if
(
LOS_IsUserAddress
((
VADDR_T
)(
UINTPTR
)
name
))
{
err
=
LOS_StrncpyFromUser
(
nameBuff
,
(
const
CHAR
*
)
name
,
OS_TCB_NAME_LEN
);
if
(
err
<
0
)
{
return
-
err
;
}
namePtr
=
nameBuff
;
}
else
{
strLen
=
strnlen
(
name
,
OS_TCB_NAME_LEN
);
namePtr
=
name
;
}
if
(
strLen
==
0
)
{
err
=
EINVAL
;
PRINT_ERR
(
"set task(%u) name failed! %d
\n
"
,
OsCurrTaskGet
()
->
taskID
,
err
);
return
err
;
}
else
if
(
strLen
==
OS_TCB_NAME_LEN
)
{
strLen
=
strLen
-
1
;
}
SCHEDULER_LOCK
(
intSave
);
err
=
memcpy_s
(
runTask
->
taskName
,
OS_TCB_NAME_LEN
,
(
VOID
*
)
namePtr
,
strLen
);
err
=
strncpy_s
(
taskCB
->
taskName
,
OS_TCB_NAME_LEN
,
(
VOID
*
)
namePtr
,
OS_TCB_NAME_LEN
-
1
);
if
(
err
!=
EOK
)
{
runTask
->
taskName
[
0
]
=
'\0'
;
err
=
EINVAL
;
goto
EXIT
;
}
runTask
->
taskName
[
strLen
]
=
'\0'
;
err
=
LOS_OK
;
processCB
=
OS_PCB_FROM_PID
(
taskCB
->
processID
);
/* if thread is main thread, then set processName as taskName */
if
(
runTask
->
taskID
==
runProcess
->
threadGroupID
)
{
(
VOID
)
memcpy_s
(
runProcess
->
processName
,
OS_PCB_NAME_LEN
,
(
VOID
*
)
runTask
->
taskName
,
OS_TCB_NAME_LEN
);
if
((
taskCB
->
taskID
==
processCB
->
threadGroupID
)
&&
(
setPName
==
TRUE
))
{
err
=
(
INT32
)
OsSetProcessName
(
processCB
,
(
const
CHAR
*
)
taskCB
->
taskName
);
if
(
err
!=
LOS_OK
)
{
err
=
EINVAL
;
}
}
SCHEDULER_UNLOCK
(
intSave
);
return
LOS_OK
;
EXIT:
SCHEDULER_UNLOCK
(
intSave
);
return
err
;
...
...
@@ -1747,6 +1730,7 @@ LITE_OS_SEC_TEXT VOID OsTaskExitGroup(UINT32 status)
(
VOID
)
OsTaskSyncWait
(
runTask
[
cpu
]);
}
#endif
processCB
->
threadGroupID
=
OsCurrTaskGet
()
->
taskID
;
SCHEDULER_UNLOCK
(
intSave
);
LOS_ASSERT
(
processCB
->
threadNumber
==
1
);
...
...
@@ -1838,7 +1822,7 @@ LITE_OS_SEC_TEXT_INIT STATIC UINT32 OsCreateUserTaskParamCheck(UINT32 processID,
return
LOS_OK
;
}
LITE_OS_SEC_TEXT_INIT
INT32
OsCreateUserTask
(
UINT32
processID
,
TSK_INIT_PARAM_S
*
initParam
)
LITE_OS_SEC_TEXT_INIT
U
INT32
OsCreateUserTask
(
UINT32
processID
,
TSK_INIT_PARAM_S
*
initParam
)
{
LosProcessCB
*
processCB
=
NULL
;
UINT32
taskID
;
...
...
kernel/base/include/los_process_pri.h
浏览文件 @
a2d3befc
...
...
@@ -479,6 +479,7 @@ extern VOID OsWaitSignalToWakeProcess(LosProcessCB *processCB);
extern
UINT32
OsExecRecycleAndInit
(
LosProcessCB
*
processCB
,
const
CHAR
*
name
,
LosVmSpace
*
oldAspace
,
UINTPTR
oldFiles
);
extern
UINT32
OsExecStart
(
const
TSK_ENTRY_FUNC
entry
,
UINTPTR
sp
,
UINTPTR
mapBase
,
UINT32
mapSize
);
extern
UINT32
OsSetProcessName
(
LosProcessCB
*
processCB
,
const
CHAR
*
name
);
extern
INT32
OsSetProcessScheduler
(
INT32
which
,
INT32
pid
,
UINT16
prio
,
UINT16
policy
,
BOOL
policyFlag
);
extern
INT32
OsGetProcessPriority
(
INT32
which
,
INT32
pid
);
extern
VOID
*
OsUserStackAlloc
(
UINT32
processID
,
UINT32
*
size
);
...
...
kernel/base/include/los_task_pri.h
浏览文件 @
a2d3befc
...
...
@@ -566,10 +566,10 @@ extern UINT32 OsTaskDeleteUnsafe(LosTaskCB *taskCB, UINT32 status, UINT32 intSav
extern
VOID
OsTaskResourcesToFree
(
LosTaskCB
*
taskCB
);
extern
VOID
OsRunTaskToDelete
(
LosTaskCB
*
taskCB
);
extern
UINT32
OsTaskSyncWait
(
const
LosTaskCB
*
taskCB
);
extern
INT32
OsCreateUserTask
(
UINT32
processID
,
TSK_INIT_PARAM_S
*
initParam
);
extern
U
INT32
OsCreateUserTask
(
UINT32
processID
,
TSK_INIT_PARAM_S
*
initParam
);
extern
INT32
OsTaskSchedulerSetUnsafe
(
LosTaskCB
*
taskCB
,
UINT16
policy
,
UINT16
priority
,
BOOL
policyFlag
,
UINT32
intSave
);
extern
INT32
OsSet
CurrTaskName
(
const
CHAR
*
n
ame
);
extern
INT32
OsSet
TaskName
(
LosTaskCB
*
taskCB
,
const
CHAR
*
name
,
BOOL
setPN
ame
);
extern
VOID
OsTaskCBRecyleToFree
(
VOID
);
extern
VOID
OsTaskExitGroup
(
UINT32
status
);
extern
VOID
OsTaskToExit
(
LosTaskCB
*
taskCB
,
UINT32
status
);
...
...
syscall/fs_syscall.c
浏览文件 @
a2d3befc
...
...
@@ -1342,7 +1342,12 @@ int SysPrctl(int option, ...)
}
name
=
va_arg
(
ap
,
unsigned
long
);
err
=
OsSetCurrTaskName
((
const
char
*
)(
uintptr_t
)
name
);
if
(
!
LOS_IsUserAddress
(
name
))
{
err
=
EFAULT
;
goto
ERROR
;
}
err
=
OsSetTaskName
(
OsCurrTaskGet
(),
(
const
char
*
)(
uintptr_t
)
name
,
TRUE
);
if
(
err
!=
LOS_OK
)
{
goto
ERROR
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录