Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
communication_ipc
提交
17fd9fc5
C
communication_ipc
项目概览
OpenHarmony
/
communication_ipc
12 个月 前同步成功
通知
20
Star
3
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
communication_ipc
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
17fd9fc5
编写于
12月 30, 2021
作者:
L
liubb_0516
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ipc module
Signed-off-by:
N
liubb_0516
<
liubeibei8@huawei.com
>
上级
1b97a0a1
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
148 addition
and
533 deletion
+148
-533
interfaces/innerkits/c/ipc/BUILD.gn
interfaces/innerkits/c/ipc/BUILD.gn
+52
-34
interfaces/innerkits/c/ipc/include/serializer.h
interfaces/innerkits/c/ipc/include/serializer.h
+11
-59
ipc/native/c/adapter/Linux/rpc_os_adapter.c
ipc/native/c/adapter/Linux/rpc_os_adapter.c
+1
-1
ipc/native/c/ipc/src/binder_invoker.c
ipc/native/c/ipc/src/binder_invoker.c
+1
-1
ipc/native/c/manager/include/ipc_thread_pool.h
ipc/native/c/manager/include/ipc_thread_pool.h
+1
-2
ipc/native/c/manager/include/iremote_invoker.h
ipc/native/c/manager/include/iremote_invoker.h
+0
-2
ipc/native/c/manager/src/ipc_process_skeleton.c
ipc/native/c/manager/src/ipc_process_skeleton.c
+11
-11
ipc/native/c/manager/src/ipc_thread_pool.c
ipc/native/c/manager/src/ipc_thread_pool.c
+34
-24
ipc/native/c/manager/src/iremote_invoker.c
ipc/native/c/manager/src/iremote_invoker.c
+0
-10
ipc/native/c/manager/src/serializer.c
ipc/native/c/manager/src/serializer.c
+37
-389
未找到文件。
interfaces/innerkits/c/ipc/BUILD.gn
浏览文件 @
17fd9fc5
...
...
@@ -17,10 +17,7 @@ SUBSYSTEM_DIR = "//foundation/communication/ipc"
IPC_CORE_ROOT = "$SUBSYSTEM_DIR/ipc/native/c"
config("ipc_rpc_interface") {
include_dirs = [
"$SUBSYSTEM_DIR/interfaces/innerkits/c/ipc/include",
"$SUBSYSTEM_DIR/interfaces/innerkits/c/dbinder/include",
]
include_dirs = [ "$SUBSYSTEM_DIR/interfaces/innerkits/c/ipc/include" ]
}
if (ohos_kernel_type == "liteos_m") {
...
...
@@ -31,28 +28,62 @@ if (ohos_kernel_type == "liteos_m") {
"//base/hiviewdfx/hilog_lite/interfaces/native/innerkits"
}
ipc_common_include = [
"$IPC_CORE_ROOT/ipc/include",
"$IPC_CORE_ROOT/manager/include",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
"$hilog_lite_include_path",
]
ipc_common_src = [
"$IPC_CORE_ROOT/manager/src/ipc_process_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_thread_pool.c",
"$IPC_CORE_ROOT/manager/src/iremote_invoker.c",
"$IPC_CORE_ROOT/manager/src/serializer.c",
]
if (ohos_kernel_type == "liteos_m") {
static_library("ipc_single") {
sources = [
sources = ipc_common_src
sources += [
"$IPC_CORE_ROOT/ipc/src/binder_invoker_virtual.c",
"$IPC_CORE_ROOT/manager/src/ipc_process_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_thread_pool.c",
"$IPC_CORE_ROOT/manager/src/iremote_invoker.c",
"$IPC_CORE_ROOT/manager/src/rpc_log.c",
"$IPC_CORE_ROOT/manager/src/serializer.c",
]
include_dirs = ipc_common_include
public_configs = [ ":ipc_rpc_interface" ]
deps = [ "//foundation/communication/ipc/ipc/native/c/adapter:rpc_adapter" ]
}
} else if (ohos_kernel_type == "liteos_a") {
shared_library("rpc_log") {
sources = [ "$IPC_CORE_ROOT/manager/src/rpc_log.c" ]
include_dirs = [
"$IPC_CORE_ROOT/ipc/include",
"$IPC_CORE_ROOT/rpc/include",
"$IPC_CORE_ROOT/manager/include",
"$SUBSYSTEM_DIR/services/dbinder/c/include",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
"$hilog_lite_include_path",
]
deps = [ "//foundation/communication/ipc/ipc/native/c/adapter:rpc_adapter" ]
public_deps = [
"//base/hiviewdfx/hilog_lite/frameworks/featured:hilog_shared",
"//third_party/bounds_checking_function/:libsec_shared",
]
}
shared_library("ipc_single") {
sources = ipc_common_src
sources += [ "$IPC_CORE_ROOT/ipc/src/binder_invoker_virtual.c" ]
public_configs = [ ":ipc_rpc_interface" ]
include_dirs = ipc_common_include
ldflags = [
"-lstdc++",
"-lpthread",
]
cflags = [ "-fPIC" ]
cflags_cc = cflags
public_deps = [
":rpc_log",
"//foundation/communication/ipc/ipc/native/c/adapter:rpc_adapter",
"//third_party/bounds_checking_function/:libsec_shared",
]
}
} else {
shared_library("rpc_log") {
...
...
@@ -68,34 +99,21 @@ if (ohos_kernel_type == "liteos_m") {
}
shared_library("ipc_single") {
sources = [
"$IPC_CORE_ROOT/ipc/src/binder_invoker.c",
"$IPC_CORE_ROOT/manager/src/ipc_process_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_skeleton.c",
"$IPC_CORE_ROOT/manager/src/ipc_thread_pool.c",
"$IPC_CORE_ROOT/manager/src/iremote_invoker.c",
"$IPC_CORE_ROOT/manager/src/serializer.c",
]
sources = ipc_common_src
sources += [ "$IPC_CORE_ROOT/ipc/src/binder_invoker.c" ]
public_configs = [ ":ipc_rpc_interface" ]
include_dirs = [
"$IPC_CORE_ROOT/ipc/include",
"$IPC_CORE_ROOT/rpc/include",
"$IPC_CORE_ROOT/manager/include",
"$SUBSYSTEM_DIR/services/dbinder/c/include",
"//third_party/bounds_checking_function/include",
"//utils/native/lite/include",
]
include_dirs = ipc_common_include
ldflags = [
"-lstdc++",
"-lpthread",
"-fPIC",
]
cflags = [ "-fPIC" ]
cflags_cc = cflags
public_deps = [
":rpc_log",
"//foundation/communication/ipc/ipc/native/c/adapter:rpc_adapter",
"//third_party/bounds_checking_function/:libsec_shared",
]
configs -= [ "//build/lite/config:clang_opt" ]
}
}
interfaces/innerkits/c/ipc/include/serializer.h
浏览文件 @
17fd9fc5
...
...
@@ -27,17 +27,17 @@ extern "C" {
#endif
/* __cplusplus */
typedef
struct
{
char
*
bufferBase
;
size_t
*
offsetsBase
;
char
*
bufferCur
;
size_t
*
offsetsCur
;
char
*
bufferBase
;
size_t
*
offsetsBase
;
char
*
bufferCur
;
size_t
*
offsetsCur
;
size_t
bufferLeft
;
size_t
offsetsLeft
;
uint32_t
flag
;
}
IpcIo
;
typedef
struct
{
int32_t
handle
;
// 是否按原ipc格式改成联合体
int32_t
handle
;
uintptr_t
token
;
uintptr_t
cookie
;
}
SvcIdentity
;
...
...
@@ -46,61 +46,13 @@ typedef struct {
#define IPC_IO_INITIALIZED 0x01
/* ipc flag indicates whether io is initialized */
#define IPC_IO_OVERFLOW 0x02
/* ipc flag indicates whether io is running out of space */
/* allocate a IpcIo, providing a stack-allocated working
* buffer, size of the working buffer, and how many object
* offset entries to reserve from the buffer
*/
void
IpcIoInit
(
IpcIo
*
io
,
void
*
data
,
size_t
maxdata
,
size_t
maxobjects
);
/* Must ensure all the input is valid */
void
IpcIoPushChar
(
IpcIo
*
io
,
char
c
);
void
IpcIoPushCharUnaligned
(
IpcIo
*
io
,
char
c
);
void
IpcIoPushBool
(
IpcIo
*
io
,
bool
b
);
void
IpcIoPushBoolUnaligned
(
IpcIo
*
io
,
bool
b
);
void
IpcIoPushIntptr
(
IpcIo
*
io
,
intptr_t
n
);
void
IpcIoPushUintptr
(
IpcIo
*
io
,
uintptr_t
n
);
void
IpcIoPushInt8
(
IpcIo
*
io
,
int8_t
n
);
void
IpcIoPushInt8Unaligned
(
IpcIo
*
io
,
int8_t
n
);
void
IpcIoPushUint8
(
IpcIo
*
io
,
uint8_t
n
);
void
IpcIoPushUint8Unaligned
(
IpcIo
*
io
,
uint8_t
n
);
void
IpcIoPushInt16
(
IpcIo
*
io
,
int16_t
n
);
void
IpcIoPushInt16Unaligned
(
IpcIo
*
io
,
int16_t
n
);
void
IpcIoPushUint16
(
IpcIo
*
io
,
uint16_t
n
);
void
IpcIoPushUint16Unaligned
(
IpcIo
*
io
,
uint16_t
n
);
void
IpcIoPushInt32
(
IpcIo
*
io
,
int32_t
n
);
void
IpcIoPushUint32
(
IpcIo
*
io
,
uint32_t
n
);
void
IpcIoPushInt64
(
IpcIo
*
io
,
int64_t
n
);
void
IpcIoPushUint64
(
IpcIo
*
io
,
uint64_t
n
);
void
IpcIoPushFloat
(
IpcIo
*
io
,
float
n
);
void
IpcIoPushDouble
(
IpcIo
*
io
,
double
n
);
void
IpcIoPushString
(
IpcIo
*
io
,
const
char
*
cstr
);
void
IpcIoPushFlatObj
(
IpcIo
*
io
,
const
void
*
obj
,
uint32_t
size
);
bool
IpcIoPushSvc
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
);
bool
IpcIoPushFd
(
IpcIo
*
io
,
uint32_t
fd
);
void
IpcIoInit
(
IpcIo
*
io
,
void
*
buffer
,
size_t
bufferSize
,
size_t
maxobjects
);
bool
WriteRemoteObject
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
);
bool
WriteFileDescriptor
(
IpcIo
*
io
,
uint32_t
fd
);
char
IpcIoPopChar
(
IpcIo
*
io
);
char
IpcIoPopCharUnaligned
(
IpcIo
*
io
);
bool
IpcIoPopBool
(
IpcIo
*
io
);
bool
IpcIoPopBoolUnaligned
(
IpcIo
*
io
);
intptr_t
IpcIoPopIntptr
(
IpcIo
*
io
);
uintptr_t
IpcIoPopUintptr
(
IpcIo
*
io
);
int8_t
IpcIoPopInt8
(
IpcIo
*
io
);
int8_t
IpcIoPopInt8Unaligned
(
IpcIo
*
io
);
uint8_t
IpcIoPopUint8
(
IpcIo
*
io
);
uint8_t
IpcIoPopUint8Unaligned
(
IpcIo
*
io
);
int16_t
IpcIoPopInt16
(
IpcIo
*
io
);
int16_t
IpcIoPopInt16Unaligned
(
IpcIo
*
io
);
uint16_t
IpcIoPopUint16
(
IpcIo
*
io
);
uint16_t
IpcIoPopUint16Unaligned
(
IpcIo
*
io
);
int32_t
IpcIoPopInt32
(
IpcIo
*
io
);
uint32_t
IpcIoPopUint32
(
IpcIo
*
io
);
int64_t
IpcIoPopInt64
(
IpcIo
*
io
);
uint64_t
IpcIoPopUint64
(
IpcIo
*
io
);
float
IpcIoPopFloat
(
IpcIo
*
io
);
double
IpcIoPopDouble
(
IpcIo
*
io
);
uint8_t
*
IpcIoPopString
(
IpcIo
*
io
,
size_t
*
sz
);
void
*
IpcIoPopFlatObj
(
IpcIo
*
io
,
uint32_t
*
size
);
bool
IpcIoPopSvc
(
IpcIo
*
io
,
SvcIdentity
*
svc
);
int32_t
IpcIoPopFd
(
IpcIo
*
io
);
bool
ReadRemoteObject
(
IpcIo
*
io
,
SvcIdentity
*
svc
);
int32_t
ReadFileDescriptor
(
IpcIo
*
io
);
#ifdef __cplusplus
#if __cplusplus
...
...
ipc/native/c/adapter/Linux/rpc_os_adapter.c
浏览文件 @
17fd9fc5
...
...
@@ -23,5 +23,5 @@ int32_t RpcGetPid(void)
int32_t
RpcGetUid
()
{
return
(
int32_t
)
getuid
(
void
);
return
(
int32_t
)
getuid
();
}
\ No newline at end of file
ipc/native/c/ipc/src/binder_invoker.c
浏览文件 @
17fd9fc5
...
...
@@ -211,7 +211,7 @@ static int32_t SendReply(IpcIo *reply, const int32_t *status)
static
void
HandleTransaction
(
const
struct
binder_transaction_data
*
tr
)
{
ThreadContext
*
threadContext
=
GetCurrentThreadContext
();
// sender pid, uid作用域范围
ThreadContext
*
threadContext
=
GetCurrentThreadContext
();
const
pid_t
oldPid
=
threadContext
->
callerPid
;
const
pid_t
oldUid
=
threadContext
->
callerUid
;
threadContext
->
callerPid
=
tr
->
sender_pid
;
...
...
ipc/native/c/manager/include/ipc_thread_pool.h
浏览文件 @
17fd9fc5
...
...
@@ -64,8 +64,7 @@ int32_t SpawnNewThread(ThreadPool *threadPool, int32_t policy, int32_t proto);
ThreadContext
*
GetCurrentThreadContext
(
void
);
// get or update invoker
RemoteInvoker
*
GetRemoteInvoker
(
int32_t
proto
);
RemoteInvoker
*
GetRemoteInvoker
(
void
);
void
UpdateMaxThreadNum
(
ThreadPool
*
threadPool
,
int32_t
maxThreadNum
);
...
...
ipc/native/c/manager/include/iremote_invoker.h
浏览文件 @
17fd9fc5
...
...
@@ -43,8 +43,6 @@ typedef struct {
}
RemoteInvoker
;
RemoteInvoker
*
InitRemoteInvoker
(
int32_t
proto
);
void
DeleteInvoker
(
RemoteInvoker
*
invoker
,
int32_t
proto
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
ipc/native/c/manager/src/ipc_process_skeleton.c
浏览文件 @
17fd9fc5
...
...
@@ -50,7 +50,7 @@ static IpcSkeleton* IpcProcessSkeleton()
RPC_LOG_ERROR
(
"init thread pool failed."
);
return
NULL
;
}
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
==
NULL
)
{
DeleteIpcSkeleton
(
temp
);
RPC_LOG_ERROR
(
"get remote invoker failed."
);
...
...
@@ -104,7 +104,7 @@ int32_t SetMaxWorkThread(int32_t maxThreadNum)
}
UpdateMaxThreadNum
(
g_ipcSkeleton
->
threadPool
,
maxThreadNum
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
return
(
invoker
->
SetMaxWorkThread
)(
maxThreadNum
);
}
...
...
@@ -114,7 +114,7 @@ int32_t SetMaxWorkThread(int32_t maxThreadNum)
void
JoinMainWorkThread
(
void
)
{
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
(
invoker
->
JoinThread
)(
true
);
}
...
...
@@ -146,7 +146,7 @@ const SvcIdentity *GetRegistryObject(void)
int32_t
SetRegistryObject
(
SvcIdentity
target
)
{
int32_t
ret
=
ERR_THREAD_INVOKER_NOT_INIT
;
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
ret
=
(
invoker
->
SetRegistryObject
)();
}
...
...
@@ -177,7 +177,7 @@ static void DeleteDeadHandle(int32_t handle)
}
pthread_mutex_unlock
(
&
g_ipcSkeleton
->
lock
);
if
(
isValidHandle
)
{
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
(
invoker
->
ReleaseHandle
)(
handle
);
}
...
...
@@ -188,7 +188,7 @@ int32_t ProcessSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo
MessageOption
option
,
uintptr_t
*
buffer
)
{
int32_t
ret
=
ERR_THREAD_INVOKER_NOT_INIT
;
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
ret
=
(
invoker
->
SendRequest
)(
target
,
code
,
data
,
reply
,
option
,
buffer
);
}
...
...
@@ -201,7 +201,7 @@ int32_t ProcessSendRequest(SvcIdentity target, uint32_t code, IpcIo *data, IpcIo
int32_t
ProcessFreeBuffer
(
void
*
ptr
)
{
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
return
(
invoker
->
FreeBuffer
)(
ptr
);
}
...
...
@@ -247,7 +247,7 @@ static void OnFirstStrongRef(int32_t handle)
return
;
}
if
(
FirstAddObject
(
handle
))
{
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
(
invoker
->
AcquireHandle
)(
handle
);
}
...
...
@@ -309,7 +309,7 @@ int32_t ProcessAddDeathRecipient(int32_t handle, OnRemoteDead deathFunc, void *a
pthread_mutex_unlock
(
&
g_ipcSkeleton
->
lock
);
if
(
firstDeathNode
)
{
RPC_LOG_ERROR
(
"first add death callback for handle = %d."
,
handle
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
ret
=
(
invoker
->
AddDeathRecipient
)(
handle
,
node
);
}
...
...
@@ -379,7 +379,7 @@ void SendObituary(DeathCallback *deathCallback)
}
pthread_mutex_unlock
(
&
deathCallback
->
lock
);
if
(
deathNum
>
0
)
{
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
(
invoker
->
RemoveDeathRecipient
)(
deathCallback
->
handle
,
deathCallback
);
}
...
...
@@ -404,7 +404,7 @@ void DeleteDeathCallback(DeathCallback *deathCallback)
RPC_LOG_ERROR
(
"invalid death node"
);
return
;
}
RemoteInvoker
*
invoker
=
GetRemoteInvoker
(
IF_PROT_DEFAULT
);
RemoteInvoker
*
invoker
=
GetRemoteInvoker
();
if
(
invoker
!=
NULL
)
{
(
invoker
->
ReleaseHandle
)(
deathCallback
->
handle
);
}
...
...
ipc/native/c/manager/src/ipc_thread_pool.c
浏览文件 @
17fd9fc5
...
...
@@ -30,6 +30,26 @@
static
pthread_key_t
g_localKey
=
-
1
;
static
RemoteInvoker
*
g_invoker
[
PROTO_NUM
];
ThreadContext
*
GetCurrentThreadContext
(
void
)
{
ThreadContext
*
current
=
NULL
;
void
*
curTLS
=
pthread_getspecific
(
g_localKey
);
if
(
curTLS
!=
NULL
)
{
current
=
(
ThreadContext
*
)
curTLS
;
}
else
{
current
=
(
ThreadContext
*
)
calloc
(
1
,
sizeof
(
ThreadContext
));
if
(
current
==
NULL
)
{
return
NULL
;
}
current
->
threadId
=
pthread_self
();
current
->
proto
=
IF_PROT_DEFAULT
;
current
->
callerPid
=
RpcGetPid
();
current
->
callerUid
=
RpcGetUid
();
pthread_setspecific
(
g_localKey
,
current
);
}
return
current
;
}
static
void
TlsDestructor
(
void
*
args
)
{
RPC_LOG_INFO
(
"thread exit, call tls destructor"
);
...
...
@@ -53,6 +73,16 @@ static void ThreadContextDestructor(int32_t proto)
pthread_mutex_unlock
(
&
threadPool
->
lock
);
}
static
RemoteInvoker
*
GetAndUpdateInvoker
(
int32_t
proto
)
{
ThreadContext
*
threadContext
=
GetCurrentThreadContext
();
if
(
threadContext
==
NULL
)
{
return
NULL
;
}
threadContext
->
proto
=
proto
;
return
g_invoker
[
proto
];
}
static
void
*
ThreadHandler
(
void
*
args
)
{
ThreadContext
*
threadContext
=
(
ThreadContext
*
)
args
;
...
...
@@ -60,7 +90,7 @@ static void *ThreadHandler(void *args)
int32_t
policy
=
threadContext
->
policy
;
free
(
threadContext
);
threadContext
=
NULL
;
RemoteInvoker
*
invoker
=
Get
Remo
teInvoker
(
proto
);
RemoteInvoker
*
invoker
=
Get
AndUpda
teInvoker
(
proto
);
if
(
invoker
!=
NULL
)
{
switch
(
policy
)
{
case
SPAWN_PASSIVE
:
...
...
@@ -103,7 +133,7 @@ void DeinitThreadPool(ThreadPool *threadPool)
pthread_key_delete
(
g_localKey
);
free
(
threadPool
);
for
(
int32_t
index
=
0
;
index
<
PROTO_NUM
;
++
index
)
{
DeleteInvoker
(
g_invoker
[
index
],
index
)
;
g_invoker
[
index
]
=
NULL
;
}
}
...
...
@@ -144,26 +174,6 @@ int32_t SpawnNewThread(ThreadPool *threadPool, int32_t policy, int32_t proto)
return
ERR_NONE
;
}
ThreadContext
*
GetCurrentThreadContext
(
void
)
{
ThreadContext
*
current
=
NULL
;
void
*
curTLS
=
pthread_getspecific
(
g_localKey
);
if
(
curTLS
!=
NULL
)
{
current
=
(
ThreadContext
*
)
curTLS
;
}
else
{
current
=
(
ThreadContext
*
)
calloc
(
1
,
sizeof
(
ThreadContext
));
if
(
current
==
NULL
)
{
return
NULL
;
}
current
->
threadId
=
pthread_self
();
current
->
proto
=
IF_PROT_DEFAULT
;
current
->
callerPid
=
RpcGetPid
();
current
->
callerUid
=
RpcGetUid
();
pthread_setspecific
(
g_localKey
,
current
);
}
return
current
;
}
void
UpdateMaxThreadNum
(
ThreadPool
*
threadPool
,
int32_t
maxThreadNum
)
{
int32_t
totalNum
=
maxThreadNum
+
maxThreadNum
;
...
...
@@ -183,11 +193,11 @@ void UpdateMaxThreadNum(ThreadPool *threadPool, int32_t maxThreadNum)
pthread_mutex_unlock
(
&
threadPool
->
lock
);
}
RemoteInvoker
*
GetRemoteInvoker
(
int32_t
proto
)
RemoteInvoker
*
GetRemoteInvoker
(
void
)
{
ThreadContext
*
threadContext
=
GetCurrentThreadContext
();
if
(
threadContext
==
NULL
)
{
return
NULL
;
}
return
g_invoker
[
proto
];
return
g_invoker
[
threadContext
->
proto
];
}
\ No newline at end of file
ipc/native/c/manager/src/iremote_invoker.c
浏览文件 @
17fd9fc5
...
...
@@ -25,14 +25,4 @@ RemoteInvoker *InitRemoteInvoker(int32_t proto)
remoteInvoker
=
GetIpcInvoker
();
}
return
remoteInvoker
;
}
void
DeleteInvoker
(
RemoteInvoker
*
remoteInvoker
,
int32_t
proto
)
{
if
(
remoteInvoker
==
NULL
)
{
return
;
}
if
(
proto
==
IF_PROT_BINDER
)
{
remoteInvoker
=
NULL
;
}
}
\ No newline at end of file
ipc/native/c/manager/src/serializer.c
浏览文件 @
17fd9fc5
...
...
@@ -14,18 +14,18 @@
*/
#include "serializer.h"
#include "securec.h"
#include <stdlib.h>
#include <string.h>
#ifdef __LINUX__
#include "sys_binder.h"
#endif
#include "rpc_log.h"
#include "ipc_process_skeleton.h"
#include "rpc_log.h"
#include "securec.h"
#define MAX_IO_SIZE 8192UL
#define MAX_OBJ_NUM 32UL
#define MAX_DATA_BUFF_SIZE 65536UL
#define ALIGN_SZ 4
#define IPC_IO_ALIGN(sz) (((sz) + ALIGN_SZ - 1) & (~(ALIGN_SZ - 1)))
...
...
@@ -41,7 +41,6 @@
}
\
}
while
(
0
)
static
void
*
IoPop
(
IpcIo
*
io
,
size_t
size
);
void
IpcIoInit
(
IpcIo
*
io
,
void
*
buffer
,
size_t
bufferSize
,
size_t
maxobjects
)
{
...
...
@@ -91,197 +90,6 @@ static void* IoPush(IpcIo* io, size_t size)
}
}
static
void
*
IoPushUnaligned
(
IpcIo
*
io
,
size_t
size
)
{
IPC_IO_RETURN_IF_FAIL
(
io
!=
NULL
);
IPC_IO_RETURN_IF_FAIL
(
IpcIoAvailable
(
io
));
if
(
size
>
io
->
bufferLeft
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
NULL
;
}
else
{
void
*
ptr
=
io
->
bufferCur
;
io
->
bufferCur
+=
size
;
io
->
bufferLeft
-=
size
;
return
ptr
;
}
}
void
IpcIoPushInt32
(
IpcIo
*
io
,
int32_t
n
)
{
int32_t
*
ptr
=
(
int32_t
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushUint32
(
IpcIo
*
io
,
uint32_t
n
)
{
uint32_t
*
ptr
=
(
uint32_t
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushChar
(
IpcIo
*
io
,
char
c
)
{
IpcIoPushInt32
(
io
,
(
int32_t
)
c
);
}
void
IpcIoPushCharUnaligned
(
IpcIo
*
io
,
char
c
)
{
char
*
ptr
=
(
char
*
)
IoPushUnaligned
(
io
,
sizeof
(
c
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
c
;
}
}
void
IpcIoPushBool
(
IpcIo
*
io
,
bool
b
)
{
IpcIoPushInt32
(
io
,
(
int32_t
)
b
);
}
void
IpcIoPushBoolUnaligned
(
IpcIo
*
io
,
bool
b
)
{
bool
*
ptr
=
(
bool
*
)
IoPushUnaligned
(
io
,
sizeof
(
b
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
b
;
}
}
void
IpcIoPushIntptr
(
IpcIo
*
io
,
intptr_t
intptr
)
{
intptr_t
*
ptr
=
(
intptr_t
*
)
IoPush
(
io
,
sizeof
(
intptr
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
intptr
;
}
}
void
IpcIoPushUintptr
(
IpcIo
*
io
,
uintptr_t
uintptr
)
{
uintptr_t
*
ptr
=
(
uintptr_t
*
)
IoPush
(
io
,
sizeof
(
uintptr
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
uintptr
;
}
}
void
IpcIoPushInt8
(
IpcIo
*
io
,
int8_t
n
)
{
IpcIoPushInt32
(
io
,
(
int32_t
)
n
);
}
void
IpcIoPushInt8Unaligned
(
IpcIo
*
io
,
int8_t
n
)
{
int8_t
*
ptr
=
(
int8_t
*
)
IoPushUnaligned
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushUint8
(
IpcIo
*
io
,
uint8_t
n
)
{
IpcIoPushUint32
(
io
,
(
uint32_t
)
n
);
}
void
IpcIoPushUint8Unaligned
(
IpcIo
*
io
,
uint8_t
n
)
{
uint8_t
*
ptr
=
(
uint8_t
*
)
IoPushUnaligned
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushInt16
(
IpcIo
*
io
,
int16_t
n
)
{
IpcIoPushInt32
(
io
,
(
int32_t
)
n
);
}
void
IpcIoPushInt16Unaligned
(
IpcIo
*
io
,
int16_t
n
)
{
int16_t
*
ptr
=
(
int16_t
*
)
IoPushUnaligned
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushUint16
(
IpcIo
*
io
,
uint16_t
n
)
{
IpcIoPushUint32
(
io
,
(
uint32_t
)
n
);
}
void
IpcIoPushUint16Unaligned
(
IpcIo
*
io
,
uint16_t
n
)
{
uint16_t
*
ptr
=
(
uint16_t
*
)
IoPushUnaligned
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushInt64
(
IpcIo
*
io
,
int64_t
n
)
{
int64_t
*
ptr
=
(
int64_t
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushUint64
(
IpcIo
*
io
,
uint64_t
n
)
{
uint64_t
*
ptr
=
(
uint64_t
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushFloat
(
IpcIo
*
io
,
float
n
)
{
float
*
ptr
=
(
float
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushDouble
(
IpcIo
*
io
,
double
n
)
{
double
*
ptr
=
(
double
*
)
IoPush
(
io
,
sizeof
(
n
));
if
(
ptr
!=
NULL
)
{
*
ptr
=
n
;
}
}
void
IpcIoPushString
(
IpcIo
*
io
,
const
char
*
cstr
)
{
unsigned
char
*
str
=
(
unsigned
char
*
)
cstr
;
size_t
len
;
uint8_t
*
ptr
=
NULL
;
if
(
io
==
NULL
)
{
return
;
}
if
(
str
==
NULL
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
;
}
len
=
strlen
(
cstr
);
if
(
len
==
MAX_IO_SIZE
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
;
}
/* Note: The payload will carry 32bit size instead of size_t */
IpcIoPushUint32
(
io
,
(
uint32_t
)
len
);
ptr
=
(
uint8_t
*
)
IoPush
(
io
,
len
+
1
);
if
(
ptr
!=
NULL
)
{
if
(
memset_s
(
ptr
,
IPC_IO_ALIGN
(
len
+
1
),
0
,
IPC_IO_ALIGN
(
len
+
1
))
!=
EOK
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
;
}
if
(
memcpy_s
(
ptr
,
IPC_IO_ALIGN
(
len
+
1
),
str
,
len
+
1
)
!=
EOK
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
}
}
}
static
void
*
IoPop
(
IpcIo
*
io
,
size_t
size
)
{
IPC_IO_RETURN_IF_FAIL
(
io
!=
NULL
);
...
...
@@ -300,186 +108,6 @@ static void* IoPop(IpcIo* io, size_t size)
}
}
static
void
*
IoPopUnaligned
(
IpcIo
*
io
,
size_t
size
)
{
IPC_IO_RETURN_IF_FAIL
(
io
!=
NULL
);
IPC_IO_RETURN_IF_FAIL
(
IpcIoAvailable
(
io
));
if
(
io
->
bufferLeft
<
size
)
{
io
->
bufferLeft
=
0
;
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
NULL
;
}
else
{
void
*
ptr
=
io
->
bufferCur
;
io
->
bufferCur
+=
size
;
io
->
bufferLeft
-=
size
;
return
ptr
;
}
}
char
IpcIoPopChar
(
IpcIo
*
io
)
{
char
*
ptr
=
(
char
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
char
IpcIoPopCharUnaligned
(
IpcIo
*
io
)
{
char
*
ptr
=
(
char
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
bool
IpcIoPopBool
(
IpcIo
*
io
)
{
bool
*
ptr
=
(
bool
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
bool
IpcIoPopBoolUnaligned
(
IpcIo
*
io
)
{
bool
*
ptr
=
(
bool
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
intptr_t
IpcIoPopIntptr
(
IpcIo
*
io
)
{
intptr_t
*
ptr
=
(
intptr_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uintptr_t
IpcIoPopUintptr
(
IpcIo
*
io
)
{
uintptr_t
*
ptr
=
(
uintptr_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int8_t
IpcIoPopInt8
(
IpcIo
*
io
)
{
int8_t
*
ptr
=
(
int8_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int8_t
IpcIoPopInt8Unaligned
(
IpcIo
*
io
)
{
int8_t
*
ptr
=
(
int8_t
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint8_t
IpcIoPopUint8
(
IpcIo
*
io
)
{
uint8_t
*
ptr
=
(
uint8_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint8_t
IpcIoPopUint8Unaligned
(
IpcIo
*
io
)
{
uint8_t
*
ptr
=
(
uint8_t
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int16_t
IpcIoPopInt16
(
IpcIo
*
io
)
{
int16_t
*
ptr
=
(
int16_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int16_t
IpcIoPopInt16Unaligned
(
IpcIo
*
io
)
{
int16_t
*
ptr
=
(
int16_t
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint16_t
IpcIoPopUint16
(
IpcIo
*
io
)
{
uint16_t
*
ptr
=
(
uint16_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint16_t
IpcIoPopUint16Unaligned
(
IpcIo
*
io
)
{
uint16_t
*
ptr
=
(
uint16_t
*
)
IoPopUnaligned
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int32_t
IpcIoPopInt32
(
IpcIo
*
io
)
{
int32_t
*
ptr
=
(
int32_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint32_t
IpcIoPopUint32
(
IpcIo
*
io
)
{
uint32_t
*
ptr
=
(
uint32_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
int64_t
IpcIoPopInt64
(
IpcIo
*
io
)
{
int64_t
*
ptr
=
(
int64_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint64_t
IpcIoPopUint64
(
IpcIo
*
io
)
{
uint64_t
*
ptr
=
(
uint64_t
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
float
IpcIoPopFloat
(
IpcIo
*
io
)
{
float
*
ptr
=
(
float
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
double
IpcIoPopDouble
(
IpcIo
*
io
)
{
double
*
ptr
=
(
double
*
)
IoPop
(
io
,
sizeof
(
*
ptr
));
return
ptr
?
*
ptr
:
0
;
}
uint8_t
*
IpcIoPopString
(
IpcIo
*
io
,
size_t
*
sz
)
{
size_t
len
;
/* Note: The payload will carry 32bit size instead of size_t */
len
=
(
size_t
)
IpcIoPopUint32
(
io
);
if
(
sz
!=
NULL
)
{
*
sz
=
len
;
}
if
(
len
>
MAX_IO_SIZE
)
{
return
NULL
;
}
return
(
uint8_t
*
)
IoPop
(
io
,
len
+
1
);
}
void
*
IpcIoPopFlatObj
(
IpcIo
*
io
,
uint32_t
*
size
)
{
IPC_IO_RETURN_IF_FAIL
(
size
!=
NULL
);
*
size
=
(
size_t
)
IpcIoPopUint32
(
io
);
if
(
*
size
>
MAX_IO_SIZE
)
{
return
NULL
;
}
return
(
void
*
)
IoPop
(
io
,
*
size
);
}
void
IpcIoPushFlatObj
(
IpcIo
*
io
,
const
void
*
obj
,
uint32_t
size
)
{
if
(
io
==
NULL
)
{
return
;
}
if
((
obj
==
NULL
)
||
(
size
==
0
)
||
(
size
>
MAX_IO_SIZE
))
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
return
;
}
IpcIoPushUint32
(
io
,
size
);
int32_t
*
ptr
=
(
int32_t
*
)
IoPush
(
io
,
size
);
if
(
ptr
!=
NULL
)
{
if
(
memcpy_s
(
ptr
,
size
,
obj
,
size
)
!=
EOK
)
{
io
->
flag
|=
IPC_IO_OVERFLOW
;
}
}
}
#ifdef __LINUX__
static
struct
flat_binder_object
*
IoPushBinderObj
(
IpcIo
*
io
)
{
...
...
@@ -543,7 +171,7 @@ struct flat_binder_object* IpcIoPopRef(IpcIo *io)
return
NULL
;
}
bool
IpcIoPushSvc
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
bool
WriteRemoteObject
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
{
if
(
io
==
NULL
||
svc
==
NULL
)
{
RPC_LOG_ERROR
(
"push io or svc is NULL ..."
);
...
...
@@ -558,14 +186,14 @@ bool IpcIoPushSvc(IpcIo* io, const SvcIdentity* svc)
return
res
;
}
bool
IpcIoPopSvc
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
bool
ReadRemoteObject
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
{
if
(
io
==
NULL
||
svc
==
NULL
)
{
return
false
;
}
struct
flat_binder_object
*
obj
=
IpcIoPopRef
(
io
);
if
(
obj
==
NULL
)
{
RPC_LOG_ERROR
(
"
IpcIoPopSvc
failed: obj is null"
);
RPC_LOG_ERROR
(
"
ReadRemoteObject
failed: obj is null"
);
return
false
;
}
if
(
obj
->
type
==
BINDER_TYPE_BINDER
)
{
...
...
@@ -580,13 +208,13 @@ bool IpcIoPopSvc(IpcIo* io, SvcIdentity *svc)
return
true
;
}
bool
IpcIoPushFd
(
IpcIo
*
io
,
uint32_t
fd
)
bool
WriteFileDescriptor
(
IpcIo
*
io
,
uint32_t
fd
)
{
if
(
io
==
NULL
)
{
RPC_LOG_ERROR
(
"push fd io is NULL."
);
return
false
;
}
struct
flat_binder_object
*
ptr
=
IoPushBinderObj
(
io
);
struct
flat_binder_object
*
ptr
=
IoPushBinderObj
(
io
);
if
(
ptr
==
NULL
)
{
RPC_LOG_ERROR
(
"Io push fd IPC_IO_OVERFLOW.
\n
"
);
return
false
;
...
...
@@ -599,47 +227,67 @@ bool IpcIoPushFd(IpcIo* io, uint32_t fd)
return
true
;
}
int32_t
IpcIoPopFd
(
IpcIo
*
io
)
int32_t
ReadFileDescriptor
(
IpcIo
*
io
)
{
if
(
io
==
NULL
)
{
return
-
1
;
}
struct
flat_binder_object
*
obj
=
IpcIoPopRef
(
io
);
struct
flat_binder_object
*
obj
=
IpcIoPopRef
(
io
);
if
(
obj
==
NULL
)
{
RPC_LOG_ERROR
(
"
IpcIoPopFd
failed: obj is null"
);
RPC_LOG_ERROR
(
"
ReadFileDescriptor
failed: obj is null"
);
return
-
1
;
}
if
(
obj
&&
obj
->
type
==
BINDER_TYPE_FD
)
{
if
(
obj
->
type
==
BINDER_TYPE_FD
)
{
return
obj
->
handle
;
}
RPC_LOG_ERROR
(
"
IpcIoPopFd
failed: type:%d"
,
obj
->
type
);
RPC_LOG_ERROR
(
"
ReadFileDescriptor
failed: type:%d"
,
obj
->
type
);
return
-
1
;
}
bool
IpcIoPushSvc
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
{
return
false
;
}
bool
IpcIoPopSvc
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
{
return
false
;
}
#else
bool
IpcIoPushSvc
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
bool
WriteRemoteObject
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
{
(
void
)
io
;
(
void
)
svc
;
return
false
;
}
bool
IpcIoPushFd
(
IpcIo
*
io
,
uint32_t
fd
)
bool
WriteFileDescriptor
(
IpcIo
*
io
,
uint32_t
fd
)
{
(
void
)
io
;
(
void
)
fd
;
return
false
;
}
bool
IpcIoPopSvc
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
bool
ReadRemoteObject
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
{
(
void
)
io
;
(
void
)
svc
;
return
false
;
}
int32_t
IpcIoPopFd
(
IpcIo
*
io
)
int32_t
ReadFileDescriptor
(
IpcIo
*
io
)
{
(
void
)
io
;
return
-
1
;
}
bool
IpcIoPushSvc
(
IpcIo
*
io
,
const
SvcIdentity
*
svc
)
{
return
;
}
bool
IpcIoPopSvc
(
IpcIo
*
io
,
SvcIdentity
*
svc
)
{
return
;
}
#endif
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录