Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openanolis
inclavare-containers
提交
30212200
I
inclavare-containers
项目概览
openanolis
/
inclavare-containers
通知
4
Star
7
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
5
列表
看板
标记
里程碑
合并请求
0
分析
仓库
DevOps
项目成员
Pages
I
inclavare-containers
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
5
Issue
5
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
30212200
编写于
9月 08, 2020
作者:
H
haosanzi
提交者:
GitHub
9月 08, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rune/libenclave/skeleton: Fix code style of sgxutils.c
Signed-off-by:
N
Shirong Hao
<
shirong@linux.alibaba.com
>
上级
d5cd6b8e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
43 addition
and
47 deletion
+43
-47
rune/libenclave/internal/runtime/pal/skeleton/sgx.h
rune/libenclave/internal/runtime/pal/skeleton/sgx.h
+2
-2
rune/libenclave/internal/runtime/pal/skeleton/sgxutils.c
rune/libenclave/internal/runtime/pal/skeleton/sgxutils.c
+41
-45
未找到文件。
rune/libenclave/internal/runtime/pal/skeleton/sgx.h
浏览文件 @
30212200
...
...
@@ -10,8 +10,8 @@
/**
* enum sgx_epage_flags - page control flags
* %SGX_PAGE_MEASURE: Measure the page contents with a
sequence of
*
ENCLS[EEXTEND] operations.
* %SGX_PAGE_MEASURE: Measure the page contents with a
*
sequence of
ENCLS[EEXTEND] operations.
*/
enum
sgx_page_flags
{
SGX_PAGE_MEASURE
=
0x01
,
...
...
rune/libenclave/internal/runtime/pal/skeleton/sgxutils.c
浏览文件 @
30212200
...
...
@@ -7,88 +7,84 @@ static inline void cpuid(int *eax, int *ebx, int *ecx, int *edx)
{
#if defined(__x86_64__)
asm
volatile
(
"cpuid"
:
"=a"
(
*
eax
),
"=b"
(
*
ebx
),
"=c"
(
*
ecx
),
"=d"
(
*
edx
)
:
"0"
(
*
eax
),
"2"
(
*
ecx
)
:
"memory"
);
:
"=a"
(
*
eax
),
"=b"
(
*
ebx
),
"=c"
(
*
ecx
),
"=d"
(
*
edx
)
:
"0"
(
*
eax
),
"2"
(
*
ecx
)
:
"memory"
);
#else
/*
on 32bit, ebx can NOT be used as PIC code
*/
/*
on 32bit, ebx can NOT be used as PIC code
*/
asm
volatile
(
"xchgl %%ebx, %1; cpuid; xchgl %%ebx, %1"
:
"=a"
(
*
eax
),
"=r"
(
*
ebx
),
"=c"
(
*
ecx
),
"=d"
(
*
edx
)
:
"0"
(
*
eax
),
"2"
(
*
ecx
)
:
"memory"
);
:
"=a"
(
*
eax
),
"=r"
(
*
ebx
),
"=c"
(
*
ecx
),
"=d"
(
*
edx
)
:
"0"
(
*
eax
),
"2"
(
*
ecx
)
:
"memory"
);
#endif
}
static
inline
void
__cpuid
(
int
a
[
4
],
int
b
)
{
a
[
0
]
=
b
;
a
[
2
]
=
0
;
cpuid
(
&
a
[
0
],
&
a
[
1
],
&
a
[
2
],
&
a
[
3
]);
a
[
0
]
=
b
;
a
[
2
]
=
0
;
cpuid
(
&
a
[
0
],
&
a
[
1
],
&
a
[
2
],
&
a
[
3
]);
}
static
inline
void
__cpuidex
(
int
a
[
4
],
int
b
,
int
c
)
{
a
[
0
]
=
b
;
a
[
2
]
=
c
;
cpuid
(
&
a
[
0
],
&
a
[
1
],
&
a
[
2
],
&
a
[
3
]);
a
[
0
]
=
b
;
a
[
2
]
=
c
;
cpuid
(
&
a
[
0
],
&
a
[
1
],
&
a
[
2
],
&
a
[
3
]);
}
static
inline
uint64_t
xgetbv
(
uint32_t
index
)
{
uint32_t
eax
,
edx
;
uint32_t
eax
,
edx
;
asm
volatile
(
".byte 0x0f,0x01,0xd0"
/* xgetbv */
:
"=a"
(
eax
),
"=d"
(
edx
)
:
"c"
(
index
));
asm
volatile
(
".byte 0x0f,0x01,0xd0"
/* xgetbv */
:
"=a"
(
eax
),
"=d"
(
edx
)
:
"c"
(
index
));
return
eax
+
((
uint64_t
)
edx
<<
32
);
return
eax
+
((
uint64_t
)
edx
<<
32
);
}
static
inline
uint64_t
get_xcr0
()
{
return
xgetbv
(
0
);
return
xgetbv
(
0
);
}
static
bool
try_get_xcr0
(
uint64_t
*
value
)
{
int
cpu_info
[
4
]
=
{
0
,
0
,
0
,
0
};
int
cpu_info
[
4
]
=
{
0
,
0
,
0
,
0
};
*
value
=
SGX_XFRM_LEGACY
;
*
value
=
SGX_XFRM_LEGACY
;
// check if xgetbv instruction is supported
__cpuid
(
cpu_info
,
1
);
// ecx[27:26] indicate whether support xsave/xrstor, and whether enable xgetbv, xsetbv
if
(
!
(
cpu_info
[
2
]
&
(
1
<<
XSAVE_SHIFT
))
||
!
(
cpu_info
[
2
]
&
(
1
<<
OSXSAVE_SHIFT
)))
return
false
;
// check if xgetbv instruction is supported
__cpuid
(
cpu_info
,
1
);
// ecx[27:26] indicate whether support xsave/xrstor, and whether enable xgetbv, xsetbv
if
(
!
(
cpu_info
[
2
]
&
(
1
<<
XSAVE_SHIFT
))
||
!
(
cpu_info
[
2
]
&
(
1
<<
OSXSAVE_SHIFT
)))
return
false
;
*
value
=
get_xcr0
();
*
value
=
get_xcr0
();
// check if xsavec is supported
// Assume that XSAVEC is always supported if XSAVE is supported
cpu_info
[
0
]
=
cpu_info
[
1
]
=
cpu_info
[
2
]
=
cpu_info
[
3
]
=
0
;
__cpuidex
(
cpu_info
,
0xD
,
1
);
if
(
!
(
cpu_info
[
0
]
&
(
1
<<
XSAVEC_SHIFT
)))
return
false
;
// check if xsavec is supported
// Assume that XSAVEC is always supported if XSAVE is supported
cpu_info
[
0
]
=
cpu_info
[
1
]
=
cpu_info
[
2
]
=
cpu_info
[
3
]
=
0
;
__cpuidex
(
cpu_info
,
0xD
,
1
);
if
(
!
(
cpu_info
[
0
]
&
(
1
<<
XSAVEC_SHIFT
)))
return
false
;
return
true
;
return
true
;
}
void
get_sgx_xfrm_by_cpuid
(
uint64_t
*
xfrm
)
{
int
cpu_info
[
4
]
=
{
0
,
0
,
0
,
0
};
int
cpu_info
[
4
]
=
{
0
,
0
,
0
,
0
};
__cpuidex
(
cpu_info
,
SGX_LEAF
,
1
);
__cpuidex
(
cpu_info
,
SGX_LEAF
,
1
);
if
(
false
==
try_get_xcr0
(
xfrm
))
{
if
(
try_get_xcr0
(
xfrm
)
==
false
)
{
// if XSAVE is supported, while XSAVEC is not supported,
// set xfrm to legacy, because XSAVEC cannot be executed within enclave.
*
xfrm
=
SGX_XFRM_LEGACY
;
}
else
{
*
xfrm
=
SGX_XFRM_LEGACY
;
}
else
{
// If x-feature is supported and enabled by OS, we need make sure it is also supported in enclave.
*
xfrm
&=
(((
uint64_t
)
cpu_info
[
3
]
<<
32
)
|
cpu_info
[
2
]);
}
*
xfrm
&=
(((
uint64_t
)
cpu_info
[
3
]
<<
32
)
|
cpu_info
[
2
]);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录