iPXE
Defines | Functions
linux_api.c File Reference

Implementation of most of the linux API. More...

#include <linux_api.h>
#include <stdarg.h>
#include <asm/unistd.h>
#include <string.h>

Go to the source code of this file.

Defines

#define SOCKOP_socket   1
#define SOCKOP_bind   2
#define SOCKOP_sendto   11

Functions

 FILE_LICENCE (GPL2_OR_LATER)
int linux_open (const char *pathname, int flags)
int linux_close (int fd)
off_t linux_lseek (int fd, off_t offset, int whence)
__kernel_ssize_t linux_read (int fd, void *buf, __kernel_size_t count)
__kernel_ssize_t linux_write (int fd, const void *buf, __kernel_size_t count)
int linux_fcntl (int fd, int cmd,...)
int linux_ioctl (int fd, int request,...)
int linux_poll (struct pollfd *fds, nfds_t nfds, int timeout)
int linux_nanosleep (const struct timespec *req, struct timespec *rem)
int linux_usleep (useconds_t usec)
int linux_gettimeofday (struct timeval *tv, struct timezone *tz)
void * linux_mmap (void *addr, __kernel_size_t length, int prot, int flags, int fd, __kernel_off_t offset)
void * linux_mremap (void *old_address, __kernel_size_t old_size, __kernel_size_t new_size, int flags)
int linux_munmap (void *addr, __kernel_size_t length)
int linux_socket (int domain, int type_, int protocol)
int linux_bind (int fd, const struct sockaddr *addr, socklen_t addrlen)
ssize_t linux_sendto (int fd, const void *buf, size_t len, int flags, const struct sockaddr *daddr, socklen_t addrlen)

Detailed Description

Implementation of most of the linux API.

Definition in file linux_api.c.


Define Documentation

#define SOCKOP_socket   1

Referenced by linux_socket().

#define SOCKOP_bind   2

Referenced by linux_bind().

#define SOCKOP_sendto   11

Referenced by linux_sendto().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER  )
int linux_open ( const char *  pathname,
int  flags 
)

Definition at line 32 of file linux_api.c.

References linux_syscall().

                                                   {
        return linux_syscall ( __NR_open, pathname, flags );
}
int linux_close ( int  fd)

Definition at line 36 of file linux_api.c.

References linux_syscall().

                           {
        return linux_syscall ( __NR_close, fd );
}
off_t linux_lseek ( int  fd,
off_t  offset,
int  whence 
)

Definition at line 40 of file linux_api.c.

References linux_syscall().

                                                       {
        return linux_syscall ( __NR_lseek, fd, offset, whence );
}
__kernel_ssize_t linux_read ( int  fd,
void *  buf,
__kernel_size_t  count 
)

Definition at line 44 of file linux_api.c.

References linux_syscall().

                                                                         {
        return linux_syscall ( __NR_read, fd, buf, count );
}
__kernel_ssize_t linux_write ( int  fd,
const void *  buf,
__kernel_size_t  count 
)

Definition at line 48 of file linux_api.c.

References linux_syscall().

                                                       {
        return linux_syscall  (  __NR_write, fd, buf, count );
}
int linux_fcntl ( int  fd,
int  cmd,
  ... 
)

Definition at line 53 of file linux_api.c.

References linux_syscall(), va_arg, va_end, and va_start.

                                         {
        long arg;
        va_list list;

        va_start ( list, cmd );
        arg = va_arg ( list, long );
        va_end ( list );

        return linux_syscall ( __NR_fcntl, fd, cmd, arg );
}
int linux_ioctl ( int  fd,
int  request,
  ... 
)

Definition at line 64 of file linux_api.c.

References linux_syscall(), va_arg, va_end, and va_start.

                                             {
        void *arg;
        va_list list;

        va_start ( list, request );
        arg = va_arg ( list, void * );
        va_end ( list );

        return linux_syscall ( __NR_ioctl, fd, request, arg );
}
int linux_poll ( struct pollfd *  fds,
nfds_t  nfds,
int  timeout 
)

