First commit, Vystem v0.1
This commit is contained in:
7
docs/shelter/std/malloc.md
Normal file
7
docs/shelter/std/malloc.md
Normal file
@@ -0,0 +1,7 @@
|
||||
# Heap memory allocations
|
||||
|
||||
The Shelter standard library provide a single API for memory allocations on the heap. The heap is only initialized at the end of the memory subsystem and can't be used before. It's not adapted for memory mapped I/O or big buffers allocations (larger than one hundrer pages). The heap internal documentation can be found inside the memory subsystem documentation.
|
||||
|
||||
The memory allocations API provide the two following functions (defined inside `shelter/lib/include/std/malloc.h` and implemented inside `shelter/lib/src/std/malloc.c`):
|
||||
- `void* sh_malloc(sh_uint64 size)`: allocate `size` amount of bytes. Return `SH_NULLPTR` if an error occured. The heap internal will trigger a heap crash (essentially a `while (SH_TRUE)` loop) to prevent any further damage if something very bad happen.
|
||||
- `void sh_free(void *ptr)`: free the memory allocated at `ptr`. The heap internal will trigger a heap crash (essentially a `while (SH_TRUE)` loop) to prevent any further damage if something very bad happen.
|
||||
6
docs/shelter/std/mem.md
Normal file
6
docs/shelter/std/mem.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# Basic memory operations
|
||||
|
||||
The Shelter standard library provide very basic memory operations primitives, defined in `shelter/lib/include/std/mem.h` and implemented inside `shelter/lib/src/std/mem.c`:
|
||||
- `SH_STATUS sh_mem_compare(const void *a,const void *b,sh_uint64 size)`: compare two memory regions with the same size. Return `SH_STATUS_SUCCESS` if both regions are equal, or `SH_STATUS_MEM_NOT_EQUAL` if one byte is different.
|
||||
- `SH_STATUS sh_mem_copy(const void *destination,const void *source,sh_uint64 size)`: copy one region of memory to another. Return `SH_STATUS_SUCCESS`
|
||||
- `SH_STATUS sh_mem_set_8(sh_uint8 *ptr,const sh_uint8 byte,sh_uint64 count)`: set a provided amount of bytes to the value of one provided byte. Return `SH_STATUS_SUCCESS`
|
||||
20
docs/shelter/std/status.md
Normal file
20
docs/shelter/std/status.md
Normal file
@@ -0,0 +1,20 @@
|
||||
# Return status
|
||||
|
||||
## Introduction
|
||||
|
||||
The vast majority of functions in Shelter return status code know as the `SH_STATUS` type. All the status codes are defined inside `shelter/lib/include/std/status.h`.
|
||||
|
||||
## Overview
|
||||
|
||||
Shelter define a status code with the `SH_STATUS` type. It's a wrapper of `sh_int64`.
|
||||
|
||||
The sign of a status play a big role:
|
||||
- If the sign is negative, the status code isn't an error but rather an indication of something not that bad that happened during the function call. It can also serve the purpose of indicating a more detailled result.
|
||||
- If the status code is 0, it's equivalent to a success, defined as `SH_STATUS_SUCCESS`
|
||||
- If the sign is positive, the status code signify an error. You can use the `sh_status_error(SH_STATUS status)` function to know if a status code is an error. Return `SH_TRUE` if so.
|
||||
|
||||
Please check `shelter/lib/include/std/status.h` for the list of all status codes.
|
||||
|
||||
In Shelter, most function will returned to the caller the status code of all the functions calls they made if an error happened. Sometimes, it's necessary to dig through the code to understand from where an error come from.
|
||||
|
||||
If at any moment, a function that return a `SH_STATUS` call a function that return a pointer and the pointer is `SH_NULLPTR`, the status code `SH_STATUS_ERROR_NULLPTR_RETURNED` (not all error start with `SH_STATUS_ERROR`) will be returned.
|
||||
14
docs/shelter/std/std.md
Normal file
14
docs/shelter/std/std.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Shelter standard library
|
||||
|
||||
## Introduction
|
||||
|
||||
In order to function properly, any kernel need a standard library. Shelter define his own minimal standard library with his own particularities.
|
||||
|
||||
## Summary
|
||||
|
||||
1) [Basic types](types.md)
|
||||
2) [Return status](status.md)
|
||||
3) [Basic memory operations](mem.md)
|
||||
4) [Heap memory allocations](malloc.md)
|
||||
|
||||
You can include the file `shelter/lib/include/std/stdlib.h` to include all necessary headers to access the Shelter standard library.
|
||||
35
docs/shelter/std/types.md
Normal file
35
docs/shelter/std/types.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Basic types
|
||||
|
||||
The Shelter standard library define the following type in `shelter/lib/include/std/type.h`:
|
||||
- `sh_int8`: 1 byte signed integer
|
||||
- `sh_uint8`: 1 byte unsigned integer
|
||||
- `sh_int16`: 2 bytes signed integer
|
||||
- `sh_uint16`: 2 bytes unsigned integer
|
||||
- `sh_int32`: 4 bytes signed integer
|
||||
- `sh_uint32`: 4 bytes unsigned integer
|
||||
- `sh_int64`: 8 bytes signed integer
|
||||
- `sh_uint64`: 8 bytes unsigned integer
|
||||
- `sh_bool`: wrapper of `sh_uint8`
|
||||
- `sh_iter64`: wrapper of `sh_uint64`, used for loops
|
||||
- `va_list`: wrapper of `__builtin_va_list`
|
||||
|
||||
The Shelter standard library the following macros and values in `shelter/lib/include/std/type.h`:
|
||||
- `SH_INT8_MIN`: the minimum possible value of `sh_int8`
|
||||
- `SH_INT8_MAX`: the maximum possible value of `sh_int8`
|
||||
- `SH_UINT8_MAX`: the maximum possible value of `sh_uint8`
|
||||
- `SH_INT16_MIN`: the minimum possible value of `sh_int16`
|
||||
- `SH_INT16_MAX`: the maximum possible value of `sh_int16`
|
||||
- `SH_UINT16_MAX`: the maximum possible value of `sh_uint16`
|
||||
- `SH_INT32_MIN`: the minimum possible value of `sh_int32`
|
||||
- `SH_INT32_MAX`: the maximum possible value of `sh_int32`
|
||||
- `SH_UINT32_MAX`: the maximum possible value of `sh_uint32`
|
||||
- `SH_INT64_MIN`: the minimum possible value of `sh_int64`
|
||||
- `SH_INT64_MAX`: the maximum possible value of `sh_int64`
|
||||
- `SH_UINT64_MAX`: the maximum possible value of `sh_uint64`
|
||||
- `SH_TRUE`: a wrapper of `(sh_bool)1`
|
||||
- `SH_FALSE`: a wrapper of `(sh_bool)0`
|
||||
- `SH_DEFVALUE`: the default value for any argument marked by `DEFAULT`
|
||||
- `SH_NULLPTR`: wrapper of `(void*)0`
|
||||
- `va_start(v,l)`: wrapper of `__builtin_va_start(v,l)`
|
||||
- `va_end(v)`: wrapper of `__builtin_va_end(v)`
|
||||
- `va_arg(v,l)`: wrapper of `__builtin_va_arg(v,l)`
|
||||
Reference in New Issue
Block a user