summaryrefslogtreecommitdiffstats
path: root/lib/libjove/include/object-untyped.h
blob: a947c23dfe58db85996274c2470aeef0a36baa6d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _LIBJOVE_OBJECT_UNTYPED_H
#define _LIBJOVE_OBJECT_UNTYPED_H 1

#include <jove/object-typed.h>
#include <jove/object-dir.h>

/**@STRUCT Represents a KO_MEMOY_UNTYPED*/
typedef struct _KernelObjectUntyped
{
    KernelObjectTyped typed;
    size_t bytes;
    intmax_t alignment;

    KernelObjectTyped *children_head;
    KernelObjectTyped *sibling;
} KernelObjectUntyped;

extern KernelObjectDirectory __jove_untyped_directory;

/**@FUNC INTERNAL FUNCTION DO NOT USE.
 * Initializes a block of memory as an untyped object.
 * @PARAM untyped pointer to new block of memory.
 * @PARAM parent directory this new object is a member of.
 * @PARAM membi index to place this new object.*/
void _jove_alloc_untyped_inplace(KernelObjectUntyped *untyped, struct _KernelObjectDirectory *parent, uint8_t membi);

/**@FUNC INTERNAL FUNCTION DO NOT USE.
 * Allocates a block of memory representing an untyped object into the heap.
 * @PARAM parent directory this new object is a member of.
 * @PARAM membi index to place this new object.
 * @RETURN pointer to allocated object. NULL on failure. 
 * Possible failures:
 *      EJOVE_NOALLOC: libjove does not have an allocator set yet.
 *      EJOVE_FULL: destination is already taken.*/
KernelObjectUntyped *_jove_alloc_untyped(struct _KernelObjectDirectory *parent, uint8_t membi);

/**@FUNC Changes pointer type of typed object to untyped if correct.
 * @PARAM typed pointer to convert.
 * @RETURN pointer as KernelObjectUntyped*, NULL on failure.
 * Possible failures:
 *      EJOVE_BADOBJ: passed object is not an untyped.*/
KernelObjectUntyped *jove_object_as_untyped(KernelObjectTyped *typed);

/**@FUNC Gets the number of bytes a given untyped block represents.
 * @PARAM untyped block of untyped memory.
 * @RETURN number of bytes. negative on failure.
 * Possible failures:
 *      EJOVE_BADOBJ: passed object does not exist / is not an untyped. */
int jove_untyped_size(KernelObjectUntyped *untyped);

/**@FUNC Gets the byte alignment of a given untyped block up to a page.
 * @PARAM untyped block of untyped memory.
 * @RETURN alignment in bytes. negative on failure.*/
int jove_untyped_alignment(KernelObjectUntyped *untyped);

/**@FUNC Splits a given untyped block of memory into a block with the given size
 * and the remainder. New untyped object is stored in dest at destmemb.
 * @PARAM untyped block of untyped memory to split.
 * @PARAM bytes number of bytes the new block should have.
 *        Minimum sizeof(size_t)
 * @PARAM dest directory to store the new block.
 * @PARAM destmemb index in dest to store new block.
 * @RETURN Newly created block of memory. NULL on failure.
 * Possible failures:
 *      EJOVE_BADSIZE: bytes < sizeof(size_t)
 *      EJOVE_BADOBJ: dest or untyped are incorrect types / do not exist.*/
KernelObjectUntyped *jove_untyped_split(
        KernelObjectUntyped *untyped, size_t bytes,
        KernelObjectDirectory *dest, uint8_t destmemb);

JoveError jove_untyped_split_inplace(
        KernelObjectUntyped *untyped,
        size_t bytes,
        KernelObjectUntyped *dest);

#endif