Esempio n. 1
0
int main()
{
	//init win32 socket
#ifdef __WIN32__
	static WSADATA wsa_data; 
	int result = WSAStartup((WORD)(1<<8|1), &wsa_data); //初始化WinSocket动态连接库
	if( result != 0 ) // 初始化失败
		return -1;
#endif
#ifndef __WIN32__
	signal( SIGPIPE, SIG_IGN );	//ignore send,recv SIGPIPE error
#endif
	NEW( websrv, sizeof(webserver) );
	memset( websrv, 0, sizeof(webserver) );
	server_create( websrv, "config.xml" );
	server_start( websrv );
	do_console();
	server_stop( websrv );
	server_end( websrv );
	DEL( websrv );

#ifdef __WIN32__
	WSACleanup();
#endif
	memory_end();
	return 0;
}
Esempio n. 2
0
#include "page.h"
#include "memory.h"
#include <paging.h>
#include <stdalign.h>
#include <limits.h>

// TODO: larger pages

static uint64_t num_frames;
static struct page *page_frames;
static struct list free_pages;

void page_alloc_init(void) {
	// TODO: allocate page_frames on a page boundary and map it to a fixed location
	num_frames = memory_end() >> PAGE_SHIFT;
	page_frames = memory_alloc(
		PAGE_SIZE, memory_end(), num_frames * sizeof(*page_frames), alignof(*page_frames)
	);

	list_init(&free_pages);
	for (uint64_t i = 0; i < num_frames; i++) {
		page_frames[i].ref_count = 1;
		list_init(&page_frames[i].free);
	}

	uint64_t i = 0, found_start, found_end;
	while (memory_free_next(&i, &found_start, &found_end), i != (uint64_t)-1) {
		uint64_t page_start = (found_start + PAGE_SIZE - 1) >> PAGE_SHIFT;
		uint64_t page_end = found_end >> PAGE_SHIFT;

		if (page_start >= page_end)