Fix ipc to support null pointer.
This commit is contained in:
parent
2c4fe30bd3
commit
dd0c6c66ed
|
@ -27,7 +27,7 @@ INC_DIR = -I$(KERNEL_ROOT)/services/shell/letter-shell \
|
||||||
-I$(KERNEL_ROOT)/services/app
|
-I$(KERNEL_ROOT)/services/app
|
||||||
|
|
||||||
ifeq ($(BOARD), imx6q-sabrelite)
|
ifeq ($(BOARD), imx6q-sabrelite)
|
||||||
all: init test_fault simple_client simple_server shell fs_server semaphore_server test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
all: init test_fault simple_client simple_server shell fs_server semaphore_server test_ipc_null test_thread test_irq_hdlr test_irq_block test_irq_send eth_driver epit_server readme.txt | bin
|
||||||
else
|
else
|
||||||
all: init test_fault simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
|
all: init test_fault simple_client simple_server shell fs_server test_irq_hdlr readme.txt | bin
|
||||||
endif
|
endif
|
||||||
|
@ -53,6 +53,10 @@ epit_server: timer.o epit.o ccm_pll.o usyscall.o arch_usyscall.o libserial.o pri
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
test_ipc_null: test_ipc_null.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
|
||||||
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
||||||
semaphore_server: semaphore_server.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
|
semaphore_server: semaphore_server.o libserial.o printf.o usyscall.o arch_usyscall.o libipc.o session.o
|
||||||
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
@${ld} ${user_ldflags} -e main -o $@ $^ ${board_specs}
|
||||||
@${objdump} -S $@ > $@.asm
|
@${objdump} -S $@ > $@.asm
|
||||||
|
|
|
@ -0,0 +1,85 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 AIIT XUOS Lab
|
||||||
|
* XiUOS is licensed under Mulan PSL v2.
|
||||||
|
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
* You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
* http://license.coscl.org.cn/MulanPSL2
|
||||||
|
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||||
|
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||||
|
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
*/
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "libipc.h"
|
||||||
|
#include "libserial.h"
|
||||||
|
#include "usyscall.h"
|
||||||
|
|
||||||
|
IPC_SERVICES(IpcTestNull, Ipc_test_null);
|
||||||
|
#define TEST_BUF_SIZE 32
|
||||||
|
|
||||||
|
static char test_null_server_name[] = "TestNullServer";
|
||||||
|
static char test_null_client_name[] = "TestNullClient";
|
||||||
|
|
||||||
|
// client side
|
||||||
|
static char buf[TEST_BUF_SIZE];
|
||||||
|
|
||||||
|
IPC_INTERFACE(Ipc_test_null, 1, ptr, sizeof(buf));
|
||||||
|
int test_null(struct Session* session, char* ptr)
|
||||||
|
{
|
||||||
|
return IPC_CALL(Ipc_test_null)(session, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// client thread
|
||||||
|
int server_thread(int argc, char** argv);
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
struct Session session;
|
||||||
|
bool server_enabled = false;
|
||||||
|
while (connect_session(&session, test_null_server_name, 4096) < 0) {
|
||||||
|
if (!server_enabled) {
|
||||||
|
char* server_param[] = { test_null_server_name, NULL };
|
||||||
|
if (thread(server_thread, test_null_server_name, server_param) >= 0) {
|
||||||
|
server_enabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("[%s] Call using NULL ptr.\n", test_null_client_name);
|
||||||
|
test_null(&session, NULL);
|
||||||
|
printf("[%s] Call using non-NULL ptr.\n", test_null_client_name);
|
||||||
|
test_null(&session, buf);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// server side
|
||||||
|
int IPC_DO_SERVE_FUNC(Ipc_test_null)(void* ptr)
|
||||||
|
{
|
||||||
|
if (ptr == NULL) {
|
||||||
|
printf("[%s]: A NULL ptr ipc call.\n", test_null_server_name);
|
||||||
|
} else {
|
||||||
|
printf("[%s]: A non-NULL ptr ipc call.\n", test_null_server_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
IPC_SERVER_INTERFACE(Ipc_test_null, 1);
|
||||||
|
IPC_SERVER_REGISTER_INTERFACES(IpcTestNull, 1, Ipc_test_null);
|
||||||
|
|
||||||
|
// server threads
|
||||||
|
int server_thread(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (register_server(test_null_server_name) < 0) {
|
||||||
|
printf("[%s] Register %s server failed.\n", test_null_server_name, test_null_server_name);
|
||||||
|
exit(1);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
ipc_server_loop(&IpcTestNull);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -83,11 +83,22 @@ bool ipc_msg_set_nth_arg(struct IpcMsg* msg, const int arg_num, const void* cons
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
struct IpcArgInfo* nth_arg_info = IPCMSG_ARG_INFO(msg, arg_num);
|
struct IpcArgInfo* nth_arg_info = IPCMSG_ARG_INFO(msg, arg_num);
|
||||||
if (len > nth_arg_info->len) {
|
if (len < 0 || (uint32_t)len > (uint32_t)nth_arg_info->len) {
|
||||||
printf("[%s] IPC: size of arg out of buffer range, given len: %d, len %u\n", __func__, len, nth_arg_info->len);
|
printf("[%s] IPC: size of arg out of buffer range, given len: %d, len %u\n", __func__, len, nth_arg_info->len);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* buf = ipc_msg_get_nth_arg_buf(msg, arg_num);
|
void* buf = ipc_msg_get_nth_arg_buf(msg, arg_num);
|
||||||
|
|
||||||
|
// handle attributes of different params
|
||||||
|
if (data == NULL) {
|
||||||
|
nth_arg_info->null_ptr = 1;
|
||||||
|
memset(buf, 0x0, len);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
nth_arg_info->null_ptr = 0;
|
||||||
|
}
|
||||||
|
|
||||||
memmove(buf, data, len);
|
memmove(buf, data, len);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -109,6 +120,12 @@ bool ipc_msg_get_nth_arg(struct IpcMsg* msg, const int arg_num, void* data, cons
|
||||||
printf("[%s] IPC: size of arg out of buffer range", __func__);
|
printf("[%s] IPC: size of arg out of buffer range", __func__);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle null ptr: do nothing
|
||||||
|
if (nth_arg_info->null_ptr == 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void* buf = ipc_msg_get_nth_arg_buf(msg, arg_num);
|
void* buf = ipc_msg_get_nth_arg_buf(msg, arg_num);
|
||||||
memmove(data, buf, len);
|
memmove(data, buf, len);
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -60,6 +60,13 @@ typedef struct {
|
||||||
struct IpcArgInfo {
|
struct IpcArgInfo {
|
||||||
uint16_t offset;
|
uint16_t offset;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
union {
|
||||||
|
uint16_t attr;
|
||||||
|
struct {
|
||||||
|
uint16_t null_ptr : 1;
|
||||||
|
uint16_t reserved : 15;
|
||||||
|
};
|
||||||
|
};
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
/* [header, ipc_arg_buffer_len[], ipc_arg_buffer[]] */
|
/* [header, ipc_arg_buffer_len[], ipc_arg_buffer[]] */
|
||||||
|
@ -104,6 +111,10 @@ struct IpcNode {
|
||||||
/// @return
|
/// @return
|
||||||
__attribute__((__always_inline__)) static inline void* ipc_msg_get_nth_arg_buf(struct IpcMsg* msg, int arg_num)
|
__attribute__((__always_inline__)) static inline void* ipc_msg_get_nth_arg_buf(struct IpcMsg* msg, int arg_num)
|
||||||
{
|
{
|
||||||
|
if (IPCMSG_ARG_INFO(msg, arg_num)->null_ptr == 1) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
return (void*)((char*)msg + IPCMSG_ARG_INFO(msg, arg_num)->offset);
|
return (void*)((char*)msg + IPCMSG_ARG_INFO(msg, arg_num)->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue