iPXE
Defines | Typedefs | Functions
linux_api.h File Reference

*Linux API prototypes. More...

#include <bits/linux_api.h>
#include <bits/linux_api_platform.h>
#include <stdint.h>
#include <linux/types.h>
#include <linux/posix_types.h>
#include <linux/time.h>
#include <linux/mman.h>
#include <linux/fcntl.h>
#include <linux/ioctl.h>
#include <linux/poll.h>

Go to the source code of this file.

Defines

#define __KERNEL_STRICT_NAMES
#define MAP_FAILED   ( ( void * ) -1 )
#define SEEK_SET   0

Typedefs

typedef __kernel_pid_t pid_t
typedef __kernel_suseconds_t suseconds_t
typedef __kernel_loff_t loff_t
typedef unsigned long nfds_t
typedef uint32_t useconds_t
typedef uint32_t socklen_t

Functions

 FILE_LICENCE (GPL2_OR_LATER)
long linux_syscall (int number,...)
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, 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)
const char * linux_strerror (int errnum)

Detailed Description

*

Linux API prototypes.

Most of the functions map directly to linux syscalls and are the equivalent of POSIX functions with the linux_ prefix removed.

Definition in file linux_api.h.


Define Documentation

Definition at line 36 of file linux_api.h.

#define MAP_FAILED   ( ( void * ) -1 )

Definition at line 51 of file linux_api.h.

#define SEEK_SET   0

Definition at line 52 of file linux_api.h.


Typedef Documentation

typedef __kernel_pid_t pid_t

Definition at line 39 of file linux_api.h.

typedef __kernel_suseconds_t suseconds_t

Definition at line 40 of file linux_api.h.

typedef __kernel_loff_t loff_t

Definition at line 41 of file linux_api.h.

typedef unsigned long nfds_t

Definition at line 47 of file linux_api.h.

Definition at line 48 of file linux_api.h.

Definition at line 49 of file linux_api.h.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER  )
long linux_syscall ( int  number,
  ... 
)
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,
off_t  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
}
const char* linux_strerror ( int  errnum)

Definition at line 158 of file linux_strerror.c.

References errors, and snprintf().

{
        static char errbuf[64];
        static int errors_size = sizeof(errors) / sizeof(*errors);
        
        if (errnum >= errors_size || errnum < 0) {
                snprintf(errbuf, sizeof(errbuf), "Error %#08x", errnum);
                return errbuf;
        } else {
                return errors[errnum];
        }
}