コード例 #1
0
// public API
APIE inventory_get_processes(Session *session, ObjectID *processes_id) {
	List *processes;
	APIE error_code;
	int i;
	Process *process;

	error_code = list_allocate(_objects[OBJECT_TYPE_PROCESS].count,
	                           session, OBJECT_CREATE_FLAG_EXTERNAL,
	                           NULL, &processes);

	if (error_code != API_E_SUCCESS) {
		return error_code;
	}

	for (i = 0; i < _objects[OBJECT_TYPE_PROCESS].count; ++i) {
		process = *(Process **)array_get(&_objects[OBJECT_TYPE_PROCESS], i);
		error_code = list_append_to(processes, process->base.id);

		if (error_code != API_E_SUCCESS) {
			object_remove_external_reference(&processes->base, session);

			return error_code;
		}
	}

	*processes_id = processes->base.id;

	return API_E_SUCCESS;
}
コード例 #2
0
ファイル: module.c プロジェクト: UIKit0/TSOS
/*
 * Loads the modules specified in the ramdisk. Loading follows this general
 * procedure:
 *
 * 1. Ensure the file is a valid ELF.
 * 2. Dynamically link with kernel functions from kernel symtab.
 * 3. Call module entry point
 */
void modules_ramdisk_load() {
	if(!ramdisk_loaded()) return;

	// Initialise some data structures
	loaded_module_map = hashmap_allocate();
	loaded_module_names = list_allocate();

	// Acquire initial placement address
	module_placement_addr = paging_get_memrange(kMemorySectionDrivers)[0];
	module_placement_end = paging_get_memrange(kMemorySectionDrivers)[1];

	// Get modules
	char *modulesToLoad = hal_config_get("modules");
	char *moduleName = strtok(modulesToLoad, " ");
	void *elf;

	// Find all modules
	while(moduleName) {
		// Attempt to load module from ramdisk
		if((elf = ramdisk_fopen(moduleName))) {
			module_load(elf, moduleName);
		}

		moduleName = strtok(NULL, " ");
	}

	KSUCCESS("Dynamically loaded modules initialised");
}
コード例 #3
0
ファイル: vfs.cpp プロジェクト: UIKit0/TSOS
/*
 * Allocates a directory structure, as well as any child objects that are
 * associated with it.
 */
fs_directory_t *hal_vfs_allocate_directory(bool createHandle) {
	fs_directory_t *dir = (fs_directory_t *) kmalloc(sizeof(fs_directory_t));

	// Handle out of memory conditions
	if(dir) {
		dir->children = list_allocate();
		dir->i.type = kFSItemTypeDirectory;

		// Create a handle for this directory, if requested
		if(createHandle) {
			dir->i.handle = hal_handle_allocate(dir, kFSItemTypeDirectory);
		}

		// Default permissions: no owner, anyone can access
		dir->i.owner = {0, 0};
		dir->i.permissions = 0775;

		return dir;
	}

	return NULL;
}
コード例 #4
0
// public API
APIE inventory_get_programs(Session *session, ObjectID *programs_id) {
	List *programs;
	APIE error_code;
	int i;
	Program *program;

	error_code = list_allocate(_objects[OBJECT_TYPE_PROCESS].count,
	                           session, OBJECT_CREATE_FLAG_EXTERNAL,
	                           NULL, &programs);

	if (error_code != API_E_SUCCESS) {
		return error_code;
	}

	for (i = 0; i < _objects[OBJECT_TYPE_PROGRAM].count; ++i) {
		program = *(Program **)array_get(&_objects[OBJECT_TYPE_PROGRAM], i);

		if (program->base.internal_reference_count == 0) {
			// ignore program object that are only alive because there are
			// external references left to it
			continue;
		}

		error_code = list_append_to(programs, program->base.id);

		if (error_code != API_E_SUCCESS) {
			object_remove_external_reference(&programs->base, session);

			return error_code;
		}
	}

	*programs_id = programs->base.id;

	return API_E_SUCCESS;
}
コード例 #5
0
ファイル: vfs.cpp プロジェクト: UIKit0/TSOS
/*
 * Initialises the VFS driver.
 */
static int hal_vfs_init(void) {
	registered_vfs = list_allocate();
	filesystem_superblocks = list_allocate();

	return 0;
}
コード例 #6
0
ファイル: list_parser.c プロジェクト: UIKit0/TSOS
list_t *parse_list(char *in, const char *delimiter) {
	if(!in) return NULL;

	// Copy input buffer
	size_t in_len = strlen(in);
	char *string = (char *) kmalloc(in_len + 4);
	memcpy(string, in, in_len);

	// Allocate list
	list_t *list = list_allocate();

	// Read the file, separated by the specified delimiter
	char *token = strtok(string, delimiter);

	// Temporary string buffer
	char *tokBuf = (char *) kmalloc(1024);

	while(token) {
		memclr(tokBuf, 1024);

		// Locate hash so we can ignore comments
		char *startOfComment = strchr(token, '#');

		// If a comment was found, copy the line up to the comment
		if(startOfComment) {
			size_t size = startOfComment - token;

			// Ignore comments (first character == hash)
			if(size == 0) {
				goto findNext;
			} else {
				memcpy(tokBuf, token, size);
			}
		} else { // This line has no comment
			if(strlen(token) > 2) {
				strncpy(tokBuf, token, 1024-1);
			} else {
				goto findNext;
			}
		}

		// Ignore zero-length lines
		if(strlen(tokBuf) > 0) {
			// Allocate a buffer for the line
			size_t bufSize = strlen(tokBuf) + 4;
			char *copy = (char *) kmalloc(bufSize);
			memclr(copy, bufSize);

			// If success, copy the line and add to list
			if(copy) {
				strncpy(copy, tokBuf, bufSize - 1);
				list_add(list, copy);
			}
		}

		// Find next line
		findNext: ;
		token = strtok(NULL, delimiter);
	}

	// Clean up memory
	kfree(tokBuf);
	kfree(string);

	return list;	
}