提交 78a297fd 编写于 作者: 悟空又丢了's avatar 悟空又丢了

修复ppoll接口"[ERR]OsMemFree check error!"报错

【背景】
内核中释放用户空间指针报错:"[ERR]OsMemFree check error!"

【修改方案】
修改SysPpoll函数。

【影响】
对现有的产品编译不会有影响。

re #I47YWZ

Change-Id: Id7f86036870d4f32be8fc438b9aad85cdda59546
Signed-off-by: 悟空又丢了's avatarpef <cyd1997@126.com>
上级 a55f68f9
......@@ -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;
}
......
......@@ -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,
......
......@@ -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(); \
} \
......
/*
* 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);
......
/*
* 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)
......
/*
* 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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册