iPXE
Functions | Variables
fault.h File Reference

Fault injection. More...

#include <stdint.h>
#include <config/fault.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
int inject_fault_nonzero (unsigned int rate)
 Inject fault with a specified probability. More...
 
void inject_corruption_nonzero (unsigned int rate, const void *data, size_t len)
 Corrupt data with a specified probability. More...
 
static __attribute__ ((always_inline)) int inject_fault(unsigned int rate)
 Inject fault with a specified probability. More...
 
return inject_corruption_nonzero (rate, data, len)
 

Variables

static const void * data
 
static const void size_t len
 

Detailed Description

Fault injection.

Definition in file fault.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ inject_fault_nonzero()

int inject_fault_nonzero ( unsigned int  rate)

Inject fault with a specified probability.

Parameters
rateReciprocal of fault probability (must be non-zero)
Return values
rcReturn status code

Definition at line 42 of file fault.c.

42  {
43 
44  /* Do nothing unless we want to inject a fault now */
45  if ( ( random() % rate ) != 0 )
46  return 0;
47 
48  /* Generate error number here so that faults can be injected
49  * into files that don't themselves have error file
50  * identifiers (via errfile.h).
51  */
52  return -EFAULT;
53 }
#define EFAULT
Bad address.
Definition: errno.h:393
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:30

References EFAULT, and random().

Referenced by __attribute__(), and inject_corruption_nonzero().

◆ inject_corruption_nonzero() [1/2]

void inject_corruption_nonzero ( unsigned int  rate,
const void *  data,
size_t  len 
)

Corrupt data with a specified probability.

Parameters
rateReciprocal of fault probability (must be non-zero)
dataData
lenLength of data
Return values
rcReturn status code

Definition at line 63 of file fault.c.

64  {
65  uint8_t *writable;
66  size_t offset;
67 
68  /* Do nothing if we have no data to corrupt */
69  if ( ! len )
70  return;
71 
72  /* Do nothing unless we want to inject a fault now */
73  if ( ! inject_fault_nonzero ( rate ) )
74  return;
75 
76  /* Get a writable pointer to the nominally read-only data */
77  writable = ( ( uint8_t * ) data );
78 
79  /* Pick a random victim byte and zap it */
80  offset = ( random() % len );
81  writable[offset] ^= random();
82 }
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
long int random(void)
Generate a pseudo-random number between 0 and 2147483647L or 2147483562?
Definition: random.c:30
unsigned char uint8_t
Definition: stdint.h:10
int inject_fault_nonzero(unsigned int rate)
Inject fault with a specified probability.
Definition: fault.c:42
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12

References data, inject_fault_nonzero(), len, offset, and random().

◆ __attribute__()

static __attribute__ ( (always_inline)  )
inlinestatic

Inject fault with a specified probability.

Corrupt data with a specified probability.

Parameters
rateReciprocal of fault probability (zero for no faults)
Return values
rcReturn status code
Parameters
rateReciprocal of fault probability (zero for no faults)
dataData
lenLength of data
Return values
rcReturn status code

Definition at line 25 of file fault.h.

26  {
27 
28  /* Force dead code elimination in non-fault-injecting builds */
29  if ( rate == 0 )
30  return 0;
31 
32  return inject_fault_nonzero ( rate );
33 }
int inject_fault_nonzero(unsigned int rate)
Inject fault with a specified probability.
Definition: fault.c:42

References inject_fault_nonzero().

◆ inject_corruption_nonzero() [2/2]

return inject_corruption_nonzero ( rate  ,
data  ,
len   
)

Variable Documentation

◆ data

const void* data

Definition at line 44 of file fault.h.

◆ len

const void size_t len
Initial value:
{
if ( rate == 0 )
return

Definition at line 44 of file fault.h.