I’m trying to write a wrapper function for read() , under Linux .
Please go easy on me , since this is my first time using Wrappers 🙂
Given the code the my_wrappers.c file :
#include "my_wrappers.h"
#include <unistd.h>
#include <sys/types.h>
ssize_t my_read (int fd, void *buf, size_t count)
{
long ret;
extern int errno;
__asm__ __volatile__ ("pushl %%ebx\n\t"
"movl %%esi,%%ebx\n\t"
"int $0x80\n\t"
"popl %%ebx"
: "=a" (ret)
: "0" (SYS_read), "S" ((long) fd),
"c" ((long) buf) "d" ((long) count): "bx");
if (ret >= 0)
{
return (int) ret;
}
errno = -ret;
return -1;
}
and my_wrappers.h file :
#ifndef __MY_WRAPPERS_H_
#define __MY_WRAPPERS_H_
#include <unistd.h>
#include <sys/types.h>
int my_open(const char *pathname, int flags, mode_t mode);
ssize_t my_write(int fd, const void *buf, size_t count);
ssize_t my_read(int fd, void *buf, size_t count);
int my_close(int fd);
pid_t my_fork(void);
#endif
I’m only allowed to use call the libc wrappers, i.e. , I’m not allowed to call open(), read() and etc.
What’s wrong with this code ? maybe because I didn’t use the number of the system call table ?
The error from Eclipse : – ‘SYS_read’ undeclared (first use in this function)
Regards
Ron
You need to
#include <syscall.h>or possibly#include <sys/syscall.h>