1/* @ajax/mesh-view-alloc: first-fit allocation over the view heap's
2 * VIEW_PAGES pages (programs.rs Heap). A view of 0 bytes takes no page
3 * (offset 0). Offsets are mailbox offsets. Freeing a free page is a bug in
4 * meshd: it aborts, as the Rust panics. */
5#ifndef MESH_VIEW_ALLOC_H
6#define MESH_VIEW_ALLOC_H
78#include "mesh/abi/view_heap.h"
910#include <stdbool.h>
11#include <stddef.h>
12#include <stdint.h>
1314typedef struct {
15 bool used[MESH_VIEW_PAGES];
16} mesh_view_heap;
1718void mesh_view_heap_init(mesh_view_heap *h);
19/* Pages a view of `bytes` takes. */
20size_t mesh_view_pages(uint32_t bytes);
21/* A view's mailbox offset (0 for 0 bytes); false when no run of pages fits. */
22bool mesh_view_heap_alloc(mesh_view_heap *h, uint32_t bytes, uint32_t *off);
23void mesh_view_heap_free(mesh_view_heap *h, uint32_t off, uint32_t bytes);
24uint32_t mesh_view_heap_free_pages(const mesh_view_heap *h);
25/* The largest run of free pages (the largest view that still loads). */
26uint32_t mesh_view_heap_largest_run(const mesh_view_heap *h);
2728#endif