Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party Musl
提交
82d45776
T
Third Party Musl
项目概览
OpenHarmony
/
Third Party Musl
1 年多 前同步成功
通知
37
Star
125
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party Musl
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
82d45776
编写于
1月 16, 2023
作者:
O
openharmony_ci
提交者:
Gitee
1月 16, 2023
浏览文件
操作
浏览文件
下载
差异文件
!786 【跳单release】third_party_musl适配setAppNet
Merge pull request !786 from liyufan/monthly_20221018
上级
cf178463
e7e5c198
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
382 addition
and
2 deletion
+382
-2
musl_src.gni
musl_src.gni
+1
-0
musl_template.gni
musl_template.gni
+11
-2
porting/linux/user/src/hook/musl_socket.h
porting/linux/user/src/hook/musl_socket.h
+21
-0
porting/linux/user/src/hook/musl_socket_dispatch.h
porting/linux/user/src/hook/musl_socket_dispatch.h
+26
-0
porting/linux/user/src/hook/musl_socket_preinit.c
porting/linux/user/src/hook/musl_socket_preinit.c
+137
-0
porting/linux/user/src/hook/musl_socket_preinit_common.c
porting/linux/user/src/hook/musl_socket_preinit_common.c
+16
-0
porting/linux/user/src/hook/musl_socket_preinit_common.h
porting/linux/user/src/hook/musl_socket_preinit_common.h
+83
-0
porting/linux/user/src/hook/socket_common.c
porting/linux/user/src/hook/socket_common.c
+18
-0
porting/linux/user/src/network/socket.c
porting/linux/user/src/network/socket.c
+69
-0
未找到文件。
musl_src.gni
浏览文件 @
82d45776
...
...
@@ -2072,6 +2072,7 @@ musl_src_porting_file = [
"src/malloc/malloc_random.c",
"src/multibyte/wcsnrtombs.c",
"src/network/inet_legacy.c",
"src/network/socket.c",
"src/passwd/getspnam_r.c",
"src/sched/sched_setparam.c",
"src/sched/sched_getparam.c",
...
...
musl_template.gni
浏览文件 @
82d45776
...
...
@@ -125,7 +125,10 @@ template("musl_libs") {
]
if (!is_asan) {
cflags_auto += [ "-DHOOK_ENABLE" ]
cflags_auto += [
"-DHOOK_ENABLE",
"-DOHOS_SOCKET_HOOK_ENABLE",
]
}
cflags_auto += [ "-DRESERVE_SIGNAL_STACK" ]
...
...
@@ -195,7 +198,10 @@ template("musl_libs") {
]
if (!is_asan) {
defines += [ "HOOK_ENABLE" ]
defines += [
"HOOK_ENABLE",
"OHOS_SOCKET_HOOK_ENABLE",
]
}
ldflags = [ "-nostdlib" ]
...
...
@@ -700,6 +706,9 @@ template("musl_libs") {
"./porting/linux/user/src/hook/memory_tag.c",
"./porting/linux/user/src/hook/musl_preinit.c",
"./porting/linux/user/src/hook/musl_preinit_common.c",
"./porting/linux/user/src/hook/musl_socket_preinit.c",
"./porting/linux/user/src/hook/musl_socket_preinit_common.c",
"./porting/linux/user/src/hook/socket_common.c",
]
deps = [
...
...
porting/linux/user/src/hook/musl_socket.h
0 → 100644
浏览文件 @
82d45776
#ifndef _MUSL_SOCKET_H
#define _MUSL_SOCKET_H
#include <sys/socket.h>
#ifdef __cplusplus
extern
"C"
{
#endif
#ifdef OHOS_SOCKET_HOOK_ENABLE
#define MuslSocket(func) __libc_ ## func
int
__libc_socket
(
int
,
int
,
int
);
#else
#define MuslSocket(func) func
#endif
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
porting/linux/user/src/hook/musl_socket_dispatch.h
0 → 100644
浏览文件 @
82d45776
#ifndef _MUSL_SOCKET_DISPATCH_H
#define _MUSL_SOCKET_DISPATCH_H
#include <stdbool.h>
#ifdef __cplusplus
extern
"C"
{
#endif
typedef
int
(
*
SocketSocketType
)(
int
,
int
,
int
);
typedef
bool
(
*
SocketGetHookFlagType
)();
typedef
bool
(
*
SocketSetHookFlagType
)(
bool
);
struct
SocketDispatchType
{
SocketSocketType
socket
;
SocketGetHookFlagType
get_hook_flag
;
SocketSetHookFlagType
set_hook_flag
;
};
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
porting/linux/user/src/hook/musl_socket_preinit.c
0 → 100644
浏览文件 @
82d45776
#ifdef OHOS_SOCKET_HOOK_ENABLE
#include <unistd.h>
#include <signal.h>
#include <stdlib.h>
#include <limits.h>
#include <dlfcn.h>
#include <errno.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include <stdio.h>
#include "musl_socket_preinit_common.h"
static
char
*
__socket_hook_shared_lib
=
"libfwmark_client.z.so"
;
static
char
*
__socket_hook_function_prefix
=
"ohos_socket_hook"
;
void
*
shared_lib_func
[
LAST_FUNC
];
long
long
__ohos_socket_hook_shared_library
;
typedef
bool
(
*
init_func_type
)(
const
struct
SocketDispatchType
*
,
bool
*
,
const
char
*
);
typedef
void
(
*
finalize_func_type
)();
#define MAX_SYMBOL_SIZE 1000
static
bool
init_socket_function
(
void
*
shared_library_handler
,
SocketSocketType
*
func
)
{
char
symbol
[
MAX_SYMBOL_SIZE
];
(
void
)
snprintf
(
symbol
,
sizeof
(
symbol
),
"%s_%s"
,
__socket_hook_function_prefix
,
"socket"
);
*
func
=
(
SocketSocketType
)(
dlsym
(
shared_library_handler
,
symbol
));
if
(
*
func
==
NULL
)
{
return
false
;
}
return
true
;
}
static
void
clear_socket_function
()
{
memset
(
shared_lib_func
,
0
,
sizeof
(
shared_lib_func
));
}
static
void
socket_finalize
()
{
((
finalize_func_type
)
shared_lib_func
[
FINALIZE_FUNC
])();
__current_dispatch
=
NULL
;
__socket_hook_begin_flag
=
false
;
// Don't dlclose because hidumper crash
}
static
bool
finish_install_ohos_socket_hooks
(
const
char
*
options
)
{
init_func_type
init_func
=
(
init_func_type
)(
shared_lib_func
[
INITIALIZE_FUNC
]);
if
(
!
init_func
(
&
__libc_socket_default_dispatch
,
NULL
,
options
))
{
clear_socket_function
();
return
false
;
}
int
ret_value
=
atexit
(
socket_finalize
);
return
true
;
}
static
bool
init_socket_hook_shared_library
(
void
*
shared_library_handle
)
{
static
const
char
*
names
[]
=
{
"initialize"
,
"finalize"
,
"get_hook_flag"
,
"set_hook_flag"
,
};
for
(
int
i
=
0
;
i
<
LAST_FUNC
;
i
++
)
{
char
symbol
[
MAX_SYMBOL_SIZE
];
(
void
)
snprintf
(
symbol
,
sizeof
(
symbol
),
"%s_%s"
,
__socket_hook_function_prefix
,
names
[
i
]);
shared_lib_func
[
i
]
=
dlsym
(
shared_library_handle
,
symbol
);
if
(
shared_lib_func
[
i
]
==
NULL
)
{
clear_socket_function
();
return
false
;
}
}
if
(
!
init_socket_function
(
shared_library_handle
,
&
(
__musl_libc_socket_dispatch
.
socket
)))
{
clear_socket_function
();
return
false
;
}
return
true
;
}
static
void
*
load_socket_hook_shared_library
()
{
void
*
shared_library_handle
=
NULL
;
shared_library_handle
=
dlopen
(
__socket_hook_shared_lib
,
RTLD_NOW
|
RTLD_LOCAL
);
if
(
shared_library_handle
==
NULL
)
{
return
NULL
;
}
if
(
!
init_socket_hook_shared_library
(
shared_library_handle
))
{
dlclose
(
shared_library_handle
);
shared_library_handle
=
NULL
;
}
return
shared_library_handle
;
}
static
void
install_ohos_socket_hook
()
{
void
*
shared_library_handle
=
(
void
*
)
__ohos_socket_hook_shared_library
;
if
(
shared_library_handle
!=
NULL
&&
shared_library_handle
!=
(
void
*
)
-
1
)
{
return
;
}
__current_dispatch
=
NULL
;
shared_library_handle
=
load_socket_hook_shared_library
();
if
(
shared_library_handle
==
NULL
)
{
return
;
}
if
(
finish_install_ohos_socket_hooks
(
NULL
))
{
__ohos_socket_hook_shared_library
=
(
long
long
)
shared_library_handle
;
__current_dispatch
=
(
long
long
)(
&
__musl_libc_socket_dispatch
);
}
else
{
__ohos_socket_hook_shared_library
=
NULL
;
dlclose
((
void
*
)
shared_library_handle
);
}
}
static
void
init_ohos_socket_hook
()
{
install_ohos_socket_hook
();
}
__attribute__
((
constructor
()))
static
void
__musl_socket_initialize
()
{
bool
begin_flag
=
__get_socket_hook_begin_flag
();
if
(
!
begin_flag
)
{
__socket_hook_begin_flag
=
true
;
init_ohos_socket_hook
();
}
}
#endif
\ No newline at end of file
porting/linux/user/src/hook/musl_socket_preinit_common.c
0 → 100644
浏览文件 @
82d45776
#ifdef OHOS_SOCKET_HOOK_ENABLE
#include <sys/socket.h>
#include "musl_socket.h"
#include "musl_socket_preinit_common.h"
struct
SocketDispatchType
__musl_libc_socket_dispatch
;
long
long
__current_dispatch
;
struct
SocketDispatchType
__libc_socket_default_dispatch
=
{
.
socket
=
MuslSocket
(
socket
),
};
bool
__socket_hook_begin_flag
;
#endif
\ No newline at end of file
porting/linux/user/src/hook/musl_socket_preinit_common.h
0 → 100644
浏览文件 @
82d45776
#ifndef _MUSL_SOCKET_PREINIT_COMMON_H
#define _MUSL_SOCKET_PREINIT_COMMON_H
#include <stdio.h>
#include "musl_socket_dispatch.h"
#include "common_def.h"
extern
struct
SocketDispatchType
__musl_libc_socket_dispatch
;
extern
struct
SocketDispatchType
__libc_socket_default_dispatch
;
enum
SocketFuncEnum
{
INITIALIZE_FUNC
,
FINALIZE_FUNC
,
GET_HOOK_FLAG_FUNC
,
SET_HOOK_FLAG_FUNC
,
LAST_FUNC
,
};
#ifdef OHOS_SOCKET_HOOK_ENABLE
extern
long
long
__current_dispatch
;
extern
bool
__socket_hook_begin_flag
;
extern
long
long
__ohos_socket_hook_shared_library
;
extern
void
*
shared_lib_func
[
LAST_FUNC
];
#endif
#ifdef __cplusplus
extern
"C"
{
#endif
__attribute__
((
always_inline
))
inline
bool
__get_socket_hook_begin_flag
()
{
#ifdef OHOS_SOCKET_HOOK_ENABLE
return
__socket_hook_begin_flag
;
#else
return
false
;
#endif
}
__attribute__
((
always_inline
))
inline
bool
__get_socket_hook_flag
()
{
#ifdef OHOS_SOCKET_HOOK_ENABLE
void
*
handle
=
(
void
*
)
__ohos_socket_hook_shared_library
;
if
(
handle
==
NULL
)
{
return
false
;
}
else
if
(
handle
==
(
void
*
)
-
1
)
{
return
true
;
}
else
{
SocketGetHookFlagType
get_hook_func_ptr
=
(
SocketGetHookFlagType
)(
shared_lib_func
[
GET_HOOK_FLAG_FUNC
]);
bool
flag
=
get_hook_func_ptr
();
return
flag
;
}
#else
return
false
;
#endif
}
__attribute__
((
always_inline
))
inline
volatile
const
struct
SocketDispatchType
*
get_socket_dispatch
()
{
#ifdef OHOS_SOCKET_HOOK_ENABLE
volatile
const
struct
SocketDispatchType
*
ret
=
(
struct
SocketDispatchType
*
)
__current_dispatch
;
if
(
ret
!=
NULL
)
{
if
(
!
__get_socket_hook_begin_flag
())
{
ret
=
NULL
;
}
else
if
(
!
__get_socket_hook_flag
())
{
ret
=
NULL
;
}
else
{
return
ret
;
}
}
return
ret
;
#else
return
NULL
;
#endif
}
#ifdef __cplusplus
}
#endif
#endif
\ No newline at end of file
porting/linux/user/src/hook/socket_common.c
0 → 100644
浏览文件 @
82d45776
#ifdef OHOS_SOCKET_HOOK_ENABLE
#include "musl_socket.h"
#include <sys/socket.h>
#include "common_def.h"
#include "musl_socket_preinit_common.h"
int
socket
(
int
domain
,
int
type
,
int
protocol
)
{
volatile
const
struct
SocketDispatchType
*
dispatch
=
get_socket_dispatch
();
if
(
__predict_false
(
dispatch
!=
NULL
))
{
int
ret
=
dispatch
->
socket
(
domain
,
type
,
protocol
);
return
ret
;
}
int
result
=
MuslSocket
(
socket
)(
domain
,
type
,
protocol
);
return
result
;
}
#endif
\ No newline at end of file
porting/linux/user/src/network/socket.c
0 → 100644
浏览文件 @
82d45776
#include <sys/socket.h>
#include <fcntl.h>
#include <errno.h>
#include <dlfcn.h>
#include <stdint.h>
#include <stddef.h>
#include "syscall.h"
#if OHOS_PERMISSION_INTERNET
typedef
uint8_t
(
*
AllowFunc
)(
void
);
static
const
char
*
LIB_NETSYS_CLIENT_NAME
=
"libnetsys_client.z.so"
;
static
const
char
*
ALLOW_SOCKET_FUNC_NAME
=
"IsAllowInternet"
;
/*
* Read a flag from netsys_client, there is only one place to set this flag, is the
* founction named DoStartup in startup_appspawn.
* */
uint8_t
is_allow_internet
(
void
)
{
static
uint8_t
first_time
=
1
;
static
uint8_t
allow
=
1
;
if
(
!
first_time
)
{
return
allow
;
}
void
*
handler
=
dlopen
(
LIB_NETSYS_CLIENT_NAME
,
RTLD_LAZY
);
if
(
handler
!=
NULL
)
{
AllowFunc
func
=
(
AllowFunc
)
dlsym
(
handler
,
ALLOW_SOCKET_FUNC_NAME
);
if
(
func
!=
NULL
&&
func
()
==
0
)
{
allow
=
0
;
}
dlclose
(
handler
);
}
first_time
=
0
;
return
allow
;
}
#endif
#ifdef OHOS_SOCKET_HOOK_ENABLE
int
__libc_socket
(
int
domain
,
int
type
,
int
protocol
)
#else
int
socket
(
int
domain
,
int
type
,
int
protocol
)
#endif
{
#if OHOS_PERMISSION_INTERNET
if
((
domain
==
AF_INET
||
domain
==
AF_INET6
)
&&
is_allow_internet
()
==
0
)
{
errno
=
EPERM
;
return
-
1
;
}
#endif
int
s
=
socketcall
(
socket
,
domain
,
type
,
protocol
,
0
,
0
,
0
);
if
(
s
<
0
&&
(
errno
==
EINVAL
||
errno
==
EPROTONOSUPPORT
)
&&
(
type
&
(
SOCK_CLOEXEC
|
SOCK_NONBLOCK
)))
{
s
=
socketcall
(
socket
,
domain
,
type
&
~
(
SOCK_CLOEXEC
|
SOCK_NONBLOCK
),
protocol
,
0
,
0
,
0
);
if
(
s
<
0
)
{
return
s
;
}
if
(
type
&
SOCK_CLOEXEC
)
{
__syscall
(
SYS_fcntl
,
s
,
F_SETFD
,
FD_CLOEXEC
);
}
if
(
type
&
SOCK_NONBLOCK
)
{
__syscall
(
SYS_fcntl
,
s
,
F_SETFL
,
O_NONBLOCK
);
}
}
return
s
;
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录