// D import file generated from '../../../../libphobos/libdruntime/core/runtime.d'
module core.runtime;
version (Android)
{
	version = HaveDLADDR;
	version = GenericBacktrace;
}
else
{
	version (GNU)
	{
		version = GenericBacktrace;
	}
	else
	{
		version (Windows)
		{
			version = WindowsBacktrace;
		}
		else
		{
			version (linux)
			{
				version = GlibcBacktrace;
			}
			else
			{
				version (OSX)
				{
					version = OSXBacktrace;
				}
			}
		}
	}
}
private 
{
	alias bool function() ModuleUnitTester;
	alias bool function(Object) CollectHandler;
	alias Throwable.TraceInfo function(void* ptr) TraceHandler;
	extern (C) void rt_setCollectHandler(CollectHandler h);

	extern (C) CollectHandler rt_getCollectHandler();

	extern (C) void rt_setTraceHandler(TraceHandler h);

	extern (C) TraceHandler rt_getTraceHandler();

	alias void delegate(Throwable) ExceptionHandler;
	extern (C) bool rt_init(ExceptionHandler dg = null);

	extern (C) bool rt_term(ExceptionHandler dg = null);

	extern (C) void* rt_loadLibrary(in char[] name);

	extern (C) bool rt_unloadLibrary(void* ptr);

	extern (C) void* thread_stackBottom();

	extern (C) string[] rt_args();

	extern (C) CArgs rt_cArgs();

	version (HaveDLADDR)
	{
		extern (C) 
		{
			int dladdr(void* addr, Dl_info* info);
			struct Dl_info
			{
				const(char*) dli_fname;
				void* dli_fbase;
				const(char*) dli_sname;
				void* dli_saddr;
			}
		}
	}
	version (GenericBacktrace)
	{
		import gcc.unwind;
		import core.demangle;
		import core.stdc.stdio : snprintf, printf;
		import core.stdc.string : strlen;
		version (Posix)
		{
			import core.sys.posix.signal;
		}
	}
	else
	{
		version (GlibcBacktrace)
		{
			import core.demangle;
			import core.stdc.stdlib : free;
			import core.stdc.string : strlen, memchr;
			extern (C) int backtrace(void**, int);

			extern (C) char** backtrace_symbols(void**, int);

			extern (C) void backtrace_symbols_fd(void**, int, int);

			version (Posix)
			{
				import core.sys.posix.signal;
			}
		}
		else
		{
			version (OSXBacktrace)
			{
				import core.demangle;
				import core.stdc.stdlib : free;
				import core.stdc.string : strlen;
				extern (C) int backtrace(void**, int);

				extern (C) char** backtrace_symbols(void**, int);

				extern (C) void backtrace_symbols_fd(void**, int, int);

				import core.sys.posix.signal;
			}
			else
			{
				version (WindowsBacktrace)
				{
					import core.sys.windows.stacktrace;
				}
			}
		}
	}
	version (Windows)
	{
		import core.sys.windows.windows;
	}
	else
	{
		version (Posix)
		{
			import core.sys.posix.unistd;
		}
	}
}
static this();
struct CArgs
{
	int argc;
	char** argv;
}
struct Runtime
{
	static bool initialize(ExceptionHandler dg = null);

	static bool terminate(ExceptionHandler dg = null);

	static @property string[] args();

	static @property CArgs cArgs();

	static void* loadLibrary(in char[] name);

	static bool unloadLibrary(void* p);

	static @property void traceHandler(TraceHandler h);

	static @property TraceHandler traceHandler();

	static @property void collectHandler(CollectHandler h);

	static @property CollectHandler collectHandler();

	static @property void moduleUnitTester(ModuleUnitTester h);

	static @property ModuleUnitTester moduleUnitTester();

	private __gshared ModuleUnitTester sm_moduleUnitTester = null;


}
extern (C) bool runModuleUnitTests();

import core.stdc.stdio;
Throwable.TraceInfo defaultTraceHandler(void* ptr = null);
version (GenericBacktrace)
{
	static enum MAXFRAMES = 128;

	struct gdcBacktraceData
	{
		void*[MAXFRAMES] callstack;
		int numframes = 0;
	}
	struct backtraceSymbol
	{
		const(char)* name;
		const(char)* fileName;
		size_t offset;
		void* address;
	}
	struct btSymbolData
	{
		size_t entries;
		backtraceSymbol[MAXFRAMES] symbols;
	}
	static extern (C) _Unwind_Reason_Code unwindCB(_Unwind_Context* ctx, void* d);


	gdcBacktraceData gdcBacktrace();
	btSymbolData gdcBacktraceSymbols(gdcBacktraceData data);
}
