|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Read a page-cached object as a seekable byte stream – impl (#147/#151). More...
#include "ra8_vmem_stream.h"#include <stddef.h>#include <stdint.h>#include <string.h>#include "ra8_check.h"#include "ra8_err.h"#include "ra8_vmem.h"Go to the source code of this file.
Functions | |
| ra8_err_t | ra8_vmem_stream_init (ra8_vmem_stream_t *st, ra8_vmem_t *vm, uint32_t object_id, uint64_t size) |
| Bind a page-cached paged object to the byte-stream reader. | |
| size_t | ra8_vmem_stream_read (void *ctx, uint64_t offset, void *buf, size_t len) |
| Read len bytes at absolute offset through the page cache. | |
Variables | |
| static const char *const | s_tag = "ra8_vmem_stream" |
| Module log tag. | |
Read a page-cached object as a seekable byte stream – impl (#147/#151).
Serves an arbitrary (offset, len) span by walking the covering cache frames one at a time: page in the frame that holds cur (ra8_vmem_get), copy the in-frame slice, release the pin (ra8_vmem_put), and advance. At most one frame is pinned at any instant, so the resident set is the caller's fixed ra8_vmem pool plus O(1) – never the object size.
Definition in file ra8_vmem_stream.c.
|
nodiscard |
Bind a page-cached paged object to the byte-stream reader.
| [out] | st | Stream binding to populate (zero-initialised by caller). |
| [in] | vm | Initialised cache whose loader serves object_id. |
| [in] | object_id | A paged object id registered with vm's source. |
| [in] | size | Object length in bytes (> 0). |
| k_ra8_ok | Bound; ra8_vmem_stream_read may be used. |
| k_ra8_err_null_ptr | st or vm was NULL. |
| k_ra8_err_invalid_size | size was 0, or vm's frame size was 0. |
object_id. Definition at line 33 of file ra8_vmem_stream.c.
References ra8_vmem_t::cfg, ra8_vmem_cfg_t::frame_bytes, ra8_vmem_stream_t::frame_bytes, k_ra8_err_invalid_size, k_ra8_ok, ra8_vmem_stream_t::object_id, RA8_CHECK_NULL_PTR, s_tag, ra8_vmem_stream_t::size, and ra8_vmem_stream_t::vm.
Referenced by internal_cache_bind(), and mem_run_vmem().
| size_t ra8_vmem_stream_read | ( | void * | ctx, |
| uint64_t | offset, | ||
| void * | buf, | ||
| size_t | len ) |
Read len bytes at absolute offset through the page cache.
Pages the covering frames through the SLRU cache one at a time, copying each in-frame slice into buf, and clamps the request to the object end. A read fully past the end returns 0; a partial read (a cache/loader failure mid-span) returns the bytes copied so far, which a consumer like ra8_epub_open_streamed() treats as end-of-file.
| [in] | ctx | The ra8_vmem_stream_t binding (as a void cookie). |
| [in] | offset | Absolute byte offset within the object. |
| [out] | buf | Destination buffer (len writable bytes). |
| [in] | len | Bytes requested. |
| len | The full request was satisfied (every covering frame paged in). |
| 0 | offset is at/after the object end, or the first frame failed. |
| <len | A frame failed mid-span; the bytes copied before the failure. |
Definition at line 51 of file ra8_vmem_stream.c.
References ra8_vmem_stream_t::frame_bytes, k_ra8_ok, memcpy(), ra8_vmem_stream_t::object_id, ra8_vmem_get(), ra8_vmem_put(), ra8_vmem_stream_t::size, and ra8_vmem_stream_t::vm.
Referenced by internal_stream_open(), and mem_stream_window().
|
static |
Module log tag.
Definition at line 30 of file ra8_vmem_stream.c.