Giter Club home page Giter Club logo

rustos's Introduction

Learning Operating Systems by building an OS in Rust

Following along here

Latest Commits:

commit 3667c9e

alloc_from_region function to test and provide valid memory

For context, the find_region function traverses the linked list of
memory regions in search of a valid free region to use for
allocation. On each traversal, the logic for testing the validity
of a memory region is encapsulated within the alloc_from_region
function which we now define.

The alloc_from_region function uses the start and end address
to check for an overflow or if the end address is behind the end
address of the region. In either case, an error is returned to the
find_region function, which tells it to continue traversing for
other memory regions.

If neither occurs, the region is still potentially valid. The next
check performed by alloc_from_region ensures that the remaining
region is usable after allocation. To do so, the function checks
that the remainder is either the same size or larger than a
ListNode.

commit 052ed59

Create find region method for Linked List Allocator

Implement the find_region method for the LinkedListAllocator struct,
to search the linked list for a free region suitable to use for a
particular heap allocation.

We search the linked list iteratively, storing the current node in
a current variable and iterating with a while let construct that
loops as long as there are existing regions in the linked list.

On each iteration we check if the current region is suitable in
terms of both size and alignment with the alloc_from_region
method which has yet to be implemented.

If it is suitable, it is removed from the linked list by creating
temp variables and linking the current region's next pointer
(the current region is the region to be allocated) and assigning
it to the region after the region to be allocated. With the
linked list now rebuilt excluding the region to be allocated,
we return it in a tuple with its aligned alloc_start address.

If the current region is not suitable, we continue searching
the linked list, using a standard iterative technique of
reassigning the current variable to the current node's
next field.

commit b5bc8ff

Create function to add free memory region to front of linked list.

The add_free_region method implemented on the LinkedListAllocator
struct is how we push free regions onto the linked list. The method
takes an address and size and adds that memory region to the front.

We first assert that the region is large enough to store the ListNode,
then creates a new node with the size of the free region. Option::take
sets this new node's next pointer to the current head. The node is then
written to the beginning of the free region and the head is pointed
to it.

commit 1ae9915

ChangeLog

commit e9ae2aa

Create LinkedListAllocator struct using ListNode

The LinkedListAllocator has one field โ€” the head, a ListNode
pointing to the first region of freed heap memory.
LinkedListAllocator's new function doesn't initialize the allocator
with heap bounds because the ALLOCATOR static needs it at compile
time, whereas writing a node to heap memory must be done at runtime.
Thus we separate instantiation and initialization into a const fn
and unsafe fn respectively.

rustos's People

Contributors

nickschmitt avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.