Skip to content

Commit

Permalink
Step 13: define unwrappers.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben Laurie committed Apr 28, 2012
1 parent df12033 commit 5c5ef33
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
6 changes: 6 additions & 0 deletions contrib/bzip2/CONVERSION
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@
we wrapped earlier. Luckily, there's a list in bzip2_wrapped.h, so we wrapped earlier. Luckily, there's a list in bzip2_wrapped.h, so
we'll just haul those in and get back on track with errors. Note we'll just haul those in and get back on track with errors. Note
that the unwrap functions just take a file descriptor. that the unwrap functions just take a file descriptor.

13. Define the unwrappers. Note that you have to remember to add them
to caps[] and adjust the calls where it is used. Again, an IDL
would fix this.

Now we're done.
64 changes: 60 additions & 4 deletions contrib/bzip2/bzip2.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ void wrapped_clear_outputHandleJustInCase(void) {
outputHandleJustInCase = NULL; outputHandleJustInCase = NULL;
} }


static
void unwrap_clear_outputHandleJustInCase ( int fd ) {
wrapped_clear_outputHandleJustInCase();
lc_write_void(fd);
}

#undef workFactor #undef workFactor
#define workFactor _workFactor #define workFactor _workFactor
Int32 workFactor; Int32 workFactor;
Expand All @@ -225,9 +231,18 @@ static void unwrap_compressedStreamEOF ( int fd ) NORETURN;


static int output_fd; static int output_fd;


#define CAP(x) { #x, unwrap_##x }
static struct lc_capability caps[] = { static struct lc_capability caps[] = {
{ "applySavedFileAttrToOutputFile", unwrap_applySavedFileAttrToOutputFile }, CAP(applySavedFileAttrToOutputFile),
CAP(clear_outputHandleJustInCase),
CAP(configError),
CAP(outOfMemory),
CAP(ioError),
CAP(panic),
CAP(crcError),
CAP(compressedStreamEOF),
}; };
#undef CAP


// This is only needed to get the function types to match for // This is only needed to get the function types to match for
// lc_wrap_filter(). // lc_wrap_filter().
Expand All @@ -243,7 +258,8 @@ static void compressStream(FILE *stream, FILE *zStream) {
} }


output_fd = fileno(zStream); output_fd = fileno(zStream);
lc_wrap_filter(call_compressStream, stream, zStream, caps, 1); // FIXME: this only needs a subset of caps
lc_wrap_filter(call_compressStream, stream, zStream, caps, 8);
} }


static int call_uncompressStream(FILE *zStream, FILE *stream) { static int call_uncompressStream(FILE *zStream, FILE *stream) {
Expand All @@ -255,7 +271,7 @@ static Bool uncompressStream(FILE *zStream, FILE *stream) {
return wrapped_uncompressStream(zStream, stream); return wrapped_uncompressStream(zStream, stream);


output_fd = fileno(stream); output_fd = fileno(stream);
return lc_wrap_filter(call_uncompressStream, zStream, stream, caps, 1); return lc_wrap_filter(call_uncompressStream, zStream, stream, caps, 8);
} }


static int call_testStream(FILE *zStream, FILE *dummy) { static int call_testStream(FILE *zStream, FILE *dummy) {
Expand All @@ -266,7 +282,8 @@ static Bool testStream(FILE *zStream) {
if (!lc_available()) if (!lc_available())
return wrapped_testStream(zStream); return wrapped_testStream(zStream);


return lc_wrap_filter(call_testStream, zStream, NULL, NULL, 0); // FIXME: this only needs a subset of caps
return lc_wrap_filter(call_testStream, zStream, NULL, caps, 8);
} }


/*---------------------------------------------------*/ /*---------------------------------------------------*/
Expand Down Expand Up @@ -381,6 +398,17 @@ void wrapped_panic ( const Char* s )
cleanUpAndFail( 3 ); cleanUpAndFail( 3 );
} }


static
void unwrap_panic ( int fd ) {
int wrapped_errno;
char *str;

lc_read_int( fd, &wrapped_errno );
lc_read_string( fd, &str, 1024 );
wrapped_panic( str );
/* NOTREACHED */
}



/*---------------------------------------------*/ /*---------------------------------------------*/
void wrapped_crcError ( void ) void wrapped_crcError ( void )
Expand All @@ -393,6 +421,13 @@ void wrapped_crcError ( void )
cleanUpAndFail( 2 ); cleanUpAndFail( 2 );
} }


static
void unwrap_crcError ( int fd ) {
wrapped_crcError();
/* NOTREACHED */
}




/*---------------------------------------------*/ /*---------------------------------------------*/
void wrapped_compressedStreamEOF ( void ) void wrapped_compressedStreamEOF ( void )
Expand All @@ -409,6 +444,11 @@ void wrapped_compressedStreamEOF ( void )
cleanUpAndFail( 2 ); cleanUpAndFail( 2 );
} }


static
void unwrap_compressedStreamEOF ( int fd ) {
wrapped_crcError();
/* NOTREACHED */
}


/*---------------------------------------------*/ /*---------------------------------------------*/
void wrapped_ioError ( void ) void wrapped_ioError ( void )
Expand All @@ -422,6 +462,12 @@ void wrapped_ioError ( void )
cleanUpAndFail( 1 ); cleanUpAndFail( 1 );
} }


static
void unwrap_ioError ( int fd ) {
wrapped_ioError();
/* NOTREACHED */
}



/*---------------------------------------------*/ /*---------------------------------------------*/
static static
Expand Down Expand Up @@ -500,6 +546,11 @@ void wrapped_outOfMemory ( void )
cleanUpAndFail(1); cleanUpAndFail(1);
} }


static
void unwrap_outOfMemory ( int fd ) {
wrapped_outOfMemory();
/* NOTREACHED */
}


/*---------------------------------------------*/ /*---------------------------------------------*/
void wrapped_configError ( void ) void wrapped_configError ( void )
Expand All @@ -514,6 +565,11 @@ void wrapped_configError ( void )
exit(exitValue); exit(exitValue);
} }


static
void unwrap_configError ( int fd ) {
wrapped_configError();
/* NOTREACHED */
}


/*---------------------------------------------------*/ /*---------------------------------------------------*/
/*--- The main driver machinery ---*/ /*--- The main driver machinery ---*/
Expand Down
2 changes: 1 addition & 1 deletion contrib/bzip2/capsicum.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static size_t lc_full_read(int fd, void *buffer, size_t count) {
return n; return n;
} }


static int lc_read_string(int fd, char **result, uint32_t max) { int lc_read_string(int fd, char **result, uint32_t max) {
uint32_t size; uint32_t size;


// FIXME: check for errors // FIXME: check for errors
Expand Down
3 changes: 2 additions & 1 deletion contrib/bzip2/capsicum.h
Original file line number Original file line Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <stdio.h> #include <stdio.h>
#include <sys/types.h>


int lc_available(void); int lc_available(void);


Expand All @@ -17,4 +18,4 @@ int lc_wrap_filter(int (*func)(FILE *in, FILE *out), FILE *in, FILE *out,


void lc_write_void(int fd); void lc_write_void(int fd);
int lc_read_int(int fd, int *result); int lc_read_int(int fd, int *result);

int lc_read_string(int fd, char **result, uint32_t max);

0 comments on commit 5c5ef33

Please sign in to comment.