iPXE
Macros | Typedefs | Functions
linux_api.h File Reference
#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.

Macros

#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.

Macro Definition Documentation

◆ __KERNEL_STRICT_NAMES

#define __KERNEL_STRICT_NAMES

Definition at line 36 of file linux_api.h.

◆ MAP_FAILED

#define MAP_FAILED   ( ( void * ) -1 )

Definition at line 51 of file linux_api.h.

◆ SEEK_SET

#define SEEK_SET   0

Definition at line 52 of file linux_api.h.

Typedef Documentation

◆ pid_t

typedef __kernel_pid_t pid_t

Definition at line 39 of file linux_api.h.

◆ suseconds_t

typedef __kernel_suseconds_t suseconds_t

Definition at line 40 of file linux_api.h.

◆ loff_t

typedef __kernel_loff_t loff_t

Definition at line 41 of file linux_api.h.

◆ nfds_t

typedef unsigned long nfds_t

Definition at line 47 of file linux_api.h.

◆ useconds_t

Definition at line 48 of file linux_api.h.

◆ socklen_t

Definition at line 49 of file linux_api.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ linux_syscall()

long linux_syscall ( int  number,
  ... 
)

◆ linux_open()

int linux_open ( const char *  pathname,
int  flags 
)

Definition at line 32 of file linux_api.c.

32  {
33  return linux_syscall ( __NR_open, pathname, flags );
34 }
long linux_syscall(int number,...)
uint8_t flags
Flags.
Definition: ena.h:18

References flags, and linux_syscall().

◆ linux_close()

int linux_close ( int  fd)

Definition at line 36 of file linux_api.c.

36  {
37  return linux_syscall ( __NR_close, fd );
38 }
long linux_syscall(int number,...)

References linux_syscall().

◆ linux_lseek()

off_t linux_lseek ( int  fd,
off_t  offset,
int  whence 
)

Definition at line 40 of file linux_api.c.

40  {
41  return linux_syscall ( __NR_lseek, fd, offset, whence );
42 }
long linux_syscall(int number,...)
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259

References linux_syscall(), and offset.

◆ linux_read()

__kernel_ssize_t linux_read ( int  fd,
void *  buf,
__kernel_size_t  count 
)

Definition at line 44 of file linux_api.c.

44  {
45  return linux_syscall ( __NR_read, fd, buf, count );
46 }
long linux_syscall(int number,...)
uint16_t count
Number of entries.
Definition: ena.h:22

References count, and linux_syscall().

◆ linux_write()

__kernel_ssize_t linux_write ( int  fd,
const void *  buf,
__kernel_size_t  count 
)

Definition at line 48 of file linux_api.c.

49  {
50  return linux_syscall ( __NR_write, fd, buf, count );
51 }
long linux_syscall(int number,...)
uint16_t count
Number of entries.
Definition: ena.h:22

References count, and linux_syscall().

◆ linux_fcntl()

int linux_fcntl ( int  fd,
int  cmd,
  ... 
)

Definition at line 53 of file linux_api.c.

53  {
54  long arg;
55  va_list list;
56 
57  va_start ( list, cmd );
58  arg = va_arg ( list, long );
59  va_end ( list );
60 
61  return linux_syscall ( __NR_fcntl, fd, cmd, arg );
62 }
#define va_end(ap)
Definition: stdarg.h:9
long linux_syscall(int number,...)
#define va_arg(ap, type)
Definition: stdarg.h:8
__builtin_va_list va_list
Definition: stdarg.h:6
#define va_start(ap, last)
Definition: stdarg.h:7
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29

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

◆ linux_ioctl()

int linux_ioctl ( int  fd,
int  request,
  ... 
)

Definition at line 64 of file linux_api.c.

64  {
65  void *arg;
66  va_list list;
67 
68  va_start ( list, request );
69  arg = va_arg ( list, void * );
70  va_end ( list );
71 
72  return linux_syscall ( __NR_ioctl, fd, request, arg );
73 }
#define va_end(ap)
Definition: stdarg.h:9
long linux_syscall(int number,...)
#define va_arg(ap, type)
Definition: stdarg.h:8
__builtin_va_list va_list
Definition: stdarg.h:6
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
#define va_start(ap, last)
Definition: stdarg.h:7

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

◆ linux_poll()

int linux_poll ( struct pollfd *  fds,
nfds_t  nfds,
int  timeout 
)

Definition at line 75 of file linux_api.c.

75  {
76  return linux_syscall ( __NR_poll, fds, nfds, timeout );
77 }
long linux_syscall(int number,...)
void timeout(int)

References linux_syscall(), and timeout().

◆ linux_nanosleep()

int linux_nanosleep ( const struct timespec *  req,
struct timespec *  rem 
)

Definition at line 79 of file linux_api.c.