Definition at line 75 of file linux_api.c.

References linux_syscall().

                                                                {
        return linux_syscall ( __NR_poll, fds, nfds, timeout );
}
int linux_nanosleep ( const struct timespec *  req,
struct timespec *  rem 
)

Definition at line 79 of file linux_api.c.

References linux_syscall().

Referenced by linux_usleep().

                                                                         {
        return linux_syscall ( __NR_nanosleep, req, rem );
}
int linux_usleep ( useconds_t  usec)

Definition at line 83 of file linux_api.c.

References linux_nanosleep(), and NULL.

                                     {
        struct timespec ts = {
                .tv_sec = ( ( long ) ( usec / 1000000 ) ),
                .tv_nsec = ( ( long ) ( usec % 1000000 ) * 1000UL ),
        };

        return linux_nanosleep ( &ts, NULL );
}
int linux_gettimeofday ( struct timeval *  tv,
struct timezone *  tz 
)

Definition at line 92 of file linux_api.c.

References linux_syscall().

                                                                   {
        return linux_syscall ( __NR_gettimeofday, tv, tz );
}
void* linux_mmap ( void *  addr,
__kernel_size_t  length,
int  prot,
int  flags,
int  fd,
__kernel_off_t  offset 
)

Definition at line 96 of file linux_api.c.

References __SYSCALL_mmap, and linux_syscall().

                                                    {
        return ( void * ) linux_syscall ( __SYSCALL_mmap, addr, length, prot,
                                          flags, fd, offset );
}
void* linux_mremap ( void *  old_address,
__kernel_size_t  old_size,
__kernel_size_t  new_size,
int  flags 
)

Definition at line 102 of file linux_api.c.

References linux_syscall().

                                                            {
        return ( void * ) linux_syscall ( __NR_mremap, old_address, old_size,
                                          new_size, flags );
}
int linux_munmap ( void *  addr,
__kernel_size_t  length 
)

Definition at line 108 of file linux_api.c.

References linux_syscall().

                                                        {
        return linux_syscall ( __NR_munmap, addr, length );
}
int linux_socket ( int  domain,
int  type_,
int  protocol 
)

Definition at line 112 of file linux_api.c.

References domain, linux_syscall(), and SOCKOP_socket.

                                                         {
#ifdef __NR_socket
        return linux_syscall ( __NR_socket, domain, type_, protocol );
#else
#ifndef SOCKOP_socket
# define SOCKOP_socket 1
#endif
        unsigned long sc_args[] = { domain, type_, protocol };
        return linux_syscall ( __NR_socketcall, SOCKOP_socket, sc_args );
#endif
}
int linux_bind ( int  fd,
const struct sockaddr addr,
socklen_t  addrlen 
)

Definition at line 124 of file linux_api.c.

References linux_syscall(), and SOCKOP_bind.

                                                                          {
#ifdef __NR_bind
        return linux_syscall ( __NR_bind, fd, addr, addrlen );
#else
#ifndef SOCKOP_bind
# define SOCKOP_bind 2
#endif
        unsigned long sc_args[] = { fd, (unsigned long)addr, addrlen };
        return linux_syscall ( __NR_socketcall, SOCKOP_bind, sc_args );
#endif
}
ssize_t linux_sendto ( int  fd,
const void *  buf,
size_t  len,
int  flags,
const struct sockaddr daddr,
socklen_t  addrlen 
)

Definition at line 136 of file linux_api.c.

References linux_syscall(), and SOCKOP_sendto.

                                                                         {
#ifdef __NR_sendto
        return linux_syscall ( __NR_sendto, fd, buf, len, flags,
                               daddr, addrlen );
#else
#ifndef SOCKOP_sendto
# define SOCKOP_sendto 11
#endif
        unsigned long sc_args[] = { fd, (unsigned long)buf, len,
                                    flags, (unsigned long)daddr, addrlen };
        return linux_syscall ( __NR_socketcall, SOCKOP_sendto, sc_args );
#endif
}