2020-02-05 17:43:02 +01:00
|
|
|
/*
|
2023-02-14 15:03:52 +00:00
|
|
|
* Copyright (C) 2020-2023 Intel Corporation
|
2020-02-05 17:43:02 +01:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/linux/sys_calls.h"
|
2020-02-05 17:43:02 +01:00
|
|
|
|
2021-02-23 14:03:54 +01:00
|
|
|
#include <dlfcn.h>
|
2020-02-07 14:32:02 +01:00
|
|
|
#include <fcntl.h>
|
2021-02-17 22:17:01 +01:00
|
|
|
#include <iostream>
|
2021-04-02 14:19:00 +00:00
|
|
|
#include <poll.h>
|
2021-02-17 22:17:01 +01:00
|
|
|
#include <stdio.h>
|
2020-02-13 13:26:40 +01:00
|
|
|
#include <sys/ioctl.h>
|
2021-02-17 22:17:01 +01:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <sys/sysmacros.h>
|
2020-02-05 17:43:02 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
|
|
namespace NEO {
|
2021-07-08 17:19:43 +00:00
|
|
|
|
2020-02-05 17:43:02 +01:00
|
|
|
namespace SysCalls {
|
2021-07-08 17:19:43 +00:00
|
|
|
|
|
|
|
|
unsigned int getProcessId() {
|
|
|
|
|
return getpid();
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-06 12:21:52 +00:00
|
|
|
unsigned long getNumThreads() {
|
|
|
|
|
struct stat taskStat;
|
|
|
|
|
stat("/proc/self/task", &taskStat);
|
|
|
|
|
return taskStat.st_nlink - 2;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 17:43:02 +01:00
|
|
|
int close(int fileDescriptor) {
|
|
|
|
|
return ::close(fileDescriptor);
|
|
|
|
|
}
|
2020-02-07 14:32:02 +01:00
|
|
|
int open(const char *file, int flags) {
|
|
|
|
|
return ::open(file, flags);
|
|
|
|
|
}
|
2020-02-13 13:26:40 +01:00
|
|
|
int ioctl(int fileDescriptor, unsigned long int request, void *arg) {
|
|
|
|
|
return ::ioctl(fileDescriptor, request, arg);
|
|
|
|
|
}
|
2021-02-17 22:17:01 +01:00
|
|
|
|
2021-02-23 14:03:54 +01:00
|
|
|
void *dlopen(const char *filename, int flag) {
|
|
|
|
|
return ::dlopen(filename, flag);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-17 22:17:01 +01:00
|
|
|
int access(const char *pathName, int mode) {
|
|
|
|
|
return ::access(pathName, mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int readlink(const char *path, char *buf, size_t bufsize) {
|
|
|
|
|
return static_cast<int>(::readlink(path, buf, bufsize));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int getDevicePath(int deviceFd, char *buf, size_t &bufSize) {
|
|
|
|
|
struct stat st;
|
2021-03-29 12:01:37 +00:00
|
|
|
if (::fstat(deviceFd, &st)) {
|
2021-02-17 22:17:01 +01:00
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snprintf(buf, bufSize, "/sys/dev/char/%d:%d",
|
|
|
|
|
major(st.st_rdev), minor(st.st_rdev));
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2021-04-02 14:19:00 +00:00
|
|
|
|
|
|
|
|
int poll(struct pollfd *pollFd, unsigned long int numberOfFds, int timeout) {
|
|
|
|
|
return ::poll(pollFd, numberOfFds, timeout);
|
|
|
|
|
}
|
2021-03-29 12:01:37 +00:00
|
|
|
|
|
|
|
|
int fstat(int fd, struct stat *buf) {
|
|
|
|
|
return ::fstat(fd, buf);
|
|
|
|
|
}
|
2021-05-27 16:41:47 +00:00
|
|
|
|
|
|
|
|
ssize_t pread(int fd, void *buf, size_t count, off_t offset) {
|
|
|
|
|
return ::pread(fd, buf, count, offset);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 17:35:15 +00:00
|
|
|
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
|
|
|
|
|
return ::pwrite(fd, buf, count, offset);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 14:32:27 +00:00
|
|
|
void *mmap(void *addr, size_t size, int prot, int flags, int fd, off_t off) noexcept {
|
2021-06-17 18:25:55 +00:00
|
|
|
return ::mmap(addr, size, prot, flags, fd, off);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-22 14:32:27 +00:00
|
|
|
int munmap(void *addr, size_t size) noexcept {
|
2021-06-17 18:25:55 +00:00
|
|
|
return ::munmap(addr, size);
|
|
|
|
|
}
|
2022-03-02 06:59:39 +00:00
|
|
|
|
|
|
|
|
ssize_t read(int fd, void *buf, size_t count) {
|
|
|
|
|
return ::read(fd, buf, count);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 19:43:26 +00:00
|
|
|
ssize_t write(int fd, void *buf, size_t count) {
|
|
|
|
|
return ::write(fd, buf, count);
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 09:25:16 +00:00
|
|
|
int fcntl(int fd, int cmd) {
|
|
|
|
|
return ::fcntl(fd, cmd);
|
|
|
|
|
}
|
|
|
|
|
int fcntl(int fd, int cmd, int arg) {
|
|
|
|
|
return ::fcntl(fd, cmd, arg);
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:03:52 +00:00
|
|
|
char *realpath(const char *path, char *buf) {
|
|
|
|
|
return ::realpath(path, buf);
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-27 19:43:26 +00:00
|
|
|
int pipe(int pipeFd[2]) {
|
|
|
|
|
return ::pipe(pipeFd);
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-05 17:43:02 +01:00
|
|
|
} // namespace SysCalls
|
|
|
|
|
} // namespace NEO
|