<commit_before>/** @file sim_interface.c
 * @brief sim_specific files in order to simulate module loading.
 * @author <NAME>
 * Academic Free License, Version 1.2
 * This is open source.  For exact license terms read the LICENSE file
 * Copyright 2005, <NAME>. All Rights Reserved.
 */
#include <hardware.h>
#include <sos_info.h>
#include "sim_interface.h"

#ifndef SOS_DEBUG_SIM_INTERFACE
#undef DEBUG
#define DEBUG(...)
#endif

mod_header_ptr module_headers[MAX_NETWORK_MODULES];
mod_header_ptr get_header_from_sim(sos_code_id_t cid)
{
    int i;
    DEBUG("get_header_from_sim(cid: %d)\n", cid);
    for(i = 0; i < MAX_NETWORK_MODULES; i++){
        mod_header_ptr h;
        sos_code_id_t code_id;
        h = module_headers[i];
		if(h == 0) continue;
        DEBUG("module_headers[%d] = 0x%x\n", i, h);
        code_id = sos_read_header_word(h, offsetof(mod_header_t, code_id));
		code_id = entohs( code_id );

        DEBUG("code_id = %d\n", code_id);
        if(cid == code_id){
            DEBUG("cid(%d) == code_id(%d)\n",cid,code_id);
            return h;
        }
    }
    DEBUG("get_header_from_sim no header found\n");
    return (mod_header_ptr)NULL;
}

#if 0
void set_version_to_sim(sos_pid_t pid, uint8_t version)
{
    int i;
    for(i = 0; i < MAX_NETWORK_MODULES; i++){
        mod_header_ptr h;
        sos_pid_t mod_id;
        
        h = module_headers[i];
        if(h == 0) continue;
        mod_id = sos_read_header_byte(h, offsetof(mod_header_t, mod_id));
        
        if(pid == mod_id){
            mod_header_t *header_ptr = (mod_header_t *) h;
            header_ptr->version = version;	
            return;
        }
    }
}
#endif<commit_msg>add dlopen to sim target<commit_after>/** @file sim_interface.c
 * @brief sim_specific files in order to simulate module loading.
 * @author <NAME>
 * Academic Free License, Version 1.2
 * This is open source.  For exact license terms read the LICENSE file
 * Copyright 2005, <NAME>. All Rights Reserved.
 */
#include <hardware.h>
#include <sos_info.h>
#include "sim_interface.h"
#include <dlfcn.h>

#ifndef SOS_DEBUG_SIM_INTERFACE
#undef DEBUG
#define DEBUG(...)
#endif

mod_header_ptr module_headers[MAX_NETWORK_MODULES];
mod_header_ptr get_header_from_sim(sos_code_id_t cid)
{
    int i;
	char name_buf[128];
	void *dlh;
	void *mod_sym;
	int cnt;
				
    DEBUG("get_header_from_sim(cid: %d)\n", cid);
    for(i = 0; i < MAX_NETWORK_MODULES; i++){
        mod_header_ptr h;
        sos_code_id_t code_id;
        h = module_headers[i];
		if(h == 0) continue;
        DEBUG("module_headers[%d] = 0x%x\n", i, h);
        code_id = sos_read_header_word(h, offsetof(mod_header_t, code_id));
		code_id = entohs( code_id );

        DEBUG("code_id = %d\n", code_id);
        if(cid == code_id){
            DEBUG("cid(%d) == code_id(%d)\n",cid,code_id);
            return h;
        }
    }
    DEBUG("get_header_from_sim no header found\n");
    DEBUG("try look for %d.sos\n", cid);
	cnt = sprintf(name_buf, "%d.sos", cid);
	name_buf[cnt] = '\0';
	dlh = dlopen(name_buf, RTLD_NOW | RTLD_LOCAL );
	if( dlh == NULL ) {
		DEBUG("cannot find %d.sos\n", cid);
		return (mod_header_ptr)NULL;
	}
	mod_sym = dlsym( dlh, "mod_header" );
	if( mod_sym == NULL ) {
		DEBUG("dlerror: %s\n", dlerror());
		return (mod_header_ptr)NULL;
	}
	DEBUG("found %d.sos\n", cid);	
    return (mod_header_ptr)mod_sym;
}

{'fraction_non_alphanumeric': 0.1368888888888889, 'fraction_numerical': 0.007703703703703704, 'mean_word_length': 3.1372549019607843, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '491658', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1299, 'n_words': 289}