aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / mm / heap.h
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* heap.h -- first-fit kernel heap over one contiguous region. Blocks carry a |
| 18 | * 16-byte header (size, magic); payloads are 16-byte aligned and zeroed on |
| 19 | * allocation; free coalesces with free neighbours. Pure, host testable. */ |
| 20 | #ifndef AIENOS_CK_HEAP_H |
| 21 | #define AIENOS_CK_HEAP_H |
| 22 | |
| 23 | #include <stddef.h> |
| 24 | #include <stdint.h> |
| 25 | |
| 26 | struct ck_heap { |
| 27 | uint8_t *base; |
| 28 | size_t size; |
| 29 | }; |
| 30 | |
| 31 | int ck_heap_init(struct ck_heap *h, void *base, size_t size); |
| 32 | void *ck_heap_alloc(struct ck_heap *h, size_t bytes); |
| 33 | /* 0 on success; -1 for a pointer that is not a live block (double free, |
| 34 | * foreign pointer, corrupted header). */ |
| 35 | int ck_heap_free(struct ck_heap *h, void *p); |
| 36 | size_t ck_heap_free_bytes(const struct ck_heap *h); |
| 37 | /* Walks every block; 0 if all headers are intact and sizes add up. */ |
| 38 | int ck_heap_check(const struct ck_heap *h); |
| 39 | |
| 40 | #endif |