* Copyright (c) 2025 Huawei Technologies Co., Ltd.
* This program is free software, you can redistribute it and/or modify it under the terms and conditions of
* CANN Open Software License Agreement Version 2.0 (the "License").
* Please refer to the License for details. You may not use this file except in compliance with the License.
* 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 FITNESS FOR A PARTICULAR PURPOSE.
* See LICENSE in the root of the software repository for the full text of the License.
*
* The code snippet comes from Ascend project
*
* Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MMPA_LINUX_MMPA_LINUX_H
#define MMPA_LINUX_MMPA_LINUX_H
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif
#endif
#define MMPA_MACINFO_DEFAULT_SIZE 18
#define MMPA_CPUDESC_DEFAULT_SIZE 64
typedef pthread_t mmThread;
typedef pthread_mutex_t mmMutex_t;
typedef pthread_cond_t mmCond;
typedef pthread_mutex_t mmMutexFC;
typedef pthread_rwlock_t mmRWLock_t;
typedef signed int mmProcess;
typedef int mmPollHandle;
typedef int mmPipeHandle;
typedef int mmFileHandle;
typedef int mmComPletionKey;
typedef int mmCompletionHandle;
typedef int mmErrorMsg;
typedef int mmFd_t;
typedef void *mmExitCode;
typedef key_t mmKey_t;
typedef int mmMsgid;
typedef struct dirent mmDirent;
typedef struct dirent mmDirent2;
typedef struct shmid_ds mmshmId_ds;
typedef int (*mmFilter)(const mmDirent *entry);
typedef int (*mmFilter2)(const mmDirent2 *entry);
typedef int (*mmSort)(const mmDirent **a, const mmDirent **b);
typedef int (*mmSort2)(const mmDirent2 **a, const mmDirent2 **b);
typedef size_t mmSize_t;
typedef off_t mmOfft_t;
typedef pid_t mmPid_t;
typedef long MM_LONG;
typedef void *(*userProcFunc)(void *pulArg);
typedef struct {
userProcFunc procFunc;
void *pulArg;
} mmUserBlock_t;
typedef struct {
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
size_t dli_size;
int dli_bind;
int dli_type;
} mmDlInfo;
typedef struct {
int wSecond;
int wMinute;
int wHour;
int wDay;
int wMonth;
int wYear;
int wDayOfWeek;
int tm_yday;
int tm_isdst;
long int wMilliseconds;
} mmSystemTime_t;
typedef sem_t mmSem_t;
typedef struct sockaddr mmSockAddr;
typedef socklen_t mmSocklen_t;
typedef int mmSockHandle;
typedef timer_t mmTimer;
typedef pthread_key_t mmThreadKey;
typedef int mmOverLap;
typedef ssize_t mmSsize_t;
typedef size_t mmSize;
typedef struct {
unsigned int createFlag;
signed int oaFlag;
} mmCreateFlag;
typedef struct {
void *sendBuf;
signed int sendLen;
} mmIovSegment;
typedef struct in_addr mmInAddr;
typedef struct {
void *inbuf;
signed int inbufLen;
void *outbuf;
signed int outbufLen;
mmOverLap *oa;
} mmIoctlBuf;
typedef int mmAtomicType;
typedef int mmAtomicType64;
typedef enum {
pollTypeRead = 1,
pollTypeRecv,
pollTypeIoctl,
} mmPollType;
typedef struct {
mmPollHandle handle;
mmPollType pollType;
signed int ioctl_code;
mmComPletionKey completionKey;
} mmPollfd;
typedef struct {
void *priv;
mmPollHandle bufHandle;
mmPollType bufType;
void *buf;
unsigned int bufLen;
unsigned int bufRes;
} mmPollData, *pmmPollData;
typedef void (*mmPollBack)(pmmPollData);
typedef struct {
signed int tz_minuteswest;
signed int tz_dsttime;
} mmTimezone;
typedef struct {
long long tv_sec;
long long tv_usec;
} mmTimeval;
typedef struct {
MM_LONG tv_sec;
MM_LONG tv_nsec;
} mmTimespec;
typedef struct {
unsigned long long totalSize;
unsigned long long freeSize;
unsigned long long availSize;
} mmDiskSize;
#define mmTLS __thread
typedef struct stat mmStat_t;
typedef struct stat64 mmStat64_t;
typedef mode_t mmMode_t;
typedef struct option mmStructOption;
typedef struct {
char addr[MMPA_MACINFO_DEFAULT_SIZE];
} mmMacInfo;
typedef struct {
char **argv;
signed int argvCount;
char **envp;
signed int envpCount;
} mmArgvEnv;
typedef struct {
char arch[MMPA_CPUDESC_DEFAULT_SIZE];
char manufacturer[MMPA_CPUDESC_DEFAULT_SIZE];
char version[MMPA_CPUDESC_DEFAULT_SIZE];
signed int frequency;
signed int maxFrequency;
signed int ncores;
signed int nthreads;
signed int ncounts;
} mmCpuDesc;
typedef mode_t MODE;
typedef struct {
signed int detachFlag;
signed int priorityFlag;
signed int priority;
signed int policyFlag;
signed int policy;
signed int stackFlag;
unsigned int stackSize;
} mmThreadAttr;
#ifdef __ANDROID__
#define S_IREAD S_IRUSR
#define S_IWRITE S_IWUSR
#endif
#define mm_no_argument no_argument
#define mm_required_argument required_argument
#define mm_optional_argument optional_argument
#define M_FILE_RDONLY O_RDONLY
#define M_FILE_WRONLY O_WRONLY
#define M_FILE_RDWR O_RDWR
#define M_FILE_CREAT O_CREAT
#define M_RDONLY O_RDONLY
#define M_WRONLY O_WRONLY
#define M_RDWR O_RDWR
#define M_CREAT O_CREAT
#define M_BINARY O_RDONLY
#define M_TRUNC O_TRUNC
#define M_IRWXU S_IRWXU
#define M_APPEND O_APPEND
#define M_IN_CREATE IN_CREATE
#define M_IN_CLOSE_WRITE IN_CLOSE_WRITE
#define M_IN_IGNORED IN_IGNORED
#define M_OUT_CREATE IN_CREATE
#define M_OUT_CLOSE_WRITE IN_CLOSE_WRITE
#define M_OUT_IGNORED IN_IGNORED
#define M_OUT_ISDIR IN_ISDIR
#define M_IREAD S_IREAD
#define M_IRUSR S_IRUSR
#define M_IWRITE S_IWRITE
#define M_IWUSR S_IWUSR
#define M_IXUSR S_IXUSR
#define FDSIZE 64
#define M_MSG_CREAT IPC_CREAT
#define M_MSG_EXCL (IPC_CREAT | IPC_EXCL)
#define M_MSG_NOWAIT IPC_NOWAIT
#define M_WAIT_NOHANG WNOHANG
#define M_WAIT_UNTRACED \
WUNTRACED
#define M_UMASK_USRREAD S_IRUSR
#define M_UMASK_GRPREAD S_IRGRP
#define M_UMASK_OTHREAD S_IROTH
#define M_UMASK_USRWRITE S_IWUSR
#define M_UMASK_GRPWRITE S_IWGRP
#define M_UMASK_OTHWRITE S_IWOTH
#define M_UMASK_USREXEC S_IXUSR
#define M_UMASK_GRPEXEC S_IXGRP
#define M_UMASK_OTHEXEC S_IXOTH
#define mmConstructor(x) __attribute__((constructor)) void x()
#define mmDestructor(x) __attribute__((destructor)) void x()
#define MMPA_NO_ARGUMENT 0
#define MMPA_REQUIRED_ARGUMENT 1
#define MMPA_OPTIONAL_ARGUMENT 2
#define MMPA_MAX_PATH PATH_MAX
#define M_NAME_MAX MAX_FNAME
#define M_F_OK F_OK
#define M_X_OK X_OK
#define M_W_OK W_OK
#define M_R_OK R_OK
#define MM_DT_DIR DT_DIR
#define MM_DT_REG DT_REG
#define MMPA_STDIN STDIN_FILENO
#define MMPA_STDOUT STDOUT_FILENO
#define MMPA_STDERR STDERR_FILENO
#define MMPA_RTLD_NOW RTLD_NOW
#define MMPA_RTLD_GLOBAL RTLD_GLOBAL
#define MMPA_RTLD_LAZY RTLD_LAZY
#define MMPA_RTLD_NODELETE RTLD_NODELETE
#define MMPA_DL_EXT_NAME ".so"
#define MMPA_DLL_API
#ifdef __cplusplus
#if __cplusplus
}
#endif
#endif
#endif