diff options
-rw-r--r-- | kernel/include/buffer.h | 4 | ||||
-rw-r--r-- | kernel/include/hashtbl.h | 3 | ||||
-rw-r--r-- | kernel/lib/buffer.c | 8 |
3 files changed, 9 insertions, 6 deletions
diff --git a/kernel/include/buffer.h b/kernel/include/buffer.h index 577ceae..c47e2b4 100644 --- a/kernel/include/buffer.h +++ b/kernel/include/buffer.h @@ -7,6 +7,8 @@ // enabling the creation, sharing, slicing and concatenation of buffers // without having to copy everything each time +// Buffers are always allocated on the core kernel heap (kmalloc/kfree) + // Once a buffer is allocated, its contents is immutable // Encoding and decoding functions for buffer contents are provided in @@ -22,7 +24,7 @@ size_t buffer_len(buffer_t* buf); size_t read_buffer(buffer_t* buf, char* to, size_t begin, size_t n); // returns num of bytes read buffer_t* buffer_from_bytes(const char* data, size_t n); // bytes are COPIED -buffer_t* buffer_from_bytes_nocopy(const char* data, size_t n); // bytes are NOT COPIED +buffer_t* buffer_from_bytes_nocopy(const char* data, size_t n, bool own_bytes); // bytes are NOT COPIED // these functions GIVE the buffer in order to create the new buffer, ie they do not increase RC // the buffer is NOT GIVED if the new buffer could not be created (ie retval == 0) diff --git a/kernel/include/hashtbl.h b/kernel/include/hashtbl.h index 984aa70..16dfefb 100644 --- a/kernel/include/hashtbl.h +++ b/kernel/include/hashtbl.h @@ -8,6 +8,9 @@ // Supports adding, seeking, removing // When adding a binding to the table, the previous binding for same key (if exists) is removed +// TODO : possibility to allocate the hashtbl structure on any heap +// (currently uses kmalloc/kfree) + struct hashtbl; typedef struct hashtbl hashtbl_t; diff --git a/kernel/lib/buffer.c b/kernel/lib/buffer.c index 4d168e0..d2f9644 100644 --- a/kernel/lib/buffer.c +++ b/kernel/lib/buffer.c @@ -91,7 +91,7 @@ size_t read_buffer(buffer_t *b, char* dest, size_t begin, size_t n) { // BUFFER CREATION FUNCTIONS // // ========================= // -buffer_t *buffer_from_bytes_nocopy(const char* data, size_t n) { +buffer_t *buffer_from_bytes_nocopy(const char* data, size_t n, bool own_bytes) { buffer_t *b = (buffer_t*)kmalloc(sizeof(buffer_t)); if (b == 0) return 0; @@ -99,7 +99,7 @@ buffer_t *buffer_from_bytes_nocopy(const char* data, size_t n) { b->type = T_BYTES; b->len = n; b->bytes.data = data; - b->bytes.owned = false; + b->bytes.owned = own_bytes; return b; } @@ -109,14 +109,12 @@ buffer_t *buffer_from_bytes(const char* data, size_t n) { memcpy(data2, data, n); - buffer_t *b = buffer_from_bytes_nocopy(data2, n); + buffer_t *b = buffer_from_bytes_nocopy(data2, n, true); if (b == 0) { kfree(data2); return 0; } - b->bytes.owned = true; - return b; } |