未验证 提交 66a36b13 编写于 作者: O openharmony_ci 提交者: Gitee

!418 RM.010.线程stacksize根据产品配置,增加stack pageguard保护

Merge pull request !418 from dhy308/branch_rm010
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_util.h"
#define DEFAULT_GUARD_SIZE 8192
static void pthread_guard_size_0100(void)
{
pthread_attr_t attr = {0};
size_t guard_size = 0;
pthread_getattr_default_np(&attr);
pthread_attr_getguardsize(&attr, &guard_size);
#ifdef TARGET_GUARD_SIZE
TEST(guard_size == TARGET_GUARD_SIZE);
#else
TEST(guard_size == DEFAULT_GUARD_SIZE);
#endif
}
TEST_FUN G_Fun_Array[] = {
pthread_guard_size_0100,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <errno.h>
#include <pthread.h>
#include "pthread_util.h"
#define DEFAULT_STACK_SIZE 131072
static void pthread_stack_size_0100(void)
{
pthread_attr_t attr = {0};
size_t stack_size = 0;
pthread_getattr_default_np(&attr);
pthread_attr_getstacksize(&attr, &stack_size);
#ifdef TARGET_STACK_SIZE
TEST(stack_size == TARGET_STACK_SIZE);
#else
TEST(stack_size == DEFAULT_STACK_SIZE);
#endif
}
TEST_FUN G_Fun_Array[] = {
pthread_stack_size_0100,
};
int main(void)
{
int num = sizeof(G_Fun_Array) / sizeof(TEST_FUN);
for (int pos = 0; pos < num; ++pos) {
G_Fun_Array[pos]();
}
return t_status;
}
\ No newline at end of file
......@@ -15,4 +15,6 @@ functionalext_thread_list = [
"pthread_mutex",
"pthread_rwlock_rdlock",
"pthread_rwlock_wrlock",
"pthread_guard_size",
"pthread_stack_size",
]
import("//build/test.gni")
import("//third_party/musl/musl_config.gni")
musl_base_dir = "third_party/musl/"
test_dir = "${musl_base_dir}/libc-test"
......@@ -176,6 +177,28 @@ template("test_unittest") {
ldflags += [ "-Wl,-rpath=./" ]
}
}
if (target_dir == "functionalext/thread") {
if (!defined(defines)) {
defines = []
}
if (musl_target_os == "linux" && product_path != "" &&
product_path != rebase_path("//productdefine/common/products")) {
_product_config = read_file("${product_path}/config.json", "json")
if (target_name == "pthread_stack_size") {
if (defined(_product_config.device_stack_size)) {
defines +=
[ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ]
}
}
if (target_name == "pthread_guard_size") {
if (defined(_product_config.device_guard_size)) {
defines +=
[ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ]
}
}
}
}
}
}
......
......@@ -56,3 +56,9 @@ declare_args() {
enable_musl_log = false
musl_secure_level = 1
}
declare_args() {
if (!defined(product_path)) {
product_path = ""
}
}
......@@ -389,6 +389,20 @@ template("musl_libs") {
configs -= musl_inherited_configs
configs += [ ":${abi_prefix}_musl_config" ]
if (!defined(defines)) {
defines = []
}
if (musl_target_os == "linux" && product_path != "" &&
product_path != rebase_path("//productdefine/common/products")) {
_product_config = read_file("${product_path}/config.json", "json")
if (defined(_product_config.device_stack_size)) {
defines += [ "TARGET_STACK_SIZE=${_product_config.device_stack_size}" ]
}
if (defined(_product_config.device_guard_size)) {
defines += [ "TARGET_GUARD_SIZE=${_product_config.device_guard_size}" ]
}
}
deps = porting_deps
}
......
......@@ -242,8 +242,17 @@ extern hidden volatile int __thread_list_lock;
extern hidden unsigned __default_stacksize;
extern hidden unsigned __default_guardsize;
#ifdef TARGET_STACK_SIZE
#define DEFAULT_STACK_SIZE TARGET_STACK_SIZE
#else
#define DEFAULT_STACK_SIZE 131072
#endif
#ifdef TARGET_GUARD_SIZE
#define DEFAULT_GUARD_SIZE TARGET_GUARD_SIZE
#else
#define DEFAULT_GUARD_SIZE 8192
#endif
#define DEFAULT_STACK_MAX (8<<20)
#define DEFAULT_GUARD_MAX (1<<20)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册