Exemplo n.º 1
0
Arquivo: main.c Projeto: HideSand/ksm
NTSTATUS DriverEntry(PDRIVER_OBJECT driverObject, PUNICODE_STRING registryPath)
{
	LdrDataTableEntry *entry = driverObject->DriverSection;
	PsLoadedModuleList = entry->in_load_links.Flink;
	driverObject->DriverUnload = DriverUnload;

	VCPU_DEBUG("We're mapped at %p (size: %d bytes (%d KB), on %d pages)\n",
		   entry->base, entry->size, entry->size / 1024, entry->size / PAGE_SIZE);
	LdrDataTableEntry *kentry = container_of(PsLoadedModuleList->Flink, LdrDataTableEntry, in_load_links);
	g_kernel_base = kentry->base;

	VCPU_DEBUG("Kernel: %p -> %p (size: 0x%X pages: %d) path: %wS\n",
		   kentry->base, (uintptr_t)kentry->base + kentry->size,
		   kentry->size, BYTES_TO_PAGES(kentry->size),
		   kentry->path.Buffer);
	ExInitializeDriverRuntime(DrvRtPoolNxOptIn);

	NTSTATUS status = ksm_init();
	if (NT_SUCCESS(status))
		status = register_power_callback(&g_dev_ext);

	if (NT_SUCCESS(status))
		status = PsCreateSystemThread(&hThread, STANDARD_RIGHTS_ALL, NULL, NULL, &cid, (PKSTART_ROUTINE)sys_thread, NULL);

	VCPU_DEBUG("ret: 0x%08X\n", status);
	return status;
}
Exemplo n.º 2
0
/*
功能:初始化IOSS模块
参数:无
*/
IO_API __bool PMC_API init_ioss()
{
	_load_settings();//通过pmc.in或程序默认,给几个相关变量赋初值g_fltMaxChangeRate、g_fltTagLife

	register_power_callback(_power_callback, 0);//用形参对CALLBACK_ITEM的成员赋值,并链接到RTK_LIST_ENTRY
	
	pnp_probe_devices();//加载设备驱动DLL,并得到其导出函数的指针

	if(!CDBRefresher::init()){//add本地节点、组和标签;对g_Handlers[]中的函数指针赋值;开启一个线程
		utils_error("Global initialization of CRefresher failed.\n");
		return __false;
	}	

	return __true;
}
Exemplo n.º 3
0
bool CRtkService::_init()
{
	char serverName[rtkm_node_key_length + 1];

	m_bPending = __true;
	
	PrimaryCheckInterval = GetPrivateProfileInt(
		"PMC",
		"PrimaryCheckInterval",
		500,
		get_config_file()
		);
	if(PrimaryCheckInterval < 50 || PrimaryCheckInterval > 5000){
		utils_error(
			"Warning : PrimaryCheckInterval=%d is invalid, reset to 500.\n",
			PrimaryCheckInterval
			);
		PrimaryCheckInterval = 500;
	}
	MaxPrimaryWatchDogCounter = GetPrivateProfileInt(
		"PMC",
		"PrimaryWatchDogCounter",
		8,
		get_config_file()
		);
	if(MaxPrimaryWatchDogCounter < 3 || MaxPrimaryWatchDogCounter > 50){
		utils_error(
			"Warning : PrimaryWatchDogCounter=%d is invalid, reset to 20.\n",
			PrimaryWatchDogCounter
			);
		MaxPrimaryWatchDogCounter = 8;
	}
	PrimaryWatchDogCounter = MaxPrimaryWatchDogCounter;
	
	m_bPending = __false;

	init_powermgr();

#ifdef _WIN32
	init_spac();//初始化得到security descriptor、mutex对象句柄数组mutics[]和event对象句柄数组events[]
#endif
	
	init_server_shell();//创建g_shell

	init_config();//空函数。。。
	
	GetPrivateProfileString(
		"PMC",
		"ServerName",
		"",
		serverName,
		sizeof(serverName),
		get_config_file()
		);
	//若pmc.ini中没有给出节点名,取本机名为节点名
	if(!serverName[0]){
		DWORD len;
		len = sizeof(serverName);
		GetComputerName(serverName, &len);
	}
	
	//初始化网络,即设定一些值,创建链表g_buses,<bus_id, CRtkVBus*>,并开启5个VBUS线程
	if(!init_network(RTK_INIT_AS_SERVER, serverName)){
		return false;
	}
	//给g_buses中的4个元素的CRtkVBus的成员赋值
	connect_vbus(
		BUSID_RTDB, 
		VBUS_CONNECT_AS_SERVER, 
		on_rtdb, 
		rtdb_filter
		);
	connect_vbus(
		BUSID_SYSTEM, 
		VBUS_CONNECT_AS_SERVER, 
		on_system, 
		server_filter
		);
	connect_vbus(
		BUSID_OPERATION, 
		VBUS_CONNECT_AS_SERVER, 
		on_operation, 
		server_filter
		);
	connect_vbus(
		BUSID_CONFIG, 
		VBUS_CONNECT_AS_SERVER, 
		on_config, 
		server_filter
		);
	utils_trace("Networking Subsystem initialized.\n"); 	

	register_power_callback(power_state_changed, 0);//创建一个CALLBACK_ITEM,用形参给其成员赋值,并链接上RTK_LIST_ENTRY
	// checking primary site
	if(!setup_running_state()){
		return false;
	}	

	setup_rtdb();//在pmc.ini中寻找组名,加载组名对应的*.csv文件中的标签到内存,并开启一个线程。
	utils_trace("Realtime Database Subsystem initialized.\n");
	init_ioss();
	utils_trace("IO Susbsystem initialized.\n");	

	utils_trace("%s started...\n",  versionString.c_str());

	if(get_power_state() == PWR_RUNNING){
		online_broadcast();//发送一个报警数据包,RTK_ALARM_PACKET型
	}

	return true;
}