Skip to content

Commit c02b317

Browse files
committed
audio: iadk: resolve missing module placeholders
The current loadable-module entry point calls the system agent with a null placeholder. Creating the module at that address corrupts memory before its adapter can register. Resolve a null placeholder to the instance BSS already allocated by the library manager. Also propagate factory errors and reject a module that did not register an adapter. Signed-off-by: Gaggery Tsai <gaggery.tsai@intel.com>
1 parent f00d8c3 commit c02b317

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

src/audio/module_adapter/iadk/README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,11 @@ keep their API 4.5.0 layout.
5858

5959
1. The OS host driver sends an IPC `INIT_INSTANCE` command for the module.
6060
2. The `system_agent_start()` function intercepts this, invokes the dynamic module's `create_instance` entry point (which invokes a `ModuleFactory`).
61-
3. The `SystemAgent` deduces the pin count (interfaces) and initial pipeline configurations using `ModuleInitialSettingsConcrete`.
62-
4. The factory allocates the concrete algorithm and checks it back into SOF through `SystemAgent::CheckIn`.
61+
3. If the entry point provides a null module placeholder, the `SystemAgent`
62+
resolves it to the instance BSS allocated by the library manager after
63+
verifying that the module object fits in that region.
64+
4. The `SystemAgent` deduces the pin count (interfaces) and initial pipeline configurations using `ModuleInitialSettingsConcrete`.
65+
5. The factory allocates the concrete algorithm and checks it back into SOF through `SystemAgent::CheckIn`.
6366

6467
```mermaid
6568
sequenceDiagram
@@ -70,6 +73,7 @@ sequenceDiagram
7073
7174
IPC->>SA: Trigger Mod Creation
7275
SA->>Fac: CI invokes create_instance
76+
SA->>SA: Resolve instance BSS placeholder
7377
Fac->>Fac: Deduce BaseModuleCfgExt
7478
Fac->>Mod: operator new instantiate
7579

src/audio/module_adapter/iadk/system_agent.cpp

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
#include <sof/audio/module_adapter/library/native_system_service.h>
2525
#include <sof/audio/module_adapter/library/native_system_agent.h>
2626

27+
/* sof/lib_manager.h pulls C-only component headers into this C++ unit. */
2728
struct sof_man_module;
2829
extern "C" const struct sof_man_module *
2930
lib_manager_get_module_manifest(const uint32_t module_id);
3031
extern "C" void
3132
lib_manager_get_instance_bss_address(uint32_t instance_id,
3233
const struct sof_man_module *mod,
33-
void **va_addr, size_t *size);
34+
void __sparse_cache **va_addr, size_t *size);
3435

3536
using namespace intel_adsp;
3637
using namespace intel_adsp::system;
@@ -46,6 +47,21 @@ namespace intel_adsp
4647
namespace system
4748
{
4849

50+
static void *system_agent_get_instance_bss(uint32_t module_id,
51+
uint32_t instance_id,
52+
size_t *size)
53+
{
54+
const struct sof_man_module *mod = lib_manager_get_module_manifest(module_id);
55+
void __sparse_cache *base = NULL;
56+
57+
*size = 0;
58+
if (!mod)
59+
return NULL;
60+
61+
lib_manager_get_instance_bss_address(instance_id, mod, &base, size);
62+
return reinterpret_cast<void *>(base);
63+
}
64+
4965
/* Structure storing handles to system service operations */
5066
const APP_TASK_DATA AdspSystemService SystemAgent::system_service_ = {
5167
native_system_service_log_message,
@@ -98,15 +114,9 @@ void SystemAgent::CheckInDetector(DetectorModuleInterface& processing_module,
98114

99115
void *SystemAgent::GetBssBase(void)
100116
{
101-
const struct sof_man_module *mod = lib_manager_get_module_manifest(module_id_);
102-
void *base = NULL;
103117
size_t size = 0;
104118

105-
if (!mod)
106-
return NULL;
107-
108-
lib_manager_get_instance_bss_address(instance_id_, mod, &base, &size);
109-
return base;
119+
return system_agent_get_instance_bss(module_id_, instance_id_, &size);
110120
}
111121

112122
int SystemAgent::CheckIn(ProcessingModuleFactoryInterface& module_factory,
@@ -117,6 +127,19 @@ int SystemAgent::CheckIn(ProcessingModuleFactoryInterface& module_factory,
117127
void *obfuscated_parent_ppl,
118128
void **obfuscated_modinst_p)
119129
{
130+
if (!module_placeholder) {
131+
size_t bss_size;
132+
void *bss_base = system_agent_get_instance_bss(module_id_, instance_id_,
133+
&bss_size);
134+
135+
if (!bss_base || processing_module_size > bss_size)
136+
return -ENOMEM;
137+
138+
module_placeholder = reinterpret_cast<ModulePlaceholder *>(bss_base);
139+
}
140+
141+
module_size_ = processing_module_size;
142+
120143
IoPinsInfo pins_info;
121144
const dsp_fw::DwordArray& cfg_ipc_msg =
122145
*reinterpret_cast<const dsp_fw::DwordArray*>(obfuscated_mod_cfg);
@@ -140,7 +163,14 @@ int SystemAgent::CheckIn(ProcessingModuleFactoryInterface& module_factory,
140163
settings.DeduceBaseModuleCfgExt(prerequisites.input_pins_count,
141164
prerequisites.output_pins_count);
142165

143-
module_factory.Create(*this, module_placeholder, ModuleInitialSettings(settings), pins_info);
166+
int ret = module_factory.Create(*this, module_placeholder,
167+
ModuleInitialSettings(settings), pins_info);
168+
if (ret)
169+
return ret;
170+
171+
if (!module_handle_)
172+
return -EINVAL;
173+
144174
IadkModuleAdapter& module_adapter = *reinterpret_cast<IadkModuleAdapter*>(module_handle_);
145175
*obfuscated_modinst_p = &module_adapter;
146176
reinterpret_cast<intel_adsp::ProcessingModuleInterface*>(module_placeholder)->Init();

0 commit comments

Comments
 (0)