summaryrefslogtreecommitdiffstats
path: root/firmware/buflib.c
AgeCommit message (Collapse)AuthorFilesLines
2020-07-15Buflib_init Bugfix MinsizeWilliam Wilgus1-0/+6
when buflib_init is called with a buffer smaller than sizeof(union buflib_data); size will be zero Later when the alloc fails buflib will keep try to free items in order to satisify the request this crashes in the sim I suspect this behavior holds true on device as well but I havent verified this as of yet. patch adds minimal overhead to the buflib and panics when the size is too small Change-Id: I46e510367fc1cac19ce01ee6f92d8cf0d65ef914
2019-01-04Buflib add range checks blocks and crc_slot raise panic if out of rangeWilliam Wilgus1-0/+7
Change-Id: I81df5c145a8cb003827a5423f484f70333e2472e
2015-01-02buflib: Switch from term "cookie" to "metadata"Thomas Jarosch1-13/+13
The documentation of buflib first mentions metadata and then changes to "cookie" without explaining it. Fix it by sticking to metadata. Change-Id: I0b36b18f4f2590132901c10326481975f8b9b9da
2015-01-02Improve core_alloc() / buflib_alloc() documentationThomas Jarosch1-3/+8
Document the fact that buffers are movable by default. Care must be taken to not pass them to functions that yield(). Also clarify other things: - Passing NULL as "ops" to buflib_alloc_ex() causes buffers to be movable by default (but not shrinkable). - If you want shrinkable buffers during compaction, you have to provide a shrink callback. - To disable buffer movement, you have to pass NULL for the move_callback inside the callback structure. - The concept of default callbacks was removed long ago, remove the only reference of it. Change-Id: I3bf0ea6b08b507d80a19f3c2c835aca32b3f7800
2015-01-01PictureFlow: Add move callback for buflib allocationsThomas Jarosch1-1/+1
If we don't provide a callback to buflib_alloc(), the buffer is always movable (to reduce fragmentation). Since we pass our buffer to functions that call yield(), this could lead to memory corruption on buflib compaction. Change-Id: Id1fad1822479d692551c55cb8bc87cea7b78f759
2014-12-30Add missing newline in debug outputThomas Jarosch1-1/+1
Change-Id: Ifd67dbcc80db328391464ec93316c48f914bc590
2014-12-29Document 'union buflib_data'Thomas Jarosch1-2/+2
Change-Id: Ia98fa8e7887338d6c0b7a5795a0ae5c7a13014ba
2014-02-02buflib: Add a define telling the per-alloc overhead.Thomas Martitz1-0/+2
This allows buflib clients to more accurately estimate the total memory usage. It's still not 100% accurate because the handle table grows in blocks, thus buflib might use more memory that caused by allocations directly. Change-Id: I68338bb94f510ad188fcb588aebf895b5f9197c5
2014-02-02buflib: Properly support allocations without any name, to avoid wasting spaceThomas Martitz1-13/+15
in micro-allocation scenarios. Change-Id: I97a065bcfba8e0fda9b1670445e839e267c769c8
2014-02-02buflib: Check the validity of of handles passed to buflib_get_data() in ↵Thomas Martitz1-0/+9
DEBUG builds. Change-Id: Ic274bfb4a8e1a1a10f9a54186b9173dbc0faa4c8
2014-02-02buflib: Abstract panicf() into buflib_panic().Thomas Martitz1-2/+18
Change-Id: I4968a9bc290e10e30a77c36c19f694e286e7ef22
2014-01-16buflib: Add crc field protecting buflib cookie integrityMarcin Bukat1-9/+63
This should catch the case of buffer misuse which results in corrupted cookie of next allocation. The check is performed on move_block() so it may be a bit late. There is buflib_check_valid() provided which checks the integrity of all cookies for given context. On DEBUG build with --sdl-thread this check is carried out for core_ctx on every context switch to catch problems earlier. Change-Id: I999d4576084592394e3dbd3bdf0f32935ff5f601 Reviewed-on: http://gerrit.rockbox.org/711 Reviewed-by: Thomas Martitz <kugel@rockbox.org>
2014-01-05Do not include kernel.h in system.h.Thomas Martitz1-0/+1
system.h doesn't need it on its own and this change makes it less dependant on Rockbox internals. Change-Id: I4e1e4108a52a7b599627a829204eb82b392fc6d6
2013-12-22buflib: Add buflib_context_relocate().Thomas Martitz1-0/+26
This function relocates a buflib back buffer, updating pointers in struct buflib_context. It does not move any data by itself. The intended use-case is buflib-on-buflib, where a buflib back buffer is allocated with buflib and attempted to be moved. The move_callback() can call this and return BUFLIB_CB_OK on success. No move_callback() is called for the subordinate buflib buffer, therefore it must not contain non-movable allocations. The caller is generally responsible moving the data and all its implications. Change-Id: I869219f9cff786a172c9e917a5f34470073892e6
2013-12-22buflib: Try harder in buflib_alloc_maximum().Thomas Martitz1-1/+12
This function will now ask shrinkable allocations to give up all of their memory. With future support of playback.c this can be used as a safe replacement for audio_get_buffer(). Change-Id: I290a51d2c75254e66baf5698c41dc444dea6247a
2013-07-07buflib: Change buflib_available() and add buflib_allocatable().Thomas Martitz1-2/+25
buflib_allocatable() is what buflib_available() was before (it was in fact simply renamed). It returns the largest contiguous block of memory. This can be allocated and will definitely succeed, although larger allocations may also succeed if the buffer can be compacted and shrinked. buflib_available() now counts all free bytes, contiguous or not. This better matches the description and how the caller use it. Change-Id: I511e4eb5f4cf1821d957b3f4ef8a685ce40fe289 Reviewed-on: http://gerrit.rockbox.org/481 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Tested-by: Thomas Martitz <kugel@rockbox.org>
2013-06-24buflib: Allow handle to be freed entirely during the shrink callback.Thomas Martitz1-4/+10
Change-Id: I3a069dcb99bbd4022faf37596b03beb926d2ea82 Reviewed-on: http://gerrit.rockbox.org/480 Reviewed-by: Thomas Martitz <kugel@rockbox.org> Tested-by: Thomas Martitz <kugel@rockbox.org>
2013-05-23buflib: Remove compulsory IRQ disable during buffer move.Michael Sevakis1-16/+2
It can cause excessively long interrupt outages if moving a larger buffer and disrupt audio where DMA is not at a higher interrupt priority such as FIQ. Some targets, like Gigabeat S, have very low audio interrupt latency requirements and will even channel swap if they are missed. Pictureflow will make the issue very obvious. Even then, moves could take milliseconds or more depending on the buffer size which is far too long for any target. Change-Id: I8e7817213e901da67c36b7eb25d7cb1c1e3ba802 Reviewed-on: http://gerrit.rockbox.org/472 Reviewed-by: Michael Sevakis <jethead71@rockbox.org> Tested-by: Michael Sevakis <jethead71@rockbox.org>
2012-05-02Stop the BDEBUGF format warnings in buflib.cMichael Sevakis1-2/+3
Change-Id: I63881da2b857cf4e462f7730f9cd54dc1743fc2f
2012-05-02Stop lame warnings about braces and empty body of 'if' statement.Michael Sevakis1-0/+8
Change-Id: I9f0e3d047a91a8f49d5c64f961f8fff054f37099
2012-05-02Use buflib for the allocation of voice PCM resources.Michael Sevakis1-12/+16
Buffers are not allocated and thread is not created until the first call where voice is required. Adds a different callback (sync_callback) to buflib so that other sorts of synchonization are possible, such as briefly locking-out the PCM callback for a buffer move. It's sort of a messy addition but it is needed so voice decoding won't have to be stopped when its buffer is moved. Change-Id: I4d4d8c35eed5dd15fb7ee7df9323af3d036e92b3
2011-12-19Buflib: Fix handles being possibly moved twiceThomas Martitz1-0/+1
Author: Boris Gjenero Fixes: FS#12441, FS#12464 git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31359 a1c6a512-1295-4272-9138-f99709370657
2011-12-01Address some weaknesses and bugs of buflib_compact() and make the code ↵Thomas Martitz1-24/+36
prettier. Thanks to Boris Gjenero for his great investigation. Flyspray: FS#12409 Author: myself git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31101 a1c6a512-1295-4272-9138-f99709370657
2011-11-29FS#12412 : Delete old buffer allocation code which has been replaced by ↵Boris Gjenero1-1/+0
core_alloc, and move buffer setup code to core_alloc.c git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31088 a1c6a512-1295-4272-9138-f99709370657
2011-11-27In buflib_buffer_shift(), properly update handle->alloc values, which are ↵Boris Gjenero1-2/+3
char * and not union buflib data * git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31066 a1c6a512-1295-4272-9138-f99709370657
2011-11-17Buflib: Make shrinking and buflib_available() smarter.Thomas Martitz1-6/+62
* shrinking now considers freespace just before the alloc-to-be-shrinked, that means less (or sometimes none at all) is taken from the audio buffer. * core_available() now searches for the best free space, instead of simply the end, i.e. it will not return 0 if the audio buffer is allocated and there's free space before it. It also runs a compaction to ensure maximum contiguous memory. audio_buffer_available() is also enhanced. It now considers the 256K reserve buffer, and returns free buflib space instead if the audio buffer is short. This all fixes the root problem of FS#12344 (Sansa Clip+: PANIC occurred when dircache is enabled), that alloced from the audio buffer, even if it was very short and buflib had many more available as free space before it. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31006 a1c6a512-1295-4272-9138-f99709370657
2011-10-09Fix audio_get_buffer() implementation on hwcodec, to be similar to the ↵Thomas Martitz1-0/+4
swcodec one. Should make hwcodec bood again. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30737 a1c6a512-1295-4272-9138-f99709370657
2011-10-09Protect the move operation of buflib against IRQs.Thomas Martitz1-0/+10
This makes accessing the buffers with core_get_data() from interrupt context safe, other buflib functions aren't really safe (yet). git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30736 a1c6a512-1295-4272-9138-f99709370657
2011-09-10Buflib: Correct return value of handle_table_shrink() to match comment.Thomas Martitz1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30495 a1c6a512-1295-4272-9138-f99709370657
2011-09-09Remove obsolete commentThomas Martitz1-3/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30488 a1c6a512-1295-4272-9138-f99709370657
2011-09-09Buflib: Stop caching the first unallocated block. It has little benefit but ↵Thomas Martitz1-43/+42
is complicated to keep up-to-date. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30487 a1c6a512-1295-4272-9138-f99709370657
2011-09-09Buflib: Handle not having enough space for new handles (fixes FS#12265).Thomas Martitz1-27/+40
Handles are allocated at the end, growing downwards. The tiny allocations from r30478 broke buflib, since it was assumed that the only shrinkable allocation (the audiobuffer) is the very last allocation. The tiny allocations however fit into the reserve buffer for new handles, breaking the above assumption, and they can't shrink to make room for handles. Now, move any allocations before audiobuf (or shrink audiobuf like before) to make room for handles. This also unifies some duplicated code. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30486 a1c6a512-1295-4272-9138-f99709370657
2011-09-07Remove unecessary castingThomas Martitz1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30470 a1c6a512-1295-4272-9138-f99709370657
2011-09-07Buflib: Clarification about invalid handlesThomas Martitz1-2/+2
* Enhance allocation function comments to better state the return value and what an invalid value is * Change clients to check for "< 0" instead of "<= 0" or "== 0" * Return -1 or -2 depending on the exact failure in buflib_alloc_ex. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30469 a1c6a512-1295-4272-9138-f99709370657
2011-08-30Fix h100 red and other warnings.Thomas Martitz1-1/+1
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30384 a1c6a512-1295-4272-9138-f99709370657
2011-08-30GSoC/Buflib: Enable compaction in buflib.Thomas Martitz1-5/+0
This enables the ability to allocate (and free) memory dynamically without fragmentation, through compaction. This means allocations can move and fragmentation be reduced. Most changes are preparing Rockbox for this, which many times means adding a move callback which can temporarily disable movement when the corresponding code is in a critical section. For now, the audio buffer allocation has a central role, because it's the one having allocated most. This buffer is able to shrink itself, for which it needs to stop playback for a very short moment. For this, audio_buffer_available() returns the size of the audio buffer which can possibly be used by other allocations because the audio buffer can shrink. lastfm scrobbling and timestretch can now be toggled at runtime without requiring a reboot. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30381 a1c6a512-1295-4272-9138-f99709370657
2011-08-30GSoC/Buflib: Add buflib memory alocator to the core.Thomas Martitz1-0/+777
The buflib memory allocator is handle based and can free and compact, move or resize memory on demand. This allows to effeciently allocate memory dynamically without an MMU, by avoiding fragmentation through memory compaction. This patch adds the buflib library to the core, along with convinience wrappers to omit the context parameter. Compaction is not yet enabled, but will be in a later patch. Therefore, this acts as a replacement for buffer_alloc/buffer_get_buffer() with the benifit of a debug menu. See buflib.h for some API documentation. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30380 a1c6a512-1295-4272-9138-f99709370657