iPXE
fault.h
Go to the documentation of this file.
00001 #ifndef _IPXE_FAULT_H
00002 #define _IPXE_FAULT_H
00003 
00004 /** @file
00005  *
00006  * Fault injection
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <config/fault.h>
00014 
00015 extern int inject_fault_nonzero ( unsigned int rate );
00016 extern void inject_corruption_nonzero ( unsigned int rate, const void *data,
00017                                         size_t len );
00018 
00019 /**
00020  * Inject fault with a specified probability
00021  *
00022  * @v rate              Reciprocal of fault probability (zero for no faults)
00023  * @ret rc              Return status code
00024  */
00025 static inline __attribute__ (( always_inline )) int
00026 inject_fault ( unsigned int rate ) {
00027 
00028         /* Force dead code elimination in non-fault-injecting builds */
00029         if ( rate == 0 )
00030                 return 0;
00031 
00032         return inject_fault_nonzero ( rate );
00033 }
00034 
00035 /**
00036  * Corrupt data with a specified probability
00037  *
00038  * @v rate              Reciprocal of fault probability (zero for no faults)
00039  * @v data              Data
00040  * @v len               Length of data
00041  * @ret rc              Return status code
00042  */
00043 static inline __attribute__ (( always_inline )) void
00044 inject_corruption ( unsigned int rate, const void *data, size_t len ) {
00045 
00046         /* Force dead code elimination in non-fault-injecting builds */
00047         if ( rate == 0 )
00048                 return;
00049 
00050         return inject_corruption_nonzero ( rate, data, len );
00051 }
00052 
00053 #endif /* _IPXE_FAULT_H */