aboutsummaryrefslogtreecommitdiff
path: root/src/survive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/survive.c')
-rwxr-xr-xsrc/survive.c71
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