atsushieno / aap-core

an Audio Plugin Format/Framework for Android
MIT License
92 stars 3 forks source link

Clean up memory management regarding audio buffers, extensions, and shared memory #113

Closed atsushieno closed 2 years ago

atsushieno commented 2 years ago

Current implementation causes fdsan violation which seems due to inconsistent mmap state:

fdsan: attempted to close file descriptor 124, expected to be unowned, actually owned by unique_fd 0xb90c3ed4

To find out the cause of it, I have been investigating the existing code, noticed that current buffer management is a big mess spaghetti code. Therefore I am refactoring the port fundamentals to make it possible to dynamically determine port configs and allocate shared memory as well as buffers.

On an ongoing change I have merged PluginSharedMemoryBuffer into AAPXSSharedMemoryStore to unify/simplify some memory management bits in a place, but it is likely bringing in another conflict of interest; AAPXS has be isolated from aap::PluginHost implementation. They have to be sorted out and desirably well documented.

atsushieno commented 2 years ago

Almost figured out: when we migrated Kotlin client internals to NativeRemotePluginInstance class, it has its own JNI glue code that calls ASharedMemory_create() and mmap() by its own (because we need audio buffer at client side), whereas those shared memory classes expect them stored within themselves. We should probably have to find the way to not create native buffer at client.

atsushieno commented 2 years ago

fdsan errors are gone with eb6af71, but aapbarebonepluginsample causes another crash:

Scudo ERROR: corrupted chunk header at address 0xc0fe6730

Fortunately it is 100% reproducible at PluginBuffer::~PluginBuffer(), at freeing the 8th buffer (i = 7).

related: https://source.android.com/devices/tech/debug/scudo

atsushieno commented 2 years ago

All those crashers are gone. I still see Android Studio causing random crashes while debugging, but it seems that Android Studio + LLDB integration itself is super buggy right now and it never happens when I run those apps without debugging.

I can close this issue, but maybe some documentation improvements is desired.

atsushieno commented 2 years ago

On trying aap-lv2-mda I noticed that some plugins crashes, but it seems dependent on order of tried plugins. It is most likely PluginPreview or something is stale about state.

atsushieno commented 2 years ago

It is completed as ^.