Pwnos design Document Version 0a


Design Organisational Overview



Download 135.4 Kb.
Page4/6
Date31.01.2017
Size135.4 Kb.
#13944
1   2   3   4   5   6

Design

Organisational Overview


This section outlines the overall organisation of PwnOS, the relations between its major modules, and design aspects common to all or most major modules of PwnOS.
To optimise the use of modern general-purpose CPUs, PwnOS is a 64-bit operating system for processors supporting x86-64 architecture and SSE3. Portability and backward compatibility often conflict with the goals of low time and space overhead, and so are not considered in the design of PwnOS. PwnOS is designed to best work with many CPU cores. Because of the similarity from software, the terms “CPU” and “CPU core” are used interchangeably in the rest of this document.
The following figure presents the overall code architecture of PwnOS in terms of its modules and the relevant interfaces.
architecture2a.png

Figure : Overall Architecture

The reasoning behind having the heap memory management module and part of the synchronisation module accessible directly from Privilege Level 3 (PL3) is that some of the time overhead of system calls can be avoided by using regular function calls where possible. Managing heap memory does not require actively changing page tables or updating core data structures, so can be done from PL3. Likewise, synchronisation actions such as getting a lock that is currently free and releasing a lock on which no threads are blocking are both operations that can be done in PL3, and upon failure (e.g. the lock is not free when attempting to get it) can call PL0 to properly handle all cases.


That these modules are in special, read-only, pages of memory common to all processes is also important. There will be a heap for modules in PL0 and a heap for each application, and duplication of the heap management code would be wasteful, so it is kept in common for all tasks using global, read-only pages for efficiency and accident avoidance. This is discussed further in the Page Memory Management section.
Custom libraries in this read-only memory may include libraries developed by/for a user of PwnOS, the Code Cortex libraries, or any other libraries to be loaded here.
The following diagram presents the dependencies between the modules of PwnOS.
dependencies.png

Figure : Module Dependencies

Dependencies on (Fast) Sync have been omitted since all modules but Thread Scheduler and (Full) Sync have such a dependency. There are cyclic dependencies involving I/O, Page and Heap Memory, and Sync, and as such, they must be initialised without using any of the code therein. See the Booting section for more detail on initialisation.



API Specification

The following table specifies the core Application Programming Interface of PwnOS. It has been designed to be simple, with meaningful names, and still have sufficient functionality. Parameters are passed by registers, and system calls are made using the special SYSCALL instruction for optimal performance. Library calls can be made as normal calls (after relocation).




Function

Parameters

Returns

Description

AllocatePages

Address

nPages


AllocType

Address

Allocates the specified number of pages with the specified properties. If Address is not NULL, the pages will be allocated with that virtual address (rounded down to the page).

FreePages

Address

nPages





Deallocates the specified number of pages starting at the specified address (rounded down to the page).

AllocateMemory

nBytes

Address

Allocates on the heap a range of the specified number of bytes.

AllocateAlignedMemory

nBytes

Alignment



Address

Allocates on the head a range of the specified number of bytes aligned to 2Alignment bytes.

FreeMemory

Address




Deallocates the memory range starting at Address from the heap.

GetAllocationSize

Address

nBytes

Returns the size of the heap memory range containing Address.

GetAllocationStart

Address

StartAddress

Returns the start address of the heap memory range containing Address.

CreateProcess

pName

DataSize


pData

Flags


pProcess

Creates a new process from a file with the specified name and specified properties. If pData is not NULL, DataSize bytes of data are copied to the new process as command data.

DestroyProcess

pProcess




Stops and completely eliminates the specified process and all of its threads. This does not return if pProcess is the current process.

GetCurrentProcess




pProcess

Returns a reference to the current process.

CreateThread

pFunction

StackSize

Flags

Parameter



pThread

Creates a new thread with the specified properties that starts execution by calling the specified function with Parameter. The new thread’s stack has the specified size. Returning from the function destroys the thread.

DestroyThread

pThread




Destroys the specified thread. This does not return if pProcess is the current process.

PauseThread

pThread




Pauses execution of the specified thread, saving its state.

ResumeThread

pThread




Resumes execution of the specified thread if the thread was paused or sleeping.

Sleep

pThread

Milliseconds






Puts the specified thread to sleep (similar to pausing) for the specified number of milliseconds, after which execution resumes normally.

ScheduleThread

pThread

pFunction

Parameter

Milliseconds



pSchedule

Schedules the specified paused thread to call the specified function with Parameter after the specified number of milliseconds. If the thread had state saved when paused, that state may be overwritten.

UnscheduleThread

pSchedule




Unschedules the previously scheduled thread execution event.

GetCurrentThread




pThread

Returns a reference to the current thread.

GetLock

pLock




Assigns the access controlled by the specified lock to the current thread, blocking until it is allowed to do so if necessary. (PL3and PL0)

ReleaseLock

pLock




Releases the access controlled by the specified lock from the current thread immediately, informing blocked threads. (PL3 and PL0)

AttemptGetLock

pLock

Milliseconds



hasLock

Attempts to assigns the access controlled by the specified lock to the current thread for a limited amount of time before giving up. (PL3 and PL0)

WaitForNotify

pQueue




Adds the current thread to the specified queue of waiting threads. (all PL0)

AttemptWaitForNotify

pQueue

Milliseconds



wasNotified

Adds the current thread to the specified queue of waiting threads for a limited amount of time before giving up. (all PL0)

Notify

pQueue

nNotified

Notifies the first thread in the specified queue of waiting threads (if any). (all PL0)

NotifyAll

pQueue

nNotified

Notifies all threads in the specified queue of waiting threads. (all PL0)

OpenFile

pName

Flags


pFile

Opens a file with the specified name with the specified access and properties.

ReadFile

pFile

pDestination

nBytes


nBytesRead

Reads the specified number of bytes to the specified address in memory from the specified opened file.

WriteFile

pFile

pSource


nBytes

nBytesWritten

Writes the specified number of bytes to the specified file from the specified address in memory.

CloseFile

pFile




Closes the specified file.

GetFileSize

pFile

nBytes

Returns the size of the specified file if it has a size.

GetFilePointer

pFile

ByteIndex

Returns the current location in the specified file from which the next read or write operation would occur, if it has such a location.

SetFilePointer

pFile

ByteIndex






Sets the current location in the specified file from which the next read or write operation would occur, if it has such a location.

GetGraphicsAccess




pGraphics

Allocates pages onto the graphics linear frame buffer (or virtual linear frame buffer), returning a pointer to a structure describing the buffer.

ReleaseGraphicsAccess







Deallocates pages of the graphics linear frame buffer (or virtual linear frame buffer).

AddKeyListener

pFunction




Registers the specified function to be called using the current thread when a key of a keyboard is pressed or released.

RemoveKeyListener

pFunction




Deregisters the specified function from being called on key events, preferring the current thread if duplicates exist.

AddMouseButtonListener

pFunction




Registers the specified function to be called using the current thread when a button of a mouse is pressed or released.

RemoveMouseButtonListener

pFunction




Deregisters the specified function from being called on mouse button events, preferring the current thread if duplicates exist.

AddMouseMotionListener

pFunction




Registers the specified function to be called using the current thread when a mouse is moved.

RemoveMouseMotionListener

pFunction




Deregisters the specified function from being called on mouse motion events, preferring the current thread if duplicates exist.




Download 135.4 Kb.

Share with your friends:
1   2   3   4   5   6




The database is protected by copyright ©ininet.org 2024
send message

    Main page