Example #1
0
// Link module to CHDK core code.
// Functions and variables to link to are mapped via the symbol_hash_table array.
// The link information in the module comprises 'import_count' int values (4 bytes each)
// grouped into blocks. Each block is defined as:
//      - function / variable symbol hash
//      - N x int values, each value specifies the offset in the module to link
// The value of N is stored in the top 8 bits of the first value in list.
// Each location to link is assumed to be a pointer (4 bytes) into the CHDK core memory.
// To update each link location add the initial value stored to the link address found in the symbol table.
static int module_do_imports(flat_hdr* flat, void* relocbuf, uint32_t import_count)
{
    int i;
    unsigned char* buf = (unsigned char*)flat;  // base address of module in memory
    uint32_t* rbuf = (uint32_t*)relocbuf;       // link array

    for (i=0; i < import_count;)
    {
        // Find CHDK address of symbol via hash value, if not found return error
        int importaddress = (int)module_find_symbol_address(rbuf[i++]);
        if (importaddress == 0) return 0;

        // Get number of locations in module to link
        int cnt = rbuf[i] >> 24;

        for (; cnt>0; cnt--)
        {
            // Get offset into module (exclude count value)
            uint32_t offs = rbuf[i++] & 0x00FFFFFF;
            // Add initial value at location to symbol address
            *(uint32_t*)(buf+offs) += importaddress;
        }
    }  
    return 1;
}
Example #2
0
//---------------------------------------------------------
// PURPOSE:   Bind module symbols with chdk. 
//		Required function
// PARAMETERS: pointer to chdk list of export
// RETURN VALUE: 1 error, 0 ok
//---------------------------------------------------------
int _module_loader( unsigned int* chdk_export_list )
{
	if ( chdk_export_list[0] != EXPORTLIST_MAGIC_NUMBER )
    	return 1;

	// If "gui_menu_run_fltmodule" is 0, then menu system is changed
	if ( module_find_symbol_address(MODULESYM_GUI_MENU_RUN_FLTMODULE) == 0)
		return 1;

    if ( !API_VERSION_MATCH_REQUIREMENT( gui_version.menu_api, 1, 0 ) )
	  return 1;

	return 0;
}
Example #3
0
static int module_do_imports( struct flat_hdr* flat, void* relocbuf, uint32_t import_count )
{
    int i;
    unsigned char* buf = (unsigned char*)flat;
    uint32_t* rbuf = (uint32_t*)relocbuf;

    for ( i=0; i < import_count; )
    {
        const void* importaddress = module_find_symbol_address(rbuf[i++]);
        if (importaddress == 0) return 0;

        int cnt = rbuf[i] >> 24;
        for (; cnt>0; cnt--)
        {
            uint32_t offs = rbuf[i++] & 0x00FFFFFF;
            uint32_t* ptr = (uint32_t*)( buf + offs );
            *ptr += (int)importaddress;
        }
    }  
    return 1;
}