提交 b21cbbe5 编写于 作者: Y yinchuang 提交者: Gitee

Merge branch 'master' of gitee.com:openharmony/third_party_musl into musl_print

Signed-off-by: Nyinchuang <yinchuang@huawei.com>
...@@ -44,4 +44,7 @@ __progname; ...@@ -44,4 +44,7 @@ __progname;
__progname_full; __progname_full;
__stack_chk_guard; __stack_chk_guard;
exit;
_Exit;
}; };
...@@ -105,6 +105,7 @@ config("config_unittest") { ...@@ -105,6 +105,7 @@ config("config_unittest") {
"-Wno-error=unused-function", "-Wno-error=unused-function",
"-g", "-g",
"-D_FILE_OFFSET_BITS=64", "-D_FILE_OFFSET_BITS=64",
"-Wno-constant-conversion",
] ]
ldflags = [ "-nostdlib" ] ldflags = [ "-nostdlib" ]
......
...@@ -43,7 +43,7 @@ void readdir_0200(void) ...@@ -43,7 +43,7 @@ void readdir_0200(void)
DIR *dir = (DIR *)""; DIR *dir = (DIR *)"";
struct dirent *ret; struct dirent *ret;
ret = readdir(dir); ret = readdir(dir);
EXPECT_TRUE("readdir_0200", NULL == ret); EXPECT_TRUE(" readdir_0200", NULL == ret);
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
......
/** /**
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
#include <netdb.h> #include <netdb.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <pthread.h>
#include <string.h>
#include <errno.h>
#include "functionalext.h" #include "functionalext.h"
...@@ -276,7 +279,7 @@ void getaddrinfo_1500(void) ...@@ -276,7 +279,7 @@ void getaddrinfo_1500(void)
EXPECT_EQ("getaddrinfo_1500", ret, SOCKTYPE_NOTSUPPORTED); EXPECT_EQ("getaddrinfo_1500", ret, SOCKTYPE_NOTSUPPORTED);
} }
int main(int argc, char *argv[]) static void *test_all_cases(void *arg)
{ {
getaddrinfo_0100(); getaddrinfo_0100();
getaddrinfo_0200(); getaddrinfo_0200();
...@@ -293,6 +296,40 @@ int main(int argc, char *argv[]) ...@@ -293,6 +296,40 @@ int main(int argc, char *argv[])
getaddrinfo_1300(); getaddrinfo_1300();
getaddrinfo_1400(); getaddrinfo_1400();
getaddrinfo_1500(); getaddrinfo_1500();
return arg;
}
static void do_test_concurrently(void *(*test) (void *arg), size_t num_threads)
{
pthread_t *threads = (pthread_t *) malloc(sizeof(pthread_t) * num_threads);
if (threads == NULL) {
t_error("Failed to allocate memory: %s\n", strerror(errno));
return;
}
size_t last = 0;
while (last < num_threads) {
if (pthread_create(&(threads[last]), NULL, test, NULL)) {
t_error("Failed to create thread: %s\n", strerror(errno));
break;
}
last++;
}
for (size_t i = 0; i < last; i++) {
if (pthread_join(threads[i], NULL)) {
t_error("Failed to join thread: %s\n", strerror(errno));
}
}
free(threads);
return;
}
int main(int argc, char *argv[])
{
size_t num_threads = 16;
do_test_concurrently(test_all_cases, num_threads);
return t_status; return t_status;
} }
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <trace/trace_marker.h> #include <trace/trace_marker.h>
#include <errno.h>
#include <fcntl.h> #include <fcntl.h>
#include <pthread.h> #include <pthread.h>
#include <stdbool.h> #include <stdbool.h>
...@@ -25,6 +26,8 @@ ...@@ -25,6 +26,8 @@
#include <unistd.h> #include <unistd.h>
#define BUFFER_LEN 10240 #define BUFFER_LEN 10240
#define READ_BUFFER_SIZE 4096
#define OUTFILE "/data/local/tmp/musl.trace"
#define EXPECT_TRUE(c) \ #define EXPECT_TRUE(c) \
do \ do \
{ \ { \
...@@ -38,21 +41,64 @@ ...@@ -38,21 +41,64 @@
t_error("[%s] failed \n"); \ t_error("[%s] failed \n"); \
} while (0) } while (0)
#ifndef TRACE_TEMP_FAILURE_RETRY
#define TRACE_TEMP_FAILURE_RETRY(exp) \
({ \
long int _rc; \
do { \
_rc = (long int)(exp); \
} while ((_rc == -1) && (errno == EINTR)); \
_rc; \
})
#endif
typedef void (*TEST_FUN)(void); typedef void (*TEST_FUN)(void);
static const int WAIT_TIME = 1; static const int WAIT_TIME = 1;
static const int count = 10; static const int count = 100;
static void clear_trace()
{
if (access("/sys/kernel/tracing/trace", F_OK) == 0) {
system("echo > /sys/kernel/tracing/trace");
}
if (access("/sys/kernel/debug/tracing/trace", F_OK) == 0) {
system("echo > /sys/kernel/tracing/trace");
}
return;
}
static void dump_trace(int trace_fd)
{
char buffer[READ_BUFFER_SIZE];
int nwrite;
int nread;
int out_fd = open(OUTFILE, O_WRONLY | O_CREAT);
if (out_fd == -1) {
return;
}
do {
nread = TRACE_TEMP_FAILURE_RETRY(read(trace_fd, buffer, READ_BUFFER_SIZE));
if ((nread == 0) || (nread == -1)) {
break;
}
nwrite = TRACE_TEMP_FAILURE_RETRY(write(out_fd, buffer, nread));
} while (nwrite > 0);
close(out_fd);
}
/** /**
* @tc.name : trace_marker * @tc.name : trace_marker
* @tc.desc : Test trace_marker_begin and trace_marker_end. * @tc.desc : Test trace_marker_begin and trace_marker_end.
* @tc.level : Level 0 * @tc.level : Level 0
*/ */
static void trace_marker_0010(void) static void trace_marker_0010(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Musl_Trace_Marker_0100", ""); trace_marker_begin(HITRACE_TAG_MUSL, "Musl_Trace_Marker_0010", "");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -67,7 +113,7 @@ static void trace_marker_0010(void) ...@@ -67,7 +113,7 @@ static void trace_marker_0010(void)
char buf_begin[BUFFER_LEN] = {0}; char buf_begin[BUFFER_LEN] = {0};
char buf_end[BUFFER_LEN] = {0}; char buf_end[BUFFER_LEN] = {0};
int buf_begin_fd = snprintf(buf_begin, BUFFER_LEN, "B|%d|%s", getpid(), "Musl_Trace_Marker_0100"); int buf_begin_fd = snprintf(buf_begin, BUFFER_LEN, "B|%d|%s", getpid(), "Musl_Trace_Marker_0010");
if (buf_begin_fd < 0) { if (buf_begin_fd < 0) {
close(trace_fd); close(trace_fd);
return; return;
...@@ -100,9 +146,10 @@ static void trace_marker_0010(void) ...@@ -100,9 +146,10 @@ static void trace_marker_0010(void)
*/ */
static void trace_marker_0020(void) static void trace_marker_0020(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("async_begin_0200", "trace_async",1); trace_marker_async_begin(HITRACE_TAG_MUSL, "async_begin_0200", "trace_async",1);
trace_marker_async_end("async_end_0200", "trace_async",1); trace_marker_async_end(HITRACE_TAG_MUSL, "async_end_0200", "trace_async",1);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -150,9 +197,10 @@ static void trace_marker_0020(void) ...@@ -150,9 +197,10 @@ static void trace_marker_0020(void)
*/ */
static void trace_marker_0030(void) static void trace_marker_0030(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
int traceCount = 5; int traceCount = 5;
trace_marker_count("traceCount", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -195,6 +243,7 @@ static void trace_marker_0030(void) ...@@ -195,6 +243,7 @@ static void trace_marker_0030(void)
*/ */
static void trace_marker_0040(void) static void trace_marker_0040(void)
{ {
clear_trace();
bool trace_sucess = false; bool trace_sucess = false;
char buffer_fir[BUFFER_LEN] = {0}; char buffer_fir[BUFFER_LEN] = {0};
char buffer_sec[BUFFER_LEN] = {0}; char buffer_sec[BUFFER_LEN] = {0};
...@@ -208,8 +257,8 @@ static void trace_marker_0040(void) ...@@ -208,8 +257,8 @@ static void trace_marker_0040(void)
} else if (fpid == 0) { } else if (fpid == 0) {
int pidChild = getpid(); int pidChild = getpid();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker0400_Forkfir", ""); trace_marker_begin(HITRACE_TAG_MUSL, "Trace_Marker0400_Forkfir", "");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -246,8 +295,8 @@ static void trace_marker_0040(void) ...@@ -246,8 +295,8 @@ static void trace_marker_0040(void)
exit(pidChild); exit(pidChild);
} else { } else {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker0400_Forksec", ""); trace_marker_begin(HITRACE_TAG_MUSL, "Trace_Marker0400_Forksec", "");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -291,6 +340,7 @@ static void trace_marker_0040(void) ...@@ -291,6 +340,7 @@ static void trace_marker_0040(void)
*/ */
static void trace_marker_0050(void) static void trace_marker_0050(void)
{ {
clear_trace();
bool trace_async_sucess = false; bool trace_async_sucess = false;
char buffer_forkFir[BUFFER_LEN] = {0}; char buffer_forkFir[BUFFER_LEN] = {0};
char buffer_forkSec[BUFFER_LEN] = {0}; char buffer_forkSec[BUFFER_LEN] = {0};
...@@ -304,8 +354,8 @@ static void trace_marker_0050(void) ...@@ -304,8 +354,8 @@ static void trace_marker_0050(void)
} else if (fpid == 0) { } else if (fpid == 0) {
int pidChild = getpid(); int pidChild = getpid();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("async0500_Forkfir", "begin_fir", 2); trace_marker_async_begin(HITRACE_TAG_MUSL, "async0500_Forkfir", "begin_fir", 2);
trace_marker_async_end("async0500_Forkfir", "end_fir", 2); trace_marker_async_end(HITRACE_TAG_MUSL, "async0500_Forkfir", "end_fir", 2);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -342,8 +392,8 @@ static void trace_marker_0050(void) ...@@ -342,8 +392,8 @@ static void trace_marker_0050(void)
exit(pidChild); exit(pidChild);
} else { } else {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("async0500_Forksec", "begin_sec", 3); trace_marker_async_begin(HITRACE_TAG_MUSL, "async0500_Forksec", "begin_sec", 3);
trace_marker_async_end("async0500_Forksec", "end_sec", 3); trace_marker_async_end(HITRACE_TAG_MUSL, "async0500_Forksec", "end_sec", 3);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -387,6 +437,7 @@ static void trace_marker_0050(void) ...@@ -387,6 +437,7 @@ static void trace_marker_0050(void)
*/ */
static void trace_marker_0060(void) static void trace_marker_0060(void)
{ {
clear_trace();
int traceCount = 5; int traceCount = 5;
bool trace_count_sucess = false; bool trace_count_sucess = false;
char buffer_forkFir[BUFFER_LEN] = {0}; char buffer_forkFir[BUFFER_LEN] = {0};
...@@ -401,7 +452,7 @@ static void trace_marker_0060(void) ...@@ -401,7 +452,7 @@ static void trace_marker_0060(void)
int pidChild = getpid(); int pidChild = getpid();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_count("traceCount_forkfir", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount_forkfir", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -432,7 +483,7 @@ static void trace_marker_0060(void) ...@@ -432,7 +483,7 @@ static void trace_marker_0060(void)
exit(pidChild); exit(pidChild);
} else { } else {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_count("traceCount_forksec", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount_forksec", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY | O_APPEND);
...@@ -466,8 +517,8 @@ static void trace_marker_0060(void) ...@@ -466,8 +517,8 @@ static void trace_marker_0060(void)
static void *ThreadTraceMarkerFir(void *arg) static void *ThreadTraceMarkerFir(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker_Threadfir", "pthreadfir"); trace_marker_begin(HITRACE_TAG_MUSL, "Trace_Marker_Threadfir", "pthreadfir");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -512,8 +563,8 @@ static void *ThreadTraceMarkerFir(void *arg) ...@@ -512,8 +563,8 @@ static void *ThreadTraceMarkerFir(void *arg)
static void *ThreadTraceMarkerSec(void *arg) static void *ThreadTraceMarkerSec(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker_Threadsec", "pthreadsec"); trace_marker_begin(HITRACE_TAG_MUSL, "Trace_Marker_Threadsec", "pthreadsec");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -562,6 +613,7 @@ static void *ThreadTraceMarkerSec(void *arg) ...@@ -562,6 +613,7 @@ static void *ThreadTraceMarkerSec(void *arg)
*/ */
static void trace_marker_0070(void) static void trace_marker_0070(void)
{ {
clear_trace();
int res; int res;
const char msgThread1[1024] = {"msgThread1"}; const char msgThread1[1024] = {"msgThread1"};
const char msgThread2[1024] = {"msgThread2"}; const char msgThread2[1024] = {"msgThread2"};
...@@ -582,8 +634,8 @@ static void trace_marker_0070(void) ...@@ -582,8 +634,8 @@ static void trace_marker_0070(void)
static void *ThreadTraceMarkerAsyncFir(void *arg) static void *ThreadTraceMarkerAsyncFir(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("Async_Threadfir", "begin_threadfir",4); trace_marker_async_begin(HITRACE_TAG_MUSL, "Async_Threadfir", "begin_threadfir",4);
trace_marker_async_end("Async_Threadfir", "end_threadfir", 4); trace_marker_async_end(HITRACE_TAG_MUSL, "Async_Threadfir", "end_threadfir", 4);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -628,8 +680,8 @@ static void *ThreadTraceMarkerAsyncFir(void *arg) ...@@ -628,8 +680,8 @@ static void *ThreadTraceMarkerAsyncFir(void *arg)
static void *ThreadTraceMarkerAsyncSec(void *arg) static void *ThreadTraceMarkerAsyncSec(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("Async_Threadsec", "begin_threadsec",5); trace_marker_async_begin(HITRACE_TAG_MUSL, "Async_Threadsec", "begin_threadsec",5);
trace_marker_async_end("Async_Threadsec", "end_threadsec",5); trace_marker_async_end(HITRACE_TAG_MUSL, "Async_Threadsec", "end_threadsec",5);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -678,6 +730,7 @@ static void *ThreadTraceMarkerAsyncSec(void *arg) ...@@ -678,6 +730,7 @@ static void *ThreadTraceMarkerAsyncSec(void *arg)
*/ */
static void trace_marker_0080(void) static void trace_marker_0080(void)
{ {
clear_trace();
int res; int res;
const char msgThread1[1024] = {"msgThread3"}; const char msgThread1[1024] = {"msgThread3"};
const char msgThread2[1024] = {"msgThread4"}; const char msgThread2[1024] = {"msgThread4"};
...@@ -699,7 +752,7 @@ static void *ThreadTraceMarkerCountFir(void *arg) ...@@ -699,7 +752,7 @@ static void *ThreadTraceMarkerCountFir(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
int traceCount = 5; int traceCount = 5;
trace_marker_count("traceCount_Threadfir", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount_Threadfir", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -740,7 +793,7 @@ static void *ThreadTraceMarkerCountSec(void *arg) ...@@ -740,7 +793,7 @@ static void *ThreadTraceMarkerCountSec(void *arg)
{ {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
int traceCount = 5; int traceCount = 5;
trace_marker_count("traceCount_Threadsec", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount_Threadsec", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -783,6 +836,7 @@ static void *ThreadTraceMarkerCountSec(void *arg) ...@@ -783,6 +836,7 @@ static void *ThreadTraceMarkerCountSec(void *arg)
*/ */
static void trace_marker_0090(void) static void trace_marker_0090(void)
{ {
clear_trace();
int res; int res;
const char msgThread1[1024] = {"msgThread5"}; const char msgThread1[1024] = {"msgThread5"};
const char msgThread2[1024] = {"msgThread6"}; const char msgThread2[1024] = {"msgThread6"};
...@@ -807,9 +861,10 @@ static void trace_marker_0090(void) ...@@ -807,9 +861,10 @@ static void trace_marker_0090(void)
*/ */
static void trace_marker_0100(void) static void trace_marker_0100(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Musl_Trace_Marker_0100", NULL); trace_marker_begin(HITRACE_TAG_MUSL, "Musl_Trace_Marker_0100", NULL);
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -858,13 +913,14 @@ static void trace_marker_0100(void) ...@@ -858,13 +913,14 @@ static void trace_marker_0100(void)
*/ */
static void trace_marker_0110(void) static void trace_marker_0110(void)
{ {
clear_trace();
char message[1026]= {0}; char message[1026]= {0};
memset(message, 1, 1025); memset(message, 1, 1025);
message[1025] = '\0'; message[1025] = '\0';
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin(message, ""); trace_marker_begin(HITRACE_TAG_MUSL, message, "");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -914,9 +970,10 @@ static void trace_marker_0110(void) ...@@ -914,9 +970,10 @@ static void trace_marker_0110(void)
*/ */
static void trace_marker_0120(void) static void trace_marker_0120(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin(NULL, ""); trace_marker_begin(HITRACE_TAG_MUSL, NULL, "");
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -957,9 +1014,10 @@ static void trace_marker_0120(void) ...@@ -957,9 +1014,10 @@ static void trace_marker_0120(void)
*/ */
static void trace_marker_0140(void) static void trace_marker_0140(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("async_begin_0200", NULL,1); trace_marker_async_begin(HITRACE_TAG_MUSL, "async_begin_0200", NULL,1);
trace_marker_async_end("async_end_0200", NULL,1); trace_marker_async_end(HITRACE_TAG_MUSL, "async_end_0200", NULL,1);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -1009,13 +1067,14 @@ static void trace_marker_0140(void) ...@@ -1009,13 +1067,14 @@ static void trace_marker_0140(void)
*/ */
static void trace_marker_0150(void) static void trace_marker_0150(void)
{ {
clear_trace();
char message[1026]= {0}; char message[1026]= {0};
memset(message, 1, 1025); memset(message, 1, 1025);
message[1025] = '\0'; message[1025] = '\0';
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin(message, "trace_async",1); trace_marker_async_begin(HITRACE_TAG_MUSL, message, "trace_async",1);
trace_marker_async_end(message, "trace_async",1); trace_marker_async_end(HITRACE_TAG_MUSL, message, "trace_async",1);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -1063,9 +1122,10 @@ static void trace_marker_0150(void) ...@@ -1063,9 +1122,10 @@ static void trace_marker_0150(void)
*/ */
static void trace_marker_0160(void) static void trace_marker_0160(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin(NULL, "trace_async",1); trace_marker_async_begin(HITRACE_TAG_MUSL, NULL, "trace_async",1);
trace_marker_async_end(NULL, "trace_async",1); trace_marker_async_end(HITRACE_TAG_MUSL, NULL, "trace_async",1);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -1113,13 +1173,14 @@ static void trace_marker_0160(void) ...@@ -1113,13 +1173,14 @@ static void trace_marker_0160(void)
*/ */
static void trace_marker_0180(void) static void trace_marker_0180(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
int traceCount = 5; int traceCount = 5;
char message[1026]= {0}; char message[1026]= {0};
memset(message, 1, 1025); memset(message, 1, 1025);
message[1025] = '\0'; message[1025] = '\0';
trace_marker_count(message, traceCount); trace_marker_count(HITRACE_TAG_MUSL, message, traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -1162,9 +1223,10 @@ static void trace_marker_0180(void) ...@@ -1162,9 +1223,10 @@ static void trace_marker_0180(void)
*/ */
static void trace_marker_0190(void) static void trace_marker_0190(void)
{ {
clear_trace();
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
int traceCount = 5; int traceCount = 5;
trace_marker_count(NULL, traceCount); trace_marker_count(HITRACE_TAG_MUSL, NULL, traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY); int trace_fd = open("/sys/kernel/tracing/trace", O_CLOEXEC | O_RDONLY);
...@@ -1217,7 +1279,7 @@ TEST_FUN G_Fun_Array[] = { ...@@ -1217,7 +1279,7 @@ TEST_FUN G_Fun_Array[] = {
trace_marker_0160, trace_marker_0160,
trace_marker_0180, trace_marker_0180,
trace_marker_0190, trace_marker_0190,
}; };
int main(void) int main(void)
{ {
...@@ -1227,4 +1289,4 @@ int main(void) ...@@ -1227,4 +1289,4 @@ int main(void)
} }
return t_status; return t_status;
} }
\ No newline at end of file
...@@ -49,8 +49,8 @@ static void trace_marker_stresstest_0010(void) ...@@ -49,8 +49,8 @@ static void trace_marker_stresstest_0010(void)
while (traceCount <= 5000) { while (traceCount <= 5000) {
snprintf(buf, BUFFER_LEN, "%d", traceCount); snprintf(buf, BUFFER_LEN, "%d", traceCount);
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_async_begin("Trace_Marker_Async_Begin", buf, 1); trace_marker_async_begin(HITRACE_TAG_MUSL, "Trace_Marker_Async_Begin", buf, 1);
trace_marker_async_end("Trace_Marker_Async_End", buf, 1); trace_marker_async_end(HITRACE_TAG_MUSL, "Trace_Marker_Async_End", buf, 1);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
printf("trace_marker_async_begin has been running times is:%d\n", traceCount); printf("trace_marker_async_begin has been running times is:%d\n", traceCount);
traceCount++; traceCount++;
...@@ -69,8 +69,8 @@ static void trace_marker_stresstest_0010(void) ...@@ -69,8 +69,8 @@ static void trace_marker_stresstest_0010(void)
while (traceCount <= 5000) { while (traceCount <= 5000) {
snprintf(buf, BUFFER_LEN, "%d", traceCount); snprintf(buf, BUFFER_LEN, "%d", traceCount);
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_begin("Trace_Marker", buf); trace_marker_begin(HITRACE_TAG_MUSL, "Trace_Marker", buf);
trace_marker_end(); trace_marker_end(HITRACE_TAG_MUSL);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
printf("trace_marker_begin has been running times is:%d\n", traceCount); printf("trace_marker_begin has been running times is:%d\n", traceCount);
traceCount++; traceCount++;
...@@ -82,7 +82,7 @@ static void trace_marker_stresstest_0010(void) ...@@ -82,7 +82,7 @@ static void trace_marker_stresstest_0010(void)
while (traceCount <= 5000) { while (traceCount <= 5000) {
system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 1 > tracing_on");
trace_marker_count("traceCount", traceCount); trace_marker_count(HITRACE_TAG_MUSL, "traceCount", traceCount);
system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on"); system("cd /sys/kernel/debug/tracing;echo 0 > tracing_on");
printf("trace_marker_count has been running times is:%d\n", traceCount); printf("trace_marker_count has been running times is:%d\n", traceCount);
traceCount++; traceCount++;
......
...@@ -77,11 +77,11 @@ ...@@ -77,11 +77,11 @@
__fxstatat64; __fxstatat64;
__getcwd_chk; __getcwd_chk;
__getdelim; __getdelim;
__getgmtoff; # __getgmtoff;
__getitimer_time64; __getitimer_time64;
__getrusage_time64; __getrusage_time64;
__gettimeofday_time64; __gettimeofday_time64;
__getzonename; # __getzonename;
__gmtime64; __gmtime64;
__gmtime64_r; __gmtime64_r;
__gnu_Unwind_Find_exidx; __gnu_Unwind_Find_exidx;
...@@ -130,8 +130,8 @@ ...@@ -130,8 +130,8 @@
__libc_free; __libc_free;
__libc_malloc; __libc_malloc;
__libc_malloc_default_dispatch; __libc_malloc_default_dispatch;
__libc_mmap; # __libc_mmap;
__libc_munmap; # __libc_munmap;
__libc_start_main; __libc_start_main;
__lldb_mmap; __lldb_mmap;
__localtime64; __localtime64;
...@@ -142,14 +142,14 @@ ...@@ -142,14 +142,14 @@
__lxstat64; __lxstat64;
__memchr_diagnose; __memchr_diagnose;
__memcpy_chk; __memcpy_chk;
__memmove_aarch64; # __memmove_aarch64;
__memmove_chk; __memmove_chk;
__mempcpy_chk; __mempcpy_chk;
__memrchr_chk; __memrchr_chk;
__memset_chk; __memset_chk;
__mktime64; __mktime64;
__mq_timedreceive_time64; # __mq_timedreceive_time64;
__mq_timedsend_time64; # __mq_timedsend_time64;
__mtx_timedlock_time64; __mtx_timedlock_time64;
__musl_libc_globals; __musl_libc_globals;
__nanosleep_time64; __nanosleep_time64;
...@@ -160,7 +160,7 @@ ...@@ -160,7 +160,7 @@
__open64_diagnose; __open64_diagnose;
__openat_diagnose; __openat_diagnose;
__openat64_diagnose; __openat64_diagnose;
__optpos; # __optpos;
__optreset; __optreset;
__overflow; __overflow;
__poll_diagnose; __poll_diagnose;
...@@ -174,20 +174,20 @@ ...@@ -174,20 +174,20 @@
__pthread_cond_timedwait_time64; __pthread_cond_timedwait_time64;
__pthread_gettid_np; __pthread_gettid_np;
__pthread_mutex_timedlock_time64; __pthread_mutex_timedlock_time64;
__pthread_release_signal_stack; # __pthread_release_signal_stack;
__pthread_reserve_signal_stack; # __pthread_reserve_signal_stack;
__pthread_rwlock_timedrdlock_time64; __pthread_rwlock_timedrdlock_time64;
__pthread_rwlock_timedwrlock_time64; __pthread_rwlock_timedwrlock_time64;
__pthread_timedjoin_np_time64; # __pthread_timedjoin_np_time64;
__pwrite_chk; __pwrite_chk;
__read_chk; __read_chk;
__readlink_chk; __readlink_chk;
__readlinkat_chk; __readlinkat_chk;
__reboot; # __reboot;
__recv_diagnose; __recv_diagnose;
__recvfrom_diagnose; __recvfrom_diagnose;
__recvmmsg_time64; __recvmmsg_time64;
__res_state; # __res_state;
__sched_cpualloc; __sched_cpualloc;
__sched_cpucount; __sched_cpucount;
__sched_rr_get_interval_time64; __sched_rr_get_interval_time64;
...@@ -313,20 +313,20 @@ ...@@ -313,20 +313,20 @@
add_special_signal_handler; add_special_signal_handler;
adjtime; adjtime;
adjtimex; adjtimex;
aio_cancel; # aio_cancel;
aio_cancel64; # aio_cancel64;
aio_error; # aio_error;
aio_error64; # aio_error64;
aio_fsync; # aio_fsync;
aio_fsync64; # aio_fsync64;
aio_read; # aio_read;
aio_read64; # aio_read64;
aio_return; # aio_return;
aio_return64; # aio_return64;
aio_suspend; # aio_suspend;
aio_suspend64; # aio_suspend64;
aio_write; # aio_write;
aio_write64; # aio_write64;
alarm; alarm;
aligned_alloc; aligned_alloc;
alphasort; alphasort;
...@@ -421,7 +421,7 @@ ...@@ -421,7 +421,7 @@
cfsetospeed; cfsetospeed;
cfsetspeed; cfsetspeed;
chdir; chdir;
check_asan_path; # check_asan_path;
chmod; chmod;
chown; chown;
chroot; chroot;
...@@ -451,8 +451,8 @@ ...@@ -451,8 +451,8 @@
cnd_signal; cnd_signal;
cnd_timedwait; cnd_timedwait;
cnd_wait; cnd_wait;
configor_free; # configor_free;
configor_init; # configor_init;
confstr; confstr;
conj; conj;
conjf; conjf;
...@@ -480,7 +480,7 @@ ...@@ -480,7 +480,7 @@
creat; creat;
creat64; creat64;
crypt; crypt;
crypt_r; # crypt_r;
csin; csin;
csinf; csinf;
csinh; csinh;
...@@ -524,9 +524,9 @@ ...@@ -524,9 +524,9 @@
dlns_inherit; dlns_inherit;
dlns_init; dlns_init;
dlns_set_namespace_allowed_libs; dlns_set_namespace_allowed_libs;
dlns_set_namespace_lib_path; # dlns_set_namespace_lib_path;
dlns_set_namespace_permitted_paths; # dlns_set_namespace_permitted_paths;
dlns_set_namespace_separated; # dlns_set_namespace_separated;
dlopen; dlopen;
dlopen_ext; dlopen_ext;
dlopen_ns; dlopen_ns;
...@@ -537,7 +537,7 @@ ...@@ -537,7 +537,7 @@
dn_skipname; dn_skipname;
dngettext; dngettext;
dns_get_addr_info_from_netsys_cache; dns_get_addr_info_from_netsys_cache;
dns_set_addr_info_to_netsys_cache; # dns_set_addr_info_to_netsys_cache;
dprintf; dprintf;
drand48; drand48;
drem; drem;
...@@ -548,8 +548,8 @@ ...@@ -548,8 +548,8 @@
duplocale; duplocale;
eaccess; eaccess;
ecvt; ecvt;
encode_ptr; # encode_ptr;
encrypt; # encrypt;
endgrent; endgrent;
endhostent; endhostent;
endmntent; endmntent;
...@@ -668,7 +668,7 @@ ...@@ -668,7 +668,7 @@
fgetxattr; fgetxattr;
fileno; fileno;
fileno_unlocked; fileno_unlocked;
find_ns_by_name; # find_ns_by_name;
finish_install_ohos_malloc_hooks; finish_install_ohos_malloc_hooks;
finite; finite;
finitef; finitef;
...@@ -762,7 +762,7 @@ ...@@ -762,7 +762,7 @@
get_application_target_sdk_version; get_application_target_sdk_version;
get_avphys_pages; get_avphys_pages;
get_current_dir_name; get_current_dir_name;
get_default_ns; # get_default_ns;
get_device_api_version; get_device_api_version;
get_fatal_message; get_fatal_message;
get_nprocs; get_nprocs;
...@@ -857,7 +857,7 @@ ...@@ -857,7 +857,7 @@
getsockopt; getsockopt;
getspent; getspent;
getspnam; getspnam;
getspnam_r; # getspnam_r;
getsubopt; getsubopt;
gettext; gettext;
GetThreadName; GetThreadName;
...@@ -886,7 +886,7 @@ ...@@ -886,7 +886,7 @@
gmtime_r; gmtime_r;
grantpt; grantpt;
h_errno; h_errno;
handle_asan_path_open; # handle_asan_path_open;
HashMapAdd; HashMapAdd;
HashMapCreate; HashMapCreate;
HashMapDestroy; HashMapDestroy;
...@@ -945,11 +945,11 @@ ...@@ -945,11 +945,11 @@
inotify_init1; inotify_init1;
inotify_rm_watch; inotify_rm_watch;
insque; insque;
INVALID_SOCKET; # INVALID_SOCKET;
ioctl; ioctl;
is_accessible; # is_accessible;
is_allow_internet; is_allow_internet;
is_sharable; # is_sharable;
isalnum; isalnum;
isalnum_l; isalnum_l;
isalpha; isalpha;
...@@ -1034,8 +1034,8 @@ ...@@ -1034,8 +1034,8 @@
lgetxattr; lgetxattr;
link; link;
linkat; linkat;
lio_listio; # lio_listio;
lio_listio64; # lio_listio64;
listen; listen;
listxattr; listxattr;
llabs; llabs;
...@@ -1143,16 +1143,16 @@ ...@@ -1143,16 +1143,16 @@
modfl; modfl;
mount; mount;
mprotect; mprotect;
mq_close; # mq_close;
mq_getattr; # mq_getattr;
mq_notify; # mq_notify;
mq_open; # mq_open;
mq_receive; # mq_receive;
mq_send; # mq_send;
mq_setattr; # mq_setattr;
mq_timedreceive; # mq_timedreceive;
mq_timedsend; # mq_timedsend;
mq_unlink; # mq_unlink;
mrand48; mrand48;
mremap; mremap;
msgctl; msgctl;
...@@ -1178,7 +1178,7 @@ ...@@ -1178,7 +1178,7 @@
nearbyintf; nearbyintf;
nearbyintl; nearbyintl;
newlocale; newlocale;
next_key; # next_key;
nextafter; nextafter;
nextafterf; nextafterf;
nextafterl; nextafterl;
...@@ -1192,10 +1192,10 @@ ...@@ -1192,10 +1192,10 @@
nl_langinfo; nl_langinfo;
nl_langinfo_l; nl_langinfo_l;
nrand48; nrand48;
ns_add_dso; # ns_add_dso;
ns_add_inherit; ns_add_inherit;
ns_alloc; # ns_alloc;
ns_free; # ns_free;
ns_get16; ns_get16;
ns_get32; ns_get32;
ns_initparse; ns_initparse;
...@@ -1203,17 +1203,17 @@ ...@@ -1203,17 +1203,17 @@
ns_parserr; ns_parserr;
ns_put16; ns_put16;
ns_put32; ns_put32;
ns_set_allowed_libs; # ns_set_allowed_libs;
ns_set_asan_lib_paths; # ns_set_asan_lib_paths;
ns_set_asan_permitted_paths; # ns_set_asan_permitted_paths;
ns_set_env_paths; # ns_set_env_paths;
ns_set_lib_paths; # ns_set_lib_paths;
ns_set_name; # ns_set_name;
ns_set_permitted_paths; # ns_set_permitted_paths;
ns_set_separated; # ns_set_separated;
ns_skiprr; ns_skiprr;
nslist_add_ns; # nslist_add_ns;
nslist_init; # nslist_init;
ntohl; ntohl;
ntohs; ntohs;
OH_HashMapAdd; OH_HashMapAdd;
...@@ -1338,7 +1338,7 @@ ...@@ -1338,7 +1338,7 @@
pthread_barrierattr_getpshared; pthread_barrierattr_getpshared;
pthread_barrierattr_init; pthread_barrierattr_init;
pthread_barrierattr_setpshared; pthread_barrierattr_setpshared;
pthread_cancel; # pthread_cancel;
pthread_cond_broadcast; pthread_cond_broadcast;
pthread_cond_clockwait; pthread_cond_clockwait;
pthread_cond_destroy; pthread_cond_destroy;
...@@ -1372,7 +1372,7 @@ ...@@ -1372,7 +1372,7 @@
pthread_key_delete; pthread_key_delete;
pthread_kill; pthread_kill;
pthread_mutex_clocklock; pthread_mutex_clocklock;
pthread_mutex_consistent; # pthread_mutex_consistent;
pthread_mutex_destroy; pthread_mutex_destroy;
pthread_mutex_getprioceiling; pthread_mutex_getprioceiling;
pthread_mutex_init; pthread_mutex_init;
...@@ -1386,12 +1386,12 @@ ...@@ -1386,12 +1386,12 @@
pthread_mutexattr_destroy; pthread_mutexattr_destroy;
pthread_mutexattr_getprotocol; pthread_mutexattr_getprotocol;
pthread_mutexattr_getpshared; pthread_mutexattr_getpshared;
pthread_mutexattr_getrobust; # pthread_mutexattr_getrobust;
pthread_mutexattr_gettype; pthread_mutexattr_gettype;
pthread_mutexattr_init; pthread_mutexattr_init;
pthread_mutexattr_setprotocol; pthread_mutexattr_setprotocol;
pthread_mutexattr_setpshared; pthread_mutexattr_setpshared;
pthread_mutexattr_setrobust; # pthread_mutexattr_setrobust;
pthread_mutexattr_settype; pthread_mutexattr_settype;
pthread_once; pthread_once;
pthread_rwlock_clockrdlock; pthread_rwlock_clockrdlock;
...@@ -1415,7 +1415,7 @@ ...@@ -1415,7 +1415,7 @@
pthread_setaffinity_np; pthread_setaffinity_np;
pthread_setattr_default_np; pthread_setattr_default_np;
pthread_setcancelstate; pthread_setcancelstate;
pthread_setcanceltype; # pthread_setcanceltype;
pthread_setconcurrency; pthread_setconcurrency;
pthread_setname_np; pthread_setname_np;
pthread_setschedparam; pthread_setschedparam;
...@@ -1427,9 +1427,9 @@ ...@@ -1427,9 +1427,9 @@
pthread_spin_lock; pthread_spin_lock;
pthread_spin_trylock; pthread_spin_trylock;
pthread_spin_unlock; pthread_spin_unlock;
pthread_testcancel; # pthread_testcancel;
pthread_timedjoin_np; # pthread_timedjoin_np;
pthread_tryjoin_np; # pthread_tryjoin_np;
ptrace; ptrace;
ptsname; ptsname;
ptsname_r; ptsname_r;
...@@ -1578,7 +1578,7 @@ ...@@ -1578,7 +1578,7 @@
sethostname; sethostname;
setitimer; setitimer;
setjmp; setjmp;
setkey; # setkey;
setlinebuf; setlinebuf;
setlocale; setlocale;
setlogmask; setlogmask;
...@@ -1601,6 +1601,7 @@ ...@@ -1601,6 +1601,7 @@
setsockopt; setsockopt;
setspent; setspent;
setstate; setstate;
SetThreadInfoCallback;
settimeofday; settimeofday;
setuid; setuid;
setusershell; setusershell;
...@@ -1608,8 +1609,8 @@ ...@@ -1608,8 +1609,8 @@
setutxent; setutxent;
setvbuf; setvbuf;
setxattr; setxattr;
shm_open; # shm_open;
shm_unlink; # shm_unlink;
shmat; shmat;
shmctl; shmctl;
shmdt; shmdt;
...@@ -1659,7 +1660,7 @@ ...@@ -1659,7 +1660,7 @@
sockatmark; sockatmark;
socket; socket;
SOCKET_ADDR; SOCKET_ADDR;
SOCKET_TYPE; # SOCKET_TYPE;
socketpair; socketpair;
splice; splice;
sprintf; sprintf;
...@@ -1670,7 +1671,7 @@ ...@@ -1670,7 +1671,7 @@
srand48; srand48;
srandom; srandom;
sscanf; sscanf;
stack_naming; # stack_naming;
stat; stat;
stat64; stat64;
statfs; statfs;
...@@ -1813,11 +1814,11 @@ ...@@ -1813,11 +1814,11 @@
towlower_l; towlower_l;
towupper; towupper;
towupper_l; towupper_l;
trace_marker_async_begin; # trace_marker_async_begin;
trace_marker_async_end; # trace_marker_async_end;
trace_marker_begin; trace_marker_begin;
trace_marker_count; # trace_marker_count;
trace_marker_end; # trace_marker_end;
trunc; trunc;
truncate; truncate;
truncate64; truncate64;
...@@ -1958,111 +1959,37 @@ ...@@ -1958,111 +1959,37 @@
y1f; y1f;
yn; yn;
ynf; ynf;
dlopen_ns_ext;
init_cfi_shadow;
map_dso_to_cfi_shadow;
unmap_dso_from_cfi_shadow;
__cfi_slowpath;
__cfi_slowpath_diag;
__memleak_hook_flag;
SystemFindParameter;
SystemGetParameterCommitId;
SystemGetParameterValue;
GetSystemCommitId;
mallopt;
TestParameterReaderPerformance;
reallocarray;
CachedParameterCreate;
CachedParameterGet;
CachedParameterDestroy;
CachedParameterGetChanged;
malloc_stats_print;
GetParamLabelIndex;
malloc_disable;
malloc_enable;
malloc_info;
malloc_iterate;
GetLabelIndex;
tcgetwinsize;
_Fork;
malloc_backtrace;
tcsetwinsize;
qsort_r;
local: local:
mq_close; *;
mq_getattr;
mq_notify;
mq_open;
mq_receive;
mq_send;
mq_setattr;
mq_timedreceive;
mq_timedsend;
mq_unlink;
__mq_timedreceive_time64;
__mq_timedsend_time64;
shm_open;
shm_unlink;
pthread_cancel;
# pthread_setcancelstate;
pthread_setcanceltype;
pthread_testcancel;
pthread_mutex_consistent;
pthread_mutexattr_getrobust;
pthread_mutexattr_setrobust;
__optpos;
aio_cancel;
aio_cancel64;
aio_error;
aio_error64;
aio_fsync;
aio_fsync64;
aio_read;
aio_read64;
aio_return;
aio_return64;
aio_suspend;
aio_suspend64;
aio_write;
aio_write64;
lio_listio;
lio_listio64;
setkey;
__getgmtoff;
__getzonename;
__libc_mmap;
__libc_munmap;
# __mem_typeset;
__memmove_aarch64;
__pthread_release_signal_stack;
__pthread_reserve_signal_stack;
__pthread_timedjoin_np_time64;
__reboot;
__res_state;
check_asan_path;
configor_free;
configor_init;
# crypt;
crypt_r;
dlns_set_namespace_lib_path;
dlns_set_namespace_permitted_paths;
dlns_set_namespace_separated;
dns_get_addr_info_from_net;
dns_set_addr_info_to_net;
dns_set_addr_info_to_netsys_cache;
encode_ptr;
encrypt;
find_ns_by_name;
get_default_ns;
# getspnam;
getspnam_r;
handle_asan_path_open;
HiLogAdapterIsLoggable;
HiLogAdapterPrint;
INVALID_SOCKET;
is_accessible;
is_allow_inherit;
is_sharable;
next_key;
ns_add_dso;
ns_alloc;
ns_free;
ns_set_allowed_libs;
ns_set_asan_lib_paths;
ns_set_asan_permitted_paths;
ns_set_env_paths;
ns_set_lib_paths;
ns_set_name;
ns_set_permitted_paths;
ns_set_separated;
nslist_add_ns;
nslist_init;
# ohos_malloc_hook_shared_library;
pthread_timedjoin_np;
pthread_tryjoin_np;
SOCKER_ADDR;
SOCKET_TYPE;
spnam;
stack_naming;
strlist_alloc;
strlist_free;
strlist_set;
strlwc;
strsplit;
strtrim;
sys_cache;
trace_marker_async_begin;
trace_marker_async_end;
trace_marker_count;
trace_marker_end;
}; };
...@@ -144,6 +144,7 @@ if (musl_arch == "arm") { ...@@ -144,6 +144,7 @@ if (musl_arch == "arm") {
musl_src_arch_file = [ musl_src_arch_file = [
"src/fenv/x86_64/fenv.s", "src/fenv/x86_64/fenv.s",
"src/ldso/x86_64/dlsym.s", "src/ldso/x86_64/dlsym.s",
"src/ldso/x86_64/dlvsym.s",
"src/ldso/x86_64/tlsdesc.s", "src/ldso/x86_64/tlsdesc.s",
"src/math/x86_64/__invtrigl.s", "src/math/x86_64/__invtrigl.s",
"src/math/x86_64/acosl.s", "src/math/x86_64/acosl.s",
...@@ -2165,6 +2166,9 @@ musl_src_porting_file = [ ...@@ -2165,6 +2166,9 @@ musl_src_porting_file = [
"src/ldso/x86_64/dlvsym.s", "src/ldso/x86_64/dlvsym.s",
"src/stdio/__fdopen.c", "src/stdio/__fdopen.c",
"src/stdio/vfprintf.c", "src/stdio/vfprintf.c",
"src/stdio/__stdio_read.c",
"src/stdio/fread.c",
"src/internal/stdio_impl.h",
"src/internal/vdso.c", "src/internal/vdso.c",
"src/time/clock_gettime.c", "src/time/clock_gettime.c",
"src/time/clock_getres.c", "src/time/clock_getres.c",
...@@ -2180,6 +2184,7 @@ musl_src_porting_file = [ ...@@ -2180,6 +2184,7 @@ musl_src_porting_file = [
"src/sigchain/sigchain.c", "src/sigchain/sigchain.c",
"src/conf/legacy.c", "src/conf/legacy.c",
"src/conf/sysconf.c", "src/conf/sysconf.c",
"src/env/getenv.c",
] ]
musl_inc_hook_files = [ musl_inc_hook_files = [
......
...@@ -154,6 +154,7 @@ template("musl_libs") { ...@@ -154,6 +154,7 @@ template("musl_libs") {
defines += [ defines += [
"OHOS_DNS_PROXY_BY_NETSYS=1", "OHOS_DNS_PROXY_BY_NETSYS=1",
"OHOS_PERMISSION_INTERNET=1", "OHOS_PERMISSION_INTERNET=1",
"STANDARD_SYSTEM",
] ]
} }
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#ifndef _TRACE_TRACE_MARKER_H #ifndef _TRACE_TRACE_MARKER_H
#define _TRACE_TRACE_MARKER_H #define _TRACE_TRACE_MARKER_H
#include <stdint.h>
#define TRACE_MARKER_MESSAGE_LEN 1024 #define TRACE_MARKER_MESSAGE_LEN 1024
#ifdef __cplusplus #ifdef __cplusplus
...@@ -23,42 +25,55 @@ extern "C" ...@@ -23,42 +25,55 @@ extern "C"
{ {
#endif #endif
static const uint64_t HITRACE_TAG_ALWAYS = (1ULL << 0); // This tag is always enabled.
static const uint64_t HITRACE_TAG_MUSL = (1ULL << 12); // musl tag.
/**
* @brief Reset trace_marker trace switch status
*/
void trace_marker_reset(void);
/** /**
* @brief Write the function call information to the trace_marker node in kernel space, * @brief Write the function call information to the trace_marker node in kernel space,
* used on the same thread as trace_marker_end(),with the symbol "B". * used on the same thread as trace_marker_end(),with the symbol "B".
* @param label The tagLabel of current sub-system.
* @param message The function of information. * @param message The function of information.
* @param value The value which want to trace. * @param value The value which want to trace.
*/ */
void trace_marker_begin(const char *message, const char *value); void trace_marker_begin(uint64_t label, const char *message, const char *value);
/** /**
* @brief Write the terminator to the trace_marker node of the kernel space, * @brief Write the terminator to the trace_marker node of the kernel space,
* used on the same thread as trace_marker_begin(),with the symbol "E". * used on the same thread as trace_marker_begin(),with the symbol "E".
* @param label The tagLabel of current sub-system.
*/ */
void trace_marker_end(void); void trace_marker_end(uint64_t label);
/** /**
* @brief Write the function call information to the trace_marker node in kernel space, * @brief Write the function call information to the trace_marker node in kernel space,
* used in a different thread than trace_marker_async_end(),with the symbol "S". * used in a different thread than trace_marker_async_end(),with the symbol "S".
* @param label The tagLabel of current sub-system.
* @param message The function of information. * @param message The function of information.
* @param value The value which want to trace. * @param value The value which want to trace.
*/ */
void trace_marker_async_begin(const char *message, const char *value, int taskId); void trace_marker_async_begin(uint64_t label, const char *message, const char *value, int taskId);
/** /**
* @brief Write the terminator to the trace_marker node in kernel space, * @brief Write the terminator to the trace_marker node in kernel space,
* used in a different thread than trace_marker_async_begin(),with the symbol "F". * used in a different thread than trace_marker_async_begin(),with the symbol "F".
* @param label The tagLabel of current sub-system.
* @param message The function of information. * @param message The function of information.
* @param value The value which want to trace. * @param value The value which want to trace.
*/ */
void trace_marker_async_end(const char *message, const char *value, int taskId); void trace_marker_async_end(uint64_t label, const char *message, const char *value, int taskId);
/** /**
* @brief Marks a pre-traced numeric variable,with the symbol "C". * @brief Marks a pre-traced numeric variable,with the symbol "C".
* @param label The tagLabel of current sub-system.
* @param message The function of information. * @param message The function of information.
* @param value The value which want to trace. * @param value The value which want to trace.
*/ */
void trace_marker_count(const char *message, int value); void trace_marker_count(uint64_t label, const char *message, int value);
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "pthread_impl.h" #include "pthread_impl.h"
#include "fork_impl.h" #include "fork_impl.h"
#include "strops.h" #include "strops.h"
#include "trace/trace_marker.h"
#ifdef OHOS_ENABLE_PARAMETER #ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h" #include "sys_param.h"
#endif #endif
...@@ -103,7 +105,7 @@ struct reserved_address_params { ...@@ -103,7 +105,7 @@ struct reserved_address_params {
#endif #endif
}; };
typedef void (*stage3_func)(size_t *, size_t *); typedef void (*stage3_func)(size_t *, size_t *, size_t *);
static struct builtin_tls { static struct builtin_tls {
char c[8]; char c[8];
...@@ -304,6 +306,8 @@ static void init_namespace(struct dso *app) ...@@ -304,6 +306,8 @@ static void init_namespace(struct dso *app)
char file_path[sizeof "/etc/ld-musl-namespace-" + sizeof (LDSO_ARCH) + sizeof ".ini" + 1] = {0}; char file_path[sizeof "/etc/ld-musl-namespace-" + sizeof (LDSO_ARCH) + sizeof ".ini" + 1] = {0};
(void)snprintf(file_path, sizeof file_path, "/etc/ld-musl-namespace-%s.ini", LDSO_ARCH); (void)snprintf(file_path, sizeof file_path, "/etc/ld-musl-namespace-%s.ini", LDSO_ARCH);
LD_LOGI("init_namespace file_path:%{public}s", file_path); LD_LOGI("init_namespace file_path:%{public}s", file_path);
trace_marker_reset();
trace_marker_begin(HITRACE_TAG_MUSL, "parse linker config", file_path);
int ret = conf->parse(file_path, app_path); int ret = conf->parse(file_path, app_path);
if (ret < 0) { if (ret < 0) {
LD_LOGE("init_namespace ini file parse failed!"); LD_LOGE("init_namespace ini file parse failed!");
...@@ -311,6 +315,7 @@ static void init_namespace(struct dso *app) ...@@ -311,6 +315,7 @@ static void init_namespace(struct dso *app)
if (!sys_path) get_sys_path(conf); if (!sys_path) get_sys_path(conf);
init_default_namespace(app); init_default_namespace(app);
configor_free(); configor_free();
trace_marker_end(HITRACE_TAG_MUSL);
return; return;
} }
...@@ -326,6 +331,7 @@ static void init_namespace(struct dso *app) ...@@ -326,6 +331,7 @@ static void init_namespace(struct dso *app)
if (!nsl) { if (!nsl) {
LD_LOGE("init nslist fail!"); LD_LOGE("init nslist fail!");
configor_free(); configor_free();
trace_marker_end(HITRACE_TAG_MUSL);
return; return;
} }
strlist *s_ns = conf->get_namespaces(); strlist *s_ns = conf->get_namespaces();
...@@ -345,6 +351,7 @@ static void init_namespace(struct dso *app) ...@@ -345,6 +351,7 @@ static void init_namespace(struct dso *app)
set_ns_inherits(nsl->nss[i], conf); set_ns_inherits(nsl->nss[i], conf);
} }
configor_free(); configor_free();
trace_marker_end(HITRACE_TAG_MUSL);
return; return;
} }
...@@ -2474,7 +2481,13 @@ static void do_init_fini(struct dso **queue) ...@@ -2474,7 +2481,13 @@ static void do_init_fini(struct dso **queue)
if (dyn[0] & (1<<DT_INIT_ARRAY)) { if (dyn[0] & (1<<DT_INIT_ARRAY)) {
size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t); size_t n = dyn[DT_INIT_ARRAYSZ]/sizeof(size_t);
size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]); size_t *fn = laddr(p, dyn[DT_INIT_ARRAY]);
if (p != &ldso) {
trace_marker_begin(HITRACE_TAG_MUSL, "calling constructors: ", p->name);
}
while (n--) ((void (*)(void))*fn++)(); while (n--) ((void (*)(void))*fn++)();
if (p != &ldso) {
trace_marker_end(HITRACE_TAG_MUSL);
}
} }
pthread_mutex_lock(&init_fini_lock); pthread_mutex_lock(&init_fini_lock);
...@@ -2596,6 +2609,9 @@ hidden void __dls2(unsigned char *base, size_t *sp) ...@@ -2596,6 +2609,9 @@ hidden void __dls2(unsigned char *base, size_t *sp)
} else { } else {
ldso.base = base; ldso.base = base;
} }
size_t aux[AUX_CNT];
decode_vec(auxv, aux, AUX_CNT);
libc.page_size = aux[AT_PAGESZ];
Ehdr *ehdr = (void *)ldso.base; Ehdr *ehdr = (void *)ldso.base;
ldso.name = ldso.shortname = "libc.so"; ldso.name = ldso.shortname = "libc.so";
ldso.phnum = ehdr->e_phnum; ldso.phnum = ehdr->e_phnum;
...@@ -2632,8 +2648,8 @@ hidden void __dls2(unsigned char *base, size_t *sp) ...@@ -2632,8 +2648,8 @@ hidden void __dls2(unsigned char *base, size_t *sp)
* symbolically as a barrier against moving the address * symbolically as a barrier against moving the address
* load across the above relocation processing. */ * load across the above relocation processing. */
struct symdef dls2b_def = find_sym(&ldso, "__dls2b", 0); struct symdef dls2b_def = find_sym(&ldso, "__dls2b", 0);
if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls2b_def.sym-ldso.syms])(sp, auxv); if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls2b_def.sym-ldso.syms])(sp, auxv, aux);
else ((stage3_func)laddr(&ldso, dls2b_def.sym->st_value))(sp, auxv); else ((stage3_func)laddr(&ldso, dls2b_def.sym->st_value))(sp, auxv, aux);
} }
/* Stage 2b sets up a valid thread pointer, which requires relocations /* Stage 2b sets up a valid thread pointer, which requires relocations
...@@ -2642,7 +2658,7 @@ hidden void __dls2(unsigned char *base, size_t *sp) ...@@ -2642,7 +2658,7 @@ hidden void __dls2(unsigned char *base, size_t *sp)
* so that loads of the thread pointer and &errno can be pure/const and * so that loads of the thread pointer and &errno can be pure/const and
* thereby hoistable. */ * thereby hoistable. */
void __dls2b(size_t *sp, size_t *auxv) void __dls2b(size_t *sp, size_t *auxv, size_t *aux)
{ {
/* Setup early thread pointer in builtin_tls for ldso/libc itself to /* Setup early thread pointer in builtin_tls for ldso/libc itself to
* use during dynamic linking. If possible it will also serve as the * use during dynamic linking. If possible it will also serve as the
...@@ -2656,8 +2672,8 @@ void __dls2b(size_t *sp, size_t *auxv) ...@@ -2656,8 +2672,8 @@ void __dls2b(size_t *sp, size_t *auxv)
} }
struct symdef dls3_def = find_sym(&ldso, "__dls3", 0); struct symdef dls3_def = find_sym(&ldso, "__dls3", 0);
if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp, auxv); if (DL_FDPIC) ((stage3_func)&ldso.funcdescs[dls3_def.sym-ldso.syms])(sp, auxv, aux);
else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp, auxv); else ((stage3_func)laddr(&ldso, dls3_def.sym->st_value))(sp, auxv, aux);
} }
/* Stage 3 of the dynamic linker is called with the dynamic linker/libc /* Stage 3 of the dynamic linker is called with the dynamic linker/libc
...@@ -2665,10 +2681,9 @@ void __dls2b(size_t *sp, size_t *auxv) ...@@ -2665,10 +2681,9 @@ void __dls2b(size_t *sp, size_t *auxv)
* process dependencies and relocations for the main application and * process dependencies and relocations for the main application and
* transfer control to its entry point. */ * transfer control to its entry point. */
void __dls3(size_t *sp, size_t *auxv) void __dls3(size_t *sp, size_t *auxv, size_t *aux)
{ {
static struct dso app, vdso; static struct dso app, vdso;
size_t aux[AUX_CNT];
size_t i; size_t i;
char *env_preload=0; char *env_preload=0;
char *replace_argv0=0; char *replace_argv0=0;
...@@ -2681,10 +2696,8 @@ void __dls3(size_t *sp, size_t *auxv) ...@@ -2681,10 +2696,8 @@ void __dls3(size_t *sp, size_t *auxv)
/* Find aux vector just past environ[] and use it to initialize /* Find aux vector just past environ[] and use it to initialize
* global data that may be needed before we can make syscalls. */ * global data that may be needed before we can make syscalls. */
__environ = envp; __environ = envp;
decode_vec(auxv, aux, AUX_CNT);
search_vec(auxv, &__sysinfo, AT_SYSINFO); search_vec(auxv, &__sysinfo, AT_SYSINFO);
__pthread_self()->sysinfo = __sysinfo; __pthread_self()->sysinfo = __sysinfo;
libc.page_size = aux[AT_PAGESZ];
libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID] libc.secure = ((aux[0]&0x7800)!=0x7800 || aux[AT_UID]!=aux[AT_EUID]
|| aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]); || aux[AT_GID]!=aux[AT_EGID] || aux[AT_SECURE]);
...@@ -3094,6 +3107,8 @@ static void *dlopen_impl( ...@@ -3094,6 +3107,8 @@ static void *dlopen_impl(
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
pthread_rwlock_wrlock(&lock); pthread_rwlock_wrlock(&lock);
__inhibit_ptc(); __inhibit_ptc();
trace_marker_reset();
trace_marker_begin(HITRACE_TAG_MUSL, "dlopen: ", file);
debug.state = RT_ADD; debug.state = RT_ADD;
_dl_debug_state(); _dl_debug_state();
...@@ -3170,12 +3185,14 @@ static void *dlopen_impl( ...@@ -3170,12 +3185,14 @@ static void *dlopen_impl(
LD_LOGE("dlopen_impl create loadtask failed"); LD_LOGE("dlopen_impl create loadtask failed");
goto end; goto end;
} }
trace_marker_begin(HITRACE_TAG_MUSL, "loading: entry so", file);
if (!load_library_header(task)) { if (!load_library_header(task)) {
error(noload ? error(noload ?
"Library %s is not already loaded" : "Library %s is not already loaded" :
"Error loading shared library %s: %m", "Error loading shared library %s: %m",
file); file);
LD_LOGE("dlopen_impl load library header failed for %{public}s", task->name); LD_LOGE("dlopen_impl load library header failed for %{public}s", task->name);
trace_marker_end(HITRACE_TAG_MUSL); // "loading: entry so" trace end.
goto end; goto end;
} }
if (reserved_address) { if (reserved_address) {
...@@ -3188,6 +3205,7 @@ static void *dlopen_impl( ...@@ -3188,6 +3205,7 @@ static void *dlopen_impl(
"Library %s is not already loaded" : "Library %s is not already loaded" :
"Error loading shared library %s: %m", "Error loading shared library %s: %m",
file); file);
trace_marker_end(HITRACE_TAG_MUSL); // "loading: entry so" trace end.
goto end; goto end;
} }
if (!task->isloaded) { if (!task->isloaded) {
...@@ -3210,6 +3228,7 @@ static void *dlopen_impl( ...@@ -3210,6 +3228,7 @@ static void *dlopen_impl(
free_loadtasks(tasks); free_loadtasks(tasks);
tasks = NULL; tasks = NULL;
#else #else
trace_marker_begin(HITRACE_TAG_MUSL, "loading: entry so", file);
p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL); p = load_library(file, head, ns, true, reserved_address ? &reserved_params : NULL);
} }
...@@ -3218,11 +3237,13 @@ static void *dlopen_impl( ...@@ -3218,11 +3237,13 @@ static void *dlopen_impl(
"Library %s is not already loaded" : "Library %s is not already loaded" :
"Error loading shared library %s: %m", "Error loading shared library %s: %m",
file); file);
trace_marker_end(HITRACE_TAG_MUSL); // "loading: entry so" trace end.
goto end; goto end;
} }
/* First load handling */ /* First load handling */
load_deps(p, reserved_address && reserved_address_recursive ? &reserved_params : NULL); load_deps(p, reserved_address && reserved_address_recursive ? &reserved_params : NULL);
#endif #endif
trace_marker_end(HITRACE_TAG_MUSL); // "loading: entry so" trace end.
extend_bfs_deps(p); extend_bfs_deps(p);
pthread_mutex_lock(&init_fini_lock); pthread_mutex_lock(&init_fini_lock);
int constructed = p->constructed; int constructed = p->constructed;
...@@ -3246,9 +3267,11 @@ static void *dlopen_impl( ...@@ -3246,9 +3267,11 @@ static void *dlopen_impl(
} }
} }
struct dso *reloc_head_so = p; struct dso *reloc_head_so = p;
trace_marker_begin(HITRACE_TAG_MUSL, "linking: entry so", p->name);
if (!p->relocated) { if (!p->relocated) {
reloc_all(p, extinfo); reloc_all(p, extinfo);
} }
trace_marker_end(HITRACE_TAG_MUSL);
reloc_head_so->is_reloc_head_so_dep = false; reloc_head_so->is_reloc_head_so_dep = false;
for (size_t i=0; reloc_head_so->deps[i]; i++) { for (size_t i=0; reloc_head_so->deps[i]; i++) {
reloc_head_so->deps[i]->is_reloc_head_so_dep = false; reloc_head_so->deps[i]->is_reloc_head_so_dep = false;
...@@ -3297,6 +3320,7 @@ end: ...@@ -3297,6 +3320,7 @@ end:
free(ctor_queue); free(ctor_queue);
} }
pthread_setcancelstate(cs, 0); pthread_setcancelstate(cs, 0);
trace_marker_end(HITRACE_TAG_MUSL); // "dlopen: " trace end.
return p; return p;
} }
...@@ -3487,31 +3511,19 @@ void *addr2dso(size_t a) ...@@ -3487,31 +3511,19 @@ void *addr2dso(size_t a)
{ {
struct dso *p; struct dso *p;
size_t i; size_t i;
if (DL_FDPIC) for (p=head; p; p=p->next) {
i = count_syms(p);
if (a-(size_t)p->funcdescs < i*sizeof(*p->funcdescs))
return p;
}
for (p=head; p; p=p->next) { for (p=head; p; p=p->next) {
if (DL_FDPIC && p->loadmap) { if (a < p->map || a - (size_t)p->map >= p->map_len) continue;
for (i=0; i<p->loadmap->nsegs; i++) { Phdr *ph = p->phdr;
if (a-p->loadmap->segs[i].p_vaddr size_t phcnt = p->phnum;
< p->loadmap->segs[i].p_memsz) size_t entsz = p->phentsize;
return p; size_t base = (size_t)p->base;
} for (; phcnt--; ph=(void *)((char *)ph+entsz)) {
} else { if (ph->p_type != PT_LOAD) continue;
Phdr *ph = p->phdr; if (a-base-ph->p_vaddr < ph->p_memsz)
size_t phcnt = p->phnum; return p;
size_t entsz = p->phentsize;
size_t base = (size_t)p->base;
for (; phcnt--; ph=(void *)((char *)ph+entsz)) {
if (ph->p_type != PT_LOAD) continue;
if (a-base-ph->p_vaddr < ph->p_memsz)
return p;
}
if (a-(size_t)p->map < p->map_len)
return 0;
} }
if (a-(size_t)p->map < p->map_len)
return 0;
} }
return 0; return 0;
} }
...@@ -3544,8 +3556,11 @@ static void *do_dlsym(struct dso *p, const char *s, const char *v, void *ra) ...@@ -3544,8 +3556,11 @@ static void *do_dlsym(struct dso *p, const char *s, const char *v, void *ra)
ns = caller->namespace; ns = caller->namespace;
} }
} }
trace_marker_reset();
trace_marker_begin(HITRACE_TAG_MUSL, "dlsym: ", (s == NULL ? "(NULL)" : s));
struct verinfo verinfo = { .s = s, .v = v, .use_vna_hash = false }; struct verinfo verinfo = { .s = s, .v = v, .use_vna_hash = false };
struct symdef def = find_sym2(p, &verinfo, 0, use_deps, ns); struct symdef def = find_sym2(p, &verinfo, 0, use_deps, ns);
trace_marker_end(HITRACE_TAG_MUSL);
if (!def.sym) { if (!def.sym) {
LD_LOGE("do_dlsym failed: symbol not found. so=%{public}s s=%{public}s v=%{public}s", p->name, s, v); LD_LOGE("do_dlsym failed: symbol not found. so=%{public}s s=%{public}s v=%{public}s", p->name, s, v);
error("Symbol not found: %s, version: %s", s, strlen(v) > 0 ? v : "null"); error("Symbol not found: %s, version: %s", s, strlen(v) > 0 ? v : "null");
...@@ -3580,7 +3595,8 @@ static int dlclose_impl(struct dso *p) ...@@ -3580,7 +3595,8 @@ static int dlclose_impl(struct dso *p)
if (--(p->nr_dlopen) > 0) if (--(p->nr_dlopen) > 0)
return 0; return 0;
trace_marker_reset();
trace_marker_begin(HITRACE_TAG_MUSL, "dlclose", p->name);
/* call destructors if needed */ /* call destructors if needed */
if (p->constructed) { if (p->constructed) {
size_t dyn[DYN_CNT]; size_t dyn[DYN_CNT];
...@@ -3588,8 +3604,10 @@ static int dlclose_impl(struct dso *p) ...@@ -3588,8 +3604,10 @@ static int dlclose_impl(struct dso *p)
if (dyn[0] & (1<<DT_FINI_ARRAY)) { if (dyn[0] & (1<<DT_FINI_ARRAY)) {
n = dyn[DT_FINI_ARRAYSZ] / sizeof(size_t); n = dyn[DT_FINI_ARRAYSZ] / sizeof(size_t);
size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY]) + n; size_t *fn = (size_t *)laddr(p, dyn[DT_FINI_ARRAY]) + n;
trace_marker_begin(HITRACE_TAG_MUSL, "calling destructors:", p->name);
while (n--) while (n--)
((void (*)(void))*--fn)(); ((void (*)(void))*--fn)();
trace_marker_end(HITRACE_TAG_MUSL);
} }
p->constructed = 0; p->constructed = 0;
} }
...@@ -3667,6 +3685,7 @@ static int dlclose_impl(struct dso *p) ...@@ -3667,6 +3685,7 @@ static int dlclose_impl(struct dso *p)
if (p->tls.size == 0) { if (p->tls.size == 0) {
free(p); free(p);
} }
trace_marker_end(HITRACE_TAG_MUSL);
return 0; return 0;
} }
...@@ -3746,15 +3765,71 @@ hidden int __dlclose(void *p) ...@@ -3746,15 +3765,71 @@ hidden int __dlclose(void *p)
return rc; return rc;
} }
static inline int sym_is_matched(const Sym* sym, size_t addr_offset_so) {
return sym->st_value &&
(1<<(sym->st_info&0xf) != STT_TLS) &&
(addr_offset_so >= sym->st_value) &&
(addr_offset_so < sym->st_value + sym->st_size);
}
static inline Sym* find_addr_by_elf(size_t addr_offset_so, struct dso *p) {
uint32_t nsym = p->hashtab[1];
Sym *sym = p->syms;
for (; nsym; nsym--, sym++) {
if (sym_is_matched(sym, addr_offset_so)) {
return sym;
}
}
return NULL;
}
static inline Sym* find_addr_by_gnu(size_t addr_offset_so, struct dso *p) {
size_t i, nsym, first_hash_sym_index;
uint32_t *hashval;
Sym *sym_tab = p->syms;
uint32_t *buckets= p->ghashtab + 4 + (p->ghashtab[2]*sizeof(size_t)/4);
// Points to the first defined symbol, all symbols before it are undefined.
first_hash_sym_index = buckets[0];
Sym *sym = &sym_tab[first_hash_sym_index];
// Get the location pointed by the last bucket.
for (i = nsym = 0; i < p->ghashtab[0]; i++) {
if (buckets[i] > nsym)
nsym = buckets[i];
}
for (i = first_hash_sym_index; i < nsym; i++) {
if (sym_is_matched(sym, addr_offset_so)) {
return sym;
}
sym++;
}
// Start traversing the hash list from the position pointed to by the last bucket.
if (nsym) {
hashval = buckets + p->ghashtab[0] + (nsym - p->ghashtab[1]);
do {
nsym++;
if (sym_is_matched(sym, addr_offset_so)) {
return sym;
}
sym++;
}
while (!(*hashval++ & 1));
}
return NULL;
}
int dladdr(const void *addr_arg, Dl_info *info) int dladdr(const void *addr_arg, Dl_info *info)
{ {
size_t addr = (size_t)addr_arg; size_t addr = (size_t)addr_arg;
struct dso *p; struct dso *p;
Sym *sym, *bestsym; Sym *match_sym = NULL;
uint32_t nsym;
char *strings; char *strings;
size_t best = 0;
size_t besterr = -1;
pthread_rwlock_rdlock(&lock); pthread_rwlock_rdlock(&lock);
p = addr2dso(addr); p = addr2dso(addr);
...@@ -3762,54 +3837,26 @@ int dladdr(const void *addr_arg, Dl_info *info) ...@@ -3762,54 +3837,26 @@ int dladdr(const void *addr_arg, Dl_info *info)
if (!p) return 0; if (!p) return 0;
sym = p->syms;
strings = p->strings; strings = p->strings;
nsym = count_syms(p); size_t addr_offset_so = addr - (size_t)p->base;
if (DL_FDPIC) { info->dli_fname = p->name;
size_t idx = (addr-(size_t)p->funcdescs) info->dli_fbase = p->map;
/ sizeof(*p->funcdescs);
if (idx < nsym && (sym[idx].st_info&0xf) == STT_FUNC) {
best = (size_t)(p->funcdescs + idx);
bestsym = sym + idx;
besterr = 0;
}
}
if (!best) for (; nsym; nsym--, sym++) { if (p->ghashtab) {
if (sym->st_value match_sym = find_addr_by_gnu(addr_offset_so, p);
&& (1<<(sym->st_info&0xf) & OK_TYPES)
&& (1<<(sym->st_info>>4) & OK_BINDS)) {
size_t symaddr = (size_t)laddr(p, sym->st_value);
if (symaddr > addr || symaddr <= best)
continue;
best = symaddr;
bestsym = sym;
besterr = addr - symaddr;
if (addr == symaddr)
break;
}
}
if (best && besterr > bestsym->st_size-1) { } else {
best = 0; match_sym = find_addr_by_elf(addr_offset_so, p);
bestsym = 0;
} }
info->dli_fname = p->name; if (!match_sym) {
info->dli_fbase = p->map;
if (!best) {
info->dli_sname = 0; info->dli_sname = 0;
info->dli_saddr = 0; info->dli_saddr = 0;
return 1; return 1;
} }
info->dli_sname = strings + match_sym->st_name;
if (DL_FDPIC && (bestsym->st_info&0xf) == STT_FUNC) info->dli_saddr = (void *)laddr(p, match_sym->st_value);
best = (size_t)(p->funcdescs + (bestsym - p->syms));
info->dli_sname = strings + bestsym->st_name;
info->dli_saddr = (void *)best;
return 1; return 1;
} }
...@@ -4054,7 +4101,7 @@ void* dlopen_ext(const char *file, int mode, const dl_extinfo *extinfo) ...@@ -4054,7 +4101,7 @@ void* dlopen_ext(const char *file, int mode, const dl_extinfo *extinfo)
mode, mode,
caller_addr, caller_addr,
extinfo ? extinfo->flag : 0); extinfo ? extinfo->flag : 0);
return dlopen_impl(file, mode, NULL, caller_addr, extinfo); return dlopen_impl(file, mode, NULL, caller_addr, extinfo);
} }
#ifdef LOAD_ORDER_RANDOMIZATION #ifdef LOAD_ORDER_RANDOMIZATION
......
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
char *getenv(const char *name)
{
if (name == NULL || __environ == NULL)
return 0;
size_t i, l = 0;
const char *np;
char **p, *ep;
for (; *(name + l) && *(name + l) != '='; ++l);
for (p = __environ; (ep = *p) != NULL; ++p) {
for (np = name, i = l; i && *ep; i--) {
if (*ep++ != *np++) {
break;
}
}
if (i == 0 && *ep++ == '=') {
return (ep);
}
}
return 0;
}
...@@ -74,9 +74,6 @@ struct pthread { ...@@ -74,9 +74,6 @@ struct pthread {
volatile int killlock[1]; volatile int killlock[1];
char *dlerror_buf; char *dlerror_buf;
void *stdio_locks; void *stdio_locks;
#ifdef RESERVE_SIGNAL_STACK
void *signal_stack;
#endif
/* Part 3 -- the positions of these fields relative to /* Part 3 -- the positions of these fields relative to
* the end of the structure is external and internal ABI. */ * the end of the structure is external and internal ABI. */
......
#ifndef _STDIO_IMPL_H
#define _STDIO_IMPL_H
#include <stdio.h>
#include "syscall.h"
#define UNGET 8
#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0)
#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0)
#define F_PERM 1
#define F_NORD 4
#define F_NOWR 8
#define F_EOF 16
#define F_ERR 32
#define F_SVB 64
#define F_APP 128
struct _IO_FILE {
unsigned flags;
unsigned char *rpos, *rend;
int (*close)(FILE *);
unsigned char *wend, *wpos;
unsigned char *mustbezero_1;
unsigned char *wbase;
size_t (*read)(FILE *, unsigned char *, size_t);
size_t (*readx)(FILE *, unsigned char *, size_t);
size_t (*write)(FILE *, const unsigned char *, size_t);
off_t (*seek)(FILE *, off_t, int);
unsigned char *buf;
size_t buf_size;
FILE *prev, *next;
int fd;
int pipe_pid;
long lockcount;
int mode;
volatile int lock;
int lbf;
void *cookie;
off_t off;
char *getln_buf;
void *mustbezero_2;
unsigned char *shend;
off_t shlim, shcnt;
FILE *prev_locked, *next_locked;
struct __locale_struct *locale;
};
extern hidden FILE *volatile __stdin_used;
extern hidden FILE *volatile __stdout_used;
extern hidden FILE *volatile __stderr_used;
hidden int __lockfile(FILE *);
hidden void __unlockfile(FILE *);
hidden size_t __stdio_read(FILE *, unsigned char *, size_t);
hidden size_t __stdio_readx(FILE *, unsigned char *, size_t);
hidden size_t __stdio_write(FILE *, const unsigned char *, size_t);
hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
hidden off_t __stdio_seek(FILE *, off_t, int);
hidden int __stdio_close(FILE *);
hidden int __fill_buffer(FILE *f);
hidden int __toread(FILE *);
hidden int __towrite(FILE *);
hidden void __stdio_exit(void);
hidden void __stdio_exit_needed(void);
#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303)
__attribute__((visibility("protected")))
#endif
int __overflow(FILE *, int), __uflow(FILE *);
hidden int __fseeko(FILE *, off_t, int);
hidden int __fseeko_unlocked(FILE *, off_t, int);
hidden off_t __ftello(FILE *);
hidden off_t __ftello_unlocked(FILE *);
hidden size_t __fwritex(const unsigned char *, size_t, FILE *);
hidden int __putc_unlocked(int, FILE *);
hidden FILE *__fdopen(int, const char *);
hidden int __fmodeflags(const char *);
hidden FILE *__ofl_add(FILE *f);
hidden FILE **__ofl_lock(void);
hidden void __ofl_unlock(void);
struct __pthread;
hidden void __register_locked_file(FILE *, struct __pthread *);
hidden void __unlist_locked_file(FILE *);
hidden void __do_orphaned_stdio_locks(void);
#define MAYBE_WAITERS 0x40000000
hidden void __getopt_msg(const char *, const char *, const char *, size_t);
#define feof(f) ((f)->flags & F_EOF)
#define ferror(f) ((f)->flags & F_ERR)
#define getc_unlocked(f) \
( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) )
#define putc_unlocked(c, f) \
( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \
? *(f)->wpos++ = (unsigned char)(c) \
: __overflow((f),(unsigned char)(c)) )
/* Caller-allocated FILE * operations */
hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t);
hidden int __fclose_ca(FILE *);
#endif
...@@ -152,7 +152,11 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static ...@@ -152,7 +152,11 @@ static int name_from_dns(struct address buf[static MAXADDRS], char canon[static
{ .af = AF_INET, .rr = RR_AAAA }, { .af = AF_INET, .rr = RR_AAAA },
}; };
#ifdef STANDARD_SYSTEM
for (i=0; i<1; i++) {
#else
for (i=0; i<2; i++) { for (i=0; i<2; i++) {
#endif
if (family != afrr[i].af) { if (family != afrr[i].af) {
qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr, qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr,
0, 0, 0, qbuf[nq], sizeof *qbuf); 0, 0, 0, qbuf[nq], sizeof *qbuf);
......
/*
* Copyright (c) 2023 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 "lookup.h" #include "lookup.h"
#include "stdio_impl.h" #include "stdio_impl.h"
#include <ctype.h> #include <ctype.h>
...@@ -5,8 +20,89 @@ ...@@ -5,8 +20,89 @@
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <netinet/in.h> #include <netinet/in.h>
#define DNS_RESOLV_CONF_PATH "/etc/resolv.conf"
#if OHOS_DNS_PROXY_BY_NETSYS #if OHOS_DNS_PROXY_BY_NETSYS
#include "atomic.h"
#include <dlfcn.h> #include <dlfcn.h>
static void *open_dns_lib(void)
{
static void *dns_lib_handle = NULL;
if (dns_lib_handle != NULL) {
a_barrier();
return dns_lib_handle;
}
void *lib = dlopen(DNS_SO_PATH, RTLD_LAZY);
if (lib == NULL) {
DNS_CONFIG_PRINT("%s: dlopen %s failed: %s",
__func__, DNS_SO_PATH, dlerror());
return NULL;
}
void *old_lib = a_cas_p(&dns_lib_handle, NULL, lib);
if (old_lib == NULL) {
DNS_CONFIG_PRINT("%s: %s loaded", __func__, DNS_SO_PATH);
return lib;
} else {
/* Another thread has already loaded the library,
* dlclose is invoked to make refcount correct */
DNS_CONFIG_PRINT("%s: %s has been loaded by another thread",
__func__, DNS_SO_PATH);
if (dlclose(lib)) {
DNS_CONFIG_PRINT("%s: dlclose %s failed: %s",
__func__, DNS_SO_PATH, dlerror());
}
return old_lib;
}
}
static void *load_from_dns_lib(const char *symbol)
{
void *lib_handle = open_dns_lib();
if (lib_handle == NULL) {
return NULL;
}
void *sym_addr = dlsym(lib_handle, symbol);
if (sym_addr == NULL) {
DNS_CONFIG_PRINT("%s: loading symbol %s with dlsym failed: %s",
__func__, symbol, dlerror());
}
return sym_addr;
}
void resolve_dns_sym(void **holder, const char *symbol)
{
if (*holder != NULL) {
a_barrier();
return;
}
void *ptr = load_from_dns_lib(symbol);
if (ptr == NULL) {
return;
}
void *old_ptr = a_cas_p(holder, NULL, ptr);
if (old_ptr != NULL) {
DNS_CONFIG_PRINT("%s: %s has been found by another thread",
__func__, symbol);
} else {
DNS_CONFIG_PRINT("%s: %s found", __func__, symbol);
}
}
static GetConfig load_config_getter(void)
{
static GetConfig config_getter = NULL;
resolve_dns_sym((void **) &config_getter, OHOS_GET_CONFIG_FUNC_NAME);
return config_getter;
}
#endif #endif
int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz) int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
...@@ -22,22 +118,15 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz) ...@@ -22,22 +118,15 @@ int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz)
if (search) *search = 0; if (search) *search = 0;
#if OHOS_DNS_PROXY_BY_NETSYS #if OHOS_DNS_PROXY_BY_NETSYS
void *handle = dlopen(DNS_SO_PATH, RTLD_LAZY); GetConfig func = load_config_getter();
if (handle == NULL) { if (!func) {
DNS_CONFIG_PRINT("__get_resolv_conf dlopen err %s\n", dlerror()); DNS_CONFIG_PRINT("%s: loading %s failed, use %s as a fallback",
goto etc_resolv_conf; __func__, OHOS_GET_CONFIG_FUNC_NAME, DNS_RESOLV_CONF_PATH);
}
GetConfig func = dlsym(handle, OHOS_GET_CONFIG_FUNC_NAME);
if (func == NULL) {
DNS_CONFIG_PRINT("__get_resolv_conf dlsym err %s\n", dlerror());
dlclose(handle);
goto etc_resolv_conf; goto etc_resolv_conf;
} }
struct resolv_config config = {0}; struct resolv_config config = {0};
int ret = func(0, &config); int ret = func(0, &config);
dlclose(handle);
if (ret < 0) { if (ret < 0) {
DNS_CONFIG_PRINT("__get_resolv_conf OHOS_GET_CONFIG_FUNC_NAME err %d\n", ret); DNS_CONFIG_PRINT("__get_resolv_conf OHOS_GET_CONFIG_FUNC_NAME err %d\n", ret);
return EAI_NONAME; return EAI_NONAME;
...@@ -74,7 +163,7 @@ netsys_conf: ...@@ -74,7 +163,7 @@ netsys_conf:
etc_resolv_conf: etc_resolv_conf:
#endif #endif
f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf); f = __fopen_rb_ca(DNS_RESOLV_CONF_PATH, &_f, _buf, sizeof _buf);
if (!f) switch (errno) { if (!f) switch (errno) {
case ENOENT: case ENOENT:
case ENOTDIR: case ENOTDIR:
......
...@@ -45,7 +45,7 @@ extern int __libc_sigaction(int sig, const struct sigaction *restrict sa, ...@@ -45,7 +45,7 @@ extern int __libc_sigaction(int sig, const struct sigaction *restrict sa,
#define SIGCHAIN_PRINT_ERROR(...) #define SIGCHAIN_PRINT_ERROR(...)
#define SIGCHAIN_PRINT_INFO(...) #define SIGCHAIN_PRINT_INFO(...)
#define SIGCHAIN_PRINT_DEBUG(...) #define SIGCHAIN_PRINT_DEBUG(...)
#define SIGCHAIN_LOG_FATAL(...) #define SIGCHAIN_LOG_FATAL(...)
#endif #endif
#define SIGCHAIN_PRINT_FATAL(...) do { \ #define SIGCHAIN_PRINT_FATAL(...) do { \
...@@ -167,7 +167,7 @@ static void signal_chain_handler(int signo, siginfo_t* siginfo, void* ucontext_r ...@@ -167,7 +167,7 @@ static void signal_chain_handler(int signo, siginfo_t* siginfo, void* ucontext_r
sigchain_sigmask(SIG_SETMASK, &sig_chains[signo - 1].sca_special_actions[i].sca_mask, sigchain_sigmask(SIG_SETMASK, &sig_chains[signo - 1].sca_special_actions[i].sca_mask,
&previous_mask); &previous_mask);
bool previous_value = get_handling_signal(); bool previous_value = get_handling_signal();
if (!noreturn) { if (!noreturn) {
set_handling_signal(true); set_handling_signal(true);
} }
...@@ -201,8 +201,13 @@ static void signal_chain_handler(int signo, siginfo_t* siginfo, void* ucontext_r ...@@ -201,8 +201,13 @@ static void signal_chain_handler(int signo, siginfo_t* siginfo, void* ucontext_r
if (sig_chains[signo - 1].sig_action.sa_handler == SIG_IGN) { if (sig_chains[signo - 1].sig_action.sa_handler == SIG_IGN) {
return; return;
} else if (sig_chains[signo - 1].sig_action.sa_handler == SIG_DFL) { } else if (sig_chains[signo - 1].sig_action.sa_handler == SIG_DFL) {
SIGCHAIN_PRINT_FATAL("%{public}s exiting due to SIG_DFL handler for signal: %{public}d", SIGCHAIN_PRINT_DEBUG("%{public}s SIG_DFL handler for signal: %{public}d", __func__, signo);
__func__, signo); remove_all_special_handler(signo);
if (__syscall(SYS_rt_tgsigqueueinfo, __syscall(SYS_getpid), __syscall(SYS_gettid), signo, siginfo) != 0) {
SIGCHAIN_PRINT_ERROR("Failed to rethrow sig(%{public}d), errno(%{public}d).", signo, errno);
} else {
SIGCHAIN_PRINT_INFO("pid(%{public}d) rethrow sig(%{public}d).", __syscall(SYS_getpid), signo);
}
} else { } else {
sig_chains[signo - 1].sig_action.sa_handler(signo); sig_chains[signo - 1].sig_action.sa_handler(signo);
} }
......
...@@ -93,6 +93,7 @@ FILE *__fdopen(int fd, const char *mode) ...@@ -93,6 +93,7 @@ FILE *__fdopen(int fd, const char *mode)
f->write = __stdio_write; f->write = __stdio_write;
f->seek = __stdio_seek; f->seek = __stdio_seek;
f->close = __stdio_close; f->close = __stdio_close;
f->readx = __stdio_readx;
if (!libc.threaded) { if (!libc.threaded) {
f->lock = -1; f->lock = -1;
......
#include "stdio_impl.h"
#include <sys/uio.h>
size_t __stdio_readx(FILE *f, unsigned char *buf, size_t len)
{
return syscall(SYS_read, f->fd, buf, len);
}
size_t __stdio_read(FILE *f, unsigned char *buf, size_t len)
{
struct iovec iov_buf[2] = {
{ .iov_base = buf, .iov_len = len - !!f->buf_size },
{ .iov_base = f->buf, .iov_len = f->buf_size }
};
ssize_t cnt;
cnt = iov_buf[0].iov_len ? syscall(SYS_readv, f->fd, iov_buf, 2)
: syscall(SYS_read, f->fd, iov_buf[1].iov_base, iov_buf[1].iov_len);
if (cnt <= 0) {
f->flags |= cnt ? F_ERR : F_EOF;
return 0;
}
if (cnt <= iov_buf[0].iov_len) {
return cnt;
}
cnt -= iov_buf[0].iov_len;
f->rpos = f->buf;
f->rend = f->buf + cnt;
if (f->buf_size) buf[len-1] = *f->rpos++;
return len;
}
#include "stdio_impl.h"
#include <string.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
int __fill_buffer(FILE *f)
{
int r = __toread(f);
if (r != 0) {
return r;
}
int k = f->readx(f, f->buf, f->buf_size);
if (k <= 0) {
f->flags |= (k == 0) ? F_EOF : F_ERR;
f->rpos = f->rend;
return k;
}
f->rpos = f->buf;
f->rend = f->rpos + k;
return 0;
}
size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f)
{
unsigned char *dest = destv;
size_t len = size * nmemb, l = len, k;
if (!size) {
nmemb = 0;
}
FLOCK(f);
f->mode |= f->mode-1;
while (l > 0) {
if (f->rpos != f->rend) {
/* First exhaust the buffer. */
k = MIN(f->rend - f->rpos, l);
memcpy(dest, f->rpos, k);
f->rpos += k;
dest += k;
l -= k;
}
/* done */
if (l == 0) {
goto exit;
}
/* if user buffer is longer than file buffer, read directly */
if (l > f->buf_size) {
break;
}
if (__fill_buffer(f)) {
goto exit;
}
}
/* Read the remainder directly */
for (; l; l-=k, dest+=k) {
k = f->readx(f, dest, l);
if (k <= 0) {
f->flags |= (k == 0 ? F_EOF : F_ERR);
break;
}
}
exit:
FUNLOCK(f);
return (len - l) / size;
}
weak_alias(fread, fread_unlocked);
...@@ -61,7 +61,6 @@ void __pthread_reserve_signal_stack() ...@@ -61,7 +61,6 @@ void __pthread_reserve_signal_stack()
sigaltstack(&signal_stack, NULL); sigaltstack(&signal_stack, NULL);
pthread_t self = __pthread_self(); pthread_t self = __pthread_self();
self->signal_stack = stack;
char name[ANON_STACK_NAME_SIZE]; char name[ANON_STACK_NAME_SIZE];
snprintf(name, ANON_STACK_NAME_SIZE, "signal_stack:%d", __pthread_self()->tid); snprintf(name, ANON_STACK_NAME_SIZE, "signal_stack:%d", __pthread_self()->tid);
prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, signal_stack.ss_sp, signal_stack.ss_size, name); prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, signal_stack.ss_sp, signal_stack.ss_size, name);
...@@ -70,17 +69,13 @@ void __pthread_reserve_signal_stack() ...@@ -70,17 +69,13 @@ void __pthread_reserve_signal_stack()
void __pthread_release_signal_stack() void __pthread_release_signal_stack()
{ {
pthread_t self = __pthread_self(); stack_t signal_stack, old_stack;
if (self->signal_stack == NULL) {
return;
}
stack_t signal_stack;
memset(&signal_stack, 0, sizeof(signal_stack)); memset(&signal_stack, 0, sizeof(signal_stack));
signal_stack.ss_flags = SS_DISABLE; signal_stack.ss_flags = SS_DISABLE;
sigaltstack(&signal_stack, NULL); sigaltstack(&signal_stack, &old_stack);
munmap(self->signal_stack, RESERVE_SIGNAL_STACK_SIZE); if (old_stack.ss_flags != SS_DISABLE) {
self->signal_stack = NULL; munmap(old_stack.ss_sp, old_stack.ss_size);
}
} }
weak_alias(__pthread_reserve_signal_stack, pthread_reserve_signal_stack); weak_alias(__pthread_reserve_signal_stack, pthread_reserve_signal_stack);
......
...@@ -24,22 +24,58 @@ ...@@ -24,22 +24,58 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include "musl_log.h" #include "musl_log.h"
#ifdef OHOS_ENABLE_PARAMETER
#include "sys_param.h"
#endif
#ifndef MUSL_TEMP_FAILURE_RETRY #ifndef MUSL_TEMP_FAILURE_RETRY
#define MUSL_TEMP_FAILURE_RETRY(exp) \ #define MUSL_TEMP_FAILURE_RETRY(exp) \
({ \ ({ \
long int _rc; \ long int _rc; \
do { \ do { \
_rc = (long int)(exp); \ _rc = (long int)(exp); \
} while ((_rc == -1) && (errno == EINTR)); \ } while ((_rc == -1) && (errno == EINTR)); \
_rc; \ _rc; \
}) })
#endif #endif
#define LIKELY(exp) (__builtin_expect(!!(exp), 1))
#ifdef OHOS_ENABLE_PARAMETER
#define TRACE_PROPERTY_FLAG "debug.hitrace.tags.enableflags"
static uint64_t g_trace_switch_status = 0;
uint64_t get_uint64_sysparam(CachedHandle cachedhandle)
{
char *param_value = CachedParameterGet(cachedhandle);
if (param_value != NULL) {
return strtoull(param_value, NULL, 0);
}
return 0;
}
#endif
void trace_marker_reset(void)
{
#ifdef OHOS_ENABLE_PARAMETER
static CachedHandle trace_switch_handle = NULL;
if (trace_switch_handle == NULL) {
trace_switch_handle = CachedParameterCreate(TRACE_PROPERTY_FLAG, "0");
}
g_trace_switch_status = get_uint64_sysparam(trace_switch_handle);
#else
return;
#endif
}
// Check whether the user space trace function is enabled // Check whether the user space trace function is enabled
static inline bool is_enable_trace(void) static inline bool is_enable_trace(uint64_t label)
{ {
return true; #ifdef OHOS_ENABLE_PARAMETER
return (((g_trace_switch_status & label) != 0) || ((g_trace_switch_status & HITRACE_TAG_ALWAYS) != 0));
#else
return false;
#endif
} }
// Get the fd of trace_marker // Get the fd of trace_marker
...@@ -54,9 +90,9 @@ static inline int get_trace_marker_fd(void) ...@@ -54,9 +90,9 @@ static inline int get_trace_marker_fd(void)
/* Write the function call information to the trace_marker node in kernel space, /* Write the function call information to the trace_marker node in kernel space,
used on the same thread as trace_marker_end(),with the symbol "B". */ used on the same thread as trace_marker_end(),with the symbol "B". */
void trace_marker_begin(const char *message, const char *value) void trace_marker_begin(uint64_t label, const char *message, const char *value)
{ {
if (!is_enable_trace() || message == NULL) { if (LIKELY((!is_enable_trace(label) || message == NULL))) {
return; return;
} }
...@@ -68,7 +104,7 @@ void trace_marker_begin(const char *message, const char *value) ...@@ -68,7 +104,7 @@ void trace_marker_begin(const char *message, const char *value)
char buf[TRACE_MARKER_MESSAGE_LEN] = {0}; char buf[TRACE_MARKER_MESSAGE_LEN] = {0};
int len = 0; int len = 0;
if (value == NULL) { if (value == NULL) {
len = snprintf(buf, TRACE_MARKER_MESSAGE_LEN, "B|%d %s", getpid(), message); len = snprintf(buf, TRACE_MARKER_MESSAGE_LEN, "B|%d|%s", getpid(), message);
} else { } else {
len = snprintf(buf, TRACE_MARKER_MESSAGE_LEN, "B|%d|%s %s", getpid(), message, value); len = snprintf(buf, TRACE_MARKER_MESSAGE_LEN, "B|%d|%s %s", getpid(), message, value);
} }
...@@ -87,9 +123,9 @@ void trace_marker_begin(const char *message, const char *value) ...@@ -87,9 +123,9 @@ void trace_marker_begin(const char *message, const char *value)
/* Write the terminator to the trace_marker node of the kernel space, /* Write the terminator to the trace_marker node of the kernel space,
used on the same thread as trace_marker_begin(),with the symbol "E". */ used on the same thread as trace_marker_begin(),with the symbol "E". */
void trace_marker_end(void) void trace_marker_end(uint64_t label)
{ {
if (!is_enable_trace()) { if (LIKELY(!is_enable_trace(label))) {
return; return;
} }
...@@ -115,9 +151,9 @@ void trace_marker_end(void) ...@@ -115,9 +151,9 @@ void trace_marker_end(void)
/* Write the function call information to the trace_marker node in kernel space, /* Write the function call information to the trace_marker node in kernel space,
used in a different thread than trace_marker_async_end(),with the symbol "S". */ used in a different thread than trace_marker_async_end(),with the symbol "S". */
void trace_marker_async_begin(const char *message, const char *value, int taskId) void trace_marker_async_begin(uint64_t label, const char *message, const char *value, int taskId)
{ {
if (!is_enable_trace() || message == NULL) { if (LIKELY((!is_enable_trace(label) || message == NULL))) {
return; return;
} }
...@@ -148,9 +184,9 @@ void trace_marker_async_begin(const char *message, const char *value, int taskId ...@@ -148,9 +184,9 @@ void trace_marker_async_begin(const char *message, const char *value, int taskId
/* Write the terminator to the trace_marker node in kernel space, /* Write the terminator to the trace_marker node in kernel space,
used in a different thread than trace_marker_async_begin(),with the symbol "F". */ used in a different thread than trace_marker_async_begin(),with the symbol "F". */
void trace_marker_async_end(const char *message, const char *value, int taskId) void trace_marker_async_end(uint64_t label, const char *message, const char *value, int taskId)
{ {
if (!is_enable_trace() || message == NULL) { if (LIKELY((!is_enable_trace(label) || message == NULL))) {
return; return;
} }
...@@ -180,9 +216,9 @@ void trace_marker_async_end(const char *message, const char *value, int taskId) ...@@ -180,9 +216,9 @@ void trace_marker_async_end(const char *message, const char *value, int taskId)
} }
// A numeric variable used to mark a pre trace, with the symbol "C". // A numeric variable used to mark a pre trace, with the symbol "C".
void trace_marker_count(const char *message, int value) void trace_marker_count(uint64_t label, const char *message, int value)
{ {
if (!is_enable_trace() || message == NULL) { if (LIKELY((!is_enable_trace(label) || message == NULL))) {
return; return;
} }
......
...@@ -70,18 +70,6 @@ _Noreturn void __pthread_exit(void *result) ...@@ -70,18 +70,6 @@ _Noreturn void __pthread_exit(void *result)
__block_app_sigs(&set); __block_app_sigs(&set);
/* This atomic potentially competes with a concurrent pthread_detach
* call; the loser is responsible for freeing thread resources. */
int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);
if (state==DT_DETACHED && self->map_base) {
/* Since __unmapself bypasses the normal munmap code path,
* explicitly wait for vmlock holders first. This must be
* done before any locks are taken, to avoid lock ordering
* issues that could lead to deadlock. */
__vm_wait();
}
/* Access to target the exiting thread with syscalls that use /* Access to target the exiting thread with syscalls that use
* its kernel tid is controlled by killlock. For detached threads, * its kernel tid is controlled by killlock. For detached threads,
* any use past this point would have undefined behavior, but for * any use past this point would have undefined behavior, but for
...@@ -99,7 +87,6 @@ _Noreturn void __pthread_exit(void *result) ...@@ -99,7 +87,6 @@ _Noreturn void __pthread_exit(void *result)
if (self->next == self) { if (self->next == self) {
__tl_unlock(); __tl_unlock();
UNLOCK(self->killlock); UNLOCK(self->killlock);
self->detach_state = state;
__restore_sigs(&set); __restore_sigs(&set);
exit(0); exit(0);
} }
...@@ -138,6 +125,10 @@ _Noreturn void __pthread_exit(void *result) ...@@ -138,6 +125,10 @@ _Noreturn void __pthread_exit(void *result)
self->prev->next = self->next; self->prev->next = self->next;
self->prev = self->next = self; self->prev = self->next = self;
/* This atomic potentially competes with a concurrent pthread_detach
* call; the loser is responsible for freeing thread resources. */
int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING);
#if 0 #if 0
if (state==DT_DETACHED && self->map_base) { if (state==DT_DETACHED && self->map_base) {
/* Robust list will no longer be valid, and was already /* Robust list will no longer be valid, and was already
......
...@@ -7,6 +7,13 @@ touch /data/tests/libc-test/REPORT ...@@ -7,6 +7,13 @@ touch /data/tests/libc-test/REPORT
touch /data/tests/libc-test/FileList.txt touch /data/tests/libc-test/FileList.txt
touch /data/tests/libc-test/SkipList.txt touch /data/tests/libc-test/SkipList.txt
echo 'root:This.is.a.test:18997:0:99999:7:::'>/etc/shadow echo 'root:This.is.a.test:18997:0:99999:7:::'>/etc/shadow
param set debug.hitrace.tags.enableflags 1
ARCH=arm
ABILIST=$(param get const.product.cpu.abilist)
if [ $ABILIST == "arm64-v8a" ]; then
ARCH=aarch64
fi
function FileSuffix() { function FileSuffix() {
local filename="$1" local filename="$1"
...@@ -29,8 +36,15 @@ ShieldedList=("trace_stresstest" "syslog" "vsyslog" "runtest" ...@@ -29,8 +36,15 @@ ShieldedList=("trace_stresstest" "syslog" "vsyslog" "runtest"
#Some math test cases need to skip. #Some math test cases need to skip.
"acoshl" "asinhl" "erfcl" "fenv" "fma" "fmaf" "fmal" "lgammal" "nearbyint" "nearbyintf" "acoshl" "asinhl" "erfcl" "fenv" "fma" "fmaf" "fmal" "lgammal" "nearbyint" "nearbyintf"
"nearbyintl" "rint" "rintf" "rintl" "sqrt" "sqrtf" "sqrtl" "tgammal" "nearbyintl" "rint" "rintf" "rintl" "sqrt" "sqrtf" "sqrtl" "tgammal"
#TODO-arm32
"dlopen_ns" "malloc-brk-fail" "pthread_cancel" "res_send"
) )
#TODO-aarch64
if [ $ARCH == "aarch64" ]; then
ShieldedList+=("faccessat" "signal" "unittest_hilog_vsnprint" "yn")
fi
for skiped in ${ShieldedList[*]};do for skiped in ${ShieldedList[*]};do
echo $skiped >> /data/tests/libc-test/SkipList.txt echo $skiped >> /data/tests/libc-test/SkipList.txt
done done
...@@ -62,4 +76,4 @@ do ...@@ -62,4 +76,4 @@ do
./runtest -w '' -t 30 $file >> /data/tests/libc-test/REPORT ./runtest -w '' -t 30 $file >> /data/tests/libc-test/REPORT
fi fi
fi fi
done done
\ No newline at end of file
...@@ -14,6 +14,7 @@ set REMOTE=/data/tests/libc-test ...@@ -14,6 +14,7 @@ set REMOTE=/data/tests/libc-test
set REMOTESYSTEM=/system/lib set REMOTESYSTEM=/system/lib
@REM runtest脚本所在目录 @REM runtest脚本所在目录
set SHDIR=%LOCAL%\third_party\musl\scripts set SHDIR=%LOCAL%\third_party\musl\scripts
set ARCH=arm
@REM 检查设备是否连接 @REM 检查设备是否连接
echo checking HDC device echo checking HDC device
...@@ -33,6 +34,11 @@ if exist %TESTDIR% ( ...@@ -33,6 +34,11 @@ if exist %TESTDIR% (
@REM 在单板创建目录, 需要预先创建好才能传输到相应位置。 @REM 在单板创建目录, 需要预先创建好才能传输到相应位置。
:hdcStart :hdcStart
for /F "usebackq delims==" %%r in (`hdc shell param get const.product.cpu.abilist`) DO (
echo %%r | findstr "arm64-v8a" && set ARCH=aarch64
)
echo detect arch = %ARCH%
echo. echo.
echo now mkdir... echo now mkdir...
hdc shell rm -rf /data/tests/libc-test hdc shell rm -rf /data/tests/libc-test
...@@ -56,9 +62,9 @@ hdc shell chmod +x %REMOTE%/src/* ...@@ -56,9 +62,9 @@ hdc shell chmod +x %REMOTE%/src/*
hdc shell mount -o rw,remount / hdc shell mount -o rw,remount /
hdc shell chmod 777 /etc hdc shell chmod 777 /etc
hdc shell cp /etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-arm.ini.bak hdc shell cp /etc/ld-musl-namespace-%ARCH%.ini /etc/ld-musl-namespace-%ARCH%.ini.bak
hdc file send %LOCAL%\third_party\musl\porting\linux\user\config\ld-musl-namespace-arm-test.ini ^ hdc file send %LOCAL%\third_party\musl\porting\linux\user\config\ld-musl-namespace-%ARCH%-test.ini ^
/etc/ld-musl-namespace-arm.ini /etc/ld-musl-namespace-%ARCH%.ini
hdc shell mkdir %REMOTE%/src/A hdc shell mkdir %REMOTE%/src/A
hdc shell mkdir %REMOTE%/src/B hdc shell mkdir %REMOTE%/src/B
hdc shell mkdir %REMOTE%/src/C hdc shell mkdir %REMOTE%/src/C
...@@ -97,7 +103,7 @@ if exist Summary.txt ( ...@@ -97,7 +103,7 @@ if exist Summary.txt (
hdc file recv %REMOTE%/FileList.txt %~dp0FileList.txt hdc file recv %REMOTE%/FileList.txt %~dp0FileList.txt
hdc file recv %REMOTE%/SkipList.txt %~dp0SkipList.txt hdc file recv %REMOTE%/SkipList.txt %~dp0SkipList.txt
for /f "delims=:" %%a in ('dir /b "%TESTDIR%" ^| findstr /n .*') do set all=%%a for /f "delims=:" %%a in ('dir /b /a:-d "%TESTDIR%" ^| findstr /n .*') do set all=%%a
for /f %%b in (' find /c /v "" ^<"FileList.txt" ') do set /a run=%%b for /f %%b in (' find /c /v "" ^<"FileList.txt" ') do set /a run=%%b
for /f %%c in (' find /c "FAIL" ^<"REPORT" ') do set fail=%%c for /f %%c in (' find /c "FAIL" ^<"REPORT" ') do set fail=%%c
...@@ -106,13 +112,13 @@ echo =================================== ...@@ -106,13 +112,13 @@ echo ===================================
set /a pass=%run%-%fail% set /a pass=%run%-%fail%
set /a skip=%all%-%run% set /a skip=%all%-%run%
echo SUMMARY echo SUMMARY-%ARCH%
echo All: %all% ^| Run: %run% ^| Skip: %skip% echo All: %all% ^| Run: %run% ^| Skip: %skip%
echo Pass: [%pass%/%run%] echo Pass: [%pass%/%run%]
echo Fail: [%fail%/%run%] echo Fail: [%fail%/%run%]
( (
echo SUMMARY echo SUMMARY-%ARCH%
echo All: %all% ^| Run: %run% ^| Skip: %skip% echo All: %all% ^| Run: %run% ^| Skip: %skip%
echo Pass: [%pass%/%run%] echo Pass: [%pass%/%run%]
echo Fail: [%fail%/%run%] echo Fail: [%fail%/%run%]
...@@ -140,4 +146,4 @@ echo Device not found, please check your device. ...@@ -140,4 +146,4 @@ echo Device not found, please check your device.
:end :end
echo. echo.
pause pause
exit exit
\ No newline at end of file
...@@ -113,6 +113,10 @@ typedef int32_t (*GetCache)(uint16_t netId, struct param_wrapper param, ...@@ -113,6 +113,10 @@ typedef int32_t (*GetCache)(uint16_t netId, struct param_wrapper param,
typedef int32_t (*SetCache)(uint16_t netId, struct param_wrapper param, struct addrinfo *res); typedef int32_t (*SetCache)(uint16_t netId, struct param_wrapper param, struct addrinfo *res);
/* If the memory holder points to stores NULL value, try to load symbol from the
* dns lib into holder; otherwise, it does nothing. */
hidden void resolve_dns_sym(void **holder, const char *symbol);
void void
dns_set_addr_info_to_netsys_cache(const char *__restrict host, const char *__restrict serv, dns_set_addr_info_to_netsys_cache(const char *__restrict host, const char *__restrict serv,
const struct addrinfo *__restrict const struct addrinfo *__restrict
......
/* /*
* Copyright (c) 2022 Huawei Device Co., Ltd. * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
...@@ -23,25 +23,33 @@ ...@@ -23,25 +23,33 @@
#if OHOS_DNS_PROXY_BY_NETSYS #if OHOS_DNS_PROXY_BY_NETSYS
#include "atomic.h"
static GetCache load_cache_getter(void)
{
static GetCache cache_getter = NULL;
resolve_dns_sym((void **) &cache_getter, OHOS_GET_CACHE_FUNC_NAME);
return cache_getter;
}
static SetCache load_cache_setter(void)
{
static SetCache cache_setter = NULL;
resolve_dns_sym((void **) &cache_setter, OHOS_SET_CACHE_FUNC_NAME);
return cache_setter;
}
void void
dns_set_addr_info_to_netsys_cache(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict dns_set_addr_info_to_netsys_cache(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict
hint, struct addrinfo *res) { hint, struct addrinfo *res) {
void *handle = dlopen(DNS_SO_PATH, RTLD_LAZY); SetCache func = load_cache_setter();
if (handle == NULL) { if (!func) {
DNS_CONFIG_PRINT("dns_set_addr_info_to_netsys_cache dlopen err %s\n", dlerror()); DNS_CONFIG_PRINT("%s: loading %s failed", __func__, OHOS_SET_CACHE_FUNC_NAME);
return;
}
SetCache func = dlsym(handle, OHOS_SET_CACHE_FUNC_NAME);
if (func == NULL) {
DNS_CONFIG_PRINT("dns_set_addr_info_to_netsys_cache dlsym err %s\n", dlerror());
dlclose(handle);
return; return;
} }
struct param_wrapper param = {(char *) host, (char *) serv, (struct addrinfo *) hint}; struct param_wrapper param = {(char *) host, (char *) serv, (struct addrinfo *) hint};
int ret = func(0, param, res); int ret = func(0, param, res);
dlclose(handle);
if (ret < 0) { if (ret < 0) {
DNS_CONFIG_PRINT("dns_set_addr_info_to_netsys_cache OHOS_SET_CACHE_FUNC_NAME err %d\n", ret); DNS_CONFIG_PRINT("dns_set_addr_info_to_netsys_cache OHOS_SET_CACHE_FUNC_NAME err %d\n", ret);
return; return;
...@@ -52,16 +60,9 @@ hint, struct addrinfo *res) { ...@@ -52,16 +60,9 @@ hint, struct addrinfo *res) {
int dns_get_addr_info_from_netsys_cache(const char *restrict host, const char *restrict serv, int dns_get_addr_info_from_netsys_cache(const char *restrict host, const char *restrict serv,
const struct addrinfo *restrict hint, struct addrinfo **restrict res) { const struct addrinfo *restrict hint, struct addrinfo **restrict res) {
void *handle = dlopen(DNS_SO_PATH, RTLD_LAZY); GetCache func = load_cache_getter();
if (handle == NULL) { if (!func) {
DNS_CONFIG_PRINT("dns_get_addr_info_from_netsys_cache dlopen err %s\n", dlerror()); DNS_CONFIG_PRINT("%s: loading %s failed", __func__, OHOS_GET_CACHE_FUNC_NAME);
return -1;
}
GetCache func = dlsym(handle, OHOS_GET_CACHE_FUNC_NAME);
if (func == NULL) {
DNS_CONFIG_PRINT("dns_get_addr_info_from_netsys_cache dlsym err %s\n", dlerror());
dlclose(handle);
return -1; return -1;
} }
...@@ -69,7 +70,6 @@ int dns_get_addr_info_from_netsys_cache(const char *restrict host, const char *r ...@@ -69,7 +70,6 @@ int dns_get_addr_info_from_netsys_cache(const char *restrict host, const char *r
uint32_t num = 0; uint32_t num = 0;
struct param_wrapper param = {(char *) host, (char *) serv, (struct addrinfo *) hint}; struct param_wrapper param = {(char *) host, (char *) serv, (struct addrinfo *) hint};
int ret = func(0, param, addr_info, &num); int ret = func(0, param, addr_info, &num);
dlclose(handle);
if (ret < 0) { if (ret < 0) {
DNS_CONFIG_PRINT("dns_get_addr_info_from_netsys_cache OHOS_GET_CACHE_FUNC_NAME err %d\n", ret); DNS_CONFIG_PRINT("dns_get_addr_info_from_netsys_cache OHOS_GET_CACHE_FUNC_NAME err %d\n", ret);
return -1; return -1;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册