Permalink
Browse files

Step 5: rename and invoke wrapped functions.

  • Loading branch information...
Ben Laurie
Ben Laurie committed Apr 28, 2012
1 parent 12efce8 commit 21cbf9122dcbfdf0c9fafa1a98c3e88fa0009364
Showing with 59 additions and 8 deletions.
  1. +8 −0 contrib/bzip2/CONVERSION
  2. +45 −2 contrib/bzip2/bzip2.c
  3. +3 −3 contrib/bzip2/bzip2_wrapped.c
  4. +3 −3 contrib/bzip2/bzip2_wrapped.h
View
@@ -39,3 +39,11 @@
4. The remaining unused functions do not require authority, so simply
move them into the wrapped code.
5. Rename (so we don't accidentally invoke them direactly) and invoke
the wrapped functions, handing in the capability they require (so
far). If capability mode is not available, simply call the wrapped
functions directly.
Once this is done bzip2.c compiles cleanly once more. However, the
link fails.
View
@@ -223,8 +223,53 @@ static void compressedStreamEOF ( void ) NORETURN;
static void copyFileName ( Char*, Char* );
static void* myMalloc ( Int32 );
static void applySavedFileAttrToOutputFile ( IntNative fd );
static void unwrap_applySavedFileAttrToOutputFile(int fd);
static int output_fd;
static struct lc_capability caps[] = {
{ "applySavedFileAttrToOutputFile", unwrap_applySavedFileAttrToOutputFile },
};
// This is only needed to get the function types to match for
// lc_wrap_filter().
static int call_compressStream(FILE *stream, FILE *zStream) {
wrapped_compressStream(stream, zStream);
return 1;
}
static void compressStream(FILE *stream, FILE *zStream) {
if (!lc_available()) {
wrapped_compressStream(stream, zStream);
return;
}
output_fd = fileno(zStream);
lc_wrap_filter(call_compressStream, stream, zStream, caps, 1);
}
static int call_uncompressStream(FILE *zStream, FILE *stream) {
return wrapped_uncompressStream(zStream, stream);
}
static Bool uncompressStream(FILE *zStream, FILE *stream) {
if (!lc_available())
return wrapped_uncompressStream(zStream, stream);
output_fd = fileno(stream);
return lc_wrap_filter(call_uncompressStream, zStream, stream, caps, 1);
}
static int call_testStream(FILE *zStream, FILE *dummy) {
return wrapped_testStream(zStream);
}
static Bool testStream(FILE *zStream) {
if (!lc_available())
return wrapped_testStream(zStream);
return lc_wrap_filter(call_testStream, zStream, NULL, NULL, 0);
}
/*---------------------------------------------------*/
/*--- Error [non-] handling grunge ---*/
@@ -661,8 +706,6 @@ void applySavedFileAttrToOutputFile ( IntNative fd )
# endif
}
static int output_fd;
static void unwrap_applySavedFileAttrToOutputFile(int fd) {
int ofd;
@@ -102,7 +102,7 @@ Bool myfeof ( FILE* f )
/*---------------------------------------------*/
void compressStream ( FILE *stream, FILE *zStream )
void wrapped_compressStream ( FILE *stream, FILE *zStream )
{
BZFILE* bzf = NULL;
UChar ibuf[5000];
@@ -205,7 +205,7 @@ void compressStream ( FILE *stream, FILE *zStream )
/*---------------------------------------------*/
Bool uncompressStream ( FILE *zStream, FILE *stream )
Bool wrapped_uncompressStream ( FILE *zStream, FILE *stream )
{
BZFILE* bzf = NULL;
Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
@@ -325,7 +325,7 @@ Bool uncompressStream ( FILE *zStream, FILE *stream )
/*---------------------------------------------*/
Bool testStream ( FILE *zStream )
Bool wrapped_testStream ( FILE *zStream )
{
BZFILE* bzf = NULL;
Int32 bzerr, bzerr_dummy, ret, nread, streamNo, i;
@@ -1,6 +1,6 @@
typedef unsigned char Bool;
void compressStream ( FILE *stream, FILE *zStream );
Bool uncompressStream ( FILE *zStream, FILE *stream );
Bool testStream ( FILE *zStream );
void wrapped_compressStream ( FILE *stream, FILE *zStream );
Bool wrapped_uncompressStream ( FILE *zStream, FILE *stream );
Bool wrapped_testStream ( FILE *zStream );

0 comments on commit 21cbf91

Please sign in to comment.