示例#1
0
void main(int argc, char* argv[])
{
	mono_set_dirs("lib", "");
	mono_config_parse(NULL);

	MonoDomain* domain = mono_jit_init("managed.exe");
	if(!domain)
	{
		printf("Unable to initialize mono jit.\n");
		return;
	}
	MonoAssembly* assembly = mono_domain_assembly_open(domain, "managed.exe");
	if (!assembly)
	{
		printf("Unable to open assembly.\n");
		return;
	}
	
	char* argvv[1] = { "managed" };
	mono_jit_exec(domain, assembly, 1, argvv);
	
	mono_jit_cleanup(domain);

	return;
}
示例#2
0
文件: program.cpp 项目: Babelz/SaNi
int main() {
	/*
		TODO: using abs paths just to test this shit.
	*/

	// Set path where managed assemblies live.
	mono_set_assemblies_path("C:\\Users\\Niko\\Source\\Repos\\SaNi\\vs2013\\sanimono\\SaNi\\bin\\Debug");
	// Set Mono library and configuration paths.
	mono_set_dirs("C:\\Program Files (x86)\\Mono\\lib", "C:\\Program Files (x86)\\Mono\\etc");

	// Our application assembly that contains 
	// the code we are going to run.
	domain = mono_jit_init_version("SaNi", "v4.0.30319");
	
	// Our domain in which the code will be 
	// executed.
	MonoAssembly* assembly = mono_domain_assembly_open(domain, "C:\\Users\\Niko\\Source\\Repos\\SaNi\\vs2013\\sanimono\\SaNi\\bin\\Debug\\SaNi.exe");

	if (!assembly) throw std::runtime_error("could not load the given Mono assembly");

	mono_add_internal_call("SaNi.Utils::Print(string)", (void*)print);
	mono_add_internal_call("SaNi.Utils::GetString()", (void*)getString);

	const auto argc = 6;
	char* argv[argc] = { "HELLO", "WORLD", "FROM", "THE", "F*****G", "MONO" };

	mono_jit_exec(domain, assembly, argc, argv);

	// Clean mono.
	mono_jit_cleanup(domain);

	return 0;
}
示例#3
0
void ml_uninit()
{
	g_return_if_fail(_runtime_active == TRUE);

	mono_jit_cleanup(ml_get_domain());

	ml_set_domain(NULL);

	_runtime_active = FALSE;
}
示例#4
0
int app_mono_exec(struct sip_msg *msg, char *script, char *param)
{
	int ret;
	char *argv[2];
	int argc;

	argc = 1;
	argv[0] = script;
	if(param!=NULL) {
		argc++;
		argv[1] = param;
	}
	LM_DBG("executing Mono assembly: [[%s]]\n", argv[0]);
	_sr_M_env.msg = msg;

	mono_config_parse (NULL);
	/*
	 * mono_jit_init() creates a domain: each assembly is
	 * loaded and run in a MonoDomain.
	 */
	_sr_M_env.domain = mono_jit_init (argv[0]);
	/*
	 * We add our special internal functions, so that C# code
	 * can call us back.
	 */
	sr_mono_load_class_core();
	sr_mono_load_class_pv();
	sr_mono_load_class_hdr();

	_sr_M_env.assembly = mono_domain_assembly_open(_sr_M_env.domain, argv[0]);
	if (_sr_M_env.assembly==NULL) {
		ret = -1;
		goto done;
	}
	/*
	 * mono_jit_exec() will run the Main() method in the assembly.
	 * The return value needs to be looked up from
	 * System.Environment.ExitCode.
	 */
	mono_jit_exec(_sr_M_env.domain, _sr_M_env.assembly, argc, argv);
	ret = mono_environment_exitcode_get();
	LM_DBG("returned code from mono environment: %d\n", ret);

done:
	mono_jit_cleanup(_sr_M_env.domain);

	memset(&_sr_M_env, 0, sizeof(sr_mono_env_t));
	return (ret==0)?1:-1;
}
示例#5
0
// Shuts down PythonNet and cleans up Mono
void PyNet_Finalize(PyNet_Args *pn_args) {
    MonoObject *exception = NULL;

    if (pn_args->shutdown) {
        mono_runtime_invoke(pn_args->shutdown, NULL, NULL, &exception);
        if (exception) {
            pn_args->error = PyNet_ExceptionToString(exception);
        }
        pn_args->shutdown = NULL;
    }
    
    if (pn_args->domain) {
        mono_jit_cleanup(pn_args->domain);
        pn_args->domain = NULL;
    }
    free(pn_args);
}
示例#6
0
int main (int argc, char *argv[])
{
	Global::Initialize();
	std::cout << "Mono Native 1.0 Unit Tests" << std::endl;

	/*
	GlobalFixture globalfixture;
	globalfixture.Run();

	List_1Fixture list_1Fixture;
	list_1Fixture.Run();
	*/


	testing::InitGoogleTest(&argc, argv);

	int exitcode = RUN_ALL_TESTS();

	mono_jit_cleanup(Global::GetDomain());
	return exitcode;
}
示例#7
0
CScriptDomain::~CScriptDomain()
{
	m_bDestroying = true;

	for each(auto assembly in m_assemblies)
		delete assembly;

	m_assemblies.clear();

	if(m_bRootDomain)
		mono_jit_cleanup(m_pDomain);
	else
	{
		if(IsActive())
			mono_domain_set(mono_get_root_domain(), false);

		mono_domain_finalize(m_pDomain, 2000);

		MonoObject *pException;
		try
		{
			mono_domain_try_unload(m_pDomain, &pException);
		}
		catch(char *ex)
		{
			MonoWarning("An exception was raised during ScriptDomain unload: %s", ex);
		}

		if(pException)	
		{	
			MonoWarning("An exception was raised during ScriptDomain unload:");
			MonoMethod *pExceptionMethod = mono_method_desc_search_in_class(mono_method_desc_new("::ToString()", false),mono_get_exception_class());		
			MonoString *exceptionString = (MonoString *)mono_runtime_invoke(pExceptionMethod, pException, nullptr, nullptr);		
			CryLogAlways(ToCryString((mono::string)exceptionString));
		}
	}

	g_pScriptSystem->OnDomainReleased(this);
}
示例#8
0
int 
main(int argc, char* argv[]) {
	MonoDomain *domain;
	const char *file;
	int retval;
	puts("Ola");
	if (argc < 2){
		fprintf (stderr, "Please provide an assembly to load\n");
		return 1;
	}
	file = argv [1];

	/*
	 * Load the default Mono configuration file, this is needed
	 * if you are planning on using the dllmaps defined on the
	 * system configuration
	 */
	mono_config_parse (NULL);
	/*
	 * mono_jit_init() creates a domain: each assembly is
	 * loaded and run in a MonoDomain.
	 */
	domain = mono_jit_init (file);
	/*
	 * We add our special internal call, so that C# code
	 * can call us back.
	 */
	mono_add_internal_call ("MonoEmbed::gimme", gimme);

	main_function (domain, file, argc - 1, argv + 1);
	
	retval = mono_environment_exitcode_get ();
	
	mono_jit_cleanup (domain);
 getch();
	return retval;
}
示例#9
0
static void processThroughMono(std::string& dll)
{    
    //Initialize mono runtime
    MonoDomain* domain = mono_jit_init (dll.c_str());
    MonoAssembly *assembly;

    assembly = mono_domain_assembly_open (domain, dll.c_str());
    assert(assembly);

    MonoImage *image =  mono_assembly_get_image  (assembly);
    assert(image);
    MonoMethodDesc* desc = mono_method_desc_new ("TestDLL.Program:process", true);
    assert(desc);

    MonoMethod* method = mono_method_desc_search_in_image (desc, image);
    assert(method);

    //Create our container
    Container* c = new Container();

    //Cast to uint64
    uint64_t ptr = reinterpret_cast<uint64_t>(c);

    //Fill it as an argument before the mono method invokation
    void* args[1];
    args[0] = &ptr;

    //Invoke C# code
    mono_runtime_invoke (method, nullptr, args, nullptr);

    //Clean mono runtime
    mono_jit_cleanup (domain);

    //We did it!
    c->dump();

}
示例#10
0
GDMono::~GDMono() {

	if (is_runtime_initialized()) {

		if (scripts_domain) {

			Error err = _unload_scripts_domain();
			if (err != OK) {
				WARN_PRINT("Mono: Failed to unload scripts domain");
			}
		}

		const uint32_t *k = NULL;
		while ((k = assemblies.next(k))) {
			HashMap<String, GDMonoAssembly *> &domain_assemblies = assemblies.get(*k);

			const String *kk = NULL;
			while ((kk = domain_assemblies.next(kk))) {
				memdelete(domain_assemblies.get(*kk));
			}
		}
		assemblies.clear();

		GDMonoUtils::clear_cache();

		print_verbose("Mono: Runtime cleanup...");

		mono_jit_cleanup(root_domain);

		runtime_initialized = false;
	}

	if (gdmono_log)
		memdelete(gdmono_log);

	singleton = NULL;
}
示例#11
0
void Application::InitializeMono()
{
	//this will override the internal assembly search logic.
	//do it in case you package mono in a different structure
	//mono_set_assemblies_path(dllDir.c_str());

	mono_config_parse(NULL);

	// initialize the root domain which will hold corlib and will always be alive
	domain = mono_jit_init_version("CCubed Root Domain", "v4.0.30319");

	// soft debugger needs this
	mono_thread_set_main(mono_thread_current());

	// add icalls
	mono_add_internal_call("EmbedThings.EntryPoint::reload", reload);

	// run the c# bits
	Run();

	// we're exiting the whole thing, cleanup
	mono_jit_cleanup(mono_domain_get());

}
示例#12
0
	void ScriptProvider::Shutdown()
	{
		mono_jit_cleanup(ScriptDomain);
	}
