diff options
author | Joshua Allen <axlecrusher@gmail.com> | 2017-03-15 19:26:46 -0400 |
---|---|---|
committer | Joshua Allen <axlecrusher@gmail.com> | 2017-03-15 19:26:46 -0400 |
commit | 1388d54117ff780b7fadd4fd682b6def569838fa (patch) | |
tree | 3737760c889eeaf0bd7305becc943d859ae65d96 /src/survive.c | |
parent | 62cef8aec06638bd006eaef46700f491750fc108 (diff) | |
parent | 9bd0a0d949639b516d28091f57862ac5e59e65da (diff) | |
download | libsurvive-1388d54117ff780b7fadd4fd682b6def569838fa.tar.gz libsurvive-1388d54117ff780b7fadd4fd682b6def569838fa.tar.bz2 |
Merge branch 'master' of github.com:cnlohr/libsurvive
Conflicts:
src/survive_data.c
Diffstat (limited to 'src/survive.c')
-rwxr-xr-x | src/survive.c | 71 |
1 files changed, 59 insertions, 12 deletions
diff --git a/src/survive.c b/src/survive.c index 6d49d55..1b5bed1 100755 --- a/src/survive.c +++ b/src/survive.c @@ -6,10 +6,25 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <zlib.h> #include "survive_config.h" +#ifdef RUNTIME_SYMNUM +#include <symbol_enumerator.h> +static int did_runtime_symnum; +int SymnumCheck( const char * path, const char * name, void * location, long size ) +{ + if( strncmp( name, "REGISTER", 8 ) == 0 ) + { + typedef void (*sf)(); + sf fn = (sf)location; + fn(); + } + return 0; +} + +#endif + static void survivefault( struct SurviveContext * ctx, const char * fault ) { fprintf( stderr, "Error: %s\n", fault ); @@ -24,6 +39,14 @@ static void survivenote( struct SurviveContext * ctx, const char * fault ) SurviveContext * survive_init( int headless ) { +#ifdef RUNTIME_SYMNUM + if( !did_runtime_symnum ) + { + EnumerateSymbols( SymnumCheck ); + did_runtime_symnum = 1; + } +#endif + int r = 0; int i = 0; SurviveContext * ctx = calloc( 1, sizeof( SurviveContext ) ); @@ -211,6 +234,40 @@ int survive_poll( struct SurviveContext * ctx ) } +struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, const char * name ) +{ + int i; + for( i = 0; i < ctx->objs_ct; i++ ) + { + if( strcmp( ctx->objs[i]->codename, name ) == 0 ) + return ctx->objs[i]; + } + return 0; +} + +#ifdef NOZLIB + +#include <puff.h> + + +int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ) +{ + unsigned long ol = outlen; + unsigned long il = inlen; + int ret = puff( output, &ol, input, &il ); + if( ret == 0 ) + return ol; + else + { + SV_INFO( "puff returned error code %d\n", ret ); + return -5; + } +} + +#else + +#include <zlib.h> + int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ) { z_stream zs; //Zlib stream. May only be used by configuration at beginning and by USB thread periodically. @@ -233,14 +290,4 @@ int survive_simple_inflate( struct SurviveContext * ctx, const char * input, int return len; } -struct SurviveObject * survive_get_so_by_name( struct SurviveContext * ctx, const char * name ) -{ - int i; - for( i = 0; i < ctx->objs_ct; i++ ) - { - if( strcmp( ctx->objs[i]->codename, name ) == 0 ) - return ctx->objs[i]; - } - return 0; -} - +#endif |