update openharmony 1.0.1
This commit is contained in:
0
compat/posix/Kconfig
Normal file → Executable file
0
compat/posix/Kconfig
Normal file → Executable file
@@ -1,5 +1,5 @@
|
||||
# Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
# Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
# 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:
|
||||
|
||||
23
compat/posix/include/mqueue.h
Normal file → Executable file
23
compat/posix/include/mqueue.h
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -43,6 +43,9 @@
|
||||
#include "limits.h"
|
||||
#include "los_typedef.h"
|
||||
#include "time.h"
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "los_queue_pri.h"
|
||||
|
||||
@@ -71,11 +74,23 @@ extern "C" {
|
||||
/* not suppurt prio */
|
||||
#define MQ_PRIO_MAX 1
|
||||
|
||||
typedef union send_receive_t {
|
||||
unsigned oth : 3;
|
||||
unsigned grp : 6;
|
||||
unsigned usr : 9;
|
||||
short data;
|
||||
} mode_s;
|
||||
|
||||
/* TYPE DEFINITIONS */
|
||||
struct mqarray {
|
||||
UINT32 mq_id : 31;
|
||||
UINT32 unlinkflag : 1;
|
||||
char *mq_name;
|
||||
UINT32 unlink_ref;
|
||||
mode_s mode_data; /* mode data of mqueue */
|
||||
uid_t euid; /* euid of mqueue */
|
||||
gid_t egid; /* egid of mqueue */
|
||||
fd_set mq_fdset; /* mqueue sysFd bit map */
|
||||
LosQueueCB *mqcb;
|
||||
struct mqpersonal *mq_personal;
|
||||
};
|
||||
@@ -84,7 +99,9 @@ struct mqpersonal {
|
||||
struct mqarray *mq_posixdes;
|
||||
struct mqpersonal *mq_next;
|
||||
int mq_flags;
|
||||
int mq_mode; /* Mode of mqueue */
|
||||
UINT32 mq_status;
|
||||
UINT32 mq_refcount;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -400,6 +417,8 @@ extern int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen,
|
||||
extern ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen,
|
||||
unsigned int *msgPrio, const struct timespec *absTimeout);
|
||||
|
||||
extern void mqueue_refer(int sysFd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
}
|
||||
|
||||
4
compat/posix/include/time_posix.h
Normal file → Executable file
4
compat/posix/include/time_posix.h
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
4
compat/posix/src/misc.c
Normal file → Executable file
4
compat/posix/src/misc.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
325
compat/posix/src/mqueue.c
Normal file → Executable file
325
compat/posix/src/mqueue.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -36,6 +36,8 @@
|
||||
#include "time_posix.h"
|
||||
#include "los_memory.h"
|
||||
#include "los_vm_map.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "fs_file.h"
|
||||
#include "user_copy.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
@@ -46,9 +48,14 @@ extern "C" {
|
||||
|
||||
#define FNONBLOCK O_NONBLOCK
|
||||
|
||||
#ifndef MAX_MQ_FD
|
||||
#define MAX_MQ_FD CONFIG_NQUEUE_DESCRIPTORS
|
||||
#endif
|
||||
|
||||
/* GLOBALS */
|
||||
STATIC struct mqarray g_queueTable[LOSCFG_BASE_IPC_QUEUE_LIMIT];
|
||||
STATIC pthread_mutex_t g_mqueueMutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
|
||||
STATIC struct mqpersonal *g_mqPrivBuf[MAX_MQ_FD];
|
||||
|
||||
/* LOCAL FUNCTIONS */
|
||||
STATIC INLINE INT32 MqNameCheck(const CHAR *mqName)
|
||||
@@ -100,7 +107,6 @@ STATIC INLINE struct mqarray *GetMqueueCBByName(const CHAR *name)
|
||||
return &(g_queueTable[index]);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -114,6 +120,10 @@ STATIC INT32 DoMqueueDelete(struct mqarray *mqueueCB)
|
||||
}
|
||||
|
||||
mqueueCB->mqcb = NULL;
|
||||
/* When mqueue-list head node needed free ,reset the mode_data */
|
||||
mqueueCB->mode_data.data = 0;
|
||||
mqueueCB->euid = -1;
|
||||
mqueueCB->egid = -1;
|
||||
|
||||
ret = LOS_QueueDelete(mqueueCB->mq_id);
|
||||
switch (ret) {
|
||||
@@ -152,7 +162,7 @@ STATIC int SaveMqueueName(const CHAR *mqName, struct mqarray *mqueueCB)
|
||||
return LOS_OK;
|
||||
}
|
||||
|
||||
STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag)
|
||||
STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR *mqName, INT32 openFlag, UINT32 mode)
|
||||
{
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
UINT32 mqueueID;
|
||||
@@ -191,10 +201,13 @@ STATIC struct mqpersonal *DoMqueueCreate(const struct mq_attr *attr, const CHAR
|
||||
}
|
||||
|
||||
mqueueCB->unlinkflag = FALSE;
|
||||
mqueueCB->unlink_ref = 0;
|
||||
mqueueCB->mq_personal->mq_status = MQ_USE_MAGIC;
|
||||
mqueueCB->mq_personal->mq_next = NULL;
|
||||
mqueueCB->mq_personal->mq_posixdes = mqueueCB;
|
||||
mqueueCB->mq_personal->mq_flags = (INT32)((UINT32)openFlag | ((UINT32)attr->mq_flags & (UINT32)FNONBLOCK));
|
||||
mqueueCB->mq_personal->mq_mode = mode;
|
||||
mqueueCB->mq_personal->mq_refcount = 0;
|
||||
|
||||
return mqueueCB->mq_personal;
|
||||
ERROUT:
|
||||
@@ -228,6 +241,7 @@ STATIC struct mqpersonal *DoMqueueOpen(struct mqarray *mqueueCB, INT32 openFlag)
|
||||
privateMqPersonal->mq_posixdes = mqueueCB;
|
||||
privateMqPersonal->mq_flags = openFlag;
|
||||
privateMqPersonal->mq_status = MQ_USE_MAGIC;
|
||||
privateMqPersonal->mq_refcount = 0;
|
||||
|
||||
return privateMqPersonal;
|
||||
|
||||
@@ -235,14 +249,226 @@ ERROUT:
|
||||
return (struct mqpersonal *)-1;
|
||||
}
|
||||
|
||||
/* Translate a sysFd into privateMqPersonal */
|
||||
STATIC struct mqpersonal *MqGetPrivDataBuff(mqd_t personal)
|
||||
{
|
||||
INT32 sysFd = (INT32)personal;
|
||||
INT32 id = sysFd - MQUEUE_FD_OFFSET;
|
||||
|
||||
/* Filter illegal id */
|
||||
if ((id < 0) || (id >= MAX_MQ_FD)) {
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
return g_mqPrivBuf[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Alloc sysFd, storage mq private data, set using bit.
|
||||
*
|
||||
* @param maxfdp: Maximum allowed application of mqueue sysFd.
|
||||
* @param fdset: Mqueue sysFd bit map.
|
||||
* @param privateMqPersonal: Private data.
|
||||
* @return the index of the new fd; -1 on error
|
||||
*/
|
||||
STATIC INT32 MqAllocSysFd(int maxfdp, struct mqpersonal *privateMqPersonal)
|
||||
{
|
||||
INT32 i;
|
||||
struct mqarray *mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
fd_set *fdset = &mqueueCB->mq_fdset;
|
||||
for (i = 0; i < maxfdp; i++) {
|
||||
/* sysFd: used bit setting, and get the index of swtmrID buffer */
|
||||
if (!(fdset && FD_ISSET(i + MQUEUE_FD_OFFSET, fdset))) {
|
||||
FD_SET(i + MQUEUE_FD_OFFSET, fdset);
|
||||
if (!g_mqPrivBuf[i]) {
|
||||
g_mqPrivBuf[i] = mqueueCB->mq_personal;
|
||||
return i + MQUEUE_FD_OFFSET;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* there are no more mq sysFd to use, free the personal */
|
||||
LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal);
|
||||
privateMqPersonal = NULL;
|
||||
mqueueCB->mq_personal = NULL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
STATIC VOID MqFreeSysFd(struct mqarray *mqueueCB, mqd_t personal)
|
||||
{
|
||||
INT32 sysFd = (INT32)personal;
|
||||
fd_set *fdset = &mqueueCB->mq_fdset;
|
||||
if (fdset && FD_ISSET(sysFd, fdset)) {
|
||||
FD_CLR(sysFd, fdset);
|
||||
g_mqPrivBuf[sysFd - MQUEUE_FD_OFFSET] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* Mqueue fd reference count */
|
||||
void mqueue_refer(int sysFd)
|
||||
{
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff((mqd_t)sysFd);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto OUT_UNLOCK;
|
||||
}
|
||||
mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
if (mqueueCB == NULL) {
|
||||
goto OUT_UNLOCK;
|
||||
}
|
||||
privateMqPersonal->mq_refcount++;
|
||||
mqueueCB->unlink_ref++;
|
||||
OUT_UNLOCK:
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
}
|
||||
|
||||
STATIC INT32 MqTryClose(struct mqpersonal *privateMqPersonal)
|
||||
{
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENFILE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (privateMqPersonal->mq_refcount == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
privateMqPersonal->mq_refcount--;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
STATIC INT32 MqTryUnlink(struct mqarray *mqueueCB)
|
||||
{
|
||||
if (mqueueCB->unlink_ref == 0) {
|
||||
return TRUE;
|
||||
}
|
||||
mqueueCB->unlink_ref--;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* Set the mode data bit,for consumer's mode comparing. */
|
||||
STATIC INT32 MqueueModeAnalysisSet(struct mqpersonal *privateMqPersonal)
|
||||
{
|
||||
UINT32 mode;
|
||||
UINT32 intSave;
|
||||
User *user = NULL;
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
|
||||
if ((INT32)(UINTPTR)privateMqPersonal < 0) {
|
||||
return -1;
|
||||
}
|
||||
/* Get mqueueCB of first time creating mqueue */
|
||||
mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENFILE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
mode = mqueueCB->mq_personal->mq_mode;
|
||||
/* Set mqueue gid uid */
|
||||
SCHEDULER_LOCK(intSave);
|
||||
user = OsCurrUserGet();
|
||||
mqueueCB->euid = user->effUserID;
|
||||
mqueueCB->egid = user->effGid;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* Set mode data bit */
|
||||
if (mode & S_IRUSR) {
|
||||
mqueueCB->mode_data.usr |= S_IRUSR;
|
||||
}
|
||||
if (mode & S_IWUSR) {
|
||||
mqueueCB->mode_data.usr |= S_IWUSR;
|
||||
}
|
||||
if (mode & S_IRGRP) {
|
||||
mqueueCB->mode_data.grp |= S_IRGRP;
|
||||
}
|
||||
if (mode & S_IWGRP) {
|
||||
mqueueCB->mode_data.grp |= S_IWGRP;
|
||||
}
|
||||
if (mode & S_IROTH) {
|
||||
mqueueCB->mode_data.oth |= S_IROTH;
|
||||
}
|
||||
if (mode & S_IWOTH) {
|
||||
mqueueCB->mode_data.oth |= S_IWOTH;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
STATIC INT32 GetPermissionOfVisitor(struct mqarray *mqueueCB)
|
||||
{
|
||||
uid_t euid;
|
||||
gid_t egid;
|
||||
UINT32 intSave;
|
||||
User *user = NULL;
|
||||
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENOENT;
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
/* Get the visitor process euid and egid */
|
||||
SCHEDULER_LOCK(intSave);
|
||||
user = OsCurrUserGet();
|
||||
euid = user->effUserID;
|
||||
egid = user->effGid;
|
||||
SCHEDULER_UNLOCK(intSave);
|
||||
|
||||
/* root */
|
||||
if (euid == 0) {
|
||||
return ENOERR;
|
||||
}
|
||||
if (euid == mqueueCB->euid) { /* usr */
|
||||
if (!((mqueueCB->mode_data.usr & S_IRUSR) || (mqueueCB->mode_data.usr & S_IWUSR))) {
|
||||
errno = EACCES;
|
||||
goto ERR_OUT;
|
||||
}
|
||||
} else if (egid == mqueueCB->egid) { /* grp */
|
||||
if (!((mqueueCB->mode_data.grp & S_IRGRP) || (mqueueCB->mode_data.grp & S_IWGRP))) {
|
||||
errno = EACCES;
|
||||
goto ERR_OUT;
|
||||
}
|
||||
} else { /* oth */
|
||||
if (!((mqueueCB->mode_data.oth & S_IROTH) || (mqueueCB->mode_data.oth & S_IWOTH))) {
|
||||
errno = EACCES;
|
||||
goto ERR_OUT;
|
||||
}
|
||||
}
|
||||
return ENOERR;
|
||||
|
||||
ERR_OUT:
|
||||
return -EPERM;
|
||||
}
|
||||
|
||||
STATIC INT32 GetMqueueAttr(struct mq_attr *defaultAttr, struct mq_attr *attr)
|
||||
{
|
||||
if (attr != NULL) {
|
||||
if (LOS_ArchCopyFromUser(defaultAttr, attr, sizeof(struct mq_attr))) {
|
||||
errno = EFAULT;
|
||||
return -1;
|
||||
}
|
||||
if ((defaultAttr->mq_maxmsg < 0) || (defaultAttr->mq_maxmsg > (long int)USHRT_MAX) ||
|
||||
(defaultAttr->mq_msgsize < 0) || (defaultAttr->mq_msgsize > (long int)(USHRT_MAX - sizeof(UINT32)))) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
{
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = (struct mqpersonal *)-1;
|
||||
struct mq_attr *attr = NULL;
|
||||
struct mq_attr defaultAttr = { 0, MQ_MAX_MSG_NUM, MQ_MAX_MSG_LEN, 0 };
|
||||
int retVal;
|
||||
va_list ap;
|
||||
int sysFd;
|
||||
mqd_t mqFd = -1;
|
||||
unsigned int mode = 0;
|
||||
|
||||
if (MqNameCheck(mqName) == -1) {
|
||||
return (mqd_t)-1;
|
||||
@@ -259,56 +485,62 @@ mqd_t mq_open(const char *mqName, int openFlag, ...)
|
||||
privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag);
|
||||
} else {
|
||||
va_start(ap, openFlag);
|
||||
(VOID)va_arg(ap, int);
|
||||
mode = va_arg(ap, unsigned int);
|
||||
attr = va_arg(ap, struct mq_attr *);
|
||||
va_end(ap);
|
||||
|
||||
if (attr != NULL) {
|
||||
retVal = LOS_ArchCopyFromUser(&defaultAttr, attr, sizeof(struct mq_attr));
|
||||
if (retVal != 0) {
|
||||
errno = EFAULT;
|
||||
goto OUT;
|
||||
}
|
||||
if ((defaultAttr.mq_maxmsg < 0) || (defaultAttr.mq_maxmsg > (long int)USHRT_MAX) ||
|
||||
(defaultAttr.mq_msgsize < 0) || (defaultAttr.mq_msgsize > (long int)(USHRT_MAX - sizeof(UINT32)))) {
|
||||
errno = EINVAL;
|
||||
goto OUT;
|
||||
}
|
||||
if (GetMqueueAttr(&defaultAttr, attr)) {
|
||||
goto OUT;
|
||||
}
|
||||
privateMqPersonal = DoMqueueCreate(&defaultAttr, mqName, openFlag);
|
||||
privateMqPersonal = DoMqueueCreate(&defaultAttr, mqName, openFlag, mode);
|
||||
}
|
||||
/* Set mode data bit ,just for the first node */
|
||||
if (MqueueModeAnalysisSet(privateMqPersonal)) {
|
||||
goto OUT;
|
||||
}
|
||||
} else {
|
||||
if (mqueueCB == NULL) {
|
||||
errno = ENOENT;
|
||||
if (GetPermissionOfVisitor(mqueueCB)) {
|
||||
goto OUT;
|
||||
}
|
||||
privateMqPersonal = DoMqueueOpen(mqueueCB, openFlag);
|
||||
}
|
||||
|
||||
OUT:
|
||||
if ((INT32)(UINTPTR)privateMqPersonal > 0) {
|
||||
/* alloc sysFd */
|
||||
sysFd = MqAllocSysFd(MAX_MQ_FD, privateMqPersonal);
|
||||
if (sysFd == -1) {
|
||||
errno = ENFILE;
|
||||
}
|
||||
mqFd = (mqd_t)sysFd;
|
||||
}
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
return (mqd_t)privateMqPersonal;
|
||||
return mqFd;
|
||||
}
|
||||
|
||||
int mq_close(mqd_t personal)
|
||||
{
|
||||
INT32 ret = 0;
|
||||
INT32 ret = -1;
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
struct mqpersonal *tmp = NULL;
|
||||
|
||||
if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
|
||||
/* Get the personal sysFd and reset personal fd -1 */
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto OUT_UNLOCK;
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
privateMqPersonal = (struct mqpersonal *)personal;
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
goto OUT_UNLOCK;
|
||||
}
|
||||
|
||||
/* there have other thread used the fd */
|
||||
if (!MqTryClose(privateMqPersonal)) {
|
||||
ret = 0;
|
||||
goto OUT_UNLOCK;
|
||||
}
|
||||
mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
if (mqueueCB->mq_personal == NULL) {
|
||||
errno = EBADF;
|
||||
@@ -332,6 +564,7 @@ int mq_close(mqd_t personal)
|
||||
}
|
||||
/* flag no use */
|
||||
privateMqPersonal->mq_status = 0;
|
||||
MqFreeSysFd(mqueueCB, personal);
|
||||
|
||||
/* free the personal */
|
||||
ret = LOS_MemFree(OS_SYS_MEM_ADDR, privateMqPersonal);
|
||||
@@ -354,8 +587,8 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
struct mqarray *mqueueCB = NULL;
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
|
||||
errno = EBADF;
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -365,7 +598,6 @@ int OsMqGetAttr(mqd_t personal, struct mq_attr *mqAttr)
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
privateMqPersonal = (struct mqpersonal *)personal;
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
@@ -385,8 +617,8 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
{
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
|
||||
errno = EBADF;
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -396,7 +628,6 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
privateMqPersonal = (struct mqpersonal *)personal;
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
@@ -404,7 +635,7 @@ int OsMqSetAttr(mqd_t personal, const struct mq_attr *mqSetAttr, struct mq_attr
|
||||
}
|
||||
|
||||
if (mqOldAttr != NULL) {
|
||||
(VOID)OsMqGetAttr((mqd_t)privateMqPersonal, mqOldAttr);
|
||||
(VOID)OsMqGetAttr(personal, mqOldAttr);
|
||||
}
|
||||
|
||||
privateMqPersonal->mq_flags = (INT32)((UINT32)privateMqPersonal->mq_flags & (UINT32)(~FNONBLOCK)); /* clear */
|
||||
@@ -438,10 +669,13 @@ int mq_unlink(const char *mqName)
|
||||
errno = ENOENT;
|
||||
goto ERROUT_UNLOCK;
|
||||
}
|
||||
|
||||
if (!MqTryUnlink(mqueueCB)) {
|
||||
(VOID)pthread_mutex_unlock(&g_mqueueMutex);
|
||||
return 0;
|
||||
}
|
||||
if (mqueueCB->mq_personal != NULL) {
|
||||
mqueueCB->unlinkflag = TRUE;
|
||||
} else {
|
||||
} else if (mqueueCB->unlink_ref == 0) {
|
||||
ret = DoMqueueDelete(mqueueCB);
|
||||
}
|
||||
|
||||
@@ -476,8 +710,7 @@ STATIC INT32 ConvertTimeout(long flags, const struct timespec *absTimeout, UINT6
|
||||
|
||||
STATIC INLINE BOOL MqParamCheck(mqd_t personal, const char *msg, size_t msgLen)
|
||||
{
|
||||
if (!LOS_IsKernelAddressRange(personal, sizeof(struct mqpersonal))) {
|
||||
errno = EBADF;
|
||||
if (personal < 0) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -507,11 +740,14 @@ int mq_timedsend(mqd_t personal, const char *msg, size_t msgLen, unsigned int ms
|
||||
struct mqpersonal *privateMqPersonal = NULL;
|
||||
|
||||
OS_MQ_GOTO_ERROUT_IF(!MqParamCheck(personal, msg, msgLen), errno);
|
||||
|
||||
OS_MQ_GOTO_ERROUT_IF(msgPrio > (MQ_PRIO_MAX - 1), EINVAL);
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
privateMqPersonal = (struct mqpersonal *)personal;
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto ERROUT_UNLOCK;
|
||||
}
|
||||
|
||||
OS_MQ_GOTO_ERROUT_UNLOCK_IF(privateMqPersonal->mq_status != MQ_USE_MAGIC, EBADF);
|
||||
|
||||
mqueueCB = privateMqPersonal->mq_posixdes;
|
||||
@@ -554,7 +790,10 @@ ssize_t mq_timedreceive(mqd_t personal, char *msg, size_t msgLen, unsigned int *
|
||||
}
|
||||
|
||||
(VOID)pthread_mutex_lock(&g_mqueueMutex);
|
||||
privateMqPersonal = (struct mqpersonal *)personal;
|
||||
privateMqPersonal = MqGetPrivDataBuff(personal);
|
||||
if (privateMqPersonal == NULL) {
|
||||
goto ERROUT_UNLOCK;
|
||||
}
|
||||
if (privateMqPersonal->mq_status != MQ_USE_MAGIC) {
|
||||
errno = EBADF;
|
||||
goto ERROUT_UNLOCK;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
5
compat/posix/src/pthread.c
Normal file → Executable file
5
compat/posix/src/pthread.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -36,6 +36,7 @@
|
||||
#include "stdio.h"
|
||||
#include "map_error.h"
|
||||
#include "los_process_pri.h"
|
||||
#include "los_sched_pri.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
4
compat/posix/src/pthread_cond.c
Normal file → Executable file
4
compat/posix/src/pthread_cond.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
4
compat/posix/src/pthread_mutex.c
Normal file → Executable file
4
compat/posix/src/pthread_mutex.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
4
compat/posix/src/semaphore.c
Normal file → Executable file
4
compat/posix/src/semaphore.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
|
||||
45
compat/posix/src/time.c
Normal file → Executable file
45
compat/posix/src/time.c
Normal file → Executable file
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
|
||||
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
|
||||
* 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:
|
||||
@@ -30,7 +30,6 @@
|
||||
*/
|
||||
|
||||
#include "time.h"
|
||||
#include "asm/hal_platform_ints.h"
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "sys/times.h"
|
||||
@@ -744,7 +743,7 @@ int timer_settime(timer_t timerID, int flags,
|
||||
swtmr->ucMode = interval ? LOS_SWTMR_MODE_OPP : LOS_SWTMR_MODE_NO_SELFDELETE;
|
||||
swtmr->uwExpiry = expiry + !!expiry; // PS: skip the first tick because it is NOT a full tick.
|
||||
swtmr->uwInterval = interval;
|
||||
swtmr->ucOverrun = 0;
|
||||
swtmr->uwOverrun = 0;
|
||||
LOS_SpinUnlockRestore(&g_swtmrSpin, intSave);
|
||||
|
||||
if ((value->it_value.tv_sec == 0) && (value->it_value.tv_nsec == 0)) {
|
||||
@@ -813,20 +812,15 @@ int timer_getoverrun(timer_t timerID)
|
||||
return -1;
|
||||
}
|
||||
|
||||
overRun = (INT32)(swtmr->ucOverrun);
|
||||
overRun = (INT32)(swtmr->uwOverrun);
|
||||
return (overRun > DELAYTIMER_MAX) ? DELAYTIMER_MAX : overRun;
|
||||
}
|
||||
|
||||
STATIC INT32 DoNanoSleep(UINT64 nseconds)
|
||||
STATIC INT32 DoNanoSleep(UINT64 useconds)
|
||||
{
|
||||
UINT64 tick;
|
||||
UINT32 ret;
|
||||
const UINT32 nsPerTick = OS_SYS_NS_PER_SECOND / LOSCFG_BASE_CORE_TICK_PER_SECOND;
|
||||
|
||||
tick = (nseconds + nsPerTick - 1) / nsPerTick; // Round up for ticks
|
||||
|
||||
/* PS: skip the first tick because it is NOT a full tick. */
|
||||
ret = LOS_TaskDelay((tick >= UINT32_MAX) ? UINT32_MAX : (tick ? ((UINT32)tick + 1) : 0));
|
||||
ret = LOS_TaskDelay(OsUS2Tick(useconds));
|
||||
if (ret == LOS_OK || ret == LOS_ERRNO_TSK_YIELD_NOT_ENOUGH_TASK) {
|
||||
return 0;
|
||||
}
|
||||
@@ -835,12 +829,12 @@ STATIC INT32 DoNanoSleep(UINT64 nseconds)
|
||||
|
||||
int usleep(unsigned useconds)
|
||||
{
|
||||
return DoNanoSleep((UINT64)useconds * OS_SYS_NS_PER_US);
|
||||
return DoNanoSleep((UINT64)useconds);
|
||||
}
|
||||
|
||||
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
{
|
||||
UINT64 nseconds;
|
||||
UINT64 useconds;
|
||||
INT32 ret = -1;
|
||||
|
||||
(VOID)rmtp;
|
||||
@@ -851,14 +845,14 @@ int nanosleep(const struct timespec *rqtp, struct timespec *rmtp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
nseconds = (UINT64)rqtp->tv_sec * OS_SYS_NS_PER_SECOND + rqtp->tv_nsec;
|
||||
useconds = (UINT64)rqtp->tv_sec * OS_SYS_US_PER_SECOND + rqtp->tv_nsec / OS_SYS_NS_PER_US;
|
||||
|
||||
return DoNanoSleep(nseconds);
|
||||
return DoNanoSleep(useconds);
|
||||
}
|
||||
|
||||
unsigned int sleep(unsigned int seconds)
|
||||
{
|
||||
return DoNanoSleep((UINT64)seconds * OS_SYS_NS_PER_SECOND);
|
||||
return DoNanoSleep((UINT64)seconds * OS_SYS_US_PER_SECOND);
|
||||
}
|
||||
|
||||
double difftime(time_t time2, time_t time1)
|
||||
@@ -879,15 +873,10 @@ clock_t clock(VOID)
|
||||
|
||||
clock_t times(struct tms *buf)
|
||||
{
|
||||
clock_t clockTick;
|
||||
clock_t clockTick = -1;
|
||||
|
||||
clockTick = LOS_TickCountGet();
|
||||
if (buf != NULL) {
|
||||
buf->tms_cstime = clockTick;
|
||||
buf->tms_cutime = clockTick;
|
||||
buf->tms_stime = clockTick;
|
||||
buf->tms_utime = clockTick;
|
||||
}
|
||||
(void)buf;
|
||||
set_errno(ENOSYS);
|
||||
|
||||
return clockTick;
|
||||
}
|
||||
@@ -914,6 +903,12 @@ int setitimer(int which, const struct itimerval *value, struct itimerval *ovalue
|
||||
}
|
||||
}
|
||||
LOS_TaskUnlock();
|
||||
|
||||
if (!ValidTimeval(&value->it_value) || !ValidTimeval(&value->it_interval)) {
|
||||
set_errno(EINVAL);
|
||||
return -1;
|
||||
}
|
||||
|
||||
TIMEVAL_TO_TIMESPEC(&value->it_value, &spec.it_value);
|
||||
TIMEVAL_TO_TIMESPEC(&value->it_interval, &spec.it_interval);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user