From 07da22df212ddbf7ae56d9c0e04bb7ced4cca0a0 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 25 Feb 2016 11:27:17 +0100 Subject: lib: du_buff alloc API changed to return pointers du_buff.[c/h]: alloc_head and alloc_tail now return a pointer to the start of the PCI for direct read/write access. --- include/ouroboros/du_buff.h | 4 ++-- src/lib/du_buff.c | 44 ++++++++++++++++++++++---------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/include/ouroboros/du_buff.h b/include/ouroboros/du_buff.h index 92d0609d..66904ca7 100644 --- a/include/ouroboros/du_buff.h +++ b/include/ouroboros/du_buff.h @@ -39,8 +39,8 @@ int du_buff_init(du_buff_t * dub, uint8_t * data, size_t len); -int du_buff_head_alloc(du_buff_t * dub, size_t size); -int du_buff_tail_alloc(du_buff_t * dub, size_t size); +uint8_t * du_buff_head_alloc(du_buff_t * dub, size_t size); +uint8_t * du_buff_tail_alloc(du_buff_t * dub, size_t size); int du_buff_head_release(du_buff_t * dub, size_t size); int du_buff_tail_release(du_buff_t * dub, size_t size); diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c index 324dccc5..3db01831 100644 --- a/src/lib/du_buff.c +++ b/src/lib/du_buff.c @@ -43,8 +43,8 @@ struct buffer { struct du_buff { struct buffer * buffer; size_t size; - size_t du_start; - size_t du_end; + size_t du_head; + size_t du_tail; }; void buffer_destroy(struct buffer * buf) @@ -253,8 +253,8 @@ du_buff_t * du_buff_create(size_t size) dub->buffer = NULL; dub->size = size; - dub->du_start = 0; - dub->du_end = 0; + dub->du_head = 0; + dub->du_tail = 0; return dub; } @@ -294,44 +294,44 @@ int du_buff_init(du_buff_t * dub, if (dub->buffer == NULL) return -ENOMEM; - dub->du_start = start; - dub->du_end = start + len; + dub->du_head = start; + dub->du_tail = start + len; return buffer_copy_data(dub->buffer, start, data, len); } -int du_buff_head_alloc(du_buff_t * dub, size_t size) +uint8_t * du_buff_head_alloc(du_buff_t * dub, size_t size) { if (dub == NULL) { LOG_DBGF("Bogus input, bugging out."); - return -EINVAL; + return NULL; } - if (dub->du_start - size < 0) { + if (dub->du_head - size < 0) { LOG_WARN("Failed to allocate PCI headspace"); - return -ENOBUFS; + return NULL; } - dub->du_start -= size; + dub->du_head -= size; - return 0; + return (buffer_seek_pos(dub->buffer, dub->du_head)); } -int du_buff_tail_alloc(du_buff_t * dub, size_t size) +uint8_t * du_buff_tail_alloc(du_buff_t * dub, size_t size) { if (dub == NULL) { LOG_DBGF("Bogus input, bugging out."); - return -EINVAL; + return NULL; } - if (dub->du_end + size >= dub->size) { + if (dub->du_tail + size >= dub->size) { LOG_WARN("Failed to allocate PCI tailspace"); - return -ENOBUFS; + return NULL; } - dub->du_end += size; + dub->du_tail += size; - return 0; + return (buffer_seek_pos(dub->buffer, dub->du_tail)); } int du_buff_head_release(du_buff_t * dub, size_t size) @@ -341,12 +341,12 @@ int du_buff_head_release(du_buff_t * dub, size_t size) return -EINVAL; } - if (size > dub->du_end - dub->du_start) { + if (size > dub->du_tail - dub->du_head) { LOG_WARN("Tried to release beyond sdu boundary"); return -EOVERFLOW; } - dub->du_start += size; + dub->du_head += size; /* FIXME: copy some random crap to the buffer for security */ @@ -360,12 +360,12 @@ int du_buff_tail_release(du_buff_t * dub, size_t size) return -EINVAL; } - if (size > dub->du_end - dub->du_start) { + if (size > dub->du_tail - dub->du_head) { LOG_WARN("Tried to release beyond sdu boundary"); return -EOVERFLOW; } - dub->du_end -= size; + dub->du_tail -= size; /* FIXME: copy some random crap to the buffer for security */ -- cgit v1.2.3 From 93e08315402c586a73fe3b9335e8d669ffc6511a Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Thu, 25 Feb 2016 11:33:12 +0100 Subject: lib: Fixed some indentation issues in du_buff.c --- src/lib/du_buff.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/du_buff.c b/src/lib/du_buff.c index 3db01831..f365ffc2 100644 --- a/src/lib/du_buff.c +++ b/src/lib/du_buff.c @@ -251,10 +251,10 @@ du_buff_t * du_buff_create(size_t size) return NULL; } - dub->buffer = NULL; - dub->size = size; + dub->buffer = NULL; + dub->size = size; dub->du_head = 0; - dub->du_tail = 0; + dub->du_tail = 0; return dub; } -- cgit v1.2.3