sdm: Add sys wrappers for read, write, eventfd system calls

Add function pointers for read, write, and eventfd in Sys
wrapper and call these instead of directly calling system calls.

CRs-Fixed: 814136
Change-Id: I9964df85be2f6eaa83371b71971c642a768830f8
This commit is contained in:
Tatenda Chipeperekwa
2016-04-01 12:25:15 -07:00
committed by Gerrit - the friendly Code Review server
parent ad4cc06a17
commit 352a0baeab
2 changed files with 17 additions and 0 deletions

View File

@@ -25,6 +25,8 @@
#ifndef __SYS_H__
#define __SYS_H__
#include <sys/eventfd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <poll.h>
@@ -46,6 +48,9 @@ class Sys {
typedef ssize_t (*getline)(char **lineptr, size_t *linelen, FILE *stream);
typedef int (*pthread_cancel)(pthread_t thread);
typedef int (*dup)(int fd);
typedef ssize_t (*read)(int, void *, size_t);
typedef ssize_t (*write)(int, const void *, size_t);
typedef int (*eventfd)(unsigned int, int);
static ioctl ioctl_;
static open open_;
@@ -58,6 +63,9 @@ class Sys {
static getline getline_;
static pthread_cancel pthread_cancel_;
static dup dup_;
static read read_;
static write write_;
static eventfd eventfd_;
};
} // namespace sdm

View File

@@ -54,6 +54,9 @@ Sys::fclose Sys::fclose_ = ::fclose;
Sys::getline Sys::getline_ = ::getline;
Sys::pthread_cancel Sys::pthread_cancel_ = PthreadCancel;
Sys::dup Sys::dup_ = ::dup;
Sys::read Sys::read_ = ::read;
Sys::write Sys::write_ = ::write;
Sys::eventfd Sys::eventfd_ = ::eventfd;
#else
@@ -68,6 +71,9 @@ extern FILE* virtual_fopen(const char *fname, const char *mode);
extern int virtual_fclose(FILE* fileptr);
extern ssize_t virtual_getline(char **lineptr, size_t *linelen, FILE *stream);
extern int virtual_dup(int fd);
extern ssize_t virtual_read(int fd, void *data, size_t count);
extern ssize_t virtual_write(int fd, const void *data, size_t count);
extern int virtual_eventfd(unsigned int initval, int flags);
Sys::ioctl Sys::ioctl_ = virtual_ioctl;
Sys::open Sys::open_ = virtual_open;
@@ -80,6 +86,9 @@ Sys::fclose Sys::fclose_ = virtual_fclose;
Sys::getline Sys::getline_ = virtual_getline;
Sys::pthread_cancel Sys::pthread_cancel_ = ::pthread_cancel;
Sys::dup Sys::dup_ = virtual_dup;
Sys::read Sys::read_ = virtual_read;
Sys::write Sys::write_ = virtual_write;
Sys::eventfd Sys::eventfd_ = virtual_eventfd;
#endif // SDM_VIRTUAL_DRIVER