mirror of
https://github.com/neocturne/fastd.git
synced 2025-05-14 12:25:07 +02:00
buffer: move allocation function into separate compilation unit
This commit is contained in:
parent
5ab8c7c154
commit
32e861ef68
3 changed files with 34 additions and 14 deletions
31
src/buffer.c
Normal file
31
src/buffer.c
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
/*
|
||||||
|
Copyright (c) 2012-2016, Matthias Schiffer <mschiffer@universe-factory.net>
|
||||||
|
All rights reserved.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
\file
|
||||||
|
|
||||||
|
Buffer management
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "alloc.h"
|
||||||
|
#include "buffer.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Allocate a new buffer
|
||||||
|
|
||||||
|
A buffer can have head and tail space which allows changing with data size without moving the data.
|
||||||
|
|
||||||
|
The buffer is always allocated aligned to 16 bytes to allow efficient access for SIMD instructions
|
||||||
|
etc. in crypto implementations
|
||||||
|
*/
|
||||||
|
fastd_buffer_t fastd_buffer_alloc(const size_t len, size_t head_space, size_t tail_space) {
|
||||||
|
size_t base_len = alignto(head_space + len + tail_space, sizeof(fastd_block128_t));
|
||||||
|
void *ptr = fastd_alloc_aligned(base_len, sizeof(fastd_block128_t));
|
||||||
|
|
||||||
|
return (fastd_buffer_t){ .base = ptr, .base_len = base_len, .data = ptr + head_space, .len = len };
|
||||||
|
}
|
16
src/buffer.h
16
src/buffer.h
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "alloc.h"
|
#include "log.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,20 +27,8 @@ struct fastd_buffer {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
fastd_buffer_t fastd_buffer_alloc(const size_t len, size_t head_space, size_t tail_space);
|
||||||
Allocate a new buffer
|
|
||||||
|
|
||||||
A buffer can have head and tail space which allows changing with data size without moving the data.
|
|
||||||
|
|
||||||
The buffer is always allocated aligned to 16 bytes to allow efficient access for SIMD instructions
|
|
||||||
etc. in crypto implementations
|
|
||||||
*/
|
|
||||||
static inline fastd_buffer_t fastd_buffer_alloc(const size_t len, size_t head_space, size_t tail_space) {
|
|
||||||
size_t base_len = alignto(head_space + len + tail_space, sizeof(fastd_block128_t));
|
|
||||||
void *ptr = fastd_alloc_aligned(base_len, sizeof(fastd_block128_t));
|
|
||||||
|
|
||||||
return (fastd_buffer_t){ .base = ptr, .base_len = base_len, .data = ptr + head_space, .len = len };
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Duplicates a buffer */
|
/** Duplicates a buffer */
|
||||||
static inline fastd_buffer_t fastd_buffer_dup(const fastd_buffer_t buffer, size_t head_space, size_t tail_space) {
|
static inline fastd_buffer_t fastd_buffer_dup(const fastd_buffer_t buffer, size_t head_space, size_t tail_space) {
|
||||||
|
|
|
@ -35,6 +35,7 @@ src = [
|
||||||
version_h,
|
version_h,
|
||||||
'android.c',
|
'android.c',
|
||||||
'async.c',
|
'async.c',
|
||||||
|
'buffer.c',
|
||||||
'capabilities.c',
|
'capabilities.c',
|
||||||
'config.c',
|
'config.c',
|
||||||
'fastd.c',
|
'fastd.c',
|
||||||
|
|
Loading…
Add table
Reference in a new issue