Skip to content

Commit

Permalink
Add per-file error identifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brown committed Jul 24, 2007
1 parent f0acd8d commit 9aa61ad
Show file tree
Hide file tree
Showing 16 changed files with 393 additions and 178 deletions.
31 changes: 31 additions & 0 deletions src/arch/i386/include/bits/errfile.h
@@ -0,0 +1,31 @@
#ifndef _BITS_ERRFILE_H
#define _BITS_ERRFILE_H

/**
* @addtogroup errfile Error file identifiers
* @{
*/

#define ERRFILE_umalloc ( ERRFILE_ARCH | ERRFILE_CORE | 0x00000000 )
#define ERRFILE_memmap ( ERRFILE_ARCH | ERRFILE_CORE | 0x00010000 )
#define ERRFILE_pnpbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00020000 )
#define ERRFILE_smbios ( ERRFILE_ARCH | ERRFILE_CORE | 0x00030000 )
#define ERRFILE_biosint ( ERRFILE_ARCH | ERRFILE_CORE | 0x00040000 )
#define ERRFILE_int13 ( ERRFILE_ARCH | ERRFILE_CORE | 0x00050000 )

#define ERRFILE_bootsector ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00000000 )
#define ERRFILE_bzimage ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00010000 )
#define ERRFILE_eltorito ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00020000 )
#define ERRFILE_multiboot ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00030000 )
#define ERRFILE_nbi ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00040000 )
#define ERRFILE_pxe_image ( ERRFILE_ARCH | ERRFILE_IMAGE | 0x00050000 )

#define ERRFILE_undi ( ERRFILE_ARCH | ERRFILE_NET | 0x00000000 )
#define ERRFILE_undiload ( ERRFILE_ARCH | ERRFILE_NET | 0x00010000 )
#define ERRFILE_undinet ( ERRFILE_ARCH | ERRFILE_NET | 0x00020000 )
#define ERRFILE_undionly ( ERRFILE_ARCH | ERRFILE_NET | 0x00030000 )
#define ERRFILE_undirom ( ERRFILE_ARCH | ERRFILE_NET | 0x00040000 )

/** @} */

#endif /* _BITS_ERRFILE_H */
20 changes: 20 additions & 0 deletions src/core/iobuf.c
Expand Up @@ -17,6 +17,7 @@
*/

#include <stdint.h>
#include <errno.h>
#include <gpxe/malloc.h>
#include <gpxe/iobuf.h>

Expand Down Expand Up @@ -72,3 +73,22 @@ void free_iob ( struct io_buffer *iobuf ) {
( iobuf->end - iobuf->head ) + sizeof ( *iobuf ) );
}
}

/**
* Ensure I/O buffer has sufficient headroom
*
* @v iobuf I/O buffer
* @v len Required headroom
*
* This function currently only checks for the required headroom; it
* does not reallocate the I/O buffer if required. If we ever have a
* code path that requires this functionality, it's a fairly trivial
* change to make.
*/
int iob_ensure_headroom ( struct io_buffer *iobuf, size_t len ) {

if ( iob_headroom ( iobuf ) >= len )
return 0;
return -ENOBUFS;
}

1 change: 1 addition & 0 deletions src/crypto/axtls_aes.c
@@ -1,5 +1,6 @@
#include "crypto/axtls/crypto.h"
#include <string.h>
#include <errno.h>
#include <gpxe/crypto.h>
#include <gpxe/aes.h>

Expand Down
24 changes: 24 additions & 0 deletions src/crypto/cipher.c
@@ -0,0 +1,24 @@
#include <stdint.h>
#include <errno.h>
#include <gpxe/crypto.h>

int cipher_encrypt ( struct crypto_algorithm *crypto,
void *ctx, const void *src, void *dst,
size_t len ) {
if ( ( len & ( crypto->blocksize - 1 ) ) ) {
return -EINVAL;
}
crypto->encode ( ctx, src, dst, len );
return 0;
}

int cipher_decrypt ( struct crypto_algorithm *crypto,
void *ctx, const void *src, void *dst,
size_t len ) {
if ( ( len & ( crypto->blocksize - 1 ) ) ) {
return -EINVAL;
}
crypto->decode ( ctx, src, dst, len );
return 0;
}

15 changes: 6 additions & 9 deletions src/hci/strerror.c
Expand Up @@ -60,15 +60,7 @@ static struct errortab * find_closest_error ( int errno ) {
/* Second, try masking off the gPXE-specific bit and seeing if
* we have an entry for the generic POSIX error message.
*/
if ( ( errortab = find_error ( errno, 0x0000ffff ) ) != NULL )
return errortab;

/* Lastly, try masking off the POSIX bits and seeing if we
* have a match just based on the PXENV component. This
* allows us to report errors from underlying PXE stacks.
*/
if ( ( errortab = find_error ( ( errno & 0x000000ff ),
0xffff00ff ) ) != NULL )
if ( ( errortab = find_error ( errno, 0x4f0000ff ) ) != NULL )
return errortab;

return NULL;
Expand Down Expand Up @@ -109,6 +101,10 @@ const char * strerror ( int errno ) {
return errbuf;
}

/* Do not include ERRFILE portion in the numbers in the error table */
#undef ERRFILE
#define ERRFILE 0

/** The most common errors */
struct errortab common_errors[] __errortab = {
{ 0, "No error" },
Expand All @@ -121,4 +117,5 @@ struct errortab common_errors[] __errortab = {
{ ENETUNREACH, "Network unreachable" },
{ ETIMEDOUT, "Connection timed out" },
{ EPIPE, "Broken pipe" },
{ ECANCELED, "Operation cancelled" },
};
3 changes: 3 additions & 0 deletions src/include/compiler.h
Expand Up @@ -267,6 +267,9 @@ extern void dbg_hex_dump_da ( unsigned long dispaddr,
#define NDEBUG
#endif

/** Select file identifier for errno.h (if used) */
#define ERRFILE PREFIX_OBJECT ( ERRFILE_ )

/** Declare a data structure as packed. */
#define PACKED __attribute__ (( packed ))

Expand Down

0 comments on commit 9aa61ad

Please sign in to comment.