示例#13
0
__int32 WINAPI _CorExeMain(void)
{
    int exit_code;
    int argc;
    char **argv;
    MonoDomain *domain=NULL;
    MonoImage *image;
    MonoImageOpenStatus status;
    MonoAssembly *assembly=NULL;
    WCHAR filename[MAX_PATH];
    char *filenameA;
    ICLRRuntimeInfo *info;
    RuntimeHost *host;
    HRESULT hr;
    int i;

    get_utf8_args(&argc, &argv);

    GetModuleFileNameW(NULL, filename, MAX_PATH);

    TRACE("%s", debugstr_w(filename));
    for (i=0; i<argc; i++)
        TRACE(" %s", debugstr_a(argv[i]));
    TRACE("\n");

    filenameA = WtoA(filename);
    if (!filenameA)
        return -1;

    FixupVTable(GetModuleHandleW(NULL));

    hr = get_runtime_info(filename, NULL, NULL, 0, 0, FALSE, &info);

    if (SUCCEEDED(hr))
    {
        hr = ICLRRuntimeInfo_GetRuntimeHost(info, &host);

        if (SUCCEEDED(hr))
            hr = RuntimeHost_GetDefaultDomain(host, &domain);

        if (SUCCEEDED(hr))
        {
            image = mono_image_open_from_module_handle(GetModuleHandleW(NULL),
                filenameA, 1, &status);

            if (image)
                assembly = mono_assembly_load_from(image, filenameA, &status);

            if (assembly)
            {
                mono_trace_set_assembly(assembly);

                exit_code = mono_jit_exec(domain, assembly, argc, argv);
            }
            else
            {
                ERR("couldn't load %s, status=%d\n", debugstr_w(filename), status);
                exit_code = -1;
            }

            RuntimeHost_DeleteDomain(host, domain);
        }
        else
            exit_code = -1;

        ICLRRuntimeInfo_Release(info);
    }
    else
        exit_code = -1;

    HeapFree(GetProcessHeap(), 0, argv);

    if (domain)
    {
        mono_thread_manage();
        mono_jit_cleanup(domain);
    }

    return exit_code;
}
示例#14
0
//#####################################################################
// Function ~Mono
//#####################################################################
MonoSystem::~MonoSystem() {
    reportPinnedObjects();

    mDomain.fireProcessExit();
    mono_jit_cleanup(mDomain.domain());
}
void SharpSource::SDK_OnUnload()
{
  mono_jit_cleanup(domain);
}