79  {
80  return linux_syscall ( __NR_nanosleep, req, rem );
81 }
long linux_syscall(int number,...)

References linux_syscall().

Referenced by linux_usleep().

◆ linux_usleep()

int linux_usleep ( useconds_t  usec)

Definition at line 83 of file linux_api.c.

83  {
84  struct timespec ts = {
85  .tv_sec = ( ( long ) ( usec / 1000000 ) ),
86  .tv_nsec = ( ( long ) ( usec % 1000000 ) * 1000UL ),
87  };
88 
89  return linux_nanosleep ( &ts, NULL );
90 }
int linux_nanosleep(const struct timespec *req, struct timespec *rem)
Definition: linux_api.c:79
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References linux_nanosleep(), and NULL.

◆ linux_gettimeofday()

int linux_gettimeofday ( struct timeval *  tv,
struct timezone *  tz 
)

Definition at line 92 of file linux_api.c.

92  {
93  return linux_syscall ( __NR_gettimeofday, tv, tz );
94 }
long linux_syscall(int number,...)

References linux_syscall().

◆ linux_mmap()

void* linux_mmap ( void *  addr,
__kernel_size_t  length,
int  prot,
int  flags,
int  fd,
off_t  offset 
)

◆ linux_mremap()

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.

103  {
104  return ( void * ) linux_syscall ( __NR_mremap, old_address, old_size,
105  new_size, flags );
106 }
long linux_syscall(int number,...)
uint8_t flags
Flags.
Definition: ena.h:18

References flags, and linux_syscall().

◆ linux_munmap()

int linux_munmap ( void *  addr,
__kernel_size_t  length 
)

Definition at line 108 of file linux_api.c.

108  {
109  return linux_syscall ( __NR_munmap, addr, length );
110 }
u16 length
Definition: sky2.h:9
long linux_syscall(int number,...)
u32 addr
Definition: sky2.h:8

References addr, length, and linux_syscall().

◆ linux_socket()

int linux_socket ( int  domain,
int  type_,
int  protocol 
)

Definition at line 112 of file linux_api.c.

112  {
113 #ifdef __NR_socket
114  return linux_syscall ( __NR_socket, domain, type_, protocol );
115 #else
116 #ifndef SOCKOP_socket
117 # define SOCKOP_socket 1
118 #endif
119  unsigned long sc_args[] = { domain, type_, protocol };
120  return linux_syscall ( __NR_socketcall, SOCKOP_socket, sc_args );
121 #endif
122 }
#define SOCKOP_socket
long linux_syscall(int number,...)
uint16_t protocol
Protocol ID.
Definition: stp.h:18
struct ntlm_data domain
Domain name.
Definition: ntlm.h:16

References domain, linux_syscall(), protocol, and SOCKOP_socket.

◆ linux_bind()

int linux_bind ( int  fd,
const struct sockaddr addr,
socklen_t  addrlen 
)

Definition at line 124 of file linux_api.c.

124  {
125 #ifdef __NR_bind
126  return linux_syscall ( __NR_bind, fd, addr, addrlen );
127 #else
128 #ifndef SOCKOP_bind
129 # define SOCKOP_bind 2
130 #endif
131  unsigned long sc_args[] = { fd, (unsigned long)addr, addrlen };
132  return linux_syscall ( __NR_socketcall, SOCKOP_bind, sc_args );
133 #endif
134 }
#define SOCKOP_bind
long linux_syscall(int number,...)
u32 addr
Definition: sky2.h:8

References addr, linux_syscall(), and SOCKOP_bind.

◆ linux_sendto()

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.

137  {
138 #ifdef __NR_sendto
139  return linux_syscall ( __NR_sendto, fd, buf, len, flags,
140  daddr, addrlen );
141 #else
142 #ifndef SOCKOP_sendto
143 # define SOCKOP_sendto 11
144 #endif
145  unsigned long sc_args[] = { fd, (unsigned long)buf, len,
146  flags, (unsigned long)daddr, addrlen };
147  return linux_syscall ( __NR_socketcall, SOCKOP_sendto, sc_args );
148 #endif
149 }
#define SOCKOP_sendto
long linux_syscall(int number,...)
uint32_t len
Length.
Definition: ena.h:14
uint8_t flags
Flags.
Definition: ena.h:18

References flags, len, linux_syscall(), and SOCKOP_sendto.

◆ linux_strerror()

const char* linux_strerror ( int  errnum)

Definition at line 158 of file linux_strerror.c.

159 {
160  static char errbuf[64];
161  static int errors_size = sizeof(errors) / sizeof(*errors);
162 
163  if (errnum >= errors_size || errnum < 0) {
164  snprintf(errbuf, sizeof(errbuf), "Error %#08x", errnum);
165  return errbuf;
166  } else {
167  return errors[errnum];
168  }
169 }
static const char * errors[]
Error names from glibc.
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

References errors, and snprintf().