From a55f68f957e9f8ad74bd9e0c1b3d27775e0f8c75 Mon Sep 17 00:00:00 2001 From: teamol <28105285@qq.com> Date: Tue, 31 Aug 2021 13:35:09 +0800 Subject: [PATCH 1/3] fix: fix ppoll 1.modifications: modified: syscall/fs_syscall.c 2.modify 2 testcases: IO/full/IO_test_ppoll_001.cpp IO/full/IO_test_ppoll_002.cpp 3.influence: none Signed-off-by: pef Change-Id: I85fc091098a6dfef1a4694a3bbc489640ee6dda2 --- kernel/base/ipc/los_signal.c | 2 +- syscall/fs_syscall.c | 34 +-- testsuites/unittest/IO/BUILD.gn | 1 + testsuites/unittest/IO/It_test_IO.h | 3 +- .../unittest/IO/full/IO_test_ppoll_001.cpp | 218 ++++++------------ .../unittest/IO/full/IO_test_ppoll_002.cpp | 161 ++++++------- .../unittest/IO/full/IO_test_ppoll_003.cpp | 124 ++++++++++ testsuites/unittest/IO/io_test.cpp | 11 + 8 files changed, 292 insertions(+), 262 deletions(-) create mode 100755 testsuites/unittest/IO/full/IO_test_ppoll_003.cpp diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c index a4066845..497159eb 100644 --- a/kernel/base/ipc/los_signal.c +++ b/kernel/base/ipc/los_signal.c @@ -226,7 +226,7 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset) unsigned int intSave; sigset_t set; int retVal; - + if (setl != NULL) { retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t)); if (retVal != 0) { diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 3e7b921c..58365c55 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -2521,31 +2521,35 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons sigset_t_l origMask; sigset_t_l setl; - if (sigMask == NULL) { - ret = -EINVAL; - return ret; - } - CHECK_ASPACE(tmo_p, sizeof(struct timespec)); CHECK_ASPACE(sigMask, sizeof(sigset_t)); - CPY_FROM_USER(tmo_p); - CPY_FROM_USER(sigMask); + DUP_FROM_USER(tmo_p, sizeof(struct timespec)); + DUP_FROM_USER(sigMask, sizeof(sigset_t), FREE_DUP(tmo_p)); - timeout = (tmo_p == NULL) ? -1 : (tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS); - if (timeout & 0x80000000) { - ret = -EINVAL; - return ret; + if (tmo_p != NULL) { + timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS; + if (timeout & 0x80000000) { + ret = -EINVAL; + printf("ret[1] = %d\n", ret); + return ret; + } + } else { + timeout = -1; } - setl.sig[0] = *sigMask; - OsSigprocMask(SIG_SETMASK, &setl, &origMask); + + if (sigMask != NULL) { + memcpy(&setl.sig[0], sigMask, sizeof(sigset_t)); + } + + OsSigprocMask(SIG_SETMASK, sigMask?(&setl):NULL, &origMask); ret = SysPoll(fds, nfds, timeout); if (ret < 0) { ret = -get_errno(); } OsSigprocMask(SIG_SETMASK, &origMask, NULL); - PointerFree(tmo_pbak); - PointerFree(sigMaskbak); + FREE_DUP(tmo_p); + FREE_DUP(sigMask); return (ret == -1) ? -get_errno() : ret; } diff --git a/testsuites/unittest/IO/BUILD.gn b/testsuites/unittest/IO/BUILD.gn index 7eb948e4..fe03995a 100644 --- a/testsuites/unittest/IO/BUILD.gn +++ b/testsuites/unittest/IO/BUILD.gn @@ -85,6 +85,7 @@ sources_full = [ "full/IO_test_strncasecmp_l_002.cpp", "full/IO_test_ppoll_001.cpp", "full/IO_test_ppoll_002.cpp", + "full/IO_test_ppoll_003.cpp", "full/IO_test_pselect_001.cpp", "full/IO_test_pselect_002.cpp", ] diff --git a/testsuites/unittest/IO/It_test_IO.h b/testsuites/unittest/IO/It_test_IO.h index 5c763ca3..353010d3 100644 --- a/testsuites/unittest/IO/It_test_IO.h +++ b/testsuites/unittest/IO/It_test_IO.h @@ -127,13 +127,12 @@ extern VOID IO_TEST_DCNGETTEXT_002(VOID); extern VOID IO_TEST_DCGETTEXT_001(VOID); extern VOID IO_TEST_DCGETTEXT_002(VOID); extern VOID IO_TEST_GETTEXT_001(VOID); -extern VOID IO_TEST_PPOLL_001(void); -extern VOID IO_TEST_PPOLL_002(void); extern VOID IO_TEST_PSELECT_001(void); extern VOID IO_TEST_PSELECT_002(void); extern VOID IO_TEST_STRFMON_L_001(VOID); extern VOID IO_TEST_STRFMON_L_002(VOID); extern VOID IO_TEST_PPOLL_001(VOID); extern VOID IO_TEST_PPOLL_002(VOID); +extern VOID IO_TEST_PPOLL_003(VOID); #endif diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp index 66d6c06d..f0f86960 100644 --- a/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp +++ b/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp @@ -1,172 +1,90 @@ -/* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - #include "It_test_IO.h" -#include -#include "signal.h" #include "pthread.h" -#define LISTEN_FD_NUM 10 -#define POLL_EVENTS 1 +#define BUF_SIZE 128 +#define DELAY_TIME 200 -int pipeFdPpoll[LISTEN_FD_NUM][2]; -static pthread_t g_tid = -1; -extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigmask); +STATIC INT32 pipeFdPpoll[2]; +STATIC INT32 g_step = 1; +STATIC CHAR strBuf[] = "hello world."; +STATIC struct pollfd pfd; -static void *pthread_01(void) +STATIC VOID *pthread_01(VOID *arg) { - static int count = 0; - int total_num = 0; - int times = 3; - int i, ret; - struct pollfd fds[LISTEN_FD_NUM] = { 0 }; - char buffer[20]; - struct timespec t = { 3,0 }; - sigset_t sigset; - - /* TEST_PRINT("[INFO]%s:%d,%s,Create thread %d\n", __FILE__, __LINE__, __func__, count); */ - count++; - - sigemptyset(&sigset); - sigaddset(&sigset, SIGALRM); /* 把SIGALRM 信号添加到sigset 信号集中 */ - sigaddset(&sigset, SIGUSR1); - - for (i = 0; i < LISTEN_FD_NUM; i++) { - fds[i].fd = pipeFdPpoll[i][0]; - fds[i].events = POLL_EVENTS; + INT32 retVal; + CHAR buf[BUF_SIZE]; + const struct timespec timeout = {1000, 0}; + + /* 执行ppoll监视文件描述符*/ + while(g_step < 3) { + usleep(DELAY_TIME); } - - while (times--) { - ret = ppoll(fds, LISTEN_FD_NUM, &t, &sigset); - total_num += ((ret > 0) ? ret : 0); - - if (ret <= 0) { - continue; - } - - for (i = 0; i < LISTEN_FD_NUM; i++) { - if (fds[i].revents & POLL_EVENTS) { - ret = read(fds[i].fd, buffer, 12); - ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); - ret = strcmp(buffer, "hello world"); - TEST_PRINT("[EVENT]%s:%d,%s,buffer=%s\n", __FILE__, __LINE__, __func__, buffer); - } - } - - if (total_num == LISTEN_FD_NUM) { - break; - } + g_step++; + retVal = ppoll(&pfd, 1, NULL, NULL); + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); + + while(g_step < 5) { + usleep(DELAY_TIME); } + g_step++; + + /* 判断revents*/ + if (pfd.revents & POLLIN) { + memset(buf, 0, sizeof(buf)); + retVal = read(pfd.fd, buf, BUF_SIZE); + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); - /* ICUNIT_GOTO_EQUAL(total_num, 10, -1, EXIT); */ - /* TEST_PRINT("[INFO]%s:%d,%s,total_num=%d\n", __FILE__, __LINE__, __func__, total_num); */ -EXIT: - return nullptr; + retVal = strcmp(strBuf, buf); + ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal); + } + + while(g_step < 6) { + usleep(DELAY_TIME); + } + pthread_exit(NULL); } -static UINT32 testcase1(VOID) +STATIC UINT32 testcase(VOID) { - int i; - int ret; - int count = 0; - - for (i = 0; i < LISTEN_FD_NUM; i++) { - ret = pipe(pipeFdPpoll[i]); - ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][0]); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][0]=%d\n", __FILE__, __LINE__, __func__, ret, i, pipeFdPpoll[i][1]); + INT32 retVal; + pthread_t tid; + + /* 建立管道*/ + while(g_step < 1) { + usleep(DELAY_TIME); } - - errno = 0; - ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno)); - ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); - - errno = 0; - for (i = 0; i < LISTEN_FD_NUM; i++) { - if ((pipeFdPpoll[i][1] != 9) && (pipeFdPpoll[i][1] != 10) && (pipeFdPpoll[i][1] != 11)) { - ret = write(pipeFdPpoll[i][1], "hello world!", 12); /* 12, "hello world" length and '\0' */ - } - ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno)); + retVal = pipe(pipeFdPpoll); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + g_step++; + + /* 设置pfd*/ + pfd.fd = pipeFdPpoll[0]; + pfd.events = POLLIN; + + /* 开辟线程执行 ppoll*/ + while(g_step < 2) { + usleep(DELAY_TIME); } - -#if 1 /* write looply */ - while(1) { - if (count++ > 3) { - break; - } - sleep(1); - for (i = 0; i < LISTEN_FD_NUM; i++) { - errno = 0; - ret = pthread_create(&g_tid, nullptr, (void *(*)(void *))pthread_01, nullptr); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno)); - ICUNIT_GOTO_EQUAL(ret, 0, ret, EXIT); - - if ((pipeFdPpoll[i][1] == 13) || (pipeFdPpoll[i][1] == 14) || (pipeFdPpoll[i][1] == 15)) { - errno = 0; - ret = write(pipeFdPpoll[i][1], "World HELLO!", 12); /* 12, "hello world" length and '\0' */ - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,errno=%d,errstr=%s\n", __FILE__, __LINE__, __func__, ret, errno, strerror(errno)); - TEST_PRINT("[INFO]%s:%d,%s,ret=%d,pipeFdPpoll[%d][1]=%d,count=%d\n", __FILE__, __LINE__, __func__, ret,i, pipeFdPpoll[i][1], count); - } - /* ICUNIT_GOTO_EQUAL(ret, 12, ret, EXIT); */ - } + retVal = pthread_create(&tid, NULL, pthread_01, NULL); + ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); + g_step++; + + /* 向管道写入数据*/ + while(g_step < 4) { + usleep(DELAY_TIME); } -#endif - - pthread_join(g_tid, nullptr); - - for (i = 0; i < LISTEN_FD_NUM; i++) { - close(pipeFdPpoll[i][0]); - close(pipeFdPpoll[i][1]); - } - - return LOS_OK; - -EXIT: - for (i = 0; i < LISTEN_FD_NUM; i++) { - close(pipeFdPpoll[i][0]); - close(pipeFdPpoll[i][1]); - } - return LOS_NOK; -} - -static UINT32 testcase(VOID) -{ - testcase1(); + sleep(1); + + retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + g_step++; + pthread_join(tid, NULL); + return LOS_OK; } VOID IO_TEST_PPOLL_001(VOID) { TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION); -} +} \ No newline at end of file diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp index ae52d927..b93a7bc3 100644 --- a/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp +++ b/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp @@ -1,112 +1,85 @@ -/* - * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. - * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * 3. Neither the name of the copyright holder nor the names of its contributors may be used - * to endorse or promote products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, - * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - #include "It_test_IO.h" -#include "time.h" #include "signal.h" -#include -#include -#include -#include +#include "pthread.h" -#define BUF_LEN 20 -#define MAX_SCAN_FDSET 10 /* define poll's listened FD set's size */ -#define POLL_WAIT_TIMEOUT 10*1000 /* ms */ +#define BUF_SIZE 128 +#define DELAY_TIME 200 -extern int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *timeout, const sigset_t *sigmask); -void work_ppoll(int fd) +static int pipeFdPpoll[2]; +static int g_step = 1; +static char strBuf[] = "hello world."; +static struct pollfd pfd; + +static void *pthread_01(void *arg) { - int ret = 0; - int i = 0; - char recv_buf[BUF_LEN]; - sigset_t sigset; - struct timespec t; - struct pollfd scan_fdset[MAX_SCAN_FDSET]; - int scan_fdset_num = 10; - int count = 5; - - bzero(recv_buf, BUF_LEN); - sigemptyset(&sigset); - sigaddset(&sigset, SIGALRM); /* add SIGALRM to sigset */ - sigaddset(&sigset, SIGUSR1); /* add SIGUSR1 to sigset */ - bzero(&t, sizeof(struct timespec)); - t.tv_sec = 10; - t.tv_nsec = 0; - bzero(scan_fdset, sizeof(struct pollfd) * MAX_SCAN_FDSET); - scan_fdset[0].fd = fd; - - /* attention:in the book《UNIX网络编程第一卷》P162 metions:POLLERR,POLLHUP,POLLNVAL\ - those error signals can not be set in events. */ - /* they will return in revents,while the proper condition happens. */ - scan_fdset[0].events = POLLOUT; /* set the signal needed to be listened:POLLOUT/POLLIN */ - - /* set other elements in the array as invalid. */ - for (i = 1; i < MAX_SCAN_FDSET; i++) { - /* scan_fdset[i].fd = -1; */ - scan_fdset[i].fd = fd; - scan_fdset[i].events = POLLOUT; /* set the signal needed to be listened. */ + int retVal; + char buf[BUF_SIZE]; + const struct timespec timeout = {10000, 0}; + + /* 执行ppoll监视文件描述符 */ + while(g_step < 4) { + usleep(DELAY_TIME); } - /* scan_fdset_num = 1; */ /* 表示当前的scan_fdset[] 数组中只使用前面1 个元素存放需要监听的扫描符 */ - - while (count--) { - ret = ppoll(scan_fdset, scan_fdset_num, &t, &sigset); - - for (i = 0; i < MAX_SCAN_FDSET; i++) { - if (scan_fdset[i].revents & POLLOUT) { - TEST_PRINT("[INFO]%s:%d,%s,fd have signal!\n", __FILE__, __LINE__, __func__); - ret = read(fd, recv_buf, BUF_LEN); - if (-1 == ret) { - TEST_PRINT("[INFO]%s:%d,%s,read error!\n", __FILE__, __LINE__, __func__); - continue; - } - TEST_PRINT("[INFO]%s:%d,%s,recv_buf=%s\n", __FILE__, __LINE__, __func__, recv_buf); - } - TEST_PRINT("[INFO]%s:%d,%s,scan_fdset[i].revents=%d\n", __FILE__, __LINE__, __func__, scan_fdset[i].revents); - } + g_step++; + retVal = ppoll(&pfd, 1, &timeout, NULL); + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); + + /* 判断revents */ + if (pfd.revents & POLLIN) { + memset(buf, 0, sizeof(buf)); + retVal = read(pfd.fd, buf, BUF_SIZE); + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); + retVal = strcmp(strBuf, buf); + ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal); } + + while(g_step < 5) { + usleep(DELAY_TIME); + } + pthread_exit(NULL); } static UINT32 testcase(VOID) { - int fd; - char *filename = FILEPATH_775; + int retVal; + pthread_t tid; + + /* 建立管道 */ + while(g_step < 1) { + usleep(DELAY_TIME); + } + retVal = pipe(pipeFdPpoll); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + g_step++; + + /* 设置pfd */ + pfd.fd = pipeFdPpoll[0]; + pfd.events = POLLIN; + + /* 向管道写入数据 */ + while(g_step < 2) { + usleep(DELAY_TIME); + } + sleep(1); + + retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + g_step++; - fd = open(filename, O_RDWR); - TEST_PRINT("[INFO]%s:%d,%s,fd=%d\n", __FILE__, __LINE__, __func__, fd); - work_ppoll(fd); + /* 开辟线程执行 ppoll */ + while(g_step < 3) { + usleep(DELAY_TIME); + } + retVal = pthread_create(&tid, NULL, pthread_01, NULL); + ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); + g_step++; - return LOS_OK; + pthread_join(tid, NULL); + + return LOS_OK; } VOID IO_TEST_PPOLL_002(VOID) { TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION); -} +} \ No newline at end of file diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp new file mode 100755 index 00000000..bebf0716 --- /dev/null +++ b/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp @@ -0,0 +1,124 @@ +#include "It_test_IO.h" +#include "pthread.h" +#include "signal.h" + +#define BUF_SIZE 128 +#define DELAY_TIME 200 + +STATIC INT32 pipeFdPpoll[2]; +STATIC INT32 g_step = 1; +STATIC CHAR strBuf[] = "hello world."; +STATIC struct pollfd pfd; +sigset_t sigMask; +STATIC UINT32 count = 0; + +STATIC VOID signalHandle(INT32 sigNum) +{ + //printf("Capture %d\n", sigNum); + g_step++; + + return; +} + +STATIC VOID *pthread_01(VOID *arg) +{ + INT32 retVal; + CHAR buf[BUF_SIZE]; + + signal(SIGUSR1, signalHandle); + + while (1) { + /*执行ppoll监视文件描述符*/ + while (g_step < 2) { + usleep(DELAY_TIME); + } + g_step++; + retVal = ppoll(&pfd, 1, NULL, &sigMask); + + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); + + /*判断revents*/ + if (pfd.revents & POLLIN) { + memset(buf, 0, sizeof(buf)); + retVal = read(pfd.fd, buf, BUF_SIZE); + ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); + + retVal = strcmp(strBuf, buf); + ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal); + + count++; + } else { + ICUNIT_ASSERT_NOT_EQUAL_NULL(pfd.revents & POLLIN, 0, pfd.revents & POLLIN); + } + g_step++; + + if (g_step >= 7) { + ICUNIT_ASSERT_EQUAL_NULL(count, 2, count); + pthread_exit(NULL); + } + + } + + return LOS_OK; +} + +STATIC UINT32 testcase(VOID) +{ + INT32 retVal; + pthread_t tid; + + /*建立管道*/ + while (g_step < 1) { + usleep(DELAY_TIME); + } + retVal = pipe(pipeFdPpoll); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + + /*设置pfd sigmask*/ + pfd.fd = pipeFdPpoll[0]; + pfd.events = POLLIN; + pfd.revents = 0x0; + + sigemptyset(&sigMask); + sigaddset(&sigMask, SIGUSR1); + + /*开辟线程执行 ppoll*/ + retVal = pthread_create(&tid, NULL, pthread_01, NULL); + ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); + g_step++; + + /*向管道写入数据*/ + while (g_step < 3) { + usleep(DELAY_TIME); + } + sleep(1); /*保证先挂起再写入数据*/ + retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + + /*向线程发送信号*/ + while (g_step < 5) { + usleep(DELAY_TIME); + } + sleep(1); /*保证先挂起再发送信号*/ + retVal = pthread_kill(tid, SIGUSR1); + ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); + + /*继续向管道写入数据*/ + ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /*判断挂起解除之前信号没有被处理*/ + retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); + ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); + + while (g_step < 7) { + usleep(DELAY_TIME); + } + ICUNIT_ASSERT_EQUAL(count, 2, count); + /*等待退出*/ + pthread_join(tid, NULL); + + return LOS_OK; +} + +VOID IO_TEST_PPOLL_003(VOID) +{ + TEST_ADD_CASE(__FUNCTION__, testcase, TEST_LIB, TEST_LIBC, TEST_LEVEL1, TEST_FUNCTION); +} \ No newline at end of file diff --git a/testsuites/unittest/IO/io_test.cpp b/testsuites/unittest/IO/io_test.cpp index 5b8f668d..cda69475 100644 --- a/testsuites/unittest/IO/io_test.cpp +++ b/testsuites/unittest/IO/io_test.cpp @@ -137,6 +137,17 @@ HWTEST_F(IoTest, IO_TEST_PPOLL_002, TestSize.Level0) IO_TEST_PPOLL_002(); } +/* * + * @tc.name: IO_TEST_PPOLL_003 + * @tc.desc: function for IoTest + * @tc.type: FUNC + * @tc.require: AR000EEMQ9 + */ +HWTEST_F(IoTest, IO_TEST_PPOLL_003, TestSize.Level0) +{ + IO_TEST_PPOLL_003(); +} + /* * * @tc.name: IT_STDLIB_POLL_002 * @tc.desc: function for IoTest From 78a297fd4ecea708e73348f9b23c7e02aaac07e6 Mon Sep 17 00:00:00 2001 From: pef Date: Thu, 28 Oct 2021 11:47:10 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dppoll=E6=8E=A5=E5=8F=A3"[?= =?UTF-8?q?ERR]OsMemFree=20check=20error!"=E6=8A=A5=E9=94=99=20=E3=80=90?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=80=91=20=E5=86=85=E6=A0=B8=E4=B8=AD?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E7=94=A8=E6=88=B7=E7=A9=BA=E9=97=B4=E6=8C=87?= =?UTF-8?q?=E9=92=88=E6=8A=A5=E9=94=99:"[ERR]OsMemFree=20check=20error!"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【修改方案】 修改SysPpoll函数。 【影响】 对现有的产品编译不会有影响。 re #I47YWZ Change-Id: Id7f86036870d4f32be8fc438b9aad85cdda59546 Signed-off-by: pef --- kernel/base/ipc/los_signal.c | 6 +- syscall/fs_syscall.c | 29 +++-- syscall/syscall_pub.h | 2 +- .../unittest/IO/full/IO_test_ppoll_001.cpp | 74 ++++++++---- .../unittest/IO/full/IO_test_ppoll_002.cpp | 49 ++++++-- .../unittest/IO/full/IO_test_ppoll_003.cpp | 114 +++++++++++------- 6 files changed, 183 insertions(+), 91 deletions(-) diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c index 497159eb..16e9d7c0 100644 --- a/kernel/base/ipc/los_signal.c +++ b/kernel/base/ipc/los_signal.c @@ -226,9 +226,9 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset) unsigned int intSave; sigset_t set; int retVal; - + if (setl != NULL) { - retVal = LOS_ArchCopyFromUser(&set, &(setl->sig[0]), sizeof(sigset_t)); + retVal = LOS_CopyToKernel(&set, sizeof(sigset_t), &(setl->sig[0]), sizeof(sigset_t)); if (retVal != 0) { return -EFAULT; } @@ -268,7 +268,7 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset) SCHEDULER_UNLOCK(intSave); if (oldset != NULL) { - retVal = LOS_ArchCopyToUser(&(oldset->sig[0]), &oldSigprocmask, sizeof(sigset_t)); + retVal = LOS_CopyFromKernel(&(oldset->sig[0]), sizeof(sigset_t), &oldSigprocmask, sizeof(sigset_t)); if (retVal != 0) { return -EFAULT; } diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index 58365c55..ae2e05af 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -2518,39 +2518,42 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons { int timeout; int ret; + int retVal; sigset_t_l origMask; sigset_t_l setl; CHECK_ASPACE(tmo_p, sizeof(struct timespec)); CHECK_ASPACE(sigMask, sizeof(sigset_t)); - DUP_FROM_USER(tmo_p, sizeof(struct timespec)); - DUP_FROM_USER(sigMask, sizeof(sigset_t), FREE_DUP(tmo_p)); + CPY_FROM_USER(tmo_p); + CPY_FROM_USER(sigMask); if (tmo_p != NULL) { timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS; - if (timeout & 0x80000000) { - ret = -EINVAL; - printf("ret[1] = %d\n", ret); - return ret; + if (timeout < 0) { + return -EINVAL; } } else { timeout = -1; } if (sigMask != NULL) { - memcpy(&setl.sig[0], sigMask, sizeof(sigset_t)); + memcpy_s(&setl.sig[0], sizeof(sigset_t), sigMask, sizeof(sigset_t)); } - OsSigprocMask(SIG_SETMASK, sigMask?(&setl):NULL, &origMask); + ret = OsSigprocMask(SIG_SETMASK, sigMask ? &setl : NULL, &origMask); + if (ret != 0) { + return -EINVAL; + } ret = SysPoll(fds, nfds, timeout); if (ret < 0) { - ret = -get_errno(); + retVal = -get_errno(); + } + ret = OsSigprocMask(SIG_SETMASK, &origMask, NULL); + if (ret != 0) { + return -EINVAL; } - OsSigprocMask(SIG_SETMASK, &origMask, NULL); - FREE_DUP(tmo_p); - FREE_DUP(sigMask); - return (ret == -1) ? -get_errno() : ret; + return retVal; } int SysPselect6(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, diff --git a/syscall/syscall_pub.h b/syscall/syscall_pub.h index e784a510..c1186621 100644 --- a/syscall/syscall_pub.h +++ b/syscall/syscall_pub.h @@ -110,7 +110,7 @@ Please deal with the "char *" by function:UserPathCopy. #define CPY_FROM_USER(ptr) \ __typeof(*ptr) ptr##cpy = {0}, *ptr##bak = ptr; \ if (ptr != NULL) { \ - if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr, sizeof(*ptr)) != 0) { \ + if (LOS_ArchCopyFromUser((void*)&ptr##cpy, ptr##bak, sizeof(*ptr##bak)) != 0) { \ set_errno(EFAULT); \ return -get_errno(); \ } \ diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp index f0f86960..e80b1858 100644 --- a/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp +++ b/testsuites/unittest/IO/full/IO_test_ppoll_001.cpp @@ -1,36 +1,66 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "It_test_IO.h" #include "pthread.h" -#define BUF_SIZE 128 -#define DELAY_TIME 200 +const int BUF_SIZE = 128; +const int DELAY_TIME = 200; -STATIC INT32 pipeFdPpoll[2]; -STATIC INT32 g_step = 1; -STATIC CHAR strBuf[] = "hello world."; -STATIC struct pollfd pfd; +static INT32 pipeFdPpoll[2]; +static INT32 g_step = 1; +static CHAR strBuf[] = "hello world."; +static struct pollfd pfd; -STATIC VOID *pthread_01(VOID *arg) +static void *pthread_01(void *arg) { INT32 retVal; CHAR buf[BUF_SIZE]; - const struct timespec timeout = {1000, 0}; - /* 执行ppoll监视文件描述符*/ - while(g_step < 3) { + /* 执行ppoll监视文件描述符 */ + while (g_step < 3) { /* 3, 3rd step */ usleep(DELAY_TIME); } g_step++; retVal = ppoll(&pfd, 1, NULL, NULL); ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); - while(g_step < 5) { + while (g_step < 5) { /* 5, 5th step */ usleep(DELAY_TIME); } g_step++; - /* 判断revents*/ + /* 判断revents */ if (pfd.revents & POLLIN) { - memset(buf, 0, sizeof(buf)); + memset_s(buf, sizeof(buf), 0, sizeof(buf)); retVal = read(pfd.fd, buf, BUF_SIZE); ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); @@ -38,7 +68,7 @@ STATIC VOID *pthread_01(VOID *arg) ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal); } - while(g_step < 6) { + while (g_step < 6) { /* 6, 6th step */ usleep(DELAY_TIME); } pthread_exit(NULL); @@ -49,28 +79,28 @@ STATIC UINT32 testcase(VOID) INT32 retVal; pthread_t tid; - /* 建立管道*/ - while(g_step < 1) { + /* 建立管道 */ + while (g_step < 1) { /* 1, 1st step */ usleep(DELAY_TIME); } retVal = pipe(pipeFdPpoll); ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); g_step++; - /* 设置pfd*/ - pfd.fd = pipeFdPpoll[0]; + /* 设置pfd */ + pfd.fd = pipeFdPpoll[0]; pfd.events = POLLIN; - /* 开辟线程执行 ppoll*/ - while(g_step < 2) { + /* 开辟线程执行 ppoll */ + while (g_step < 2) { /* 2, 2nd step */ usleep(DELAY_TIME); } retVal = pthread_create(&tid, NULL, pthread_01, NULL); ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); g_step++; - /* 向管道写入数据*/ - while(g_step < 4) { + /* 向管道写入数据 */ + while (g_step < 4) { /* 4, 4th step */ usleep(DELAY_TIME); } sleep(1); diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp index b93a7bc3..9f121a79 100644 --- a/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp +++ b/testsuites/unittest/IO/full/IO_test_ppoll_002.cpp @@ -1,9 +1,40 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "It_test_IO.h" #include "signal.h" #include "pthread.h" -#define BUF_SIZE 128 -#define DELAY_TIME 200 +const int BUF_SIZE = 128; +const int DELAY_TIME = 200; static int pipeFdPpoll[2]; static int g_step = 1; @@ -17,7 +48,7 @@ static void *pthread_01(void *arg) const struct timespec timeout = {10000, 0}; /* 执行ppoll监视文件描述符 */ - while(g_step < 4) { + while (g_step < 4) { /* 4, 4th step */ usleep(DELAY_TIME); } g_step++; @@ -26,14 +57,14 @@ static void *pthread_01(void *arg) /* 判断revents */ if (pfd.revents & POLLIN) { - memset(buf, 0, sizeof(buf)); + memset_s(buf, sizeof(buf), 0, sizeof(buf)); retVal = read(pfd.fd, buf, BUF_SIZE); ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); retVal = strcmp(strBuf, buf); ICUNIT_ASSERT_EQUAL_NULL(retVal, 0, retVal); } - while(g_step < 5) { + while (g_step < 5) { /* 5, 5th step */ usleep(DELAY_TIME); } pthread_exit(NULL); @@ -45,7 +76,7 @@ static UINT32 testcase(VOID) pthread_t tid; /* 建立管道 */ - while(g_step < 1) { + while (g_step < 1) { usleep(DELAY_TIME); } retVal = pipe(pipeFdPpoll); @@ -57,7 +88,7 @@ static UINT32 testcase(VOID) pfd.events = POLLIN; /* 向管道写入数据 */ - while(g_step < 2) { + while (g_step < 2) { /* 2, 2nd step */ usleep(DELAY_TIME); } sleep(1); @@ -67,7 +98,7 @@ static UINT32 testcase(VOID) g_step++; /* 开辟线程执行 ppoll */ - while(g_step < 3) { + while (g_step < 3) { /* 3, 3rd step */ usleep(DELAY_TIME); } retVal = pthread_create(&tid, NULL, pthread_01, NULL); @@ -76,7 +107,7 @@ static UINT32 testcase(VOID) pthread_join(tid, NULL); - return LOS_OK; + return LOS_OK; } VOID IO_TEST_PPOLL_002(VOID) diff --git a/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp b/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp index bebf0716..ea0852f4 100755 --- a/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp +++ b/testsuites/unittest/IO/full/IO_test_ppoll_003.cpp @@ -1,35 +1,64 @@ +/* + * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved. + * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * 3. Neither the name of the copyright holder nor the names of its contributors may be used + * to endorse or promote products derived from this software without specific prior written + * permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + #include "It_test_IO.h" #include "pthread.h" #include "signal.h" -#define BUF_SIZE 128 -#define DELAY_TIME 200 +const int BUF_SIZE = 128; +const int DELAY_TIME = 200; -STATIC INT32 pipeFdPpoll[2]; -STATIC INT32 g_step = 1; -STATIC CHAR strBuf[] = "hello world."; -STATIC struct pollfd pfd; -sigset_t sigMask; -STATIC UINT32 count = 0; +static INT32 pipeFdPpoll[2]; +static INT32 g_step = 1; +static CHAR strBuf[] = "hello world."; +static struct pollfd pfd; +static sigset_t sigMask; +static UINT32 count = 0; -STATIC VOID signalHandle(INT32 sigNum) +static void signalHandle(INT32 sigNum) { - //printf("Capture %d\n", sigNum); g_step++; - return; } -STATIC VOID *pthread_01(VOID *arg) +static void *pthread_01(void *arg) { INT32 retVal; CHAR buf[BUF_SIZE]; - signal(SIGUSR1, signalHandle); - + (void)signal(SIGUSR1, signalHandle); + while (1) { - /*执行ppoll监视文件描述符*/ - while (g_step < 2) { + /* 执行ppoll监视文件描述符 */ + while (g_step < 2) { /* 2, 2nd step */ usleep(DELAY_TIME); } g_step++; @@ -37,9 +66,9 @@ STATIC VOID *pthread_01(VOID *arg) ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); - /*判断revents*/ + /* 判断revents */ if (pfd.revents & POLLIN) { - memset(buf, 0, sizeof(buf)); + memset_s(buf, sizeof(buf), 0, sizeof(buf)); retVal = read(pfd.fd, buf, BUF_SIZE); ICUNIT_ASSERT_NOT_EQUAL_NULL(retVal, -1, retVal); @@ -50,72 +79,71 @@ STATIC VOID *pthread_01(VOID *arg) } else { ICUNIT_ASSERT_NOT_EQUAL_NULL(pfd.revents & POLLIN, 0, pfd.revents & POLLIN); } - g_step++; + g_step++; - if (g_step >= 7) { - ICUNIT_ASSERT_EQUAL_NULL(count, 2, count); + if (g_step >= 7) { /* 7, 7th step */ + ICUNIT_ASSERT_EQUAL_NULL(count, 2, count); /* 2, 2nd step */ pthread_exit(NULL); } - } return LOS_OK; } -STATIC UINT32 testcase(VOID) +static UINT32 testcase(VOID) { INT32 retVal; pthread_t tid; - - /*建立管道*/ + + /* 建立管道 */ while (g_step < 1) { usleep(DELAY_TIME); } retVal = pipe(pipeFdPpoll); ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); - /*设置pfd sigmask*/ - pfd.fd = pipeFdPpoll[0]; + /* 设置pfd sigmask */ + pfd.fd = pipeFdPpoll[0]; pfd.events = POLLIN; pfd.revents = 0x0; sigemptyset(&sigMask); sigaddset(&sigMask, SIGUSR1); - - /*开辟线程执行 ppoll*/ + + /* 开辟线程执行 ppoll */ retVal = pthread_create(&tid, NULL, pthread_01, NULL); ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); g_step++; - - /*向管道写入数据*/ - while (g_step < 3) { + + /* 向管道写入数据 */ + while (g_step < 3) { /* 3, 3ed step */ usleep(DELAY_TIME); } - sleep(1); /*保证先挂起再写入数据*/ + sleep(1); /* 保证先挂起再写入数据 */ retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); - /*向线程发送信号*/ - while (g_step < 5) { + /* 向线程发送信号 */ + while (g_step < 5) { /* 5, 5th step */ usleep(DELAY_TIME); } - sleep(1); /*保证先挂起再发送信号*/ + sleep(1); /* 保证先挂起再发送信号 */ retVal = pthread_kill(tid, SIGUSR1); ICUNIT_ASSERT_EQUAL(retVal, 0, retVal); - /*继续向管道写入数据*/ - ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /*判断挂起解除之前信号没有被处理*/ + /* 继续向管道写入数据 */ + ICUNIT_ASSERT_EQUAL(g_step, 5, g_step); /* 5, sth。判断挂起解除之前信号没有被处理 */ retVal = write(pipeFdPpoll[1], "hello world.", sizeof(strBuf)); ICUNIT_ASSERT_NOT_EQUAL(retVal, -1, retVal); - while (g_step < 7) { + while (g_step < 7) { /* 7, 7th step */ usleep(DELAY_TIME); } - ICUNIT_ASSERT_EQUAL(count, 2, count); - /*等待退出*/ + ICUNIT_ASSERT_EQUAL(count, 2, count); /* 2, 2nd step */ + /* 等待退出 */ pthread_join(tid, NULL); - - return LOS_OK; + + return LOS_OK; } VOID IO_TEST_PPOLL_003(VOID) From 2e3bbf1e61c2e52be1f60145523af9ca8e646e03 Mon Sep 17 00:00:00 2001 From: lnlan Date: Sat, 30 Oct 2021 02:37:42 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dppoll=E6=8E=A5=E5=8F=A3"[?= =?UTF-8?q?ERR]OsMemFree=20check=20error!"=E6=8A=A5=E9=94=99=20=E3=80=90?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E3=80=91=201.=E5=86=85=E6=A0=B8=E4=B8=AD?= =?UTF-8?q?=E9=87=8A=E6=94=BE=E7=94=A8=E6=88=B7=E7=A9=BA=E9=97=B4=E6=8C=87?= =?UTF-8?q?=E9=92=88=E6=8A=A5=E9=94=99:"[ERR]OsMemFree=20check=20error!"?= =?UTF-8?q?=202.=E7=8E=B0=E6=9C=89ppoll=E5=AE=9E=E7=8E=B0=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E9=97=AE=E9=A2=98=203.=E7=9B=B8=E5=85=B3=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E9=9C=80=E8=A6=81=E6=95=B4=E7=90=86=20=E3=80=90?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=96=B9=E6=A1=88=E3=80=91=201.=E5=8E=BB?= =?UTF-8?q?=E6=8E=89=E9=87=8A=E6=94=BE=E7=94=A8=E6=88=B7=E7=A9=BA=E9=97=B4?= =?UTF-8?q?=E6=8C=87=E9=92=88=E6=93=8D=E4=BD=9C=202.=E6=9B=B4=E6=AD=A3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=94=99=E8=AF=AF=203.=E6=9B=B4=E6=AD=A3?= =?UTF-8?q?=E6=8E=A9=E7=A0=81=E8=AE=BE=E7=BD=AE=E4=B8=8E=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=B8=8D=E8=B5=B7=E4=BD=9C=E7=94=A8=204.=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=A1=A5=E5=85=85=E7=8E=B0=E6=9C=89=E7=94=A8=E4=BE=8B=20?= =?UTF-8?q?=E3=80=90=E5=BD=B1=E5=93=8D=E3=80=91=20=E5=AF=B9=E7=8E=B0?= =?UTF-8?q?=E6=9C=89=E7=9A=84=E4=BA=A7=E5=93=81=E7=BC=96=E8=AF=91=E4=B8=8D?= =?UTF-8?q?=E4=BC=9A=E6=9C=89=E5=BD=B1=E5=93=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit re #I47YWZ Change-Id: Ib2f60986e9cafb2ea5ef1097ab8552cbb1ede5b4 Signed-off-by: lnlan --- kernel/base/ipc/los_signal.c | 22 +++++----------------- syscall/fs_syscall.c | 36 ++++++++++++++---------------------- syscall/ipc_syscall.c | 12 ++++++++++-- 3 files changed, 29 insertions(+), 41 deletions(-) diff --git a/kernel/base/ipc/los_signal.c b/kernel/base/ipc/los_signal.c index 16e9d7c0..465db123 100644 --- a/kernel/base/ipc/los_signal.c +++ b/kernel/base/ipc/los_signal.c @@ -218,28 +218,22 @@ void OsSigMaskSwitch(LosTaskCB * const rtcb, sigset_t set) } } -int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset) +int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldsetl) { LosTaskCB *spcb = NULL; - sigset_t oldSigprocmask; int ret = LOS_OK; unsigned int intSave; sigset_t set; - int retVal; - if (setl != NULL) { - retVal = LOS_CopyToKernel(&set, sizeof(sigset_t), &(setl->sig[0]), sizeof(sigset_t)); - if (retVal != 0) { - return -EFAULT; - } - } SCHEDULER_LOCK(intSave); spcb = OsCurrTaskGet(); /* If requested, copy the old mask to user. */ - oldSigprocmask = spcb->sig.sigprocmask; - + if (oldsetl != NULL) { + *(sigset_t *)oldsetl = spcb->sig.sigprocmask; + } /* If requested, modify the current signal mask. */ if (setl != NULL) { + set = *(sigset_t *)setl; /* Okay, determine what we are supposed to do */ switch (how) { /* Set the union of the current set and the signal @@ -267,12 +261,6 @@ int OsSigprocMask(int how, const sigset_t_l *setl, sigset_t_l *oldset) } SCHEDULER_UNLOCK(intSave); - if (oldset != NULL) { - retVal = LOS_CopyFromKernel(&(oldset->sig[0]), sizeof(sigset_t), &oldSigprocmask, sizeof(sigset_t)); - if (retVal != 0) { - return -EFAULT; - } - } return ret; } diff --git a/syscall/fs_syscall.c b/syscall/fs_syscall.c index ae2e05af..f3e10416 100644 --- a/syscall/fs_syscall.c +++ b/syscall/fs_syscall.c @@ -2516,16 +2516,12 @@ int SysFstatfs64(int fd, size_t sz, struct statfs *buf) int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, const sigset_t *sigMask, int nsig) { - int timeout; - int ret; - int retVal; - sigset_t_l origMask; - sigset_t_l setl; + int timeout, retVal; + sigset_t_l origMask = {0}; + sigset_t_l set = {0}; CHECK_ASPACE(tmo_p, sizeof(struct timespec)); - CHECK_ASPACE(sigMask, sizeof(sigset_t)); CPY_FROM_USER(tmo_p); - CPY_FROM_USER(sigMask); if (tmo_p != NULL) { timeout = tmo_p->tv_sec * OS_SYS_US_PER_MS + tmo_p->tv_nsec / OS_SYS_NS_PER_MS; @@ -2535,24 +2531,20 @@ int SysPpoll(struct pollfd *fds, nfds_t nfds, const struct timespec *tmo_p, cons } else { timeout = -1; } - + if (sigMask != NULL) { - memcpy_s(&setl.sig[0], sizeof(sigset_t), sigMask, sizeof(sigset_t)); - } - - ret = OsSigprocMask(SIG_SETMASK, sigMask ? &setl : NULL, &origMask); - if (ret != 0) { - return -EINVAL; - } - ret = SysPoll(fds, nfds, timeout); - if (ret < 0) { - retVal = -get_errno(); - } - ret = OsSigprocMask(SIG_SETMASK, &origMask, NULL); - if (ret != 0) { - return -EINVAL; + retVal = LOS_ArchCopyFromUser(&set, sigMask, sizeof(sigset_t)); + if (retVal != 0) { + return -EFAULT; + } + (VOID)OsSigprocMask(SIG_SETMASK, &set, &origMask); + } else { + (VOID)OsSigprocMask(SIG_SETMASK, NULL, &origMask); } + retVal = SysPoll(fds, nfds, timeout); + (VOID)OsSigprocMask(SIG_SETMASK, &origMask, NULL); + return retVal; } diff --git a/syscall/ipc_syscall.c b/syscall/ipc_syscall.c index 628a966c..83ebac4b 100644 --- a/syscall/ipc_syscall.c +++ b/syscall/ipc_syscall.c @@ -29,6 +29,7 @@ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "syscall_pub.h" #include "mqueue.h" #include #include @@ -36,6 +37,7 @@ #include "time_posix.h" #include "user_copy.h" #include "los_signal.h" +#include "los_process_pri.h" #include "los_strncpy_from_user.h" #include "fs/file.h" @@ -229,8 +231,14 @@ int SysSigAction(int sig, const sigaction_t *restrict sa, sigaction_t *restrict int SysSigprocMask(int how, const sigset_t_l *restrict setl, sigset_t_l *restrict oldl, size_t sigsetsize) { - /* Let nxsig_procmask do all of the work */ - return OsSigprocMask(how, setl, oldl); + CHECK_ASPACE(setl, sizeof(sigset_t_l)); + CHECK_ASPACE(oldl, sizeof(sigset_t_l)); + CPY_FROM_USER(setl); + CPY_FROM_USER(oldl); + /* Let OsSigprocMask do all of the work */ + int ret = OsSigprocMask(how, setl, oldl); + CPY_TO_USER(oldl); + return ret; } int SysKill(pid_t pid, int sig)