Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Kernel Liteos A
提交
339c467e
K
Kernel Liteos A
项目概览
OpenHarmony
/
Kernel Liteos A
1 年多 前同步成功
通知
460
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看板
提交
339c467e
编写于
6月 29, 2021
作者:
O
openharmony_ci
提交者:
Gitee
6月 29, 2021
浏览文件
操作
浏览文件
下载
差异文件
!375 基于汇编实现内核对用户态内存清零的功能
Merge pull request !375 from Harylee/mem
上级
43bdf2f1
9db34075
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
157 addition
and
34 deletion
+157
-34
arch/arm/arm/include/arm_user_clear.h
arch/arm/arm/include/arm_user_clear.h
+50
-0
arch/arm/arm/src/clear_user.S
arch/arm/arm/src/clear_user.S
+100
-0
arch/arm/arm/src/user_copy.c
arch/arm/arm/src/user_copy.c
+3
-8
kernel/extended/dynload/src/los_load_elf.c
kernel/extended/dynload/src/los_load_elf.c
+4
-26
未找到文件。
arch/arm/arm/include/arm_user_clear.h
0 → 100644
浏览文件 @
339c467e
/*
* Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARM_USER_CLEAR_H
#define _ARM_USER_CLEAR_H
#include "los_typedef.h"
#ifdef __cplusplus
#if __cplusplus
extern
"C"
{
#endif
/* __cplusplus */
#endif
/* __cplusplus */
size_t
_arm_clear_user
(
void
*
addr
,
size_t
bytes
);
#ifdef __cplusplus
#if __cplusplus
}
#endif
/* __cplusplus */
#endif
/* __cplusplus */
#endif
/* _ARM_USER_CLEAR_H */
arch/arm/arm/src/clear_user.S
0 → 100644
浏览文件 @
339c467e
/*
*
Copyright
(
c
)
2021
-
2021
Huawei
Device
Co
.
,
Ltd
.
All
rights
reserved
.
*
*
Redistribution
and
use
in
source
and
binary
forms
,
with
or
without
modification
,
*
are
permitted
provided
that
the
following
conditions
are
met
:
*
*
1
.
Redistributions
of
source
code
must
retain
the
above
copyright
notice
,
this
list
of
*
conditions
and
the
following
disclaimer
.
*
*
2
.
Redistributions
in
binary
form
must
reproduce
the
above
copyright
notice
,
this
list
*
of
conditions
and
the
following
disclaimer
in
the
documentation
and
/
or
other
materials
*
provided
with
the
distribution
.
*
*
3
.
Neither
the
name
of
the
copyright
holder
nor
the
names
of
its
contributors
may
be
used
*
to
endorse
or
promote
products
derived
from
this
software
without
specific
prior
written
*
permission
.
*
*
THIS
SOFTWARE
IS
PROVIDED
BY
THE
COPYRIGHT
HOLDERS
AND
CONTRIBUTORS
*
"AS IS"
AND
ANY
EXPRESS
OR
IMPLIED
WARRANTIES
,
INCLUDING
,
BUT
NOT
LIMITED
TO
,
*
THE
IMPLIED
WARRANTIES
OF
MERCHANTABILITY
AND
FITNESS
FOR
A
PARTICULAR
*
PURPOSE
ARE
DISCLAIMED
.
IN
NO
EVENT
SHALL
THE
COPYRIGHT
HOLDER
OR
*
CONTRIBUTORS
BE
LIABLE
FOR
ANY
DIRECT
,
INDIRECT
,
INCIDENTAL
,
SPECIAL
,
*
EXEMPLARY
,
OR
CONSEQUENTIAL
DAMAGES
(
INCLUDING
,
BUT
NOT
LIMITED
TO
,
*
PROCUREMENT
OF
SUBSTITUTE
GOODS
OR
SERVICES
; LOSS OF USE, DATA, OR PROFITS;
*
OR
BUSINESS
INTERRUPTION
)
HOWEVER
CAUSED
AND
ON
ANY
THEORY
OF
LIABILITY
,
*
WHETHER
IN
CONTRACT
,
STRICT
LIABILITY
,
OR
TORT
(
INCLUDING
NEGLIGENCE
OR
*
OTHERWISE
)
ARISING
IN
ANY
WAY
OUT
OF
THE
USE
OF
THIS
SOFTWARE
,
EVEN
IF
*
ADVISED
OF
THE
POSSIBILITY
OF
SUCH
DAMAGE
.
*/
#include "asm.h"
.
syntax
unified
.
arm
//
size_t
_arm_clear_user
(
void
*
addr
,
size_t
bytes
)
FUNCTION
(
_arm_clear_user
)
push
{
r0
-
r6
,
lr
}
cmp
r1
,
#
0
beq
.
Lclear_user_return
tst
r0
,
#
7
beq
.
Lclear_user_aligned
.
Lclear_user_byte
:
mov
r2
,
#
0
0
:
strb
r2
,
[
r0
],
#
1
subs
r1
,
r1
,
#
1
beq
.
Lclear_user_return
tst
r0
,
#
7
bne
0
b
.
Lclear_user_aligned
:
eor
r3
,
r3
eor
r4
,
r4
bics
r2
,
r1
,
#
15
bne
.
Lclear_user_16bytes
bics
r2
,
r1
,
#
7
bne
.
Lclear_user_8bytes
b
.
Lclear_user_remaining
.
Lclear_user_16bytes
:
eor
r5
,
r5
eor
r6
,
r6
1
:
stmia
r0
!,
{
r3
,
r4
,
r5
,
r6
}
subs
r2
,
r2
,
#
16
bne
1
b
ands
r1
,
r1
,
#
15
beq
.
Lclear_user_return
bics
r2
,
r1
,
#
7
beq
.
Lclear_user_remaining
.
Lclear_user_8bytes
:
2
:
stmia
r0
!,
{
r3
,
r4
}
ands
r1
,
r1
,
#
7
beq
.
Lclear_user_return
.
Lclear_user_remaining
:
mov
r2
,
#
0
3
:
strb
r2
,
[
r0
],
#
1
subs
r1
,
r1
,
#
1
bne
3
b
.
Lclear_user_return
:
pop
{
r0
-
r6
,
lr
}
mov
r0
,
#
0
bx
lr
.
Lclear_user_err
:
pop
{
r0
,
r1
}
sub
r0
,
r2
,
r0
sub
r0
,
r1
,
r0
pop
{
r2
-
r6
,
lr
}
bx
lr
.
pushsection
__exc_table
,
"a"
.
long
0
b
,
.
Lclear_user_err
.
long
1
b
,
.
Lclear_user_err
.
long
2
b
,
.
Lclear_user_err
.
long
3
b
,
.
Lclear_user_err
.
popsection
arch/arm/arm/src/user_copy.c
浏览文件 @
339c467e
...
...
@@ -31,6 +31,7 @@
#include "user_copy.h"
#include "arm_user_copy.h"
#include "arm_user_clear.h"
#include "securec.h"
#include "los_memory.h"
#include "los_vm_map.h"
...
...
@@ -96,15 +97,9 @@ INT32 LOS_UserMemClear(unsigned char *buf, UINT32 len)
if
(
!
LOS_IsUserAddressRange
((
vaddr_t
)(
UINTPTR
)
buf
,
len
))
{
(
VOID
)
memset_s
(
buf
,
len
,
0
,
len
);
}
else
{
unsigned
char
*
tmp
=
(
unsigned
char
*
)
LOS_MemAlloc
(
OS_SYS_MEM_ADDR
,
len
);
if
(
tmp
==
NULL
)
{
return
-
ENOMEM
;
if
(
_arm_clear_user
(
buf
,
len
))
{
return
-
EFAULT
;
}
(
VOID
)
memset_s
(
tmp
,
len
,
0
,
len
);
if
(
_arm_user_copy
(
buf
,
tmp
,
len
)
!=
0
)
{
ret
=
-
EFAULT
;
}
LOS_MemFree
(
OS_SYS_MEM_ADDR
,
tmp
);
}
return
ret
;
}
...
...
kernel/extended/dynload/src/los_load_elf.c
浏览文件 @
339c467e
...
...
@@ -416,42 +416,20 @@ INT32 OsGetKernelVaddr(const LosVmSpace *space, VADDR_T vaddr, VADDR_T *kvaddr)
STATIC
INT32
OsSetBss
(
const
LD_ELF_PHDR
*
elfPhdr
,
INT32
fd
,
UINTPTR
bssStart
,
UINT32
bssEnd
,
UINT32
elfProt
)
{
UINTPTR
bss
PageStart
,
bss
StartPageAlign
,
bssEndPageAlign
;
UINTPTR
bssStartPageAlign
,
bssEndPageAlign
;
UINTPTR
mapBase
;
UINT32
offset
,
size
;
UINT32
bssMapSize
;
INT32
stackFlags
;
INT32
ret
;
vaddr_t
kvaddr
=
0
;
bssPageStart
=
ROUNDDOWN
(
bssStart
,
PAGE_SIZE
);
bssStartPageAlign
=
ROUNDUP
(
bssStart
,
PAGE_SIZE
);
bssEndPageAlign
=
ROUNDUP
(
bssEnd
,
PAGE_SIZE
);
ret
=
LOS_UnMMap
(
bssPageStart
,
(
bssEndPageAlign
-
bssPageStart
));
if
((
ret
!=
LOS_OK
)
&&
(
bssPageStart
!=
0
))
{
PRINT_ERR
(
"%s[%d], Failed to unmap a region, vaddr: %#x!
\n
"
,
__FUNCTION__
,
__LINE__
,
bssPageStart
);
}
ret
=
LOS_UserSpaceVmAlloc
(
OsCurrProcessGet
()
->
vmSpace
,
PAGE_SIZE
,
(
VOID
**
)
&
bssPageStart
,
0
,
OsCvtProtFlagsToRegionFlags
(
elfProt
,
MAP_FIXED
));
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"%s[%d], Failed to do vmm alloc!
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
ENOMEM
;
}
ret
=
OsGetKernelVaddr
(
OsCurrProcessGet
()
->
vmSpace
,
bssPageStart
,
&
kvaddr
);
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"%s[%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
ret
=
LOS_UserMemClear
((
VOID
*
)
bssStart
,
PAGE_SIZE
-
ROUNDOFFSET
(
bssStart
,
PAGE_SIZE
));
if
(
ret
!=
0
)
{
PRINT_ERR
(
"%s[%d], Failed to clear bss
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
EFAULT
;
}
(
VOID
)
memset_s
((
VOID
*
)(
UINTPTR
)
kvaddr
,
PAGE_SIZE
,
0
,
PAGE_SIZE
);
offset
=
ROUNDDOWN
(
elfPhdr
->
offset
+
elfPhdr
->
fileSize
,
PAGE_SIZE
);
size
=
ROUNDOFFSET
(
elfPhdr
->
offset
+
elfPhdr
->
fileSize
,
PAGE_SIZE
);
ret
=
OsReadELFInfo
(
fd
,
(
UINT8
*
)(
UINTPTR
)
kvaddr
,
size
,
offset
);
if
(
ret
!=
LOS_OK
)
{
PRINT_ERR
(
"%s[%d]
\n
"
,
__FUNCTION__
,
__LINE__
);
return
-
EIO
;
}
bssMapSize
=
bssEndPageAlign
-
bssStartPageAlign
;
if
(
bssMapSize
>
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录