Пример #1
0
void generate_entry( FILE *file, struct function *f, char *entry )
{
	fprintf(file,"extern \"C\" %s %s( %s )\n{\n",type_string(f->type),entry,param_string(f->params));

	fprintf(file,"\t%s (*fptr)(%s);\n",type_string(f->type),param_string(f->params));
	if(!is_void(f->type)) {
		fprintf(file,"\t%s result;\n",type_string(f->type));
	}
	write_vararg_decls( file, f->params );

	fprintf(file,"\tbypass_layer_init();\n");
    // PZK 8/7/07: changed int to intptr_t for 64-bit compatibility
	fprintf(file,"\tfptr = (%s(*)(%s)) layer_lookup( \"bypass_agent_action_%s\", \"%s\", (intptr_t) %s );\n",type_string(f->type),param_string(f->params),f->name->text,entry,entry);
	fprintf(file,"\tif(!fptr) fptr = %s;\n",entry);
	fprintf(file,"\tlayer_descend();\n");
	if(!is_void(f->type)) {
		fprintf(file,"\tresult = ");
	} else {
		fprintf(file,"\t");
	}
	fprintf(file,"(*fptr) ( %s );\n",arg_string(f->params));
	fprintf(file,"\tlayer_ascend();\n");
	if(!is_void(f->type)) {
		fprintf(file,"\treturn result;\n");
	}

	/* special case: a switch for _exit() or exit() must fall back on a fatal message */
	if(!strcmp(f->name->text,"exit") || !strcmp(f->name->text,"_exit") ) {
		fprintf(file,"\tbypass_fatal(\"exit() returned without exiting!\");\n");
	}
	fprintf(file,"}\n\n");
}
Пример #2
0
char * ftype_string( struct function *f )
{
	char *buffer = malloc(STRING_BUFFER_SIZE*10);

	sprintf(buffer,"%s (*)(%s)",
		type_string(f->type),
		param_string(f->params));

	return buffer;
}
Пример #3
0
void write_dynamic_call( FILE *file, struct function *f )
{
	/* Declare a library handle, open it if needed */
	fprintf(file,"\t\t\tstatic void *handle = 0;\n");
	fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.so\");\n",f->options->library->text);
	fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.sl\");\n",f->options->library->text);
	fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.so.6\");\n",f->options->library->text);
	fprintf(file,"\t\t\tif(!handle) bypass_call_error(BYPASS_CALL_%s,\"can't find library\");\n\n",f->name->text);

	/* Declare a function pointer, look it up if needed */
	fprintf(file,"\t\t\tstatic %s (*fptr)( %s ) = 0;\n",type_string(f->type),param_string(f->params));
	fprintf(file,"\t\t\tif(!fptr) fptr = (%s(*)(%s)) bypass_library_lookup(handle,\"%s\");\n",type_string(f->type),param_string(f->params),pattern_complete(f->options->local_name->text,f->name->text));
	fprintf(file,"\t\t\tif(!fptr) bypass_call_error(BYPASS_CALL_%s,\"can't find procedure in library\");\n",f->name->text);

	/* Otherwise, invoke the function */

	if(!is_void(f->type)) {
		fprintf(file,"\t\t\tresult = ");
	} else {
		fprintf(file,"\t\t\t");
	}
	fprintf(file,"fptr( %s );\n",arg_string(f->params));
}
Пример #4
0
static void check_string_elem( Telem* elem )
{
  if (!verify_nparams( 2, 2, elem )) return;
  param_string( elem->params, 1 );
  param_elem( elem->params, 2, 0 );
}
Пример #5
0
static void check_string_cb( Telem* elem )
{
  if (!verify_nparams( 2, 2, elem )) return;
  param_string( elem->params, 1 );
  param_callback( elem->params, 2 );
}
Пример #6
0
static void check_string( Telem* elem )
{
  if (!verify_nparams( 1, 1, elem )) return;
  param_string( elem->params, 1 );
}
Пример #7
0
void generate_agent_action( FILE *file, struct function *f )
{
	fprintf(file,"extern \"C\" %s bypass_agent_action_%s( %s )\n{\n",type_string(f->type),f->name->text,param_string(f->params));
	
	write_vararg_decls(file,f->params);

	if(f->agent_action) {
		fprintf(file,"\t%s\n",f->agent_action->text );
	} else {

		if(!is_void(f->type)) {
			fprintf(file,"\treturn ");
		}

		fprintf(file,"bypass_shadow_%s( %s );\n",pattern_complete(f->options->remote_name->text,f->name->text),arg_string_noconst(f->params));
	}

	fprintf(file,"\n}\n\n");

	if( f->options->instead ) {
		generate_agent_action( file, f->options->instead );
	}
}
Пример #8
0
void write_static_call( FILE *file, struct function *f )
{
	fprintf(file,"\t\t\textern %s %s (%s);\n",type_string(f->type),upper_string(pattern_complete(f->options->local_name->text,f->name->text)),param_string(f->params));

	if(!is_void(f->type)) {
		fprintf(file,"\t\t\tresult = ");
	} else {
		fprintf(file,"\t\t\t");
	}
	fprintf(file,"%s( %s );\n",upper_string(pattern_complete(f->options->local_name->text,f->name->text)),arg_string(f->params));
}
Пример #9
0
void generate_switch_prototype( FILE *file, struct function *f )
{
	fprintf(file,"extern \"C\" %s %s( %s );\n",type_string(f->type),f->name->text,param_string(f->params));
}