From 25ee559c5b420199d3421057036b3489186ba97a Mon Sep 17 00:00:00 2001 From: Konrad Dybcio Date: Mon, 11 Aug 2025 11:57:25 +0200 Subject: [PATCH 1/3] Add .clang-format Formatting tools help maintain style consistency across the codebase. Add a config for the de-facto standard formatter, clang-format. Loosely based on the kernel code style Signed-off-by: Konrad Dybcio --- .clang-format | 243 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 .clang-format diff --git a/.clang-format b/.clang-format new file mode 100644 index 00000000..342de3c4 --- /dev/null +++ b/.clang-format @@ -0,0 +1,243 @@ +--- +Language: Cpp +AccessModifierOffset: -2 +AlignAfterOpenBracket: Align +AlignArrayOfStructures: None +AlignConsecutiveAssignments: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: true +AlignConsecutiveBitFields: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveDeclarations: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveMacros: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCompound: false + AlignFunctionPointers: false + PadOperators: false +AlignConsecutiveShortCaseStatements: + Enabled: false + AcrossEmptyLines: false + AcrossComments: false + AlignCaseColons: false +AlignEscapedNewlines: Right +AlignOperands: Align +AlignTrailingComments: + Kind: Always + OverEmptyLines: 0 +AllowAllArgumentsOnNextLine: true +AllowAllParametersOfDeclarationOnNextLine: true +AllowBreakBeforeNoexceptSpecifier: Never +AllowShortBlocksOnASingleLine: Never +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: true +AllowShortEnumsOnASingleLine: true +AllowShortFunctionsOnASingleLine: All +AllowShortIfStatementsOnASingleLine: Never +AllowShortLambdasOnASingleLine: All +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterDefinitionReturnType: All +AlwaysBreakAfterReturnType: AllDefinitions +AlwaysBreakBeforeMultilineStrings: false +AlwaysBreakTemplateDeclarations: MultiLine +AttributeMacros: + - __capability +BinPackArguments: true +BinPackParameters: true +BitFieldColonSpacing: Both +BraceWrapping: + AfterCaseLabel: true + AfterClass: true + AfterControlStatement: Always + AfterEnum: true + AfterExternBlock: true + AfterFunction: true + AfterNamespace: true + AfterObjCDeclaration: true + AfterStruct: true + AfterUnion: true + BeforeCatch: true + BeforeElse: true + BeforeLambdaBody: false + BeforeWhile: true + IndentBraces: true + SplitEmptyFunction: true + SplitEmptyRecord: true + SplitEmptyNamespace: true +BreakAdjacentStringLiterals: true +BreakAfterAttributes: Leave +BreakAfterJavaFieldAnnotations: false +BreakArrays: true +BreakBeforeBinaryOperators: All +BreakBeforeConceptDeclarations: Always +BreakBeforeBraces: Linux +BreakBeforeInlineASMColon: OnlyMultiline +BreakBeforeTernaryOperators: true +BreakConstructorInitializers: BeforeColon +BreakInheritanceList: BeforeColon +BreakStringLiterals: true +ColumnLimit: 79 +CommentPragmas: "^ IWYU pragma:" +CompactNamespaces: false +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: false +DerivePointerAlignment: false +DisableFormat: false +EmptyLineAfterAccessModifier: Never +EmptyLineBeforeAccessModifier: LogicalBlock +ExperimentalAutoDetectBinPacking: false +FixNamespaceComments: false +ForEachMacros: + - foreach + - Q_FOREACH + - BOOST_FOREACH +IfMacros: + - KJ_IF_MAYBE +IncludeBlocks: Preserve +IncludeCategories: + - Regex: ^"(llvm|llvm-c|clang|clang-c)/ + Priority: 2 + SortPriority: 0 + CaseSensitive: false + - Regex: ^(<|"(gtest|gmock|isl|json)/) + Priority: 3 + SortPriority: 0 + CaseSensitive: false + - Regex: .* + Priority: 1 + SortPriority: 0 + CaseSensitive: false +IncludeIsMainRegex: (Test)?$ +IncludeIsMainSourceRegex: "" +IndentAccessModifiers: false +IndentCaseBlocks: false +IndentCaseLabels: false +IndentExternBlock: AfterExternBlock +IndentGotoLabels: true +IndentPPDirectives: None +IndentRequiresClause: true +IndentWidth: 8 +IndentWrappedFunctionNames: false +InsertBraces: false +InsertNewlineAtEOF: true +InsertTrailingCommas: None +IntegerLiteralSeparator: + Binary: 0 + BinaryMinDigits: 0 + Decimal: 0 + DecimalMinDigits: 0 + Hex: 0 + HexMinDigits: 0 +JavaScriptQuotes: Leave +JavaScriptWrapImports: true +KeepEmptyLinesAtTheStartOfBlocks: true +KeepEmptyLinesAtEOF: false +LambdaBodyIndentation: Signature +LineEnding: LF +MacroBlockBegin: "" +MacroBlockEnd: "" +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBinPackProtocolList: Auto +ObjCBlockIndentWidth: 2 +ObjCBreakBeforeNestedBlockParam: true +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: true +PackConstructorInitializers: BinPack +PenaltyBreakAssignment: 2 +PenaltyBreakBeforeFirstCallParameter: 19 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakOpenParenthesis: 0 +PenaltyBreakScopeResolution: 500 +PenaltyBreakString: 1000 +PenaltyBreakTemplateDeclaration: 10 +PenaltyExcessCharacter: 1000000 +PenaltyIndentedWhitespace: 0 +PenaltyReturnTypeOnItsOwnLine: 60 +PointerAlignment: Right +PPIndentWidth: -1 +QualifierAlignment: Leave +ReferenceAlignment: Pointer +ReflowComments: true +RemoveBracesLLVM: false +RemoveParentheses: Leave +RemoveSemicolon: false +RequiresClausePosition: OwnLine +RequiresExpressionIndentation: OuterScope +SeparateDefinitionBlocks: Leave +ShortNamespaceLines: 1 +SkipMacroDefinitionBody: false +SortIncludes: CaseSensitive +SortJavaStaticImport: Before +SortUsingDeclarations: LexicographicNumeric +SpaceAfterCStyleCast: false +SpaceAfterLogicalNot: false +SpaceAfterTemplateKeyword: true +SpaceAroundPointerQualifiers: Default +SpaceBeforeAssignmentOperators: true +SpaceBeforeCaseColon: false +SpaceBeforeCpp11BracedList: false +SpaceBeforeCtorInitializerColon: true +SpaceBeforeInheritanceColon: true +SpaceBeforeJsonColon: false +SpaceBeforeParens: Never +SpaceBeforeParensOptions: + AfterControlStatements: false + AfterForeachMacros: false + AfterFunctionDefinitionName: false + AfterFunctionDeclarationName: false + AfterIfMacros: false + AfterOverloadedOperator: false + AfterPlacementOperator: false + AfterRequiresInClause: false + AfterRequiresInExpression: false + BeforeNonEmptyParentheses: false +SpaceBeforeRangeBasedForLoopColon: true +SpaceBeforeSquareBrackets: false +SpaceInEmptyBlock: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: Never +SpacesInContainerLiterals: true +SpacesInLineCommentPrefix: + Minimum: 1 + Maximum: -1 +SpacesInParens: Never +SpacesInParensOptions: + InCStyleCasts: false + InConditionalStatements: false + InEmptyParentheses: false + Other: false +SpacesInSquareBrackets: false +Standard: c++03 +StatementAttributeLikeMacros: + - Q_EMIT +StatementMacros: + - Q_UNUSED + - QT_REQUIRE_VERSION +TabWidth: 8 +UseTab: AlignWithSpaces +VerilogBreakBetweenInstancePorts: true +WhitespaceSensitiveMacros: + - BOOST_PP_STRINGIZE + - CF_SWIFT_NAME + - NS_SWIFT_NAME + - PP_STRINGIZE + - STRINGIZE From 12397c327167a7ffe2ea996c7f8b1fcc66ce5e2c Mon Sep 17 00:00:00 2001 From: Konrad Dybcio Date: Mon, 11 Aug 2025 11:28:11 +0200 Subject: [PATCH 2/3] github: workflows: Add clang-format action Loosely based on #136 Signed-off-by: Konrad Dybcio --- .github/workflows/clang-format.yml | 38 ++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/clang-format.yml diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 00000000..b46869db --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,38 @@ +name: Check formatting + +on: + push: + branches: + - 'main' + - 'development' + pull_request: + branches: + - 'main' + - 'development' + +jobs: + clang-format: + # The exact version doesn't really matter, as we're getting a build from LLVM repos anyway + runs-on: [ ubuntu-latest ] + + env: + CLANG_MAJOR_VERSION: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Clang Format + run: | + wget https://apt.llvm.org/llvm.sh + sudo chmod +x llvm.sh + sudo ./llvm.sh $CLANG_MAJOR_VERSION + sudo apt-get install clang-format-$CLANG_MAJOR_VERSION + + - name: Print clang-format version + run: clang-format-$CLANG_MAJOR_VERSION --version + + - name: Run Clang Format + run: | + find . -name '*.cpp' -o -name '*.hpp' -o -name '*.c' -o -name '*.h' | xargs clang-format-$CLANG_MAJOR_VERSION -i + git diff --exit-code || (echo "The changes are not formatted properly" && exit 1) From 3144455bab51fc8470199739387ea0aad01e6e14 Mon Sep 17 00:00:00 2001 From: Konrad Dybcio Date: Thu, 11 Sep 2025 15:50:25 +0200 Subject: [PATCH 3/3] treewide: Run clang-format Signed-off-by: Konrad Dybcio --- inc/AEEBufBound.h | 29 +- inc/AEEQList.h | 285 +- inc/AEEStdDef.h | 58 +- inc/AEEStdErr.h | 565 +- inc/AEEstd.h | 92 +- inc/HAP_debug.h | 64 +- inc/HAP_farf.h | 184 +- inc/HAP_farf_internal.h | 3 - inc/HAP_pls.h | 47 +- inc/adsp_current_process.h | 35 +- inc/adsp_current_process1.h | 94 +- inc/adsp_default_listener.h | 3 +- inc/adsp_default_listener1.h | 196 +- inc/adsp_listener.h | 35 +- inc/adsp_listener1.h | 230 +- inc/adsp_perf.h | 17 +- inc/adsp_perf1.h | 215 +- inc/adsp_pls.h | 14 +- inc/adspmsgd_adsp.h | 11 +- inc/adspmsgd_adsp1.h | 67 +- inc/adspmsgd_apps.h | 23 +- inc/adspmsgd_internal.h | 48 +- inc/apps_mem.h | 31 +- inc/apps_mem_internal.h | 12 +- inc/apps_remotectl.h | 14 +- inc/apps_std.h | 303 +- inc/apps_std_internal.h | 19 +- inc/dspqueue.h | 279 +- inc/dspqueue_rpc.h | 76 +- inc/dspqueue_shared.h | 103 +- inc/dspsignal.h | 25 +- inc/fastrpc_apps_user.h | 36 +- inc/fastrpc_async.h | 39 +- inc/fastrpc_cap.h | 36 +- inc/fastrpc_common.h | 215 +- inc/fastrpc_config.h | 322 +- inc/fastrpc_context.h | 12 +- inc/fastrpc_hash_table.h | 83 +- inc/fastrpc_internal.h | 504 +- inc/fastrpc_ioctl.h | 210 +- inc/fastrpc_latency.h | 24 +- inc/fastrpc_mem.h | 51 +- inc/fastrpc_notif.h | 8 +- inc/fastrpc_perf.h | 6 +- inc/fastrpc_pm.h | 34 +- inc/fastrpc_process_attributes.h | 7 +- inc/fastrpc_trace.h | 62 +- inc/listener_android.h | 24 +- inc/listener_buf.h | 163 +- inc/log_config.h | 16 +- inc/mod_table.h | 101 +- inc/mutex.h | 111 +- inc/platform_libs.h | 56 +- inc/pls.h | 313 +- inc/pthread_rw_mutex.h | 38 +- inc/remote.h | 1388 ++--- inc/remote64.h | 3 +- inc/remotectl.h | 21 +- inc/remotectl1.h | 219 +- inc/rpcmem.h | 91 +- inc/rpcmem_internal.h | 4 +- inc/sbuf.h | 145 +- inc/sbuf_parser.h | 227 +- inc/shared.h | 55 +- inc/std_dtoa.h | 119 +- inc/uthash.h | 1700 +++--- inc/verify.h | 159 +- inc/version.h | 40 +- src/BufBound.c | 176 +- src/adsp_current_process1_stub.c | 1239 +++-- src/adsp_current_process_stub.c | 1406 ++--- src/adsp_default_listener.c | 551 +- src/adsp_default_listener1_stub.c | 463 +- src/adsp_default_listener_stub.c | 678 +-- src/adsp_listener1_stub.c | 1420 +++-- src/adsp_listener_stub.c | 1687 +++--- src/adsp_perf1_stub.c | 635 ++- src/adsp_perf_stub.c | 853 +-- src/adspmsgd.c | 293 +- src/adspmsgd_adsp1_stub.c | 681 +-- src/adspmsgd_adsp_stub.c | 782 +-- src/adspmsgd_apps_skel.c | 573 +- src/adspmsgd_printf.c | 45 +- src/apps_mem_imp.c | 648 +-- src/apps_mem_skel.c | 1027 ++-- src/apps_remotectl_skel.c | 701 +-- src/apps_std_imp.c | 3142 +++++------ src/apps_std_skel.c | 2849 +++++----- src/dspqueue/dspqueue_cpu.c | 4896 +++++++++-------- src/dspqueue/dspqueue_rpc_stub.c | 801 +-- src/dsprpcd.c | 105 +- src/dspsignal.c | 443 +- src/fastrpc_apps_user.c | 8168 ++++++++++++++++------------- src/fastrpc_async.c | 870 +-- src/fastrpc_cap.c | 246 +- src/fastrpc_config.c | 794 +-- src/fastrpc_context.c | 207 +- src/fastrpc_ioctl.c | 442 +- src/fastrpc_latency.c | 335 +- src/fastrpc_log.c | 569 +- src/fastrpc_mem.c | 1763 ++++--- src/fastrpc_notif.c | 379 +- src/fastrpc_perf.c | 556 +- src/fastrpc_pm.c | 360 +- src/fastrpc_procbuf.c | 278 +- src/gpls.c | 68 +- src/listener_android.c | 879 ++-- src/log_config.c | 1434 ++--- src/mod_table.c | 1845 ++++--- src/pl_list.c | 4 +- src/platform_libs.c | 116 +- src/remotectl1_stub.c | 724 +-- src/remotectl_stub.c | 951 ++-- src/rpcmem_linux.c | 360 +- src/std_dtoa.c | 833 ++- src/std_path.c | 197 +- test/fastrpc_test.c | 297 +- 117 files changed, 32394 insertions(+), 26194 deletions(-) diff --git a/inc/AEEBufBound.h b/inc/AEEBufBound.h index 30713698..1288d913 100644 --- a/inc/AEEBufBound.h +++ b/inc/AEEBufBound.h @@ -21,11 +21,10 @@ REVISION HISTORY: ==============================================================================*/ -typedef struct BufBound -{ - char* pcBuf; /* original buffer */ - char* pcWrite; /* write pointer */ - char* pcEnd; /* first illegal write pointer */ +typedef struct BufBound { + char *pcBuf; /* original buffer */ + char *pcWrite; /* write pointer */ + char *pcEnd; /* first illegal write pointer */ } BufBound; #ifdef __cplusplus @@ -37,29 +36,30 @@ extern void BufBound_Write(BufBound *me, const char *pc, int nLen); extern void BufBound_Putc(BufBound *me, char c); extern void BufBound_Putnc(BufBound *me, char c, int nCount); extern void BufBound_ForceNullTerm(BufBound *me); -extern void BufBound_Puts(BufBound *me, const char* cpsz); +extern void BufBound_Puts(BufBound *me, const char *cpsz); extern void BufBound_Advance(BufBound *me, int nLen); extern int BufBound_BufSize(BufBound *me); -extern int BufBound_Left(BufBound* me); -extern int BufBound_ReallyWrote(BufBound* me); -extern int BufBound_Wrote(BufBound* me); +extern int BufBound_Left(BufBound *me); +extern int BufBound_ReallyWrote(BufBound *me); +extern int BufBound_Wrote(BufBound *me); -static __inline int BufBound_IsFull(BufBound* me) +static __inline int +BufBound_IsFull(BufBound *me) { - return (BufBound_Left(me) <= 0); + return (BufBound_Left(me) <= 0); } // Deprecated: -static __inline int BufBound_IsCounter(BufBound* me) +static __inline int +BufBound_IsCounter(BufBound *me) { - return BufBound_BufSize(me) == 0; + return BufBound_BufSize(me) == 0; } #ifdef __cplusplus } #endif /* #ifdef __cplusplus */ - /*===================================================================== ======================================================================= DATA STRUCTURE DOCUMENTATION @@ -467,4 +467,3 @@ See Also: ======================================================================= */ #endif /* #ifndef AEEBUFBOUND_H */ - diff --git a/inc/AEEQList.h b/inc/AEEQList.h index b85f013a..4fd469a5 100644 --- a/inc/AEEQList.h +++ b/inc/AEEQList.h @@ -11,222 +11,221 @@ GENERAL DESCRIPTION: Doubly-linked circular list implementation #ifndef _AEEQLIST_H_ #define _AEEQLIST_H_ - typedef struct QNode QNode; struct QNode { - QNode *pNext; - QNode *pPrev; + QNode *pNext; + QNode *pPrev; }; #define QLIST_DEFINE_INIT(f) QList f = { { &f.n, &f.n } } typedef struct QList QList; struct QList { - QNode n; + QNode n; }; - - -static __inline void QNode_InsPrev(QNode *me, QNode *pn) +static __inline void +QNode_InsPrev(QNode *me, QNode *pn) { - QNode *pPrev = me->pPrev; + QNode *pPrev = me->pPrev; - pn->pNext = me; - pn->pPrev = pPrev; - pPrev->pNext = pn; - me->pPrev = pn; + pn->pNext = me; + pn->pPrev = pPrev; + pPrev->pNext = pn; + me->pPrev = pn; } - -static __inline void QNode_InsNext(QNode *me, QNode *pn) +static __inline void +QNode_InsNext(QNode *me, QNode *pn) { - QNode *pNext = me->pNext; + QNode *pNext = me->pNext; - pn->pPrev = me; - pn->pNext = pNext; - pNext->pPrev = pn; - me->pNext = pn; + pn->pPrev = me; + pn->pNext = pNext; + pNext->pPrev = pn; + me->pNext = pn; } - - -static __inline void QNode_Dequeue(QNode *me) +static __inline void +QNode_Dequeue(QNode *me) { - QNode *pNext = me->pNext; - QNode *pPrev = me->pPrev; + QNode *pNext = me->pNext; + QNode *pPrev = me->pPrev; - pPrev->pNext = pNext; - pNext->pPrev = pPrev; + pPrev->pNext = pNext; + pNext->pPrev = pPrev; } -static __inline void QNode_CtorZ(QNode *me) +static __inline void +QNode_CtorZ(QNode *me) { - me->pNext = me->pPrev = 0; + me->pNext = me->pPrev = 0; } -static __inline int QNode_IsQueuedZ(QNode *me) +static __inline int +QNode_IsQueuedZ(QNode *me) { - return (0 != me->pNext); + return (0 != me->pNext); } -static __inline void QNode_DequeueZ(QNode *me) +static __inline void +QNode_DequeueZ(QNode *me) { - if (QNode_IsQueuedZ(me)) { - QNode_Dequeue(me); - me->pNext = me->pPrev = 0; - } + if(QNode_IsQueuedZ(me)) { + QNode_Dequeue(me); + me->pNext = me->pPrev = 0; + } } //-------------------------------------------------------------------- //-- QList functions ---------------------------------------------- //-------------------------------------------------------------------- - -static __inline void QList_Zero(QList *me) +static __inline void +QList_Zero(QList *me) { - me->n.pNext = me->n.pPrev = &me->n; + me->n.pNext = me->n.pPrev = &me->n; } - -static __inline void QList_Ctor(QList *me) +static __inline void +QList_Ctor(QList *me) { - QList_Zero(me); + QList_Zero(me); } - -static __inline int QList_IsEmpty(QList *me) +static __inline int +QList_IsEmpty(QList *me) { - return me->n.pNext == &me->n; + return me->n.pNext == &me->n; } -static __inline int QList_IsNull(QList *me) +static __inline int +QList_IsNull(QList *me) { - return ((0 == me->n.pNext) && (0 == me->n.pPrev)); + return ((0 == me->n.pNext) && (0 == me->n.pPrev)); } - -static __inline void QList_AppendNode(QList *me, QNode *pn) +static __inline void +QList_AppendNode(QList *me, QNode *pn) { - QNode_InsPrev(&me->n, pn); + QNode_InsPrev(&me->n, pn); } - -static __inline void QList_PrependNode(QList *me, QNode *pn) +static __inline void +QList_PrependNode(QList *me, QNode *pn) { - QNode_InsNext(&me->n, pn); + QNode_InsNext(&me->n, pn); } - -static __inline void QList_CtorFrom(QList *me, QList *psrc) +static __inline void +QList_CtorFrom(QList *me, QList *psrc) { - QNode *s = &psrc->n; - QNode *d = &me->n; + QNode *s = &psrc->n; + QNode *d = &me->n; - s->pNext->pPrev = d; - d->pPrev = s->pPrev; - d->pNext = s->pNext; - s->pPrev->pNext = d; + s->pNext->pPrev = d; + d->pPrev = s->pPrev; + d->pNext = s->pNext; + s->pPrev->pNext = d; - QList_Zero(psrc); + QList_Zero(psrc); } - - -static __inline void QList_AppendList(QList *me, QList *psrc) +static __inline void +QList_AppendList(QList *me, QList *psrc) { - QNode *s = &psrc->n; - QNode *d = &me->n; - QNode *dp = d->pPrev; - QNode *sn = s->pNext; - QNode *sp; - - sn->pPrev = dp; - dp->pNext = sn; - d->pPrev = (sp = s->pPrev); - sp->pNext = d; - - QList_Zero(psrc); + QNode *s = &psrc->n; + QNode *d = &me->n; + QNode *dp = d->pPrev; + QNode *sn = s->pNext; + QNode *sp; + + sn->pPrev = dp; + dp->pNext = sn; + d->pPrev = (sp = s->pPrev); + sp->pNext = d; + + QList_Zero(psrc); } +#define QLIST_FOR_ALL(pList, pNode) \ + for((pNode) = (pList)->n.pNext; (pNode) != &(pList)->n; \ + (pNode) = (pNode)->pNext) -#define QLIST_FOR_ALL(pList, pNode) \ - for ((pNode) = (pList)->n.pNext; \ - (pNode) != &(pList)->n; \ - (pNode) = (pNode)->pNext) +#define QLIST_FOR_REST(pList, pNode) \ + for(; (pNode) != &(pList)->n; (pNode) = (pNode)->pNext) -#define QLIST_FOR_REST(pList, pNode) \ - for (; \ - (pNode) != &(pList)->n; \ - (pNode) = (pNode)->pNext) +#define QLIST_REV_FOR_ALL(pList, pNode) \ + for((pNode) = (pList)->n.pPrev; (pNode) != &(pList)->n; \ + (pNode) = (pNode)->pPrev) -#define QLIST_REV_FOR_ALL(pList, pNode) \ - for ((pNode) = (pList)->n.pPrev; \ - (pNode) != &(pList)->n; \ - (pNode) = (pNode)->pPrev) - -#define QLIST_REV_FOR_REST(pList, pNode) \ - for (; \ - (pNode) != &(pList)->n; \ - (pNode) = (pNode)->pPrev) +#define QLIST_REV_FOR_REST(pList, pNode) \ + for(; (pNode) != &(pList)->n; (pNode) = (pNode)->pPrev) /* Allows dequeing QNodes during iteration */ -#define QLIST_NEXTSAFE_FOR_ALL(pList, pNode, pNodeNext) \ - for ((pNode) = (pList)->n.pNext, (pNodeNext) = (pNode)->pNext; \ - (pNode) != &(pList)->n; \ - (pNode) = (pNodeNext), (pNodeNext) = (pNode)->pNext) +#define QLIST_NEXTSAFE_FOR_ALL(pList, pNode, pNodeNext) \ + for((pNode) = (pList)->n.pNext, (pNodeNext) = (pNode)->pNext; \ + (pNode) != &(pList)->n; \ + (pNode) = (pNodeNext), (pNodeNext) = (pNode)->pNext) -static __inline QNode *QList_GetFirst(QList *me) +static __inline QNode * +QList_GetFirst(QList *me) { - QNode *pn = me->n.pNext; + QNode *pn = me->n.pNext; - return (pn == &me->n ? 0 : pn); + return (pn == &me->n ? 0 : pn); } -static __inline QNode *QList_GetLast(QList *me) +static __inline QNode * +QList_GetLast(QList *me) { - QNode *pn = me->n.pPrev; + QNode *pn = me->n.pPrev; - return (pn == &me->n ? 0 : pn); + return (pn == &me->n ? 0 : pn); } -static __inline QNode *QList_Pop(QList *me) +static __inline QNode * +QList_Pop(QList *me) { - QNode *pn = me->n.pNext; - QNode *pnn = pn->pNext; + QNode *pn = me->n.pNext; + QNode *pnn = pn->pNext; - me->n.pNext = pnn; - pnn->pPrev = &me->n; + me->n.pNext = pnn; + pnn->pPrev = &me->n; - return (pn == &me->n ? 0 : pn); + return (pn == &me->n ? 0 : pn); } -static __inline QNode *QList_PopZ(QList *me) +static __inline QNode * +QList_PopZ(QList *me) { - QNode *pn = QList_Pop(me); - if (0 != pn) { - QNode_CtorZ(pn); - } - return pn; + QNode *pn = QList_Pop(me); + if(0 != pn) { + QNode_CtorZ(pn); + } + return pn; } -static __inline QNode *QList_PopLast(QList *me) +static __inline QNode * +QList_PopLast(QList *me) { - QNode *pp = me->n.pPrev; - QNode *ppp = pp->pPrev; + QNode *pp = me->n.pPrev; + QNode *ppp = pp->pPrev; - me->n.pPrev = ppp; - ppp->pNext = &me->n; + me->n.pPrev = ppp; + ppp->pNext = &me->n; - return (pp == &me->n ? 0 : pp); + return (pp == &me->n ? 0 : pp); } -static __inline QNode *QList_PopLastZ(QList *me) +static __inline QNode * +QList_PopLastZ(QList *me) { - QNode *pn = QList_PopLast(me); - if (0 != pn) { - QNode_CtorZ(pn); - } - return pn; + QNode *pn = QList_PopLast(me); + if(0 != pn) { + QNode_CtorZ(pn); + } + return pn; } /*===================================================================== @@ -373,14 +372,14 @@ See Also: QNode_InsPrev() Description: - insert a node before this one. + insert a node before this one. Prototype: - static __inline void QNode_InsPrev(QNode *me, QNode *pn) + static __inline void QNode_InsPrev(QNode *me, QNode *pn) Parameters: - me: the QNode - pn: the node to be inserted. + me: the QNode + pn: the node to be inserted. Return Value: None @@ -398,14 +397,14 @@ See Also: QNode_InsNext() Description: - insert a node after this one. + insert a node after this one. Prototype: - static __inline void QNode_InsNext(QNode *me, QNode *pn) + static __inline void QNode_InsNext(QNode *me, QNode *pn) Parameters: - me: the QNode - pn: the node to be inserted. + me: the QNode + pn: the node to be inserted. Return Value: None @@ -423,13 +422,13 @@ See Also: QNode_Dequeue() Description: - dequeue this node. + dequeue this node. Prototype: - static __inline void QNode_Dequeue(QNode *me) + static __inline void QNode_Dequeue(QNode *me) Parameters: - me: the QNode to be dequeued + me: the QNode to be dequeued Return Value: None @@ -584,8 +583,8 @@ QList_CtorFrom() Description: Move nodes from one queue to a newly constructed queue. Weird aliasing voodoo allows this to work without conditional branches, even - when psrc is empty. In that case, "s->pNext->pPrev = d" overwrites s->pPrev with d, - so that "s->pPrev->pNext = d" will later overwrite d->pNext with d. + when psrc is empty. In that case, "s->pNext->pPrev = d" overwrites s->pPrev +with d, so that "s->pPrev->pNext = d" will later overwrite d->pNext with d. Prototype: @@ -713,8 +712,8 @@ Side Effects: None See Also: - QNode_PopZ, QNode_PopLast(), QNode_PopLastZ, QNode_CtorZ(), QNode_IsQueued(), - QNode_DequeueZ() + QNode_PopZ, QNode_PopLast(), QNode_PopLastZ, QNode_CtorZ(), +QNode_IsQueued(), QNode_DequeueZ() ======================================================================= QList_PopZ() @@ -792,7 +791,7 @@ Side Effects: None See Also: - None + None ======================================================================= diff --git a/inc/AEEStdDef.h b/inc/AEEStdDef.h index 6574b411..b2145742 100644 --- a/inc/AEEStdDef.h +++ b/inc/AEEStdDef.h @@ -21,42 +21,44 @@ DESCRIPTION: definition of basic types, constants, ** Standard Types ** ----------------------------------------------------------------------- */ - /** @defgroup stdret standard return values -* @{ -*/ +/** @defgroup stdret standard return values + * @{ + */ //! @cond Doxygen_Suppress #ifndef _AEEUID_DEFINED -typedef uint32_t AEEUID; +typedef uint32_t AEEUID; #define _AEEUID_DEFINED #endif #ifndef _AEEIID_DEFINED -typedef uint32_t AEEIID; +typedef uint32_t AEEIID; #define _AEEIID_DEFINED #endif #ifndef _AEECLSID_DEFINED -typedef uint32_t AEECLSID; +typedef uint32_t AEECLSID; #define _AEECLSID_DEFINED #endif #ifndef _AEEPRIVID_DEFINED -typedef uint32_t AEEPRIVID; +typedef uint32_t AEEPRIVID; #define _AEEPRIVID_DEFINED #endif #ifndef _AECHAR_DEFINED -typedef uint16_t AECHAR; +typedef uint16_t AECHAR; #define _AECHAR_DEFINED #endif //! @endcond /** - * @brief Return value of functions indicating success or failure. return value 0 indicates success. A non zero value indicates a failure. Any data in rout parameters is not propagated back. + * @brief Return value of functions indicating success or failure. return value + * 0 indicates success. A non zero value indicates a failure. Any data in rout + * parameters is not propagated back. */ #ifndef _AEERESULT_DEFINED -typedef int AEEResult; +typedef int AEEResult; #define _AEERESULT_DEFINED #endif @@ -64,7 +66,6 @@ typedef int AEEResult; * @} */ - /* ----------------------------------------------------------------------- ** Function Calling Conventions ** ----------------------------------------------------------------------- */ @@ -80,9 +81,9 @@ typedef int AEEResult; /* ----------------------------------------------------------------------- ** Constants ** ----------------------------------------------------------------------- */ - /** @defgroup stdminmax Standard Min and Max for all data types -* @{ -*/ +/** @defgroup stdminmax Standard Min and Max for all data types + * @{ + */ //! @cond Doxygen_Suppress #ifndef MIN_AECHAR @@ -110,19 +111,17 @@ typedef int AEEResult; ** Types for code generated from IDL ** ----------------------------------------------------------------------- */ - /** @defgroup QIDL data types -* @{ -*/ +/** @defgroup QIDL data types + * @{ + */ //! @cond Doxygen_Suppress #ifndef __QIDL_WCHAR_T_DEFINED__ #define __QIDL_WCHAR_T_DEFINED__ typedef uint16_t _wchar_t; #endif - /* __STRING_OBJECT__ will be deprecated in the future */ - #if !defined(__QIDL_STRING_OBJECT_DEFINED__) && !defined(__STRING_OBJECT__) #define __QIDL_STRING_OBJECT_DEFINED__ #define __STRING_OBJECT__ @@ -132,9 +131,9 @@ typedef uint16_t _wchar_t; sequence or union. */ typedef struct _cstring_s { - char* data; - int dataLen; - int dataLenReq; + char *data; + int dataLen; + int dataLenReq; } _cstring_t; /** @@ -143,9 +142,9 @@ typedef struct _cstring_s { */ typedef struct _wstring_s { - _wchar_t* data; - int dataLen; - int dataLenReq; + _wchar_t *data; + int dataLen; + int dataLenReq; } _wstring_t; #endif /* __QIDL_STRING_OBJECT_DEFINED__ */ //! @endcond @@ -175,8 +174,8 @@ AEEUID AEEIID Description: - This is an interface ID type, used to denote a BREW interface. It is a special case - of AEEUID. + This is an interface ID type, used to denote a BREW interface. It is a +special case of AEEUID. Definition: typedef uint32_t AEEIID @@ -197,8 +196,8 @@ AEECLSID AEEPRIVID Description: - This is a privilege ID type, used to express a privilege. It is a special case - of AEEUID. + This is a privilege ID type, used to express a privilege. It is a special +case of AEEUID. Definition: typedef uint32_t AEEPRIVID @@ -309,4 +308,3 @@ See Also: */ #endif /* #ifndef AEESTDDEF_H */ - diff --git a/inc/AEEStdErr.h b/inc/AEEStdErr.h index 8b7d5ff0..31d1f99a 100644 --- a/inc/AEEStdErr.h +++ b/inc/AEEStdErr.h @@ -7,101 +7,137 @@ // Basic Error Codes // // -#define DSP_AEE_EOFFSET 0x80000400 +#define DSP_AEE_EOFFSET 0x80000400 #if defined(__hexagon__) - #define AEE_EOFFSET DSP_AEE_EOFFSET +#define AEE_EOFFSET DSP_AEE_EOFFSET #else - #define AEE_EOFFSET 0x00000000 +#define AEE_EOFFSET 0x00000000 #endif // Kernel error code start -#define KERNEL_ERRNO_START -1024 +#define KERNEL_ERRNO_START -1024 // Userspace error code end -#define HLOS_ERR_END 1024 +#define HLOS_ERR_END 1024 /** @defgroup stdbasicerror Basic error codes * @{ */ -#define AEE_SUCCESS 0 ///< No error -#define AEE_EUNKNOWN -1 ///< Unknown error (should not use this) +#define AEE_SUCCESS 0 ///< No error +#define AEE_EUNKNOWN -1 ///< Unknown error (should not use this) -#define AEE_EFAILED (AEE_EOFFSET + 0x001) ///< General failure -#define AEE_ENOMEMORY (AEE_EOFFSET + 0x002) ///< Memory allocation failed because of insufficient RAM -#define AEE_ECLASSNOTSUPPORT (AEE_EOFFSET + 0x003) ///< Specified class unsupported -#define AEE_EVERSIONNOTSUPPORT (AEE_EOFFSET + 0x004) ///< Version not supported -#define AEE_EALREADYLOADED (AEE_EOFFSET + 0x005) ///< Object already loaded -#define AEE_EUNABLETOLOAD (AEE_EOFFSET + 0x006) ///< Unable to load object/applet -#define AEE_EUNABLETOUNLOAD (AEE_EOFFSET + 0x007) ///< Unable to unload - ///< object/applet -#define AEE_EALARMPENDING (AEE_EOFFSET + 0x008) ///< Alarm is pending -#define AEE_EINVALIDTIME (AEE_EOFFSET + 0x009) ///< Invalid time -#define AEE_EBADCLASS (AEE_EOFFSET + 0x00A) ///< NULL class object -#define AEE_EBADMETRIC (AEE_EOFFSET + 0x00B) ///< Invalid metric specified -#define AEE_EEXPIRED (AEE_EOFFSET + 0x00C) ///< App/Component Expired -#define AEE_EBADSTATE (AEE_EOFFSET + 0x00D) ///< Process or thread is not in expected state -#define AEE_EBADPARM (AEE_EOFFSET + 0x00E) ///< Invalid parameter -#define AEE_ESCHEMENOTSUPPORTED (AEE_EOFFSET + 0x00F) ///< Invalid URL scheme -#define AEE_EBADITEM (AEE_EOFFSET + 0x010) ///< Value out of range -#define AEE_EINVALIDFORMAT (AEE_EOFFSET + 0x011) ///< Invalid format -#define AEE_EINCOMPLETEITEM (AEE_EOFFSET + 0x012) ///< Incomplete item, like length of a string is less that expected -#define AEE_ENOPERSISTMEMORY (AEE_EOFFSET + 0x013) ///< Insufficient flash -#define AEE_EUNSUPPORTED (AEE_EOFFSET + 0x014) ///< API not implemented -#define AEE_EPRIVLEVEL (AEE_EOFFSET + 0x015) ///< Privileges are insufficient - ///< for this operation -#define AEE_ERESOURCENOTFOUND (AEE_EOFFSET + 0x016) ///< Unable to find specified - ///< resource -#define AEE_EREENTERED (AEE_EOFFSET + 0x017) ///< Non re-entrant API - ///< re-entered -#define AEE_EBADTASK (AEE_EOFFSET + 0x018) ///< API called in wrong task - ///< context -#define AEE_EALLOCATED (AEE_EOFFSET + 0x019) ///< App/Module left memory - ///< allocated when released. -#define AEE_EALREADY (AEE_EOFFSET + 0x01A) ///< Operation is already in - ///< progress -#define AEE_EADSAUTHBAD (AEE_EOFFSET + 0x01B) ///< ADS mutual authorization - ///< failed -#define AEE_ENEEDSERVICEPROG (AEE_EOFFSET + 0x01C) ///< Need service programming -#define AEE_EMEMPTR (AEE_EOFFSET + 0x01D) ///< bad memory pointer, expected to be NULL -#define AEE_EHEAP (AEE_EOFFSET + 0x01E) ///< An internal heap error was detected -#define AEE_EIDLE (AEE_EOFFSET + 0x01F) ///< Context (system, interface, - ///< etc.) is idle -#define AEE_EITEMBUSY (AEE_EOFFSET + 0x020) ///< Context (system, interface, - ///< etc.) is busy -#define AEE_EBADSID (AEE_EOFFSET + 0x021) ///< Invalid subscriber ID -#define AEE_ENOTYPE (AEE_EOFFSET + 0x022) ///< No type detected/found -#define AEE_ENEEDMORE (AEE_EOFFSET + 0x023) ///< Need more data/info -#define AEE_EADSCAPS (AEE_EOFFSET + 0x024) ///< ADS Capabilities do not - ///< match those required for phone -#define AEE_EBADSHUTDOWN (AEE_EOFFSET + 0x025) ///< App failed to close properly -#define AEE_EBUFFERTOOSMALL (AEE_EOFFSET + 0x026) ///< Destination buffer given is - ///< too small - ///< or service exists or is - ///< valid -#define AEE_EACKPENDING (AEE_EOFFSET + 0x028) ///< ACK pending on application -#define AEE_ENOTOWNER (AEE_EOFFSET + 0x029) ///< Not an owner authorized to - ///< perform the operation -#define AEE_EINVALIDITEM (AEE_EOFFSET + 0x02A) ///< Current item is invalid, it can be a switch case or a pointer to memory -#define AEE_ENOTALLOWED (AEE_EOFFSET + 0x02B) ///< Not allowed to perform the - ///< operation -#define AEE_EINVHANDLE (AEE_EOFFSET + 0x02C) ///< Invalid handle - adding here as its defined in vendor AEEStdErr.h - needed to check valid handle in stub.c -#define AEE_EOUTOFHANDLES (AEE_EOFFSET + 0x02D) ///< Out of handles (Handle list is already full) -//Hole here -#define AEE_ENOMORE (AEE_EOFFSET + 0x02F) ///< No more items available -- - ///< reached end -#define AEE_ECPUEXCEPTION (AEE_EOFFSET + 0x030) ///< A CPU exception occurred -#define AEE_EREADONLY (AEE_EOFFSET + 0x031) ///< Cannot change read-only - ///< object or parameter ( Parameter is in protected mode) -#define AEE_ERPC (AEE_EOFFSET + 0x200) ///< Error due to fastrpc implementation -#define AEE_EFILE (AEE_EOFFSET + 0x201) /// (max)) ? (max) : (val)) -#define STD_BETWEEN( val, minGE, maxLT ) \ - ( ((unsigned long)(minGE) <= (unsigned long)(val)) && \ - ( (unsigned long)((unsigned long)(val) - (unsigned long)(minGE)) < \ - (unsigned long)((unsigned long)(maxLT) - (unsigned long)(minGE))) ) -#define STD_ARRAY_SIZE(a) ((int)((sizeof((a))/sizeof((a)[0])))) -#define STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a)))) - -#define STD_SIZEOF(x) ((int)sizeof(x)) -#define STD_OFFSETOF(type,member) (((char*)(&((type*)1)->member))-((char*)1)) - -#define STD_RECOVER_REC(type,member,p) ((void)((p)-&(((type*)1)->member)),\ - (type*)(void*)(((char*)(void*)(p))-STD_OFFSETOF(type,member))) -#define STD_MIN(a,b) ((a)<(b)?(a):(b)) -#define STD_MAX(a,b) ((a)>(b)?(a):(b)) -//lint -emacro(545,STD_ZEROAT) -#define STD_ZEROAT(p) memset((p), 0, sizeof(*p)) - -#define _STD_BITS_PER(bits) (8*sizeof((bits)[0])) - -#define STD_BIT_SET(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] |= 0x1<<((ix) & (_STD_BITS_PER((bits))-1))) -#define STD_BIT_CLEAR(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] &= ~(0x1<<((ix) & (_STD_BITS_PER((bits))-1)))) -#define STD_BIT_TEST(bits, ix) ((bits)[(ix)/_STD_BITS_PER((bits))] & (0x1<<((ix) & (_STD_BITS_PER((bits))-1)))) +#define STD_CONSTRAIN(val, min, max) \ + (((val) < (min)) ? (min) : ((val) > (max)) ? (max) : (val)) +#define STD_BETWEEN(val, minGE, maxLT) \ + (((unsigned long)(minGE) <= (unsigned long)(val)) \ + && ((unsigned long)((unsigned long)(val) - (unsigned long)(minGE)) \ + < (unsigned long)((unsigned long)(maxLT) \ + - (unsigned long)(minGE)))) +#define STD_ARRAY_SIZE(a) ((int)((sizeof((a)) / sizeof((a)[0])))) +#define STD_ARRAY_MEMBER(p, a) \ + (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a)))) + +#define STD_SIZEOF(x) ((int)sizeof(x)) +#define STD_OFFSETOF(type, member) \ + (((char *)(&((type *)1)->member)) - ((char *)1)) + +#define STD_RECOVER_REC(type, member, p) \ + ((void)((p) - &(((type *)1)->member)), \ + (type *)(void *)(((char *)(void *)(p)) \ + - STD_OFFSETOF(type, member))) +#define STD_MIN(a, b) ((a) < (b) ? (a) : (b)) +#define STD_MAX(a, b) ((a) > (b) ? (a) : (b)) +// lint -emacro(545,STD_ZEROAT) +#define STD_ZEROAT(p) memset((p), 0, sizeof(*p)) + +#define _STD_BITS_PER(bits) (8 * sizeof((bits)[0])) + +#define STD_BIT_SET(bits, ix) \ + ((bits)[(ix) / _STD_BITS_PER((bits))] \ + |= 0x1 << ((ix) & (_STD_BITS_PER((bits)) - 1))) +#define STD_BIT_CLEAR(bits, ix) \ + ((bits)[(ix) / _STD_BITS_PER((bits))] \ + &= ~(0x1 << ((ix) & (_STD_BITS_PER((bits)) - 1)))) +#define STD_BIT_TEST(bits, ix) \ + ((bits)[(ix) / _STD_BITS_PER((bits))] \ + & (0x1 << ((ix) & (_STD_BITS_PER((bits)) - 1)))) // // Error codes // -#define STD_NODIGITS 1 -#define STD_NEGATIVE 2 -#define STD_OVERFLOW 3 -#define STD_BADPARAM 4 -#define STD_UNDERFLOW 5 +#define STD_NODIGITS 1 +#define STD_NEGATIVE 2 +#define STD_OVERFLOW 3 +#define STD_BADPARAM 4 +#define STD_UNDERFLOW 5 #ifdef __cplusplus extern "C" { #endif /* #ifdef __cplusplus */ -//Path functions -extern int std_makepath(const char *cpszDir, - const char *cpszFile, - char *pszDest, int nDestSize); -extern char * std_splitpath(const char *cpszPath, const char *cpszDir); -extern char * std_cleanpath(char *pszPath); -extern char * std_basename(const char *pszPath); +// Path functions +extern int std_makepath(const char *cpszDir, const char *cpszFile, + char *pszDest, int nDestSize); +extern char *std_splitpath(const char *cpszPath, const char *cpszDir); +extern char *std_cleanpath(char *pszPath); +extern char *std_basename(const char *pszPath); #ifdef __cplusplus } #endif /* #ifdef __cplusplus */ - /* ======================================================================= MACROS DOCUMENTATION @@ -108,7 +118,8 @@ Evaluation Value: STD_ARRAY_SIZE() Description: - STD_ARRAY_SIZE() gives the number of elements in a statically allocated array. + STD_ARRAY_SIZE() gives the number of elements in a statically allocated +array. Definition: STD_ARRAY_SIZE(a) (sizeof((a))/sizeof((a)[0])) @@ -124,7 +135,8 @@ Evaluation Value: STD_ARRAY_MEMBER() Description: - STD_ARRAY_MEMBER() tests whether an item is a member of a statically allocated array. + STD_ARRAY_MEMBER() tests whether an item is a member of a statically +allocated array. Definition: STD_ARRAY_MEMBER(p,a) (((p) >= (a)) && ((p) < ((a) + STD_ARRAY_SIZE(a)))) @@ -162,7 +174,8 @@ STD_RECOVER_REC() of a struct to a pointer to the containing struct Definition: - STD_RECOVER_REC(type,member,p) ((type*)(((char*)(p))-STD_OFFSETOF(type,member))) + STD_RECOVER_REC(type,member,p) +((type*)(((char*)(p))-STD_OFFSETOF(type,member))) Parameters: type: structured type @@ -586,4 +599,3 @@ Return Value: =======================================================================*/ #endif // AEESTD_H - diff --git a/inc/HAP_debug.h b/inc/HAP_debug.h index 5863bd5e..59242aef 100644 --- a/inc/HAP_debug.h +++ b/inc/HAP_debug.h @@ -12,55 +12,58 @@ extern "C" { #endif -#define MAX_FARF_LEN 256 +#define MAX_FARF_LEN 256 -#define HAP_LEVEL_LOW 0 -#define HAP_LEVEL_MEDIUM 1 -#define HAP_LEVEL_HIGH 2 -#define HAP_LEVEL_ERROR 3 -#define HAP_LEVEL_FATAL 4 +#define HAP_LEVEL_LOW 0 +#define HAP_LEVEL_MEDIUM 1 +#define HAP_LEVEL_HIGH 2 +#define HAP_LEVEL_ERROR 3 +#define HAP_LEVEL_FATAL 4 -#define HAP_LEVEL_CRITICAL 5 +#define HAP_LEVEL_CRITICAL 5 -#define HAP_LEVEL_RPC_LOW 16 -#define HAP_LEVEL_RPC_MEDIUM 17 -#define HAP_LEVEL_RPC_HIGH 18 -#define HAP_LEVEL_RPC_ERROR 19 -#define HAP_LEVEL_RPC_FATAL 20 +#define HAP_LEVEL_RPC_LOW 16 +#define HAP_LEVEL_RPC_MEDIUM 17 +#define HAP_LEVEL_RPC_HIGH 18 +#define HAP_LEVEL_RPC_ERROR 19 +#define HAP_LEVEL_RPC_FATAL 20 -#define HAP_LEVEL_RPC_CRITICAL 21 +#define HAP_LEVEL_RPC_CRITICAL 21 -#define HAP_LEVEL_RUNTIME (1 << 5) +#define HAP_LEVEL_RUNTIME (1 << 5) -//Add a weak reference so shared objects work with older images +// Add a weak reference so shared objects work with older images #pragma weak HAP_debug_v2 -//Add a weak reference for enabling FARF in autogen stub files +// Add a weak reference for enabling FARF in autogen stub files #pragma weak HAP_debug -//Add a weak reference so runtime FARFs are ignored on older images +// Add a weak reference so runtime FARFs are ignored on older images #pragma weak HAP_debug_runtime /************************************************************************** These HAP_debug* functions are not meant to be called directly. Please use the FARF() macros to call them instead **************************************************************************/ -void HAP_debug_v2(int level, const char* file, int line, const char* format, ...); -void HAP_debug_runtime(int level, const char* file, int line, const char* format, ...); -int HAP_setFARFRuntimeLoggingParams(unsigned int mask, const char* files[], +void HAP_debug_v2(int level, const char *file, int line, const char *format, + ...); +void HAP_debug_runtime(int level, const char *file, int line, + const char *format, ...); +int HAP_setFARFRuntimeLoggingParams(unsigned int mask, const char *files[], unsigned short numberOfFiles); // Keep these around to support older shared objects and older images void HAP_debug(const char *msg, int level, const char *filename, int line); -static __inline void _HAP_debug_v2(int level, const char* file, int line, - const char* format, ...){ - char buf[256]; - va_list args; - va_start(args, format); - vsnprintf(buf, sizeof(buf), format, args); - va_end(args); - HAP_debug(buf, level, file, line); +static __inline void +_HAP_debug_v2(int level, const char *file, int line, const char *format, ...) +{ + char buf[256]; + va_list args; + va_start(args, format); + vsnprintf(buf, sizeof(buf), format, args); + va_end(args); + HAP_debug(buf, level, file, line); } /*! @@ -78,15 +81,14 @@ Returns */ bool HAP_log_data_packet(unsigned short log_code_type, unsigned int dataLen, - unsigned char* data); + unsigned char *data); #define HAP_DEBUG_TRACEME 0 -long HAP_debug_ptrace(int req, unsigned int pid, void* addr, void* data); +long HAP_debug_ptrace(int req, unsigned int pid, void *addr, void *data); #ifdef __cplusplus } #endif #endif // HAP_DEBUG_H - diff --git a/inc/HAP_farf.h b/inc/HAP_farf.h index dd71e70e..929c2eca 100644 --- a/inc/HAP_farf.h +++ b/inc/HAP_farf.h @@ -19,9 +19,9 @@ * `Compile time logging options:` * * Logging is controlled via conditional compilation. - * The FARF level allows the user to selectively enable or disable certain types - * of messages according to their priority level. - * The following levels are supported and listed in increasing priority: + * The FARF level allows the user to selectively enable or disable certain + *types of messages according to their priority level. The following levels are + *supported and listed in increasing priority: * * LOW * @@ -54,7 +54,8 @@ * will be compiled in. * * If both HIGH and LOW messages are used but only FARF_LOW is defined - * as shown in below example then only LOW message will be compiled in and sent to DIAG. + * as shown in below example then only LOW message will be compiled in and sent + *to DIAG. * * @code * #define FARF_LOW 1 @@ -94,11 +95,11 @@ * * @endcode * - * @param[in] x the FARF level defined to either 0 to disable compilation or 1 to enable. + * @param[in] x the FARF level defined to either 0 to disable compilation or 1 + *to enable. * @param[in] ... the format string and arguments. */ -#define FARF(x, ...) _FARF_PASTE(_FARF_,_FARF_VAL(FARF_##x))(x, ##__VA_ARGS__) - +#define FARF(x, ...) _FARF_PASTE(_FARF_, _FARF_VAL(FARF_##x))(x, ##__VA_ARGS__) /** * @defgroup static_FARF Compile-time macros @@ -135,164 +136,173 @@ * The FARF_ALWAYS macro causes log messages to be ALWAYS compiled in */ #ifndef FARF_ALWAYS -#define FARF_ALWAYS 1 +#define FARF_ALWAYS 1 #endif /** - * The FARF_LOW macro causes log messages to be compiled in when FARF_LOW is defined to 1 -*/ + * The FARF_LOW macro causes log messages to be compiled in when FARF_LOW is + * defined to 1 + */ #ifndef FARF_LOW -#define FARF_LOW 0 +#define FARF_LOW 0 #endif /** -* The FARF_MEDIUM macro causes log messages to be compiled in when FARF_MEDIUM is defined to 1 -*/ + * The FARF_MEDIUM macro causes log messages to be compiled in when FARF_MEDIUM + * is defined to 1 + */ #ifndef FARF_MEDIUM -#define FARF_MEDIUM 0 +#define FARF_MEDIUM 0 #endif /** -* The FARF_HIGH macro causes log messages to be compiled in when FARF_HIGH is defined to 1 -*/ + * The FARF_HIGH macro causes log messages to be compiled in when FARF_HIGH is + * defined to 1 + */ #ifndef FARF_HIGH -#define FARF_HIGH 0 +#define FARF_HIGH 0 #endif /** -* The FARF_ERROR macro causes log messages to be compiled in when FARF_ERROR is defined to 1 -*/ + * The FARF_ERROR macro causes log messages to be compiled in when FARF_ERROR + * is defined to 1 + */ #ifndef FARF_ERROR -#define FARF_ERROR 1 +#define FARF_ERROR 1 #endif /** -* The FARF_FATAL macro causes log messages to be compiled in when FARF_FATAL is defined to 1 -*/ + * The FARF_FATAL macro causes log messages to be compiled in when FARF_FATAL + * is defined to 1 + */ #ifndef FARF_FATAL -#define FARF_FATAL 1 +#define FARF_FATAL 1 #endif #ifndef FARF_CRITICAL -#define FARF_CRITICAL 0 /* 0 turns me off */ +#define FARF_CRITICAL 0 /* 0 turns me off */ #endif - //! @cond Doxygen_Suppress -#define FARF_ALWAYS_LEVEL HAP_LEVEL_HIGH -#define FARF_LOW_LEVEL HAP_LEVEL_LOW -#define FARF_MEDIUM_LEVEL HAP_LEVEL_MEDIUM -#define FARF_HIGH_LEVEL HAP_LEVEL_HIGH -#define FARF_ERROR_LEVEL HAP_LEVEL_ERROR -#define FARF_FATAL_LEVEL HAP_LEVEL_FATAL -#define FARF_CRITICAL_LEVEL HAP_LEVEL_CRITICAL +#define FARF_ALWAYS_LEVEL HAP_LEVEL_HIGH +#define FARF_LOW_LEVEL HAP_LEVEL_LOW +#define FARF_MEDIUM_LEVEL HAP_LEVEL_MEDIUM +#define FARF_HIGH_LEVEL HAP_LEVEL_HIGH +#define FARF_ERROR_LEVEL HAP_LEVEL_ERROR +#define FARF_FATAL_LEVEL HAP_LEVEL_FATAL +#define FARF_CRITICAL_LEVEL HAP_LEVEL_CRITICAL //! @endcond /* @} */ - /** -* @defgroup Runtime_FARF Runtime macros -* -* Runtime FARF macros can be enabled at runtime. -* They are turned OFF by default. -* -* Usage Example: -* @code -* -* FARF(RUNTIME_HIGH,"Log message"); -* -* @endcode -*/ + * @defgroup Runtime_FARF Runtime macros + * + * Runtime FARF macros can be enabled at runtime. + * They are turned OFF by default. + * + * Usage Example: + * @code + * + * FARF(RUNTIME_HIGH,"Log message"); + * + * @endcode + */ /* @{ */ //! @cond Doxygen_Suppress #ifndef FARF_RUNTIME_LOW -#define FARF_RUNTIME_LOW 1 +#define FARF_RUNTIME_LOW 1 #endif -#define FARF_RUNTIME_LOW_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_LOW) +#define FARF_RUNTIME_LOW_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_LOW) #ifndef FARF_RUNTIME_MEDIUM -#define FARF_RUNTIME_MEDIUM 1 +#define FARF_RUNTIME_MEDIUM 1 #endif -#define FARF_RUNTIME_MEDIUM_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_MEDIUM) +#define FARF_RUNTIME_MEDIUM_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_MEDIUM) #ifndef FARF_RUNTIME_HIGH -#define FARF_RUNTIME_HIGH 1 +#define FARF_RUNTIME_HIGH 1 #endif -#define FARF_RUNTIME_HIGH_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_HIGH) +#define FARF_RUNTIME_HIGH_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_HIGH) #ifndef FARF_RUNTIME_ERROR -#define FARF_RUNTIME_ERROR 1 +#define FARF_RUNTIME_ERROR 1 #endif -#define FARF_RUNTIME_ERROR_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_ERROR) +#define FARF_RUNTIME_ERROR_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_ERROR) #ifndef FARF_RUNTIME_FATAL -#define FARF_RUNTIME_FATAL 1 +#define FARF_RUNTIME_FATAL 1 #endif -#define FARF_RUNTIME_FATAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_FATAL) +#define FARF_RUNTIME_FATAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_FATAL) #ifndef FARF_RUNTIME_RPC_LOW -#define FARF_RUNTIME_RPC_LOW 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_LOW 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_LOW_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_LOW) +#define FARF_RUNTIME_RPC_LOW_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_LOW) #ifndef FARF_RUNTIME_RPC_MEDIUM -#define FARF_RUNTIME_RPC_MEDIUM 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_MEDIUM 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_MEDIUM_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_MEDIUM) +#define FARF_RUNTIME_RPC_MEDIUM_LEVEL \ + (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_MEDIUM) #ifndef FARF_RUNTIME_RPC_HIGH -#define FARF_RUNTIME_RPC_HIGH 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_HIGH 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_HIGH_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_HIGH) +#define FARF_RUNTIME_RPC_HIGH_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_HIGH) #ifndef FARF_RUNTIME_RPC_ERROR -#define FARF_RUNTIME_RPC_ERROR 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_ERROR 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_ERROR_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_ERROR) +#define FARF_RUNTIME_RPC_ERROR_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_ERROR) #ifndef FARF_RUNTIME_RPC_FATAL -#define FARF_RUNTIME_RPC_FATAL 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_FATAL 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_FATAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_FATAL) +#define FARF_RUNTIME_RPC_FATAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_FATAL) #ifndef FARF_RUNTIME_RPC_CRITICAL -#define FARF_RUNTIME_RPC_CRITICAL 1 /* 0 turns me off */ +#define FARF_RUNTIME_RPC_CRITICAL 1 /* 0 turns me off */ #endif -#define FARF_RUNTIME_RPC_CRITICAL_LEVEL (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_CRITICAL) +#define FARF_RUNTIME_RPC_CRITICAL_LEVEL \ + (HAP_LEVEL_RUNTIME | HAP_LEVEL_RPC_CRITICAL) //! @endcond /* @} */ - //! @cond Doxygen_Suppress -#define _FARF_PASTE(a,b) _FARF_PASTE_(a,b) -#define _FARF_PASTE_(a,b) a##b +#define _FARF_PASTE(a, b) _FARF_PASTE_(a, b) +#define _FARF_PASTE_(a, b) a##b #define _FARF_VAL(a) a - #define _FARF_0(x, ...) #ifndef __FILENAME__ #define __FILENAME__ __FILE__ #endif -#define _FARF_1(x, ...) \ - do { \ - if(0 == (HAP_debug_v2)) { \ - _HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, __LINE__, ##__VA_ARGS__); \ - } else { \ - if (FARF_##x##_LEVEL & HAP_LEVEL_RUNTIME) { \ - if (0 != HAP_debug_runtime) { \ - HAP_debug_runtime(FARF_##x##_LEVEL ^ HAP_LEVEL_RUNTIME , __FILENAME__, __LINE__, ##__VA_ARGS__); \ - } else { \ - break; \ - } \ - } else { \ - HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, __LINE__, ##__VA_ARGS__); \ - } \ - } \ - } while (0) +#define _FARF_1(x, ...) \ + do { \ + if(0 == (HAP_debug_v2)) { \ + _HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, \ + __LINE__, ##__VA_ARGS__); \ + } else { \ + if(FARF_##x##_LEVEL & HAP_LEVEL_RUNTIME) { \ + if(0 != HAP_debug_runtime) { \ + HAP_debug_runtime( \ + FARF_##x##_LEVEL \ + ^ HAP_LEVEL_RUNTIME, \ + __FILENAME__, __LINE__, \ + ##__VA_ARGS__); \ + } else { \ + break; \ + } \ + } else { \ + HAP_debug_v2(FARF_##x##_LEVEL, __FILENAME__, \ + __LINE__, ##__VA_ARGS__); \ + } \ + } \ + } while(0) #endif /* #ifndef HAP_FARF_H */ //! @endcond diff --git a/inc/HAP_farf_internal.h b/inc/HAP_farf_internal.h index bdebfe13..0b49cfb9 100644 --- a/inc/HAP_farf_internal.h +++ b/inc/HAP_farf_internal.h @@ -6,7 +6,4 @@ #include "HAP_farf.h" - - - #endif /*__HAP_FARF_INTERNAL_H__*/ diff --git a/inc/HAP_pls.h b/inc/HAP_pls.h index 717685d4..58c89931 100644 --- a/inc/HAP_pls.h +++ b/inc/HAP_pls.h @@ -13,8 +13,8 @@ extern "C" { /** * Process local storage is local storage for the hlos process context. * - * Warning, this API should only be called from within a thread started by FastRPC, and not from - * any user created threads via the qurt apis. + * Warning, this API should only be called from within a thread started by + * FastRPC, and not from any user created threads via the qurt apis. * * When used from within a FastRPC started thread this will attach * desturctors to the lifetime of the HLOS process that is making the @@ -30,30 +30,29 @@ extern "C" { * For example: * * static int my_instance(struct my_struct* me) { - * return HAP_pls_add_lookup((uintptr_t)my_ctor, //type, some unique static address - * 0, //key, for different type instances + * return HAP_pls_add_lookup((uintptr_t)my_ctor, //type, some unique + * static address 0, //key, for different type instances * sizeof(*me), //size of our struture * my_ctor, //structure ctor - * 0, //aditional user context for ctor - * my_dtor, //desturctor - * &me); //result + * 0, //aditional user context + * for ctor my_dtor, //desturctor &me); //result * } * - * First call to my_instance will initialize the structure by allocating it and calling my_ctor. - * Second call to my_instance will return the created instance. - * This API is thread safe, but when two threads try to intialize the structure the first - * time they may both create an instance, but only 1 will be returned. - * The destructor will be called when the HLOS process exits. + * First call to my_instance will initialize the structure by allocating it and + * calling my_ctor. Second call to my_instance will return the created + * instance. This API is thread safe, but when two threads try to intialize the + * structure the first time they may both create an instance, but only 1 will + * be returned. The destructor will be called when the HLOS process exits. * * See HAP_pls_add and HAP_pls_add_lookup. * * Exit Hooks * ---------- * - * Users can use either HAP_pls_add_lookup or HAP_pls_add to add a destructor that will be - * called when the HLOS process exits. The main difference between the two functions is that - * HAP_pls_add will always add, and the last instance added will be the one returned by - * HAP_pls_lookup. + * Users can use either HAP_pls_add_lookup or HAP_pls_add to add a destructor + * that will be called when the HLOS process exits. The main difference + * between the two functions is that HAP_pls_add will always add, and the last + * instance added will be the one returned by HAP_pls_lookup. * * */ @@ -74,7 +73,9 @@ extern "C" { * @param ppo, output data * @retval, 0 for success */ -int HAP_pls_add(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); +int HAP_pls_add(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo); /** * Like add, but will only add 1 item, and return the same item on the @@ -83,9 +84,12 @@ int HAP_pls_add(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, * may be called twice. * item if its already there, otherwise tries to add. * ctor may be called twice - * callers should avoid calling pls_add for the same type/key which will override the singleton + * callers should avoid calling pls_add for the same type/key which will + * override the singleton */ -int HAP_pls_add_lookup(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); +int HAP_pls_add_lookup(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo); /** * finds the last data pointer added for key to the local storage @@ -94,10 +98,9 @@ int HAP_pls_add_lookup(uintptr_t type, uintptr_t key, int size, int (*ctor)(void * @param ppo, output data * @retval, 0 for success */ -int HAP_pls_lookup(uintptr_t type, uintptr_t key, void** ppo); - +int HAP_pls_lookup(uintptr_t type, uintptr_t key, void **ppo); #ifdef __cplusplus } #endif -#endif //HAP_PLS_H +#endif // HAP_PLS_H diff --git a/inc/adsp_current_process.h b/inc/adsp_current_process.h index 5b0196b1..3c55c810 100644 --- a/inc/adsp_current_process.h +++ b/inc/adsp_current_process.h @@ -35,20 +35,33 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_exit)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_thread_exit)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_set_logging_params)(unsigned short mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_getASID)(unsigned int* asid) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_setQoS)(unsigned int latency) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_exception)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_set_logging_params2)(unsigned int mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_poll_mode)(unsigned int enable, unsigned int timeout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_enable_notifications)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process_exit)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_thread_exit)(void) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process_set_logging_params)( + unsigned short mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_getASID)( + unsigned int *asid) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_setQoS)( + unsigned int latency) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_exception)(void) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process_set_logging_params2)( + unsigned int mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process_poll_mode)( + unsigned int enable, unsigned int timeout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER( + adsp_current_process_enable_notifications)(void) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adsp_current_process1.h b/inc/adsp_current_process1.h index ec871e06..ea769acc 100644 --- a/inc/adsp_current_process1.h +++ b/inc/adsp_current_process1.h @@ -36,54 +36,76 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ #define _const_adsp_current_process1_handle 4 /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; -/** + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_open)( + const char *uri, remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; +/** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_exit)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_thread_exit)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_set_logging_params)(remote_handle64 _h, unsigned short mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_getASID)(remote_handle64 _h, unsigned int* asid) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_setQoS)(remote_handle64 _h, unsigned int latency) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_exception)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_set_logging_params2)(remote_handle64 _h, unsigned int mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_poll_mode)(remote_handle64 _h, unsigned int enable, unsigned int timeout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_enable_notifications)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_panic_err_codes)(remote_handle64 _h, const int* err_codes, int err_codesLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_close)( + remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_exit)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_thread_exit)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process1_set_logging_params)( + remote_handle64 _h, unsigned short mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_getASID)( + remote_handle64 _h, unsigned int *asid) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_setQoS)( + remote_handle64 _h, unsigned int latency) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_exception)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process1_set_logging_params2)( + remote_handle64 _h, unsigned int mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_poll_mode)( + remote_handle64 _h, unsigned int enable, + unsigned int timeout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_current_process1_enable_notifications)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_current_process1_panic_err_codes)( + remote_handle64 _h, const int *err_codes, + int err_codesLen) __QAIC_HEADER_ATTRIBUTE; #ifndef adsp_current_process1_URI -#define adsp_current_process1_URI "file:///libadsp_current_process1_skel.so?adsp_current_process1_skel_handle_invoke&_modver=1.0" +#define adsp_current_process1_URI \ + "file:///" \ + "libadsp_current_process1_skel.so?adsp_current_process1_skel_handle_" \ + "invoke&_modver=1.0" #endif /*adsp_current_process1_URI*/ #ifdef __cplusplus } diff --git a/inc/adsp_default_listener.h b/inc/adsp_default_listener.h index 53ba793d..45dd8aff 100644 --- a/inc/adsp_default_listener.h +++ b/inc/adsp_default_listener.h @@ -31,7 +31,8 @@ #ifdef __cplusplus extern "C" { #endif -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener_register)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener_register)(void) + __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adsp_default_listener1.h b/inc/adsp_default_listener1.h index 2042fffd..cbe3856c 100644 --- a/inc/adsp_default_listener1.h +++ b/inc/adsp_default_listener1.h @@ -5,8 +5,8 @@ #define _ADSP_DEFAULT_LISTENER1_H #include #include -#include #include +#include #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff @@ -52,7 +52,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -62,7 +62,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -120,52 +120,56 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) @@ -174,73 +178,78 @@ static __inline void _qaic_memmove(void* dst, void* src, int size) { #ifdef _WIN32 #define _QAIC_FARF(level, msg, ...) (void)0 #else -#define _QAIC_FARF(level, msg, ...) \ - do {\ - if(0 == (HAP_debug_v2) ) {\ - (void)0; \ - } else { \ - FARF(level, msg , ##__VA_ARGS__); \ - } \ - }while(0) +#define _QAIC_FARF(level, msg, ...) \ + do { \ + if(0 == (HAP_debug_v2)) { \ + (void)0; \ + } else { \ + FARF(level, msg, ##__VA_ARGS__); \ + } \ + } while(0) #endif //_WIN32 for _QAIC_FARF -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _TRY_FARF(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - goto ee##farf##bail;\ - } \ - } while (0) +#define _TRY_FARF(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + goto ee##farf##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) -#define _CATCH_FARF(exception) exception##farf##bail: if (exception != AEE_SUCCESS) +#define _CATCH_FARF(exception) \ + exception##farf##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifdef __cplusplus extern "C" { #endif /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_open)( + const char *uri, remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; /** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. @@ -248,10 +257,15 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_open)(const char* * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_register)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_close)( + remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_default_listener1_register)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; #ifndef adsp_default_listener1_URI -#define adsp_default_listener1_URI "file:///libadsp_default_listener1_skel.so?adsp_default_listener1_skel_handle_invoke&_modver=1.0" +#define adsp_default_listener1_URI \ + "file:///" \ + "libadsp_default_listener1_skel.so?adsp_default_listener1_skel_" \ + "handle_invoke&_modver=1.0" #endif /*adsp_default_listener1_URI*/ #ifdef __cplusplus } diff --git a/inc/adsp_listener.h b/inc/adsp_listener.h index 2b3d5506..7b5ecbd3 100644 --- a/inc/adsp_listener.h +++ b/inc/adsp_listener.h @@ -33,20 +33,37 @@ extern "C" { #endif #define _const_adsp_listener_handle 3 -typedef struct _adsp_listener_buffer__seq_uint8 _adsp_listener_buffer__seq_uint8; +typedef struct _adsp_listener_buffer__seq_uint8 + _adsp_listener_buffer__seq_uint8; typedef _adsp_listener_buffer__seq_uint8 adsp_listener_buffer; struct _adsp_listener_buffer__seq_uint8 { - uint8_t* data; - int dataLen; + uint8_t *data; + int dataLen; }; typedef uint32_t adsp_listener_remote_handle; typedef uint32_t adsp_listener_invoke_ctx; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_next_invoke)(adsp_listener_invoke_ctx prevCtx, int prevResult, const adsp_listener_buffer* outBufs, int outBufsLen, adsp_listener_invoke_ctx* ctx, adsp_listener_remote_handle* handle, uint32_t* sc, adsp_listener_buffer* inBuffers, int inBuffersLen, int* inBufLenReq, int inBufLenReqLen, int* routBufLenReq, int routBufLenReqLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_invoke_get_in_bufs)(adsp_listener_invoke_ctx ctx, adsp_listener_buffer* inBuffers, int inBuffersLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_init)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_init2)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_next2)(adsp_listener_invoke_ctx prevCtx, int prevResult, const uint8_t* prevbufs, int prevbufsLen, adsp_listener_invoke_ctx* ctx, adsp_listener_remote_handle* handle, uint32_t* sc, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_get_in_bufs2)(adsp_listener_invoke_ctx ctx, int offset, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_next_invoke)( + adsp_listener_invoke_ctx prevCtx, int prevResult, + const adsp_listener_buffer *outBufs, int outBufsLen, + adsp_listener_invoke_ctx *ctx, adsp_listener_remote_handle *handle, + uint32_t *sc, adsp_listener_buffer *inBuffers, int inBuffersLen, + int *inBufLenReq, int inBufLenReqLen, int *routBufLenReq, + int routBufLenReqLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_invoke_get_in_bufs)( + adsp_listener_invoke_ctx ctx, adsp_listener_buffer *inBuffers, + int inBuffersLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_listener_init)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_listener_init2)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_next2)( + adsp_listener_invoke_ctx prevCtx, int prevResult, const uint8_t *prevbufs, + int prevbufsLen, adsp_listener_invoke_ctx *ctx, + adsp_listener_remote_handle *handle, uint32_t *sc, uint8_t *bufs, + int bufsLen, int *bufsLenReq) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener_get_in_bufs2)( + adsp_listener_invoke_ctx ctx, int offset, uint8_t *bufs, int bufsLen, + int *bufsLenReq) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adsp_listener1.h b/inc/adsp_listener1.h index 58b66dd3..db1d37d2 100644 --- a/inc/adsp_listener1.h +++ b/inc/adsp_listener1.h @@ -5,9 +5,8 @@ #define _ADSP_LISTENER1_H #include #include -#include #include - +#include #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff @@ -53,7 +52,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -63,7 +62,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -121,52 +120,56 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) @@ -175,46 +178,50 @@ static __inline void _qaic_memmove(void* dst, void* src, int size) { #ifdef _WIN32 #define _QAIC_FARF(level, msg, ...) (void)0 #else -#define _QAIC_FARF(level, msg, ...) \ - do {\ - if(0 == (HAP_debug_v2) ) {\ - (void)0; \ - } else { \ - FARF(level, msg , ##__VA_ARGS__); \ - } \ - }while(0) +#define _QAIC_FARF(level, msg, ...) \ + do { \ + if(0 == (HAP_debug_v2)) { \ + (void)0; \ + } else { \ + FARF(level, msg, ##__VA_ARGS__); \ + } \ + } while(0) #endif //_WIN32 for _QAIC_FARF -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _TRY_FARF(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - goto ee##farf##bail;\ - } \ - } while (0) +#define _TRY_FARF(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + goto ee##farf##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) -#define _CATCH_FARF(exception) exception##farf##bail: if (exception != AEE_SUCCESS) +#define _CATCH_FARF(exception) \ + exception##farf##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifdef __cplusplus @@ -222,27 +229,28 @@ extern "C" { #endif #define _const_adsp_listener1_handle 7 /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_open)( + const char *uri, remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; /** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. @@ -250,23 +258,45 @@ __QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_open)(const char* uri, rem * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -typedef struct _adsp_listener1_buffer__seq_uint8 _adsp_listener1_buffer__seq_uint8; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_close)(remote_handle64 h) + __QAIC_HEADER_ATTRIBUTE; +typedef struct _adsp_listener1_buffer__seq_uint8 + _adsp_listener1_buffer__seq_uint8; typedef _adsp_listener1_buffer__seq_uint8 adsp_listener1_buffer; struct _adsp_listener1_buffer__seq_uint8 { - uint8_t* data; - int dataLen; + uint8_t *data; + int dataLen; }; typedef uint32_t adsp_listener1_remote_handle; typedef uint32_t adsp_listener1_invoke_ctx; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_next_invoke)(remote_handle64 _h, adsp_listener1_invoke_ctx prevCtx, int prevResult, const adsp_listener1_buffer* outBufs, int outBufsLen, adsp_listener1_invoke_ctx* ctx, adsp_listener1_remote_handle* handle, uint32_t* sc, adsp_listener1_buffer* inBuffers, int inBuffersLen, int* inBufLenReq, int inBufLenReqLen, int* routBufLenReq, int routBufLenReqLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_invoke_get_in_bufs)(remote_handle64 _h, adsp_listener1_invoke_ctx ctx, adsp_listener1_buffer* inBuffers, int inBuffersLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_init)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_init2)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_next2)(remote_handle64 _h, adsp_listener1_invoke_ctx prevCtx, int prevResult, const uint8_t* prevbufs, int prevbufsLen, adsp_listener1_invoke_ctx* ctx, adsp_listener1_remote_handle* handle, uint32_t* sc, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_get_in_bufs2)(remote_handle64 _h, adsp_listener1_invoke_ctx ctx, int offset, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_next_invoke)( + remote_handle64 _h, adsp_listener1_invoke_ctx prevCtx, int prevResult, + const adsp_listener1_buffer *outBufs, int outBufsLen, + adsp_listener1_invoke_ctx *ctx, adsp_listener1_remote_handle *handle, + uint32_t *sc, adsp_listener1_buffer *inBuffers, int inBuffersLen, + int *inBufLenReq, int inBufLenReqLen, int *routBufLenReq, + int routBufLenReqLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_invoke_get_in_bufs)( + remote_handle64 _h, adsp_listener1_invoke_ctx ctx, + adsp_listener1_buffer *inBuffers, + int inBuffersLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_init)(remote_handle64 _h) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_init2)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_next2)( + remote_handle64 _h, adsp_listener1_invoke_ctx prevCtx, int prevResult, + const uint8_t *prevbufs, int prevbufsLen, adsp_listener1_invoke_ctx *ctx, + adsp_listener1_remote_handle *handle, uint32_t *sc, uint8_t *bufs, + int bufsLen, int *bufsLenReq) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_listener1_get_in_bufs2)( + remote_handle64 _h, adsp_listener1_invoke_ctx ctx, int offset, + uint8_t *bufs, int bufsLen, int *bufsLenReq) __QAIC_HEADER_ATTRIBUTE; #ifndef adsp_listener1_URI -#define adsp_listener1_URI "file:///libadsp_listener1_skel.so?adsp_listener1_skel_handle_invoke&_modver=1.0" +#define adsp_listener1_URI \ + "file:///" \ + "libadsp_listener1_skel.so?adsp_listener1_skel_handle_invoke&_" \ + "modver=1.0" #endif /*adsp_listener1_URI*/ #ifdef __cplusplus } diff --git a/inc/adsp_perf.h b/inc/adsp_perf.h index ac6d792e..0095457e 100644 --- a/inc/adsp_perf.h +++ b/inc/adsp_perf.h @@ -35,13 +35,13 @@ extern "C" { /** * Interface for querying the adsp for counter data * For example, to enable all the perf numbers: - * + * * int perf_on(void) { * int nErr = 0; * int numKeys = 0, maxLen = 0, ii; * char keys[512]; * char* buf = &keys[0]; - * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); + * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); * assert(maxLen < 512); * for(ii = 0; ii < numKeys; ++ii) { * char* name = buf; @@ -61,7 +61,7 @@ extern "C" { * char keys[512]; * char* buf = &keys[0]; * long long usecs[16]; - * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); + * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); * printf("perf keys: %d\n", numKeys); * VERIFY(0 == adsp_perf_get_usecs(usecs, 16)); * assert(maxLen < 512); @@ -76,9 +76,14 @@ extern "C" { * } */ #define _const_adsp_perf_handle 6 -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf_enable)(int ix) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf_get_usecs)(int64_t* dst, int dstLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf_get_keys)(char* keys, int keysLen, int* maxLen, int* numKeys) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf_enable)(int ix) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf_get_usecs)(int64_t *dst, + int dstLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf_get_keys)(char *keys, int keysLen, int *maxLen, + int *numKeys) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adsp_perf1.h b/inc/adsp_perf1.h index 19f272f5..56444dd0 100644 --- a/inc/adsp_perf1.h +++ b/inc/adsp_perf1.h @@ -5,9 +5,8 @@ #define _ADSP_PERF1_H #include #include -#include #include - +#include #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff @@ -53,7 +52,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -63,7 +62,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -121,52 +120,56 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) @@ -175,46 +178,50 @@ static __inline void _qaic_memmove(void* dst, void* src, int size) { #ifdef _WIN32 #define _QAIC_FARF(level, msg, ...) (void)0 #else -#define _QAIC_FARF(level, msg, ...) \ - do {\ - if(0 == (HAP_debug_v2) ) {\ - (void)0; \ - } else { \ - FARF(level, msg , ##__VA_ARGS__); \ - } \ - }while(0) +#define _QAIC_FARF(level, msg, ...) \ + do { \ + if(0 == (HAP_debug_v2)) { \ + (void)0; \ + } else { \ + FARF(level, msg, ##__VA_ARGS__); \ + } \ + } while(0) #endif //_WIN32 for _QAIC_FARF -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _TRY_FARF(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - goto ee##farf##bail;\ - } \ - } while (0) +#define _TRY_FARF(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + goto ee##farf##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) -#define _CATCH_FARF(exception) exception##farf##bail: if (exception != AEE_SUCCESS) +#define _CATCH_FARF(exception) \ + exception##farf##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifdef __cplusplus @@ -223,13 +230,13 @@ extern "C" { /** * Interface for querying the adsp for counter data * For example, to enable all the perf numbers: - * + * * int perf_on(void) { * int nErr = 0; * int numKeys = 0, maxLen = 0, ii; * char keys[512]; * char* buf = &keys[0]; - * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); + * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); * assert(maxLen < 512); * for(ii = 0; ii < numKeys; ++ii) { * char* name = buf; @@ -249,7 +256,7 @@ extern "C" { * char keys[512]; * char* buf = &keys[0]; * long long usecs[16]; - * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); + * VERIFY(0 == adsp_perf_get_keys(keys, 512, &maxLen, &numKeys)); * printf("perf keys: %d\n", numKeys); * VERIFY(0 == adsp_perf_get_usecs(usecs, 16)); * assert(maxLen < 512); @@ -265,40 +272,52 @@ extern "C" { */ #define _const_adsp_perf1_handle 9 /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; -/** + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf1_open)(const char *uri, + remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; +/** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf1_enable)(remote_handle64 _h, int ix) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf1_get_usecs)(remote_handle64 _h, int64_t* dst, int dstLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adsp_perf1_get_keys)(remote_handle64 _h, char* keys, int keysLen, int* maxLen, int* numKeys) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf1_enable)(remote_handle64 _h, + int ix) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf1_get_usecs)(remote_handle64 _h, int64_t *dst, + int dstLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adsp_perf1_get_keys)(remote_handle64 _h, char *keys, + int keysLen, int *maxLen, + int *numKeys) __QAIC_HEADER_ATTRIBUTE; #ifndef adsp_perf1_URI -#define adsp_perf1_URI "file:///libadsp_perf1_skel.so?adsp_perf1_skel_handle_invoke&_modver=1.0" +#define adsp_perf1_URI \ + "file:///" \ + "libadsp_perf1_skel.so?adsp_perf1_skel_handle_invoke&_modver=1.0" #endif /*adsp_perf1_URI*/ #ifdef __cplusplus } diff --git a/inc/adsp_pls.h b/inc/adsp_pls.h index b16e042c..5af9db05 100644 --- a/inc/adsp_pls.h +++ b/inc/adsp_pls.h @@ -15,7 +15,7 @@ extern "C" { /** * @file adsp_pls - * + * * adsp process local storage is local storage for the fastrpc hlos * process context. @@ -40,7 +40,9 @@ extern "C" { * @param ppo, output data * @retval, 0 for success */ -int adsp_pls_add(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); +int adsp_pls_add(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo); /** * Like add, but will only add 1 item, and return the same item on the @@ -51,7 +53,9 @@ int adsp_pls_add(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, * ctor may be called twice * callers should avoid calling pls_add which will override the singleton */ -int adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void*), void** ppo); +int adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo); /** * finds the last data pointer added for key to the local storage @@ -60,7 +64,7 @@ int adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, int (*ctor)(voi * @param ppo, output data * @retval, 0 for success */ -int adsp_pls_lookup(uintptr_t type, uintptr_t key, void** ppo); +int adsp_pls_lookup(uintptr_t type, uintptr_t key, void **ppo); /** * force init/deinit @@ -71,4 +75,4 @@ void gpls_deinit(void); #ifdef __cplusplus } #endif -#endif //ADSP_PLS_H +#endif // ADSP_PLS_H diff --git a/inc/adspmsgd_adsp.h b/inc/adspmsgd_adsp.h index d180ea93..3e5d0bb8 100644 --- a/inc/adspmsgd_adsp.h +++ b/inc/adspmsgd_adsp.h @@ -32,9 +32,14 @@ #ifdef __cplusplus extern "C" { #endif -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp_init)(int heapid, uint32_t ion_flags, uint32_t filter, uint32_t buf_size, int* buff_addr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp_init2)(void) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp_deinit)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adspmsgd_adsp_init)(int heapid, uint32_t ion_flags, + uint32_t filter, uint32_t buf_size, + int *buff_addr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adspmsgd_adsp_init2)(void) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(adspmsgd_adsp_deinit)(void) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adspmsgd_adsp1.h b/inc/adspmsgd_adsp1.h index f1b78150..25cb0bde 100644 --- a/inc/adspmsgd_adsp1.h +++ b/inc/adspmsgd_adsp1.h @@ -6,7 +6,6 @@ #include #include - #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff #endif //__QAIC_HEADER @@ -35,41 +34,51 @@ extern "C" { #endif #define _const_adspmsgd_adsp1_handle 5 /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; -/** + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_open)( + const char *uri, remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; +/** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_init2)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_deinit)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_init3)(remote_handle64 _h, int heapid, uint32_t ion_flags, uint32_t filter, uint64_t buf_size, uint64_t* buff_addr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_wait)(remote_handle64 _h, uint64_t* bytes_to_read) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_close)(remote_handle64 h) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_init2)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_deinit)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_init3)( + remote_handle64 _h, int heapid, uint32_t ion_flags, uint32_t filter, + uint64_t buf_size, uint64_t *buff_addr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_adsp1_wait)( + remote_handle64 _h, uint64_t *bytes_to_read) __QAIC_HEADER_ATTRIBUTE; #ifndef adspmsgd_adsp1_URI -#define adspmsgd_adsp1_URI "file:///libadspmsgd_adsp1_skel.so?adspmsgd_adsp1_skel_handle_invoke&_modver=1.0" +#define adspmsgd_adsp1_URI \ + "file:///" \ + "libadspmsgd_adsp1_skel.so?adspmsgd_adsp1_skel_handle_invoke&_" \ + "modver=1.0" #endif /*adspmsgd_adsp1_URI*/ #ifdef __cplusplus } diff --git a/inc/adspmsgd_apps.h b/inc/adspmsgd_apps.h index 32002526..2dc61b34 100644 --- a/inc/adspmsgd_apps.h +++ b/inc/adspmsgd_apps.h @@ -33,21 +33,24 @@ extern "C" { #endif enum adspmsgd_apps_Level { - LOW, - MEDIUM, - HIGH, - ERROR, - FATAL, - _32BIT_PLACEHOLDER_adspmsgd_apps_Level = 0x7fffffff + LOW, + MEDIUM, + HIGH, + ERROR, + FATAL, + _32BIT_PLACEHOLDER_adspmsgd_apps_Level = 0x7fffffff }; typedef enum adspmsgd_apps_Level adspmsgd_apps_Level; -typedef struct _adspmsgd_apps_octetSeq__seq_octet _adspmsgd_apps_octetSeq__seq_octet; +typedef struct _adspmsgd_apps_octetSeq__seq_octet + _adspmsgd_apps_octetSeq__seq_octet; typedef _adspmsgd_apps_octetSeq__seq_octet adspmsgd_apps_octetSeq; struct _adspmsgd_apps_octetSeq__seq_octet { - unsigned char* data; - int dataLen; + unsigned char *data; + int dataLen; }; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_apps_log)(const unsigned char* log_message_buffer, int log_message_bufferLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(adspmsgd_apps_log)( + const unsigned char *log_message_buffer, + int log_message_bufferLen) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/adspmsgd_internal.h b/inc/adspmsgd_internal.h index b526c1f0..164a08af 100644 --- a/inc/adspmsgd_internal.h +++ b/inc/adspmsgd_internal.h @@ -4,38 +4,42 @@ #ifndef __ADSPMSGD_INTERNAL__ #define __ADSPMSGD_INTERNAL__ -#include -#include #include +#include +#include -typedef void* (*reader_thread)(); +typedef void *(*reader_thread)(); typedef struct { - volatile int threadStop;// variable to stop the msgd HLOS thread - bool thread_running; // to check whether logger thread was launched - unsigned int bufferSize; //size of msgd shared buffer - unsigned int readIndex; //the index from which msgd thread starts reading - unsigned int* currentIndex; //if currentIndex is same as readIndex then msgd thread waits for messages from DSP - char* headPtr; //head pointer to the msgd shared buffer - char* message; //scratch buffer used to print messages - pthread_t msgreader_thread; - FILE *log_file_fd; // file descriptor to save runtime farf logs + volatile int threadStop; // variable to stop the msgd HLOS thread + bool thread_running; // to check whether logger thread was launched + unsigned int bufferSize; // size of msgd shared buffer + unsigned int + readIndex; // the index from which msgd thread starts reading + unsigned int + *currentIndex; // if currentIndex is same as readIndex then msgd + // thread waits for messages from DSP + char *headPtr; // head pointer to the msgd shared buffer + char *message; // scratch buffer used to print messages + pthread_t msgreader_thread; + FILE *log_file_fd; // file descriptor to save runtime farf logs } msgd; /** - * @brief API to initialize adspmsgd module - * Initializes data structures and global variables in this module - */ + * @brief API to initialize adspmsgd module + * Initializes data structures and global variables in this module + */ int adspmsgd_init(remote_handle64 handle, int filter); /** - * @brief API to log a new message in adspmsgd - * Sends the new message to stdout/any other logging mechanism available on the system - */ + * @brief API to log a new message in adspmsgd + * Sends the new message to stdout/any other logging mechanism available on the + * system + */ void adspmsgd_log_message(char *format, char *msg); /** - * @brief API to stop running this module - * after calling this API, no new messages will be logged in the system. - */ + * @brief API to stop running this module + * after calling this API, no new messages will be logged in the system. + */ void adspmsgd_stop(int); -#endif /* __ADSPMSGD_INTERNAL__ */ \ No newline at end of file +#endif /* __ADSPMSGD_INTERNAL__ */ diff --git a/inc/apps_mem.h b/inc/apps_mem.h index cc72e68f..3c6fcf1b 100644 --- a/inc/apps_mem.h +++ b/inc/apps_mem.h @@ -32,14 +32,29 @@ #ifdef __cplusplus extern "C" { #endif -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_map)(int heapid, uint32_t ion_flags, uint32_t rflags, uint32_t vin, int32_t len, uint32_t* vapps, uint32_t* vadsp) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_unmap)(uint32_t vadsp, int32_t len) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_map64)(int heapid, uint32_t ion_flags, uint32_t rflags, uint64_t vin, int64_t len, uint64_t* vapps, uint64_t* vadsp) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_unmap64)(uint64_t vadsp, int64_t len) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_share_map)(int fd, int size, uint64_t* vapps, uint64_t* vadsp) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_share_unmap)(uint64_t vadsp, int size) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_dma_handle_map)(int fd, int offset, int size) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_dma_handle_unmap)(int fd, int size) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_map)( + int heapid, uint32_t ion_flags, uint32_t rflags, uint32_t vin, int32_t len, + uint32_t *vapps, uint32_t *vadsp) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_mem_request_unmap)(uint32_t vadsp, + int32_t len) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_map64)( + int heapid, uint32_t ion_flags, uint32_t rflags, uint64_t vin, int64_t len, + uint64_t *vapps, uint64_t *vadsp) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_mem_request_unmap64)( + uint64_t vadsp, int64_t len) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_mem_share_map)(int fd, int size, uint64_t *vapps, + uint64_t *vadsp) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_mem_share_unmap)(uint64_t vadsp, + int size) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_mem_dma_handle_map)(int fd, int offset, + int size) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_mem_dma_handle_unmap)(int fd, + int size) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/apps_mem_internal.h b/inc/apps_mem_internal.h index bd985b33..4f87a667 100644 --- a/inc/apps_mem_internal.h +++ b/inc/apps_mem_internal.h @@ -7,14 +7,14 @@ #include "apps_mem.h" /** - * @brief API to initialize the apps_mem module - * initializes internal data structures and global variables - **/ + * @brief API to initialize the apps_mem module + * initializes internal data structures and global variables + **/ int apps_mem_init(int domain); /** - * @brief API to de-initialize the apps_mem module - * de-initializes internal data structures and global variables - **/ + * @brief API to de-initialize the apps_mem module + * de-initializes internal data structures and global variables + **/ void apps_mem_deinit(int domain); #endif /*__APPS_MEM_INTERNAL_H__*/ diff --git a/inc/apps_remotectl.h b/inc/apps_remotectl.h index 2590b14d..2c601631 100644 --- a/inc/apps_remotectl.h +++ b/inc/apps_remotectl.h @@ -36,13 +36,19 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_remotectl_open)(const char* name, int* handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_remotectl_close)(int handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_remotectl_open)(const char *name, int *handle, + char *dlerror, int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_remotectl_close)(int handle, char *dlerror, + int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/apps_std.h b/inc/apps_std.h index b083b7d4..3bc43c6a 100644 --- a/inc/apps_std.h +++ b/inc/apps_std.h @@ -36,151 +36,220 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ /** - * standard library functions remoted from the apps to the dsp - */ + * standard library functions remoted from the apps to the dsp + */ typedef int apps_std_FILE; enum apps_std_SEEK { - APPS_STD_SEEK_SET, - APPS_STD_SEEK_CUR, - APPS_STD_SEEK_END, - _32BIT_PLACEHOLDER_apps_std_SEEK = 0x7fffffff + APPS_STD_SEEK_SET, + APPS_STD_SEEK_CUR, + APPS_STD_SEEK_END, + _32BIT_PLACEHOLDER_apps_std_SEEK = 0x7fffffff }; typedef enum apps_std_SEEK apps_std_SEEK; typedef struct apps_std_DIR apps_std_DIR; struct apps_std_DIR { - uint64_t handle; + uint64_t handle; }; typedef struct apps_std_DIRENT apps_std_DIRENT; struct apps_std_DIRENT { - int ino; - char name[255]; + int ino; + char name[255]; }; typedef struct apps_std_STAT apps_std_STAT; struct apps_std_STAT { - uint64_t tsz; - uint64_t dev; - uint64_t ino; - uint32_t mode; - uint32_t nlink; - uint64_t rdev; - uint64_t size; - int64_t atime; - int64_t atimensec; - int64_t mtime; - int64_t mtimensec; - int64_t ctime; - int64_t ctimensec; + uint64_t tsz; + uint64_t dev; + uint64_t ino; + uint32_t mode; + uint32_t nlink; + uint64_t rdev; + uint64_t size; + int64_t atime; + int64_t atimensec; + int64_t mtime; + int64_t mtimensec; + int64_t ctime; + int64_t ctimensec; }; /** - * @retval, if operation fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen)(const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_freopen)(apps_std_FILE sin, const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fflush)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fclose)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; + * @retval, if operation fails errno is returned + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen)( + const char *name, const char *mode, + apps_std_FILE *psout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_freopen)( + apps_std_FILE sin, const char *name, const char *mode, + apps_std_FILE *psout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fflush)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fclose)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; /** - * @param, bEOF, if read or write bytes <= bufLen bytes then feof() is called - * and the result is returned in bEOF, otherwise bEOF is set to 0. - * @retval, if read or write return 0 for non zero length buffers, ferror is checked - * and a non zero value is returned in case of error with no rout parameters - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fread)(apps_std_FILE sin, unsigned char* buf, int bufLen, int* bytesRead, int* bEOF) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fwrite)(apps_std_FILE sin, const unsigned char* buf, int bufLen, int* bytesWritten, int* bEOF) __QAIC_HEADER_ATTRIBUTE; + * @param, bEOF, if read or write bytes <= bufLen bytes then feof() is called + * and the result is returned in bEOF, otherwise bEOF is set to 0. + * @retval, if read or write return 0 for non zero length buffers, ferror is + * checked and a non zero value is returned in case of error with no rout + * parameters + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fread)(apps_std_FILE sin, unsigned char *buf, + int bufLen, int *bytesRead, + int *bEOF) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fwrite)(apps_std_FILE sin, const unsigned char *buf, + int bufLen, int *bytesWritten, + int *bEOF) __QAIC_HEADER_ATTRIBUTE; /** - * @param, pos, this buffer is filled up to MIN(posLen, sizeof(fpos_t)) - * @param, posLenReq, returns sizeof(fpos_t) - * @retval, if operation fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fgetpos)(apps_std_FILE sin, unsigned char* pos, int posLen, int* posLenReq) __QAIC_HEADER_ATTRIBUTE; + * @param, pos, this buffer is filled up to MIN(posLen, sizeof(fpos_t)) + * @param, posLenReq, returns sizeof(fpos_t) + * @retval, if operation fails errno is returned + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fgetpos)(apps_std_FILE sin, unsigned char *pos, + int posLen, + int *posLenReq) __QAIC_HEADER_ATTRIBUTE; /** - * @param, if size of pos doesn't match the system size an error is returned. - * fgetpos can be used to query the size of fpos_t - * @retval, if operation fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fsetpos)(apps_std_FILE sin, const unsigned char* pos, int posLen) __QAIC_HEADER_ATTRIBUTE; + * @param, if size of pos doesn't match the system size an error is returned. + * fgetpos can be used to query the size of fpos_t + * @retval, if operation fails errno is returned + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fsetpos)(apps_std_FILE sin, + const unsigned char *pos, + int posLen) __QAIC_HEADER_ATTRIBUTE; /** - * @retval, if operation fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ftell)(apps_std_FILE sin, int* pos) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fseek)(apps_std_FILE sin, int offset, apps_std_SEEK whence) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_flen)(apps_std_FILE sin, uint64_t* len) __QAIC_HEADER_ATTRIBUTE; + * @retval, if operation fails errno is returned + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_ftell)(apps_std_FILE sin, + int *pos) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fseek)( + apps_std_FILE sin, int offset, + apps_std_SEEK whence) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_flen)(apps_std_FILE sin, + uint64_t *len) __QAIC_HEADER_ATTRIBUTE; /** - * @retval, only fails if transport fails - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_rewind)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_feof)(apps_std_FILE sin, int* bEOF) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ferror)(apps_std_FILE sin, int* err) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_clearerr)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_print_string)(const char* str) __QAIC_HEADER_ATTRIBUTE; + * @retval, only fails if transport fails + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_rewind)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_feof)(apps_std_FILE sin, + int *bEOF) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_ferror)(apps_std_FILE sin, + int *err) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_clearerr)(apps_std_FILE sin) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_print_string)(const char *str) + __QAIC_HEADER_ATTRIBUTE; /** - * @param val, must contain space for NULL - * @param valLenReq, length required with NULL - * @retval, if fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_getenv)(const char* name, char* val, int valLen, int* valLenReq) __QAIC_HEADER_ATTRIBUTE; + * @param val, must contain space for NULL + * @param valLenReq, length required with NULL + * @retval, if fails errno is returned + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_getenv)(const char *name, char *val, int valLen, + int *valLenReq) __QAIC_HEADER_ATTRIBUTE; /** - * @retval, if fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_setenv)(const char* name, const char* val, int override) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_unsetenv)(const char* name) __QAIC_HEADER_ATTRIBUTE; + * @retval, if fails errno is returned + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_setenv)(const char *name, const char *val, + int override) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_unsetenv)(const char *name) __QAIC_HEADER_ATTRIBUTE; /** - * This function will try to open a file given directories in envvarname separated by - * delim. - * so given environment variable FOO_PATH=/foo;/bar - * fopen_wth_env("FOO_PATH", ";", "path/to/file", "rw", &out); - * will try to open /foo/path/to/file, /bar/path/to/file - * if the variable is unset, it will open the file directly - * - * @param envvarname, name of the environment variable containing the path - * @param delim, delimiator string, such as ";" - * @param name, name of the file - * @param mode, mode - * @param psout, output handle - * @retval, 0 on success errno or -1 on failure - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_with_env)(const char* envvarname, const char* delim, const char* name, const char* mode, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fgets)(apps_std_FILE sin, unsigned char* buf, int bufLen, int* bEOF) __QAIC_HEADER_ATTRIBUTE; + * This function will try to open a file given directories in envvarname + * separated by delim. so given environment variable FOO_PATH=/foo;/bar + * fopen_wth_env("FOO_PATH", ";", "path/to/file", "rw", &out); + * will try to open /foo/path/to/file, /bar/path/to/file + * if the variable is unset, it will open the file directly + * + * @param envvarname, name of the environment variable containing the path + * @param delim, delimiator string, such as ";" + * @param name, name of the file + * @param mode, mode + * @param psout, output handle + * @retval, 0 on success errno or -1 on failure + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_with_env)( + const char *envvarname, const char *delim, const char *name, + const char *mode, apps_std_FILE *psout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fgets)(apps_std_FILE sin, unsigned char *buf, + int bufLen, + int *bEOF) __QAIC_HEADER_ATTRIBUTE; /** - * This method will return the paths that are searched when looking for a file. - * The paths are defined by the environment variable (separated by delimiters) - * that is passed to the method. - * - * @param envvarname, name of the environment variable containing the path - * @param delim, delimiator string, such as ";" - * @param name, name of the file - * @param paths, Search paths - * @param numPaths, Actual number of paths found - * @param maxPathLen, The max path length - * @retval, 0 on success errno or -1 on failure - * - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_get_search_paths_with_env)(const char* envvarname, const char* delim, _cstring1_t* paths, int pathsLen, uint32_t* numPaths, uint16_t* maxPathLen) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fileExists)(const char* path, bool* exists) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fsync)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fremove)(const char* name) __QAIC_HEADER_ATTRIBUTE; + * This method will return the paths that are searched when looking for a file. + * The paths are defined by the environment variable (separated by delimiters) + * that is passed to the method. + * + * @param envvarname, name of the environment variable containing the path + * @param delim, delimiator string, such as ";" + * @param name, name of the file + * @param paths, Search paths + * @param numPaths, Actual number of paths found + * @param maxPathLen, The max path length + * @retval, 0 on success errno or -1 on failure + * + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_get_search_paths_with_env)( + const char *envvarname, const char *delim, _cstring1_t *paths, + int pathsLen, uint32_t *numPaths, + uint16_t *maxPathLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fileExists)(const char *path, + bool *exists) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fsync)(apps_std_FILE sin) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fremove)(const char *name) __QAIC_HEADER_ATTRIBUTE; /** - * This function decrypts the file using the provided open file descriptor, closes the - * original descriptor and return a new file descriptor. - * @retval, if operation fails errno is returned - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fdopen_decrypt)(apps_std_FILE sin, apps_std_FILE* psout) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_opendir)(const char* name, apps_std_DIR* dir) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_closedir)(const apps_std_DIR* dir) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_readdir)(const apps_std_DIR* dir, apps_std_DIRENT* dirent, int* bEOF) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_mkdir)(const char* name, int mode) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_rmdir)(const char* name) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_stat)(const char* name, apps_std_STAT* stat) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ftrunc)(apps_std_FILE sin, int offset) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_frename)(const char* oldname, const char* newname) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_fd)(const char* name, const char* mode, int* fd, int* len) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fclose_fd)(int fd) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_with_env_fd)(const char* envvarname, const char* delim, const char* name, const char* mode, int* fd, int* len) __QAIC_HEADER_ATTRIBUTE; + * This function decrypts the file using the provided open file descriptor, + * closes the original descriptor and return a new file descriptor. + * @retval, if operation fails errno is returned + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fdopen_decrypt)( + apps_std_FILE sin, apps_std_FILE *psout) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_opendir)(const char *name, + apps_std_DIR *dir) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_closedir)( + const apps_std_DIR *dir) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_readdir)(const apps_std_DIR *dir, + apps_std_DIRENT *dirent, + int *bEOF) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_mkdir)(const char *name, + int mode) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_rmdir)(const char *name) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_stat)(const char *name, + apps_std_STAT *stat) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_ftrunc)(apps_std_FILE sin, + int offset) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_frename)( + const char *oldname, const char *newname) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fopen_fd)(const char *name, const char *mode, + int *fd, + int *len) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(apps_std_fclose_fd)(int fd) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fopen_with_env_fd)( + const char *envvarname, const char *delim, const char *name, + const char *mode, int *fd, int *len) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/apps_std_internal.h b/inc/apps_std_internal.h index 74d7ae63..b5d6d66e 100644 --- a/inc/apps_std_internal.h +++ b/inc/apps_std_internal.h @@ -7,12 +7,12 @@ #include "apps_std.h" /** - * @brief Macros used in apps_std - * defines the search paths where fastRPC library should - * look for skel libraries, .debugconfig, .farf files. - * Could be overloaded from build system. - **/ - + * @brief Macros used in apps_std + * defines the search paths where fastRPC library should + * look for skel libraries, .debugconfig, .farf files. + * Could be overloaded from build system. + **/ + #define RETRY_WRITE (3) // number of times to retry write operation // Environment variable name, that can be used to override the search paths @@ -46,9 +46,12 @@ #define VENDOR_DOM_LOCATION "/vendor/dsp/xdsp/" #endif -// Search path used by fastRPC to search skel library, .debugconfig and .farf files +// Search path used by fastRPC to search skel library, .debugconfig and .farf +// files #ifndef DSP_SEARCH_PATH -#define DSP_SEARCH_PATH ";/usr/lib/rfsa/adsp;/vendor/lib/rfsa/adsp;/vendor/dsp/;/usr/lib/dsp/;" +#define DSP_SEARCH_PATH \ + ";/usr/lib/rfsa/adsp;/vendor/lib/rfsa/adsp;/vendor/dsp/;/usr/lib/" \ + "dsp/;" #endif // Search path used by fastRPC for acdb path diff --git a/inc/dspqueue.h b/inc/dspqueue.h index 79e7dec5..c9a88d38 100644 --- a/inc/dspqueue.h +++ b/inc/dspqueue.h @@ -8,10 +8,9 @@ #ifndef DSPQUEUE_H #define DSPQUEUE_H -#include -#include #include - +#include +#include /** @defgroup dspqueue_consts Asynchronous DSP Packet Queue API Constants * @{ @@ -20,47 +19,67 @@ /** Infinite timeout */ #define DSPQUEUE_TIMEOUT_NONE 0xffffffff - /** - * Packet flags. The flags are used as a bitfield in packet read/write operations. + * Packet flags. The flags are used as a bitfield in packet read/write + * operations. */ enum dspqueue_packet_flags { - DSPQUEUE_PACKET_FLAG_MESSAGE = 0x0001, /**< Packet contains a message */ - DSPQUEUE_PACKET_FLAG_BUFFERS = 0x0002, /**< Packet contains buffer references */ - DSPQUEUE_PACKET_FLAG_WAKEUP = 0x0004, /**< Early wakeup packet */ - DSPQUEUE_PACKET_FLAG_DRIVER_READY = 0x0008, /**< Packet is ready for driver consumption. Currently unused. */ - DSPQUEUE_PACKET_FLAG_USER_READY = 0x0010, /**< Packet is ready for userspace library consumption */ - DSPQUEUE_PACKET_FLAG_RESERVED_ZERO = 0xffe0 + DSPQUEUE_PACKET_FLAG_MESSAGE + = 0x0001, /**< Packet contains a message */ + DSPQUEUE_PACKET_FLAG_BUFFERS + = 0x0002, /**< Packet contains buffer references */ + DSPQUEUE_PACKET_FLAG_WAKEUP = 0x0004, /**< Early wakeup packet */ + DSPQUEUE_PACKET_FLAG_DRIVER_READY + = 0x0008, /**< Packet is ready for driver consumption. Currently + unused. */ + DSPQUEUE_PACKET_FLAG_USER_READY + = 0x0010, /**< Packet is ready for userspace library consumption */ + DSPQUEUE_PACKET_FLAG_RESERVED_ZERO = 0xffe0 }; /** * Buffer flags. The flags are used in dspqueue_buffer.flags as a bitfield. */ enum dspqueue_buffer_flags { - /* 1 and 2 reserved */ - DSPQUEUE_BUFFER_FLAG_REF = 0x00000004, /**< Add a reference to a previously mapped buffer */ - DSPQUEUE_BUFFER_FLAG_DEREF = 0x00000008, /**< Remove a reference from a previously mapped buffer */ - DSPQUEUE_BUFFER_FLAG_FLUSH_SENDER = 0x00000010, /**< Flush buffer from sender caches */ - DSPQUEUE_BUFFER_FLAG_INVALIDATE_SENDER = 0x00000020, /**< Invalidate buffer from sender caches */ - DSPQUEUE_BUFFER_FLAG_FLUSH_RECIPIENT = 0x00000040, /**< Flush buffer from recipient caches */ - DSPQUEUE_BUFFER_FLAG_INVALIDATE_RECIPIENT = 0x00000080, /**< Invalidate buffer from recipient caches */ - DSPQUEUE_BUFFER_FLAG_RESERVED_ZERO = 0xffffff00 + /* 1 and 2 reserved */ + DSPQUEUE_BUFFER_FLAG_REF + = 0x00000004, /**< Add a reference to a previously mapped buffer */ + DSPQUEUE_BUFFER_FLAG_DEREF = 0x00000008, /**< Remove a reference from a + previously mapped buffer */ + DSPQUEUE_BUFFER_FLAG_FLUSH_SENDER + = 0x00000010, /**< Flush buffer from sender caches */ + DSPQUEUE_BUFFER_FLAG_INVALIDATE_SENDER + = 0x00000020, /**< Invalidate buffer from sender caches */ + DSPQUEUE_BUFFER_FLAG_FLUSH_RECIPIENT + = 0x00000040, /**< Flush buffer from recipient caches */ + DSPQUEUE_BUFFER_FLAG_INVALIDATE_RECIPIENT + = 0x00000080, /**< Invalidate buffer from recipient caches */ + DSPQUEUE_BUFFER_FLAG_RESERVED_ZERO = 0xffffff00 }; - /** * Statistics readable with dspqueue_get_stat() */ enum dspqueue_stat { - DSPQUEUE_STAT_READ_QUEUE_PACKETS = 1, /**< Numbers of packets in the read queue */ - DSPQUEUE_STAT_READ_QUEUE_BYTES, /**< Number of bytes in the read queue */ - DSPQUEUE_STAT_WRITE_QUEUE_PACKETS, /**< Number of packets in the write queue */ - DSPQUEUE_STAT_WRITE_QUEUE_BYTES, /**< Number of bytes in the write queue */ - DSPQUEUE_STAT_EARLY_WAKEUP_WAIT_TIME, /**< Total accumulated early wakeup wait time in microseconds */ - DSPQUEUE_STAT_EARLY_WAKEUP_MISSES, /**< Number accumulated of packets missed in the early wakeup loop */ - DSPQUEUE_STAT_SIGNALING_PERF /**< Signaling performance; 0 or undefined indicates the first implementation, - DSPQUEUE_SIGNALING_PERF_REDUCED_SIGNALING or higher a version if reduced - signaling for polling clients. */ + DSPQUEUE_STAT_READ_QUEUE_PACKETS + = 1, /**< Numbers of packets in the read queue */ + DSPQUEUE_STAT_READ_QUEUE_BYTES, /**< Number of bytes in the read queue + */ + DSPQUEUE_STAT_WRITE_QUEUE_PACKETS, /**< Number of packets in the write + queue */ + DSPQUEUE_STAT_WRITE_QUEUE_BYTES, /**< Number of bytes in the write + queue */ + DSPQUEUE_STAT_EARLY_WAKEUP_WAIT_TIME, /**< Total accumulated early + wakeup wait time in + microseconds */ + DSPQUEUE_STAT_EARLY_WAKEUP_MISSES, /**< Number accumulated of packets + missed in the early wakeup loop + */ + DSPQUEUE_STAT_SIGNALING_PERF /**< Signaling performance; 0 or undefined + indicates the first implementation, + DSPQUEUE_SIGNALING_PERF_REDUCED_SIGNALING + or higher a version if reduced + signaling for polling clients. */ }; /* Request IDs to be used with "dspqueue_request" */ @@ -83,14 +102,12 @@ typedef enum { /** @} */ - /** @defgroup dspqueue_types Asynchronous DSP Packet Queue API Data Types * @{ */ struct dspqueue; -typedef struct dspqueue* dspqueue_t; /**< Queue handle */ - +typedef struct dspqueue *dspqueue_t; /**< Queue handle */ /** * Buffer reference in a packet. @@ -102,21 +119,22 @@ typedef struct dspqueue* dspqueue_t; /**< Queue handle */ * mapped to the DSP, not just the subsection specified. */ struct dspqueue_buffer { - uint32_t fd; /**< Buffer file descriptor */ - uint32_t size; /**< Buffer size in bytes. The client can set this field - to zero when writing packets; in this case the - framework will set the field to the size of the - buffer as mapped. */ - uint32_t offset; /**< Offset within the buffer in bytes as allocated and mapped. - The virtual address #ptr includes the offset */ - uint32_t flags; /**< Buffer flags, see enum #dspqueue_buffer_flags */ - union { - void *ptr; /**< Buffer virtual address; NULL if not mapped in the local context */ - uint64_t address; - }; + uint32_t fd; /**< Buffer file descriptor */ + uint32_t size; /**< Buffer size in bytes. The client can set this field + to zero when writing packets; in this case the + framework will set the field to the size of the + buffer as mapped. */ + uint32_t offset; /**< Offset within the buffer in bytes as allocated + and mapped. The virtual address #ptr includes + the offset */ + uint32_t flags; /**< Buffer flags, see enum #dspqueue_buffer_flags */ + union { + void *ptr; /**< Buffer virtual address; NULL if not mapped in + the local context */ + uint64_t address; + }; }; - /** * Callback function type for all queue callbacks * @@ -124,7 +142,8 @@ struct dspqueue_buffer { * @param error Error code * @param context Client-provided context pointer */ -typedef void (*dspqueue_callback_t)(dspqueue_t queue, AEEResult error, void *context); +typedef void (*dspqueue_callback_t)(dspqueue_t queue, AEEResult error, + void *context); /* Struct to be used with DSPQUEUE_CREATE request */ typedef struct dspqueue_create_req { @@ -197,12 +216,10 @@ typedef struct dspqueue_request_payload { /** @} */ - #ifdef __cplusplus extern "C" { #endif - /** @defgroup dspqueue_funcs Asynchronous DSP Packet Queue API Functions * @{ */ @@ -214,31 +231,34 @@ extern "C" { * This function cannot be used to create multi-domain queue. * Refer 'dspqueue_request' for that. * - * @param [in] domain DSP to communicate with (CDSP_DOMAIN_ID in remote.h for cDSP) + * @param [in] domain DSP to communicate with (CDSP_DOMAIN_ID in remote.h for + * cDSP) * @param [in] flags Queue creation flags - * @param [in] req_queue_size Total request queue memory size in bytes; use 0 for system default - * @param [in] resp_queue_size Total response queue memory size in bytes; use 0 for system default - * @param [in] packet_callback Callback function called when there are new packets to read. - * The call will be done in a different thread's context. - * NULL to disable the callback. Clients cannot use blocking read - * calls if a packet callback has been set. - * @param [in] error_callback Callback function called on unrecoverable errors. NULL to disable. + * @param [in] req_queue_size Total request queue memory size in bytes; use 0 + * for system default + * @param [in] resp_queue_size Total response queue memory size in bytes; use 0 + * for system default + * @param [in] packet_callback Callback function called when there are new + * packets to read. The call will be done in a different thread's context. NULL + * to disable the callback. Clients cannot use blocking read calls if a packet + * callback has been set. + * @param [in] error_callback Callback function called on unrecoverable errors. + * NULL to disable. * @param [in] callback_context Context pointer for callback functions * @param [out] queue Queue handle * * @return 0 on success, error code on failure. * - AEE_ENOMEMORY: Not enough memory available * - AEE_EUNSUPPORTED: Message queue not supported on the given DSP - * - AEE_EBADPARM: Bad parameters, e.g. Invalid domain (use CDSP_DOMAIN_ID for cDSP) + * - AEE_EBADPARM: Bad parameters, e.g. Invalid domain (use + * CDSP_DOMAIN_ID for cDSP) * - AEE_ERPC: Internal RPC error, e.g. Queue list corrupt */ -AEEResult dspqueue_create(int domain, - uint32_t flags, - uint32_t req_queue_size, uint32_t resp_queue_size, +AEEResult dspqueue_create(int domain, uint32_t flags, uint32_t req_queue_size, + uint32_t resp_queue_size, dspqueue_callback_t packet_callback, dspqueue_callback_t error_callback, - void *callback_context, - dspqueue_t *queue); + void *callback_context, dspqueue_t *queue); /** * Close a queue and free all memory associated with it. The @@ -249,10 +269,12 @@ AEEResult dspqueue_create(int domain, * This function can be called on both single-domain and multi-domain * queues. * - * @param [in] queue Queue handle from dsp_queue_create() from dsp_queue_import(). + * @param [in] queue Queue handle from dsp_queue_create() from + * dsp_queue_import(). * * @return 0 on success, error code on failure. - * - AEE_ERPC: Internal RPC error, e.g. The queue is open on the DSP when attempting to close it on the host CPU + * - AEE_ERPC: Internal RPC error, e.g. The queue is open on the DSP + * when attempting to close it on the host CPU */ AEEResult dspqueue_close(dspqueue_t queue); @@ -276,24 +298,24 @@ AEEResult dspqueue_export(dspqueue_t queue, uint64_t *queue_id); * queue and communicate with its host CPU counterpart. * * @param [in] queue_id Queue ID from dspqueue_export(). - * @param [in] packet_callback Callback function called when there are new packets to read. - * The call will be done in a different thread's context. - * NULL to disable the callback. - * @param [in] error_callback Callback function called on unrecoverable errors. NULL to disable. + * @param [in] packet_callback Callback function called when there are new + * packets to read. The call will be done in a different thread's context. NULL + * to disable the callback. + * @param [in] error_callback Callback function called on unrecoverable errors. + * NULL to disable. * @param [in] callback_context Context pointer fo callback functions * @param [out] queue Queue handle * * @return 0 on success, error code on failure. * - AEE_EITEMBUSY: The queue has already been imported - * - AEE_EQURTTHREADCREATE: Unable to create callback thread; the system may have - * reached its thread limit. + * - AEE_EQURTTHREADCREATE: Unable to create callback thread; the + * system may have reached its thread limit. * - AEE_EBADSTATE: Bad internal state */ AEEResult dspqueue_import(uint64_t queue_id, dspqueue_callback_t packet_callback, dspqueue_callback_t error_callback, - void *callback_context, - dspqueue_t *queue); + void *callback_context, dspqueue_t *queue); /** * Make dspqueue related requests - like creation of multi-domain queue @@ -303,7 +325,8 @@ AEEResult dspqueue_import(uint64_t queue_id, * @return 0 on success, error code on failure. * - AEE_ENOMEMORY : Not enough memory available * - AEE_EUNSUPPORTED : Not supported on given domains - * - AEE_EBADPARM : Bad parameters, e.g. invalid context + * - AEE_EBADPARM : Bad parameters, e.g. invalid + *context * - AEE_ERPC : Internal RPC error */ int dspqueue_request(dspqueue_request_payload *req); @@ -334,14 +357,18 @@ int dspqueue_request(dspqueue_request_payload *req); * * @return 0 on success, error code on failure. * - AEE_EWOULDBLOCK: The queue is full - * - AEE_EBADPARM: Bad parameters, e.g. buffers is NULL when num_buffers > 0 - * - AEE_ENOSUCHMAP: Attempt to refer to an unmapped buffer. Buffers must be mapped to the DSP - * with fastrpc_mmap() before they can be used in queue packets. + * - AEE_EBADPARM: Bad parameters, e.g. buffers is NULL when + * num_buffers > 0 + * - AEE_ENOSUCHMAP: Attempt to refer to an unmapped buffer. Buffers + * must be mapped to the DSP with fastrpc_mmap() before they can be used in + * queue packets. * - AEE_EBADSTATE: Queue is in bad-state and can no longer be used */ AEEResult dspqueue_write_noblock(dspqueue_t queue, uint32_t flags, - uint32_t num_buffers, struct dspqueue_buffer *buffers, - uint32_t message_length, const uint8_t *message); + uint32_t num_buffers, + struct dspqueue_buffer *buffers, + uint32_t message_length, + const uint8_t *message); /** * Write a packet to a queue. If the queue is full this function will @@ -372,9 +399,11 @@ AEEResult dspqueue_write_noblock(dspqueue_t queue, uint32_t flags, * zero for non-blocking behavior. * * @return 0 on success, error code on failure. - * - AEE_EBADPARM: Bad parameters, e.g. buffers is NULL when num_buffers > 0 - * - AEE_ENOSUCHMAP: Attempt to refer to an unmapped buffer. Buffers must be mapped to the DSP - * with fastrpc_mmap() before they can be used in queue packets. + * - AEE_EBADPARM: Bad parameters, e.g. buffers is NULL when + * num_buffers > 0 + * - AEE_ENOSUCHMAP: Attempt to refer to an unmapped buffer. Buffers + * must be mapped to the DSP with fastrpc_mmap() before they can be used in + * queue packets. * - AEE_EEXPIRED: Request timed out * - AEE_EINTERRUPTED: The request was canceled * - AEE_EBADSTATE: Queue is in bad-state and can no longer be used @@ -401,22 +430,28 @@ AEEResult dspqueue_write(dspqueue_t queue, uint32_t flags, * * @param [in] queue Queue handle from dspqueue_create() or dspqueue_import() * @param [out] flags Packet flags. See enum #dspqueue_packet_flags - * @param [in] max_buffers The maximum number of buffer references that can fit in the "buffers" parameter + * @param [in] max_buffers The maximum number of buffer references that can fit + * in the "buffers" parameter * @param [out] num_buffers The number of buffer references in the packet * @param [out] buffers Buffer reference data from the packet - * @param [in] max_message_length Maximum message length that can fit in the "message" parameter + * @param [in] max_message_length Maximum message length that can fit in the + * "message" parameter * @param [out] message_length Message length in bytes * @param [out] message Packet message * * @return 0 on success, error code on failure. - * - AEE_ENOSUCHMAP: The packet refers to an unmapped buffer. Buffers must be mapped to the DSP - * with fastrpc_mmap() before they can be used in queue packets. + * - AEE_ENOSUCHMAP: The packet refers to an unmapped buffer. Buffers + * must be mapped to the DSP with fastrpc_mmap() before they can be used in + * queue packets. * - AEE_EWOULDBLOCK: The queue is empty; try again later - * - AEE_EBADITEM: The queue contains a corrupted packet. Internal error. + * - AEE_EBADITEM: The queue contains a corrupted packet. Internal + * error. */ AEEResult dspqueue_read_noblock(dspqueue_t queue, uint32_t *flags, - uint32_t max_buffers, uint32_t *num_buffers, struct dspqueue_buffer *buffers, - uint32_t max_message_length, uint32_t *message_length, uint8_t *message); + uint32_t max_buffers, uint32_t *num_buffers, + struct dspqueue_buffer *buffers, + uint32_t max_message_length, + uint32_t *message_length, uint8_t *message); /** * Read a packet from a queue. If the queue is empty this function @@ -431,10 +466,12 @@ AEEResult dspqueue_read_noblock(dspqueue_t queue, uint32_t *flags, * * @param [in] queue Queue handle from dspqueue_create() or dspqueue_import() * @param [out] flags Packet flags. See enum #dspqueue_packet_flags - * @param [in] max_buffers The maximum number of buffer references that can fit in the "buffers" parameter + * @param [in] max_buffers The maximum number of buffer references that can fit + * in the "buffers" parameter * @param [out] num_buffers The number of buffer references in the packet * @param [out] buffers Buffer reference data from the packet - * @param [in] max_message_length Maximum message length that can fit in the "message" parameter + * @param [in] max_message_length Maximum message length that can fit in the + * "message" parameter * @param [out] message_length Message length in bytes * @param [out] message Packet message * @param [in] timeout_us Timeout in microseconds; use DSPQUEUE_TIMEOUT_NONE to @@ -442,16 +479,19 @@ AEEResult dspqueue_read_noblock(dspqueue_t queue, uint32_t *flags, * zero for non-blocking behavior. * * @return 0 on success, error code on failure. - * - AEE_ENOSUCHMAP: The packet refers to an unmapped buffer. Buffers must be mapped to the DSP - * with fastrpc_mmap() before they can be used in queue packets. - * - AEE_EBADITEM: The queue contains a corrupted packet. Internal error. + * - AEE_ENOSUCHMAP: The packet refers to an unmapped buffer. Buffers + * must be mapped to the DSP with fastrpc_mmap() before they can be used in + * queue packets. + * - AEE_EBADITEM: The queue contains a corrupted packet. Internal + * error. * - AEE_EEXPIRED: Request timed out * - AEE_EINTERRUPTED: The request was canceled */ AEEResult dspqueue_read(dspqueue_t queue, uint32_t *flags, - uint32_t max_buffers, uint32_t *num_buffers, struct dspqueue_buffer *buffers, - uint32_t max_message_length, uint32_t *message_length, uint8_t *message, - uint32_t timeout_us); + uint32_t max_buffers, uint32_t *num_buffers, + struct dspqueue_buffer *buffers, + uint32_t max_message_length, uint32_t *message_length, + uint8_t *message, uint32_t timeout_us); /** * Retrieve information for the next packet if available, without reading @@ -472,9 +512,11 @@ AEEResult dspqueue_read(dspqueue_t queue, uint32_t *flags, * * @return 0 on success, error code on failure. * - AEE_EWOULDBLOCK: The queue is empty; try again later - * - AEE_EBADITEM: The queue contains a corrupted packet. Internal error. + * - AEE_EBADITEM: The queue contains a corrupted packet. Internal + * error. */ -AEEResult dspqueue_peek_noblock(dspqueue_t queue, uint32_t *flags, uint32_t *num_buffers, +AEEResult dspqueue_peek_noblock(dspqueue_t queue, uint32_t *flags, + uint32_t *num_buffers, uint32_t *message_length); /** @@ -489,18 +531,19 @@ AEEResult dspqueue_peek_noblock(dspqueue_t queue, uint32_t *flags, uint32_t *num * @param [out] flags Packet flags. See enum #dspqueue_packet_flags * @param [out] num_buffers Number of buffer references in packet * @param [out] message_length Packet message length in bytes - * @param [out] timeout_us Timeout in microseconds; use DSPQUEUE_TIMEOUT_NONE to - * block indefinitely until a packet is available or - * zero for non-blocking behavior. + * @param [out] timeout_us Timeout in microseconds; use DSPQUEUE_TIMEOUT_NONE + * to block indefinitely until a packet is available or zero for non-blocking + * behavior. * * @return 0 on success, error code on failure. * - AEE_EEXPIRED: Request timed out * - AEE_EINTERRUPTED: The request was canceled - * - AEE_EBADITEM: The queue contains a corrupted packet. Internal error. + * - AEE_EBADITEM: The queue contains a corrupted packet. Internal + * error. */ -AEEResult dspqueue_peek(dspqueue_t queue, uint32_t *flags, uint32_t *num_buffers, - uint32_t *message_length, uint32_t timeout_us); - +AEEResult dspqueue_peek(dspqueue_t queue, uint32_t *flags, + uint32_t *num_buffers, uint32_t *message_length, + uint32_t timeout_us); /** * Write an early wakeup packet to the queue. Early wakeup packets are used @@ -516,19 +559,19 @@ AEEResult dspqueue_peek(dspqueue_t queue, uint32_t *flags, uint32_t *num_buffers * is done on all the domains that the queue was created on. * * @param [in] queue Queue handle from dspqueue_create() or dspqueue_import() - * @param [in] wakeup_delay Wakeup time in microseconds; this indicates how soon - * the real message packet should be available. Zero if not known. - * The recipient can use this information to determine how to - * wait for the packet. + * @param [in] wakeup_delay Wakeup time in microseconds; this indicates how + * soon the real message packet should be available. Zero if not known. The + * recipient can use this information to determine how to wait for the packet. * @param [in] packet_flags Flags for the upcoming packet if known. - * The recipient can use this information to determine how to - * wait for the packet. See enum #dspqueue_packet_flags + * The recipient can use this information to determine how + * to wait for the packet. See enum #dspqueue_packet_flags * * @return 0 on success, error code on failure. * - AEE_EWOULDBLOCK: The queue is full */ -AEEResult dspqueue_write_early_wakeup_noblock(dspqueue_t queue, uint32_t wakeup_delay, uint32_t packet_flags); - +AEEResult dspqueue_write_early_wakeup_noblock(dspqueue_t queue, + uint32_t wakeup_delay, + uint32_t packet_flags); /** * Retrieve statistics from a queue. Statistics are relative to the queue @@ -547,21 +590,21 @@ AEEResult dspqueue_write_early_wakeup_noblock(dspqueue_t queue, uint32_t wakeup_ * * @param [in] queue Queue handle from dspqueue_create() or dspqueue_import() * @param [in] stat Statistic to read, see enum dspqueue_stat - * @param [out] value Statistic value. Reading a statistic will reset it to zero + * @param [out] value Statistic value. Reading a statistic will reset it to + * zero * * @return 0 on success, error code on failure. * - AEE_EBADPARM: Invalid statistic */ -AEEResult dspqueue_get_stat(dspqueue_t queue, enum dspqueue_stat stat, uint64_t *value); - +AEEResult dspqueue_get_stat(dspqueue_t queue, enum dspqueue_stat stat, + uint64_t *value); /** @} */ - #ifdef __cplusplus } #endif -#endif //DSPQUEUE_H +#endif // DSPQUEUE_H diff --git a/inc/dspqueue_rpc.h b/inc/dspqueue_rpc.h index b346b2af..39bd6b83 100644 --- a/inc/dspqueue_rpc.h +++ b/inc/dspqueue_rpc.h @@ -6,7 +6,6 @@ #include #include - #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff #endif //__QAIC_HEADER @@ -34,44 +33,57 @@ extern "C" { #endif /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(dspqueue_rpc_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; -/** + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int __QAIC_HEADER(dspqueue_rpc_open)( + const char *uri, remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; +/** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(dspqueue_rpc_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_init_process_state)(remote_handle64 _h, int32_t process_state_fd) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_create_queue)(remote_handle64 _h, uint32_t id, int32_t queue_fd, uint32_t count, uint64_t* queue_id) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_destroy_queue)(remote_handle64 _h, uint64_t queue_id) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_is_imported)(remote_handle64 _h, uint64_t queue_id, int32_t* imported) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_wait_signal)(remote_handle64 _h, int32_t* signal) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_cancel_wait_signal)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_signal)(remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(dspqueue_rpc_close)(remote_handle64 h) + __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_init_process_state)( + remote_handle64 _h, int32_t process_state_fd) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_create_queue)( + remote_handle64 _h, uint32_t id, int32_t queue_fd, uint32_t count, + uint64_t *queue_id) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_destroy_queue)( + remote_handle64 _h, uint64_t queue_id) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_is_imported)( + remote_handle64 _h, uint64_t queue_id, + int32_t *imported) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_wait_signal)( + remote_handle64 _h, int32_t *signal) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_cancel_wait_signal)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT AEEResult __QAIC_HEADER(dspqueue_rpc_signal)( + remote_handle64 _h) __QAIC_HEADER_ATTRIBUTE; #ifndef dspqueue_rpc_URI -#define dspqueue_rpc_URI "file:///libdspqueue_rpc_skel.so?dspqueue_rpc_skel_handle_invoke&_modver=1.0" +#define dspqueue_rpc_URI \ + "file:///" \ + "libdspqueue_rpc_skel.so?dspqueue_rpc_skel_handle_invoke&_modver=1.0" #endif /*dspqueue_rpc_URI*/ #ifdef __cplusplus } diff --git a/inc/dspqueue_shared.h b/inc/dspqueue_shared.h index 958f3420..81124853 100644 --- a/inc/dspqueue_shared.h +++ b/inc/dspqueue_shared.h @@ -4,57 +4,68 @@ #ifndef DSPQUEUE_SHARED_H #define DSPQUEUE_SHARED_H -#include -#include #include "dspqueue.h" +#include +#include /* Shared memory queue definitions. - Each queue is allocated as a single shared ION buffer. The buffer consists of: + Each queue is allocated as a single shared ION buffer. The buffer consists + of: * struct dspqueue_header - - request packet queue header. Used for messages from the host CPU to the DSP. - - response packet queue header. Used for messages from the DSP to the host CPU. + - request packet queue header. Used for messages from the host CPU to the + DSP. + - response packet queue header. Used for messages from the DSP to the host + CPU. * read/write states for each packet queue, including read/write pointers. Each read/write state structure must be on a separate cache line. * Request and response packet queues - Packet queues are circular buffers consisting packet headers and data - Packets are padded to be 64-bit aligned - The reader and writer manage read and write positions - - Packets do not wrap around at the end of the queue. If a packet cannot fit before the end - of the queue, the entire packet is written at the beginning. The 64-bit header is replicated. + - Packets do not wrap around at the end of the queue. If a packet cannot + fit before the end of the queue, the entire packet is written at the + beginning. The 64-bit header is replicated. */ - /* Header structure for each one-way packet queue. - All offsets are in bytes to the beginning of the shared memory queue block. */ + All offsets are in bytes to the beginning of the shared memory queue block. + */ struct dspqueue_packet_queue_header { - uint32_t queue_offset; /* Queue offset */ - uint32_t queue_length; /* Queue length in bytes */ - uint32_t read_state_offset; /* Read state offset. Contains struct dspqueue_packet_queue_state, - describing the state of the reader of this queue. */ - uint32_t write_state_offset; /* Write state offset. Contains a struct dspqueue_packet_queue_state, - describing the state of the writer of this queue. */ + uint32_t queue_offset; /* Queue offset */ + uint32_t queue_length; /* Queue length in bytes */ + uint32_t + read_state_offset; /* Read state offset. Contains struct + dspqueue_packet_queue_state, describing the + state of the reader of this queue. */ + uint32_t + write_state_offset; /* Write state offset. Contains a struct + dspqueue_packet_queue_state, describing the + state of the writer of this queue. */ }; -/* State structure, used to describe the state of the reader or writer of each queue. - The state structure is at an offset from the start of the header as defined in - struct dspqueue_packet_queue_header above, and must fit in a single cache line. */ +/* State structure, used to describe the state of the reader or writer of each + queue. The state structure is at an offset from the start of the header as + defined in struct dspqueue_packet_queue_header above, and must fit in a + single cache line. */ struct dspqueue_packet_queue_state { - volatile uint32_t position; /* Position within the queue in bytes */ - volatile uint32_t packet_count; /* Number of packets read/written */ - volatile uint32_t wait_count; /* Non-zero if the reader/writer is waiting for a signal - for a new packet or more space in the queue respectively */ + volatile uint32_t position; /* Position within the queue in bytes */ + volatile uint32_t packet_count; /* Number of packets read/written */ + volatile uint32_t + wait_count; /* Non-zero if the reader/writer is waiting for a + signal for a new packet or more space in the queue + respectively */ }; - /* Userspace shared memory queue header */ struct dspqueue_header { - uint32_t version; /* Initial version 1, 2 if any flags are set and need to be checked. */ - int32_t error; - uint32_t flags; - struct dspqueue_packet_queue_header req_queue; /* CPU to DSP */ - struct dspqueue_packet_queue_header resp_queue; /* DSP to CPU */ - uint32_t queue_count; + uint32_t version; /* Initial version 1, 2 if any flags are set and need + to be checked. */ + int32_t error; + uint32_t flags; + struct dspqueue_packet_queue_header req_queue; /* CPU to DSP */ + struct dspqueue_packet_queue_header resp_queue; /* DSP to CPU */ + uint32_t queue_count; }; /* The version number currently expected if both CPU and DSP sides match */ @@ -69,8 +80,9 @@ struct dspqueue_header { #define DSPQUEUE_HEADER_FLAG_DRIVER_SIGNALING 2 /* Unexpected flags */ -#define DSPQUEUE_HEADER_UNEXPECTED_FLAGS ~(DSPQUEUE_HEADER_FLAG_WAIT_COUNTS | DSPQUEUE_HEADER_FLAG_DRIVER_SIGNALING) - +#define DSPQUEUE_HEADER_UNEXPECTED_FLAGS \ + ~(DSPQUEUE_HEADER_FLAG_WAIT_COUNTS \ + | DSPQUEUE_HEADER_FLAG_DRIVER_SIGNALING) /* Maximum queue size in bytes */ #define DSPQUEUE_MAX_QUEUE_SIZE 16777216 @@ -85,12 +97,10 @@ struct dspqueue_header { #define DSPQUEUE_DEFAULT_REQ_SIZE 65536 #define DSPQUEUE_DEFAULT_RESP_SIZE 16384 - -/* Maximum number of queues per process. Must ensure the state arrays get cache line aligned. - Update signal allocations in dspsignal.h if this changes. */ +/* Maximum number of queues per process. Must ensure the state arrays get cache + line aligned. Update signal allocations in dspsignal.h if this changes. */ #define DSPQUEUE_MAX_PROCESS_QUEUES 64 - /* Process queue information block, used with RPC-based signaling. Each participant increments the packet/space count for the @@ -102,10 +112,10 @@ struct dspqueue_header { use argumentless FastRPC calls for signaling. */ struct dspqueue_process_queue_state { - uint32_t req_packet_count[DSPQUEUE_MAX_PROCESS_QUEUES]; - uint32_t req_space_count[DSPQUEUE_MAX_PROCESS_QUEUES]; - uint32_t resp_packet_count[DSPQUEUE_MAX_PROCESS_QUEUES]; - uint32_t resp_space_count[DSPQUEUE_MAX_PROCESS_QUEUES]; + uint32_t req_packet_count[DSPQUEUE_MAX_PROCESS_QUEUES]; + uint32_t req_space_count[DSPQUEUE_MAX_PROCESS_QUEUES]; + uint32_t resp_packet_count[DSPQUEUE_MAX_PROCESS_QUEUES]; + uint32_t resp_space_count[DSPQUEUE_MAX_PROCESS_QUEUES]; }; /* Info specific to multi-domain queues */ @@ -129,15 +139,14 @@ struct dspqueue_multidomain { uint64_t *dsp_ids; }; -/* Signals IDs used with driver signaling. Update the signal allocations in dspsignal.h - if this changes. */ +/* Signals IDs used with driver signaling. Update the signal allocations in + dspsignal.h if this changes. */ enum dspqueue_signal { - DSPQUEUE_SIGNAL_REQ_PACKET = 0, - DSPQUEUE_SIGNAL_REQ_SPACE, - DSPQUEUE_SIGNAL_RESP_PACKET, - DSPQUEUE_SIGNAL_RESP_SPACE, - DSPQUEUE_NUM_SIGNALS + DSPQUEUE_SIGNAL_REQ_PACKET = 0, + DSPQUEUE_SIGNAL_REQ_SPACE, + DSPQUEUE_SIGNAL_RESP_PACKET, + DSPQUEUE_SIGNAL_RESP_SPACE, + DSPQUEUE_NUM_SIGNALS }; - #endif diff --git a/inc/dspsignal.h b/inc/dspsignal.h index ccbb9276..f38193e1 100644 --- a/inc/dspsignal.h +++ b/inc/dspsignal.h @@ -4,7 +4,6 @@ #ifndef DSPSIGNAL_H #define DSPSIGNAL_H - /** @file Internal FastRPC CPU-DSP signaling API. @@ -63,10 +62,9 @@ signals can only be used in FastRPC user PDs. */ -#include -#include #include - +#include +#include /** Infinite timeout */ #define DSPSIGNAL_TIMEOUT_NONE UINT32_MAX @@ -80,16 +78,14 @@ */ #define DSPSIGNAL_DSPQUEUE_MIN 0 #define DSPSIGNAL_DSPQUEUE_MAX 255 -#define DSPSIGNAL_RESERVED_MIN (DSPSIGNAL_DSPQUEUE_MAX+1) +#define DSPSIGNAL_RESERVED_MIN (DSPSIGNAL_DSPQUEUE_MAX + 1) #define DSPSIGNAL_RESERVED_MAX 1023 -#define DSPSIGNAL_NUM_SIGNALS (DSPSIGNAL_RESERVED_MAX+1) - +#define DSPSIGNAL_NUM_SIGNALS (DSPSIGNAL_RESERVED_MAX + 1) #ifdef __cplusplus extern "C" { #endif - /** * Create a signal instance for use. * @@ -98,19 +94,19 @@ extern "C" { * DSPSIGNAL_DOMAIN_CPU for the main application * CPU on the DSP. * @param [in] id Signal ID. The ID must be unique within the process and - * within the range specified above (i.e. -#include #include +#include #include -#include +#include #include +#include -#include "remote.h" #include "fastrpc_common.h" +#include "remote.h" #ifdef __LE_TVM__ #define __CONSTRUCTOR_ATTRIBUTE__ @@ -29,13 +29,13 @@ * and the range for staticPD handles is <256,512> */ typedef enum { - OISPD_HANDLE = 256, - AUDIOPD_HANDLE = 257, - SENSORPD_HANDLE = 258, - ATTACHGUESTOS_HANDLE = 259, - ROOTPD_HANDLE = 260, - SECUREPD_HANDLE = 261 - } static_pd_handle; + OISPD_HANDLE = 256, + AUDIOPD_HANDLE = 257, + SENSORPD_HANDLE = 258, + ATTACHGUESTOS_HANDLE = 259, + ROOTPD_HANDLE = 260, + SECUREPD_HANDLE = 261 +} static_pd_handle; /* * API to initialize rpcmem data structures for ION allocation */ @@ -51,13 +51,13 @@ void rpcmem_deinit_internal(); * Returns NULL if allocation fails * */ -void* rpcmem_alloc_internal(int heapid, uint32_t flags, size_t size); +void *rpcmem_alloc_internal(int heapid, uint32_t flags, size_t size); /* * API to free internally allocated ION memory * */ -void rpcmem_free_internal(void* po); +void rpcmem_free_internal(void *po); /* * API to get fd of internally allocated ION buffer @@ -69,8 +69,8 @@ int rpcmem_to_fd_internal(void *po); // API to get domain from handle int get_domain_from_handle(remote_handle64 local, int *domain); - -/* fastrpc initialization function to call from global functions exported to user */ +/* fastrpc initialization function to call from global functions exported to + * user */ int __CONSTRUCTOR_ATTRIBUTE__ fastrpc_init_once(void); /* Utility function to find session opened or not for a given domain @@ -116,8 +116,8 @@ void fastrpc_session_unlock(int domain); * @returns: 0 on success, valid non-zero error code on failure * */ -int close_reverse_handle(remote_handle64 handle, char* errStr, int errStrLen, int* pdlErr); - +int close_reverse_handle(remote_handle64 handle, char *errStr, int errStrLen, + int *pdlErr); /* * API to get unsigned PD attribute for a given domain @@ -134,4 +134,4 @@ int get_unsigned_pd_attribute(uint32_t domain, int *unsigned_module); */ int is_userspace_allocation_supported(); -#endif //FASTRPC_ANDROID_USER_H +#endif // FASTRPC_ANDROID_USER_H diff --git a/inc/fastrpc_async.h b/inc/fastrpc_async.h index 76c244dd..657f6369 100644 --- a/inc/fastrpc_async.h +++ b/inc/fastrpc_async.h @@ -4,38 +4,42 @@ #ifndef FASTRPC_ASYNC_H #define FASTRPC_ASYNC_H -#include "remote64.h" #include "fastrpc_internal.h" +#include "remote64.h" -#define POS_TO_MASK(pos) ((1UL << pos) - 1) +#define POS_TO_MASK(pos) ((1UL << pos) - 1) -#define FASTRPC_ASYNC_JOB_POS 4 // Position in jobid where job starts +#define FASTRPC_ASYNC_JOB_POS 4 // Position in jobid where job starts -// Store jobs in Queue. Index of queue calculated based on hash value of job. Always needs to be 2^value +// Store jobs in Queue. Index of queue calculated based on hash value of job. +// Always needs to be 2^value #define FASTRPC_ASYNC_QUEUE_LIST_LEN 16 // Position where hash ends in jobid -#define FASTRPC_ASYNC_HASH_IDX_POS (FASTRPC_ASYNC_JOB_POS + (FASTRPC_ASYNC_QUEUE_LIST_LEN >> 2)) +#define FASTRPC_ASYNC_HASH_IDX_POS \ + (FASTRPC_ASYNC_JOB_POS + (FASTRPC_ASYNC_QUEUE_LIST_LEN >> 2)) // Position in jobid where timespec starts -#define FASTRPC_ASYNC_TIME_SPEC_POS 48 +#define FASTRPC_ASYNC_TIME_SPEC_POS 48 -#define SECONDS_PER_HOUR (3600) +#define SECONDS_PER_HOUR (3600) -#define FASTRPC_ASYNC_DOMAIN_MASK (POS_TO_MASK(FASTRPC_ASYNC_JOB_POS)) -#define FASTRPC_ASYNC_JOB_CNT_MASK (POS_TO_MASK(FASTRPC_ASYNC_TIME_SPEC_POS) & ~FASTRPC_ASYNC_DOMAIN_MASK) -#define FASTRPC_ASYNC_HASH_MASK (POS_TO_MASK(FASTRPC_ASYNC_HASH_IDX_POS) & ~FASTRPC_ASYNC_DOMAIN_MASK) +#define FASTRPC_ASYNC_DOMAIN_MASK (POS_TO_MASK(FASTRPC_ASYNC_JOB_POS)) +#define FASTRPC_ASYNC_JOB_CNT_MASK \ + (POS_TO_MASK(FASTRPC_ASYNC_TIME_SPEC_POS) & ~FASTRPC_ASYNC_DOMAIN_MASK) +#define FASTRPC_ASYNC_HASH_MASK \ + (POS_TO_MASK(FASTRPC_ASYNC_HASH_IDX_POS) & ~FASTRPC_ASYNC_DOMAIN_MASK) // Async job structure struct fastrpc_async_job { uint32_t isasyncjob; // set if async job /* - * Fastrpc async job ID bit-map: - * - * bits 0-3 : domain ID - * bits 4-47 : job counter - * bits 48-63 : timespec - */ + * Fastrpc async job ID bit-map: + * + * bits 0-3 : domain ID + * bits 4-47 : job counter + * bits 48-63 : timespec + */ fastrpc_async_jobid jobid; uint32_t reserved; // reserved }; @@ -48,7 +52,8 @@ struct fastrpc_async_job { * returns 0 on success * */ -int fastrpc_save_async_job(int domain, struct fastrpc_async_job *asyncjob, fastrpc_async_descriptor_t *desc); +int fastrpc_save_async_job(int domain, struct fastrpc_async_job *asyncjob, + fastrpc_async_descriptor_t *desc); /* * Internal function to remove async job, if async invocation to DSP fails diff --git a/inc/fastrpc_cap.h b/inc/fastrpc_cap.h index 360a2530..57794bae 100644 --- a/inc/fastrpc_cap.h +++ b/inc/fastrpc_cap.h @@ -8,32 +8,34 @@ #define STATUS_NOTIF_V2 3 /** - * @brief reads specific capability from DSP/Kernel and returns - * attributeID - specifies which capability is of interest - * domain - specific domain ID (DSP or the session running on DSP) - * capability - integer return value. in case of boolean - 0/1 is returned. - **/ -int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, uint32_t *capability); + * @brief reads specific capability from DSP/Kernel and returns + * attributeID - specifies which capability is of interest + * domain - specific domain ID (DSP or the session running on DSP) + * capability - integer return value. in case of boolean - 0/1 is returned. + **/ +int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, + uint32_t *capability); /** - * @brief Checks whether DMA reverse RPC capability is supported - * by DSP. - **/ + * @brief Checks whether DMA reverse RPC capability is supported + * by DSP. + **/ uint32_t get_dsp_dma_reverse_rpc_map_capability(int domain); /** - * @brief Checks kernel if error codes returned are latest to the user - **/ + * @brief Checks kernel if error codes returned are latest to the user + **/ int check_error_code_change_present(void); /** - * @brief Lastest version of status notification features is enabled - **/ + * @brief Lastest version of status notification features is enabled + **/ int is_status_notif_version2_supported(int domain); /** - * @brief Checks if user space DMA allocation is supported - **/ + * @brief Checks if user space DMA allocation is supported + **/ int is_userspace_allocation_supported(void); /** - * @brief API to check if DSP process supports the configuration buffer (procbuf) - **/ + * @brief API to check if DSP process supports the configuration buffer + *(procbuf) + **/ int is_proc_sharedbuf_supported_dsp(int domain); #endif /*__FASTRPC_CAP_H__*/ diff --git a/inc/fastrpc_common.h b/inc/fastrpc_common.h index 1d52afec..65083d3f 100644 --- a/inc/fastrpc_common.h +++ b/inc/fastrpc_common.h @@ -4,20 +4,19 @@ #ifndef FASTRPC_COMMON_H #define FASTRPC_COMMON_H +#include #include #include -#include -#include #include +#include /* Header file used by all other modules * will contain the most critical defines - * and APIs. ****** SHOULD NOT ****** be used for - * hlist/any domain specific fastrpc_apps_user.c + * and APIs. ****** SHOULD NOT ****** be used for + * hlist/any domain specific fastrpc_apps_user.c * symbols here. */ - /* Number of subsystem supported by fastRPC*/ #ifndef NUM_DOMAINS #define NUM_DOMAINS 8 @@ -37,7 +36,7 @@ /* Macros for invalids/defaults*/ #define INVALID_DOMAIN_ID -1 #define INVALID_HANDLE (remote_handle64)(-1) -#define INVALID_KEY (pthread_key_t)(-1) +#define INVALID_KEY (pthread_key_t)(-1) #define INVALID_DEVICE (-1) // Number of domains extended to include sessions @@ -46,69 +45,75 @@ #define NUM_DOMAINS_EXTEND (NUM_DOMAINS * NUM_SESSIONS) // Domain name types -#define DOMAIN_NAME_IN_URI 1 // Domain name with standard module URI +#define DOMAIN_NAME_IN_URI 1 // Domain name with standard module URI #define DOMAIN_NAME_STAND_ALONE 2 // Stand-alone domain name -#define PROFILE(time_taken, ff) \ -{ \ - struct timeval tv1, tv2; \ - if(is_systrace_enabled()){ \ - gettimeofday(&tv1, 0); \ - ff; \ - gettimeofday(&tv2, 0); \ - *time_taken = (tv2.tv_sec - tv1.tv_sec) * 1000000ULL + (tv2.tv_usec - tv1.tv_usec); \ - } else { \ - ff; \ - } \ -} - -#define PROFILE_ALWAYS(time_taken, ff) \ -{ \ - struct timeval tv1, tv2; \ - uint64_t temp1, temp2, temp3; \ - gettimeofday(&tv1, 0); \ - ff; \ - gettimeofday(&tv2, 0); \ - __builtin_sub_overflow(tv2.tv_sec, tv1.tv_sec, &temp1); \ - __builtin_sub_overflow(tv2.tv_usec, tv1.tv_usec, &temp2); \ - __builtin_mul_overflow(temp1, 1000000ULL, &temp3); \ - __builtin_add_overflow(temp2, temp3, time_taken); \ -} +#define PROFILE(time_taken, ff) \ + { \ + struct timeval tv1, tv2; \ + if(is_systrace_enabled()) { \ + gettimeofday(&tv1, 0); \ + ff; \ + gettimeofday(&tv2, 0); \ + *time_taken = (tv2.tv_sec - tv1.tv_sec) * 1000000ULL \ + + (tv2.tv_usec - tv1.tv_usec); \ + } else { \ + ff; \ + } \ + } + +#define PROFILE_ALWAYS(time_taken, ff) \ + { \ + struct timeval tv1, tv2; \ + uint64_t temp1, temp2, temp3; \ + gettimeofday(&tv1, 0); \ + ff; \ + gettimeofday(&tv2, 0); \ + __builtin_sub_overflow(tv2.tv_sec, tv1.tv_sec, &temp1); \ + __builtin_sub_overflow(tv2.tv_usec, tv1.tv_usec, &temp2); \ + __builtin_mul_overflow(temp1, 1000000ULL, &temp3); \ + __builtin_add_overflow(temp2, temp3, time_taken); \ + } /* Macros to check if the remote call is from static module */ #define FASTRPC_STATIC_HANDLE_LISTENER (3) #define FASTRPC_MAX_STATIC_HANDLE (10) -#define REVERSE_RPC_SCALAR 0x04020200 // corresponding to next2() method -#define IS_STATIC_HANDLE(handle) ((handle) >= 0 && (handle) <= FASTRPC_MAX_STATIC_HANDLE) -#define IS_REVERSE_RPC_CALL(handle, sc) ((handle == FASTRPC_STATIC_HANDLE_LISTENER) && (sc == REVERSE_RPC_SCALAR)) - -//number of times to retry write operation +#define REVERSE_RPC_SCALAR 0x04020200 // corresponding to next2() method +#define IS_STATIC_HANDLE(handle) \ + ((handle) >= 0 && (handle) <= FASTRPC_MAX_STATIC_HANDLE) +#define IS_REVERSE_RPC_CALL(handle, sc) \ + ((handle == FASTRPC_STATIC_HANDLE_LISTENER) \ + && (sc == REVERSE_RPC_SCALAR)) + +// number of times to retry write operation #define RETRY_WRITE (3) // Macro to increment a reference count for the active domain -#define FASTRPC_GET_REF(domain) VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_get(domain))); \ - ref = 1; +#define FASTRPC_GET_REF(domain) \ + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_get(domain))); \ + ref = 1; // Macro to decrement a reference count after the remote call is complete -#define FASTRPC_PUT_REF(domain) if(ref == 1) { \ - fastrpc_session_put(domain); \ - ref = 0; \ - } +#define FASTRPC_PUT_REF(domain) \ + if(ref == 1) { \ + fastrpc_session_put(domain); \ + ref = 0; \ + } /** - * @brief Process types on remote subsystem - * Always add new PD types at the end, before MAX_PD_TYPE, - * for maintaining back ward compatibility + * @brief Process types on remote subsystem + * Always add new PD types at the end, before MAX_PD_TYPE, + * for maintaining back ward compatibility **/ -#define DEFAULT_UNUSED 0 /* pd type not configured for context banks */ -#define ROOT_PD 1 /* Root PD */ -#define AUDIO_STATICPD 2 /* ADSP Audio Static PD */ -#define SENSORS_STATICPD 3 /* ADSP Sensors Static PD */ -#define SECURE_STATICPD 4 /* CDSP Secure Static PD */ -#define OIS_STATICPD 5 /* ADSP OIS Static PD */ -#define CPZ_USERPD 6 /* CDSP CPZ USER PD */ -#define USERPD 7 /* DSP User Dynamic PD */ -#define GUEST_OS_SHARED 8 /* Legacy Guest OS Shared */ -#define MAX_PD_TYPE 9 /* Max PD type */ +#define DEFAULT_UNUSED 0 /* pd type not configured for context banks */ +#define ROOT_PD 1 /* Root PD */ +#define AUDIO_STATICPD 2 /* ADSP Audio Static PD */ +#define SENSORS_STATICPD 3 /* ADSP Sensors Static PD */ +#define SECURE_STATICPD 4 /* CDSP Secure Static PD */ +#define OIS_STATICPD 5 /* ADSP OIS Static PD */ +#define CPZ_USERPD 6 /* CDSP CPZ USER PD */ +#define USERPD 7 /* DSP User Dynamic PD */ +#define GUEST_OS_SHARED 8 /* Legacy Guest OS Shared */ +#define MAX_PD_TYPE 9 /* Max PD type */ /* * Enum defined for fastrpc User Properties @@ -116,18 +121,20 @@ * Enum values corresponds to array indices * */ - typedef enum { - FASTRPC_PROCESS_ATTRS = 0, //to spawn a User process as Critical - FASTRPC_DEBUG_TRACE = 1, // to enable logs on remote invocation - FASTRPC_DEBUG_TESTSIG = 2, // to get process test signature - FASTRPC_PERF_KERNEL = 3, //to enable rpc perf on fastrpc kernel - FASTRPC_PERF_ADSP = 4, //to enable rpc perf on DSP - FASTRPC_PERF_FREQ = 5, //to set performance frequency - FASTRPC_ENABLE_SYSTRACE = 6, //to enable tracing using Systrace - FASTRPC_DEBUG_PDDUMP = 7, // to enable pd dump debug data collection on rooted device for signed/unsigned pd - FASTRPC_PROCESS_ATTRS_PERSISTENT = 8, // to set proc attr as persistent - FASTRPC_BUILD_TYPE = 9 // Fetch build type of firmware image. It gives the details if its debug or prod build - }fastrpc_properties; +typedef enum { + FASTRPC_PROCESS_ATTRS = 0, // to spawn a User process as Critical + FASTRPC_DEBUG_TRACE = 1, // to enable logs on remote invocation + FASTRPC_DEBUG_TESTSIG = 2, // to get process test signature + FASTRPC_PERF_KERNEL = 3, // to enable rpc perf on fastrpc kernel + FASTRPC_PERF_ADSP = 4, // to enable rpc perf on DSP + FASTRPC_PERF_FREQ = 5, // to set performance frequency + FASTRPC_ENABLE_SYSTRACE = 6, // to enable tracing using Systrace + FASTRPC_DEBUG_PDDUMP = 7, // to enable pd dump debug data collection on + // rooted device for signed/unsigned pd + FASTRPC_PROCESS_ATTRS_PERSISTENT = 8, // to set proc attr as persistent + FASTRPC_BUILD_TYPE = 9 // Fetch build type of firmware image. It gives + // the details if its debug or prod build +} fastrpc_properties; /** * @enum fastrpc_internal_attributes @@ -136,15 +143,22 @@ * not allowed to request these. */ enum fastrpc_internal_attributes { - PERF_V2_DSP_SUPPORT = 128, /**< Perf logging V2 DSP support */ - MAP_DMA_HANDLE_REVERSERPC = 129, /**< Map DMA handle in reverse RPC call */ - DSPSIGNAL_DSP_SUPPORT = 130, /**< New "dspsignal" signaling supported on DSP */ - PROC_SHARED_BUFFER_SUPPORT = 131, /**< sharedbuf capability support */ - PERF_V2_DRIVER_SUPPORT = 256, /**< Perf logging V2 kernel support */ - DRIVER_ERROR_CODE_CHANGE = 257, /**< Fastrpc Driver error code change */ - USERSPACE_ALLOCATION_SUPPORT = 258, /**< Userspace memory allocation support */ - DSPSIGNAL_DRIVER_SUPPORT = 259, /**< dspsignal signaling supported in CPU driver */ - FASTRPC_MAX_ATTRIBUTES = DSPSIGNAL_DRIVER_SUPPORT + 1, /**< Max DSP/Kernel attributes supported */ + PERF_V2_DSP_SUPPORT = 128, /**< Perf logging V2 DSP support */ + MAP_DMA_HANDLE_REVERSERPC + = 129, /**< Map DMA handle in reverse RPC call */ + DSPSIGNAL_DSP_SUPPORT + = 130, /**< New "dspsignal" signaling supported on DSP */ + PROC_SHARED_BUFFER_SUPPORT = 131, /**< sharedbuf capability support */ + PERF_V2_DRIVER_SUPPORT = 256, /**< Perf logging V2 kernel support */ + DRIVER_ERROR_CODE_CHANGE + = 257, /**< Fastrpc Driver error code change */ + USERSPACE_ALLOCATION_SUPPORT + = 258, /**< Userspace memory allocation support */ + DSPSIGNAL_DRIVER_SUPPORT + = 259, /**< dspsignal signaling supported in CPU driver */ + FASTRPC_MAX_ATTRIBUTES + = DSPSIGNAL_DRIVER_SUPPORT + + 1, /**< Max DSP/Kernel attributes supported */ }; /* Utility function to get pd type of a DSP domain @@ -153,40 +167,43 @@ enum fastrpc_internal_attributes { */ int fastrpc_get_pd_type(int domain); /** - * @brief API to initialize the global data strcutures in fastRPC library - */ + * @brief API to initialize the global data strcutures in fastRPC library + */ int fastrpc_init_once(void); /** - * @brief API to get the recently used domain from a thread context - * Uses pthread_key to associate a domain to the recently used domain - */ + * @brief API to get the recently used domain from a thread context + * Uses pthread_key to associate a domain to the recently used domain + */ int get_current_domain(void); /** - * @brief returns the file descriptor of the fastrpc device node - */ + * @brief returns the file descriptor of the fastrpc device node + */ int fastrpc_session_open(int domain, int *dev); /** - * @brief closes the remote session/file descriptor of the fastrpc device node - */ + * @brief closes the remote session/file descriptor of the fastrpc device node + */ void fastrpc_session_close(int domain, int dev); /** - * @brief increments the reference count of the domain - * used to identify whether there are any active remote calls for a specific domain - */ + * @brief increments the reference count of the domain + * used to identify whether there are any active remote calls for a specific + * domain + */ int fastrpc_session_get(int domain); /** - * @brief decrements the reference count of the domain. - * used to identify whether there are any active remote calls for a specific domain - */ + * @brief decrements the reference count of the domain. + * used to identify whether there are any active remote calls for a specific + * domain + */ int fastrpc_session_put(int domain); /** - * @brief returns the device node opened for specific domain - */ + * @brief returns the device node opened for specific domain + */ int fastrpc_session_dev(int domain, int *dev); /* * API to get User property values where value type corresponds to integer - * @UserPropertyKey: [in] Value(enum type) that corresponds to array index of User property string + * @UserPropertyKey: [in] Value(enum type) that corresponds to array index of + * User property string * @defValue: [in] default value returned when user property is not set * On user property set, returns user value. Else, returns default value * @@ -195,14 +212,16 @@ int fastrpc_get_property_int(fastrpc_properties UserPropertyKey, int defValue); /* * API to get User property values where value type corresponds to string - * @UserPropertyKey: [in] Value(enum type) that corresponds to array index of User property string + * @UserPropertyKey: [in] Value(enum type) that corresponds to array index of + * User property string * @value: [out] Pointer to the User set string * @defValue: [in] default value returned when user property is not set * returns the length of the value which will never be * greater than PROPERTY_VALUE_MAX - 1 and will always be zero terminated. * */ -int fastrpc_get_property_string(fastrpc_properties UserPropertyKey, char * value, char * defValue); +int fastrpc_get_property_string(fastrpc_properties UserPropertyKey, + char *value, char *defValue); /* * This function is used to check the current process is exiting or not. @@ -233,4 +252,4 @@ bool is_process_exiting(int domain); */ int open_device_node(int domain_id); -#endif //FASTRPC_COMMON_H +#endif // FASTRPC_COMMON_H diff --git a/inc/fastrpc_config.h b/inc/fastrpc_config.h index e7b0eb14..3cd649fc 100644 --- a/inc/fastrpc_config.h +++ b/inc/fastrpc_config.h @@ -7,207 +7,209 @@ #include "AEEstd.h" /* Maximum number of panic error codes allowed in debug config. */ -#define MAX_PANIC_ERR_CODES 32 +#define MAX_PANIC_ERR_CODES 32 /** - * @enum err_codes - * @brief stores all error codes for which panic will be raised - * , when the error happens on DSP/APSS - **/ + * @enum err_codes + * @brief stores all error codes for which panic will be raised + * , when the error happens on DSP/APSS + **/ struct err_codes { - int err_code[MAX_PANIC_ERR_CODES]; /* Panic err codes read from debug config. */ - int num_err_codes; /* Number of panic error codes read from debug config. */ + int err_code[MAX_PANIC_ERR_CODES]; /* Panic err codes read from debug + config. */ + int num_err_codes; /* Number of panic error codes read from debug + config. */ }; /** - * @file fastrpc_config - * - * fastRPC library has few configurable options that can used - * in debugging. library looks for a ".debugconfig" file in the - * DSP search path during the process start. - * Any and all debug configurations mentioned in this file is - * enabled by fastRPC. - * Note: all these debug features are enabled only on debug devices - * and not available on production devices. - * - * Debug features available are - * 1) Crash on Error codes - * 2) PD dump enablement - * 3) Remote call timeout - * 4) Kernel Perf counters - * 5) DSP Perf counters - * 6) DSP Runtime FARF - * 7) APSS Runtime FARF - * 8) DSP Memory Logging - * 9) QTF Tracing - * 10) Heap caller level - * 11) UAF checks in heap - * 12) Debug level logs - * 13) QXDM Log packet - * 14) Leak detection in Heap - * 15) Call stack - * - **/ - + * @file fastrpc_config + * + * fastRPC library has few configurable options that can used + * in debugging. library looks for a ".debugconfig" file in the + * DSP search path during the process start. + * Any and all debug configurations mentioned in this file is + * enabled by fastRPC. + * Note: all these debug features are enabled only on debug devices + * and not available on production devices. + * + * Debug features available are + * 1) Crash on Error codes + * 2) PD dump enablement + * 3) Remote call timeout + * 4) Kernel Perf counters + * 5) DSP Perf counters + * 6) DSP Runtime FARF + * 7) APSS Runtime FARF + * 8) DSP Memory Logging + * 9) QTF Tracing + * 10) Heap caller level + * 11) UAF checks in heap + * 12) Debug level logs + * 13) QXDM Log packet + * 14) Leak detection in Heap + * 15) Call stack + * + **/ /** - * fastrpc_config_get_errcodes - * - * @brief returns the list of error codes from .debugconfig - * that should induce a crash. Useful in debugging issues where - * there are errors. - * - * @param void - * @return struct error_codes - list of error codes - **/ + * fastrpc_config_get_errcodes + * + * @brief returns the list of error codes from .debugconfig + * that should induce a crash. Useful in debugging issues where + * there are errors. + * + * @param void + * @return struct error_codes - list of error codes + **/ struct err_codes *fastrpc_config_get_errcodes(void); /** - * fastrpc_config_get_rpctimeout - * - * @brief returns the timeout value configured in .debugconfig file. - * used by the remote APIs to timeout when the DSP is taking more time - * than expected. - * - * @param void - * @return integer - timeout value - **/ + * fastrpc_config_get_rpctimeout + * + * @brief returns the timeout value configured in .debugconfig file. + * used by the remote APIs to timeout when the DSP is taking more time + * than expected. + * + * @param void + * @return integer - timeout value + **/ int fastrpc_config_get_rpctimeout(void); /** - * fastrpc_config_is_pddump_enabled - * - * @brief returns whether PD dump is enabled or not. PD dumps are - * similar to coredumps in application space. dumps are useful in - * debugging issues, by loading them on gdb/lldb. - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_pddump_enabled + * + * @brief returns whether PD dump is enabled or not. PD dumps are + * similar to coredumps in application space. dumps are useful in + * debugging issues, by loading them on gdb/lldb. + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_pddump_enabled(void); /** - * fastrpc_config_is_perfkernel_enabled - * - * @brief returns whether performance counters in kernel should be - * enabled or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_perfkernel_enabled + * + * @brief returns whether performance counters in kernel should be + * enabled or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_perfkernel_enabled(void); /** - * fastrpc_config_is_perfdsp_enabled - * - * @brief returns whether performance counters in DSP should be - * enabled or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_perfdsp_enabled + * + * @brief returns whether performance counters in DSP should be + * enabled or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_perfdsp_enabled(void); /** - * fastrpc_config_get_runtime_farf_file - * - * @brief returns the name of the FARF file, where the runtime - * FARF levels are specified. These log levels are enabled - * in the user space/DSP - * - * @param void - * @return string - name of the file - **/ + * fastrpc_config_get_runtime_farf_file + * + * @brief returns the name of the FARF file, where the runtime + * FARF levels are specified. These log levels are enabled + * in the user space/DSP + * + * @param void + * @return string - name of the file + **/ char *fastrpc_config_get_runtime_farf_file(void); /** - * fastrpc_config_get_userspace_runtime_farf_file - * - * @brief returns the name of the file where runtime FARF logs are - * stored. - * - * @param void - * @return string - name of the file - **/ + * fastrpc_config_get_userspace_runtime_farf_file + * + * @brief returns the name of the file where runtime FARF logs are + * stored. + * + * @param void + * @return string - name of the file + **/ char *fastrpc_config_get_userspace_runtime_farf_file(void); /** - * fastrpc_config_is_log_iregion_enabled - * - * @brief returns whether the debug logs in memory management module - * (in DSP) should be enabled or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_log_iregion_enabled + * + * @brief returns whether the debug logs in memory management module + * (in DSP) should be enabled or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_log_iregion_enabled(void); /** - * fastrpc_config_is_debug_logging_enabled - * - * @brief returns whether DSP power (HAP_power) specific logs are enabled or not - * - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_debug_logging_enabled + * + * @brief returns whether DSP power (HAP_power) specific logs are enabled or + *not + * + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_debug_logging_enabled(void); /** - * fastrpc_config_is_sysmon_reserved_bit_enabled - * - * @brief returns whether debug logging for sysmon is enabled or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_sysmon_reserved_bit_enabled + * + * @brief returns whether debug logging for sysmon is enabled or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_sysmon_reserved_bit_enabled(void); /** - * fastrpc_config_is_qtf_tracing_enabled - * - * @brief returns whether qtf tracing is enabled or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_qtf_tracing_enabled + * + * @brief returns whether qtf tracing is enabled or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_qtf_tracing_enabled(void); // Function to get heap caller level. int fastrpc_config_get_caller_level(void); /** - * fastrpc_config_is_uaf_enabled - * - * @brief returns whether use after free check should be enabled - * in user heap (on DSP PD) or not - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_uaf_enabled + * + * @brief returns whether use after free check should be enabled + * in user heap (on DSP PD) or not + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_uaf_enabled(void); /** - * fastrpc_config_is_logpacket_enabled - * - * @brief returns whether QXDM log packet should be enabled - * QXDM log packets provide additional information on the fastRPC - * internal data structures at runtime and they are low latency - * logs. - * - * @param void - * @return bool - true/false - **/ + * fastrpc_config_is_logpacket_enabled + * + * @brief returns whether QXDM log packet should be enabled + * QXDM log packets provide additional information on the fastRPC + * internal data structures at runtime and they are low latency + * logs. + * + * @param void + * @return bool - true/false + **/ bool fastrpc_config_is_logpacket_enabled(void); /** - * fastrpc_config_get_leak_detect - * - * @brief returns whether the leak detecting feature in user heap - * (on DSP PD) is enabled or not - * - * @param void - * @return integer - 1/0 - **/ + * fastrpc_config_get_leak_detect + * + * @brief returns whether the leak detecting feature in user heap + * (on DSP PD) is enabled or not + * + * @param void + * @return integer - 1/0 + **/ int fastrpc_config_get_leak_detect(void); // Function to return the call stack num int fastrpc_config_get_caller_stack_num(void); /** - * fastrpc_config_init - * - * @brief Initialization routine to initialize the datastructures and global - * variables in this module. - * - * @param void - * @return integer - 0 for success, non-zero for error cases. - **/ + * fastrpc_config_init + * + * @brief Initialization routine to initialize the datastructures and global + * variables in this module. + * + * @param void + * @return integer - 0 for success, non-zero for error cases. + **/ int fastrpc_config_init(); /* diff --git a/inc/fastrpc_context.h b/inc/fastrpc_context.h index 381aed78..0c1e09f4 100644 --- a/inc/fastrpc_context.h +++ b/inc/fastrpc_context.h @@ -4,10 +4,10 @@ #ifndef FASTRPC_CONTEXT_H #define FASTRPC_CONTEXT_H -#include -#include #include "remote.h" #include "uthash.h" +#include +#include typedef struct fastrpc_context { /* Hash table handle */ @@ -41,7 +41,7 @@ typedef struct fastrpc_context_table { /* Flag to indicate context table init is done */ bool init; -} fastrpc_context_table; +} fastrpc_context_table; /** * Initialize the fastrpc-context table @@ -92,7 +92,7 @@ int fastrpc_destroy_context(uint64_t uctx); * * Returns 0 on success */ -int fastrpc_context_get_domains(uint64_t uctx, - unsigned int **effec_domain_ids, unsigned int *num_domain_ids); +int fastrpc_context_get_domains(uint64_t uctx, unsigned int **effec_domain_ids, + unsigned int *num_domain_ids); -#endif // FASTRPC_CONTEXT_H \ No newline at end of file +#endif // FASTRPC_CONTEXT_H diff --git a/inc/fastrpc_hash_table.h b/inc/fastrpc_hash_table.h index 3cda75c8..f4fc0427 100644 --- a/inc/fastrpc_hash_table.h +++ b/inc/fastrpc_hash_table.h @@ -7,62 +7,63 @@ #include "uthash.h" /* Add members to a struct to hash it using effective domain id */ -#define ADD_DOMAIN_HASH() \ - int domain; \ +#define ADD_DOMAIN_HASH() \ + int domain; \ UT_hash_handle hh; /* Declare hash-table struct and variable with given name */ -#define DECLARE_HASH_TABLE(name, type) \ - typedef struct { \ - type *tbl; \ - pthread_mutex_t mut; \ - } name##_table; \ +#define DECLARE_HASH_TABLE(name, type) \ + typedef struct { \ + type *tbl; \ + pthread_mutex_t mut; \ + } name##_table; \ static name##_table info; /* Initialize hash-table and associated members */ -#define HASH_TABLE_INIT(type) \ - do {\ - pthread_mutex_init(&info.mut, 0); \ +#define HASH_TABLE_INIT(type) \ + do { \ + pthread_mutex_init(&info.mut, 0); \ } while(0) /* Delete & all entries in hash-table */ -#define HASH_TABLE_CLEANUP(type) \ - do { \ - type *me = NULL, *tmp = NULL; \ - \ - pthread_mutex_lock(&info.mut); \ - HASH_ITER(hh, info.tbl, me, tmp) { \ - HASH_DEL(info.tbl, me); \ - free(me); \ - } \ - pthread_mutex_unlock(&info.mut); \ - pthread_mutex_destroy(&info.mut); \ +#define HASH_TABLE_CLEANUP(type) \ + do { \ + type *me = NULL, *tmp = NULL; \ + \ + pthread_mutex_lock(&info.mut); \ + HASH_ITER(hh, info.tbl, me, tmp) \ + { \ + HASH_DEL(info.tbl, me); \ + free(me); \ + } \ + pthread_mutex_unlock(&info.mut); \ + pthread_mutex_destroy(&info.mut); \ } while(0) /* Declare a function to get hash-node of given type */ -#define GET_HASH_NODE(type, domain, me) \ - do {\ - pthread_mutex_lock(&info.mut); \ - HASH_FIND_INT(info.tbl, &domain, me); \ - pthread_mutex_unlock(&info.mut); \ +#define GET_HASH_NODE(type, domain, me) \ + do { \ + pthread_mutex_lock(&info.mut); \ + HASH_FIND_INT(info.tbl, &domain, me); \ + pthread_mutex_unlock(&info.mut); \ } while(0) /* Allocate new node of given type, set key and add to table */ -#define ALLOC_AND_ADD_NEW_NODE_TO_TABLE(type, domain, me) \ - do { \ - pthread_mutex_lock(&info.mut); \ - HASH_FIND_INT(info.tbl, &domain, me); \ - if (!me) { \ - me = (type *)calloc(1, sizeof(type)); \ - if (!me) { \ - pthread_mutex_unlock(&info.mut); \ - nErr = AEE_ENOMEMORY; \ - goto bail; \ - } \ - me->domain = domain; \ - HASH_ADD_INT(info.tbl, domain, me); \ - } \ - pthread_mutex_unlock(&info.mut); \ +#define ALLOC_AND_ADD_NEW_NODE_TO_TABLE(type, domain, me) \ + do { \ + pthread_mutex_lock(&info.mut); \ + HASH_FIND_INT(info.tbl, &domain, me); \ + if(!me) { \ + me = (type *)calloc(1, sizeof(type)); \ + if(!me) { \ + pthread_mutex_unlock(&info.mut); \ + nErr = AEE_ENOMEMORY; \ + goto bail; \ + } \ + me->domain = domain; \ + HASH_ADD_INT(info.tbl, domain, me); \ + } \ + pthread_mutex_unlock(&info.mut); \ } while(0) #endif // FASTRPC_HASH_TABLE_H diff --git a/inc/fastrpc_internal.h b/inc/fastrpc_internal.h index 859bfe8c..4db47391 100644 --- a/inc/fastrpc_internal.h +++ b/inc/fastrpc_internal.h @@ -5,37 +5,39 @@ #define FASTRPC_INTERNAL_H #include -#include #include +#include -#include "HAP_farf.h" -#include "AEEStdErr.h" -#include "remote64.h" -#include "verify.h" -#include "AEEstd.h" #include "AEEQList.h" #include "AEEStdErr.h" -#include "fastrpc_latency.h" +#include "AEEstd.h" +#include "HAP_farf.h" #include "fastrpc_common.h" +#include "fastrpc_latency.h" +#include "remote64.h" +#include "verify.h" // Aligns the memory -#define ALIGN_B(p, a) (((p) + ((a) - 1)) & ~((a) - 1)) +#define ALIGN_B(p, a) (((p) + ((a) - 1)) & ~((a) - 1)) -#define FASTRPC_SESSION_ID1 (4) +#define FASTRPC_SESSION_ID1 (4) // URI string to choose Session 1. #define FASTRPC_SESSION1_URI "&_session=1" -// URI string to choose a particular session. Session ID needs to be appended to Session uri. +// URI string to choose a particular session. Session ID needs to be appended +// to Session uri. #define FASTRPC_SESSION_URI "&_session=" // URI string of Domain. Domain name needs to be appended to domain URI. #define FASTRPC_DOMAIN_URI "&_dom=" /* Additional URI length required to add domain and session information to URI - * Two extra characters for session ID > 9 and domain name more than 4 characters. + * Two extra characters for session ID > 9 and domain name more than 4 + * characters. */ -#define FASTRPC_URI_BUF_LEN (strlen(CDSP1_DOMAIN) + strlen(FASTRPC_SESSION1_URI) + 2) +#define FASTRPC_URI_BUF_LEN \ + (strlen(CDSP1_DOMAIN) + strlen(FASTRPC_SESSION1_URI) + 2) /** * Maximum values of enums exposed in remote @@ -56,38 +58,45 @@ #define FASTRPC_MAP_MAX FASTRPC_MAP_FD_NOMAP + 1 #if !(defined __qdsp6__) && !(defined __hexagon__) -static __inline uint32_t Q6_R_cl0_R(uint32_t num) { - int ii; - for(ii = 31; ii >= 0; --ii) { - if(num & (1 << ii)) { - return 31 - ii; - } - } - return 0; +static __inline uint32_t +Q6_R_cl0_R(uint32_t num) +{ + int ii; + for(ii = 31; ii >= 0; --ii) { + if(num & (1 << ii)) { + return 31 - ii; + } + } + return 0; } #else #include "hexagon_protos.h" #include #endif -#define FASTRPC_INFO_SMMU (1 << 0) +#define FASTRPC_INFO_SMMU (1 << 0) -#define GET_SESSION_ID_FROM_DOMAIN_ID(domain_id) ((int)(domain_id / NUM_DOMAINS)) +#define GET_SESSION_ID_FROM_DOMAIN_ID(domain_id) \ + ((int)(domain_id / NUM_DOMAINS)) /* From actual domain ID (0-3) and session ID, get effective domain ID */ -#define GET_EFFECTIVE_DOMAIN_ID(domain, session) (domain + (NUM_DOMAINS * session)) +#define GET_EFFECTIVE_DOMAIN_ID(domain, session) \ + (domain + (NUM_DOMAINS * session)) /* From effective domain ID, get actual domain ID */ -#define GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(effec_dom_id) (effec_dom_id & DOMAIN_ID_MASK) +#define GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(effec_dom_id) \ + (effec_dom_id & DOMAIN_ID_MASK) /* Check if given domain ID is in valid range */ #define IS_VALID_DOMAIN_ID(domain) ((domain >= 0) && (domain < NUM_DOMAINS)) /* Check if given effective domain ID is in valid range */ -#define IS_VALID_EFFECTIVE_DOMAIN_ID(domain) ((domain >= 0) && (domain < NUM_DOMAINS_EXTEND)) +#define IS_VALID_EFFECTIVE_DOMAIN_ID(domain) \ + ((domain >= 0) && (domain < NUM_DOMAINS_EXTEND)) /* Check if given effective domain ID is in extended range */ -#define IS_EXTENDED_DOMAIN_ID(domain) ((domain >= NUM_DOMAINS) && (domain < NUM_DOMAINS_EXTEND)) +#define IS_EXTENDED_DOMAIN_ID(domain) \ + ((domain >= NUM_DOMAINS) && (domain < NUM_DOMAINS_EXTEND)) /* Loop thru list of all domain ids */ #define FOR_EACH_DOMAIN_ID(i) for(i = 0; i < NUM_DOMAINS; i++) @@ -102,28 +111,28 @@ static __inline uint32_t Q6_R_cl0_R(uint32_t num) { * Create allows the DSP to create a new user PD * Create static helps to attach to the audio PD on DSP * attach sensors is used to attach to the sensors PD running on DSP -**/ -#define FASTRPC_INIT_ATTACH 0 -#define FASTRPC_INIT_CREATE 1 -#define FASTRPC_INIT_CREATE_STATIC 2 + **/ +#define FASTRPC_INIT_ATTACH 0 +#define FASTRPC_INIT_CREATE 1 +#define FASTRPC_INIT_CREATE_STATIC 2 #define FASTRPC_INIT_ATTACH_SENSORS 3 // Attribute to specify the process is a debug process #define FASTRPC_ATTR_DEBUG_PROCESS (1) // Max length of the DSP PD name -#define MAX_DSPPD_NAMELEN 30 +#define MAX_DSPPD_NAMELEN 30 // Maximum attributes that a DSP PD can understand #ifndef FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK -#define FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK 1 +#define FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK 1 #endif /** - * @brief DSP thread specific information are stored here - * priority, stack size are client configurable. - * Internal fastRPC data structures - **/ + * @brief DSP thread specific information are stored here + * priority, stack size are client configurable. + * Internal fastRPC data structures + **/ struct fastrpc_thread_params { uint32_t thread_priority; uint32_t stack_size; @@ -133,76 +142,79 @@ struct fastrpc_thread_params { }; /** - * @brief Stores all DSP capabilities, cached once and used - * in multiple places. - * Internal fastRPC data structures - **/ + * @brief Stores all DSP capabilities, cached once and used + * in multiple places. + * Internal fastRPC data structures + **/ struct fastrpc_dsp_capabilities { - uint32_t is_cached; //! Flag if dsp attributes are cached - uint32_t dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK]; + uint32_t is_cached; //! Flag if dsp attributes are cached + uint32_t dsp_attributes[FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK]; }; /** - * @brief structure to hold fd and size of buffer shared with DSP, - * which contains inital debug parameters that needs to be passed - * during process initialization. - **/ + * @brief structure to hold fd and size of buffer shared with DSP, + * which contains inital debug parameters that needs to be passed + * during process initialization. + **/ struct fastrpc_proc_sharedbuf_info { - int buf_fd; - int buf_size; + int buf_fd; + int buf_size; }; enum { - FASTRPC_DOMAIN_STATE_CLEAN = 0, - FASTRPC_DOMAIN_STATE_INIT = 1, - FASTRPC_DOMAIN_STATE_DEINIT = 2, + FASTRPC_DOMAIN_STATE_CLEAN = 0, + FASTRPC_DOMAIN_STATE_INIT = 1, + FASTRPC_DOMAIN_STATE_DEINIT = 2, }; /** - * @brief FastRPC ioctl structure to set session related info - **/ + * @brief FastRPC ioctl structure to set session related info + **/ struct fastrpc_proc_sess_info { - uint32_t domain_id; /* Set the remote subsystem, Domain ID of the session */ - uint32_t session_id; /* Unused, Set the Session ID on remote subsystem */ - uint32_t pd_type; /* Set the process type on remote subsystem */ - uint32_t sharedcb; /* Unused, Session can share context bank with other sessions */ + uint32_t + domain_id; /* Set the remote subsystem, Domain ID of the session */ + uint32_t + session_id; /* Unused, Set the Session ID on remote subsystem */ + uint32_t pd_type; /* Set the process type on remote subsystem */ + uint32_t sharedcb; /* Unused, Session can share context bank with other + sessions */ }; /** - * @enum defined for updating non-domain and reverse handle list - **/ - typedef enum { - NON_DOMAIN_LIST_PREPEND = 0, - NON_DOMAIN_LIST_DEQUEUE = 1, - REVERSE_HANDLE_LIST_PREPEND = 2, - REVERSE_HANDLE_LIST_DEQUEUE = 3, - DOMAIN_LIST_PREPEND = 4, - DOMAIN_LIST_DEQUEUE = 5, - } handle_list_update_id; + * @enum defined for updating non-domain and reverse handle list + **/ +typedef enum { + NON_DOMAIN_LIST_PREPEND = 0, + NON_DOMAIN_LIST_DEQUEUE = 1, + REVERSE_HANDLE_LIST_PREPEND = 2, + REVERSE_HANDLE_LIST_DEQUEUE = 3, + DOMAIN_LIST_PREPEND = 4, + DOMAIN_LIST_DEQUEUE = 5, +} handle_list_update_id; /** - * @enum for remote handle control requests - **/ + * @enum for remote handle control requests + **/ enum fastrpc_control_type { - FASTRPC_CONTROL_LATENCY = 1, - FASTRPC_CONTROL_SMMU = 2, - FASTRPC_CONTROL_KALLOC = 3, - FASTRPC_CONTROL_WAKELOCK = 4, - FASTRPC_CONTROL_PM = 5, - FASTRPC_CONTROL_RPC_POLL = 7, - FASTRPC_CONTROL_ASYNC_WAKE = 8, - FASTRPC_CONTROL_NOTIF_WAKE = 9, + FASTRPC_CONTROL_LATENCY = 1, + FASTRPC_CONTROL_SMMU = 2, + FASTRPC_CONTROL_KALLOC = 3, + FASTRPC_CONTROL_WAKELOCK = 4, + FASTRPC_CONTROL_PM = 5, + FASTRPC_CONTROL_RPC_POLL = 7, + FASTRPC_CONTROL_ASYNC_WAKE = 8, + FASTRPC_CONTROL_NOTIF_WAKE = 9, }; /** - * @enum different types of remote invoke supported in fastRPC - * internal datastructures. - * INVOKE - only parameters allowed - * INVOKE_ATTRS - INVOKE + additional process attributes - * INVOKE_FD - INVOKE_ATTRS + file descriptor for each parameters - * INVOKE_CRC - INVOKE_FD + CRC checks for each params - * INVOKE_PERF - INVOKE_CRC + Performance counters from kernel and DSP - **/ + * @enum different types of remote invoke supported in fastRPC + * internal datastructures. + * INVOKE - only parameters allowed + * INVOKE_ATTRS - INVOKE + additional process attributes + * INVOKE_FD - INVOKE_ATTRS + file descriptor for each parameters + * INVOKE_CRC - INVOKE_FD + CRC checks for each params + * INVOKE_PERF - INVOKE_CRC + Performance counters from kernel and DSP + **/ enum fastrpc_invoke_type { INVOKE, INVOKE_ATTRS, @@ -212,15 +224,15 @@ enum fastrpc_invoke_type { }; /** - * @enum different types of mmap supported by fastRPC. internal datastructures. - * MMAP - maps a 32bit address on DSP - * MMAP_64 - 64bit address support - * MEM_MAP - file descriptor support - * MUNMAP - unmaps a 32bit address from DSP - * MUNMAP_64 - 64bit address support - * MEM_UNMAP - file descriptor support - * MUNMAP_FD - Unmaps a file descriptor from DSP - **/ + * @enum different types of mmap supported by fastRPC. internal datastructures. + * MMAP - maps a 32bit address on DSP + * MMAP_64 - 64bit address support + * MEM_MAP - file descriptor support + * MUNMAP - unmaps a 32bit address from DSP + * MUNMAP_64 - 64bit address support + * MEM_UNMAP - file descriptor support + * MUNMAP_FD - Unmaps a file descriptor from DSP + **/ enum fastrpc_map_type { MMAP, MUNMAP, @@ -232,26 +244,26 @@ enum fastrpc_map_type { }; /** - * @brief memory mapping and unmapping data structures used in - * mmap/munmap ioctls. internal datastructures. - * fastrpc_mem_map - used for storing memory map information - * fastrpc_mem_unmap - used while unmapping the memory from the - * local data structures. - **/ + * @brief memory mapping and unmapping data structures used in + * mmap/munmap ioctls. internal datastructures. + * fastrpc_mem_map - used for storing memory map information + * fastrpc_mem_unmap - used while unmapping the memory from the + * local data structures. + **/ struct fastrpc_mem_map { - int fd; /* ion fd */ - int offset; /* buffer offset */ - uint32_t flags; /* flags defined in enum fastrpc_map_flags */ - int attrs; /* buffer attributes used for SMMU mapping */ - uintptr_t vaddrin; /* buffer virtual address */ - size_t length; /* buffer length */ - uint64_t vaddrout; /* [out] remote virtual address */ + int fd; /* ion fd */ + int offset; /* buffer offset */ + uint32_t flags; /* flags defined in enum fastrpc_map_flags */ + int attrs; /* buffer attributes used for SMMU mapping */ + uintptr_t vaddrin; /* buffer virtual address */ + size_t length; /* buffer length */ + uint64_t vaddrout; /* [out] remote virtual address */ }; struct fastrpc_mem_unmap { - int fd; /* ion fd */ - uint64_t vaddr; /* remote process (dsp) virtual address */ - size_t length; /* buffer size */ + int fd; /* ion fd */ + uint64_t vaddr; /* remote process (dsp) virtual address */ + size_t length; /* buffer size */ }; struct fastrpc_map { @@ -260,32 +272,31 @@ struct fastrpc_map { }; /** - * @brief handle_list is the global structure used to store all information - * required for a specific domain on DSP. So, usually it is used as an array - * of domains supported by this process. for eg: if a process loading this - * library is offloading to ADSP and CDSP, the array of eight handle_list is - * created and index 0 and 3 are used to store all information about the PD. - * Contains: - * nql - list of modules loaded (stubs) in this process. - * ql - list of modules loaded (stubs) using domains in this process. - * rql - list of modules loaded (skels) in this process. - * dsppd - Type of the process that should be created on DSP (specific domain) - * dsppdname - Name of the process - * sessionname - Name of the session, if more than one process created on same DSP - * kmem_support - Stores whether kernel can allocate memory for signed process - * dev - file descriptor returned by open() - * cphandle, msghandle, lsitenerhandle, remotectlhandle, adspperfhandle - static - * handles created for the stub files loaded by fastRPC. - * procattrs - Attributes for the DSP Process. Stores information like debug process, - * trace enablement, etc. - * qos, th_params, cap_info - stores information needed for DSP process. these are - * used by remote calls whenever needed. - **/ + * @brief handle_list is the global structure used to store all information + * required for a specific domain on DSP. So, usually it is used as an array + * of domains supported by this process. for eg: if a process loading this + * library is offloading to ADSP and CDSP, the array of eight handle_list is + * created and index 0 and 3 are used to store all information about the PD. + * Contains: + * nql - list of modules loaded (stubs) in this process. + * ql - list of modules loaded (stubs) using domains in this process. + * rql - list of modules loaded (skels) in this process. + * dsppd - Type of the process that should be created on DSP (specific + *domain) dsppdname - Name of the process sessionname - Name of the session, if + *more than one process created on same DSP kmem_support - Stores whether + *kernel can allocate memory for signed process dev - file descriptor returned + *by open() cphandle, msghandle, lsitenerhandle, + *remotectlhandle, adspperfhandle - static handles created for the stub files + *loaded by fastRPC. procattrs - Attributes for the DSP Process. Stores + *information like debug process, trace enablement, etc. qos, th_params, + *cap_info - stores information needed for DSP process. these are used by + *remote calls whenever needed. + **/ struct handle_list { - QList ql; //Forward domains handles - QList nql; //Forward non-domains handles - QList rql; //Reverse handles - pthread_mutex_t lmut; + QList ql; // Forward domains handles + QList nql; // Forward non-domains handles + QList rql; // Reverse handles + pthread_mutex_t lmut; pthread_mutex_t mut; pthread_mutex_t init; uint32_t constCount; @@ -317,13 +328,15 @@ struct handle_list { struct fastrpc_dsp_capabilities cap_info; int trace_marker_fd; uint64_t jobid; - /* Capability flag to check if mapping DMA handle through reverse RPC is supported */ + /* Capability flag to check if mapping DMA handle through reverse RPC + * is supported */ int dma_handle_reverse_rpc_map_capability; /* Mutex to synchronize ASync init and deinit */ pthread_mutex_t async_init_deinit_mut; - uint32_t pd_initmem_size; /** Initial memory allocated for remote userPD */ - uint32_t refs; // Number of multi-domain handles + contexts on session - bool is_session_reserved; /** Set if session is reserved or used */ + uint32_t + pd_initmem_size; /** Initial memory allocated for remote userPD */ + uint32_t refs; // Number of multi-domain handles + contexts on session + bool is_session_reserved; /** Set if session is reserved or used */ /* buffer shared with DSP containing initial config parameters */ void *proc_sharedbuf; /* current process shared buffer address to pack process params */ @@ -331,60 +344,64 @@ struct handle_list { }; /** - * @brief API to get the DSP_SEARCH_PATH stored locally as static. - * @get_path : get_path will be updated with the path stored in DSP_SEARCH_PATH locally. - **/ -void get_default_dsp_search_path(char* path); + * @brief API to get the DSP_SEARCH_PATH stored locally as static. + * @get_path : get_path will be updated with the path stored in DSP_SEARCH_PATH + *locally. + **/ +void get_default_dsp_search_path(char *path); /** - * @brief API to map memory to the remote domain - * @ fd: fd associated with this memory - * @ flags: flags to be used for the mapping - * @ vaddrin: input address - * @ size: size of buffer - * @ vaddrout: output address - * returns 0 on success - * - **/ -int remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, int64_t size, uint64_t* vaddrout); + * @brief API to map memory to the remote domain + * @ fd: fd associated with this memory + * @ flags: flags to be used for the mapping + * @ vaddrin: input address + * @ size: size of buffer + * @ vaddrout: output address + * returns 0 on success + * + **/ +int remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, + int64_t size, uint64_t *vaddrout); /** * @brief remote_get_info API to get DSP/Kernel capibility * * @param[in] domain: DSP domain - * @param[in] attributeID: One of the DSP/kernel attributes from enum fastrpc_internal_attributes. + * @param[in] attributeID: One of the DSP/kernel attributes from enum + *fastrpc_internal_attributes. * @param[out] capability: Result of the DSP/kernel capability. * @return Integer value. Zero for success and non-zero for failure. **/ -int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, uint32_t *capability); +int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, + uint32_t *capability); /** - * @brief Check whether error is because of fastrpc. - * Either kernel driver or dsp. - * @err: error code to be checked. - * returns 0 on success i.e. rpc error. - * - **/ + * @brief Check whether error is because of fastrpc. + * Either kernel driver or dsp. + * @err: error code to be checked. + * returns 0 on success i.e. rpc error. + * + **/ int check_rpc_error(int err); /** - * @brief Notify the FastRPC QoS logic of activity outside of the invoke code path - * that should still be considered in QoS timeout calculations. - * Note that the function will silently fail on errors such as the domain - * not having a valid QoS mode. - * - * @param[in] domain DSP domain - **/ + * @brief Notify the FastRPC QoS logic of activity outside of the invoke code + *path that should still be considered in QoS timeout calculations. Note that + *the function will silently fail on errors such as the domain not having a + *valid QoS mode. + * + * @param[in] domain DSP domain + **/ void fastrpc_qos_activity(int domain); /** - * @brief Make IOCTL call to exit async thread - */ + * @brief Make IOCTL call to exit async thread + */ int fastrpc_exit_async_thread(int domain); /** - * @brief Make IOCTL call to exit notif thread - */ + * @brief Make IOCTL call to exit notif thread + */ int fastrpc_exit_notif_thread(int domain); // Kernel errno start @@ -393,60 +410,67 @@ int fastrpc_exit_notif_thread(int domain); #define MAX_KERNEL_ERRNO 135 /** - * @brief Convert kernel to user error. - * @nErr: Error from ioctl - * @err_no: errno from kernel - * returns user error - **/ - -static __inline int convert_kernel_to_user_error(int nErr, int err_no) { - if (!(nErr == AEE_EUNKNOWN && err_no && (err_no >= MIN_KERNEL_ERRNO && err_no <= MAX_KERNEL_ERRNO))) { + * @brief Convert kernel to user error. + * @nErr: Error from ioctl + * @err_no: errno from kernel + * returns user error + **/ + +static __inline int +convert_kernel_to_user_error(int nErr, int err_no) +{ + if(!(nErr == AEE_EUNKNOWN && err_no + && (err_no >= MIN_KERNEL_ERRNO && err_no <= MAX_KERNEL_ERRNO))) { return nErr; } - switch (err_no) { - case EIO: /* EIO 5 I/O error */ - case ETOOMANYREFS: /* ETOOMANYREFS 109 Too many references: cannot splice */ - case EADDRNOTAVAIL: /* EADDRNOTAVAIL 99 Cannot assign requested address */ - case ENOTTY: /* ENOTTY 25 Not a typewriter */ - case EBADRQC: /* EBADRQC 56 Invalid request code */ + switch(err_no) { + case EIO: /* EIO 5 I/O error */ + case ETOOMANYREFS: /* ETOOMANYREFS 109 Too many references: cannot + splice */ + case EADDRNOTAVAIL: /* EADDRNOTAVAIL 99 Cannot assign requested address + */ + case ENOTTY: /* ENOTTY 25 Not a typewriter */ + case EBADRQC: /* EBADRQC 56 Invalid request code */ nErr = AEE_ERPC; break; - case EFAULT: /* EFAULT 14 Bad address */ - case ECHRNG: /* ECHRNG 44 Channel number out of range */ - case EBADFD: /* EBADFD 77 File descriptor in bad state */ - case EINVAL: /* EINVAL 22 Invalid argument */ - case EBADF: /* EBADF 9 Bad file number */ - case EBADE: /* EBADE 52 Invalid exchange */ - case EBADR: /* EBADR 53 Invalid request descriptor */ - case EOVERFLOW: /* EOVERFLOW 75 Value too large for defined data type */ + case EFAULT: /* EFAULT 14 Bad address */ + case ECHRNG: /* ECHRNG 44 Channel number out of range */ + case EBADFD: /* EBADFD 77 File descriptor in bad state */ + case EINVAL: /* EINVAL 22 Invalid argument */ + case EBADF: /* EBADF 9 Bad file number */ + case EBADE: /* EBADE 52 Invalid exchange */ + case EBADR: /* EBADR 53 Invalid request descriptor */ + case EOVERFLOW: /* EOVERFLOW 75 Value too large for defined data type + */ case EHOSTDOWN: /* EHOSTDOWN 112 Host is down */ - case EEXIST: /* EEXIST 17 File exists */ - case EBADMSG: /* EBADMSG 74 Not a data message */ + case EEXIST: /* EEXIST 17 File exists */ + case EBADMSG: /* EBADMSG 74 Not a data message */ nErr = AEE_EBADPARM; break; - case ENXIO: /* ENXIO 6 No such device or address */ + case ENXIO: /* ENXIO 6 No such device or address */ case ENODEV: /* ENODEV 19 No such device*/ case ENOKEY: /* ENOKEY 126 Required key not available */ nErr = AEE_ENOSUCHDEVICE; break; case ENOBUFS: /* ENOBUFS 105 No buffer space available */ - case ENOMEM: /* ENOMEM 12 Out of memory */ + case ENOMEM: /* ENOMEM 12 Out of memory */ nErr = AEE_ENOMEMORY; break; - case ENOSR: /* ENOSR 63 Out of streams resources */ - case EDQUOT: /* EDQUOT 122 Quota exceeded */ + case ENOSR: /* ENOSR 63 Out of streams resources */ + case EDQUOT: /* EDQUOT 122 Quota exceeded */ case ETIMEDOUT: /* ETIMEDOUT 110 Connection timed out */ - case EUSERS: /* EUSERS 87 Too many users */ - case ESHUTDOWN: /* ESHUTDOWN 108 Cannot send after transport endpoint shutdown */ + case EUSERS: /* EUSERS 87 Too many users */ + case ESHUTDOWN: /* ESHUTDOWN 108 Cannot send after transport endpoint + shutdown */ nErr = AEE_EEXPIRED; break; - case ENOTCONN: /* ENOTCONN 107 Transport endpoint is not connected */ + case ENOTCONN: /* ENOTCONN 107 Transport endpoint is not connected */ case ECONNREFUSED: /* ECONNREFUSED 111 Connection refused */ nErr = AEE_ECONNREFUSED; break; case ECONNRESET: /* ECONNRESET 104 Connection reset by peer */ - case EPIPE: /* EPIPE 32 Broken pipe */ + case EPIPE: /* EPIPE 32 Broken pipe */ nErr = AEE_ECONNRESET; break; case EPROTONOSUPPORT: /* EPROTONOSUPPORT 93 Protocol not supported */ @@ -456,13 +480,13 @@ static __inline int convert_kernel_to_user_error(int nErr, int err_no) { nErr = AEE_EFILE; break; case EACCES: /* EACCES 13 Permission denied */ - case EPERM: /* EPERM 1 Operation not permitted */ + case EPERM: /* EPERM 1 Operation not permitted */ nErr = AEE_EBADPERMS; break; - case ENOENT: /* No such file or directory */ - nErr = AEE_ENOSUCH; - case EBUSY: /* Device or resource busy */ - nErr = AEE_EITEMBUSY; + case ENOENT: /* No such file or directory */ + nErr = AEE_ENOSUCH; + case EBUSY: /* Device or resource busy */ + nErr = AEE_EITEMBUSY; default: nErr = AEE_ERPC; break; @@ -472,15 +496,16 @@ static __inline int convert_kernel_to_user_error(int nErr, int err_no) { } /** - * @brief utility APIs used in fastRPC library to get name, handle from domain - **/ + * @brief utility APIs used in fastRPC library to get name, handle from domain + **/ int get_domain_from_name(const char *uri, uint32_t type); int get_domain_from_handle(remote_handle64 local, int *domain); int free_handle(remote_handle64 local); /** - * @brief APIs to return the newly allocated handles for all the static modules loaded - **/ + * @brief APIs to return the newly allocated handles for all the static modules + *loaded + **/ remote_handle64 get_adsp_current_process1_handle(int domain); remote_handle64 get_adspmsgd_adsp1_handle(int domain); remote_handle64 get_adsp_listener1_handle(int domain); @@ -488,36 +513,48 @@ remote_handle64 get_remotectl1_handle(int domain); remote_handle64 get_adsp_perf1_handle(int domain); /** - * @brief API to update non-domain and reverse handles list - * @handle: handle to prepend or dequeue - * @req: request id from enum handle_list_update_id - * @domain: domain id - * Prepend and dequeue operations can be performed on reverse and non-domain handle list - * @returns: 0 on success, valid non-zero error code on failure - * - **/ -int fastrpc_update_module_list(uint32_t req, int domain, remote_handle64 handle, remote_handle64 *local, const char *name); + * @brief API to update non-domain and reverse handles list + * @handle: handle to prepend or dequeue + * @req: request id from enum handle_list_update_id + * @domain: domain id + * Prepend and dequeue operations can be performed on reverse and non-domain + *handle list + * @returns: 0 on success, valid non-zero error code on failure + * + **/ +int fastrpc_update_module_list(uint32_t req, int domain, + remote_handle64 handle, remote_handle64 *local, + const char *name); /** - * @brief functions to wrap ioctl syscalls for downstream and upstream kernel - **/ -int ioctl_init(int dev, uint32_t flags, int attr, unsigned char* shell, int shelllen, int shellfd, char* initmem, int initmemlen, int initmemfd, int tessiglen); -int ioctl_invoke(int dev, int req, remote_handle handle, uint32_t sc, void* pra, int* fds, unsigned int* attrs, void *job, unsigned int* crc, uint64_t* perf_kernel, uint64_t* perf_dsp); -int ioctl_invoke2_response(int dev, fastrpc_async_jobid *jobid, remote_handle *handle, uint32_t *sc, int* result, uint64_t *perf_kernel, uint64_t *perf_dsp); + * @brief functions to wrap ioctl syscalls for downstream and upstream kernel + **/ +int ioctl_init(int dev, uint32_t flags, int attr, unsigned char *shell, + int shelllen, int shellfd, char *initmem, int initmemlen, + int initmemfd, int tessiglen); +int ioctl_invoke(int dev, int req, remote_handle handle, uint32_t sc, + void *pra, int *fds, unsigned int *attrs, void *job, + unsigned int *crc, uint64_t *perf_kernel, uint64_t *perf_dsp); +int ioctl_invoke2_response(int dev, fastrpc_async_jobid *jobid, + remote_handle *handle, uint32_t *sc, int *result, + uint64_t *perf_kernel, uint64_t *perf_dsp); int ioctl_invoke2_notif(int dev, int *domain, int *session, int *status); -int ioctl_mmap(int dev, int req, uint32_t flags, int attr, int fd, int offset, size_t len, uintptr_t vaddrin, uint64_t* vaddr_out); -int ioctl_munmap(int dev, int req, int attr, void* buf, int fd, int len, uint64_t vaddr); +int ioctl_mmap(int dev, int req, uint32_t flags, int attr, int fd, int offset, + size_t len, uintptr_t vaddrin, uint64_t *vaddr_out); +int ioctl_munmap(int dev, int req, int attr, void *buf, int fd, int len, + uint64_t vaddr); int ioctl_getperf(int dev, int keys, void *data, int *datalen); int ioctl_getinfo(int dev, uint32_t *info); int ioctl_getdspinfo(int dev, int domain, uint32_t attr_id, uint32_t *cap); int ioctl_setmode(int dev, int mode); -int ioctl_control(int dev, int ioctltype, void* ctrl); +int ioctl_control(int dev, int ioctltype, void *ctrl); int ioctl_signal_create(int dev, uint32_t signal, uint32_t flags); int ioctl_signal_destroy(int dev, uint32_t signal); int ioctl_signal_signal(int dev, uint32_t signal); int ioctl_signal_wait(int dev, uint32_t signal, uint32_t timeout_usec); int ioctl_signal_cancel_wait(int dev, uint32_t signal); -int ioctl_sharedbuf(int dev, struct fastrpc_proc_sharedbuf_info *sharedbuf_info); +int ioctl_sharedbuf(int dev, + struct fastrpc_proc_sharedbuf_info *sharedbuf_info); int ioctl_session_info(int dev, struct fastrpc_proc_sess_info *sess_info); int ioctl_optimization(int dev, uint32_t max_concurrency); @@ -536,9 +573,10 @@ int ioctl_optimization(int dev, uint32_t max_concurrency); * returns 0 on success */ int ioctl_mdctx_manage(int dev, int req, void *user_ctx, - unsigned int *domain_ids, unsigned int num_domain_ids, uint64_t *ctx); + unsigned int *domain_ids, unsigned int num_domain_ids, + uint64_t *ctx); -const char* get_secure_domain_name(int domain_id); +const char *get_secure_domain_name(int domain_id); int is_async_fastrpc_supported(void); #include "fastrpc_ioctl.h" diff --git a/inc/fastrpc_ioctl.h b/inc/fastrpc_ioctl.h index 779d0345..7a5dbc2c 100644 --- a/inc/fastrpc_ioctl.h +++ b/inc/fastrpc_ioctl.h @@ -4,27 +4,30 @@ #ifndef FASTRPC_INTERNAL_UPSTREAM_H #define FASTRPC_INTERNAL_UPSTREAM_H -#include #include +#include /* File only compiled when support to upstream kernel is required*/ - /** * FastRPC IOCTL functions **/ -#define FASTRPC_IOCTL_ALLOC_DMA_BUFF _IOWR('R', 1, struct fastrpc_ioctl_alloc_dma_buf) -#define FASTRPC_IOCTL_FREE_DMA_BUFF _IOWR('R', 2, __u32) -#define FASTRPC_IOCTL_INVOKE _IOWR('R', 3, struct fastrpc_ioctl_invoke) -#define FASTRPC_IOCTL_INIT_ATTACH _IO('R', 4) -#define FASTRPC_IOCTL_INIT_CREATE _IOWR('R', 5, struct fastrpc_ioctl_init_create) -#define FASTRPC_IOCTL_MMAP _IOWR('R', 6, struct fastrpc_ioctl_req_mmap) -#define FASTRPC_IOCTL_MUNMAP _IOWR('R', 7, struct fastrpc_ioctl_req_munmap) -#define FASTRPC_IOCTL_INIT_ATTACH_SNS _IO('R', 8) -#define FASTRPC_IOCTL_INIT_CREATE_STATIC _IOWR('R', 9, struct fastrpc_ioctl_init_create_static) -#define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_ioctl_mem_map) -#define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_ioctl_mem_unmap) -#define FASTRPC_IOCTL_GET_DSP_INFO _IOWR('R', 13, struct fastrpc_ioctl_capability) +#define FASTRPC_IOCTL_ALLOC_DMA_BUFF \ + _IOWR('R', 1, struct fastrpc_ioctl_alloc_dma_buf) +#define FASTRPC_IOCTL_FREE_DMA_BUFF _IOWR('R', 2, __u32) +#define FASTRPC_IOCTL_INVOKE _IOWR('R', 3, struct fastrpc_ioctl_invoke) +#define FASTRPC_IOCTL_INIT_ATTACH _IO('R', 4) +#define FASTRPC_IOCTL_INIT_CREATE \ + _IOWR('R', 5, struct fastrpc_ioctl_init_create) +#define FASTRPC_IOCTL_MMAP _IOWR('R', 6, struct fastrpc_ioctl_req_mmap) +#define FASTRPC_IOCTL_MUNMAP _IOWR('R', 7, struct fastrpc_ioctl_req_munmap) +#define FASTRPC_IOCTL_INIT_ATTACH_SNS _IO('R', 8) +#define FASTRPC_IOCTL_INIT_CREATE_STATIC \ + _IOWR('R', 9, struct fastrpc_ioctl_init_create_static) +#define FASTRPC_IOCTL_MEM_MAP _IOWR('R', 10, struct fastrpc_ioctl_mem_map) +#define FASTRPC_IOCTL_MEM_UNMAP _IOWR('R', 11, struct fastrpc_ioctl_mem_unmap) +#define FASTRPC_IOCTL_GET_DSP_INFO \ + _IOWR('R', 13, struct fastrpc_ioctl_capability) #define ADSPRPC_DEVICE "/dev/fastrpc-adsp" #define SDSPRPC_DEVICE "/dev/fastrpc-sdsp" @@ -44,67 +47,72 @@ #define FASTRPC_ATTR_NOVA (256) /* Secure and default device nodes */ -#if DEFAULT_DOMAIN_ID==ADSP_DOMAIN_ID - #define SECURE_DEVICE "/dev/fastrpc-adsp-secure" - #define DEFAULT_DEVICE "/dev/fastrpc-adsp" -#elif DEFAULT_DOMAIN_ID==MDSP_DOMAIN_ID - #define SECURE_DEVICE "/dev/fastrpc-mdsp-secure" - #define DEFAULT_DEVICE "/dev/fastrpc-mdsp" -#elif DEFAULT_DOMAIN_ID==SDSP_DOMAIN_ID - #define SECURE_DEVICE "/dev/fastrpc-sdsp-secure" - #define DEFAULT_DEVICE "/dev/fastrpc-sdsp" -#elif DEFAULT_DOMAIN_ID==CDSP_DOMAIN_ID - #define SECURE_DEVICE "/dev/fastrpc-cdsp-secure" - #define DEFAULT_DEVICE "/dev/fastrpc-cdsp" +#if DEFAULT_DOMAIN_ID == ADSP_DOMAIN_ID +#define SECURE_DEVICE "/dev/fastrpc-adsp-secure" +#define DEFAULT_DEVICE "/dev/fastrpc-adsp" +#elif DEFAULT_DOMAIN_ID == MDSP_DOMAIN_ID +#define SECURE_DEVICE "/dev/fastrpc-mdsp-secure" +#define DEFAULT_DEVICE "/dev/fastrpc-mdsp" +#elif DEFAULT_DOMAIN_ID == SDSP_DOMAIN_ID +#define SECURE_DEVICE "/dev/fastrpc-sdsp-secure" +#define DEFAULT_DEVICE "/dev/fastrpc-sdsp" +#elif DEFAULT_DOMAIN_ID == CDSP_DOMAIN_ID +#define SECURE_DEVICE "/dev/fastrpc-cdsp-secure" +#define DEFAULT_DEVICE "/dev/fastrpc-cdsp" #else - #define SECURE_DEVICE "" - #define DEFAULT_DEVICE "" +#define SECURE_DEVICE "" +#define DEFAULT_DEVICE "" #endif -#define INITIALIZE_REMOTE_ARGS(total) int *pfds = NULL; \ - unsigned *pattrs = NULL; \ - args = (struct fastrpc_invoke_args*) calloc(sizeof(*args), total); \ - if(args==NULL) { \ - goto bail; \ - } - -#define DESTROY_REMOTE_ARGS() if(args) { \ - free(args); \ - } - -#define set_args(i, pra, len, filedesc, attrs) args[i].ptr = (uint64_t)pra; \ - args[i].length = len; \ - args[i].fd = filedesc; \ - args[i].attr = attrs; - -#define set_args_ptr(i, pra) args[i].ptr = (uint64_t)pra -#define set_args_len(i, len) args[i].length = len -#define set_args_attr(i, attrs) args[i].attr = attrs -#define set_args_fd(i, filedesc) args[i].fd = filedesc -#define get_args_ptr(i) args[i].ptr -#define get_args_len(i) args[i].length -#define get_args_attr(i) args[i].attr -#define get_args_fd(i) args[i].fd -#define append_args_attr(i, attrs) args[i].attr |= attrs -#define get_args() args -#define is_upstream() 1 - -//Utility macros for reading the ioctl structure -#define NOTIF_GETDOMAIN(response) -1; -#define NOTIF_GETSESSION(response) -1; -#define NOTIF_GETSTATUS(response) -1; - -#define FASTRPC_INVOKE2_STATUS_NOTIF 2 //TODO: Temporary change (Bharath to fix) -#define FASTRPC_INVOKE2_KERNEL_OPTIMIZATIONS 1 //TODO: Temporary change (Bharath to fix) +#define INITIALIZE_REMOTE_ARGS(total) \ + int *pfds = NULL; \ + unsigned *pattrs = NULL; \ + args = (struct fastrpc_invoke_args *)calloc(sizeof(*args), total); \ + if(args == NULL) { \ + goto bail; \ + } + +#define DESTROY_REMOTE_ARGS() \ + if(args) { \ + free(args); \ + } + +#define set_args(i, pra, len, filedesc, attrs) \ + args[i].ptr = (uint64_t)pra; \ + args[i].length = len; \ + args[i].fd = filedesc; \ + args[i].attr = attrs; + +#define set_args_ptr(i, pra) args[i].ptr = (uint64_t)pra +#define set_args_len(i, len) args[i].length = len +#define set_args_attr(i, attrs) args[i].attr = attrs +#define set_args_fd(i, filedesc) args[i].fd = filedesc +#define get_args_ptr(i) args[i].ptr +#define get_args_len(i) args[i].length +#define get_args_attr(i) args[i].attr +#define get_args_fd(i) args[i].fd +#define append_args_attr(i, attrs) args[i].attr |= attrs +#define get_args() args +#define is_upstream() 1 + +// Utility macros for reading the ioctl structure +#define NOTIF_GETDOMAIN(response) -1; +#define NOTIF_GETSESSION(response) -1; +#define NOTIF_GETSTATUS(response) -1; + +#define FASTRPC_INVOKE2_STATUS_NOTIF \ + 2 // TODO: Temporary change (Bharath to fix) +#define FASTRPC_INVOKE2_KERNEL_OPTIMIZATIONS \ + 1 // TODO: Temporary change (Bharath to fix) #ifndef FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK -#define FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK 1 +#define FASTRPC_MAX_DSP_ATTRIBUTES_FALLBACK 1 #endif struct fastrpc_invoke_args { - __u64 ptr; /* pointer to invoke address*/ + __u64 ptr; /* pointer to invoke address*/ __u64 length; /* size*/ - __s32 fd; /* fd */ - __u32 attr; /* invoke attributes */ + __s32 fd; /* fd */ + __u32 attr; /* invoke attributes */ }; struct fastrpc_ioctl_invoke { @@ -114,76 +122,76 @@ struct fastrpc_ioctl_invoke { }; struct fastrpc_ioctl_alloc_dma_buf { - __s32 fd; /* fd */ + __s32 fd; /* fd */ __u32 flags; /* flags to map with */ - __u64 size; /* size */ + __u64 size; /* size */ }; struct fastrpc_ioctl_init_create { - __u32 filelen; /* elf file length */ - __s32 filefd; /* fd for the file */ + __u32 filelen; /* elf file length */ + __s32 filefd; /* fd for the file */ __u32 attrs; __u32 siglen; - __u64 file; /* pointer to elf file */ + __u64 file; /* pointer to elf file */ }; struct fastrpc_ioctl_init_create_static { - __u32 namelen; /* length of pd process name */ + __u32 namelen; /* length of pd process name */ __u32 memlen; - __u64 name; /* pd process name */ + __u64 name; /* pd process name */ }; struct fastrpc_ioctl_req_mmap { __s32 fd; - __u32 flags; /* flags for dsp to map with */ - __u64 vaddrin; /* optional virtual address */ - __u64 size; /* size */ - __u64 vaddrout; /* dsp virtual address */ + __u32 flags; /* flags for dsp to map with */ + __u64 vaddrin; /* optional virtual address */ + __u64 size; /* size */ + __u64 vaddrout; /* dsp virtual address */ }; struct fastrpc_ioctl_mem_map { __s32 version; - __s32 fd; /* fd */ - __s32 offset; /* buffer offset */ - __u32 flags; /* flags defined in enum fastrpc_map_flags */ - __u64 vaddrin; /* buffer virtual address */ - __u64 length; /* buffer length */ - __u64 vaddrout; /* [out] remote virtual address */ - __s32 attrs; /* buffer attributes used for SMMU mapping */ + __s32 fd; /* fd */ + __s32 offset; /* buffer offset */ + __u32 flags; /* flags defined in enum fastrpc_map_flags */ + __u64 vaddrin; /* buffer virtual address */ + __u64 length; /* buffer length */ + __u64 vaddrout; /* [out] remote virtual address */ + __s32 attrs; /* buffer attributes used for SMMU mapping */ __s32 reserved[4]; }; struct fastrpc_ioctl_req_munmap { - __u64 vaddrout; /* address to unmap */ - __u64 size; /* size */ + __u64 vaddrout; /* address to unmap */ + __u64 size; /* size */ }; struct fastrpc_ioctl_mem_unmap { __s32 version; - __s32 fd; /* fd */ - __u64 vaddr; /* remote process (dsp) virtual address */ - __u64 length; /* buffer size */ + __s32 fd; /* fd */ + __u64 vaddr; /* remote process (dsp) virtual address */ + __u64 length; /* buffer size */ __s32 reserved[5]; }; struct fastrpc_ioctl_capability { - __u32 domain; /* domain of the PD*/ + __u32 domain; /* domain of the PD*/ __u32 attribute_id; /* attribute id*/ __u32 capability; /* dsp capability */ __u32 reserved[4]; }; /** - * @brief internal data strcutures used in remote handle control - * fastrpc_ctrl_latency - - * fastrpc_ctrl_smmu - Allows the PD to use the shared SMMU context banks - * fastrpc_ctrl_kalloc - feature to allow the kernel allocate memory - * for signed PD memory needs. - * fastrpc_ctrl_wakelock - enabled wake lock in user space and kernel - * improves the response latency time of remote calls - * fastrpc_ctrl_pm - timeout (in ms) for which the system should stay awake - * - **/ + * @brief internal data strcutures used in remote handle control + * fastrpc_ctrl_latency - + * fastrpc_ctrl_smmu - Allows the PD to use the shared SMMU context banks + * fastrpc_ctrl_kalloc - feature to allow the kernel allocate memory + * for signed PD memory needs. + * fastrpc_ctrl_wakelock - enabled wake lock in user space and kernel + * improves the response latency time of remote calls + * fastrpc_ctrl_pm - timeout (in ms) for which the system should stay awake + * + **/ struct fastrpc_ctrl_latency { uint32_t enable; uint32_t latency; diff --git a/inc/fastrpc_latency.h b/inc/fastrpc_latency.h index caee084c..8f177a26 100644 --- a/inc/fastrpc_latency.h +++ b/inc/fastrpc_latency.h @@ -19,18 +19,18 @@ /* FastRPC latency voting data for QoS handler of a session */ struct fastrpc_latency { - int adaptive_qos; - int state; //! latency thread handler running state - int exit; - int invoke; //! invoke count in tacking window - int vote; //! current pm_qos vote status - int dev; //! associated device node - int wait_time; //! wait time for review next voting - int latency; //! user requested fastrpc latency in us - pthread_t thread; - pthread_mutex_t mut; - pthread_mutex_t wmut; - pthread_cond_t cond; + int adaptive_qos; + int state; //! latency thread handler running state + int exit; + int invoke; //! invoke count in tacking window + int vote; //! current pm_qos vote status + int dev; //! associated device node + int wait_time; //! wait time for review next voting + int latency; //! user requested fastrpc latency in us + pthread_t thread; + pthread_mutex_t mut; + pthread_mutex_t wmut; + pthread_cond_t cond; }; /* Increment RPC invoke count for activity detection in a window of time diff --git a/inc/fastrpc_mem.h b/inc/fastrpc_mem.h index e4b8667c..52ec18c8 100644 --- a/inc/fastrpc_mem.h +++ b/inc/fastrpc_mem.h @@ -5,24 +5,26 @@ #define FASTRPC_MEM_H /** - * Function to initialize fastrpc_mem module. Call only once during library initialization. + * Function to initialize fastrpc_mem module. Call only once during library + * initialization. */ int fastrpc_mem_init(void); /** - * Function to deinitialize fastrpc_mem module. Call only once while closing library. + * Function to deinitialize fastrpc_mem module. Call only once while closing + * library. */ int fastrpc_mem_deinit(void); /** - * fastrpc_mem_open() initializes fastrpc_mem module data of a fastrpc session associated with domain. - * Call once during session open for a domain. + * fastrpc_mem_open() initializes fastrpc_mem module data of a fastrpc session + * associated with domain. Call once during session open for a domain. */ int fastrpc_mem_open(int domain); /** - * fastrpc_mem_close() deinitializes fastrpc_mem module data of a fastrpc session associated with domain. - * Call once during session close for a domain. + * fastrpc_mem_close() deinitializes fastrpc_mem module data of a fastrpc + * session associated with domain. Call once during session close for a domain. */ int fastrpc_mem_close(int domain); @@ -35,42 +37,49 @@ void unregister_dma_handle(int fd, uint32_t *len, uint32_t *attr); * returns a list of FDs registered by the clients. * used while making a remote call. */ -int fdlist_fd_from_buf(void* buf, int bufLen, int* nova, void** base, int* attr, int* ofd); +int fdlist_fd_from_buf(void *buf, int bufLen, int *nova, void **base, + int *attr, int *ofd); -int remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, int64_t size, uint64_t* vaddrout); +int remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, + int64_t size, uint64_t *vaddrout); /* - * Get information about an existing mapped buffer, optionally incrementing/decrementing its - * reference count. + * Get information about an existing mapped buffer, optionally + * incrementing/decrementing its reference count. * * @param domain The DSP being used * @param fd Buffer file descriptor in current process - * @param ref 1 to increment reference count, -1 to decrement it, 0 to keep refcount unchanged - * @param va Output: Pointer to buffer virtual address in current process. Set to NULL if the buffer - * doesn't have a valid accesible mapping. + * @param ref 1 to increment reference count, -1 to decrement it, 0 to keep + * refcount unchanged + * @param va Output: Pointer to buffer virtual address in current process. Set + * to NULL if the buffer doesn't have a valid accesible mapping. * @param size Output: Buffer size in bytes * * @return 0 on success, error code on failure. * - AEE_ENOSUCHMAP: Unknown FD -*/ + */ int fastrpc_buffer_ref(int domain, int fd, int ref, void **va, size_t *size); - /* - * Register or deregister a buffer with fastrpc framework, managing its reference count + * Register or deregister a buffer with fastrpc framework, managing its + reference count * and associated metadata. * * @param buf Pointer to the buffer to be registered or deregistered * @param size Size of the buffer in bytes * @param fd File descriptor associated with the buffer; use -1 to deregister - * This function internally calls `remote_register_buf_common` with default attributes. - * - If `fd` is not -1, the buffer is registered and its reference count is incremented. - * - If `fd` is -1, the buffer is deregistered and its reference count is decremented. - * If the reference count reaches zero, the buffer is unmapped and its metadata is freed. + * This function internally calls `remote_register_buf_common` with default + attributes. + * - If `fd` is not -1, the buffer is registered and its reference count is + incremented. + * - If `fd` is -1, the buffer is deregistered and its reference count is + decremented. + * If the reference count reaches zero, the buffer is unmapped and its + metadata is freed. * * @return void */ void remote_register_buf(void *buf, int size, int fd); -#endif //FASTRPC_MEM_H +#endif // FASTRPC_MEM_H diff --git a/inc/fastrpc_notif.h b/inc/fastrpc_notif.h index 174e1093..8f89baa8 100644 --- a/inc/fastrpc_notif.h +++ b/inc/fastrpc_notif.h @@ -4,8 +4,8 @@ #ifndef FASTRPC_NOTIF_H #define FASTRPC_NOTIF_H -#include "remote64.h" #include "fastrpc_internal.h" +#include "remote64.h" /* * Internal function to create fastrpc status notification thread @@ -22,7 +22,8 @@ int fastrpc_notif_domain_init(int domain); void fastrpc_notif_domain_deinit(int domain); /* - * Internal function to get notification response from kernel. Waits in kernel until notifications are received from DSP + * Internal function to get notification response from kernel. Waits in kernel + * until notifications are received from DSP * @ domain: domain to which notification needs to be received * returns 0 on success */ @@ -36,7 +37,8 @@ void fastrpc_cleanup_notif_list(); * API to register a notification mechanism for a state change in DSP Process. * state changes can be PD start, PD exit, PD crash. */ -int fastrpc_notif_register(int domain, struct remote_rpc_notif_register *notif); +int fastrpc_notif_register(int domain, + struct remote_rpc_notif_register *notif); /* * API to initialize notif module in fastRPC diff --git a/inc/fastrpc_perf.h b/inc/fastrpc_perf.h index f19379db..bef0ea70 100644 --- a/inc/fastrpc_perf.h +++ b/inc/fastrpc_perf.h @@ -19,7 +19,7 @@ * P: PERF_PUTARGS * INV: PERF_INVARGS * INVOKE: PERF_INVOKE -*/ + */ #define PERF_KERNEL_KEY_MAX (10) @@ -37,7 +37,7 @@ * R: perf_rsp * E_R: perf_early_rsp * J_S_T: perf_job_start_time -*/ + */ #define PERF_DSP_KEY_MAX (12) @@ -47,4 +47,4 @@ void fastrpc_perf_update(int dev, remote_handle handle, uint32_t sc); int fastrpc_perf_init(int dev, int domain); void fastrpc_perf_deinit(void); -#endif //FASTRPC_PERF_H +#endif // FASTRPC_PERF_H diff --git a/inc/fastrpc_pm.h b/inc/fastrpc_pm.h index f0f2c901..35ee6a25 100644 --- a/inc/fastrpc_pm.h +++ b/inc/fastrpc_pm.h @@ -5,38 +5,38 @@ #define FASTRPC_PM_H /* - fastrpc_wake_lock: + fastrpc_wake_lock: - Takes the wake-lock - Args: None - Returns: Integer - 0 on success + Takes the wake-lock + Args: None + Returns: Integer - 0 on success */ int fastrpc_wake_lock(); /* - fastrpc_wake_unlock: + fastrpc_wake_unlock: - Releases the wake-lock - Args: None - Returns: Integer - 0 on success + Releases the wake-lock + Args: None + Returns: Integer - 0 on success */ int fastrpc_wake_unlock(); /* - fastrpc_wake_lock_init: + fastrpc_wake_lock_init: - Initializes the fastrpc wakelock struct - Args: None - Returns: Integer - 0 on success + Initializes the fastrpc wakelock struct + Args: None + Returns: Integer - 0 on success */ int fastrpc_wake_lock_init(); /* - fastrpc_wake_lock_deinit: + fastrpc_wake_lock_deinit: - De-initializes the fastrpc wakelock struct - Args: None - Returns: Integer - 0 on success + De-initializes the fastrpc wakelock struct + Args: None + Returns: Integer - 0 on success */ int fastrpc_wake_lock_deinit(); -#endif //FASTRPC_PM_H +#endif // FASTRPC_PM_H diff --git a/inc/fastrpc_process_attributes.h b/inc/fastrpc_process_attributes.h index b31bf834..229faa85 100644 --- a/inc/fastrpc_process_attributes.h +++ b/inc/fastrpc_process_attributes.h @@ -16,8 +16,8 @@ /* * enum represents the unique id corresponding to hlos id. - * Do not modify the existing id. Add new ids for sending any new parameters from hlos - * and ensure that it is matching with dsp param id. + * Do not modify the existing id. Add new ids for sending any new parameters + * from hlos and ensure that it is matching with dsp param id. */ enum proc_param_id { @@ -36,7 +36,8 @@ enum proc_param_id { /* HLOS process effective domain id */ HLOS_PROC_EFFEC_DOM_ID, - /*Get list of the .so's present in the custom DSP_LIBRARY_PATH set by user*/ + /*Get list of the .so's present in the custom DSP_LIBRARY_PATH set by + user*/ CUSTOM_DSP_SEARCH_PATH_LIBS_ID, /* HLOS process session id */ diff --git a/inc/fastrpc_trace.h b/inc/fastrpc_trace.h index 0f8246b9..fc8dd781 100644 --- a/inc/fastrpc_trace.h +++ b/inc/fastrpc_trace.h @@ -4,57 +4,59 @@ #ifndef FASTRPC_TRACE_H #define FASTRPC_TRACE_H -#if ((defined _ANDROID) || (defined ANDROID)) || (defined DISABLE_ATRACE) && !defined(LE_ENABLE) -//TODO: Bharath #include "cutils/trace.h" //for systrace support +#if ((defined _ANDROID) || (defined ANDROID)) \ + || (defined DISABLE_ATRACE) && !defined(LE_ENABLE) +// TODO: Bharath #include "cutils/trace.h" //for systrace support #endif #include "HAP_farf.h" -//for systrace support +// for systrace support #ifdef ATRACE_TAG #undef ATRACE_TAG #endif -#define ATRACE_TAG (ATRACE_TAG_POWER|ATRACE_TAG_HAL) +#define ATRACE_TAG (ATRACE_TAG_POWER | ATRACE_TAG_HAL) /* trace length for ATRACE detailed ATRACE string */ #define SYSTRACE_STR_LEN 100 #if (defined(LE_ENABLE) || defined(__LE_TVM__) || defined(DISABLE_ATRACE)) -#define FASTRPC_ATRACE_BEGIN_L(fmt,...) (void)0 +#define FASTRPC_ATRACE_BEGIN_L(fmt, ...) (void)0 #define FASTRPC_ATRACE_END_L(fmt, ...) (void)0 #define FASTRPC_ATRACE_BEGIN() (void)0 #define FASTRPC_ATRACE_END() (void)0 #else -#define FASTRPC_ATRACE_BEGIN_L(fmt,...)\ - if(is_systrace_enabled()){ \ - char systrace_string[SYSTRACE_STR_LEN] = {0};\ - FARF(RUNTIME_RPC_HIGH,fmt,##__VA_ARGS__);\ - snprintf(systrace_string, SYSTRACE_STR_LEN, fmt, ##__VA_ARGS__);\ - ATRACE_BEGIN(systrace_string); \ - } else \ +#define FASTRPC_ATRACE_BEGIN_L(fmt, ...) \ + if(is_systrace_enabled()) { \ + char systrace_string[SYSTRACE_STR_LEN] = { 0 }; \ + FARF(RUNTIME_RPC_HIGH, fmt, ##__VA_ARGS__); \ + snprintf(systrace_string, SYSTRACE_STR_LEN, fmt, \ + ##__VA_ARGS__); \ + ATRACE_BEGIN(systrace_string); \ + } else \ (void)0 -#define FASTRPC_ATRACE_END_L(fmt, ...)\ - if(is_systrace_enabled()){ \ - FARF(ALWAYS, fmt, ##__VA_ARGS__);\ - ATRACE_END(); \ - } else { \ - FARF(RUNTIME_RPC_CRITICAL,fmt,##__VA_ARGS__);\ +#define FASTRPC_ATRACE_END_L(fmt, ...) \ + if(is_systrace_enabled()) { \ + FARF(ALWAYS, fmt, ##__VA_ARGS__); \ + ATRACE_END(); \ + } else { \ + FARF(RUNTIME_RPC_CRITICAL, fmt, ##__VA_ARGS__); \ } -#define FASTRPC_ATRACE_BEGIN()\ - if(is_systrace_enabled()){ \ - FARF(ALWAYS, "%s begin", __func__);\ - ATRACE_BEGIN(__func__); \ - } else \ +#define FASTRPC_ATRACE_BEGIN() \ + if(is_systrace_enabled()) { \ + FARF(ALWAYS, "%s begin", __func__); \ + ATRACE_BEGIN(__func__); \ + } else \ (void)0 -#define FASTRPC_ATRACE_END()\ - if(is_systrace_enabled()) { \ - FARF(ALWAYS, "%s end", __func__);\ - ATRACE_END(); \ - } else { \ - FARF(RUNTIME_RPC_CRITICAL,"%s end", __func__);\ +#define FASTRPC_ATRACE_END() \ + if(is_systrace_enabled()) { \ + FARF(ALWAYS, "%s end", __func__); \ + ATRACE_END(); \ + } else { \ + FARF(RUNTIME_RPC_CRITICAL, "%s end", __func__); \ } #endif -//API to get Systrace variable +// API to get Systrace variable int is_systrace_enabled(void); #endif // FASTRPC_TRACE_H diff --git a/inc/listener_android.h b/inc/listener_android.h index 2cf229c8..5356f400 100644 --- a/inc/listener_android.h +++ b/inc/listener_android.h @@ -4,14 +4,14 @@ #ifndef LISTENER_ANDROID_H #define LISTENER_ANDROID_H -#include #include +#include -#define MSG(a, b, c) printf(__FILE_LINE__ ":" c ) -#define MSG_1(a, b, c, d) printf(__FILE_LINE__ ":" c , d) -#define MSG_2(a, b, c, d, e) printf(__FILE_LINE__ ":" c , d, e) -#define MSG_3(a, b, c, d, e, f) printf(__FILE_LINE__ ":" c , d, e, f) -#define MSG_4(a, b, c, d, e, f,g) printf(__FILE_LINE__ ":" c , d, e, f, g) +#define MSG(a, b, c) printf(__FILE_LINE__ ":" c) +#define MSG_1(a, b, c, d) printf(__FILE_LINE__ ":" c, d) +#define MSG_2(a, b, c, d, e) printf(__FILE_LINE__ ":" c, d, e) +#define MSG_3(a, b, c, d, e, f) printf(__FILE_LINE__ ":" c, d, e, f) +#define MSG_4(a, b, c, d, e, f, g) printf(__FILE_LINE__ ":" c, d, e, f, g) #define DLW_RTLD_NOW RTLD_NOW #define dlw_Open dlopen @@ -20,19 +20,23 @@ #define dlw_Error dlerror /* - * API to initialize globals and internal data structures used in listener modules + * API to initialize globals and internal data structures used in listener + * modules */ int listener_android_init(void); /* - * API to de-initialize globals and internal data structures used in listener modules + * API to de-initialize globals and internal data structures used in listener + * modules */ void listener_android_deinit(void); /* * API to initialize domain specific data strcutures used in listener modules */ -int listener_android_domain_init(int domain, int update_requested, sem_t *r_sem); +int listener_android_domain_init(int domain, int update_requested, + sem_t *r_sem); /* - * API to de-initialize domain specific data strcutures used in listener modules + * API to de-initialize domain specific data strcutures used in listener + * modules */ void listener_android_domain_deinit(int domain); diff --git a/inc/listener_buf.h b/inc/listener_buf.h index 9c5674f8..4edd7b07 100644 --- a/inc/listener_buf.h +++ b/inc/listener_buf.h @@ -4,95 +4,108 @@ #ifndef LISTENER_BUF_H #define LISTENER_BUF_H -#include "sbuf.h" #include "remote.h" +#include "sbuf.h" #include "verify.h" -static __inline void pack_in_bufs(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii; - uint32_t len; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - len = (uint32_t)pra[ii].buf.nLen; - sbuf_write(buf, (uint8_t*)&len, 4); - if(len) { - sbuf_align(buf, 8); - sbuf_write(buf, pra[ii].buf.pv, len); - } - } +static __inline void +pack_in_bufs(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii; + uint32_t len; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + len = (uint32_t)pra[ii].buf.nLen; + sbuf_write(buf, (uint8_t *)&len, 4); + if(len) { + sbuf_align(buf, 8); + sbuf_write(buf, pra[ii].buf.pv, len); + } + } } -static __inline void pack_out_lens(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii; - uint32_t len; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - len = (uint32_t)pra[ii].buf.nLen; - sbuf_write(buf, (uint8_t*)&len, 4); - } +static __inline void +pack_out_lens(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii; + uint32_t len; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + len = (uint32_t)pra[ii].buf.nLen; + sbuf_write(buf, (uint8_t *)&len, 4); + } } -static __inline void unpack_in_bufs(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii; - uint32_t len=0; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - sbuf_read(buf, (uint8_t*)&len, 4); - pra[ii].buf.nLen = len; - if(pra[ii].buf.nLen) { - sbuf_align(buf, 8); - if((int)pra[ii].buf.nLen <= sbuf_left(buf)) { - pra[ii].buf.pv = sbuf_head(buf); - } - sbuf_advance(buf, pra[ii].buf.nLen); - } - } +static __inline void +unpack_in_bufs(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii; + uint32_t len = 0; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + sbuf_read(buf, (uint8_t *)&len, 4); + pra[ii].buf.nLen = len; + if(pra[ii].buf.nLen) { + sbuf_align(buf, 8); + if((int)pra[ii].buf.nLen <= sbuf_left(buf)) { + pra[ii].buf.pv = sbuf_head(buf); + } + sbuf_advance(buf, pra[ii].buf.nLen); + } + } } -static __inline void unpack_out_lens(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii; - uint32_t len=0; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - sbuf_read(buf, (uint8_t*)&len, 4); - pra[ii].buf.nLen = len; - } +static __inline void +unpack_out_lens(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii; + uint32_t len = 0; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + sbuf_read(buf, (uint8_t *)&len, 4); + pra[ii].buf.nLen = len; + } } -//map out buffers on the hlos side to the remote_arg array -//dst is the space required for buffers we coun't map from the adsp -static __inline void pack_out_bufs(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii; - uint32_t len; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - len = (uint32_t)pra[ii].buf.nLen; - sbuf_write(buf, (uint8_t*)&len, 4); - if(pra[ii].buf.nLen) { - sbuf_align(buf, 8); - if((int)pra[ii].buf.nLen <= sbuf_left(buf)) { - pra[ii].buf.pv = sbuf_head(buf); - } - sbuf_advance(buf, pra[ii].buf.nLen); - } - } +// map out buffers on the hlos side to the remote_arg array +// dst is the space required for buffers we coun't map from the adsp +static __inline void +pack_out_bufs(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii; + uint32_t len; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + len = (uint32_t)pra[ii].buf.nLen; + sbuf_write(buf, (uint8_t *)&len, 4); + if(pra[ii].buf.nLen) { + sbuf_align(buf, 8); + if((int)pra[ii].buf.nLen <= sbuf_left(buf)) { + pra[ii].buf.pv = sbuf_head(buf); + } + sbuf_advance(buf, pra[ii].buf.nLen); + } + } } -//on the aDSP copy the data from buffers we had to copy to the local remote_arg structure -static __inline int unpack_out_bufs(struct sbuf* buf, remote_arg* pra, int nBufs) { - int ii, nErr = 0; - uint32_t len; - C_ASSERT(sizeof(len) == 4); - for(ii = 0; ii < nBufs; ++ii) { - sbuf_read(buf, (uint8_t*)&len, 4); - VERIFY(len == pra[ii].buf.nLen); - if(pra[ii].buf.nLen) { - sbuf_align(buf, 8); - sbuf_read(buf, pra[ii].buf.pv, pra[ii].buf.nLen); - } - } +// on the aDSP copy the data from buffers we had to copy to the local +// remote_arg structure +static __inline int +unpack_out_bufs(struct sbuf *buf, remote_arg *pra, int nBufs) +{ + int ii, nErr = 0; + uint32_t len; + C_ASSERT(sizeof(len) == 4); + for(ii = 0; ii < nBufs; ++ii) { + sbuf_read(buf, (uint8_t *)&len, 4); + VERIFY(len == pra[ii].buf.nLen); + if(pra[ii].buf.nLen) { + sbuf_align(buf, 8); + sbuf_read(buf, pra[ii].buf.pv, pra[ii].buf.nLen); + } + } bail: - return nErr; + return nErr; } #endif diff --git a/inc/log_config.h b/inc/log_config.h index a32033da..f14d0537 100644 --- a/inc/log_config.h +++ b/inc/log_config.h @@ -4,16 +4,16 @@ #ifndef __LOG_CONFIG_H__ #define __LOG_CONFIG_H__ /** - * @brief API to initialize logging framework - * creates a thread and looks for .farf filebuf - * when found, reads the file for log levels that - * should be enabled on APSS and DSP. - **/ + * @brief API to initialize logging framework + * creates a thread and looks for .farf filebuf + * when found, reads the file for log levels that + * should be enabled on APSS and DSP. + **/ int initFileWatcher(int domain); /** - * @brief API to de-initialize logging framework - * sets an exit flag and wait for the thread to join. - **/ + * @brief API to de-initialize logging framework + * sets an exit flag and wait for the thread to join. + **/ void deinitFileWatcher(int domain); #endif /*__LOG_CONFIG_H__*/ diff --git a/inc/mod_table.h b/inc/mod_table.h index b1accd9a..ceaae6df 100644 --- a/inc/mod_table.h +++ b/inc/mod_table.h @@ -4,12 +4,11 @@ #ifndef MOD_TABLE_H #define MOD_TABLE_H -#include "remote64.h" #include "AEEStdDef.h" +#include "remote64.h" #ifdef __cplusplus -extern "C" -{ +extern "C" { #endif /** @@ -22,48 +21,56 @@ extern "C" */ /** - * register a static component for invocations - * this can be called at any time including from a static constructor - * - * name, name of the interface to register - * pfn, function pointer to the skel invoke function - * - * for example: - * __attribute__((constructor)) static void my_module_ctor(void) { - * mod_table_register_static("my_module", my_module_skel_invoke); - * } - * - */ -int mod_table_register_static(const char* name, int (*pfn)(uint32_t sc, remote_arg* pra)); + * register a static component for invocations + * this can be called at any time including from a static constructor + * + * name, name of the interface to register + * pfn, function pointer to the skel invoke function + * + * for example: + * __attribute__((constructor)) static void my_module_ctor(void) { + * mod_table_register_static("my_module", my_module_skel_invoke); + * } + * + */ +int mod_table_register_static(const char *name, + int (*pfn)(uint32_t sc, remote_arg *pra)); /** - * same as register_static, but module with user defined handle lifetimes. - */ -int mod_table_register_static1(const char* uri, int (*pfn)(remote_handle64 h,uint32_t sc, remote_arg* pra)); + * same as register_static, but module with user defined handle lifetimes. + */ +int mod_table_register_static1(const char *uri, + int (*pfn)(remote_handle64 h, uint32_t sc, + remote_arg *pra)); /** - * register a static component for invocations - * this can be called at any time including from a static constructor - * - * overrides will be tried first, then dynamic modules, then regular - * static modules. This api should only be use by system components - * that will never be upgradable. - * - * name, name of the interface to register - * pfn, function pointer to the skel invoke function - * - * for example: - * __attribute__((constructor)) static void my_module_ctor(void) { - * mod_table_register_static("my_module", my_module_skel_invoke); - * } - * - */ -int mod_table_register_static_override(const char* name, int(*pfn)(uint32_t sc, remote_arg* pra)); + * register a static component for invocations + * this can be called at any time including from a static constructor + * + * overrides will be tried first, then dynamic modules, then regular + * static modules. This api should only be use by system components + * that will never be upgradable. + * + * name, name of the interface to register + * pfn, function pointer to the skel invoke function + * + * for example: + * __attribute__((constructor)) static void my_module_ctor(void) { + * mod_table_register_static("my_module", my_module_skel_invoke); + * } + * + */ +int mod_table_register_static_override(const char *name, + int (*pfn)(uint32_t sc, + remote_arg *pra)); /** - * same as register_static, but module with user defined handle lifetimes. - */ -int mod_table_register_static_override1(const char* uri, int(*pfn)(remote_handle64,uint32_t sc, remote_arg* pra)); + * same as register_static, but module with user defined handle lifetimes. + */ +int mod_table_register_static_override1(const char *uri, + int (*pfn)(remote_handle64, + uint32_t sc, + remote_arg *pra)); /** * Open a module and get a handle to it @@ -74,7 +81,8 @@ int mod_table_register_static_override1(const char* uri, int(*pfn)(remote_handle * dlerrorLen, Length of error String (if an error occurs) * pdlErr, Error identifier */ -int mod_table_open(const char* in_name, remote_handle* handle, char* dlerr, int dlerrorLen, int* pdlErr); +int mod_table_open(const char *in_name, remote_handle *handle, char *dlerr, + int dlerrorLen, int *pdlErr); /** * invoke a handle in the mod table @@ -83,7 +91,7 @@ int mod_table_open(const char* in_name, remote_handle* handle, char* dlerr, int * sc, scalars, see remote.h for documentation. * pra, args, see remote.h for documentation. */ -int mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg* pra); +int mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg *pra); /** * Closes a handle in the mod table @@ -93,17 +101,22 @@ int mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg* pra); * errStrLen, Length of error String (if an error occurs) * pdlErr, Error identifier */ -int mod_table_close(remote_handle handle, char* errStr, int errStrLen, int* pdlErr); +int mod_table_close(remote_handle handle, char *errStr, int errStrLen, + int *pdlErr); /** * internal use only */ -int mod_table_register_const_handle(remote_handle handle, const char* in_name, int (*pfn)(uint32_t sc, remote_arg* pra)); +int mod_table_register_const_handle(remote_handle handle, const char *in_name, + int (*pfn)(uint32_t sc, remote_arg *pra)); /** * @param remote, the handle we should expect from the transport layer * @param local, the local handle that will be passed to pfn */ -int mod_table_register_const_handle1(remote_handle remote, remote_handle64 local, const char* uri, int (*pfn)(remote_handle64 h, uint32_t sc, remote_arg* pra)); +int mod_table_register_const_handle1(remote_handle remote, + remote_handle64 local, const char *uri, + int (*pfn)(remote_handle64 h, uint32_t sc, + remote_arg *pra)); #ifdef __cplusplus } diff --git a/inc/mutex.h b/inc/mutex.h index f230d070..30abf618 100644 --- a/inc/mutex.h +++ b/inc/mutex.h @@ -7,37 +7,42 @@ #if (defined __qdsp6__) || (defined __hexagon__) #include "qurt_mutex.h" -#define RW_MUTEX_T qurt_mutex_t -#define RW_MUTEX_CTOR(mut) qurt_mutex_init(& (mut)) -#define RW_MUTEX_LOCK_READ(mut) qurt_mutex_lock(& (mut)) -#define RW_MUTEX_UNLOCK_READ(mut) qurt_mutex_unlock(& (mut)) -#define RW_MUTEX_LOCK_WRITE(mut) qurt_mutex_lock(& (mut)) -#define RW_MUTEX_UNLOCK_WRITE(mut) qurt_mutex_unlock(& (mut)) -#define RW_MUTEX_DTOR(mut) qurt_mutex_destroy(& (mut)) +#define RW_MUTEX_T qurt_mutex_t +#define RW_MUTEX_CTOR(mut) qurt_mutex_init(&(mut)) +#define RW_MUTEX_LOCK_READ(mut) qurt_mutex_lock(&(mut)) +#define RW_MUTEX_UNLOCK_READ(mut) qurt_mutex_unlock(&(mut)) +#define RW_MUTEX_LOCK_WRITE(mut) qurt_mutex_lock(&(mut)) +#define RW_MUTEX_UNLOCK_WRITE(mut) qurt_mutex_unlock(&(mut)) +#define RW_MUTEX_DTOR(mut) qurt_mutex_destroy(&(mut)) -#elif (1 == __linux) || (1 == __linux__) || (1 == __gnu_linux__) || (1 == linux) +#elif (1 == __linux) || (1 == __linux__) || (1 == __gnu_linux__) \ + || (1 == linux) #include -#include #include +#include /* asserts may be compiled out, this should always be present */ -#define ABORT_FAIL( ff ) \ - do {\ - if(! (ff) ) {\ - fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d\n", #ff, __FILE__, __LINE__);\ - abort();\ - }\ - } while(0) - -#define RW_MUTEX_T pthread_rwlock_t -#define RW_MUTEX_CTOR(mut) ABORT_FAIL(0 == pthread_rwlock_init( & (mut), 0)) -#define RW_MUTEX_LOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_rdlock( & (mut))) -#define RW_MUTEX_UNLOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_unlock( & (mut))) -#define RW_MUTEX_LOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_wrlock( & (mut))) -#define RW_MUTEX_UNLOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_unlock( & (mut))) -#define RW_MUTEX_DTOR(mut) ABORT_FAIL(0 == pthread_rwlock_destroy( & (mut))) - +#define ABORT_FAIL(ff) \ + do { \ + if(!(ff)) { \ + fprintf(stderr, \ + "assertion \"%s\" failed: file \"%s\", line " \ + "%d\n", \ + #ff, __FILE__, __LINE__); \ + abort(); \ + } \ + } while(0) + +#define RW_MUTEX_T pthread_rwlock_t +#define RW_MUTEX_CTOR(mut) ABORT_FAIL(0 == pthread_rwlock_init(&(mut), 0)) +#define RW_MUTEX_LOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_rdlock(&(mut))) +#define RW_MUTEX_UNLOCK_READ(mut) \ + ABORT_FAIL(0 == pthread_rwlock_unlock(&(mut))) +#define RW_MUTEX_LOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_wrlock(&(mut))) +#define RW_MUTEX_UNLOCK_WRITE(mut) \ + ABORT_FAIL(0 == pthread_rwlock_unlock(&(mut))) +#define RW_MUTEX_DTOR(mut) ABORT_FAIL(0 == pthread_rwlock_destroy(&(mut))) #else @@ -45,35 +50,35 @@ #define RW_MUTEX_T uint32_t #define RW_MUTEX_CTOR(mut) mut = 0 -#define RW_MUTEX_LOCK_READ(mut) \ - do {\ - assert(STD_BIT_TEST(&mut, 1) == 0); \ - assert(STD_BIT_TEST(&mut, 2) == 0); \ - STD_BIT_SET(&mut, 1); \ - } while (0) - -#define RW_MUTEX_UNLOCK_READ(mut) \ - do {\ - assert(STD_BIT_TEST(&mut, 1)); \ - assert(STD_BIT_TEST(&mut, 2) == 0); \ - STD_BIT_CLEAR(&mut, 1); \ - } while (0) - -#define RW_MUTEX_LOCK_WRITE(mut) \ - do {\ - assert(STD_BIT_TEST(&mut, 1) == 0); \ - assert(STD_BIT_TEST(&mut, 2) == 0); \ - STD_BIT_SET(&mut, 2); \ - } while (0) - -#define RW_MUTEX_UNLOCK_WRITE(mut) \ - do {\ - assert(STD_BIT_TEST(&mut, 1) == 0); \ - assert(STD_BIT_TEST(&mut, 2)); \ - STD_BIT_CLEAR(&mut, 2); \ - } while (0) +#define RW_MUTEX_LOCK_READ(mut) \ + do { \ + assert(STD_BIT_TEST(&mut, 1) == 0); \ + assert(STD_BIT_TEST(&mut, 2) == 0); \ + STD_BIT_SET(&mut, 1); \ + } while(0) + +#define RW_MUTEX_UNLOCK_READ(mut) \ + do { \ + assert(STD_BIT_TEST(&mut, 1)); \ + assert(STD_BIT_TEST(&mut, 2) == 0); \ + STD_BIT_CLEAR(&mut, 1); \ + } while(0) + +#define RW_MUTEX_LOCK_WRITE(mut) \ + do { \ + assert(STD_BIT_TEST(&mut, 1) == 0); \ + assert(STD_BIT_TEST(&mut, 2) == 0); \ + STD_BIT_SET(&mut, 2); \ + } while(0) + +#define RW_MUTEX_UNLOCK_WRITE(mut) \ + do { \ + assert(STD_BIT_TEST(&mut, 1) == 0); \ + assert(STD_BIT_TEST(&mut, 2)); \ + STD_BIT_CLEAR(&mut, 2); \ + } while(0) #define RW_MUTEX_DTOR(mut) mut = 0 #endif -#endif //MUTEX_H +#endif // MUTEX_H diff --git a/inc/platform_libs.h b/inc/platform_libs.h index b42b4b27..6e130fc1 100644 --- a/inc/platform_libs.h +++ b/inc/platform_libs.h @@ -57,24 +57,23 @@ libraryB does not need to appear in the platform library list. #include struct platform_lib { - const char* name; - atomic_uint uRefs; - int nErr; - int (*init)(void); - void (*deinit)(void); + const char *name; + atomic_uint uRefs; + int nErr; + int (*init)(void); + void (*deinit)(void); }; /** * use this macro to pull in external dependencies */ #ifdef __cplusplus -#define PL_DEP(name)\ - extern "C" {\ - extern struct platform_lib* _pl_##name(void); \ - } +#define PL_DEP(name) \ + extern "C" { \ + extern struct platform_lib *_pl_##name(void); \ + } #else -#define PL_DEP(name)\ - extern struct platform_lib* _pl_##name(void); +#define PL_DEP(name) extern struct platform_lib *_pl_##name(void); #endif /* __cplusplus */ /** @@ -82,19 +81,24 @@ struct platform_lib { * if constructor fails, destructor is not called */ #ifdef __cplusplus -#define PL_DEFINE(name, init, deinit) \ - extern "C" {\ - struct platform_lib* _pl_##name(void) {\ - static struct platform_lib _gpl_##name = { #name, 0, -1, init, deinit };\ - return &_gpl_##name;\ - }\ - } +#define PL_DEFINE(name, init, deinit) \ + extern "C" { \ + struct platform_lib * \ + _pl_##name(void) \ + { \ + static struct platform_lib _gpl_##name \ + = { #name, 0, -1, init, deinit }; \ + return &_gpl_##name; \ + } \ + } #else -#define PL_DEFINE(name, init, deinit) \ - struct platform_lib* _pl_##name(void) {\ - static struct platform_lib _gpl_##name = { #name, 0, -1, init, deinit };\ - return &_gpl_##name;\ - } +#define PL_DEFINE(name, init, deinit) \ + struct platform_lib *_pl_##name(void) \ + { \ + static struct platform_lib _gpl_##name \ + = { #name, 0, -1, init, deinit }; \ + return &_gpl_##name; \ + } #endif /* __cplusplus */ /** @@ -141,15 +145,15 @@ void pl_deinit(void); /** * initialize a single library. called via PL_INIT */ -int pl_lib_init(struct platform_lib* (*pl)(void)); +int pl_lib_init(struct platform_lib *(*pl)(void)); /** * deinitialize a single library called via PL_DEINIT */ -void pl_lib_deinit(struct platform_lib* (*pl)(void)); +void pl_lib_deinit(struct platform_lib *(*pl)(void)); #ifdef __cplusplus } #endif -#endif //PLATFORM_LIBS +#endif // PLATFORM_LIBS diff --git a/inc/pls.h b/inc/pls.h index c26a712c..1904a2c3 100644 --- a/inc/pls.h +++ b/inc/pls.h @@ -4,96 +4,106 @@ #ifndef PLS_H #define PLS_H -#include #include "AEEStdDef.h" -#include "verify.h" #include "HAP_farf.h" +#include "verify.h" +#include struct PLS; struct plskey { - uintptr_t type; - uintptr_t key; + uintptr_t type; + uintptr_t key; }; struct PLS { - uintptr_t next; - struct plskey key; - void (*dtor)(void* data); - uint64_t data[1]; + uintptr_t next; + struct plskey key; + void (*dtor)(void *data); + uint64_t data[1]; }; - struct pls_table { - atomic_uintptr_t lst; - atomic_uint uRefs; - uint32_t primThread; + atomic_uintptr_t lst; + atomic_uint uRefs; + uint32_t primThread; }; -unsigned int atomic_CompareOrAdd(atomic_uint* puDest, unsigned int uCompare, unsigned int nAdd) { - unsigned int previous; - unsigned int current; - unsigned int result; - - do { - current = atomic_load(puDest); - previous = current; - result = current; - if(current != uCompare) { - atomic_compare_exchange_strong(puDest, &previous, current + nAdd); - if(previous == current) { - result = current + nAdd; - } - } - } while(previous != current); - - return result; +unsigned int +atomic_CompareOrAdd(atomic_uint *puDest, unsigned int uCompare, + unsigned int nAdd) +{ + unsigned int previous; + unsigned int current; + unsigned int result; + + do { + current = atomic_load(puDest); + previous = current; + result = current; + if(current != uCompare) { + atomic_compare_exchange_strong(puDest, &previous, + current + nAdd); + if(previous == current) { + result = current + nAdd; + } + } + } while(previous != current); + + return result; } /** * initialize on every thread and stick the pls_thread_deinit * function into the threads tls */ -static __inline int pls_thread_init(struct pls_table* me, uintptr_t tid) { - if(tid == me->primThread) { - return 0; - } - while (1) { - unsigned int current; - - current = atomic_load(&me->uRefs); - if (current == 0) - return -1; - - if (atomic_compare_exchange_strong(&me->uRefs, ¤t, current + 1)) - return 0; - } +static __inline int +pls_thread_init(struct pls_table *me, uintptr_t tid) +{ + if(tid == me->primThread) { + return 0; + } + while(1) { + unsigned int current; + + current = atomic_load(&me->uRefs); + if(current == 0) + return -1; + + if(atomic_compare_exchange_strong(&me->uRefs, ¤t, + current + 1)) + return 0; + } } /* call this constructor before the first thread creation with the * first threads id */ -static __inline void pls_ctor(struct pls_table* me, uintptr_t primThread) { - me->uRefs = 1; - me->primThread = primThread; +static __inline void +pls_ctor(struct pls_table *me, uintptr_t primThread) +{ + me->uRefs = 1; + me->primThread = primThread; } -static __inline struct pls_table* pls_thread_deinit(struct pls_table* me) { - if(me && 0 != me->uRefs && 1 == atomic_fetch_sub(&me->uRefs, 1)) { - struct PLS* lst, *next; - lst = (struct PLS*)atomic_exchange(&me->lst, 0); - while(lst) { - next = (struct PLS*)lst->next; - if(lst->dtor) { - FARF(HIGH, "pls dtor %p", lst->dtor); - lst->dtor((void*)lst->data); - } - free(lst); - lst = next; - } - return me; - } - return 0; +static __inline struct pls_table * +pls_thread_deinit(struct pls_table *me) +{ + if(me && 0 != me->uRefs && 1 == atomic_fetch_sub(&me->uRefs, 1)) { + struct PLS *lst, *next; + lst = (struct PLS *)atomic_exchange(&me->lst, 0); + while(lst) { + next = (struct PLS *)lst->next; + if(lst->dtor) { + FARF(HIGH, "pls dtor %p", lst->dtor); + lst->dtor((void *)lst->data); + } + free(lst); + lst = next; + } + return me; + } + return 0; } /** @@ -111,81 +121,95 @@ static __inline struct pls_table* pls_thread_deinit(struct pls_table* me) { * @param ppo, output data * @retval, 0 for success */ -static __inline int pls_add(struct pls_table* me, uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* data), void** ppo) { - int nErr = 0; - struct PLS* pls = 0; - uintptr_t prev; - VERIFY(me->uRefs != 0); - VERIFY(0 != (pls = (struct PLS*)calloc(1, size + sizeof(*pls) - sizeof(pls->data)))); - if(ctor) { - VERIFY(0 == ctor(ctx, (void*)pls->data)); - } - pls->dtor = dtor; - pls->key.type = type; - pls->key.key = key; - do { - pls->next = atomic_load(&me->lst); - prev = pls->next; - atomic_compare_exchange_strong(&me->lst, &prev, (uintptr_t)pls); - } while(prev != pls->next); - if(ppo) { - *ppo = (void*)pls->data; - } - FARF(HIGH, "pls added %p", dtor); +static __inline int +pls_add(struct pls_table *me, uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *data), void **ppo) +{ + int nErr = 0; + struct PLS *pls = 0; + uintptr_t prev; + VERIFY(me->uRefs != 0); + VERIFY(0 + != (pls = (struct PLS *)calloc(1, size + sizeof(*pls) + - sizeof(pls->data)))); + if(ctor) { + VERIFY(0 == ctor(ctx, (void *)pls->data)); + } + pls->dtor = dtor; + pls->key.type = type; + pls->key.key = key; + do { + pls->next = atomic_load(&me->lst); + prev = pls->next; + atomic_compare_exchange_strong(&me->lst, &prev, + (uintptr_t)pls); + } while(prev != pls->next); + if(ppo) { + *ppo = (void *)pls->data; + } + FARF(HIGH, "pls added %p", dtor); bail: - if(nErr && pls) { - free(pls); - } - return nErr; + if(nErr && pls) { + free(pls); + } + return nErr; } -static __inline int pls_lookup(struct pls_table* me, uintptr_t type, uintptr_t key, void** ppo); +static __inline int pls_lookup(struct pls_table *me, uintptr_t type, + uintptr_t key, void **ppo); /** - * like add, but will only add 1 item if two threads try to add at the same time. returns - * item if its already there, otherwise tries to add. - * ctor may be called twice - * callers should avoid calling pls_add which will override the singleton + * like add, but will only add 1 item if two threads try to add at the same + * time. returns item if its already there, otherwise tries to add. ctor may + * be called twice callers should avoid calling pls_add which will override the + * singleton */ -static __inline int pls_add_lookup_singleton(struct pls_table* me, uintptr_t type, uintptr_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* data), void** ppo) { - int nErr = 0; - struct PLS* pls = 0; - uintptr_t prev; - if(0 == pls_lookup(me, type, key, ppo)) { - return 0; - } - VERIFY(me->uRefs != 0); - VERIFY(0 != (pls = (struct PLS*)calloc(1, size + sizeof(*pls) - sizeof(pls->data)))); - if(ctor) { - VERIFY(0 == ctor(ctx, (void*)pls->data)); - } - pls->dtor = dtor; - pls->key.type = type; - pls->key.key = key; - do { - pls->next = atomic_load(&me->lst); - if(0 == pls_lookup(me, type, key, ppo)) { - if(pls->dtor) { - pls->dtor((void*)pls->data); - } - free(pls); - return 0; - } - - prev = pls->next; - atomic_compare_exchange_strong(&me->lst, &prev, (uintptr_t)pls); - } while(prev != pls->next); - if(ppo) { - *ppo = (void*)pls->data; - } +static __inline int +pls_add_lookup_singleton(struct pls_table *me, uintptr_t type, uintptr_t key, + int size, int (*ctor)(void *ctx, void *data), + void *ctx, void (*dtor)(void *data), void **ppo) +{ + int nErr = 0; + struct PLS *pls = 0; + uintptr_t prev; + if(0 == pls_lookup(me, type, key, ppo)) { + return 0; + } + VERIFY(me->uRefs != 0); + VERIFY(0 + != (pls = (struct PLS *)calloc(1, size + sizeof(*pls) + - sizeof(pls->data)))); + if(ctor) { + VERIFY(0 == ctor(ctx, (void *)pls->data)); + } + pls->dtor = dtor; + pls->key.type = type; + pls->key.key = key; + do { + pls->next = atomic_load(&me->lst); + if(0 == pls_lookup(me, type, key, ppo)) { + if(pls->dtor) { + pls->dtor((void *)pls->data); + } + free(pls); + return 0; + } + + prev = pls->next; + atomic_compare_exchange_strong(&me->lst, &prev, + (uintptr_t)pls); + } while(prev != pls->next); + if(ppo) { + *ppo = (void *)pls->data; + } bail: - if(nErr && pls) { - free(pls); - } - return nErr; + if(nErr && pls) { + free(pls); + } + return nErr; } - /** * finds the last data pointer added for key to the local storage * @@ -194,21 +218,20 @@ static __inline int pls_add_lookup_singleton(struct pls_table* me, uintptr_t typ * @retval, 0 for success */ -static __inline int pls_lookup(struct pls_table* me, uintptr_t type, uintptr_t key, void** ppo) { - struct PLS* lst; - for(lst = (struct PLS*)atomic_load(&me->lst); - me->uRefs != 0 && lst != 0; - lst = (struct PLS *)lst->next) { - if(lst->key.type == type && lst->key.key == key) { - if(ppo) { - *ppo = lst->data; - } - return 0; - } - } - return -1; +static __inline int +pls_lookup(struct pls_table *me, uintptr_t type, uintptr_t key, void **ppo) +{ + struct PLS *lst; + for(lst = (struct PLS *)atomic_load(&me->lst); + me->uRefs != 0 && lst != 0; lst = (struct PLS *)lst->next) { + if(lst->key.type == type && lst->key.key == key) { + if(ppo) { + *ppo = lst->data; + } + return 0; + } + } + return -1; } -#endif //PLS_H - - +#endif // PLS_H diff --git a/inc/pthread_rw_mutex.h b/inc/pthread_rw_mutex.h index f2b7b0a0..b5136c8d 100644 --- a/inc/pthread_rw_mutex.h +++ b/inc/pthread_rw_mutex.h @@ -5,29 +5,33 @@ #define PTHREAD_RW_MUTEX_H #include -#include #include +#include /* asserts may be compiled out, this should always be present */ -#define ABORT_FAIL( ff ) \ - do {\ - if(! (ff) ) {\ - fprintf(stderr, "assertion \"%s\" failed: file \"%s\", line %d\n", #ff, __FILE__, __LINE__);\ - abort();\ - }\ - } while(0) - -#define RW_MUTEX_T pthread_rwlock_t -#define RW_MUTEX_CTOR(mut) ABORT_FAIL(0 == pthread_rwlock_init( & (mut), 0)) -#define RW_MUTEX_LOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_rdlock( & (mut))) +#define ABORT_FAIL(ff) \ + do { \ + if(!(ff)) { \ + fprintf(stderr, \ + "assertion \"%s\" failed: file \"%s\", line " \ + "%d\n", \ + #ff, __FILE__, __LINE__); \ + abort(); \ + } \ + } while(0) -#define RW_MUTEX_UNLOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_unlock( & (mut))) +#define RW_MUTEX_T pthread_rwlock_t +#define RW_MUTEX_CTOR(mut) ABORT_FAIL(0 == pthread_rwlock_init(&(mut), 0)) +#define RW_MUTEX_LOCK_READ(mut) ABORT_FAIL(0 == pthread_rwlock_rdlock(&(mut))) -#define RW_MUTEX_LOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_wrlock( & (mut))) +#define RW_MUTEX_UNLOCK_READ(mut) \ + ABORT_FAIL(0 == pthread_rwlock_unlock(&(mut))) -#define RW_MUTEX_UNLOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_unlock( & (mut))) +#define RW_MUTEX_LOCK_WRITE(mut) ABORT_FAIL(0 == pthread_rwlock_wrlock(&(mut))) -#define RW_MUTEX_DTOR(mut) ABORT_FAIL(0 == pthread_rwlock_destroy( & (mut))) +#define RW_MUTEX_UNLOCK_WRITE(mut) \ + ABORT_FAIL(0 == pthread_rwlock_unlock(&(mut))) +#define RW_MUTEX_DTOR(mut) ABORT_FAIL(0 == pthread_rwlock_destroy(&(mut))) -#endif //PTHREAD_RW_MUTEX_H +#endif // PTHREAD_RW_MUTEX_H diff --git a/inc/remote.h b/inc/remote.h index 1fa3baa8..156ccf1a 100644 --- a/inc/remote.h +++ b/inc/remote.h @@ -18,11 +18,11 @@ extern "C" { #ifndef __QAIC_REMOTE_EXPORT #ifdef _WIN32 #ifdef _USRDLL -#define __QAIC_REMOTE_EXPORT __declspec(dllexport) +#define __QAIC_REMOTE_EXPORT __declspec(dllexport) #elif defined(STATIC_LIB) -#define __QAIC_REMOTE_EXPORT /** Define for static libk */ -#else ///STATIC_LIB -#define __QAIC_REMOTE_EXPORT __declspec(dllimport) +#define __QAIC_REMOTE_EXPORT /** Define for static libk */ +#else /// STATIC_LIB +#define __QAIC_REMOTE_EXPORT __declspec(dllimport) #endif ///_USRDLL #else #define __QAIC_REMOTE_EXPORT @@ -82,48 +82,48 @@ extern "C" { #endif ///__QAIC_REMOTE_ATTRIBUTE /** Retrieves method attribute from the scalars parameter */ -#define REMOTE_SCALARS_METHOD_ATTR(dwScalars) (((dwScalars) >> 29) & 0x7) +#define REMOTE_SCALARS_METHOD_ATTR(dwScalars) (((dwScalars) >> 29) & 0x7) /** Retrieves method index from the scalars parameter */ -#define REMOTE_SCALARS_METHOD(dwScalars) (((dwScalars) >> 24) & 0x1f) +#define REMOTE_SCALARS_METHOD(dwScalars) (((dwScalars) >> 24) & 0x1f) /** Retrieves number of input buffers from the scalars parameter */ -#define REMOTE_SCALARS_INBUFS(dwScalars) (((dwScalars) >> 16) & 0x0ff) +#define REMOTE_SCALARS_INBUFS(dwScalars) (((dwScalars) >> 16) & 0x0ff) /** Retrieves number of output buffers from the scalars parameter */ -#define REMOTE_SCALARS_OUTBUFS(dwScalars) (((dwScalars) >> 8) & 0x0ff) +#define REMOTE_SCALARS_OUTBUFS(dwScalars) (((dwScalars) >> 8) & 0x0ff) /** Retrieves number of input handles from the scalars parameter */ -#define REMOTE_SCALARS_INHANDLES(dwScalars) (((dwScalars) >> 4) & 0x0f) +#define REMOTE_SCALARS_INHANDLES(dwScalars) (((dwScalars) >> 4) & 0x0f) /** Retrieves number of output handles from the scalars parameter */ -#define REMOTE_SCALARS_OUTHANDLES(dwScalars) ((dwScalars) & 0x0f) +#define REMOTE_SCALARS_OUTHANDLES(dwScalars) ((dwScalars) & 0x0f) -/** Makes the scalar using the method attr, index and number of io buffers and handles */ -#define REMOTE_SCALARS_MAKEX(nAttr,nMethod,nIn,nOut,noIn,noOut) \ - ((((uint32_t) (nAttr) & 0x7) << 29) | \ - (((uint32_t) (nMethod) & 0x1f) << 24) | \ - (((uint32_t) (nIn) & 0xff) << 16) | \ - (((uint32_t) (nOut) & 0xff) << 8) | \ - (((uint32_t) (noIn) & 0x0f) << 4) | \ - ((uint32_t) (noOut) & 0x0f)) +/** Makes the scalar using the method attr, index and number of io buffers and + * handles */ +#define REMOTE_SCALARS_MAKEX(nAttr, nMethod, nIn, nOut, noIn, noOut) \ + ((((uint32_t)(nAttr) & 0x7) << 29) \ + | (((uint32_t)(nMethod) & 0x1f) << 24) \ + | (((uint32_t)(nIn) & 0xff) << 16) \ + | (((uint32_t)(nOut) & 0xff) << 8) \ + | (((uint32_t)(noIn) & 0x0f) << 4) | ((uint32_t)(noOut) & 0x0f)) -#define REMOTE_SCALARS_MAKE(nMethod,nIn,nOut) REMOTE_SCALARS_MAKEX(0,nMethod,nIn,nOut,0,0) +#define REMOTE_SCALARS_MAKE(nMethod, nIn, nOut) \ + REMOTE_SCALARS_MAKEX(0, nMethod, nIn, nOut, 0, 0) /** Retrieves number of io buffers and handles */ -#define REMOTE_SCALARS_LENGTH(sc) (REMOTE_SCALARS_INBUFS(sc) +\ - REMOTE_SCALARS_OUTBUFS(sc) +\ - REMOTE_SCALARS_INHANDLES(sc) +\ - REMOTE_SCALARS_OUTHANDLES(sc)) +#define REMOTE_SCALARS_LENGTH(sc) \ + (REMOTE_SCALARS_INBUFS(sc) + REMOTE_SCALARS_OUTBUFS(sc) \ + + REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc)) /** Defines the domain IDs for supported DSPs */ -#define ADSP_DOMAIN_ID 0 -#define MDSP_DOMAIN_ID 1 -#define SDSP_DOMAIN_ID 2 -#define CDSP_DOMAIN_ID 3 -#define CDSP1_DOMAIN_ID 4 -#define GDSP0_DOMAIN_ID 5 -#define GDSP1_DOMAIN_ID 6 +#define ADSP_DOMAIN_ID 0 +#define MDSP_DOMAIN_ID 1 +#define SDSP_DOMAIN_ID 2 +#define CDSP_DOMAIN_ID 3 +#define CDSP1_DOMAIN_ID 4 +#define GDSP0_DOMAIN_ID 5 +#define GDSP1_DOMAIN_ID 6 /** Supported Domain Names */ #define ADSP_DOMAIN_NAME "adsp" @@ -151,10 +151,10 @@ extern "C" { /** Domain type for multi-domain RPC calls */ typedef struct domain { - /** Domain ID */ - int id; - /** URI for remote_handle_open */ - char uri[MAX_DOMAIN_URI_SIZE]; + /** Domain ID */ + int id; + /** URI for remote_handle_open */ + char uri[MAX_DOMAIN_URI_SIZE]; } domain_t; /** Remote handle parameter for RPC calls */ @@ -165,51 +165,52 @@ typedef uint64_t remote_handle64; /** 32-bit Remote buffer parameter for RPC calls */ typedef struct { - void *pv; /** Address of a remote buffer */ - size_t nLen; /** Size of a remote buffer */ + void *pv; /** Address of a remote buffer */ + size_t nLen; /** Size of a remote buffer */ } remote_buf; /** 64-bit Remote buffer parameter for RPC calls */ typedef struct { - uint64_t pv; /** Address of a remote buffer */ - int64_t nLen; /** Size of a remote buffer */ + uint64_t pv; /** Address of a remote buffer */ + int64_t nLen; /** Size of a remote buffer */ } remote_buf64; /** 32-bit Remote DMA handle parameter for RPC calls */ typedef struct { - int32_t fd; /** File descriptor of a remote buffer */ - uint32_t offset; /** Offset of the file descriptor */ + int32_t fd; /** File descriptor of a remote buffer */ + uint32_t offset; /** Offset of the file descriptor */ } remote_dma_handle; /** 64-bit Remote DMA handle parameter for RPC calls */ typedef struct { - int32_t fd; /** File descriptor of a remote buffer */ - uint32_t offset; /** Offset of the file descriptor */ - uint32_t len; /** Size of buffer */ + int32_t fd; /** File descriptor of a remote buffer */ + uint32_t offset; /** Offset of the file descriptor */ + uint32_t len; /** Size of buffer */ } remote_dma_handle64; /** 32-bit Remote Arg structure for RPC calls */ typedef union { - remote_buf buf; /** 32-bit remote buffer */ - remote_handle h; /** non-domains remote handle */ - remote_handle64 h64; /** multi-domains remote handle */ - remote_dma_handle dma; /** 32-bit remote dma handle */ + remote_buf buf; /** 32-bit remote buffer */ + remote_handle h; /** non-domains remote handle */ + remote_handle64 h64; /** multi-domains remote handle */ + remote_dma_handle dma; /** 32-bit remote dma handle */ } remote_arg; /** 64-bit Remote Arg structure for RPC calls */ typedef union { - remote_buf64 buf; /** 64-bit remote buffer */ - remote_handle h; /** non-domains remote handle */ - remote_handle64 h64; /** multi-domains remote handle */ - remote_dma_handle64 dma; /** 64-bit remote dma handle */ + remote_buf64 buf; /** 64-bit remote buffer */ + remote_handle h; /** non-domains remote handle */ + remote_handle64 h64; /** multi-domains remote handle */ + remote_dma_handle64 dma; /** 64-bit remote dma handle */ } remote_arg64; /** Async response type */ enum fastrpc_async_notify_type { - FASTRPC_ASYNC_NO_SYNC, /** No notification required */ - FASTRPC_ASYNC_CALLBACK, /** Callback notification using fastrpc_async_callback */ - FASTRPC_ASYNC_POLL, /** User will poll for the notification */ -/** Update FASTRPC_ASYNC_TYPE_MAX when adding new value to this enum */ + FASTRPC_ASYNC_NO_SYNC, /** No notification required */ + FASTRPC_ASYNC_CALLBACK, /** Callback notification using + fastrpc_async_callback */ + FASTRPC_ASYNC_POLL, /** User will poll for the notification */ + /** Update FASTRPC_ASYNC_TYPE_MAX when adding new value to this enum */ }; /** Job id of Async job queued to DSP */ @@ -217,19 +218,18 @@ typedef uint64_t fastrpc_async_jobid; /** Async call back response type, input structure */ typedef struct fastrpc_async_callback { - /** Callback function for async notification */ - void (*fn)(fastrpc_async_jobid jobid, void* context, int result); - /** Current context to identify the callback */ - void *context; -}fastrpc_async_callback_t; + /** Callback function for async notification */ + void (*fn)(fastrpc_async_jobid jobid, void *context, int result); + /** Current context to identify the callback */ + void *context; +} fastrpc_async_callback_t; /** Async descriptor to submit async job */ typedef struct fastrpc_async_descriptor { - enum fastrpc_async_notify_type type; /** Async response type */ - fastrpc_async_jobid jobid; /** Job id of Async job queued to DSP */ - fastrpc_async_callback_t cb; /** Async call back response type */ -}fastrpc_async_descriptor_t; - + enum fastrpc_async_notify_type type; /** Async response type */ + fastrpc_async_jobid jobid; /** Job id of Async job queued to DSP */ + fastrpc_async_callback_t cb; /** Async call back response type */ +} fastrpc_async_descriptor_t; /** * Flags used in struct remote_rpc_control_latency @@ -237,25 +237,28 @@ typedef struct fastrpc_async_descriptor { * in remote handle control interface **/ enum remote_rpc_latency_flags { - RPC_DISABLE_QOS, - -/** Control cpu low power modes based on RPC activity in 100 ms window. - * Recommended for latency sensitive use cases. - */ - RPC_PM_QOS, + RPC_DISABLE_QOS, -/** DSP driver predicts completion time of a method and send CPU wake up signal to reduce wake up latency. - * Recommended for moderate latency sensitive use cases. It is more power efficient compared to pm_qos control. - */ - RPC_ADAPTIVE_QOS, + /** Control cpu low power modes based on RPC activity in 100 ms window. + * Recommended for latency sensitive use cases. + */ + RPC_PM_QOS, -/** - * After sending invocation to DSP, CPU will enter polling mode instead of - * waiting for a glink response. This will boost fastrpc performance by - * reducing the CPU wakeup and scheduling times. Enabled only for sync RPC - * calls. Using this option also enables PM QoS with a latency of 100 us. - */ - RPC_POLL_QOS, + /** DSP driver predicts completion time of a method and send CPU wake + * up signal to reduce wake up latency. Recommended for moderate + * latency sensitive use cases. It is more power efficient compared to + * pm_qos control. + */ + RPC_ADAPTIVE_QOS, + + /** + * After sending invocation to DSP, CPU will enter polling mode instead + * of waiting for a glink response. This will boost fastrpc performance + * by reducing the CPU wakeup and scheduling times. Enabled only for + * sync RPC calls. Using this option also enables PM QoS with a latency + * of 100 us. + */ + RPC_POLL_QOS, }; /** @@ -263,22 +266,25 @@ enum remote_rpc_latency_flags { * in remote handle control interface **/ struct remote_rpc_control_latency { -/** Enable latency optimization techniques to meet requested latency. Use remote_rpc_latency_flags */ - uint32_t enable; + /** Enable latency optimization techniques to meet requested latency. + * Use remote_rpc_latency_flags */ + uint32_t enable; -/** - * Latency in microseconds. - * - * When used with RPC_PM_QOS or RPC_ADAPTIVE_QOS, user should pass maximum RPC - * latency that can be tolerated. It is not guaranteed that fastrpc will meet - * this requirement. 0 us latency is ignored. Recommended value is 100. - * - * When used with RPC_POLL_QOS, user needs to pass the expected execution time - * of method on DSP. CPU will poll for a DSP response for that specified duration - * after which it will timeout and fall back to waiting for a glink response. - * Max value that can be passed is 10000 (10 ms) - */ - uint32_t latency; + /** + * Latency in microseconds. + * + * When used with RPC_PM_QOS or RPC_ADAPTIVE_QOS, user should pass + * maximum RPC latency that can be tolerated. It is not guaranteed that + * fastrpc will meet this requirement. 0 us latency is ignored. + * Recommended value is 100. + * + * When used with RPC_POLL_QOS, user needs to pass the expected + * execution time of method on DSP. CPU will poll for a DSP response + * for that specified duration after which it will timeout and fall + * back to waiting for a glink response. Max value that can be passed + * is 10000 (10 ms) + */ + uint32_t latency; }; /** @@ -286,37 +292,42 @@ struct remote_rpc_control_latency { * @brief Argument to query DSP capability with request ID DSPRPC_GET_DSP_INFO */ typedef struct remote_dsp_capability { - uint32_t domain; /** @param[in]: DSP domain ADSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID */ - uint32_t attribute_ID; /** @param[in]: One of the DSP/kernel attributes from enum remote_dsp_attributes */ - uint32_t capability; /** @param[out]: Result of the DSP/kernel capability query based on attribute_ID */ -}fastrpc_capability; - + uint32_t + domain; /** @param[in]: DSP domain ADSP_DOMAIN_ID, SDSP_DOMAIN_ID, + CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID */ + uint32_t attribute_ID; /** @param[in]: One of the DSP/kernel attributes + from enum remote_dsp_attributes */ + uint32_t capability; /** @param[out]: Result of the DSP/kernel + capability query based on attribute_ID */ +} fastrpc_capability; /** * @enum remote_dsp_attributes * @brief Different types of DSP capabilities queried via remote_handle_control * using DSPRPC_GET_DSP_INFO request id. - * DSPRPC_GET_DSP_INFO should only be used with remote_handle_control() as a handle - * is not needed to query DSP capabilities. - * To query DSP capabilities fill out 'domain' and 'attribute_ID' from structure - * remote_dsp_capability. DSP capability will be returned on variable 'capability'. + * DSPRPC_GET_DSP_INFO should only be used with remote_handle_control() as a + * handle is not needed to query DSP capabilities. To query DSP capabilities + * fill out 'domain' and 'attribute_ID' from structure remote_dsp_capability. + * DSP capability will be returned on variable 'capability'. */ enum remote_dsp_attributes { - DOMAIN_SUPPORT, /** Check if DSP supported: supported = 1, - unsupported = 0 */ - UNSIGNED_PD_SUPPORT, /** DSP unsigned PD support: supported = 1, - unsupported = 0 */ - HVX_SUPPORT_64B, /** Number of HVX 64B support */ - HVX_SUPPORT_128B, /** Number of HVX 128B support */ - VTCM_PAGE, /** Max page size allocation possible in VTCM */ - VTCM_COUNT, /** Number of page_size blocks available */ - ARCH_VER, /** Hexagon processor architecture version */ - HMX_SUPPORT_DEPTH, /** HMX Support Depth */ - HMX_SUPPORT_SPATIAL, /** HMX Support Spatial */ - ASYNC_FASTRPC_SUPPORT, /** Async FastRPC Support */ - STATUS_NOTIFICATION_SUPPORT , /** DSP User PD status notification Support */ - MCID_MULTICAST, /** Multicast widget programming */ - /** Update FASTRPC_MAX_DSP_ATTRIBUTES when adding new value to this enum */ + DOMAIN_SUPPORT, /** Check if DSP supported: supported = 1, + unsupported = 0 */ + UNSIGNED_PD_SUPPORT, /** DSP unsigned PD support: supported = 1, + unsupported = 0 */ + HVX_SUPPORT_64B, /** Number of HVX 64B support */ + HVX_SUPPORT_128B, /** Number of HVX 128B support */ + VTCM_PAGE, /** Max page size allocation possible in VTCM */ + VTCM_COUNT, /** Number of page_size blocks available */ + ARCH_VER, /** Hexagon processor architecture version */ + HMX_SUPPORT_DEPTH, /** HMX Support Depth */ + HMX_SUPPORT_SPATIAL, /** HMX Support Spatial */ + ASYNC_FASTRPC_SUPPORT, /** Async FastRPC Support */ + STATUS_NOTIFICATION_SUPPORT, /** DSP User PD status notification + Support */ + MCID_MULTICAST, /** Multicast widget programming */ + /** Update FASTRPC_MAX_DSP_ATTRIBUTES when adding new value to this + enum */ }; /** Macro for backward compatibility. Clients can compile wakelock request code @@ -329,18 +340,18 @@ enum remote_dsp_attributes { * in remote handle control interface **/ struct remote_rpc_control_wakelock { - uint32_t enable; /** enable control of wake lock */ + uint32_t enable; /** enable control of wake lock */ }; /** * Structure used for request ID `DSPRPC_GET_DOMAIN` * in remote handle control interface. - * Get domain ID associated with an opened handle to remote interface of type remote_handle64. - * remote_handle64_control() returns domain for a given handle + * Get domain ID associated with an opened handle to remote interface of type + * remote_handle64. remote_handle64_control() returns domain for a given handle * remote_handle_control() API returns default domain ID */ typedef struct remote_rpc_get_domain { - int domain; /** @param[out]: domain ID associcated with handle */ + int domain; /** @param[out]: domain ID associcated with handle */ } remote_rpc_get_domain_t; /** @@ -348,30 +359,37 @@ typedef struct remote_rpc_get_domain { * `DSPRPC_GET_PATH` in remote handle control interface. */ struct remote_control_custom_path { - int32_t value_size; /** value size including NULL char */ - const char* path; /** key used for storing the path */ - char* value; /** value which will be used for file operations when the corresponding key is specified in the file URI */ + int32_t value_size; /** value size including NULL char */ + const char *path; /** key used for storing the path */ + char *value; /** value which will be used for file operations when the + corresponding key is specified in the file URI */ }; /** * Request IDs for remote handle control interface **/ enum handle_control_req_id { - DSPRPC_RESERVED, /** Reserved */ - DSPRPC_CONTROL_LATENCY , /** Request ID to enable/disable QOS */ - DSPRPC_GET_DSP_INFO, /** Request ID to get dsp capabilites from kernel and Hexagon */ - DSPRPC_CONTROL_WAKELOCK, /** Request ID to enable wakelock for the given domain */ - DSPRPC_GET_DOMAIN, /** Request ID to get the default domain or domain associated to an exisiting handle */ - DSPRPC_SET_PATH, /** Request ID to add a custom path to the hash table */ - DSPRPC_GET_PATH, /** Request ID to read a custom path to the hash table */ - DSPRPC_SMMU_SUPPORT, /** Request ID to check smmu support by kernel */ - DSPRPC_KALLOC_SUPPORT, /** Request ID to check kalloc support by kernel */ - DSPRPC_PM, /** Request ID to awake PM */ - DSPRPC_RPC_POLL, /** Request ID to update polling mode in kernel */ - DSPRPC_ASYNC_WAKE, /** Request ID to exit async thread */ - DSPRPC_NOTIF_WAKE, /** Request ID to exit notif thread */ - DSPRPC_REMOTE_PROCESS_KILL, /** Request ID to kill remote process */ - DSPRPC_SET_MODE, /** Request ID to set mode */ + DSPRPC_RESERVED, /** Reserved */ + DSPRPC_CONTROL_LATENCY, /** Request ID to enable/disable QOS */ + DSPRPC_GET_DSP_INFO, /** Request ID to get dsp capabilites from kernel + and Hexagon */ + DSPRPC_CONTROL_WAKELOCK, /** Request ID to enable wakelock for the + given domain */ + DSPRPC_GET_DOMAIN, /** Request ID to get the default domain or domain + associated to an exisiting handle */ + DSPRPC_SET_PATH, /** Request ID to add a custom path to the hash table + */ + DSPRPC_GET_PATH, /** Request ID to read a custom path to the hash table + */ + DSPRPC_SMMU_SUPPORT, /** Request ID to check smmu support by kernel */ + DSPRPC_KALLOC_SUPPORT, /** Request ID to check kalloc support by kernel + */ + DSPRPC_PM, /** Request ID to awake PM */ + DSPRPC_RPC_POLL, /** Request ID to update polling mode in kernel */ + DSPRPC_ASYNC_WAKE, /** Request ID to exit async thread */ + DSPRPC_NOTIF_WAKE, /** Request ID to exit notif thread */ + DSPRPC_REMOTE_PROCESS_KILL, /** Request ID to kill remote process */ + DSPRPC_SET_MODE, /** Request ID to set mode */ }; /** @@ -379,9 +397,11 @@ enum handle_control_req_id { * in remote session control interface **/ struct remote_rpc_thread_params { - int domain; /** Remote subsystem domain ID, pass -1 to set params for all domains */ - int prio; /** User thread priority (1 to 255), pass -1 to use default */ - int stack_size; /** User thread stack size, pass -1 to use default */ + int domain; /** Remote subsystem domain ID, pass -1 to set params for + all domains */ + int prio; /** User thread priority (1 to 255), pass -1 to use default + */ + int stack_size; /** User thread stack size, pass -1 to use default */ }; /** @@ -389,8 +409,9 @@ struct remote_rpc_thread_params { * in remote session control interface **/ struct remote_rpc_control_unsigned_module { - int domain; /** Remote subsystem domain ID, -1 to set params for all domains */ - int enable; /** Enable unsigned module loading */ + int domain; /** Remote subsystem domain ID, -1 to set params for all + domains */ + int enable; /** Enable unsigned module loading */ }; /** @@ -398,25 +419,31 @@ struct remote_rpc_control_unsigned_module { * in remote session control interface **/ struct remote_rpc_relative_thread_priority { - int domain; /** Remote subsystem domain ID, pass -1 to update priority for all domains */ - int relative_thread_priority; /** the value by which the default thread priority needs to increase/decrease - * DSP thread priorities run from 1 to 255 with 1 being the highest thread priority. - * So a negative relative thread priority value will 'increase' the thread priority, - * a positive value will 'decrease' the thread priority. - */ + int domain; /** Remote subsystem domain ID, pass -1 to update priority + for all domains */ + int relative_thread_priority; /** the value by which the default thread + * priority needs to increase/decrease + * DSP thread priorities run from 1 to + * 255 with 1 being the highest thread + * priority. So a negative relative + * thread priority value will 'increase' + * the thread priority, a positive value + * will 'decrease' the thread priority. + */ }; /** * When a remote invocation does not return, - * then call "remote_session_control" with FASTRPC_REMOTE_PROCESS_KILL requestID - * and the appropriate remote domain ID. Once remote process is successfully - * killed, before attempting to create new session, user is expected to - * close all open handles for shared objects in case of domains. + * then call "remote_session_control" with FASTRPC_REMOTE_PROCESS_KILL + * requestID and the appropriate remote domain ID. Once remote process is + * successfully killed, before attempting to create new session, user is + * expected to close all open handles for shared objects in case of domains. * And, user is expected to unload all shared objects including - * libcdsprpc.so/libadsprpc.so/libmdsprpc.so/libsdsprpc.so in case of non-domains. + * libcdsprpc.so/libadsprpc.so/libmdsprpc.so/libsdsprpc.so in case of + * non-domains. */ struct remote_rpc_process_clean_params { - int domain; /** Domain ID to recover process */ + int domain; /** Domain ID to recover process */ }; /** @@ -424,7 +451,8 @@ struct remote_rpc_process_clean_params { * in remote session control interface **/ struct remote_rpc_session_close { - int domain; /** Remote subsystem domain ID, -1 to close all handles for all domains */ + int domain; /** Remote subsystem domain ID, -1 to close all handles for + all domains */ }; /** @@ -433,8 +461,9 @@ struct remote_rpc_session_close { * This is used to enable/disable PD dump for userPDs on the DSP **/ struct remote_rpc_control_pd_dump { - int domain; /** Remote subsystem domain ID, -1 to set params for all domains */ - int enable; /** Enable PD dump of user PD on the DSP */ + int domain; /** Remote subsystem domain ID, -1 to set params for all + domains */ + int enable; /** Enable PD dump of user PD on the DSP */ }; /** @@ -446,12 +475,13 @@ typedef struct remote_rpc_process_clean_params remote_rpc_process_exception; /** * Process types - * Return values for FASTRPC_REMOTE_PROCESS_TYPE control req ID for remote_handle_control - * Return values denote the type of process on remote subsystem -**/ + * Return values for FASTRPC_REMOTE_PROCESS_TYPE control req ID for + *remote_handle_control Return values denote the type of process on remote + *subsystem + **/ enum fastrpc_process_type { - PROCESS_TYPE_SIGNED, /** Signed PD running on the DSP */ - PROCESS_TYPE_UNSIGNED, /** Unsigned PD running on the DSP */ + PROCESS_TYPE_SIGNED, /** Signed PD running on the DSP */ + PROCESS_TYPE_UNSIGNED, /** Unsigned PD running on the DSP */ }; /** @@ -462,21 +492,25 @@ enum fastrpc_process_type { * @param[out]: Process_type belonging to enum fastrpc_process_type */ struct remote_process_type { - int domain; - int process_type; + int domain; + int process_type; }; /** * DSP user PD status notification flags - * Status flags for the user PD on the DSP returned by the status notification function + * Status flags for the user PD on the DSP returned by the status notification + *function * -**/ + **/ typedef enum remote_rpc_status_flags { - FASTRPC_USER_PD_UP, /** DSP user process is up */ - FASTRPC_USER_PD_EXIT, /** DSP user process exited */ - FASTRPC_USER_PD_FORCE_KILL, /** DSP user process forcefully killed. Happens when DSP resources needs to be freed. */ - FASTRPC_USER_PD_EXCEPTION, /** Exception in the user process of DSP. */ - FASTRPC_DSP_SSR, /** Subsystem restart of the DSP, where user process is running. */ + FASTRPC_USER_PD_UP, /** DSP user process is up */ + FASTRPC_USER_PD_EXIT, /** DSP user process exited */ + FASTRPC_USER_PD_FORCE_KILL, /** DSP user process forcefully killed. + Happens when DSP resources needs to be + freed. */ + FASTRPC_USER_PD_EXCEPTION, /** Exception in the user process of DSP. */ + FASTRPC_DSP_SSR, /** Subsystem restart of the DSP, where user process + is running. */ } remote_rpc_status_flags_t; /** @@ -489,18 +523,20 @@ typedef enum remote_rpc_status_flags { * @param status, status of user process * @retval, 0 on success */ -typedef int (*fastrpc_notif_fn_t)(void *context, int domain, int session, remote_rpc_status_flags_t status); - +typedef int (*fastrpc_notif_fn_t)(void *context, int domain, int session, + remote_rpc_status_flags_t status); /** * Structure for remote_session_control, * used with FASTRPC_REGISTER_STATUS_NOTIFICATIONS request ID * to receive status notifications of the user PD on the DSP -**/ + **/ typedef struct remote_rpc_notif_register { - void *context; /** @param[in]: Context of the client */ - int domain; /** @param[in]: DSP domain ADSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID */ - fastrpc_notif_fn_t notifier_fn; /** @param[in]: Notification function pointer */ + void *context; /** @param[in]: Context of the client */ + int domain; /** @param[in]: DSP domain ADSP_DOMAIN_ID, SDSP_DOMAIN_ID, + CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID */ + fastrpc_notif_fn_t + notifier_fn; /** @param[in]: Notification function pointer */ } remote_rpc_notif_register_t; /** @@ -508,63 +544,87 @@ typedef struct remote_rpc_notif_register { * in remote session control interface **/ struct remote_rpc_pd_initmem_size { - int domain; /** Remote subsystem domain ID, pass -1 to set params for all domains **/ - uint32_t pd_initmem_size; /** Initial memory allocated for remote userpd, minimum value : 3MB, maximum value 200MB **/ - /** Unsupported for unsigned user PD, for unsigned user PD init mem size is fixed at 5MB **/ + int domain; /** Remote subsystem domain ID, pass -1 to set params for + all domains **/ + uint32_t + pd_initmem_size; /** Initial memory allocated for remote userpd, + minimum value : 3MB, maximum value 200MB **/ + /** Unsupported for unsigned user PD, for unsigned user PD init mem + * size is fixed at 5MB **/ }; /** * Structure for remote_session_control, * used with FASTRPC_RESERVE_SESSION request ID * to reserve new fastrpc session of the user PD on the DSP. - * Default sesion is always 0 and remains available for any module opened without Session ID. - * New session reservation starts with session ID 1. -**/ + * Default sesion is always 0 and remains available for any module opened + *without Session ID. New session reservation starts with session ID 1. + **/ typedef struct remote_rpc_reserve_new_session { - char *domain_name; /** @param[in]: Domain name of DSP, on which session need to be reserved */ - uint32_t domain_name_len; /** @param[in]: Domain name length, without NULL character */ - char *session_name; /** @param[in]: Session name of the reserved sesssion */ - uint32_t session_name_len; /** @param[in]: Session name length, without NULL character */ - uint32_t effective_domain_id; /** @param[out]: Effective Domain ID is the identifier of the session. - * Effective Domain ID is the unique identifier representing the session(PD) on DSP. - * Effective Domain ID needs to be used in place of Domain ID when application has multiple sessions. - */ - uint32_t session_id; /** @param[out]: Session ID of the reserved session. - * An application can have multiple sessions(PDs) created on DSP. - * session_id 0 is the default session. Clients can reserve session starting from 1. - * Currently only 2 sessions are supported session_id 0 and session_id 1. - */ + char *domain_name; /** @param[in]: Domain name of DSP, on which session + need to be reserved */ + uint32_t domain_name_len; /** @param[in]: Domain name length, without + NULL character */ + char *session_name; /** @param[in]: Session name of the reserved + sesssion */ + uint32_t session_name_len; /** @param[in]: Session name length, without + NULL character */ + uint32_t + effective_domain_id; /** @param[out]: Effective Domain ID is the + * identifier of the session. Effective Domain + * ID is the unique identifier representing + * the session(PD) on DSP. Effective Domain ID + * needs to be used in place of Domain ID when + * application has multiple sessions. + */ + uint32_t + session_id; /** @param[out]: Session ID of the reserved session. + * An application can have multiple sessions(PDs) + * created on DSP. session_id 0 is the default session. + * Clients can reserve session starting from 1. + * Currently only 2 sessions are supported session_id 0 + * and session_id 1. + */ } remote_rpc_reserve_new_session_t; /** * Structure for remote_session_control, * used with FASTRPC_GET_EFFECTIVE_DOMAIN_ID request ID * to get effective domain id of fastrpc session on the user PD of the DSP -**/ + **/ typedef struct remote_rpc_effective_domain_id { - char *domain_name; /** @param[in]: Domain name of DSP */ - uint32_t domain_name_len; /** @param[in]: Domain name length, without NULL character */ - uint32_t session_id; /** @param[in]: Session ID of the reserved session. 0 can be used for Default session */ - uint32_t effective_domain_id; /** @param[out]: Effective Domain ID of session */ + char *domain_name; /** @param[in]: Domain name of DSP */ + uint32_t domain_name_len; /** @param[in]: Domain name length, without + NULL character */ + uint32_t session_id; /** @param[in]: Session ID of the reserved + session. 0 can be used for Default session */ + uint32_t effective_domain_id; /** @param[out]: Effective Domain ID of + session */ } remote_rpc_effective_domain_id_t; /** * Structure for remote_session_control, * used with FASTRPC_GET_URI request ID * to get the URI needed to load the module in the fastrpc user PD on the DSP -**/ + **/ typedef struct remote_rpc_get_uri { - char *domain_name; /** @param[in]: Domain name of DSP */ - uint32_t domain_name_len; /** @param[in]: Domain name length, without NULL character */ - uint32_t session_id; /** @param[in]: Session ID of the reserved session. 0 can be used for Default session */ - char *module_uri ; /** @param[in]: URI of the module, found in the auto-generated header file*/ - uint32_t module_uri_len; /** @param[in]: Module URI length, without NULL character */ - char *uri ; /** @param[out]: URI containing module, domain and session. - * Memory for uri need to be pre-allocated with session_uri_len size. - * Typically session_uri_len is 30 characters more than Module URI length. - * If size of uri is beyond session_uri_len, remote_session_control fails with AEE_EBADSIZE - */ - uint32_t uri_len; /** @param[in]: URI length */ + char *domain_name; /** @param[in]: Domain name of DSP */ + uint32_t domain_name_len; /** @param[in]: Domain name length, without + NULL character */ + uint32_t session_id; /** @param[in]: Session ID of the reserved + session. 0 can be used for Default session */ + char *module_uri; /** @param[in]: URI of the module, found in the + auto-generated header file*/ + uint32_t module_uri_len; /** @param[in]: Module URI length, without + NULL character */ + char *uri; /** @param[out]: URI containing module, domain and session. + * Memory for uri need to be pre-allocated with + * session_uri_len size. Typically session_uri_len is 30 + * characters more than Module URI length. If size of uri is + * beyond session_uri_len, remote_session_control fails with + * AEE_EBADSIZE + */ + uint32_t uri_len; /** @param[in]: URI length */ } remote_rpc_get_uri_t; /* struct to be used with FASTRPC_CONTEXT_CREATE request ID */ @@ -603,133 +663,159 @@ typedef struct fastrpc_context_destroy { * Request IDs for remote session control interface **/ enum session_control_req_id { - FASTRPC_RESERVED_1, /** Reserved */ - FASTRPC_THREAD_PARAMS, /** Set thread parameters like priority and stack size */ - DSPRPC_CONTROL_UNSIGNED_MODULE, /** Handle the unsigned module offload request, to be called before remote_handle_open() */ - FASTRPC_RESERVED_2, /** Reserved */ - FASTRPC_RELATIVE_THREAD_PRIORITY, /** To increase/decrease default thread priority */ - FASTRPC_RESERVED_3, /** Reserved */ - FASTRPC_REMOTE_PROCESS_KILL, /** Kill remote process */ - FASTRPC_SESSION_CLOSE, /** Close all open handles of requested domain */ - FASTRPC_CONTROL_PD_DUMP, /** Enable PD dump feature */ - FASTRPC_REMOTE_PROCESS_EXCEPTION, /** Trigger Exception in the remote process */ - FASTRPC_REMOTE_PROCESS_TYPE, /** Query type of process defined by enum fastrpc_process_type */ - FASTRPC_REGISTER_STATUS_NOTIFICATIONS, /** Enable DSP User process status notifications */ - FASTRPC_PD_INITMEM_SIZE, /** Set signed userpd initial memory size **/ - FASTRPC_RESERVE_NEW_SESSION, /** Reserve new FastRPC session **/ - FASTRPC_GET_EFFECTIVE_DOMAIN_ID, /** Get effective domain ID of a FastRPC session */ - FASTRPC_GET_URI, /** Creates the URI needed to load a module in the DSP User PD */ - FASTRPC_MAX_THREAD_PARAM, /** Set max thread value for unsigned PD */ - FASTRPC_CONTEXT_CREATE, /** Create or attaches to remote session(s) on one or more domains */ - FASTRPC_CONTEXT_DESTROY, /** Destroy or detach from remote sessions */ + FASTRPC_RESERVED_1, /** Reserved */ + FASTRPC_THREAD_PARAMS, /** Set thread parameters like priority and + stack size */ + DSPRPC_CONTROL_UNSIGNED_MODULE, /** Handle the unsigned module offload + request, to be called before + remote_handle_open() */ + FASTRPC_RESERVED_2, /** Reserved */ + FASTRPC_RELATIVE_THREAD_PRIORITY, /** To increase/decrease default + thread priority */ + FASTRPC_RESERVED_3, /** Reserved */ + FASTRPC_REMOTE_PROCESS_KILL, /** Kill remote process */ + FASTRPC_SESSION_CLOSE, /** Close all open handles of requested domain + */ + FASTRPC_CONTROL_PD_DUMP, /** Enable PD dump feature */ + FASTRPC_REMOTE_PROCESS_EXCEPTION, /** Trigger Exception in the remote + process */ + FASTRPC_REMOTE_PROCESS_TYPE, /** Query type of process defined by enum + fastrpc_process_type */ + FASTRPC_REGISTER_STATUS_NOTIFICATIONS, /** Enable DSP User process + status notifications */ + FASTRPC_PD_INITMEM_SIZE, /** Set signed userpd initial memory size **/ + FASTRPC_RESERVE_NEW_SESSION, /** Reserve new FastRPC session **/ + FASTRPC_GET_EFFECTIVE_DOMAIN_ID, /** Get effective domain ID of a + FastRPC session */ + FASTRPC_GET_URI, /** Creates the URI needed to load a module in the DSP + User PD */ + FASTRPC_MAX_THREAD_PARAM, /** Set max thread value for unsigned PD */ + FASTRPC_CONTEXT_CREATE, /** Create or attaches to remote session(s) on + one or more domains */ + FASTRPC_CONTEXT_DESTROY, /** Destroy or detach from remote sessions */ }; - /** - * Memory map control flags for using with remote_mem_map() and remote_mem_unmap() + * Memory map control flags for using with remote_mem_map() and + *remote_mem_unmap() **/ enum remote_mem_map_flags { -/** - * Create static memory map on remote process with default cache configuration (writeback). - * Same remoteVirtAddr will be assigned on remote process when fastrpc call made with local virtual address. - * @Map lifetime - * Life time of this mapping is until user unmap using remote_mem_unmap or session close. - * No reference counts are used. Behavior of mapping multiple times without unmap is undefined. - * @Cache maintenance - * Driver clean caches when virtual address passed through RPC calls defined in IDL as a pointer. - * User is responsible for cleaning cache when remoteVirtAddr shared to DSP and accessed out of fastrpc method invocations on DSP. - * @recommended usage - * Map buffers which are reused for long time or until session close. This helps to reduce fastrpc latency. - * Memory shared with remote process and accessed only by DSP. - */ - REMOTE_MAP_MEM_STATIC, + /** + * Create static memory map on remote process with default cache + * configuration (writeback). Same remoteVirtAddr will be assigned on + * remote process when fastrpc call made with local virtual address. + * @Map lifetime + * Life time of this mapping is until user unmap using remote_mem_unmap + * or session close. No reference counts are used. Behavior of mapping + * multiple times without unmap is undefined. + * @Cache maintenance + * Driver clean caches when virtual address passed through RPC calls + * defined in IDL as a pointer. User is responsible for cleaning cache + * when remoteVirtAddr shared to DSP and accessed out of fastrpc method + * invocations on DSP. + * @recommended usage + * Map buffers which are reused for long time or until session close. + * This helps to reduce fastrpc latency. Memory shared with remote + * process and accessed only by DSP. + */ + REMOTE_MAP_MEM_STATIC, -/** Update REMOTE_MAP_MAX_FLAG when adding new value to this enum **/ - }; + /** Update REMOTE_MAP_MAX_FLAG when adding new value to this enum **/ +}; /** * @enum fastrpc_map_flags for fastrpc_mmap and fastrpc_munmap * @brief Types of maps with cache maintenance */ enum fastrpc_map_flags { - /** - * Map memory pages with RW- permission and CACHE WRITEBACK. - * Driver will clean cache when buffer passed in a FastRPC call. - * Same remote virtual address will be assigned for subsequent - * FastRPC calls. - */ - FASTRPC_MAP_STATIC, - - /** Reserved for compatibility with deprecated flag */ - FASTRPC_MAP_RESERVED, - - /** - * Map memory pages with RW- permission and CACHE WRITEBACK. - * Mapping tagged with a file descriptor. User is responsible for - * maintenance of CPU and DSP caches for the buffer. Get virtual address - * of buffer on DSP using HAP_mmap_get() and HAP_mmap_put() functions. - */ - FASTRPC_MAP_FD, - - /** - * Mapping delayed until user calls HAP_mmap() and HAP_munmap() - * functions on DSP. User is responsible for maintenance of CPU and DSP - * caches for the buffer. Delayed mapping is useful for users to map - * buffer on DSP with other than default permissions and cache modes - * using HAP_mmap() and HAP_munmap() functions. - */ - FASTRPC_MAP_FD_DELAYED, - - /** Reserved for compatibility **/ - FASTRPC_MAP_RESERVED_4, - FASTRPC_MAP_RESERVED_5, - FASTRPC_MAP_RESERVED_6, - FASTRPC_MAP_RESERVED_7, - FASTRPC_MAP_RESERVED_8, - FASTRPC_MAP_RESERVED_9, - FASTRPC_MAP_RESERVED_10, - FASTRPC_MAP_RESERVED_11, - FASTRPC_MAP_RESERVED_12, - FASTRPC_MAP_RESERVED_13, - FASTRPC_MAP_RESERVED_14, - FASTRPC_MAP_RESERVED_15, - - /** - * This flag is used to skip CPU mapping, - * otherwise behaves similar to FASTRPC_MAP_FD_DELAYED flag. - */ - FASTRPC_MAP_FD_NOMAP, - - /** Update FASTRPC_MAP_MAX when adding new value to this enum **/ + /** + * Map memory pages with RW- permission and CACHE WRITEBACK. + * Driver will clean cache when buffer passed in a FastRPC call. + * Same remote virtual address will be assigned for subsequent + * FastRPC calls. + */ + FASTRPC_MAP_STATIC, + + /** Reserved for compatibility with deprecated flag */ + FASTRPC_MAP_RESERVED, + + /** + * Map memory pages with RW- permission and CACHE WRITEBACK. + * Mapping tagged with a file descriptor. User is responsible for + * maintenance of CPU and DSP caches for the buffer. Get virtual + * address of buffer on DSP using HAP_mmap_get() and HAP_mmap_put() + * functions. + */ + FASTRPC_MAP_FD, + + /** + * Mapping delayed until user calls HAP_mmap() and HAP_munmap() + * functions on DSP. User is responsible for maintenance of CPU and DSP + * caches for the buffer. Delayed mapping is useful for users to map + * buffer on DSP with other than default permissions and cache modes + * using HAP_mmap() and HAP_munmap() functions. + */ + FASTRPC_MAP_FD_DELAYED, + + /** Reserved for compatibility **/ + FASTRPC_MAP_RESERVED_4, + FASTRPC_MAP_RESERVED_5, + FASTRPC_MAP_RESERVED_6, + FASTRPC_MAP_RESERVED_7, + FASTRPC_MAP_RESERVED_8, + FASTRPC_MAP_RESERVED_9, + FASTRPC_MAP_RESERVED_10, + FASTRPC_MAP_RESERVED_11, + FASTRPC_MAP_RESERVED_12, + FASTRPC_MAP_RESERVED_13, + FASTRPC_MAP_RESERVED_14, + FASTRPC_MAP_RESERVED_15, + + /** + * This flag is used to skip CPU mapping, + * otherwise behaves similar to FASTRPC_MAP_FD_DELAYED flag. + */ + FASTRPC_MAP_FD_NOMAP, + + /** Update FASTRPC_MAP_MAX when adding new value to this enum **/ }; /** * Attributes for remote_register_buf_attr **/ -#define FASTRPC_ATTR_NONE 0 /** No attribute to set.*/ -#define FASTRPC_ATTR_NON_COHERENT 2 /** Attribute to map a buffer as dma non-coherent, - Driver perform cache maintenance.*/ -#define FASTRPC_ATTR_COHERENT 4 /** Attribute to map a buffer as dma coherent, - Driver skips cache maintenenace - It will be ignored if a device is marked as dma-coherent in device tree.*/ -#define FASTRPC_ATTR_KEEP_MAP 8 /** Attribute to keep the buffer persistant - until unmap is called explicitly.*/ -#define FASTRPC_ATTR_NOMAP 16 /** Attribute for secure buffers to skip - smmu mapping in fastrpc driver*/ -#define FASTRPC_ATTR_FORCE_NOFLUSH 32 /** Attribute to map buffer such that flush by driver is skipped for that particular buffer - client has to perform cache maintenance*/ -#define FASTRPC_ATTR_FORCE_NOINVALIDATE 64 /** Attribute to map buffer such that invalidate by driver is skipped for that particular buffer - client has to perform cache maintenance */ -#define FASTRPC_ATTR_TRY_MAP_STATIC 128 /** Attribute for persistent mapping a buffer - to remote DSP process during buffer registration - with FastRPC driver. This buffer will be automatically - mapped during fastrpc session open and unmapped either - at unregister or session close. FastRPC library tries - to map buffers and ignore errors in case of failure. - pre-mapping a buffer reduces the FastRPC latency. - This flag is recommended only for buffers used with - latency critical rpc calls */ - +#define FASTRPC_ATTR_NONE 0 /** No attribute to set.*/ +#define FASTRPC_ATTR_NON_COHERENT \ + 2 /** Attribute to map a buffer as dma non-coherent, \ + Driver perform cache maintenance.*/ +#define FASTRPC_ATTR_COHERENT \ + 4 /** Attribute to map a buffer as dma coherent, \ + Driver skips cache maintenenace \ + It will be ignored if a device is marked as dma-coherent in \ + device tree.*/ +#define FASTRPC_ATTR_KEEP_MAP \ + 8 /** Attribute to keep the buffer persistant \ + until unmap is called explicitly.*/ +#define FASTRPC_ATTR_NOMAP \ + 16 /** Attribute for secure buffers to skip \ + smmu mapping in fastrpc driver*/ +#define FASTRPC_ATTR_FORCE_NOFLUSH \ + 32 /** Attribute to map buffer such that flush by driver is skipped \ + for that particular buffer client has to perform cache \ + maintenance*/ +#define FASTRPC_ATTR_FORCE_NOINVALIDATE \ + 64 /** Attribute to map buffer such that invalidate by driver is \ + skipped for that particular buffer client has to perform cache \ + maintenance */ +#define FASTRPC_ATTR_TRY_MAP_STATIC \ + 128 /** Attribute for persistent mapping a buffer \ + to remote DSP process during buffer registration \ + with FastRPC driver. This buffer will be automatically \ + mapped during fastrpc session open and unmapped either \ + at unregister or session close. FastRPC library tries \ + to map buffers and ignore errors in case of failure. \ + pre-mapping a buffer reduces the FastRPC latency. \ + This flag is recommended only for buffers used with \ + latency critical rpc calls */ /** * REMOTE_MODE_PARALLEL used with remote_set_mode @@ -739,7 +825,7 @@ enum fastrpc_map_flags { * dsp processing the call. This mode should be used when output buffers * are only read on the application processor and only written on the aDSP. */ -#define REMOTE_MODE_PARALLEL 0 +#define REMOTE_MODE_PARALLEL 0 /** * REMOTE_MODE_SERIAL used with remote_set_mode @@ -747,8 +833,7 @@ enum fastrpc_map_flags { * before calling into the dsp. This mode should be used when output * buffers have been written to somewhere besides the aDSP. */ -#define REMOTE_MODE_SERIAL 1 - +#define REMOTE_MODE_SERIAL 1 #ifdef _WIN32 #include "remote_ext.h" /** For function pointers of remote APIs */ @@ -757,16 +842,18 @@ enum fastrpc_map_flags { /** * Opens a remote handle to a DSP module for FastRPC communication * - * NOTE: This function should not be called directly from applications. It is automatically - * called by the stub functions generated by the QAIC compiler from IDL files. Applications - * should use the generated stub functions instead. + * NOTE: This function should not be called directly from applications. It is + * automatically called by the stub functions generated by the QAIC compiler + * from IDL files. Applications should use the generated stub functions + * instead. * - * This function creates a handle to communicate with a module running on the DSP. The handle - * can be used to invoke remote functions defined in the module's IDL interface. + * This function creates a handle to communicate with a module running on the + * DSP. The handle can be used to invoke remote functions defined in the + * module's IDL interface. + * + * @param name [in] URI of the module to open, found in the auto-generated + * header file. Format: "uri:module[;option1=value1][;option2=value2]..." * - * @param name [in] URI of the module to open, found in the auto-generated header file. - * Format: "uri:module[;option1=value1][;option2=value2]..." - * * Available URI options: * - _domain=: Specify target DSP domain * Values: adsp, cdsp, sdsp @@ -774,14 +861,14 @@ enum fastrpc_map_flags { * - _session=: Session ID for multi-session support * - _sgver=: Interface version requirement * - _trace=: Enable tracing (1-3) - * + * * Example URIs: * "uri:libexample.so;_domain=adsp" * "uri:libfoo.so;_domain=cdsp;_session=1;_trace=2" * - * @param ph [out] Pointer to store the opened remote handle. This handle should be used in - * subsequent remote_handle_invoke() calls and must be closed using - * remote_handle_close() when no longer needed. + * @param ph [out] Pointer to store the opened remote handle. This handle + * should be used in subsequent remote_handle_invoke() calls and must be closed + * using remote_handle_close() when no longer needed. * * @return 0 on success, otherwise error code: * - AEE_EINVALIDFORMAT: Invalid URI format @@ -795,38 +882,46 @@ enum fastrpc_map_flags { * @note The opened handle is only valid for the current process and cannot be * shared across processes. Each process needs to open its own handle. * - * @note For unsigned modules, DSPRPC_CONTROL_UNSIGNED_MODULE must be called via - * remote_session_control() before opening the handle. + * @note For unsigned modules, DSPRPC_CONTROL_UNSIGNED_MODULE must be called + * via remote_session_control() before opening the handle. * * @note This API is not thread-safe. The caller must ensure thread-safety when * opening/closing handles from multiple threads. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_open)(__QAIC_IN_CHAR const char* name, __QAIC_OUT remote_handle *ph) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_open)( __QAIC_IN_CHAR const char* name, __QAIC_OUT remote_handle64 *ph) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_open)( + __QAIC_IN_CHAR const char *name, + __QAIC_OUT remote_handle *ph) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_open)( + __QAIC_IN_CHAR const char *name, + __QAIC_OUT remote_handle64 *ph) __QAIC_REMOTE_ATTRIBUTE; /** * Invokes a remote function on the DSP through a FastRPC handle * - * NOTE: This function should not be called directly from applications. It is automatically - * called by the stub functions generated by the QAIC compiler from IDL files. Applications - * should use the generated stub functions instead. + * NOTE: This function should not be called directly from applications. It is + * automatically called by the stub functions generated by the QAIC compiler + * from IDL files. Applications should use the generated stub functions + * instead. * - * This function invokes a remote function defined in the module's IDL interface using - * the handle opened via remote_handle_open(). + * This function invokes a remote function defined in the module's IDL + * interface using the handle opened via remote_handle_open(). * * @param h [in] Remote handle obtained from remote_handle_open() - * - * @param dwScalars [in] Scalar value encoding the number and types of arguments: - * - REMOTE_SCALARS_INBUFS(sc): Number of input buffers - * - REMOTE_SCALARS_OUTBUFS(sc): Number of output buffers - * - REMOTE_SCALARS_INHANDLES(sc): Number of input handles - * - REMOTE_SCALARS_OUTHANDLES(sc): Number of output handles * - * @param pra [in] Array of remote_arg structures containing the arguments in order: + * @param dwScalars [in] Scalar value encoding the number and types of + * arguments: + * - REMOTE_SCALARS_INBUFS(sc): Number of input buffers + * - REMOTE_SCALARS_OUTBUFS(sc): Number of output buffers + * - REMOTE_SCALARS_INHANDLES(sc): Number of input + * handles + * - REMOTE_SCALARS_OUTHANDLES(sc): Number of output + * handles + * + * @param pra [in] Array of remote_arg structures containing the arguments in + * order: * 1. Input buffers * 2. Output buffers - * 3. Input handles + * 3. Input handles * 4. Output handles * Each remote_arg contains: * - buf.pv: Pointer to buffer data @@ -840,21 +935,24 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_open)( __QA * - AEE_ECONNREFUSED: Connection to DSP failed * - AEE_ETIMEOUT: RPC call timed out * - * @note This API is thread-safe and can be called concurrently from multiple threads - * using the same handle. + * @note This API is thread-safe and can be called concurrently from multiple + * threads using the same handle. * - * @note For output buffers, the caller must ensure sufficient buffer size is allocated - * before making the RPC call. + * @note For output buffers, the caller must ensure sufficient buffer size is + * allocated before making the RPC call. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_invoke)(__QAIC_IN remote_handle h, __QAIC_IN uint32_t dwScalars, __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_invoke)(__QAIC_IN remote_handle64 h, __QAIC_IN uint32_t dwScalars, __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_invoke)( + __QAIC_IN remote_handle h, __QAIC_IN uint32_t dwScalars, + __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_invoke)( + __QAIC_IN remote_handle64 h, __QAIC_IN uint32_t dwScalars, + __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; /** * Closes a remote handle previously opened with remote_handle_open() * - * This function closes the remote handle and frees any associated resources. The handle - * becomes invalid after this call and should not be used again. + * This function closes the remote handle and frees any associated resources. + * The handle becomes invalid after this call and should not be used again. * * @param h [in] Remote handle to close, obtained from remote_handle_open() * @@ -863,93 +961,113 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_invoke)(__Q * - AEE_EBUSY: Handle is still in use by pending operations * - AEE_EFAILED: Internal error occurred during cleanup * - * @note This API is thread-safe but should not be called while other threads are - * using the same handle for RPC operations. + * @note This API is thread-safe but should not be called while other threads + * are using the same handle for RPC operations. * - * @note All open handles should be closed when no longer needed to avoid resource leaks. - * Handles are not automatically closed when the process exits. + * @note All open handles should be closed when no longer needed to avoid + * resource leaks. Handles are not automatically closed when the process exits. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_close)(__QAIC_IN remote_handle h) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_close)(__QAIC_IN remote_handle64 h) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_close)( + __QAIC_IN remote_handle h) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_close)( + __QAIC_IN remote_handle64 h) __QAIC_REMOTE_ATTRIBUTE; /** * Sets control parameters for remote handle operations * - * This function allows configuring various control parameters for remote handle operations - * like latency requirements, wake lock control, domain info etc. + * This function allows configuring various control parameters for remote + * handle operations like latency requirements, wake lock control, domain info + * etc. * - * @param req [in] Request ID specifying the control parameter to set, defined in enum handle_control_req_id: + * @param req [in] Request ID specifying the control parameter to set, defined + * in enum handle_control_req_id: * - DSPRPC_CONTROL_LATENCY: Configure latency requirements * - DSPRPC_CONTROL_WAKELOCK: Enable/disable wake lock control * - DSPRPC_GET_DOMAIN: Get domain ID for a handle * See handle_control_req_id enum for full list * - * @param data [in] Pointer to request-specific data structure containing parameters: - * - For DSPRPC_CONTROL_LATENCY: struct remote_rpc_control_latency - * - For DSPRPC_CONTROL_WAKELOCK: struct remote_rpc_control_wakelock + * @param data [in] Pointer to request-specific data structure containing + * parameters: + * - For DSPRPC_CONTROL_LATENCY: struct + * remote_rpc_control_latency + * - For DSPRPC_CONTROL_WAKELOCK: struct + * remote_rpc_control_wakelock * - For DSPRPC_GET_DOMAIN: struct remote_rpc_get_domain * Structure must match the request ID * * @param datalen [in] Size of the data structure in bytes * * @return 0 on success, otherwise error code: - * - AEE_EBADPARM: Invalid parameters (NULL data pointer, invalid datalen) + * - AEE_EBADPARM: Invalid parameters (NULL data pointer, invalid + * datalen) * - AEE_EUNSUPPORTED: Request ID not supported * - AEE_EFAILED: Internal error occurred * - Request-specific error codes * - * @note This API is thread-safe and can be called concurrently from multiple threads + * @note This API is thread-safe and can be called concurrently from multiple + * threads */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_control)(__QAIC_IN uint32_t req, __QAIC_IN_LEN(datalen) void* data, __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_control)(__QAIC_IN remote_handle64 h, __QAIC_IN uint32_t req, __QAIC_IN_LEN(datalen) void* data, __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_control)( + __QAIC_IN uint32_t req, __QAIC_IN_LEN(datalen) void *data, + __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_control)( + __QAIC_IN remote_handle64 h, __QAIC_IN uint32_t req, + __QAIC_IN_LEN(datalen) void *data, + __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; /** * Sets control parameters for remote sessions * - * This function allows configuring various control parameters for remote sessions - * like process lifecycle, thread parameters, session management etc. + * This function allows configuring various control parameters for remote + * sessions like process lifecycle, thread parameters, session management etc. * - * @param req [in] Request ID specifying the control parameter to set, defined in enum session_control_req_id: + * @param req [in] Request ID specifying the control parameter to set, defined + * in enum session_control_req_id: * - FASTRPC_THREAD_PARAMS: Set thread priority and stack size * - FASTRPC_REMOTE_PROCESS_KILL: Kill remote process * - FASTRPC_SESSION_CLOSE: Close all open handles for a domain * - FASTRPC_RESERVE_NEW_SESSION: Reserve a new FastRPC session * See session_control_req_id enum for full list * - * @param data [in] Pointer to request-specific data structure containing parameters: - * - For FASTRPC_THREAD_PARAMS: struct remote_rpc_thread_params - * - For FASTRPC_REMOTE_PROCESS_KILL: struct remote_rpc_process_kill - * - For FASTRPC_RESERVE_NEW_SESSION: struct remote_rpc_control_session - * Structure must match the request ID + * @param data [in] Pointer to request-specific data structure containing + * parameters: + * - For FASTRPC_THREAD_PARAMS: struct + * remote_rpc_thread_params + * - For FASTRPC_REMOTE_PROCESS_KILL: struct + * remote_rpc_process_kill + * - For FASTRPC_RESERVE_NEW_SESSION: struct + * remote_rpc_control_session Structure must match the request ID * * @param datalen [in] Size of the data structure in bytes * * @return 0 on success, otherwise error code: - * - AEE_EBADPARM: Invalid parameters (NULL data pointer, invalid datalen) + * - AEE_EBADPARM: Invalid parameters (NULL data pointer, invalid + * datalen) * - AEE_ENOSUCH: Process/session not found * - AEE_EINVALIDDOMAIN: Invalid domain ID specified * - Other error codes returned from FastRPC framework * - * @note This API is thread-safe and can be called concurrently from multiple threads + * @note This API is thread-safe and can be called concurrently from multiple + * threads */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_session_control)(__QAIC_IN uint32_t req, __QAIC_IN_LEN(datalen) void *data, __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_session_control)( + __QAIC_IN uint32_t req, __QAIC_IN_LEN(datalen) void *data, + __QAIC_IN uint32_t datalen) __QAIC_REMOTE_ATTRIBUTE; /** * Invokes a remote handle asynchronously * - * This function allows asynchronous invocation of remote methods, providing non-blocking - * execution and callback mechanisms. + * This function allows asynchronous invocation of remote methods, providing + * non-blocking execution and callback mechanisms. * * @param h [in] Remote handle obtained from remote_handle_open() * * @param desc [in] Async descriptor containing: - * - type: Type of async job (FASTRPC_ASYNC_NO_SYNC, FASTRPC_ASYNC_CALLBACK) + * - type: Type of async job (FASTRPC_ASYNC_NO_SYNC, + * FASTRPC_ASYNC_CALLBACK) * - context: User context passed to callback - * - cb: Callback function and arguments (for FASTRPC_ASYNC_CALLBACK type) - * See fastrpc_async_descriptor_t for details + * - cb: Callback function and arguments (for + * FASTRPC_ASYNC_CALLBACK type) See fastrpc_async_descriptor_t for details * * @param dwScalars [in] Method invocation parameters encoded as scalar value: * - Number of input/output buffers @@ -971,26 +1089,37 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_session_control)(__Q * - Other error codes from FastRPC framework * * @note The async job status can be queried using fastrpc_async_get_status() - * @note Resources must be released using fastrpc_release_async_job() after completion + * @note Resources must be released using fastrpc_release_async_job() after + * completion */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle_invoke_async)(__QAIC_IN remote_handle h, __QAIC_IN fastrpc_async_descriptor_t *desc, __QAIC_IN uint32_t dwScalars, __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_invoke_async)(__QAIC_IN remote_handle64 h, __QAIC_IN fastrpc_async_descriptor_t *desc, __QAIC_IN uint32_t dwScalars, __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int + __QAIC_REMOTE(remote_handle_invoke_async)( + __QAIC_IN remote_handle h, __QAIC_IN fastrpc_async_descriptor_t *desc, + __QAIC_IN uint32_t dwScalars, + __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int + __QAIC_REMOTE(remote_handle64_invoke_async)( + __QAIC_IN remote_handle64 h, + __QAIC_IN fastrpc_async_descriptor_t *desc, + __QAIC_IN uint32_t dwScalars, + __QAIC_IN remote_arg *pra) __QAIC_REMOTE_ATTRIBUTE; /** * Gets the status and result of an asynchronous FastRPC job * - * This function allows checking the completion status of an asynchronous FastRPC job - * and retrieving its result. It can be configured to wait for job completion with - * different timeout behaviors. + * This function allows checking the completion status of an asynchronous + * FastRPC job and retrieving its result. It can be configured to wait for job + * completion with different timeout behaviors. * - * @param jobid [in] Job ID returned by remote_handle_invoke_async() when submitting - * the asynchronous job + * @param jobid [in] Job ID returned by remote_handle_invoke_async() when + * submitting the asynchronous job * * @param timeout_us [in] Timeout value in microseconds: * - 0: Returns immediately with current status/result - * - Positive value: Waits up to specified microseconds for completion - * - Negative value: Waits indefinitely until job completes + * - Positive value: Waits up to specified microseconds + * for completion + * - Negative value: Waits indefinitely until job + * completes * * @param result [out] Pointer to store the job result: * - 0 if job completed successfully @@ -1002,47 +1131,54 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_handle64_invoke_asyn * - AEE_EBADPARM: Invalid job ID provided * - AEE_EFAILED: Internal FastRPC framework error * - * @note After job completion, resources must be released using fastrpc_release_async_job() - * @note This function is thread-safe and can be called concurrently from multiple threads + * @note After job completion, resources must be released using + * fastrpc_release_async_job() + * @note This function is thread-safe and can be called concurrently from + * multiple threads */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_async_get_status)(__QAIC_IN fastrpc_async_jobid jobid,__QAIC_IN int timeout_us,__QAIC_OUT int *result); - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_async_get_status)( + __QAIC_IN fastrpc_async_jobid jobid, __QAIC_IN int timeout_us, + __QAIC_OUT int *result); /** * Releases resources associated with an asynchronous FastRPC job * - * This function must be called after an asynchronous job completes to free associated - * resources and cleanup internal state. It should only be called after receiving job - * completion status either through: + * This function must be called after an asynchronous job completes to free + * associated resources and cleanup internal state. It should only be called + * after receiving job completion status either through: * - Callback notification (for FASTRPC_ASYNC_CALLBACK jobs) * - Polling via fastrpc_async_get_status() (for FASTRPC_ASYNC_POLL jobs) * - * @param jobid [in] Job ID returned by remote_handle_invoke_async() when submitting - * the asynchronous job + * @param jobid [in] Job ID returned by remote_handle_invoke_async() when + * submitting the asynchronous job * * @return 0 on success, otherwise error code: * - AEE_EBUSY: Job is still pending and has not completed yet * - AEE_EBADPARM: Invalid job ID provided * - AEE_EFAILED: Internal FastRPC framework error * - * @note This function is thread-safe and can be called concurrently from multiple threads + * @note This function is thread-safe and can be called concurrently from + * multiple threads * @note Calling this function before job completion will return AEE_EBUSY - * @note Resources must be released exactly once per async job to avoid memory leaks + * @note Resources must be released exactly once per async job to avoid memory + * leaks */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_release_async_job)(__QAIC_IN fastrpc_async_jobid jobid); - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE( + fastrpc_release_async_job)(__QAIC_IN fastrpc_async_jobid jobid); /** * DEPRECATED: Use fastrpc_mmap() instead. - * - * Maps memory to the remote domain. This function is limited to 32-bit addresses and - * provides basic mapping functionality without cache configuration control. - * - * @param fd [in] File descriptor associated with the memory to be mapped. Must be a valid - * DMA buffer file descriptor. - * @param flags [in] Mapping flags. Currently only REMOTE_MAP_MEM_STATIC is supported. - * @param vaddrin [in] Input virtual address on CPU side. Must be the address returned by - * mmap() when mapping the DMA fd. + * + * Maps memory to the remote domain. This function is limited to 32-bit + * addresses and provides basic mapping functionality without cache + * configuration control. + * + * @param fd [in] File descriptor associated with the memory to be mapped. Must + * be a valid DMA buffer file descriptor. + * @param flags [in] Mapping flags. Currently only REMOTE_MAP_MEM_STATIC is + * supported. + * @param vaddrin [in] Input virtual address on CPU side. Must be the address + * returned by mmap() when mapping the DMA fd. * @param size [in] Size of buffer in bytes to map. Must be page aligned (4KB). * @param vaddrout [out] Pointer to store the mapped address on remote domain. * @@ -1054,18 +1190,19 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_release_async_job)( * Use fastrpc_mmap() instead which provides 64-bit address support and * better cache configuration control. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap)(__QAIC_IN int fd, __QAIC_IN uint32_t flags, __QAIC_IN uint32_t vaddrin, __QAIC_IN int size, __QAIC_OUT uint32_t* vaddrout) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap)( + __QAIC_IN int fd, __QAIC_IN uint32_t flags, __QAIC_IN uint32_t vaddrin, + __QAIC_IN int size, __QAIC_OUT uint32_t *vaddrout) __QAIC_REMOTE_ATTRIBUTE; /** * DEPRECATED: Use fastrpc_munmap() instead. - * + * * Unmaps memory previously mapped using remote_mmap() from the remote domain. * This function is limited to 32-bit addresses. * * @param vaddrout [in] Remote virtual address returned by remote_mmap() - * @param size [in] Size of buffer to unmap in bytes. Must match the size used in remote_mmap(). - * Partial unmapping is not supported. + * @param size [in] Size of buffer to unmap in bytes. Must match the size used + * in remote_mmap(). Partial unmapping is not supported. * * @return 0 on success, error code on failure: * AEE_EBADPARM - Invalid parameters @@ -1075,43 +1212,52 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap)(__QAIC_IN int * @note This API is deprecated and will be removed in a future release. * Use fastrpc_munmap() instead which provides 64-bit address support. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_munmap)(__QAIC_IN uint32_t vaddrout, __QAIC_IN int size) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int + __QAIC_REMOTE(remote_munmap)(__QAIC_IN uint32_t vaddrout, + __QAIC_IN int size) __QAIC_REMOTE_ATTRIBUTE; /** * DEPRECATED: Use fastrpc_mmap() instead. - * - * Maps memory to a specific remote domain process. This function provides more control - * over domain selection compared to remote_mmap(). * - * @param domain [in] DSP domain ID to map memory to. Use -1 for default domain based on - * linked library (lib(a/m/s/c)dsprpc.so). - * Valid domains: ADSP_DOMAIN_ID, MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, GDSP_DOMAIN_ID + * Maps memory to a specific remote domain process. This function provides more + * control over domain selection compared to remote_mmap(). + * + * @param domain [in] DSP domain ID to map memory to. Use -1 for default domain + * based on linked library (lib(a/m/s/c)dsprpc.so). Valid domains: + * ADSP_DOMAIN_ID, MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, + * GDSP_DOMAIN_ID * @param fd [in] File descriptor of DMA memory to map * @param flags [in] Mapping flags from enum remote_mem_map_flags * @param virtAddr [in] Virtual address of buffer on CPU side * @param size [in] Size of buffer in bytes to map - * @param remoteVirtAddr [out] Pointer to store the mapped address on remote domain + * @param remoteVirtAddr [out] Pointer to store the mapped address on remote + * domain * * @return 0 on success, error code on failure: * AEE_EBADPARM - Invalid parameters * AEE_EFAILED - Internal mapping failure * * @note This API is deprecated and will be removed in a future release. - * Use fastrpc_mmap() instead which provides better cache configuration control. + * Use fastrpc_mmap() instead which provides better cache configuration + * control. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mem_map)(__QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN int flags, __QAIC_IN uint64_t virtAddr, __QAIC_IN size_t size, __QAIC_OUT uint64_t* remoteVirtAddr) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mem_map)( + __QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN int flags, + __QAIC_IN uint64_t virtAddr, __QAIC_IN size_t size, + __QAIC_OUT uint64_t *remoteVirtAddr) __QAIC_REMOTE_ATTRIBUTE; /** * DEPRECATED: Use fastrpc_munmap() instead. - * - * Unmaps memory previously mapped using remote_mem_map() from a specific remote domain process. * - * @param domain [in] DSP domain ID to unmap memory from. Use -1 for default domain. - * Must match domain used in remote_mem_map(). - * @param remoteVirtAddr [in] Remote virtual address returned by remote_mem_map() - * @param size [in] Size of buffer in bytes to unmap. Must match size used in remote_mem_map(). + * Unmaps memory previously mapped using remote_mem_map() from a specific + * remote domain process. + * + * @param domain [in] DSP domain ID to unmap memory from. Use -1 for default + * domain. Must match domain used in remote_mem_map(). + * @param remoteVirtAddr [in] Remote virtual address returned by + * remote_mem_map() + * @param size [in] Size of buffer in bytes to unmap. Must match size used in + * remote_mem_map(). * * @return 0 on success, error code on failure: * AEE_EBADPARM - Invalid parameters @@ -1119,41 +1265,49 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mem_map)(__QAIC_IN i * AEE_EBUSY - Memory is still in use and cannot be unmapped * * @note This API is deprecated and will be removed in a future release. - * Use fastrpc_munmap() instead which provides better integration with the FastRPC framework. + * Use fastrpc_munmap() instead which provides better integration with + * the FastRPC framework. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mem_unmap)(__QAIC_IN int domain, __QAIC_IN uint64_t remoteVirtAddr, __QAIC_IN size_t size) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mem_unmap)( + __QAIC_IN int domain, __QAIC_IN uint64_t remoteVirtAddr, + __QAIC_IN size_t size) __QAIC_REMOTE_ATTRIBUTE; /** * DEPRECATED: Use fastrpc_mmap() instead. - * - * Maps memory to the remote domain with 64-bit address support. This is the 64-bit - * version of remote_mmap(). + * + * Maps memory to the remote domain with 64-bit address support. This is the + * 64-bit version of remote_mmap(). * * @param fd [in] File descriptor associated with the memory to be mapped - * @param flags [in] Mapping flags. Currently only REMOTE_MAP_MEM_STATIC is supported. + * @param flags [in] Mapping flags. Currently only REMOTE_MAP_MEM_STATIC is + * supported. * @param vaddrin [in] Input virtual address on CPU side (64-bit) * @param size [in] Size of buffer in bytes to map - * @param vaddrout [out] Pointer to store the mapped address on remote domain (64-bit) + * @param vaddrout [out] Pointer to store the mapped address on remote domain + * (64-bit) * * @return 0 on success, error code on failure: * AEE_EBADPARM - Invalid parameters * AEE_EFAILED - Internal mapping failure * * @note This API is deprecated and will be removed in a future release. - * Use fastrpc_mmap() instead which provides better cache configuration control. + * Use fastrpc_mmap() instead which provides better cache configuration + * control. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap64)(__QAIC_IN int fd, __QAIC_IN uint32_t flags, __QAIC_IN __QAIC_INT64PTR vaddrin, __QAIC_IN int64_t size, __QAIC_OUT __QAIC_INT64PTR *vaddrout) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap64)( + __QAIC_IN int fd, __QAIC_IN uint32_t flags, + __QAIC_IN __QAIC_INT64PTR vaddrin, __QAIC_IN int64_t size, + __QAIC_OUT __QAIC_INT64PTR *vaddrout) __QAIC_REMOTE_ATTRIBUTE; /** * DEPRECATED: Use fastrpc_munmap() instead. - * - * Unmaps memory previously mapped using remote_mmap64() from the remote domain. - * This is the 64-bit version of remote_munmap(). + * + * Unmaps memory previously mapped using remote_mmap64() from the remote + * domain. This is the 64-bit version of remote_munmap(). * * @param vaddrout [in] Remote virtual address returned by remote_mmap64() - * @param size [in] Size of buffer to unmap in bytes. Must match size used in remote_mmap64(). + * @param size [in] Size of buffer to unmap in bytes. Must match size used in + * remote_mmap64(). * * @return 0 on success, error code on failure: * AEE_EBADPARM - Invalid parameters @@ -1161,86 +1315,104 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_mmap64)(__QAIC_IN in * AEE_EBUSY - Memory is still in use and cannot be unmapped * * @note This API is deprecated and will be removed in a future release. - * Use fastrpc_munmap() instead which provides better integration with the FastRPC framework. + * Use fastrpc_munmap() instead which provides better integration with + * the FastRPC framework. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_munmap64)(__QAIC_IN __QAIC_INT64PTR vaddrout, __QAIC_IN int64_t size) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_munmap64)( + __QAIC_IN __QAIC_INT64PTR vaddrout, + __QAIC_IN int64_t size) __QAIC_REMOTE_ATTRIBUTE; /** * fastrpc_mmap - * Creates a mapping on remote process for a DMA buffer with file descriptor. New fastrpc session - * will be opened if not already opened for the domain. This API maps the buffer with RW- permission - * and CACHE WRITEBACK configuration. Driver will clean cache when buffer is passed in a FastRPC call. - * - * @param domain [in] DSP domain ID of a fastrpc session. Use -1 for default domain based on linked library. - * Valid domains are ADSP_DOMAIN_ID, MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID. - * @param fd [in] DMA memory file descriptor obtained from dma_alloc_fd() or similar DMA allocation APIs. - * @param addr [in] Virtual address of the buffer on CPU side. Must be the same address returned by mmap() - * when mapping the DMA fd. - * @param offset [in] Offset from the beginning of the buffer. Must be page aligned (4KB). - * @param length [in] Size of buffer in bytes to map. Must be page aligned (4KB). - * @param flags [in] Controls mapping functionality on DSP. See enum fastrpc_map_flags for valid flags: - * FASTRPC_MAP_CACHE_WRITEBACK - Map with writeback cache configuration (default) - * FASTRPC_MAP_CACHE_WRITETHROUGH - Map with writethrough cache configuration - * FASTRPC_MAP_CACHE_UNCACHED - Map as uncached memory - * FASTRPC_MAP_CACHE_NONCACHED - Map as non-cached memory + * Creates a mapping on remote process for a DMA buffer with file descriptor. + * New fastrpc session will be opened if not already opened for the domain. + * This API maps the buffer with RW- permission and CACHE WRITEBACK + * configuration. Driver will clean cache when buffer is passed in a FastRPC + * call. + * + * @param domain [in] DSP domain ID of a fastrpc session. Use -1 for default + * domain based on linked library. Valid domains are ADSP_DOMAIN_ID, + * MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID. + * @param fd [in] DMA memory file descriptor obtained from dma_alloc_fd() or + * similar DMA allocation APIs. + * @param addr [in] Virtual address of the buffer on CPU side. Must be the same + * address returned by mmap() when mapping the DMA fd. + * @param offset [in] Offset from the beginning of the buffer. Must be page + * aligned (4KB). + * @param length [in] Size of buffer in bytes to map. Must be page aligned + * (4KB). + * @param flags [in] Controls mapping functionality on DSP. See enum + * fastrpc_map_flags for valid flags: FASTRPC_MAP_CACHE_WRITEBACK - Map with + * writeback cache configuration (default) FASTRPC_MAP_CACHE_WRITETHROUGH - Map + * with writethrough cache configuration FASTRPC_MAP_CACHE_UNCACHED - Map as + * uncached memory FASTRPC_MAP_CACHE_NONCACHED - Map as non-cached memory * * @return 0 on success, error code on failure: - * AEE_EALREADY - Buffer already mapped. Multiple mappings for same buffer not supported. - * AEE_EBADPARM - Invalid parameters (null pointers, unaligned sizes, etc) - * AEE_EFAILED - Failed to map buffer (internal driver error) - * AEE_ENOMEMORY - Out of memory in driver - * AEE_EUNSUPPORTED - API not supported on target DSP + * AEE_EALREADY - Buffer already mapped. Multiple mappings for same + * buffer not supported. AEE_EBADPARM - Invalid parameters (null pointers, + * unaligned sizes, etc) AEE_EFAILED - Failed to map buffer (internal driver + * error) AEE_ENOMEMORY - Out of memory in driver AEE_EUNSUPPORTED - API not + * supported on target DSP * * @note This API must be called before using the buffer in any FastRPC calls. * The mapping persists until explicitly unmapped via fastrpc_munmap() or * the fastrpc session is closed. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_mmap)(__QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN void *addr, __QAIC_IN int offset, __QAIC_IN size_t length, __QAIC_IN enum fastrpc_map_flags flags)__QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_mmap)( + __QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN void *addr, + __QAIC_IN int offset, __QAIC_IN size_t length, + __QAIC_IN enum fastrpc_map_flags flags) __QAIC_REMOTE_ATTRIBUTE; /** * fastrpc_munmap - * Removes a mapping created by fastrpc_mmap() for a DMA buffer on the remote process. - * The mapping must be removed before closing the DMA file descriptor. - * - * @param domain [in] DSP domain ID of a fastrpc session. Use -1 for default domain based on linked library. - * Valid domains are ADSP_DOMAIN_ID, MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID. - * @param fd [in] DMA memory file descriptor that was used to create the mapping. - * @param addr [in] Virtual address of the buffer on CPU side. Must match the address used in fastrpc_mmap(). - * @param length [in] Size of buffer in bytes to unmap. Must match the length used in fastrpc_mmap(). + * Removes a mapping created by fastrpc_mmap() for a DMA buffer on the remote + * process. The mapping must be removed before closing the DMA file descriptor. + * + * @param domain [in] DSP domain ID of a fastrpc session. Use -1 for default + * domain based on linked library. Valid domains are ADSP_DOMAIN_ID, + * MDSP_DOMAIN_ID, SDSP_DOMAIN_ID, CDSP_DOMAIN_ID, or GDSP_DOMAIN_ID. + * @param fd [in] DMA memory file descriptor that was used to create the + * mapping. + * @param addr [in] Virtual address of the buffer on CPU side. Must match the + * address used in fastrpc_mmap(). + * @param length [in] Size of buffer in bytes to unmap. Must match the length + * used in fastrpc_mmap(). * * @return 0 on success, error code on failure: - * AEE_EBADPARM - Invalid parameters (null pointers, unaligned sizes, etc) - * AEE_EINVALIDFD - No mapping found for the specified file descriptor + * AEE_EBADPARM - Invalid parameters (null pointers, unaligned sizes, + * etc) AEE_EINVALIDFD - No mapping found for the specified file descriptor * AEE_EFAILED - Failed to unmap buffer (internal driver error) * AEE_EUNSUPPORTED - API not supported on target DSP * - * @note This API must be called to cleanup mappings before closing DMA file descriptors. - * Failing to unmap can lead to resource leaks in the driver. + * @note This API must be called to cleanup mappings before closing DMA file + * descriptors. Failing to unmap can lead to resource leaks in the driver. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_munmap)(__QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN void *addr, __QAIC_IN size_t length)__QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_munmap)( + __QAIC_IN int domain, __QAIC_IN int fd, __QAIC_IN void *addr, + __QAIC_IN size_t length) __QAIC_REMOTE_ATTRIBUTE; /** * remote_register_buf/remote_register_buf_attr - * Register a file descriptor for a buffer to enable zero-copy sharing with DSP via SMMU. - * - * These functions are thread-safe and can be called from multiple threads concurrently. - * However, registering/deregistering the same buffer from different threads simultaneously - * is not supported and will lead to undefined behavior. + * Register a file descriptor for a buffer to enable zero-copy sharing with DSP + * via SMMU. + * + * These functions are thread-safe and can be called from multiple threads + * concurrently. However, registering/deregistering the same buffer from + * different threads simultaneously is not supported and will lead to undefined + * behavior. * - * @note These APIs are limited to buffers < 2GB in size. For larger buffers, use - * remote_register_buf_attr2 which supports 64-bit sizes. + * @note These APIs are limited to buffers < 2GB in size. For larger buffers, + * use remote_register_buf_attr2 which supports 64-bit sizes. * - * @note Some versions of libcdsprpc.so lack these functions, so users should set - * these symbols as weak: - * #pragma weak remote_register_buf - * #pragma weak remote_register_buf_attr + * @note Some versions of libcdsprpc.so lack these functions, so users should + * set these symbols as weak: #pragma weak remote_register_buf #pragma weak + * remote_register_buf_attr * - * @param buf [in] Virtual address of the buffer to register. Must be a valid mapped address. + * @param buf [in] Virtual address of the buffer to register. Must be a valid + * mapped address. * @param size [in] Size of the buffer in bytes. Must be > 0 and < 2GB. - * @param fd [in] File descriptor for the buffer. Use -1 to deregister a previously registered buffer. + * @param fd [in] File descriptor for the buffer. Use -1 to deregister a + * previously registered buffer. * @param attr [in] (remote_register_buf_attr only) Buffer attributes: * 0 - Non-coherent mapping (cached) * 1 - Coherent mapping (uncached) @@ -1252,25 +1424,33 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(fastrpc_munmap)(__QAIC_IN i * EBUSY - Buffer already registered * ENOSYS - API not supported on this platform */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf)(__QAIC_IN_LEN(size) void* buf, __QAIC_IN int size, __QAIC_IN int fd) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf_attr)(__QAIC_IN_LEN(size) void* buf, __QAIC_IN int size, __QAIC_IN int fd, __QAIC_IN int attr) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf)( + __QAIC_IN_LEN(size) void *buf, __QAIC_IN int size, + __QAIC_IN int fd) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE( + remote_register_buf_attr)(__QAIC_IN_LEN(size) void *buf, + __QAIC_IN int size, __QAIC_IN int fd, + __QAIC_IN int attr) __QAIC_REMOTE_ATTRIBUTE; /** * remote_register_buf_attr2 - * Register a file descriptor for a buffer to enable zero-copy sharing with DSP via SMMU. - * This version supports 64-bit buffer sizes, unlike remote_register_buf/remote_register_buf_attr. + * Register a file descriptor for a buffer to enable zero-copy sharing with DSP + * via SMMU. This version supports 64-bit buffer sizes, unlike + * remote_register_buf/remote_register_buf_attr. * - * This function is thread-safe and can be called from multiple threads concurrently. - * However, registering/deregistering the same buffer from different threads simultaneously - * is not supported and will lead to undefined behavior. + * This function is thread-safe and can be called from multiple threads + * concurrently. However, registering/deregistering the same buffer from + * different threads simultaneously is not supported and will lead to undefined + * behavior. * - * Some older versions of libcdsprpc.so lack this function, so users should set this symbol as weak: - * #pragma weak remote_register_buf_attr2 + * Some older versions of libcdsprpc.so lack this function, so users should set + * this symbol as weak: #pragma weak remote_register_buf_attr2 * - * @param buf [in] Virtual address of the buffer to register. Must be a valid mapped address. + * @param buf [in] Virtual address of the buffer to register. Must be a valid + * mapped address. * @param size [in] Size of the buffer in bytes. Must be > 0. - * @param fd [in] File descriptor for the buffer. Use -1 to deregister a previously registered buffer. + * @param fd [in] File descriptor for the buffer. Use -1 to deregister a + * previously registered buffer. * @param attr [in] Buffer attributes: * 0 - Non-coherent mapping (cached) * 1 - Coherent mapping (uncached) @@ -1283,23 +1463,28 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf_attr)( * EBUSY - Buffer already registered * ENOSYS - API not supported on this platform */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf_attr2)(__QAIC_IN_LEN(size) void* buf, __QAIC_IN size_t size, __QAIC_IN int fd, __QAIC_IN int attr) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE( + remote_register_buf_attr2)(__QAIC_IN_LEN(size) void *buf, + __QAIC_IN size_t size, __QAIC_IN int fd, + __QAIC_IN int attr) __QAIC_REMOTE_ATTRIBUTE; /** * remote_register_dma_handle/remote_register_dma_handle_attr - * Register a DMA handle with FastRPC to enable zero-copy sharing of ION memory with DSP via SMMU. - * This API is only valid on Android systems with ION-allocated memory. + * Register a DMA handle with FastRPC to enable zero-copy sharing of ION memory + * with DSP via SMMU. This API is only valid on Android systems with + * ION-allocated memory. * - * This function is thread-safe and can be called from multiple threads concurrently. - * However, registering/deregistering the same buffer from different threads simultaneously - * is not supported and will lead to undefined behavior. + * This function is thread-safe and can be called from multiple threads + * concurrently. However, registering/deregistering the same buffer from + * different threads simultaneously is not supported and will lead to undefined + * behavior. * - * Some versions of libadsprpc.so lack this function, so users should set these symbols as weak: - * #pragma weak remote_register_dma_handle - * #pragma weak remote_register_dma_handle_attr + * Some versions of libadsprpc.so lack this function, so users should set these + * symbols as weak: #pragma weak remote_register_dma_handle #pragma weak + * remote_register_dma_handle_attr * - * @param fd [in] File descriptor for the ION buffer. Use -1 to deregister a previously registered buffer. + * @param fd [in] File descriptor for the ION buffer. Use -1 to deregister a + * previously registered buffer. * @param len [in] Size of the buffer in bytes. Must be > 0. * @param attr [in] (remote_register_dma_handle_attr only) Buffer attributes: * 0 - Non-coherent mapping (cached) @@ -1313,75 +1498,86 @@ __QAIC_REMOTE_EXPORT __QAIC_RETURN void __QAIC_REMOTE(remote_register_buf_attr2) * EBUSY - Buffer already registered * ENOSYS - API not supported on this platform */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_register_dma_handle)(__QAIC_IN int fd,__QAIC_IN uint32_t len) __QAIC_REMOTE_ATTRIBUTE; -__QAIC_REMOTE_EXPORT __QAIC_RETURN int __QAIC_REMOTE(remote_register_dma_handle_attr)(__QAIC_IN int fd,__QAIC_IN uint32_t len,__QAIC_IN uint32_t attr) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN int + __QAIC_REMOTE(remote_register_dma_handle)( + __QAIC_IN int fd, __QAIC_IN uint32_t len) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN int + __QAIC_REMOTE(remote_register_dma_handle_attr)( + __QAIC_IN int fd, __QAIC_IN uint32_t len, + __QAIC_IN uint32_t attr) __QAIC_REMOTE_ATTRIBUTE; /** * remote_register_fd - * Register a file descriptor with FastRPC to enable zero-copy sharing of memory with DSP. - * This API is useful when users have a file descriptor but no virtual address mapping. + * Register a file descriptor with FastRPC to enable zero-copy sharing of + * memory with DSP. This API is useful when users have a file descriptor but no + * virtual address mapping. * - * The function creates a PROT_NONE mapping that cannot be accessed directly, but serves - * as an identifier for the buffer in FastRPC calls. The mapping is used internally by - * the RPC layer to share the buffer with DSP. + * The function creates a PROT_NONE mapping that cannot be accessed directly, + * but serves as an identifier for the buffer in FastRPC calls. The mapping is + * used internally by the RPC layer to share the buffer with DSP. * - * This API has a 2GB size limitation. For larger buffers, use remote_register_fd2(). + * This API has a 2GB size limitation. For larger buffers, use + * remote_register_fd2(). * - * This function is thread-safe and can be called from multiple threads concurrently. - * However, registering/deregistering the same buffer from different threads simultaneously - * is not supported and will lead to undefined behavior. + * This function is thread-safe and can be called from multiple threads + * concurrently. However, registering/deregistering the same buffer from + * different threads simultaneously is not supported and will lead to undefined + * behavior. * - * Some versions of libadsprpc.so lack this function, so users should set this symbol as weak: - * #pragma weak remote_register_fd + * Some versions of libadsprpc.so lack this function, so users should set this + * symbol as weak: #pragma weak remote_register_fd * - * @param fd [in] File descriptor for the buffer. Must be a valid file descriptor. + * @param fd [in] File descriptor for the buffer. Must be a valid file + * descriptor. * @param size [in] Size of the buffer in bytes. Must be > 0 and < 2GB. * - * @return On success, returns a virtual address that can be used in FastRPC calls. - * On failure, returns (void*)-1. Check errno for error details: - * EINVAL - Invalid parameters (fd < 0, size = 0 or size >= 2GB) - * ENOMEM - Out of memory in driver - * EBADF - Invalid file descriptor - * EBUSY - Buffer already registered - * ENOSYS - API not supported on this platform + * @return On success, returns a virtual address that can be used in FastRPC + * calls. On failure, returns (void*)-1. Check errno for error details: EINVAL + * - Invalid parameters (fd < 0, size = 0 or size >= 2GB) ENOMEM - Out of + * memory in driver EBADF - Invalid file descriptor EBUSY - Buffer already + * registered ENOSYS - API not supported on this platform * - * To deregister the buffer, call remote_register_buf(addr, size, -1) with the returned address. + * To deregister the buffer, call remote_register_buf(addr, size, -1) with the + * returned address. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN void *__QAIC_REMOTE(remote_register_fd)(__QAIC_IN int fd,__QAIC_IN int size) __QAIC_REMOTE_ATTRIBUTE; +__QAIC_REMOTE_EXPORT __QAIC_RETURN void *__QAIC_REMOTE(remote_register_fd)( + __QAIC_IN int fd, __QAIC_IN int size) __QAIC_REMOTE_ATTRIBUTE; /** * remote_register_fd2 - * Register a file descriptor with FastRPC to enable zero-copy sharing of memory with DSP. - * This API is useful when users have a file descriptor but no virtual address mapping. - * Unlike remote_register_fd(), this function supports buffers larger than 2GB. + * Register a file descriptor with FastRPC to enable zero-copy sharing of + * memory with DSP. This API is useful when users have a file descriptor but no + * virtual address mapping. Unlike remote_register_fd(), this function supports + * buffers larger than 2GB. * - * The function creates a PROT_NONE mapping that cannot be accessed directly, but serves - * as an identifier for the buffer in FastRPC calls. The mapping is used internally by - * the RPC layer to share the buffer with DSP. + * The function creates a PROT_NONE mapping that cannot be accessed directly, + * but serves as an identifier for the buffer in FastRPC calls. The mapping is + * used internally by the RPC layer to share the buffer with DSP. * - * This function is thread-safe and can be called from multiple threads concurrently. - * However, registering/deregistering the same buffer from different threads simultaneously - * is not supported and will lead to undefined behavior. + * This function is thread-safe and can be called from multiple threads + * concurrently. However, registering/deregistering the same buffer from + * different threads simultaneously is not supported and will lead to undefined + * behavior. * - * Some versions of libadsprpc.so lack this function, so users should set this symbol as weak: - * #pragma weak remote_register_fd2 + * Some versions of libadsprpc.so lack this function, so users should set this + * symbol as weak: #pragma weak remote_register_fd2 * - * @param fd [in] File descriptor for the buffer. Must be a valid file descriptor. + * @param fd [in] File descriptor for the buffer. Must be a valid file + * descriptor. * @param size [in] Size of the buffer in bytes. Must be > 0. * - * @return On success, returns a virtual address that can be used in FastRPC calls. - * On failure, returns (void*)-1. Check errno for error details: - * EINVAL - Invalid parameters (fd < 0, size = 0) - * ENOMEM - Out of memory in driver + * @return On success, returns a virtual address that can be used in FastRPC + * calls. On failure, returns (void*)-1. Check errno for error details: EINVAL + * - Invalid parameters (fd < 0, size = 0) ENOMEM - Out of memory in driver * EBADF - Invalid file descriptor * EBUSY - Buffer already registered * ENOSYS - API not supported on this platform * - * To deregister the buffer, call remote_register_buf(addr, size, -1) with the returned address. + * To deregister the buffer, call remote_register_buf(addr, size, -1) with the + * returned address. */ -__QAIC_REMOTE_EXPORT __QAIC_RETURN void *__QAIC_REMOTE(remote_register_fd2)(__QAIC_IN int fd,__QAIC_IN size_t size) __QAIC_REMOTE_ATTRIBUTE; - +__QAIC_REMOTE_EXPORT __QAIC_RETURN void *__QAIC_REMOTE(remote_register_fd2)( + __QAIC_IN int fd, __QAIC_IN size_t size) __QAIC_REMOTE_ATTRIBUTE; #ifdef __cplusplus } diff --git a/inc/remote64.h b/inc/remote64.h index ec08d2d2..0759651f 100644 --- a/inc/remote64.h +++ b/inc/remote64.h @@ -7,6 +7,7 @@ #include "remote.h" /* -All the functions declared here are moved to remote.h, remote64.h will be deleted in future. +All the functions declared here are moved to remote.h, remote64.h will be +deleted in future. */ #endif // REMOTE64_H diff --git a/inc/remotectl.h b/inc/remotectl.h index c33e3b5e..00ddeb39 100644 --- a/inc/remotectl.h +++ b/inc/remotectl.h @@ -36,16 +36,25 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ #define _const_remotectl_handle 0 -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl_open)(const char* name, int* handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl_close)(int handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl_grow_heap)(uint32_t phyAddr, uint32_t nSize) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl_set_param)(int reqID, const uint32_t* params, int paramsLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl_open)(const char *name, int *handle, char *dlerror, + int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl_close)(int handle, char *dlerror, int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl_grow_heap)(uint32_t phyAddr, + uint32_t nSize) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl_set_param)(int reqID, const uint32_t *params, + int paramsLen) __QAIC_HEADER_ATTRIBUTE; #ifdef __cplusplus } #endif diff --git a/inc/remotectl1.h b/inc/remotectl1.h index 49ded092..85157c3a 100644 --- a/inc/remotectl1.h +++ b/inc/remotectl1.h @@ -5,9 +5,8 @@ #define _REMOTECTL1_H #include #include -#include #include - +#include #ifndef __QAIC_HEADER #define __QAIC_HEADER(ff) ff @@ -53,7 +52,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -63,7 +62,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -121,52 +120,56 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) @@ -175,46 +178,50 @@ static __inline void _qaic_memmove(void* dst, void* src, int size) { #ifdef _WIN32 #define _QAIC_FARF(level, msg, ...) (void)0 #else -#define _QAIC_FARF(level, msg, ...) \ - do {\ - if(0 == (HAP_debug_v2) ) {\ - (void)0; \ - } else { \ - FARF(level, msg , ##__VA_ARGS__); \ - } \ - }while(0) +#define _QAIC_FARF(level, msg, ...) \ + do { \ + if(0 == (HAP_debug_v2)) { \ + (void)0; \ + } else { \ + FARF(level, msg, ##__VA_ARGS__); \ + } \ + } while(0) #endif //_WIN32 for _QAIC_FARF -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _TRY_FARF(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - goto ee##farf##bail;\ - } \ - } while (0) +#define _TRY_FARF(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + goto ee##farf##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) -#define _CATCH_FARF(exception) exception##farf##bail: if (exception != AEE_SUCCESS) +#define _CATCH_FARF(exception) \ + exception##farf##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifdef __cplusplus @@ -224,48 +231,64 @@ extern "C" { #define __QAIC_STRING1_OBJECT_DEFINED__ #define __STRING1_OBJECT__ typedef struct _cstring1_s { - char* data; - int dataLen; + char *data; + int dataLen; } _cstring1_t; #endif /* __QAIC_STRING1_OBJECT_DEFINED__ */ #define _const_remotectl1_handle 8 /** - * Opens the handle in the specified domain. If this is the first - * handle, this creates the session. Typically this means opening - * the device, aka open("/dev/adsprpc-smd"), then calling ioctl - * device APIs to create a PD on the DSP to execute our code in, - * then asking that PD to dlopen the .so and dlsym the skel function. - * - * @param uri, _URI"&_dom=aDSP" - * _URI is a QAIC generated uri, or - * "file:///?_skel_handle_invoke&_modver=1.0" - * If the _dom parameter is not present, _dom=DEFAULT is assumed - * but not forwarded. - * Reserved uri keys: - * [0]: first unamed argument is the skel invoke function - * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT - * _modver: module version, _modver=1.0 - * _*: any other key name starting with an _ is reserved - * Unknown uri keys/values are forwarded as is. - * @param h, resulting handle - * @retval, 0 on success - */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_open)(const char* uri, remote_handle64* h) __QAIC_HEADER_ATTRIBUTE; -/** + * Opens the handle in the specified domain. If this is the first + * handle, this creates the session. Typically this means opening + * the device, aka open("/dev/adsprpc-smd"), then calling ioctl + * device APIs to create a PD on the DSP to execute our code in, + * then asking that PD to dlopen the .so and dlsym the skel function. + * + * @param uri, _URI"&_dom=aDSP" + * _URI is a QAIC generated uri, or + * "file:///?_skel_handle_invoke&_modver=1.0" + * If the _dom parameter is not present, _dom=DEFAULT is assumed + * but not forwarded. + * Reserved uri keys: + * [0]: first unamed argument is the skel invoke function + * _dom: execution domain name, _dom=mDSP/aDSP/DEFAULT + * _modver: module version, _modver=1.0 + * _*: any other key name starting with an _ is reserved + * Unknown uri keys/values are forwarded as is. + * @param h, resulting handle + * @retval, 0 on success + */ +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl1_open)(const char *uri, + remote_handle64 *h) __QAIC_HEADER_ATTRIBUTE; +/** * Closes a handle. If this is the last handle to close, the session * is closed as well, releasing all the allocated resources. * @param h, the handle to close * @retval, 0 on success, should always succeed */ -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_open1)(remote_handle64 _h, const char* name, int* handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_close1)(remote_handle64 _h, int handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_grow_heap)(remote_handle64 _h, uint32_t phyAddr, uint32_t nSize) __QAIC_HEADER_ATTRIBUTE; -__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_set_param)(remote_handle64 _h, int reqID, const uint32_t* params, int paramsLen) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl1_close)(remote_handle64 h) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl1_open1)(remote_handle64 _h, const char *name, + int *handle, char *dlerror, int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl1_close1)(remote_handle64 _h, int handle, + char *dlerror, int dlerrorLen, + int *nErr) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int __QAIC_HEADER(remotectl1_grow_heap)( + remote_handle64 _h, uint32_t phyAddr, + uint32_t nSize) __QAIC_HEADER_ATTRIBUTE; +__QAIC_HEADER_EXPORT int + __QAIC_HEADER(remotectl1_set_param)(remote_handle64 _h, int reqID, + const uint32_t *params, + int paramsLen) __QAIC_HEADER_ATTRIBUTE; #ifndef remotectl1_URI -#define remotectl1_URI "file:///libremotectl1_skel.so?remotectl1_skel_handle_invoke&_modver=1.0" +#define remotectl1_URI \ + "file:///" \ + "libremotectl1_skel.so?remotectl1_skel_handle_invoke&_modver=1.0" #endif /*remotectl1_URI*/ #ifdef __cplusplus } diff --git a/inc/rpcmem.h b/inc/rpcmem.h index c9e15059..cc7c3fbb 100644 --- a/inc/rpcmem.h +++ b/inc/rpcmem.h @@ -8,7 +8,8 @@ /** * @file rpcmem.h - * @brief APIs used to manage memory allocated by the application processor and shared with the DSP. + * @brief APIs used to manage memory allocated by the application processor + * and shared with the DSP. */ /** @defgroup rpcmem_const RPCMEM API macros and enumerations @@ -25,13 +26,16 @@ #endif /** - * The FastRPC library tries to map buffers allocated with this flag to the remote process of all current and new - * FastRPC sessions. In case of failure to map, the FastRPC library ignores the error and continues to open the session - * without pre-mapping the buffer. In case of success, buffers allocated with this flag will be pre-mapped to reduce - * the latency of upcoming FastRPC calls. This flag is recommended only for buffers that are used with latency-critical - * FastRPC methods. Pre-mapped buffers will be unmapped during either buffer free or session close. + * The FastRPC library tries to map buffers allocated with this flag to the + * remote process of all current and new FastRPC sessions. In case of failure + * to map, the FastRPC library ignores the error and continues to open the + * session without pre-mapping the buffer. In case of success, buffers + * allocated with this flag will be pre-mapped to reduce the latency of + * upcoming FastRPC calls. This flag is recommended only for buffers that are + * used with latency-critical FastRPC methods. Pre-mapped buffers will be + * unmapped during either buffer free or session close. */ -#define RPCMEM_TRY_MAP_STATIC 0x04000000 +#define RPCMEM_TRY_MAP_STATIC 0x04000000 /** * Supported RPCMEM heap IDs. @@ -41,25 +45,26 @@ * a valid ION heap ID. */ enum rpc_heap_ids { -/** - * Memory for secure use cases only. - * * Secure heap is to be used only by clients migrating to CPZ - */ - RPCMEM_HEAP_ID_SECURE = 9, -/** - * Contiguous physical memory: - * * Very limited memory is available (< 8 MB) - * * Recommended for subsystems without SMMU (sDSP and mDSP) - * * Contiguous heap memory will be deprecated from archs after v73 - */ - RPCMEM_HEAP_ID_CONTIG = 22, -/** - * Non-contiguous system physical memory. - * * Recommended for all use cases that do not require using a specific heap - * * Used with subsystems with SMMU (cDSP and aDSP) - */ - RPCMEM_HEAP_ID_SYSTEM = 25, - }; + /** + * Memory for secure use cases only. + * * Secure heap is to be used only by clients migrating to CPZ + */ + RPCMEM_HEAP_ID_SECURE = 9, + /** + * Contiguous physical memory: + * * Very limited memory is available (< 8 MB) + * * Recommended for subsystems without SMMU (sDSP and mDSP) + * * Contiguous heap memory will be deprecated from archs after v73 + */ + RPCMEM_HEAP_ID_CONTIG = 22, + /** + * Non-contiguous system physical memory. + * * Recommended for all use cases that do not require using a + * specific heap + * * Used with subsystems with SMMU (cDSP and aDSP) + */ + RPCMEM_HEAP_ID_SYSTEM = 25, +}; /** * Use uncached memory. @@ -155,7 +160,7 @@ void rpcmem_deinit(void); * rpcmem_alloc(18, RPCMEM_DEFAULT_FLAGS, 4096); * @endcode */ -void* rpcmem_alloc(int heapid, uint32_t flags, int size); +void *rpcmem_alloc(int heapid, uint32_t flags, int size); /** * Allocate a zero-copy buffer with the FastRPC framework. @@ -168,31 +173,33 @@ void* rpcmem_alloc(int heapid, uint32_t flags, int size); * * * The usage examples are same as rpcmem_alloc. */ -void* rpcmem_alloc2(int heapid, uint32_t flags, size_t size); +void *rpcmem_alloc2(int heapid, uint32_t flags, size_t size); /** * Allocate a buffer with default settings. * @param[in] size Size of the buffer to be allocated. * @return Pointer to the allocated memory buffer. */ - #if !defined(WINNT) && !defined (_WIN32_WINNT) +#if !defined(WINNT) && !defined(_WIN32_WINNT) __attribute__((unused)) #endif -static __inline void* rpcmem_alloc_def(int size) { - return rpcmem_alloc(RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS, size); +static __inline void * +rpcmem_alloc_def(int size) +{ + return rpcmem_alloc(RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS, size); } /** * Free a buffer and ignore invalid buffers. */ -void rpcmem_free(void* po); +void rpcmem_free(void *po); /** * Return an associated file descriptor. * @param[in] po Data pointer for an RPCMEM-allocated buffer. * @return Buffer file descriptor. */ -int rpcmem_to_fd(void* po); +int rpcmem_to_fd(void *po); /** * @} @@ -205,16 +212,16 @@ int rpcmem_to_fd(void* po); //! @cond Doxygen_Suppress /** These macros are deprecated. */ -#define RPCMEM_DEFAULT_HEAP -1 -#define RPCMEM_HEAP_DEFAULT 0x80000000 -#define RPCMEM_HEAP_NOREG 0x40000000 -#define RPCMEM_HEAP_UNCACHED 0x20000000 -#define RPCMEM_HEAP_NOVA 0x10000000 +#define RPCMEM_DEFAULT_HEAP -1 +#define RPCMEM_HEAP_DEFAULT 0x80000000 +#define RPCMEM_HEAP_NOREG 0x40000000 +#define RPCMEM_HEAP_UNCACHED 0x20000000 +#define RPCMEM_HEAP_NOVA 0x10000000 #define RPCMEM_HEAP_NONCOHERENT 0x08000000 -#define RPCMEM_FORCE_NOFLUSH 0x01000000 -#define RPCMEM_FORCE_NOINVALIDATE 0x02000000 +#define RPCMEM_FORCE_NOFLUSH 0x01000000 +#define RPCMEM_FORCE_NOINVALIDATE 0x02000000 // Use macros from libion instead -#define ION_SECURE_FLAGS ((1 << 31) | (1 << 19)) +#define ION_SECURE_FLAGS ((1 << 31) | (1 << 19)) //! @endcond -#endif //RPCMEM_H +#endif // RPCMEM_H diff --git a/inc/rpcmem_internal.h b/inc/rpcmem_internal.h index 4fe415e5..baf823a1 100644 --- a/inc/rpcmem_internal.h +++ b/inc/rpcmem_internal.h @@ -20,8 +20,8 @@ * @rpcflags: Memory flags describing attributes of allocation * Return : 0 on success, valid non-zero error code on failure */ -int rpcmem_set_dmabuf_name(const char *name, int fd, int heapid, - void *buf, uint32_t rpc_flags); +int rpcmem_set_dmabuf_name(const char *name, int fd, int heapid, void *buf, + uint32_t rpc_flags); /* * returns an file descriptor associated with the address */ diff --git a/inc/sbuf.h b/inc/sbuf.h index 2bc581f9..82ef3a67 100644 --- a/inc/sbuf.h +++ b/inc/sbuf.h @@ -4,9 +4,9 @@ #ifndef SBUF_H #define SBUF_H -#include -#include #include "AEEstd.h" +#include +#include /** * lightweight serialize/deserialize buffer. @@ -38,12 +38,11 @@ See sbuf_q.c for more examples */ - struct sbuf { - uintptr_t buf; //! start of valid memory - uintptr_t bufEnd; //! end of valid memory - uintptr_t bufStart; //! start with optinal offset from valid mem - uintptr_t bufCur; //! current position, could be outside of valid range + uintptr_t buf; //! start of valid memory + uintptr_t bufEnd; //! end of valid memory + uintptr_t bufStart; //! start with optinal offset from valid mem + uintptr_t bufCur; //! current position, could be outside of valid range }; /** @@ -53,73 +52,91 @@ struct sbuf { * @param data, the valid memory * @param dataLen, the length ov valid memory */ -static __inline void sbuf_init(struct sbuf* buf, int offset, void* data, int dataLen) { - buf->buf = (uintptr_t)data; - buf->bufStart = buf->bufCur = (uintptr_t)data - offset; - buf->bufEnd = (uintptr_t)data + dataLen; +static __inline void +sbuf_init(struct sbuf *buf, int offset, void *data, int dataLen) +{ + buf->buf = (uintptr_t)data; + buf->bufStart = buf->bufCur = (uintptr_t)data - offset; + buf->bufEnd = (uintptr_t)data + dataLen; } //! move the current pointer by len -static __inline void sbuf_advance(struct sbuf* buf, int len) { - buf->bufCur += len; +static __inline void +sbuf_advance(struct sbuf *buf, int len) +{ + buf->bufCur += len; } /** - * @retval, the amount of memory needed for everything from the start (with the offset) - * to the current position of the buffer + * @retval, the amount of memory needed for everything from the start (with the + * offset) to the current position of the buffer */ -static __inline int sbuf_needed(struct sbuf* buf) { - return buf->bufCur - buf->bufStart; +static __inline int +sbuf_needed(struct sbuf *buf) +{ + return buf->bufCur - buf->bufStart; } /** * @retval, the space left in the buffer. A negative value indicates overflow. * A positive value includes the offset. */ -static __inline int sbuf_left(struct sbuf* buf) { - int result; - __builtin_sub_overflow(buf->bufEnd, buf->bufCur, &result); - return result; +static __inline int +sbuf_left(struct sbuf *buf) +{ + int result; + __builtin_sub_overflow(buf->bufEnd, buf->bufCur, &result); + return result; } //! @retval the current head pointer -static __inline void* sbuf_head(struct sbuf* buf) { - return (void*)buf->bufCur; +static __inline void * +sbuf_head(struct sbuf *buf) +{ + return (void *)buf->bufCur; } //! @retval true if the current pointer is valid -static __inline int sbuf_valid(struct sbuf* buf) { - return buf->bufCur >= buf->buf && buf->bufCur < buf->bufEnd; +static __inline int +sbuf_valid(struct sbuf *buf) +{ + return buf->bufCur >= buf->buf && buf->bufCur < buf->bufEnd; } //! advance the head pointer so the "needed" is aligned to the align value -#define _SBUF_ALIGN(x, y) (((x) + ((y)-1)) & ~((y)-1)) -static __inline void sbuf_align(struct sbuf* buf, uint32_t align) { - sbuf_advance(buf, _SBUF_ALIGN(sbuf_needed(buf), align) - sbuf_needed(buf)); +#define _SBUF_ALIGN(x, y) (((x) + ((y) - 1)) & ~((y) - 1)) +static __inline void +sbuf_align(struct sbuf *buf, uint32_t align) +{ + sbuf_advance(buf, + _SBUF_ALIGN(sbuf_needed(buf), align) - sbuf_needed(buf)); } /** * Write to the buffer. - * @param src, the memory to read from. Will write srcLen bytes to buf from src - * from the buf's current position. Only the valid portion of data will - * be written. + * @param src, the memory to read from. Will write srcLen bytes to buf from + * src from the buf's current position. Only the valid portion of data will be + * written. * @param srcLen, the length of src. The buffer will be advanced by srcLen. */ -static __inline void sbuf_write(struct sbuf* buf, void *psrc, int srcLen) { - uintptr_t src = (uintptr_t)psrc; - if(buf->bufCur + srcLen > buf->buf) { - int writeLen; - if(buf->bufCur < buf->buf) { - int len = buf->buf - buf->bufCur; - srcLen -= len; - src += len; - sbuf_advance(buf, len); - } - writeLen = STD_MIN(srcLen, sbuf_left(buf)); - if(writeLen > 0) { - memmove((void*)buf->bufCur, (void*)src, STD_MIN(buf->bufEnd - buf->bufCur, writeLen)); - } - } - sbuf_advance(buf, srcLen); +static __inline void +sbuf_write(struct sbuf *buf, void *psrc, int srcLen) +{ + uintptr_t src = (uintptr_t)psrc; + if(buf->bufCur + srcLen > buf->buf) { + int writeLen; + if(buf->bufCur < buf->buf) { + int len = buf->buf - buf->bufCur; + srcLen -= len; + src += len; + sbuf_advance(buf, len); + } + writeLen = STD_MIN(srcLen, sbuf_left(buf)); + if(writeLen > 0) { + memmove((void *)buf->bufCur, (void *)src, + STD_MIN(buf->bufEnd - buf->bufCur, writeLen)); + } + } + sbuf_advance(buf, srcLen); } /** @@ -130,22 +147,24 @@ static __inline void sbuf_write(struct sbuf* buf, void *psrc, int srcLen) { * remain untouched. * @param dstLen, the length of dst. buf will be advanced by dstLen */ -static __inline void sbuf_read(struct sbuf* buf, void *pdst, int dstLen) { - uintptr_t dst = (uintptr_t)pdst; - if(buf->bufCur + dstLen > buf->buf) { - int readLen; - if(buf->bufCur < buf->buf) { - int len = buf->buf - buf->bufCur; - dstLen -= len; - dst += len; - sbuf_advance(buf, len); - } - readLen = STD_MIN(dstLen, sbuf_left(buf)); - if(readLen > 0) { - memmove((void*)dst, (void*)buf->bufCur, readLen); - } - } - sbuf_advance(buf, dstLen); +static __inline void +sbuf_read(struct sbuf *buf, void *pdst, int dstLen) +{ + uintptr_t dst = (uintptr_t)pdst; + if(buf->bufCur + dstLen > buf->buf) { + int readLen; + if(buf->bufCur < buf->buf) { + int len = buf->buf - buf->bufCur; + dstLen -= len; + dst += len; + sbuf_advance(buf, len); + } + readLen = STD_MIN(dstLen, sbuf_left(buf)); + if(readLen > 0) { + memmove((void *)dst, (void *)buf->bufCur, readLen); + } + } + sbuf_advance(buf, dstLen); } #endif diff --git a/inc/sbuf_parser.h b/inc/sbuf_parser.h index b01b33a5..1efa8663 100644 --- a/inc/sbuf_parser.h +++ b/inc/sbuf_parser.h @@ -9,8 +9,8 @@ /** * Greedy Recursive Descent Parser in C * - * Stop using strstr or regular expressions. This simple Recursive Descent Parser can be - * used to handle complex grammars. + * Stop using strstr or regular expressions. This simple Recursive Descent + * Parser can be used to handle complex grammars. * * For example: * parsing a query string form a uri @@ -69,81 +69,98 @@ */ //! init -static __inline void sbuf_parser_init(struct sbuf* buf, const char *data, int dataLen) { - sbuf_init(buf, 0, (void*)data, dataLen); +static __inline void +sbuf_parser_init(struct sbuf *buf, const char *data, int dataLen) +{ + sbuf_init(buf, 0, (void *)data, dataLen); } //! current postiion -static __inline char *sbuf_cur(struct sbuf* buf) { - return (char*)sbuf_head(buf); +static __inline char * +sbuf_cur(struct sbuf *buf) +{ + return (char *)sbuf_head(buf); } //! look at the next character if the buffer is still valid -static __inline int sbuf_peek(struct sbuf* buf, char* c) { - if(!sbuf_valid(buf)) { - return 0; - } - *c = *sbuf_cur(buf); - return 1; +static __inline int +sbuf_peek(struct sbuf *buf, char *c) +{ + if(!sbuf_valid(buf)) { + return 0; + } + *c = *sbuf_cur(buf); + return 1; } //! returns true if the buffer is ended -static __inline int sbuf_end(struct sbuf* buf) { - return sbuf_left(buf) == 0; +static __inline int +sbuf_end(struct sbuf *buf) +{ + return sbuf_left(buf) == 0; } //! consume 1 char if its in string chars -static __inline int sbuf_chars(struct sbuf *buf, const char *chars) { - int i = 0; - char c; - if(!sbuf_peek(buf, &c)) { - return 0; - } - for(i = 0; chars[i] != 0; ++i) { - if(c == chars[i]) { - sbuf_advance(buf, 1); - return 1; - } - } - return 0; +static __inline int +sbuf_chars(struct sbuf *buf, const char *chars) +{ + int i = 0; + char c; + if(!sbuf_peek(buf, &c)) { + return 0; + } + for(i = 0; chars[i] != 0; ++i) { + if(c == chars[i]) { + sbuf_advance(buf, 1); + return 1; + } + } + return 0; } //! consume 1 char only if its not in string chars -static __inline int sbuf_notchars(struct sbuf *buf, const char *chars) { - int i = 0; - char c; - if(!sbuf_peek(buf, &c)) { - return 0; - } - for(i = 0; chars[i] != 0; ++i) { - if(c == chars[i]) { - return 0; - } - } - sbuf_advance(buf, 1); - return 1; +static __inline int +sbuf_notchars(struct sbuf *buf, const char *chars) +{ + int i = 0; + char c; + if(!sbuf_peek(buf, &c)) { + return 0; + } + for(i = 0; chars[i] != 0; ++i) { + if(c == chars[i]) { + return 0; + } + } + sbuf_advance(buf, 1); + return 1; } //! consume only char t -static __inline int sbuf_char(struct sbuf *buf, const char t) { - char str[2] = {t, 0}; - return sbuf_chars(buf, str); +static __inline int +sbuf_char(struct sbuf *buf, const char t) +{ + char str[2] = { t, 0 }; + return sbuf_chars(buf, str); } //! consume any char except for t -static __inline int sbuf_notchar(struct sbuf *buf, const char t) { - char str[2] = {t, 0}; - return sbuf_notchars(buf, str); +static __inline int +sbuf_notchar(struct sbuf *buf, const char t) +{ + char str[2] = { t, 0 }; + return sbuf_notchars(buf, str); } /** * consume any char */ -static __inline int sbuf_any(struct sbuf* buf) { - return sbuf_notchars(buf, ""); +static __inline int +sbuf_any(struct sbuf *buf) +{ + return sbuf_notchars(buf, ""); } - /** * range is pairs of characters * @@ -153,88 +170,94 @@ static __inline int sbuf_any(struct sbuf* buf) { * matches uppercase and lowercase letters, numbers, dashes and dots * */ -static __inline int sbuf_range(struct sbuf *buf, const char *chars) { - int i, j; - char c; - if(!sbuf_peek(buf, &c)) { - return 0; - } - for(i = 0, j = 1; chars[i] != 0 && chars[j] != 0; i+=2,j+=2) { - if(c >= chars[i] && c <= chars[j]) { - sbuf_advance(buf, 1); - return 1; - } - } - return 0; +static __inline int +sbuf_range(struct sbuf *buf, const char *chars) +{ + int i, j; + char c; + if(!sbuf_peek(buf, &c)) { + return 0; + } + for(i = 0, j = 1; chars[i] != 0 && chars[j] != 0; i += 2, j += 2) { + if(c >= chars[i] && c <= chars[j]) { + sbuf_advance(buf, 1); + return 1; + } + } + return 0; } - /** * greedly consume and match the entire string * empty string always succeeds without consuming any data */ -static __inline int sbuf_string(struct sbuf *buf, const char *str) { - int i = 0; - for(i = 0; str[i] != 0; ++i) { - if(!sbuf_char(buf, str[i])) { - return 0; - } - } - return 1; +static __inline int +sbuf_string(struct sbuf *buf, const char *str) +{ + int i = 0; + for(i = 0; str[i] != 0; ++i) { + if(!sbuf_char(buf, str[i])) { + return 0; + } + } + return 1; } /** * consumes until fails */ -static __inline int sbuf_many(struct sbuf *buf, - int(*consume)(struct sbuf *buf)) +static __inline int +sbuf_many(struct sbuf *buf, int (*consume)(struct sbuf *buf)) { - if(!sbuf_valid(buf)) { - return 0; - } - while(consume(buf)) {;} - return 1; + if(!sbuf_valid(buf)) { + return 0; + } + while(consume(buf)) { + ; + } + return 1; } /** * consumes until fails, must consume at least 1 */ -static __inline int sbuf_many1(struct sbuf *buf, - int(*consume)(struct sbuf *buf)) +static __inline int +sbuf_many1(struct sbuf *buf, int (*consume)(struct sbuf *buf)) { - if(!consume(buf)) { - return 0; - } - sbuf_many(buf, consume); - return 1; + if(!consume(buf)) { + return 0; + } + sbuf_many(buf, consume); + return 1; } /** * runs 'consume' until 'stop' succeeds * 'stop' must fail in such a way that it doesn't consume any data */ -static __inline int sbuf_until(struct sbuf *buf, - int(*consume)(struct sbuf *buf), - int(*stop)(struct sbuf *buf)) +static __inline int +sbuf_until(struct sbuf *buf, int (*consume)(struct sbuf *buf), + int (*stop)(struct sbuf *buf)) { - while(!stop(buf)) { - if(!consume(buf)) { - return 0; - } - } - return 1; + while(!stop(buf)) { + if(!consume(buf)) { + return 0; + } + } + return 1; } /** * allows for backtracking, * @param parser, runs parser and only consume if it succeeds */ -static __inline int sbuf_try(struct sbuf *buf, int(*parser)(struct sbuf *buf)) +static __inline int +sbuf_try(struct sbuf *buf, int (*parser)(struct sbuf *buf)) { - struct sbuf tryp; - sbuf_parser_init(&tryp, sbuf_cur(buf), sbuf_left(buf)); - if(parser(&tryp)) { - sbuf_advance(buf, sbuf_cur(&tryp) - sbuf_cur(buf)); - return 1; - } - return 0; + struct sbuf tryp; + sbuf_parser_init(&tryp, sbuf_cur(buf), sbuf_left(buf)); + if(parser(&tryp)) { + sbuf_advance(buf, sbuf_cur(&tryp) - sbuf_cur(buf)); + return 1; + } + return 0; } #endif // SBUF_PARSER_H diff --git a/inc/shared.h b/inc/shared.h index a6b5f42f..79621369 100644 --- a/inc/shared.h +++ b/inc/shared.h @@ -6,8 +6,9 @@ #if defined(__NIX) // TODO these sections not supported? -//static __so_func *__autostart[] __attribute__((section (".CRT$XIU"))) = { (__so_func*)__so_ctor }; -//static __so_func *__autoexit[] __attribute__((section (".CRT$XPU"))) = { (__so_func*)__so_dtor }; +// static __so_func *__autostart[] __attribute__((section (".CRT$XIU"))) = { +// (__so_func*)__so_ctor }; static __so_func *__autoexit[] +// __attribute__((section (".CRT$XPU"))) = { (__so_func*)__so_dtor }; #define SHARED_OBJECT_API_ENTRY(ctor, dtor) @@ -19,37 +20,41 @@ static __so_cb *__so_get_ctor(); static __so_cb *__so_get_dtor(); typedef void __so_func(void); -static void __so_ctor() { - (void)(__so_get_ctor())(); +static void +__so_ctor() +{ + (void)(__so_get_ctor())(); } -static void __so_dtor() { - (void)(__so_get_dtor())(); +static void +__so_dtor() +{ + (void)(__so_get_dtor())(); } #pragma data_seg(".CRT$XIU") - static __so_func *__autostart[] = { (__so_func*)__so_ctor }; +static __so_func *__autostart[] = { (__so_func *)__so_ctor }; #pragma data_seg(".CRT$XPU") - static __so_func *__autoexit[] = { (__so_func*)__so_dtor }; +static __so_func *__autoexit[] = { (__so_func *)__so_dtor }; #pragma data_seg() -#define SHARED_OBJECT_API_ENTRY(ctor, dtor)\ - static __so_cb *__so_get_ctor() { return (__so_cb*)ctor; }\ - static __so_cb *__so_get_dtor() { return (__so_cb*)dtor; } - -#else //better be gcc - -#define SHARED_OBJECT_API_ENTRY(ctor, dtor)\ -__attribute__((constructor)) \ -static void __ctor__##ctor(void) {\ - (void)ctor();\ -}\ -\ -__attribute__((destructor))\ -static void __dtor__##dtor(void) {\ - (void)dtor();\ -} +#define SHARED_OBJECT_API_ENTRY(ctor, dtor) \ + static __so_cb *__so_get_ctor() { return (__so_cb *)ctor; } \ + static __so_cb *__so_get_dtor() { return (__so_cb *)dtor; } + +#else // better be gcc + +#define SHARED_OBJECT_API_ENTRY(ctor, dtor) \ + __attribute__((constructor)) static void __ctor__##ctor(void) \ + { \ + (void)ctor(); \ + } \ + \ + __attribute__((destructor)) static void __dtor__##dtor(void) \ + { \ + (void)dtor(); \ + } -#endif //ifdef _WIN32 +#endif // ifdef _WIN32 #endif // SHARED_H diff --git a/inc/std_dtoa.h b/inc/std_dtoa.h index a514c0ff..d06ea8a6 100644 --- a/inc/std_dtoa.h +++ b/inc/std_dtoa.h @@ -19,65 +19,67 @@ // // The buffers that contain the converted integer and the fraction parts of // the float are safely assumed to be of size 310. -#define STD_DTOA_FORMAT_FLOAT_SIZE 420 -#define STD_DTOA_FORMAT_INTEGER_SIZE 311 -#define STD_DTOA_FORMAT_FRACTION_SIZE 100 +#define STD_DTOA_FORMAT_FLOAT_SIZE 420 +#define STD_DTOA_FORMAT_INTEGER_SIZE 311 +#define STD_DTOA_FORMAT_FRACTION_SIZE 100 // Constants for operations on the IEEE 754 representation of double // precision floating point numbers. -#define STD_DTOA_DP_SIGN_SHIFT_COUNT 63 -#define STD_DTOA_DP_EXPONENT_SHIFT_COUNT 52 -#define STD_DTOA_DP_EXPONENT_MASK 0x7ff -#define STD_DTOA_DP_EXPONENT_BIAS 1023 -#define STD_DTOA_DP_MANTISSA_MASK ( ( (uint64_t)1 << 52 ) - 1 ) -#define STD_DTOA_DP_INFINITY_EXPONENT_ID 0x7FF -#define STD_DTOA_DP_MAX_EXPONENT 1023 -#define STD_DTOA_DP_MIN_EXPONENT_NORM -1022 -#define STD_DTOA_DP_MIN_EXPONENT_DENORM -1074 -#define STD_DTOA_DP_MAX_EXPONENT_DEC 308 -#define STD_DTOA_DP_MIN_EXPONENT_DEC_DENORM -323 - -#define STD_DTOA_PRECISION_ROUNDING_VALUE 4 -#define STD_DTOA_DEFAULT_FLOAT_PRECISION 6 - -#define STD_DTOA_NEGATIVE_INF_UPPER_CASE "-INF" -#define STD_DTOA_NEGATIVE_INF_LOWER_CASE "-inf" -#define STD_DTOA_POSITIVE_INF_UPPER_CASE "INF" -#define STD_DTOA_POSITIVE_INF_LOWER_CASE "inf" -#define STD_DTOA_NAN_UPPER_CASE "NAN" -#define STD_DTOA_NAN_LOWER_CASE "nan" -#define STD_DTOA_FP_POSITIVE_INF 0x7FF0000000000000uLL -#define STD_DTOA_FP_NEGATIVE_INF 0xFFF0000000000000uLL -#define STD_DTOA_FP_SNAN 0xFFF0000000000001uLL -#define STD_DTOA_FP_QNAN 0xFFFFFFFFFFFFFFFFuLL +#define STD_DTOA_DP_SIGN_SHIFT_COUNT 63 +#define STD_DTOA_DP_EXPONENT_SHIFT_COUNT 52 +#define STD_DTOA_DP_EXPONENT_MASK 0x7ff +#define STD_DTOA_DP_EXPONENT_BIAS 1023 +#define STD_DTOA_DP_MANTISSA_MASK (((uint64_t)1 << 52) - 1) +#define STD_DTOA_DP_INFINITY_EXPONENT_ID 0x7FF +#define STD_DTOA_DP_MAX_EXPONENT 1023 +#define STD_DTOA_DP_MIN_EXPONENT_NORM -1022 +#define STD_DTOA_DP_MIN_EXPONENT_DENORM -1074 +#define STD_DTOA_DP_MAX_EXPONENT_DEC 308 +#define STD_DTOA_DP_MIN_EXPONENT_DEC_DENORM -323 + +#define STD_DTOA_PRECISION_ROUNDING_VALUE 4 +#define STD_DTOA_DEFAULT_FLOAT_PRECISION 6 + +#define STD_DTOA_NEGATIVE_INF_UPPER_CASE "-INF" +#define STD_DTOA_NEGATIVE_INF_LOWER_CASE "-inf" +#define STD_DTOA_POSITIVE_INF_UPPER_CASE "INF" +#define STD_DTOA_POSITIVE_INF_LOWER_CASE "inf" +#define STD_DTOA_NAN_UPPER_CASE "NAN" +#define STD_DTOA_NAN_LOWER_CASE "nan" +#define STD_DTOA_FP_POSITIVE_INF 0x7FF0000000000000uLL +#define STD_DTOA_FP_NEGATIVE_INF 0xFFF0000000000000uLL +#define STD_DTOA_FP_SNAN 0xFFF0000000000001uLL +#define STD_DTOA_FP_QNAN 0xFFFFFFFFFFFFFFFFuLL // // Useful Macros // -#define MY_ISDIGIT(c) ( ( (c) >= '0' ) && ( (c) <= '9' ) ) -#define FP_EXPONENT(u) ( ( ( (u) >> STD_DTOA_DP_EXPONENT_SHIFT_COUNT ) \ - & STD_DTOA_DP_EXPONENT_MASK ) - STD_DTOA_DP_EXPONENT_BIAS ) -#define FP_EXPONENT_BIASED(u) ( ( (u) >> STD_DTOA_DP_EXPONENT_SHIFT_COUNT ) \ - & STD_DTOA_DP_EXPONENT_MASK ) -#define FP_MANTISSA_NORM(u) ( ( (u) & STD_DTOA_DP_MANTISSA_MASK ) | \ - ( (uint64_t)1 << STD_DTOA_DP_EXPONENT_SHIFT_COUNT ) ) -#define FP_MANTISSA_DENORM(u) ( (u) & STD_DTOA_DP_MANTISSA_MASK ) -#define FP_MANTISSA(u) ( FP_EXPONENT_BIASED(u) ? FP_MANTISSA_NORM(u) : \ - FP_MANTISSA_DENORM(u) ) -#define FP_SIGN(u) ( (u) >> STD_DTOA_DP_SIGN_SHIFT_COUNT ) +#define MY_ISDIGIT(c) (((c) >= '0') && ((c) <= '9')) +#define FP_EXPONENT(u) \ + ((((u) >> STD_DTOA_DP_EXPONENT_SHIFT_COUNT) \ + & STD_DTOA_DP_EXPONENT_MASK) \ + - STD_DTOA_DP_EXPONENT_BIAS) +#define FP_EXPONENT_BIASED(u) \ + (((u) >> STD_DTOA_DP_EXPONENT_SHIFT_COUNT) & STD_DTOA_DP_EXPONENT_MASK) +#define FP_MANTISSA_NORM(u) \ + (((u) & STD_DTOA_DP_MANTISSA_MASK) \ + | ((uint64_t)1 << STD_DTOA_DP_EXPONENT_SHIFT_COUNT)) +#define FP_MANTISSA_DENORM(u) ((u) & STD_DTOA_DP_MANTISSA_MASK) +#define FP_MANTISSA(u) \ + (FP_EXPONENT_BIASED(u) ? FP_MANTISSA_NORM(u) : FP_MANTISSA_DENORM(u)) +#define FP_SIGN(u) ((u) >> STD_DTOA_DP_SIGN_SHIFT_COUNT) // // Type Definitions // -typedef enum -{ - FP_TYPE_UNKOWN = 0, - FP_TYPE_NEGATIVE_INF, - FP_TYPE_POSITIVE_INF, - FP_TYPE_NAN, - FP_TYPE_GENERAL, +typedef enum { + FP_TYPE_UNKOWN = 0, + FP_TYPE_NEGATIVE_INF, + FP_TYPE_POSITIVE_INF, + FP_TYPE_NAN, + FP_TYPE_GENERAL, } FloatingPointType; // @@ -88,21 +90,20 @@ typedef enum extern "C" { #endif // #ifdef __cplusplus -double fp_pow_10( int nPow ); -double fp_round( double dNumber, int nPrecision ); -int fp_log_10( double dNumber ); -int fp_check_special_cases( double dNumber, FloatingPointType* pNumberType ); -int std_dtoa_decimal( double dNumber, int nPrecision, - char acIntegerPart[ STD_DTOA_FORMAT_INTEGER_SIZE ], - char acFractionPart[ STD_DTOA_FORMAT_FRACTION_SIZE ] ); -int std_dtoa_hex( double dNumber, int nPrecision, char cFormat, - char acIntegerPart[ STD_DTOA_FORMAT_INTEGER_SIZE ], - char acFractionPart[ STD_DTOA_FORMAT_FRACTION_SIZE ], - int* pnExponent ); +double fp_pow_10(int nPow); +double fp_round(double dNumber, int nPrecision); +int fp_log_10(double dNumber); +int fp_check_special_cases(double dNumber, FloatingPointType *pNumberType); +int std_dtoa_decimal(double dNumber, int nPrecision, + char acIntegerPart[STD_DTOA_FORMAT_INTEGER_SIZE], + char acFractionPart[STD_DTOA_FORMAT_FRACTION_SIZE]); +int std_dtoa_hex(double dNumber, int nPrecision, char cFormat, + char acIntegerPart[STD_DTOA_FORMAT_INTEGER_SIZE], + char acFractionPart[STD_DTOA_FORMAT_FRACTION_SIZE], + int *pnExponent); #ifdef __cplusplus } #endif // #ifdef __cplusplus -#endif // STD_DTOA_H - +#endif // STD_DTOA_H diff --git a/inc/uthash.h b/inc/uthash.h index 96322074..96d4503f 100644 --- a/inc/uthash.h +++ b/inc/uthash.h @@ -24,36 +24,37 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef UTHASH_H #define UTHASH_H -#include /* memcmp,strlen */ -#include /* ptrdiff_t */ -#include /* exit() */ +#include /* ptrdiff_t */ +#include /* exit() */ +#include /* memcmp,strlen */ /* These macros use decltype or the earlier __typeof GNU extension. As decltype is only available in newer compilers (VS2010 or gcc 4.3+ when compiling c++ source) this code uses whatever method is needed or, for VS2008 where neither is available, uses casting workarounds. */ -#ifdef _MSC_VER /* MS compiler */ -#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode */ +#ifdef _MSC_VER /* MS compiler */ +#if _MSC_VER >= 1600 && defined(__cplusplus) /* VS2010 or newer in C++ mode \ + */ #define DECLTYPE(x) (decltype(x)) -#else /* VS2008 or older (or VS2010 in C mode) */ +#else /* VS2008 or older (or VS2010 in C mode) */ #define NO_DECLTYPE #define DECLTYPE(x) #endif -#else /* GNU, Sun and other compilers */ +#else /* GNU, Sun and other compilers */ #define DECLTYPE(x) (__typeof(x)) #endif #ifdef NO_DECLTYPE -#define DECLTYPE_ASSIGN(dst,src) \ -do { \ - char **_da_dst = (char**)(&(dst)); \ - *_da_dst = (char*)(src); \ -} while(0) +#define DECLTYPE_ASSIGN(dst, src) \ + do { \ + char **_da_dst = (char **)(&(dst)); \ + *_da_dst = (char *)(src); \ + } while(0) #else -#define DECLTYPE_ASSIGN(dst,src) \ -do { \ - (dst) = DECLTYPE(dst)(src); \ -} while(0) +#define DECLTYPE_ASSIGN(dst, src) \ + do { \ + (dst) = DECLTYPE(dst)(src); \ + } while(0) #endif /* a number of the hash function use uint32_t which isn't defined on win32 */ @@ -61,7 +62,7 @@ do { typedef unsigned int uint32_t; typedef unsigned char uint8_t; #else -#include /* uint32_t */ +#include /* uint32_t */ #endif #define UTHASH_VERSION 1.9.4 @@ -74,118 +75,142 @@ typedef unsigned char uint8_t; #define UTHASH_FREE free #endif -#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ -#define uthash_malloc(sz) UTHASH_MALLOC(sz) /* malloc fcn */ -#define uthash_free(ptr,sz) UTHASH_FREE(ptr) /* free fcn */ +#define uthash_fatal(msg) exit(-1) /* fatal error (out of memory,etc) */ +#define uthash_malloc(sz) \ + UTHASH_MALLOC(sz) /* malloc fcn */ +#define uthash_free(ptr, sz) \ + UTHASH_FREE(ptr) /* free fcn */ -#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ -#define uthash_expand_fyi(tbl) /* can be defined to log expands */ +#define uthash_noexpand_fyi(tbl) /* can be defined to log noexpand */ +#define uthash_expand_fyi(tbl) /* can be defined to log expands */ /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ -#define HASH_INITIAL_NUM_BUCKETS_LOG2 5 /* lg2 of initial number of buckets */ -#define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ +#define HASH_INITIAL_NUM_BUCKETS 32 /* initial number of buckets */ +#define HASH_INITIAL_NUM_BUCKETS_LOG2 \ + 5 /* lg2 of initial number of buckets \ + */ +#define HASH_BKT_CAPACITY_THRESH 10 /* expand when bucket count reaches */ /* calculate the element whose hash handle address is hhe */ -#define ELMT_FROM_HH(tbl,hhp) ((void*)(((char*)(hhp)) - ((tbl)->hho))) - -#define HASH_FIND(hh,head,keyptr,keylen,out) \ -do { \ - unsigned _hf_bkt,_hf_hashv; \ - out=NULL; \ - if (head) { \ - HASH_FCN(keyptr,keylen, (head)->hh.tbl->num_buckets, _hf_hashv, _hf_bkt); \ - if (HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ - HASH_FIND_IN_BKT((head)->hh.tbl, hh, (head)->hh.tbl->buckets[ _hf_bkt ], \ - keyptr,keylen,out); \ - } \ - } \ -} while (0) +#define ELMT_FROM_HH(tbl, hhp) ((void *)(((char *)(hhp)) - ((tbl)->hho))) + +#define HASH_FIND(hh, head, keyptr, keylen, out) \ + do { \ + unsigned _hf_bkt, _hf_hashv; \ + out = NULL; \ + if(head) { \ + HASH_FCN(keyptr, keylen, (head)->hh.tbl->num_buckets, \ + _hf_hashv, _hf_bkt); \ + if(HASH_BLOOM_TEST((head)->hh.tbl, _hf_hashv)) { \ + HASH_FIND_IN_BKT( \ + (head)->hh.tbl, hh, \ + (head)->hh.tbl->buckets[_hf_bkt], keyptr, \ + keylen, out); \ + } \ + } \ + } while(0) #ifdef HASH_BLOOM #define HASH_BLOOM_BITLEN (1ULL << HASH_BLOOM) -#define HASH_BLOOM_BYTELEN (HASH_BLOOM_BITLEN/8) + ((HASH_BLOOM_BITLEN%8) ? 1:0) -#define HASH_BLOOM_MAKE(tbl) \ -do { \ - (tbl)->bloom_nbits = HASH_BLOOM; \ - (tbl)->bloom_bv = (uint8_t*)uthash_malloc(HASH_BLOOM_BYTELEN); \ - if (!((tbl)->bloom_bv)) { uthash_fatal( "out of memory"); } \ - memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ - (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ -} while (0); - -#define HASH_BLOOM_FREE(tbl) \ -do { \ - uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ -} while (0); - -#define HASH_BLOOM_BITSET(bv,idx) (bv[(idx)/8] |= (1U << ((idx)%8))) -#define HASH_BLOOM_BITTEST(bv,idx) (bv[(idx)/8] & (1U << ((idx)%8))) - -#define HASH_BLOOM_ADD(tbl,hashv) \ - HASH_BLOOM_BITSET((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) - -#define HASH_BLOOM_TEST(tbl,hashv) \ - HASH_BLOOM_BITTEST((tbl)->bloom_bv, (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) +#define HASH_BLOOM_BYTELEN \ + (HASH_BLOOM_BITLEN / 8) + ((HASH_BLOOM_BITLEN % 8) ? 1 : 0) +#define HASH_BLOOM_MAKE(tbl) \ + do { \ + (tbl)->bloom_nbits = HASH_BLOOM; \ + (tbl)->bloom_bv \ + = (uint8_t *)uthash_malloc(HASH_BLOOM_BYTELEN); \ + if(!((tbl)->bloom_bv)) { \ + uthash_fatal("out of memory"); \ + } \ + memset((tbl)->bloom_bv, 0, HASH_BLOOM_BYTELEN); \ + (tbl)->bloom_sig = HASH_BLOOM_SIGNATURE; \ + } while(0); + +#define HASH_BLOOM_FREE(tbl) \ + do { \ + uthash_free((tbl)->bloom_bv, HASH_BLOOM_BYTELEN); \ + } while(0); + +#define HASH_BLOOM_BITSET(bv, idx) (bv[(idx) / 8] |= (1U << ((idx) % 8))) +#define HASH_BLOOM_BITTEST(bv, idx) (bv[(idx) / 8] & (1U << ((idx) % 8))) + +#define HASH_BLOOM_ADD(tbl, hashv) \ + HASH_BLOOM_BITSET( \ + (tbl)->bloom_bv, \ + (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) + +#define HASH_BLOOM_TEST(tbl, hashv) \ + HASH_BLOOM_BITTEST( \ + (tbl)->bloom_bv, \ + (hashv & (uint32_t)((1ULL << (tbl)->bloom_nbits) - 1))) #else #define HASH_BLOOM_MAKE(tbl) #define HASH_BLOOM_FREE(tbl) -#define HASH_BLOOM_ADD(tbl,hashv) -#define HASH_BLOOM_TEST(tbl,hashv) (1) +#define HASH_BLOOM_ADD(tbl, hashv) +#define HASH_BLOOM_TEST(tbl, hashv) (1) #endif -#define HASH_MAKE_TABLE(hh,head) \ -do { \ - (head)->hh.tbl = (UT_hash_table*)uthash_malloc( \ - sizeof(UT_hash_table)); \ - if (!((head)->hh.tbl)) { uthash_fatal( "out of memory"); } \ - memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ - (head)->hh.tbl->tail = &((head)->hh); \ - (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ - (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ - (head)->hh.tbl->hho = (char*)(&(head)->hh) - (char*)(head); \ - (head)->hh.tbl->buckets = (UT_hash_bucket*)uthash_malloc( \ - HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ - if (! (head)->hh.tbl->buckets) { uthash_fatal( "out of memory"); } \ - memset((head)->hh.tbl->buckets, 0, \ - HASH_INITIAL_NUM_BUCKETS*sizeof(struct UT_hash_bucket)); \ - HASH_BLOOM_MAKE((head)->hh.tbl); \ - (head)->hh.tbl->signature = HASH_SIGNATURE; \ -} while(0) - -#define HASH_ADD(hh,head,fieldname,keylen_in,add) \ - HASH_ADD_KEYPTR(hh,head,&add->fieldname,keylen_in,add) - -#define HASH_ADD_KEYPTR(hh,head,keyptr,keylen_in,add) \ -do { \ - unsigned _ha_bkt; \ - (add)->hh.next = NULL; \ - (add)->hh.key = (char*)keyptr; \ - (add)->hh.keylen = keylen_in; \ - if (!(head)) { \ - head = (add); \ - (head)->hh.prev = NULL; \ - HASH_MAKE_TABLE(hh,head); \ - } else { \ - (head)->hh.tbl->tail->next = (add); \ - (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail); \ - (head)->hh.tbl->tail = &((add)->hh); \ - } \ - (head)->hh.tbl->num_items++; \ - (add)->hh.tbl = (head)->hh.tbl; \ - HASH_FCN(keyptr,keylen_in, (head)->hh.tbl->num_buckets, \ - (add)->hh.hashv, _ha_bkt); \ - HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt],&(add)->hh); \ - HASH_BLOOM_ADD((head)->hh.tbl,(add)->hh.hashv); \ - HASH_EMIT_KEY(hh,head,keyptr,keylen_in); \ - HASH_FSCK(hh,head); \ -} while(0) - -#define HASH_TO_BKT( hashv, num_bkts, bkt ) \ -do { \ - bkt = ((hashv) & ((num_bkts) - 1)); \ -} while(0) +#define HASH_MAKE_TABLE(hh, head) \ + do { \ + (head)->hh.tbl \ + = (UT_hash_table *)uthash_malloc(sizeof(UT_hash_table)); \ + if(!((head)->hh.tbl)) { \ + uthash_fatal("out of memory"); \ + } \ + memset((head)->hh.tbl, 0, sizeof(UT_hash_table)); \ + (head)->hh.tbl->tail = &((head)->hh); \ + (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ + (head)->hh.tbl->log2_num_buckets \ + = HASH_INITIAL_NUM_BUCKETS_LOG2; \ + (head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \ + (head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc( \ + HASH_INITIAL_NUM_BUCKETS \ + * sizeof(struct UT_hash_bucket)); \ + if(!(head)->hh.tbl->buckets) { \ + uthash_fatal("out of memory"); \ + } \ + memset((head)->hh.tbl->buckets, 0, \ + HASH_INITIAL_NUM_BUCKETS \ + * sizeof(struct UT_hash_bucket)); \ + HASH_BLOOM_MAKE((head)->hh.tbl); \ + (head)->hh.tbl->signature = HASH_SIGNATURE; \ + } while(0) + +#define HASH_ADD(hh, head, fieldname, keylen_in, add) \ + HASH_ADD_KEYPTR(hh, head, &add->fieldname, keylen_in, add) + +#define HASH_ADD_KEYPTR(hh, head, keyptr, keylen_in, add) \ + do { \ + unsigned _ha_bkt; \ + (add)->hh.next = NULL; \ + (add)->hh.key = (char *)keyptr; \ + (add)->hh.keylen = keylen_in; \ + if(!(head)) { \ + head = (add); \ + (head)->hh.prev = NULL; \ + HASH_MAKE_TABLE(hh, head); \ + } else { \ + (head)->hh.tbl->tail->next = (add); \ + (add)->hh.prev = ELMT_FROM_HH((head)->hh.tbl, \ + (head)->hh.tbl->tail); \ + (head)->hh.tbl->tail = &((add)->hh); \ + } \ + (head)->hh.tbl->num_items++; \ + (add)->hh.tbl = (head)->hh.tbl; \ + HASH_FCN(keyptr, keylen_in, (head)->hh.tbl->num_buckets, \ + (add)->hh.hashv, _ha_bkt); \ + HASH_ADD_TO_BKT((head)->hh.tbl->buckets[_ha_bkt], \ + &(add)->hh); \ + HASH_BLOOM_ADD((head)->hh.tbl, (add)->hh.hashv); \ + HASH_EMIT_KEY(hh, head, keyptr, keylen_in); \ + HASH_FSCK(hh, head); \ + } while(0) + +#define HASH_TO_BKT(hashv, num_bkts, bkt) \ + do { \ + bkt = ((hashv) & ((num_bkts) - 1)); \ + } while(0) /* delete "delptr" from the hash table. * "the usual" patch-up process for the app-order doubly-linked-list. @@ -199,138 +224,174 @@ do { * copy the deletee pointer, then the latter references are via that * scratch pointer rather than through the repointed (users) symbol. */ -#define HASH_DELETE(hh,head,delptr) \ -do { \ - unsigned _hd_bkt; \ - struct UT_hash_handle *_hd_hh_del; \ - if ( ((delptr)->hh.prev == NULL) && ((delptr)->hh.next == NULL) ) { \ - uthash_free((head)->hh.tbl->buckets, \ - (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ - HASH_BLOOM_FREE((head)->hh.tbl); \ - uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ - head = NULL; \ - } else { \ - _hd_hh_del = &((delptr)->hh); \ - if ((delptr) == ELMT_FROM_HH((head)->hh.tbl,(head)->hh.tbl->tail)) { \ - (head)->hh.tbl->tail = \ - (UT_hash_handle*)((char*)((delptr)->hh.prev) + \ - (head)->hh.tbl->hho); \ - } \ - if ((delptr)->hh.prev) { \ - ((UT_hash_handle*)((char*)((delptr)->hh.prev) + \ - (head)->hh.tbl->hho))->next = (delptr)->hh.next; \ - } else { \ - DECLTYPE_ASSIGN(head,(delptr)->hh.next); \ - } \ - if (_hd_hh_del->next) { \ - ((UT_hash_handle*)((char*)_hd_hh_del->next + \ - (head)->hh.tbl->hho))->prev = \ - _hd_hh_del->prev; \ - } \ - HASH_TO_BKT( _hd_hh_del->hashv, (head)->hh.tbl->num_buckets, _hd_bkt); \ - HASH_DEL_IN_BKT(hh,(head)->hh.tbl->buckets[_hd_bkt], _hd_hh_del); \ - (head)->hh.tbl->num_items--; \ - } \ - HASH_FSCK(hh,head); \ -} while (0) - -/* use this function to delete an item from a table only if its in that table */ -#define HASH_DELETE_IF(hh,group,ptr) \ -do {\ - if(ptr && group && ptr->hh.tbl) { \ - HASH_DELETE(hh,group,ptr); \ - ptr->hh.tbl = 0;\ - } \ -} while(0) +#define HASH_DELETE(hh, head, delptr) \ + do { \ + unsigned _hd_bkt; \ + struct UT_hash_handle *_hd_hh_del; \ + if(((delptr)->hh.prev == NULL) \ + && ((delptr)->hh.next == NULL)) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets \ + * sizeof(struct UT_hash_bucket)); \ + HASH_BLOOM_FREE((head)->hh.tbl); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + head = NULL; \ + } else { \ + _hd_hh_del = &((delptr)->hh); \ + if((delptr) \ + == ELMT_FROM_HH((head)->hh.tbl, \ + (head)->hh.tbl->tail)) { \ + (head)->hh.tbl->tail \ + = (UT_hash_handle \ + *)((char *)((delptr)->hh.prev) \ + + (head)->hh.tbl->hho); \ + } \ + if((delptr)->hh.prev) { \ + ((UT_hash_handle *)((char *)((delptr) \ + ->hh.prev) \ + + (head)->hh.tbl->hho)) \ + ->next \ + = (delptr)->hh.next; \ + } else { \ + DECLTYPE_ASSIGN(head, (delptr)->hh.next); \ + } \ + if(_hd_hh_del->next) { \ + ((UT_hash_handle *)((char *)_hd_hh_del->next \ + + (head)->hh.tbl->hho)) \ + ->prev \ + = _hd_hh_del->prev; \ + } \ + HASH_TO_BKT(_hd_hh_del->hashv, \ + (head)->hh.tbl->num_buckets, _hd_bkt); \ + HASH_DEL_IN_BKT(hh, (head)->hh.tbl->buckets[_hd_bkt], \ + _hd_hh_del); \ + (head)->hh.tbl->num_items--; \ + } \ + HASH_FSCK(hh, head); \ + } while(0) + +/* use this function to delete an item from a table only if its in that table + */ +#define HASH_DELETE_IF(hh, group, ptr) \ + do { \ + if(ptr && group && ptr->hh.tbl) { \ + HASH_DELETE(hh, group, ptr); \ + ptr->hh.tbl = 0; \ + } \ + } while(0) /* convenience forms of HASH_FIND/HASH_ADD/HASH_DEL */ -#define HASH_FIND_STR(head,findstr,out) \ - HASH_FIND(hh,head,findstr,strlen(findstr),out) -#define HASH_ADD_STR(head,strfield,add) \ - HASH_ADD(hh,head,strfield,strlen(add->strfield),add) -#define HASH_FIND_INT(head,findint,out) \ - HASH_FIND(hh,head,findint,sizeof(int),out) -#define HASH_ADD_INT(head,intfield,add) \ - HASH_ADD(hh,head,intfield,sizeof(int),add) -#define HASH_FIND_PTR(head,findptr,out) \ - HASH_FIND(hh,head,findptr,sizeof(void *),out) -#define HASH_ADD_PTR(head,ptrfield,add) \ - HASH_ADD(hh,head,ptrfield,sizeof(void *),add) -#define HASH_DEL(head,delptr) \ - HASH_DELETE(hh,head,delptr) - -/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is defined. - * This is for uthash developer only; it compiles away if HASH_DEBUG isn't defined. +#define HASH_FIND_STR(head, findstr, out) \ + HASH_FIND(hh, head, findstr, strlen(findstr), out) +#define HASH_ADD_STR(head, strfield, add) \ + HASH_ADD(hh, head, strfield, strlen(add->strfield), add) +#define HASH_FIND_INT(head, findint, out) \ + HASH_FIND(hh, head, findint, sizeof(int), out) +#define HASH_ADD_INT(head, intfield, add) \ + HASH_ADD(hh, head, intfield, sizeof(int), add) +#define HASH_FIND_PTR(head, findptr, out) \ + HASH_FIND(hh, head, findptr, sizeof(void *), out) +#define HASH_ADD_PTR(head, ptrfield, add) \ + HASH_ADD(hh, head, ptrfield, sizeof(void *), add) +#define HASH_DEL(head, delptr) HASH_DELETE(hh, head, delptr) + +/* HASH_FSCK checks hash integrity on every add/delete when HASH_DEBUG is + * defined. This is for uthash developer only; it compiles away if HASH_DEBUG + * isn't defined. */ #ifdef HASH_DEBUG -#define HASH_OOPS(...) do { fprintf(stderr,__VA_ARGS__); exit(-1); } while (0) -#define HASH_FSCK(hh,head) \ -do { \ - unsigned _bkt_i; \ - unsigned _count, _bkt_count; \ - char *_prev; \ - struct UT_hash_handle *_thh; \ - if (head) { \ - _count = 0; \ - for( _bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; _bkt_i++) { \ - _bkt_count = 0; \ - _thh = (head)->hh.tbl->buckets[_bkt_i].hh_head; \ - _prev = NULL; \ - while (_thh) { \ - if (_prev != (char*)(_thh->hh_prev)) { \ - HASH_OOPS("invalid hh_prev %p, actual %p\n", \ - _thh->hh_prev, _prev ); \ - } \ - _bkt_count++; \ - _prev = (char*)(_thh); \ - _thh = _thh->hh_next; \ - } \ - _count += _bkt_count; \ - if ((head)->hh.tbl->buckets[_bkt_i].count != _bkt_count) { \ - HASH_OOPS("invalid bucket count %d, actual %d\n", \ - (head)->hh.tbl->buckets[_bkt_i].count, _bkt_count); \ - } \ - } \ - if (_count != (head)->hh.tbl->num_items) { \ - HASH_OOPS("invalid hh item count %d, actual %d\n", \ - (head)->hh.tbl->num_items, _count ); \ - } \ - /* traverse hh in app order; check next/prev integrity, count */ \ - _count = 0; \ - _prev = NULL; \ - _thh = &(head)->hh; \ - while (_thh) { \ - _count++; \ - if (_prev !=(char*)(_thh->prev)) { \ - HASH_OOPS("invalid prev %p, actual %p\n", \ - _thh->prev, _prev ); \ - } \ - _prev = (char*)ELMT_FROM_HH((head)->hh.tbl, _thh); \ - _thh = ( _thh->next ? (UT_hash_handle*)((char*)(_thh->next) + \ - (head)->hh.tbl->hho) : NULL ); \ - } \ - if (_count != (head)->hh.tbl->num_items) { \ - HASH_OOPS("invalid app item count %d, actual %d\n", \ - (head)->hh.tbl->num_items, _count ); \ - } \ - } \ -} while (0) +#define HASH_OOPS(...) \ + do { \ + fprintf(stderr, __VA_ARGS__); \ + exit(-1); \ + } while(0) +#define HASH_FSCK(hh, head) \ + do { \ + unsigned _bkt_i; \ + unsigned _count, _bkt_count; \ + char *_prev; \ + struct UT_hash_handle *_thh; \ + if(head) { \ + _count = 0; \ + for(_bkt_i = 0; _bkt_i < (head)->hh.tbl->num_buckets; \ + _bkt_i++) { \ + _bkt_count = 0; \ + _thh = (head) \ + ->hh.tbl->buckets[_bkt_i] \ + .hh_head; \ + _prev = NULL; \ + while(_thh) { \ + if(_prev \ + != (char *)(_thh->hh_prev)) { \ + HASH_OOPS("invalid hh_prev " \ + "%p, actual %p\n", \ + _thh->hh_prev, \ + _prev); \ + } \ + _bkt_count++; \ + _prev = (char *)(_thh); \ + _thh = _thh->hh_next; \ + } \ + _count += _bkt_count; \ + if((head)->hh.tbl->buckets[_bkt_i].count \ + != _bkt_count) { \ + HASH_OOPS( \ + "invalid bucket count %d, " \ + "actual %d\n", \ + (head) \ + ->hh.tbl->buckets[_bkt_i] \ + .count, \ + _bkt_count); \ + } \ + } \ + if(_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS( \ + "invalid hh item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count); \ + } \ + /* traverse hh in app order; check next/prev \ + * integrity, count */ \ + _count = 0; \ + _prev = NULL; \ + _thh = &(head)->hh; \ + while(_thh) { \ + _count++; \ + if(_prev != (char *)(_thh->prev)) { \ + HASH_OOPS( \ + "invalid prev %p, actual %p\n", \ + _thh->prev, _prev); \ + } \ + _prev = (char *)ELMT_FROM_HH((head)->hh.tbl, \ + _thh); \ + _thh = (_thh->next \ + ? (UT_hash_handle \ + *)((char *)(_thh->next) \ + + (head)->hh.tbl->hho) \ + : NULL); \ + } \ + if(_count != (head)->hh.tbl->num_items) { \ + HASH_OOPS( \ + "invalid app item count %d, actual %d\n", \ + (head)->hh.tbl->num_items, _count); \ + } \ + } \ + } while(0) #else -#define HASH_FSCK(hh,head) +#define HASH_FSCK(hh, head) #endif /* When compiled with -DHASH_EMIT_KEYS, length-prefixed keys are emitted to * the descriptor to which this macro is defined for tuning the hash function. * The app can #include to get the prototype for write(2). */ #ifdef HASH_EMIT_KEYS -#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) \ -do { \ - unsigned _klen = fieldlen; \ - write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ - write(HASH_EMIT_KEYS, keyptr, fieldlen); \ -} while (0) +#define HASH_EMIT_KEY(hh, head, keyptr, fieldlen) \ + do { \ + unsigned _klen = fieldlen; \ + write(HASH_EMIT_KEYS, &_klen, sizeof(_klen)); \ + write(HASH_EMIT_KEYS, keyptr, fieldlen); \ + } while(0) #else -#define HASH_EMIT_KEY(hh,head,keyptr,fieldlen) +#define HASH_EMIT_KEY(hh, head, keyptr, fieldlen) #endif /* default to Jenkin's hash unless overridden e.g. DHASH_FUNCTION=HASH_SAX */ @@ -341,167 +402,215 @@ do { #endif /* The Bernstein hash function, used in Perl prior to v5.6 */ -#define HASH_BER(key,keylen,num_bkts,hashv,bkt) \ -do { \ - unsigned _hb_keylen=keylen; \ - char *_hb_key=(char*)(key); \ - (hashv) = 0; \ - while (_hb_keylen--) { (hashv) = ((hashv) * 33) + *_hb_key++; } \ - bkt = (hashv) & (num_bkts-1); \ -} while (0) - +#define HASH_BER(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _hb_keylen = keylen; \ + char *_hb_key = (char *)(key); \ + (hashv) = 0; \ + while(_hb_keylen--) { \ + (hashv) = ((hashv) * 33) + *_hb_key++; \ + } \ + bkt = (hashv) & (num_bkts - 1); \ + } while(0) /* SAX/FNV/OAT/JEN hash functions are macro variants of those listed at * http://eternallyconfuzzled.com/tuts/algorithms/jsw_tut_hashing.aspx */ -#define HASH_SAX(key,keylen,num_bkts,hashv,bkt) \ -do { \ - unsigned _sx_i; \ - char *_hs_key=(char*)(key); \ - hashv = 0; \ - for(_sx_i=0; _sx_i < keylen; _sx_i++) \ - hashv ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ - bkt = hashv & (num_bkts-1); \ -} while (0) - -#define HASH_FNV(key,keylen,num_bkts,hashv,bkt) \ -do { \ - unsigned _fn_i; \ - char *_hf_key=(char*)(key); \ - hashv = 2166136261UL; \ - for(_fn_i=0; _fn_i < keylen; _fn_i++) \ - hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ - bkt = hashv & (num_bkts-1); \ -} while(0); - -#define HASH_OAT(key,keylen,num_bkts,hashv,bkt) \ -do { \ - unsigned _ho_i; \ - char *_ho_key=(char*)(key); \ - hashv = 0; \ - for(_ho_i=0; _ho_i < keylen; _ho_i++) { \ - hashv += _ho_key[_ho_i]; \ - hashv += (hashv << 10); \ - hashv ^= (hashv >> 6); \ - } \ - hashv += (hashv << 3); \ - hashv ^= (hashv >> 11); \ - hashv += (hashv << 15); \ - bkt = hashv & (num_bkts-1); \ -} while(0) - -#define HASH_JEN_MIX(a,b,c) \ -do { \ - __builtin_sub_overflow(a, b, &a); __builtin_sub_overflow(a, c, &a); a ^= ( c >> 13 ); \ - __builtin_sub_overflow(b, c, &b); __builtin_sub_overflow(b, a, &b); b ^= ( a << 8 ); \ - __builtin_sub_overflow(c, a, &c); __builtin_sub_overflow(c, b, &c); c ^= ( b >> 13 ); \ - __builtin_sub_overflow(a, b, &a); __builtin_sub_overflow(a, c, &a); a ^= ( c >> 12 ); \ - __builtin_sub_overflow(b, c, &b); __builtin_sub_overflow(b, a, &b); b ^= ( a << 16 ); \ - __builtin_sub_overflow(c, a, &c); __builtin_sub_overflow(c, b, &c); c ^= ( b >> 5 ); \ - __builtin_sub_overflow(a, b, &a); __builtin_sub_overflow(a, c, &a); a ^= ( c >> 3 ); \ - __builtin_sub_overflow(b, c, &b); __builtin_sub_overflow(b, a, &b); b ^= ( a << 10 ); \ - __builtin_sub_overflow(c, a, &c); __builtin_sub_overflow(c, b, &c); c ^= ( b >> 15 ); \ -} while (0) - -#define HASH_JEN(key,keylen,num_bkts,hashv,bkt) \ -do { \ - unsigned _hj_i,_hj_j,_hj_k; \ - char *_hj_key=(char*)(key); \ - hashv = 0xfeedbeef; \ - _hj_i = _hj_j = 0x9e3779b9; \ - _hj_k = keylen; \ - while (_hj_k >= 12) { \ - _hj_i += (_hj_key[0] + ( (unsigned)_hj_key[1] << 8 ) \ - + ( (unsigned)_hj_key[2] << 16 ) ); \ - __builtin_add_overflow(_hj_i, ( (unsigned)_hj_key[3] << 24 ), &_hj_i); \ - _hj_j += (_hj_key[4] + ( (unsigned)_hj_key[5] << 8 ) \ - + ( (unsigned)_hj_key[6] << 16 ) ); \ - __builtin_add_overflow(_hj_j, ( (unsigned)_hj_key[7] << 24 ), &_hj_j); \ - hashv += (_hj_key[8] + ( (unsigned)_hj_key[9] << 8 ) \ - + ( (unsigned)_hj_key[10] << 16 ) ); \ - __builtin_add_overflow(hashv, ( (unsigned)_hj_key[11] << 24 ), &hashv); \ - \ - HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ - \ - _hj_key += 12; \ - _hj_k -= 12; \ - } \ - hashv += keylen; \ - switch ( _hj_k ) { \ - case 11: __builtin_add_overflow(hashv, ( (unsigned)_hj_key[10] << 24 ), &hashv); \ - case 10: __builtin_add_overflow(hashv, ( (unsigned)_hj_key[9] << 16 ), &hashv); \ - case 9: __builtin_add_overflow(hashv, ( (unsigned)_hj_key[8] << 8 ), &hashv); \ - case 8: __builtin_add_overflow(_hj_j, ( (unsigned)_hj_key[7] << 24 ), &_hj_j); \ - case 7: __builtin_add_overflow(_hj_j, ( (unsigned)_hj_key[6] << 16 ), &_hj_j); \ - case 6: __builtin_add_overflow(_hj_j, ( (unsigned)_hj_key[5] << 8 ), &_hj_j); \ - case 5: __builtin_add_overflow(_hj_j, _hj_key[4], &_hj_j); \ - case 4: __builtin_add_overflow(_hj_i, ( (unsigned)_hj_key[3] << 24 ), &_hj_i); \ - case 3: __builtin_add_overflow(_hj_i, ( (unsigned)_hj_key[2] << 16 ), &_hj_i); \ - case 2: __builtin_add_overflow(_hj_i, ( (unsigned)_hj_key[1] << 8 ), &_hj_i); \ - case 1: __builtin_add_overflow(_hj_i, _hj_key[0], &_hj_i); \ - } \ - HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ - bkt = hashv & (num_bkts-1); \ -} while(0) +#define HASH_SAX(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _sx_i; \ + char *_hs_key = (char *)(key); \ + hashv = 0; \ + for(_sx_i = 0; _sx_i < keylen; _sx_i++) \ + hashv \ + ^= (hashv << 5) + (hashv >> 2) + _hs_key[_sx_i]; \ + bkt = hashv & (num_bkts - 1); \ + } while(0) + +#define HASH_FNV(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _fn_i; \ + char *_hf_key = (char *)(key); \ + hashv = 2166136261UL; \ + for(_fn_i = 0; _fn_i < keylen; _fn_i++) \ + hashv = (hashv * 16777619) ^ _hf_key[_fn_i]; \ + bkt = hashv & (num_bkts - 1); \ + } while(0); + +#define HASH_OAT(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _ho_i; \ + char *_ho_key = (char *)(key); \ + hashv = 0; \ + for(_ho_i = 0; _ho_i < keylen; _ho_i++) { \ + hashv += _ho_key[_ho_i]; \ + hashv += (hashv << 10); \ + hashv ^= (hashv >> 6); \ + } \ + hashv += (hashv << 3); \ + hashv ^= (hashv >> 11); \ + hashv += (hashv << 15); \ + bkt = hashv & (num_bkts - 1); \ + } while(0) + +#define HASH_JEN_MIX(a, b, c) \ + do { \ + __builtin_sub_overflow(a, b, &a); \ + __builtin_sub_overflow(a, c, &a); \ + a ^= (c >> 13); \ + __builtin_sub_overflow(b, c, &b); \ + __builtin_sub_overflow(b, a, &b); \ + b ^= (a << 8); \ + __builtin_sub_overflow(c, a, &c); \ + __builtin_sub_overflow(c, b, &c); \ + c ^= (b >> 13); \ + __builtin_sub_overflow(a, b, &a); \ + __builtin_sub_overflow(a, c, &a); \ + a ^= (c >> 12); \ + __builtin_sub_overflow(b, c, &b); \ + __builtin_sub_overflow(b, a, &b); \ + b ^= (a << 16); \ + __builtin_sub_overflow(c, a, &c); \ + __builtin_sub_overflow(c, b, &c); \ + c ^= (b >> 5); \ + __builtin_sub_overflow(a, b, &a); \ + __builtin_sub_overflow(a, c, &a); \ + a ^= (c >> 3); \ + __builtin_sub_overflow(b, c, &b); \ + __builtin_sub_overflow(b, a, &b); \ + b ^= (a << 10); \ + __builtin_sub_overflow(c, a, &c); \ + __builtin_sub_overflow(c, b, &c); \ + c ^= (b >> 15); \ + } while(0) + +#define HASH_JEN(key, keylen, num_bkts, hashv, bkt) \ + do { \ + unsigned _hj_i, _hj_j, _hj_k; \ + char *_hj_key = (char *)(key); \ + hashv = 0xfeedbeef; \ + _hj_i = _hj_j = 0x9e3779b9; \ + _hj_k = keylen; \ + while(_hj_k >= 12) { \ + _hj_i += (_hj_key[0] + ((unsigned)_hj_key[1] << 8) \ + + ((unsigned)_hj_key[2] << 16)); \ + __builtin_add_overflow( \ + _hj_i, ((unsigned)_hj_key[3] << 24), &_hj_i); \ + _hj_j += (_hj_key[4] + ((unsigned)_hj_key[5] << 8) \ + + ((unsigned)_hj_key[6] << 16)); \ + __builtin_add_overflow( \ + _hj_j, ((unsigned)_hj_key[7] << 24), &_hj_j); \ + hashv += (_hj_key[8] + ((unsigned)_hj_key[9] << 8) \ + + ((unsigned)_hj_key[10] << 16)); \ + __builtin_add_overflow( \ + hashv, ((unsigned)_hj_key[11] << 24), &hashv); \ + \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + \ + _hj_key += 12; \ + _hj_k -= 12; \ + } \ + hashv += keylen; \ + switch(_hj_k) { \ + case 11: \ + __builtin_add_overflow( \ + hashv, ((unsigned)_hj_key[10] << 24), &hashv); \ + case 10: \ + __builtin_add_overflow( \ + hashv, ((unsigned)_hj_key[9] << 16), &hashv); \ + case 9: \ + __builtin_add_overflow( \ + hashv, ((unsigned)_hj_key[8] << 8), &hashv); \ + case 8: \ + __builtin_add_overflow( \ + _hj_j, ((unsigned)_hj_key[7] << 24), &_hj_j); \ + case 7: \ + __builtin_add_overflow( \ + _hj_j, ((unsigned)_hj_key[6] << 16), &_hj_j); \ + case 6: \ + __builtin_add_overflow( \ + _hj_j, ((unsigned)_hj_key[5] << 8), &_hj_j); \ + case 5: \ + __builtin_add_overflow(_hj_j, _hj_key[4], &_hj_j); \ + case 4: \ + __builtin_add_overflow( \ + _hj_i, ((unsigned)_hj_key[3] << 24), &_hj_i); \ + case 3: \ + __builtin_add_overflow( \ + _hj_i, ((unsigned)_hj_key[2] << 16), &_hj_i); \ + case 2: \ + __builtin_add_overflow( \ + _hj_i, ((unsigned)_hj_key[1] << 8), &_hj_i); \ + case 1: \ + __builtin_add_overflow(_hj_i, _hj_key[0], &_hj_i); \ + } \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + bkt = hashv & (num_bkts - 1); \ + } while(0) /* The Paul Hsieh hash function */ #undef get16bits -#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ - || defined(_MSC_VER) || defined (__BORLANDC__) || defined (__TURBOC__) -#define get16bits(d) (*((const uint16_t *) (d))) +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) \ + || defined(_MSC_VER) || defined(__BORLANDC__) || defined(__TURBOC__) +#define get16bits(d) (*((const uint16_t *)(d))) #endif -#if !defined (get16bits) -#define get16bits(d) ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ - +(uint32_t)(((const uint8_t *)(d))[0]) ) +#if !defined(get16bits) +#define get16bits(d) \ + ((((uint32_t)(((const uint8_t *)(d))[1])) << 8) \ + + (uint32_t)(((const uint8_t *)(d))[0])) #endif -#define HASH_SFH(key,keylen,num_bkts,hashv,bkt) \ -do { \ - char *_sfh_key=(char*)(key); \ - uint32_t _sfh_tmp, _sfh_len = keylen; \ - \ - int _sfh_rem = _sfh_len & 3; \ - _sfh_len >>= 2; \ - hashv = 0xcafebabe; \ - \ - /* Main loop */ \ - for (;_sfh_len > 0; _sfh_len--) { \ - hashv += get16bits (_sfh_key); \ - _sfh_tmp = (get16bits (_sfh_key+2) << 11) ^ hashv; \ - hashv = (hashv << 16) ^ _sfh_tmp; \ - _sfh_key += 2*sizeof (uint16_t); \ - hashv += hashv >> 11; \ - } \ - \ - /* Handle end cases */ \ - switch (_sfh_rem) { \ - case 3: hashv += get16bits (_sfh_key); \ - hashv ^= hashv << 16; \ - hashv ^= _sfh_key[sizeof (uint16_t)] << 18; \ - hashv += hashv >> 11; \ - break; \ - case 2: hashv += get16bits (_sfh_key); \ - hashv ^= hashv << 11; \ - hashv += hashv >> 17; \ - break; \ - case 1: hashv += *_sfh_key; \ - hashv ^= hashv << 10; \ - hashv += hashv >> 1; \ - } \ - \ - /* Force "avalanching" of final 127 bits */ \ - hashv ^= hashv << 3; \ - hashv += hashv >> 5; \ - hashv ^= hashv << 4; \ - hashv += hashv >> 17; \ - hashv ^= hashv << 25; \ - hashv += hashv >> 6; \ - bkt = hashv & (num_bkts-1); \ -} while(0); +#define HASH_SFH(key, keylen, num_bkts, hashv, bkt) \ + do { \ + char *_sfh_key = (char *)(key); \ + uint32_t _sfh_tmp, _sfh_len = keylen; \ + \ + int _sfh_rem = _sfh_len & 3; \ + _sfh_len >>= 2; \ + hashv = 0xcafebabe; \ + \ + /* Main loop */ \ + for(; _sfh_len > 0; _sfh_len--) { \ + hashv += get16bits(_sfh_key); \ + _sfh_tmp = (get16bits(_sfh_key + 2) << 11) ^ hashv; \ + hashv = (hashv << 16) ^ _sfh_tmp; \ + _sfh_key += 2 * sizeof(uint16_t); \ + hashv += hashv >> 11; \ + } \ + \ + /* Handle end cases */ \ + switch(_sfh_rem) { \ + case 3: \ + hashv += get16bits(_sfh_key); \ + hashv ^= hashv << 16; \ + hashv ^= _sfh_key[sizeof(uint16_t)] << 18; \ + hashv += hashv >> 11; \ + break; \ + case 2: \ + hashv += get16bits(_sfh_key); \ + hashv ^= hashv << 11; \ + hashv += hashv >> 17; \ + break; \ + case 1: \ + hashv += *_sfh_key; \ + hashv ^= hashv << 10; \ + hashv += hashv >> 1; \ + } \ + \ + /* Force "avalanching" of final 127 bits */ \ + hashv ^= hashv << 3; \ + hashv += hashv >> 5; \ + hashv ^= hashv << 4; \ + hashv += hashv >> 17; \ + hashv ^= hashv << 25; \ + hashv += hashv >> 6; \ + bkt = hashv & (num_bkts - 1); \ + } while(0); #ifdef HASH_USING_NO_STRICT_ALIASING -/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned reads. - * For other types of CPU's (e.g. Sparc) an unaligned read causes a bus error. - * MurmurHash uses the faster approach only on CPU's where we know it's safe. +/* The MurmurHash exploits some CPU's (x86,x86_64) tolerance for unaligned + * reads. For other types of CPU's (e.g. Sparc) an unaligned read causes a bus + * error. MurmurHash uses the faster approach only on CPU's where we know it's + * safe. * * Note the preprocessor built-in defines can be emitted using: * @@ -509,117 +618,150 @@ do { * cc -## a.c (where a.c is a simple test file) (Sun Studio) */ #if (defined(__i386__) || defined(__x86_64__)) -#define MUR_GETBLOCK(p,i) p[i] +#define MUR_GETBLOCK(p, i) p[i] #else /* non intel */ #define MUR_PLUS0_ALIGNED(p) (((unsigned long)p & 0x3) == 0) #define MUR_PLUS1_ALIGNED(p) (((unsigned long)p & 0x3) == 1) #define MUR_PLUS2_ALIGNED(p) (((unsigned long)p & 0x3) == 2) #define MUR_PLUS3_ALIGNED(p) (((unsigned long)p & 0x3) == 3) -#define WP(p) ((uint32_t*)((unsigned long)(p) & ~3UL)) -#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) || defined(__ppc64__)) -#define MUR_THREE_ONE(p) ((((*WP(p))&0x00ffffff) << 8) | (((*(WP(p)+1))&0xff000000) >> 24)) -#define MUR_TWO_TWO(p) ((((*WP(p))&0x0000ffff) <<16) | (((*(WP(p)+1))&0xffff0000) >> 16)) -#define MUR_ONE_THREE(p) ((((*WP(p))&0x000000ff) <<24) | (((*(WP(p)+1))&0xffffff00) >> 8)) +#define WP(p) ((uint32_t *)((unsigned long)(p) & ~3UL)) +#if (defined(__BIG_ENDIAN__) || defined(SPARC) || defined(__ppc__) \ + || defined(__ppc64__)) +#define MUR_THREE_ONE(p) \ + ((((*WP(p)) & 0x00ffffff) << 8) \ + | (((*(WP(p) + 1)) & 0xff000000) >> 24)) +#define MUR_TWO_TWO(p) \ + ((((*WP(p)) & 0x0000ffff) << 16) \ + | (((*(WP(p) + 1)) & 0xffff0000) >> 16)) +#define MUR_ONE_THREE(p) \ + ((((*WP(p)) & 0x000000ff) << 24) \ + | (((*(WP(p) + 1)) & 0xffffff00) >> 8)) #else /* assume little endian non-intel */ -#define MUR_THREE_ONE(p) ((((*WP(p))&0xffffff00) >> 8) | (((*(WP(p)+1))&0x000000ff) << 24)) -#define MUR_TWO_TWO(p) ((((*WP(p))&0xffff0000) >>16) | (((*(WP(p)+1))&0x0000ffff) << 16)) -#define MUR_ONE_THREE(p) ((((*WP(p))&0xff000000) >>24) | (((*(WP(p)+1))&0x00ffffff) << 8)) +#define MUR_THREE_ONE(p) \ + ((((*WP(p)) & 0xffffff00) >> 8) \ + | (((*(WP(p) + 1)) & 0x000000ff) << 24)) +#define MUR_TWO_TWO(p) \ + ((((*WP(p)) & 0xffff0000) >> 16) \ + | (((*(WP(p) + 1)) & 0x0000ffff) << 16)) +#define MUR_ONE_THREE(p) \ + ((((*WP(p)) & 0xff000000) >> 24) \ + | (((*(WP(p) + 1)) & 0x00ffffff) << 8)) #endif -#define MUR_GETBLOCK(p,i) (MUR_PLUS0_ALIGNED(p) ? ((p)[i]) : \ - (MUR_PLUS1_ALIGNED(p) ? MUR_THREE_ONE(p) : \ - (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) : \ - MUR_ONE_THREE(p)))) +#define MUR_GETBLOCK(p, i) \ + (MUR_PLUS0_ALIGNED(p) \ + ? ((p)[i]) \ + : (MUR_PLUS1_ALIGNED(p) \ + ? MUR_THREE_ONE(p) \ + : (MUR_PLUS2_ALIGNED(p) ? MUR_TWO_TWO(p) \ + : MUR_ONE_THREE(p)))) #endif -#define MUR_ROTL32(x,r) (((x) << (r)) | ((x) >> (32 - (r)))) -#define MUR_FMIX(_h) \ -do { \ - _h ^= _h >> 16; \ - _h *= 0x85ebca6b; \ - _h ^= _h >> 13; \ - _h *= 0xc2b2ae35l; \ - _h ^= _h >> 16; \ -} while(0) - -#define HASH_MUR(key,keylen,num_bkts,hashv,bkt) \ -do { \ - const uint8_t *_mur_data = (const uint8_t*)(key); \ - const int _mur_nblocks = (keylen) / 4; \ - uint32_t _mur_h1 = 0xf88D5353; \ - uint32_t _mur_c1 = 0xcc9e2d51; \ - uint32_t _mur_c2 = 0x1b873593; \ - const uint32_t *_mur_blocks = (const uint32_t*)(_mur_data+_mur_nblocks*4); \ - int _mur_i; \ - for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \ - uint32_t _mur_k1 = MUR_GETBLOCK(_mur_blocks,_mur_i); \ - _mur_k1 *= _mur_c1; \ - _mur_k1 = MUR_ROTL32(_mur_k1,15); \ - _mur_k1 *= _mur_c2; \ - \ - _mur_h1 ^= _mur_k1; \ - _mur_h1 = MUR_ROTL32(_mur_h1,13); \ - _mur_h1 = _mur_h1*5+0xe6546b64; \ - } \ - const uint8_t *_mur_tail = (const uint8_t*)(_mur_data + _mur_nblocks*4); \ - uint32_t _mur_k1=0; \ - switch((keylen) & 3) { \ - case 3: _mur_k1 ^= _mur_tail[2] << 16; \ - case 2: _mur_k1 ^= _mur_tail[1] << 8; \ - case 1: _mur_k1 ^= _mur_tail[0]; \ - _mur_k1 *= _mur_c1; \ - _mur_k1 = MUR_ROTL32(_mur_k1,15); \ - _mur_k1 *= _mur_c2; \ - _mur_h1 ^= _mur_k1; \ - } \ - _mur_h1 ^= (keylen); \ - MUR_FMIX(_mur_h1); \ - hashv = _mur_h1; \ - bkt = hashv & (num_bkts-1); \ -} while(0) -#endif /* HASH_USING_NO_STRICT_ALIASING */ +#define MUR_ROTL32(x, r) (((x) << (r)) | ((x) >> (32 - (r)))) +#define MUR_FMIX(_h) \ + do { \ + _h ^= _h >> 16; \ + _h *= 0x85ebca6b; \ + _h ^= _h >> 13; \ + _h *= 0xc2b2ae35l; \ + _h ^= _h >> 16; \ + } while(0) + +#define HASH_MUR(key, keylen, num_bkts, hashv, bkt) \ + do { \ + const uint8_t *_mur_data = (const uint8_t *)(key); \ + const int _mur_nblocks = (keylen) / 4; \ + uint32_t _mur_h1 = 0xf88D5353; \ + uint32_t _mur_c1 = 0xcc9e2d51; \ + uint32_t _mur_c2 = 0x1b873593; \ + const uint32_t *_mur_blocks \ + = (const uint32_t *)(_mur_data + _mur_nblocks * 4); \ + int _mur_i; \ + for(_mur_i = -_mur_nblocks; _mur_i; _mur_i++) { \ + uint32_t _mur_k1 = MUR_GETBLOCK(_mur_blocks, _mur_i); \ + _mur_k1 *= _mur_c1; \ + _mur_k1 = MUR_ROTL32(_mur_k1, 15); \ + _mur_k1 *= _mur_c2; \ + \ + _mur_h1 ^= _mur_k1; \ + _mur_h1 = MUR_ROTL32(_mur_h1, 13); \ + _mur_h1 = _mur_h1 * 5 + 0xe6546b64; \ + } \ + const uint8_t *_mur_tail \ + = (const uint8_t *)(_mur_data + _mur_nblocks * 4); \ + uint32_t _mur_k1 = 0; \ + switch((keylen) & 3) { \ + case 3: \ + _mur_k1 ^= _mur_tail[2] << 16; \ + case 2: \ + _mur_k1 ^= _mur_tail[1] << 8; \ + case 1: \ + _mur_k1 ^= _mur_tail[0]; \ + _mur_k1 *= _mur_c1; \ + _mur_k1 = MUR_ROTL32(_mur_k1, 15); \ + _mur_k1 *= _mur_c2; \ + _mur_h1 ^= _mur_k1; \ + } \ + _mur_h1 ^= (keylen); \ + MUR_FMIX(_mur_h1); \ + hashv = _mur_h1; \ + bkt = hashv & (num_bkts - 1); \ + } while(0) +#endif /* HASH_USING_NO_STRICT_ALIASING */ /* key comparison function; return 0 if keys equal */ -#define HASH_KEYCMP(a,b,len) memcmp(a,b,len) +#define HASH_KEYCMP(a, b, len) memcmp(a, b, len) /* iterate over items in a known bucket to find desired item */ -#define HASH_FIND_IN_BKT(tbl,hh,head,keyptr,keylen_in,out) \ -do { \ - if (head.hh_head) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,head.hh_head)); \ - else out=NULL; \ - while (out) { \ - if (out->hh.keylen == keylen_in) { \ - if ((HASH_KEYCMP(out->hh.key,keyptr,keylen_in)) == 0) break; \ - } \ - if (out->hh.hh_next) DECLTYPE_ASSIGN(out,ELMT_FROM_HH(tbl,out->hh.hh_next)); \ - else out = NULL; \ - } \ -} while(0) +#define HASH_FIND_IN_BKT(tbl, hh, head, keyptr, keylen_in, out) \ + do { \ + if(head.hh_head) \ + DECLTYPE_ASSIGN(out, \ + ELMT_FROM_HH(tbl, head.hh_head)); \ + else \ + out = NULL; \ + while(out) { \ + if(out->hh.keylen == keylen_in) { \ + if((HASH_KEYCMP(out->hh.key, keyptr, \ + keylen_in)) \ + == 0) \ + break; \ + } \ + if(out->hh.hh_next) \ + DECLTYPE_ASSIGN( \ + out, ELMT_FROM_HH(tbl, out->hh.hh_next)); \ + else \ + out = NULL; \ + } \ + } while(0) /* add an item to a bucket */ -#define HASH_ADD_TO_BKT(head,addhh) \ -do { \ - head.count++; \ - (addhh)->hh_next = head.hh_head; \ - (addhh)->hh_prev = NULL; \ - if (head.hh_head) { (head).hh_head->hh_prev = (addhh); } \ - (head).hh_head=addhh; \ - if (head.count >= ((head.expand_mult+1) * HASH_BKT_CAPACITY_THRESH) \ - && (addhh)->tbl->noexpand != 1) { \ - HASH_EXPAND_BUCKETS((addhh)->tbl); \ - } \ -} while(0) +#define HASH_ADD_TO_BKT(head, addhh) \ + do { \ + head.count++; \ + (addhh)->hh_next = head.hh_head; \ + (addhh)->hh_prev = NULL; \ + if(head.hh_head) { \ + (head).hh_head->hh_prev = (addhh); \ + } \ + (head).hh_head = addhh; \ + if(head.count \ + >= ((head.expand_mult + 1) * HASH_BKT_CAPACITY_THRESH) \ + && (addhh)->tbl->noexpand != 1) { \ + HASH_EXPAND_BUCKETS((addhh)->tbl); \ + } \ + } while(0) /* remove an item from a given bucket */ -#define HASH_DEL_IN_BKT(hh,head,hh_del) \ - (head).count--; \ - if ((head).hh_head == hh_del) { \ - (head).hh_head = hh_del->hh_next; \ - } \ - if (hh_del->hh_prev) { \ - hh_del->hh_prev->hh_next = hh_del->hh_next; \ - } \ - if (hh_del->hh_next) { \ - hh_del->hh_next->hh_prev = hh_del->hh_prev; \ - } +#define HASH_DEL_IN_BKT(hh, head, hh_del) \ + (head).count--; \ + if((head).hh_head == hh_del) { \ + (head).hh_head = hh_del->hh_next; \ + } \ + if(hh_del->hh_prev) { \ + hh_del->hh_prev->hh_next = hh_del->hh_next; \ + } \ + if(hh_del->hh_next) { \ + hh_del->hh_next->hh_prev = hh_del->hh_prev; \ + } /* Bucket expansion has the effect of doubling the number of buckets * and redistributing the items into the new buckets. Ideally the @@ -650,222 +792,347 @@ do { * ceil(n/b) = (n>>lb) + ( (n & (b-1)) ? 1:0) * */ -#define HASH_EXPAND_BUCKETS(tbl) \ -do { \ - unsigned _he_bkt; \ - unsigned _he_bkt_i; \ - struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ - UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ - _he_new_buckets = (UT_hash_bucket*)uthash_malloc( \ - 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ - if (!_he_new_buckets) { uthash_fatal( "out of memory"); } \ - memset(_he_new_buckets, 0, \ - 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ - tbl->ideal_chain_maxlen = \ - (tbl->num_items >> (tbl->log2_num_buckets+1)) + \ - ((tbl->num_items & ((tbl->num_buckets*2)-1)) ? 1 : 0); \ - tbl->nonideal_items = 0; \ - for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; _he_bkt_i++) \ - { \ - _he_thh = tbl->buckets[ _he_bkt_i ].hh_head; \ - while (_he_thh) { \ - _he_hh_nxt = _he_thh->hh_next; \ - HASH_TO_BKT( _he_thh->hashv, tbl->num_buckets*2, _he_bkt); \ - _he_newbkt = &(_he_new_buckets[ _he_bkt ]); \ - if (++(_he_newbkt->count) > tbl->ideal_chain_maxlen) { \ - tbl->nonideal_items++; \ - _he_newbkt->expand_mult = _he_newbkt->count / \ - tbl->ideal_chain_maxlen; \ - } \ - _he_thh->hh_prev = NULL; \ - _he_thh->hh_next = _he_newbkt->hh_head; \ - if (_he_newbkt->hh_head) _he_newbkt->hh_head->hh_prev = \ - _he_thh; \ - _he_newbkt->hh_head = _he_thh; \ - _he_thh = _he_hh_nxt; \ - } \ - } \ - uthash_free( tbl->buckets, tbl->num_buckets*sizeof(struct UT_hash_bucket) ); \ - tbl->num_buckets *= 2; \ - tbl->log2_num_buckets++; \ - tbl->buckets = _he_new_buckets; \ - tbl->ineff_expands = (tbl->nonideal_items > (tbl->num_items >> 1)) ? \ - (tbl->ineff_expands+1) : 0; \ - if (tbl->ineff_expands > 1) { \ - tbl->noexpand=1; \ - uthash_noexpand_fyi(tbl); \ - } \ - uthash_expand_fyi(tbl); \ -} while(0) - +#define HASH_EXPAND_BUCKETS(tbl) \ + do { \ + unsigned _he_bkt; \ + unsigned _he_bkt_i; \ + struct UT_hash_handle *_he_thh, *_he_hh_nxt; \ + UT_hash_bucket *_he_new_buckets, *_he_newbkt; \ + _he_new_buckets = (UT_hash_bucket *)uthash_malloc( \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + if(!_he_new_buckets) { \ + uthash_fatal("out of memory"); \ + } \ + memset(_he_new_buckets, 0, \ + 2 * tbl->num_buckets * sizeof(struct UT_hash_bucket)); \ + tbl->ideal_chain_maxlen \ + = (tbl->num_items >> (tbl->log2_num_buckets + 1)) \ + + ((tbl->num_items & ((tbl->num_buckets * 2) - 1)) \ + ? 1 \ + : 0); \ + tbl->nonideal_items = 0; \ + for(_he_bkt_i = 0; _he_bkt_i < tbl->num_buckets; \ + _he_bkt_i++) { \ + _he_thh = tbl->buckets[_he_bkt_i].hh_head; \ + while(_he_thh) { \ + _he_hh_nxt = _he_thh->hh_next; \ + HASH_TO_BKT(_he_thh->hashv, \ + tbl->num_buckets * 2, _he_bkt); \ + _he_newbkt = &(_he_new_buckets[_he_bkt]); \ + if(++(_he_newbkt->count) \ + > tbl->ideal_chain_maxlen) { \ + tbl->nonideal_items++; \ + _he_newbkt->expand_mult \ + = _he_newbkt->count \ + / tbl->ideal_chain_maxlen; \ + } \ + _he_thh->hh_prev = NULL; \ + _he_thh->hh_next = _he_newbkt->hh_head; \ + if(_he_newbkt->hh_head) \ + _he_newbkt->hh_head->hh_prev \ + = _he_thh; \ + _he_newbkt->hh_head = _he_thh; \ + _he_thh = _he_hh_nxt; \ + } \ + } \ + uthash_free(tbl->buckets, \ + tbl->num_buckets \ + * sizeof(struct UT_hash_bucket)); \ + tbl->num_buckets *= 2; \ + tbl->log2_num_buckets++; \ + tbl->buckets = _he_new_buckets; \ + tbl->ineff_expands \ + = (tbl->nonideal_items > (tbl->num_items >> 1)) \ + ? (tbl->ineff_expands + 1) \ + : 0; \ + if(tbl->ineff_expands > 1) { \ + tbl->noexpand = 1; \ + uthash_noexpand_fyi(tbl); \ + } \ + uthash_expand_fyi(tbl); \ + } while(0) /* This is an adaptation of Simon Tatham's O(n log(n)) mergesort */ /* Note that HASH_SORT assumes the hash handle name to be hh. * HASH_SRT was added to allow the hash handle name to be passed in. */ -#define HASH_SORT(head,cmpfcn) HASH_SRT(hh,head,cmpfcn) -#define HASH_SRT(hh,head,cmpfcn) \ -do { \ - unsigned _hs_i; \ - unsigned _hs_looping,_hs_nmerges,_hs_insize,_hs_psize,_hs_qsize; \ - struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, *_hs_tail; \ - if (head) { \ - _hs_insize = 1; \ - _hs_looping = 1; \ - _hs_list = &((head)->hh); \ - while (_hs_looping) { \ - _hs_p = _hs_list; \ - _hs_list = NULL; \ - _hs_tail = NULL; \ - _hs_nmerges = 0; \ - while (_hs_p) { \ - _hs_nmerges++; \ - _hs_q = _hs_p; \ - _hs_psize = 0; \ - for ( _hs_i = 0; _hs_i < _hs_insize; _hs_i++ ) { \ - _hs_psize++; \ - _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ - ((void*)((char*)(_hs_q->next) + \ - (head)->hh.tbl->hho)) : NULL); \ - if (! (_hs_q) ) break; \ - } \ - _hs_qsize = _hs_insize; \ - while ((_hs_psize > 0) || ((_hs_qsize > 0) && _hs_q )) { \ - if (_hs_psize == 0) { \ - _hs_e = _hs_q; \ - _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ - ((void*)((char*)(_hs_q->next) + \ - (head)->hh.tbl->hho)) : NULL); \ - _hs_qsize--; \ - } else if ( (_hs_qsize == 0) || !(_hs_q) ) { \ - _hs_e = _hs_p; \ - _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ - ((void*)((char*)(_hs_p->next) + \ - (head)->hh.tbl->hho)) : NULL); \ - _hs_psize--; \ - } else if (( \ - cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_p)), \ - DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl,_hs_q))) \ - ) <= 0) { \ - _hs_e = _hs_p; \ - _hs_p = (UT_hash_handle*)((_hs_p->next) ? \ - ((void*)((char*)(_hs_p->next) + \ - (head)->hh.tbl->hho)) : NULL); \ - _hs_psize--; \ - } else { \ - _hs_e = _hs_q; \ - _hs_q = (UT_hash_handle*)((_hs_q->next) ? \ - ((void*)((char*)(_hs_q->next) + \ - (head)->hh.tbl->hho)) : NULL); \ - _hs_qsize--; \ - } \ - if ( _hs_tail ) { \ - _hs_tail->next = ((_hs_e) ? \ - ELMT_FROM_HH((head)->hh.tbl,_hs_e) : NULL); \ - } else { \ - _hs_list = _hs_e; \ - } \ - _hs_e->prev = ((_hs_tail) ? \ - ELMT_FROM_HH((head)->hh.tbl,_hs_tail) : NULL); \ - _hs_tail = _hs_e; \ - } \ - _hs_p = _hs_q; \ - } \ - _hs_tail->next = NULL; \ - if ( _hs_nmerges <= 1 ) { \ - _hs_looping=0; \ - (head)->hh.tbl->tail = _hs_tail; \ - DECLTYPE_ASSIGN(head,ELMT_FROM_HH((head)->hh.tbl, _hs_list)); \ - } \ - _hs_insize *= 2; \ - } \ - HASH_FSCK(hh,head); \ - } \ -} while (0) +#define HASH_SORT(head, cmpfcn) HASH_SRT(hh, head, cmpfcn) +#define HASH_SRT(hh, head, cmpfcn) \ + do { \ + unsigned _hs_i; \ + unsigned _hs_looping, _hs_nmerges, _hs_insize, _hs_psize, \ + _hs_qsize; \ + struct UT_hash_handle *_hs_p, *_hs_q, *_hs_e, *_hs_list, \ + *_hs_tail; \ + if(head) { \ + _hs_insize = 1; \ + _hs_looping = 1; \ + _hs_list = &((head)->hh); \ + while(_hs_looping) { \ + _hs_p = _hs_list; \ + _hs_list = NULL; \ + _hs_tail = NULL; \ + _hs_nmerges = 0; \ + while(_hs_p) { \ + _hs_nmerges++; \ + _hs_q = _hs_p; \ + _hs_psize = 0; \ + for(_hs_i = 0; _hs_i < _hs_insize; \ + _hs_i++) { \ + _hs_psize++; \ + _hs_q \ + = (UT_hash_handle \ + *)((_hs_q->next) \ + ? ((void \ + *)((char \ + *)(_hs_q \ + ->next) \ + + (head) \ + ->hh \ + .tbl \ + ->hho)) \ + : NULL); \ + if(!(_hs_q)) \ + break; \ + } \ + _hs_qsize = _hs_insize; \ + while( \ + (_hs_psize > 0) \ + || ((_hs_qsize > 0) && _hs_q)) { \ + if(_hs_psize == 0) { \ + _hs_e = _hs_q; \ + _hs_q \ + = (UT_hash_handle \ + *)((_hs_q \ + ->next) \ + ? ((void \ + *)((char \ + *)(_hs_q \ + ->next) \ + + (head) \ + ->hh \ + .tbl \ + ->hho)) \ + : NULL); \ + _hs_qsize--; \ + } else if((_hs_qsize == 0) \ + || !(_hs_q)) { \ + _hs_e = _hs_p; \ + _hs_p \ + = (UT_hash_handle \ + *)((_hs_p \ + ->next) \ + ? ((void \ + *)((char \ + *)(_hs_p \ + ->next) \ + + (head) \ + ->hh \ + .tbl \ + ->hho)) \ + : NULL); \ + _hs_psize--; \ + } else if( \ + (cmpfcn( \ + DECLTYPE(head)( \ + ELMT_FROM_HH( \ + (head) \ + ->hh.tbl, \ + _hs_p)), \ + DECLTYPE(head)( \ + ELMT_FROM_HH( \ + (head) \ + ->hh.tbl, \ + _hs_q)))) \ + <= 0) { \ + _hs_e = _hs_p; \ + _hs_p \ + = (UT_hash_handle \ + *)((_hs_p \ + ->next) \ + ? ((void \ + *)((char \ + *)(_hs_p \ + ->next) \ + + (head) \ + ->hh \ + .tbl \ + ->hho)) \ + : NULL); \ + _hs_psize--; \ + } else { \ + _hs_e = _hs_q; \ + _hs_q \ + = (UT_hash_handle \ + *)((_hs_q \ + ->next) \ + ? ((void \ + *)((char \ + *)(_hs_q \ + ->next) \ + + (head) \ + ->hh \ + .tbl \ + ->hho)) \ + : NULL); \ + _hs_qsize--; \ + } \ + if(_hs_tail) { \ + _hs_tail->next \ + = ((_hs_e) \ + ? ELMT_FROM_HH( \ + (head) \ + ->hh \ + .tbl, \ + _hs_e) \ + : NULL); \ + } else { \ + _hs_list = _hs_e; \ + } \ + _hs_e->prev \ + = ((_hs_tail) \ + ? ELMT_FROM_HH( \ + (head) \ + ->hh \ + .tbl, \ + _hs_tail) \ + : NULL); \ + _hs_tail = _hs_e; \ + } \ + _hs_p = _hs_q; \ + } \ + _hs_tail->next = NULL; \ + if(_hs_nmerges <= 1) { \ + _hs_looping = 0; \ + (head)->hh.tbl->tail = _hs_tail; \ + DECLTYPE_ASSIGN( \ + head, \ + ELMT_FROM_HH((head)->hh.tbl, \ + _hs_list)); \ + } \ + _hs_insize *= 2; \ + } \ + HASH_FSCK(hh, head); \ + } \ + } while(0) /* This function selects items from one hash into another hash. * The end result is that the selected items have dual presence * in both hashes. There is no copy of the items made; rather * they are added into the new hash through a secondary hash * hash handle that must be present in the structure. */ -#define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ -do { \ - unsigned _src_bkt, _dst_bkt; \ - void *_last_elt=NULL, *_elt; \ - UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh=NULL; \ - ptrdiff_t _dst_hho = ((char*)(&(dst)->hh_dst) - (char*)(dst)); \ - if (src) { \ - for(_src_bkt=0; _src_bkt < (src)->hh_src.tbl->num_buckets; _src_bkt++) { \ - for(_src_hh = (src)->hh_src.tbl->buckets[_src_bkt].hh_head; \ - _src_hh; \ - _src_hh = _src_hh->hh_next) { \ - _elt = ELMT_FROM_HH((src)->hh_src.tbl, _src_hh); \ - if (cond(_elt)) { \ - _dst_hh = (UT_hash_handle*)(((char*)_elt) + _dst_hho); \ - _dst_hh->key = _src_hh->key; \ - _dst_hh->keylen = _src_hh->keylen; \ - _dst_hh->hashv = _src_hh->hashv; \ - _dst_hh->prev = _last_elt; \ - _dst_hh->next = NULL; \ - if (_last_elt_hh) { _last_elt_hh->next = _elt; } \ - if (!dst) { \ - DECLTYPE_ASSIGN(dst,_elt); \ - HASH_MAKE_TABLE(hh_dst,dst); \ - } else { \ - _dst_hh->tbl = (dst)->hh_dst.tbl; \ - } \ - HASH_TO_BKT(_dst_hh->hashv, _dst_hh->tbl->num_buckets, _dst_bkt); \ - HASH_ADD_TO_BKT(_dst_hh->tbl->buckets[_dst_bkt],_dst_hh); \ - (dst)->hh_dst.tbl->num_items++; \ - _last_elt = _elt; \ - _last_elt_hh = _dst_hh; \ - } \ - } \ - } \ - } \ - HASH_FSCK(hh_dst,dst); \ -} while (0) - -#define HASH_CLEAR(hh,head) \ -do { \ - if (head) { \ - uthash_free((head)->hh.tbl->buckets, \ - (head)->hh.tbl->num_buckets*sizeof(struct UT_hash_bucket)); \ - uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ - (head)=NULL; \ - } \ -} while(0) +#define HASH_SELECT(hh_dst, dst, hh_src, src, cond) \ + do { \ + unsigned _src_bkt, _dst_bkt; \ + void *_last_elt = NULL, *_elt; \ + UT_hash_handle *_src_hh, *_dst_hh, *_last_elt_hh = NULL; \ + ptrdiff_t _dst_hho \ + = ((char *)(&(dst)->hh_dst) - (char *)(dst)); \ + if(src) { \ + for(_src_bkt = 0; \ + _src_bkt < (src)->hh_src.tbl->num_buckets; \ + _src_bkt++) { \ + for(_src_hh \ + = (src) \ + ->hh_src.tbl->buckets[_src_bkt] \ + .hh_head; \ + _src_hh; _src_hh = _src_hh->hh_next) { \ + _elt = ELMT_FROM_HH( \ + (src)->hh_src.tbl, _src_hh); \ + if(cond(_elt)) { \ + _dst_hh \ + = (UT_hash_handle \ + *)(((char *)_elt) \ + + _dst_hho); \ + _dst_hh->key = _src_hh->key; \ + _dst_hh->keylen \ + = _src_hh->keylen; \ + _dst_hh->hashv \ + = _src_hh->hashv; \ + _dst_hh->prev = _last_elt; \ + _dst_hh->next = NULL; \ + if(_last_elt_hh) { \ + _last_elt_hh->next \ + = _elt; \ + } \ + if(!dst) { \ + DECLTYPE_ASSIGN( \ + dst, _elt); \ + HASH_MAKE_TABLE( \ + hh_dst, dst); \ + } else { \ + _dst_hh->tbl \ + = (dst) \ + ->hh_dst \ + .tbl; \ + } \ + HASH_TO_BKT( \ + _dst_hh->hashv, \ + _dst_hh->tbl \ + ->num_buckets, \ + _dst_bkt); \ + HASH_ADD_TO_BKT( \ + _dst_hh->tbl \ + ->buckets[_dst_bkt], \ + _dst_hh); \ + (dst) \ + ->hh_dst.tbl \ + ->num_items++; \ + _last_elt = _elt; \ + _last_elt_hh = _dst_hh; \ + } \ + } \ + } \ + } \ + HASH_FSCK(hh_dst, dst); \ + } while(0) + +#define HASH_CLEAR(hh, head) \ + do { \ + if(head) { \ + uthash_free((head)->hh.tbl->buckets, \ + (head)->hh.tbl->num_buckets \ + * sizeof(struct UT_hash_bucket)); \ + uthash_free((head)->hh.tbl, sizeof(UT_hash_table)); \ + (head) = NULL; \ + } \ + } while(0) #ifdef NO_DECLTYPE -#define HASH_ITER(hh,head,el,tmp) \ -for((el)=(head), (*(char**)(&(tmp)))=(char*)((head)?(head)->hh.next:NULL); \ - el; (el)=(tmp),(*(char**)(&(tmp)))=(char*)((tmp)?(tmp)->hh.next:NULL)) +#define HASH_ITER(hh, head, el, tmp) \ + for((el) = (head), \ + (*(char **)(&(tmp))) = (char *)((head) ? (head)->hh.next : NULL); \ + el; (el) = (tmp), \ + (*(char **)(&(tmp))) = (char *)((tmp) ? (tmp)->hh.next : NULL)) #else -#define HASH_ITER(hh,head,el,tmp) \ -for((el)=(head),(tmp)=DECLTYPE(el)((head)?(head)->hh.next:NULL); \ - el; (el)=(tmp),(tmp)=DECLTYPE(el)((tmp)?(tmp)->hh.next:NULL)) +#define HASH_ITER(hh, head, el, tmp) \ + for((el) = (head), \ + (tmp) = DECLTYPE(el)((head) ? (head)->hh.next : NULL); \ + el; (el) = (tmp), \ + (tmp) = DECLTYPE(el)((tmp) ? (tmp)->hh.next : NULL)) #endif /* obtain a count of items in the hash */ -#define HASH_COUNT(head) HASH_CNT(hh,head) -#define HASH_CNT(hh,head) ((head)?((head)->hh.tbl->num_items):0) +#define HASH_COUNT(head) HASH_CNT(hh, head) +#define HASH_CNT(hh, head) ((head) ? ((head)->hh.tbl->num_items) : 0) typedef struct UT_hash_bucket { - struct UT_hash_handle *hh_head; - unsigned count; - - /* expand_mult is normally set to 0. In this situation, the max chain length - * threshold is enforced at its default value, HASH_BKT_CAPACITY_THRESH. (If - * the bucket's chain exceeds this length, bucket expansion is triggered). - * However, setting expand_mult to a non-zero value delays bucket expansion - * (that would be triggered by additions to this particular bucket) - * until its chain length reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. - * (The multiplier is simply expand_mult+1). The whole idea of this - * multiplier is to reduce bucket expansions, since they are expensive, in - * situations where we know that a particular bucket tends to be overused. - * It is better to let its chain length grow to a longer yet-still-bounded - * value, than to do an O(n) bucket expansion too often. - */ - unsigned expand_mult; + struct UT_hash_handle *hh_head; + unsigned count; + + /* expand_mult is normally set to 0. In this situation, the max chain + * length threshold is enforced at its default value, + * HASH_BKT_CAPACITY_THRESH. (If the bucket's chain exceeds this + * length, bucket expansion is triggered). However, setting expand_mult + * to a non-zero value delays bucket expansion (that would be triggered + * by additions to this particular bucket) until its chain length + * reaches a *multiple* of HASH_BKT_CAPACITY_THRESH. (The multiplier is + * simply expand_mult+1). The whole idea of this multiplier is to + * reduce bucket expansions, since they are expensive, in situations + * where we know that a particular bucket tends to be overused. It is + * better to let its chain length grow to a longer yet-still-bounded + * value, than to do an O(n) bucket expansion too often. + */ + unsigned expand_mult; } UT_hash_bucket; @@ -874,47 +1141,54 @@ typedef struct UT_hash_bucket { #define HASH_BLOOM_SIGNATURE 0xb12220f2 typedef struct UT_hash_table { - UT_hash_bucket *buckets; - unsigned num_buckets, log2_num_buckets; - unsigned num_items; - struct UT_hash_handle *tail; /* tail hh in app order, for fast append */ - ptrdiff_t hho; /* hash handle offset (unsigned char pos of hash handle in element */ - - /* in an ideal situation (all buckets used equally), no bucket would have - * more than ceil(#items/#buckets) items. that's the ideal chain length. */ - unsigned ideal_chain_maxlen; - - /* nonideal_items is the number of items in the hash whose chain position - * exceeds the ideal chain maxlen. these items pay the penalty for an uneven - * hash distribution; reaching them in a chain traversal takes >ideal steps */ - unsigned nonideal_items; - - /* ineffective expands occur when a bucket doubling was performed, but - * afterward, more than half the items in the hash had nonideal chain - * positions. If this happens on two consecutive expansions we inhibit any - * further expansion, as it's not helping; this happens when the hash - * function isn't a good fit for the key domain. When expansion is inhibited - * the hash will still work, albeit no longer in constant time. */ - unsigned ineff_expands, noexpand; - - uint32_t signature; /* used only to find hash tables in external analysis */ + UT_hash_bucket *buckets; + unsigned num_buckets, log2_num_buckets; + unsigned num_items; + struct UT_hash_handle + *tail; /* tail hh in app order, for fast append */ + ptrdiff_t hho; /* hash handle offset (unsigned char pos of hash handle + in element */ + + /* in an ideal situation (all buckets used equally), no bucket would + * have more than ceil(#items/#buckets) items. that's the ideal chain + * length. */ + unsigned ideal_chain_maxlen; + + /* nonideal_items is the number of items in the hash whose chain + * position exceeds the ideal chain maxlen. these items pay the penalty + * for an uneven hash distribution; reaching them in a chain traversal + * takes >ideal steps */ + unsigned nonideal_items; + + /* ineffective expands occur when a bucket doubling was performed, but + * afterward, more than half the items in the hash had nonideal chain + * positions. If this happens on two consecutive expansions we inhibit + * any further expansion, as it's not helping; this happens when the + * hash function isn't a good fit for the key domain. When expansion is + * inhibited the hash will still work, albeit no longer in constant + * time. */ + unsigned ineff_expands, noexpand; + + uint32_t + signature; /* used only to find hash tables in external analysis */ #ifdef HASH_BLOOM - uint32_t bloom_sig; /* used only to test bloom exists in external analysis */ - uint8_t *bloom_bv; - char bloom_nbits; + uint32_t bloom_sig; /* used only to test bloom exists in external + analysis */ + uint8_t *bloom_bv; + char bloom_nbits; #endif } UT_hash_table; typedef struct UT_hash_handle { - struct UT_hash_table *tbl; - void *prev; /* prev element in app order */ - void *next; /* next element in app order */ - struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ - struct UT_hash_handle *hh_next; /* next hh in bucket order */ - void *key; /* ptr to enclosing struct's key */ - unsigned keylen; /* enclosing struct's key len */ - unsigned hashv; /* result of hash-fcn(key) */ + struct UT_hash_table *tbl; + void *prev; /* prev element in app order */ + void *next; /* next element in app order */ + struct UT_hash_handle *hh_prev; /* previous hh in bucket order */ + struct UT_hash_handle *hh_next; /* next hh in bucket order */ + void *key; /* ptr to enclosing struct's key */ + unsigned keylen; /* enclosing struct's key len */ + unsigned hashv; /* result of hash-fcn(key) */ } UT_hash_handle; #endif /* UTHASH_H */ diff --git a/inc/verify.h b/inc/verify.h index f3a0bb3c..138d6061 100644 --- a/inc/verify.h +++ b/inc/verify.h @@ -4,47 +4,54 @@ #ifndef VERIFY_H #define VERIFY_H - extern const char *__progname; #ifndef _WIN32 -#define C_ASSERT(test) \ - switch(0) {\ - case 0:\ - case test:;\ - } +#define C_ASSERT(test) \ + switch(0) { \ + case 0: \ + case test:; \ + } #endif // _WIN32 #ifndef __V_STR__ - #define __V_STR__(x) #x ":" +#define __V_STR__(x) #x ":" #endif //__STR__ #ifndef __V_TOSTR__ - #define __V_TOSTR__(x) __V_STR__(x) +#define __V_TOSTR__(x) __V_STR__(x) #endif // __TOSTR__ #ifndef __V_FILE_LINE__ - #define __V_FILE_LINE__ __FILE__ ":" __V_TOSTR__(__LINE__) +#define __V_FILE_LINE__ __FILE__ ":" __V_TOSTR__(__LINE__) #endif /*__FILE_LINE__*/ - #ifdef __ANDROID__ /*android */ -#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) +#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) \ + || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) #include #endif #ifdef VERIFY_PRINT_INFO -#define VERIFY_IPRINTF(format, ...) __android_log_print(ANDROID_LOG_DEBUG , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_IPRINTF(format, ...) \ + __android_log_print(ANDROID_LOG_DEBUG, __progname, \ + __V_FILE_LINE__ format, ##__VA_ARGS__) #endif #ifdef VERIFY_PRINT_ERROR -#define VERIFY_EPRINTF(format, ...) __android_log_print(ANDROID_LOG_ERROR , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_EPRINTF(format, ...) \ + __android_log_print(ANDROID_LOG_ERROR, __progname, \ + __V_FILE_LINE__ format, ##__VA_ARGS__) #endif -#define VERIFY_EPRINTF_ALWAYS(format, ...) __android_log_print(ANDROID_LOG_ERROR , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_EPRINTF_ALWAYS(format, ...) \ + __android_log_print(ANDROID_LOG_ERROR, __progname, \ + __V_FILE_LINE__ format, ##__VA_ARGS__) #ifdef VERIFY_PRINT_WARN -#define VERIFY_WPRINTF(format, ...) __android_log_print(ANDROID_LOG_WARN , __progname, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_WPRINTF(format, ...) \ + __android_log_print(ANDROID_LOG_WARN, __progname, \ + __V_FILE_LINE__ format, ##__VA_ARGS__) #endif /* end android */ @@ -52,62 +59,72 @@ extern const char *__progname; /* q6 */ #ifdef VERIFY_PRINT_INFO - #define FARF_VERIFY_LOW 1 - #define FARF_VERIFY_LOW_LEVEL HAP_LEVEL_LOW - #define VERIFY_IPRINTF(args...) FARF(VERIFY_LOW, args) +#define FARF_VERIFY_LOW 1 +#define FARF_VERIFY_LOW_LEVEL HAP_LEVEL_LOW +#define VERIFY_IPRINTF(args...) FARF(VERIFY_LOW, args) #endif #ifdef VERIFY_PRINT_ERROR - #define FARF_VERIFY_ERROR 1 - #define FARF_VERIFY_ERROR_LEVEL HAP_LEVEL_ERROR - #define VERIFY_EPRINTF(args...) FARF(VERIFY_ERROR, args) +#define FARF_VERIFY_ERROR 1 +#define FARF_VERIFY_ERROR_LEVEL HAP_LEVEL_ERROR +#define VERIFY_EPRINTF(args...) FARF(VERIFY_ERROR, args) #endif #if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) - #include "HAP_farf.h" +#include "HAP_farf.h" #endif /* end q6 */ #elif (defined USE_SYSLOG) /* syslog */ -#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) +#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) \ + || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) #include #endif #ifdef VERIFY_PRINT_INFO -#define VERIFY_IPRINTF(format, ...) syslog(LOG_USER|LOG_INFO, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_IPRINTF(format, ...) \ + syslog(LOG_USER | LOG_INFO, __V_FILE_LINE__ format, ##__VA_ARGS__) #endif #ifdef VERIFY_PRINT_ERROR -#define VERIFY_EPRINTF(format, ...) syslog(LOG_USER|LOG_ERR, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_EPRINTF(format, ...) \ + syslog(LOG_USER | LOG_ERR, __V_FILE_LINE__ format, ##__VA_ARGS__) #endif -#define VERIFY_EPRINTF_ALWAYS(format, ...) syslog(LOG_ERR , __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_EPRINTF_ALWAYS(format, ...) \ + syslog(LOG_ERR, __V_FILE_LINE__ format, ##__VA_ARGS__) #ifdef VERIFY_PRINT_WARN -#define VERIFY_WPRINTF(format, ...) syslog(LOG_USER|LOG_ERR, __V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_WPRINTF(format, ...) \ + syslog(LOG_USER | LOG_ERR, __V_FILE_LINE__ format, ##__VA_ARGS__) #endif /* end syslog */ #else /* generic */ -#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) +#if (defined VERIFY_PRINT_INFO) || (defined VERIFY_PRINT_ERROR) \ + || (defined VERIFY_PRINT_ERROR_ALWAYS) || (defined VERIFY_PRINT_WARN) #include #endif #ifdef VERIFY_PRINT_INFO -#define VERIFY_IPRINTF(format, ...) printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) +#define VERIFY_IPRINTF(format, ...) \ + printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) #endif #ifdef VERIFY_PRINT_ERROR -#define VERIFY_EPRINTF(format, ...) printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) +#define VERIFY_EPRINTF(format, ...) \ + printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) #endif -#define VERIFY_EPRINTF_ALWAYS(format, ...) printf(__V_FILE_LINE__ format, ##__VA_ARGS__) +#define VERIFY_EPRINTF_ALWAYS(format, ...) \ + printf(__V_FILE_LINE__ format, ##__VA_ARGS__) #ifdef VERIFY_PRINT_WARN -#define VERIFY_WPRINTF(format, ...) printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) +#define VERIFY_WPRINTF(format, ...) \ + printf(__V_FILE_LINE__ format "\n", ##__VA_ARGS__) #endif /* end generic */ @@ -122,46 +139,46 @@ extern const char *__progname; #endif #ifndef VERIFYC - #define VERIFYC(val,err_code) \ - do {\ - VERIFY_IPRINTF(":info: calling: %s", #val);\ - if(0 == (val)) {\ - nErr = err_code;\ - VERIFY_EPRINTF(":error: %d: %s", nErr, #val);\ - goto bail;\ - } else {\ - VERIFY_IPRINTF(":info: passed: %s", #val);\ - }\ - } while(0) -#endif //VERIFYC +#define VERIFYC(val, err_code) \ + do { \ + VERIFY_IPRINTF(":info: calling: %s", #val); \ + if(0 == (val)) { \ + nErr = err_code; \ + VERIFY_EPRINTF(":error: %d: %s", nErr, #val); \ + goto bail; \ + } else { \ + VERIFY_IPRINTF(":info: passed: %s", #val); \ + } \ + } while(0) +#endif // VERIFYC #ifndef VERIFY - #define VERIFY(val) \ - do {\ - VERIFY_IPRINTF(":info: calling: %s", #val);\ - if(0 == (val)) {\ - nErr = nErr == 0 ? -1 : nErr;\ - VERIFY_EPRINTF(":error: %d: %s", nErr, #val);\ - goto bail;\ - } else {\ - VERIFY_IPRINTF(":info: passed: %s", #val);\ - }\ - } while(0) -#endif //VERIFY +#define VERIFY(val) \ + do { \ + VERIFY_IPRINTF(":info: calling: %s", #val); \ + if(0 == (val)) { \ + nErr = nErr == 0 ? -1 : nErr; \ + VERIFY_EPRINTF(":error: %d: %s", nErr, #val); \ + goto bail; \ + } else { \ + VERIFY_IPRINTF(":info: passed: %s", #val); \ + } \ + } while(0) +#endif // VERIFY #ifndef VERIFYM - #define VERIFYM(val,err_code,format, ...) \ - do {\ - VERIFY_IPRINTF(":info: calling: " #val "\n");\ - if(0 == (val)) {\ - nErr = err_code;\ - VERIFY_EPRINTF_ALWAYS(":Error: 0x%x: " #val "\n", nErr);\ - goto bail;\ - } else {\ - VERIFY_IPRINTF(":info: passed: " #val "\n");\ - }\ - } while(0) -#endif //VERIFYM - -#endif //VERIFY_H - +#define VERIFYM(val, err_code, format, ...) \ + do { \ + VERIFY_IPRINTF(":info: calling: " #val "\n"); \ + if(0 == (val)) { \ + nErr = err_code; \ + VERIFY_EPRINTF_ALWAYS(":Error: 0x%x: " #val "\n", \ + nErr); \ + goto bail; \ + } else { \ + VERIFY_IPRINTF(":info: passed: " #val "\n"); \ + } \ + } while(0) +#endif // VERIFYM + +#endif // VERIFY_H diff --git a/inc/version.h b/inc/version.h index 893d6c77..9c6c1ee1 100644 --- a/inc/version.h +++ b/inc/version.h @@ -8,7 +8,7 @@ FILE: version.h GENERAL DESCRIPTION: - Definitions for versioning + Definitions for versioning ===========================================================================*/ #if !defined(VERSION_CL) #define VERSION_CL "?" @@ -26,10 +26,9 @@ GENERAL DESCRIPTION: #define VERSION_NUM "?.?.?.?" #endif -#define VERSION_STRING \ - VERSION_PROD " " \ - VERSION_NUM " " \ - "(br=" VERSION_BRANCH "; cl=" VERSION_CL ")" +#define VERSION_STRING \ + VERSION_PROD " " VERSION_NUM " " \ + "(br=" VERSION_BRANCH "; cl=" VERSION_CL ")" /* ======================================================================= @@ -39,7 +38,7 @@ MACROS DOCUMENTATION VERSION_MAJOR Description: - Defines the major release number of the version. + Defines the major release number of the version. Comments: It has to be a valid numerical value @@ -48,7 +47,7 @@ VERSION_MAJOR VERSION_MINOR Description: - Defines the minor release number of the version. + Defines the minor release number of the version. Comments: It has to be a valid numerical value @@ -57,7 +56,7 @@ VERSION_MINOR VERSION_MAINT Description: - Defines the maintenance release of the version. + Defines the maintenance release of the version. Comments: It has to be a valid numerical value @@ -66,7 +65,7 @@ VERSION_MAINT VERSION_BUILD Description: - Defines the build ID of the version. + Defines the build ID of the version. Comments: It has to be a valid numerical value @@ -75,22 +74,21 @@ VERSION_BUILD VERSION_STRING Description: - Defines the version string that specifies the version number. + Defines the version string that specifies the version number. Definition: #define VERSION_STRING "a.b.c.d (name=value;name=value;...)" - where a=major release number - b=minor release number - c=maintenance release number - d=build number - - name=value pair provides additional information about the build. - Example: - patch/feature=comma separated list of features/patches that have been installed. - br=p4 branch that was used for the build - cl=p4 change list number - machine=hostname of the machine that was used for the build. + where a=major release number + b=minor release number + c=maintenance release number + d=build number + + name=value pair provides additional information about the build. + Example: + patch/feature=comma separated list of features/patches that have been +installed. br=p4 branch that was used for the build cl=p4 change list number + machine=hostname of the machine that was used for the build. Comments: diff --git a/src/BufBound.c b/src/BufBound.c index 927906ed..b9509e34 100644 --- a/src/BufBound.c +++ b/src/BufBound.c @@ -18,9 +18,9 @@ REVISION HISTORY: Sun Mar 06 11:23:10 2005 Created ==============================================================================*/ -#include #include "AEEBufBound.h" #include "AEEstd.h" +#include // Note on bounds-checking logic and saturation: // @@ -44,8 +44,7 @@ REVISION HISTORY: // pcWrite: (a) (b) // -#define PCSAT(me) ((me)->pcBuf + INT_MAX) - +#define PCSAT(me) ((me)->pcBuf + INT_MAX) // Advance me->pcWrite, saturating. // @@ -58,119 +57,130 @@ REVISION HISTORY: static char * BufBound_ValidateWrite(BufBound *me, int *pnLen) { - int nLen = *pnLen; - char *pcWrite = me->pcWrite; - int nMaxCopy = me->pcEnd - pcWrite; // could be negative! - - if ( nMaxCopy < nLen ) { - // Must check PCSAT to validate advance - int nMaxAdvance = PCSAT(me) - pcWrite; // max amount to advance - - if (nLen > nMaxAdvance) { - nLen = nMaxAdvance; - } - if (nMaxCopy < 0) { - nMaxCopy = 0; - } - } else { - // Simple case: all fits in the buffer - nMaxCopy = nLen; - } - - *pnLen = nMaxCopy; - me->pcWrite = pcWrite + nLen; - return pcWrite; + int nLen = *pnLen; + char *pcWrite = me->pcWrite; + int nMaxCopy = me->pcEnd - pcWrite; // could be negative! + + if(nMaxCopy < nLen) { + // Must check PCSAT to validate advance + int nMaxAdvance = PCSAT(me) - pcWrite; // max amount to advance + + if(nLen > nMaxAdvance) { + nLen = nMaxAdvance; + } + if(nMaxCopy < 0) { + nMaxCopy = 0; + } + } else { + // Simple case: all fits in the buffer + nMaxCopy = nLen; + } + + *pnLen = nMaxCopy; + me->pcWrite = pcWrite + nLen; + return pcWrite; } -void BufBound_Write(BufBound *me, const char *pc, int nLen) +void +BufBound_Write(BufBound *me, const char *pc, int nLen) { - if (nLen > 0) { - char *pcDest = BufBound_ValidateWrite(me, &nLen); + if(nLen > 0) { + char *pcDest = BufBound_ValidateWrite(me, &nLen); - while (--nLen >= 0) { - pcDest[nLen] = pc[nLen]; - } - } + while(--nLen >= 0) { + pcDest[nLen] = pc[nLen]; + } + } } -void BufBound_Putnc(BufBound *me, char c, int nLen) +void +BufBound_Putnc(BufBound *me, char c, int nLen) { - if (nLen > 0) { - char *pcDest = BufBound_ValidateWrite(me, &nLen); + if(nLen > 0) { + char *pcDest = BufBound_ValidateWrite(me, &nLen); - while (--nLen >= 0) { - pcDest[nLen] = c; - } - } + while(--nLen >= 0) { + pcDest[nLen] = c; + } + } } -void BufBound_Advance(BufBound *me, int nLen) +void +BufBound_Advance(BufBound *me, int nLen) { - uint32_t uOffset = (uint32_t)((me->pcWrite - me->pcBuf) + nLen); - - if (uOffset > INT_MAX) { - uOffset = INT_MAX; - if (nLen < 0) { - uOffset = 0; - } - } - me->pcWrite = me->pcBuf + uOffset; + uint32_t uOffset = (uint32_t)((me->pcWrite - me->pcBuf) + nLen); + + if(uOffset > INT_MAX) { + uOffset = INT_MAX; + if(nLen < 0) { + uOffset = 0; + } + } + me->pcWrite = me->pcBuf + uOffset; } -void BufBound_Init(BufBound *me, char *pBuf, int nLen) +void +BufBound_Init(BufBound *me, char *pBuf, int nLen) { - if (nLen < 0) { - nLen = 0; - } - me->pcWrite = me->pcBuf = pBuf; - me->pcEnd = pBuf + nLen; + if(nLen < 0) { + nLen = 0; + } + me->pcWrite = me->pcBuf = pBuf; + me->pcEnd = pBuf + nLen; } -void BufBound_Putc(BufBound *me, char c) +void +BufBound_Putc(BufBound *me, char c) { - if ( (me->pcEnd - me->pcWrite) > 0) { - *me->pcWrite++ = c; - } else if (me->pcWrite != PCSAT(me)) { - ++me->pcWrite; - } + if((me->pcEnd - me->pcWrite) > 0) { + *me->pcWrite++ = c; + } else if(me->pcWrite != PCSAT(me)) { + ++me->pcWrite; + } } -void BufBound_ForceNullTerm(BufBound *me) +void +BufBound_ForceNullTerm(BufBound *me) { - if ( (me->pcEnd - me->pcWrite) > 0) { - *me->pcWrite++ = '\0'; - } else { - if (me->pcWrite != PCSAT(me)) { - ++me->pcWrite; - } - // ensure null termination if non-empty buffer - if (me->pcEnd != me->pcBuf) { - me->pcEnd[-1] = '\0'; - } - } + if((me->pcEnd - me->pcWrite) > 0) { + *me->pcWrite++ = '\0'; + } else { + if(me->pcWrite != PCSAT(me)) { + ++me->pcWrite; + } + // ensure null termination if non-empty buffer + if(me->pcEnd != me->pcBuf) { + me->pcEnd[-1] = '\0'; + } + } } -void BufBound_Puts(BufBound *me, const char* cpsz) +void +BufBound_Puts(BufBound *me, const char *cpsz) { - BufBound_Write(me, cpsz, strlen(cpsz)); + BufBound_Write(me, cpsz, strlen(cpsz)); } -int BufBound_BufSize(BufBound* me) +int +BufBound_BufSize(BufBound *me) { - return me->pcEnd - me->pcBuf; + return me->pcEnd - me->pcBuf; } -int BufBound_Left(BufBound* me) +int +BufBound_Left(BufBound *me) { - return (me->pcEnd - me->pcWrite); + return (me->pcEnd - me->pcWrite); } -int BufBound_ReallyWrote(BufBound* me) +int +BufBound_ReallyWrote(BufBound *me) { - return STD_MIN(me->pcEnd - me->pcBuf, me->pcWrite - me->pcBuf); + return STD_MIN(me->pcEnd - me->pcBuf, me->pcWrite - me->pcBuf); } -int BufBound_Wrote(BufBound* me) +int +BufBound_Wrote(BufBound *me) { - return (me->pcWrite - me->pcBuf); + return (me->pcWrite - me->pcBuf); } diff --git a/src/adsp_current_process1_stub.c b/src/adsp_current_process1_stub.c index 2145ee8d..b3b7dff8 100644 --- a/src/adsp_current_process1_stub.c +++ b/src/adsp_current_process1_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,159 +93,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_CURRENT_PROCESS1_SLIM_H #define _ADSP_CURRENT_PROCESS1_SLIM_H @@ -435,301 +446,523 @@ struct Interface { #endif static const Type types[2]; -static const SequenceType sequenceTypes[1] = {{&(types[0]),0x0,0x4,0x4,0x0}}; -static const Type types[2] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8)},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}}; -static const Parameter parameters[8] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x2,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x2,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0}}; -static const Parameter* const parameterArrays[11] = {(&(parameters[6])),(&(parameters[6])),(&(parameters[6])),(&(parameters[4])),(&(parameters[3])),(&(parameters[4])),(&(parameters[0])),(&(parameters[1])),(&(parameters[7])),(&(parameters[5])),(&(parameters[2]))}; -static const Method methods[9] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[6])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[10])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,3,2,(&(parameterArrays[4])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x1,0x0,0x0),0x0,0x4,1,1,(&(parameterArrays[9])),0x1,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,3,2,(&(parameterArrays[2])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x4,0x0,2,1,(&(parameterArrays[8])),0x4,0x0}}; -static const Method* const methodArrays[12] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[5]),&(methods[2]),&(methods[6]),&(methods[7]),&(methods[2]),&(methods[8])}; -static const char strings[185] = "enable_notifications\0set_logging_params2\0set_logging_params\0panic_err_codes\0thread_exit\0filesToLog\0poll_mode\0exception\0timeout\0latency\0getASID\0enable\0setQoS\0close\0asid\0mask\0open\0uri\0h\0"; -static const uint16_t methodStrings[24] = {99,143,119,21,168,88,41,168,88,173,178,182,60,66,150,127,135,163,157,182,0,109,76,83}; -static const uint16_t methodStringsArrays[12] = {9,18,23,22,6,16,14,21,3,0,20,12}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_current_process1_slim) = {12,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const SequenceType sequenceTypes[1] + = { { &(types[0]), 0x0, 0x4, 0x4, 0x0 } }; +static const Type types[2] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8) }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 } }; +static const Parameter parameters[8] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x2, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x2, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 } }; +static const Parameter *const parameterArrays[11] + = { (&(parameters[6])), (&(parameters[6])), (&(parameters[6])), + (&(parameters[4])), (&(parameters[3])), (&(parameters[4])), + (&(parameters[0])), (&(parameters[1])), (&(parameters[7])), + (&(parameters[5])), (&(parameters[2])) }; +static const Method methods[9] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[6])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[10])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 3, 2, + (&(parameterArrays[4])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x1, 0x0, 0x0), 0x0, 0x4, 1, 1, + (&(parameterArrays[9])), 0x1, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[0])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 3, 2, + (&(parameterArrays[2])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[0])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x4, 0x0, 2, 1, + (&(parameterArrays[8])), 0x4, 0x0 } }; +static const Method *const methodArrays[12] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[2]), + &(methods[3]), &(methods[4]), &(methods[5]), &(methods[2]), + &(methods[6]), &(methods[7]), &(methods[2]), &(methods[8]) }; +static const char strings[185] + = "enable_notifications\0set_logging_params2\0set_logging_params\0panic_" + "err_codes\0thread_exit\0filesToLog\0poll_" + "mode\0exception\0timeout\0latency\0getASID\0enable\0setQoS\0close\0asid" + "\0mask\0open\0uri\0h\0"; +static const uint16_t methodStrings[24] + = { 99, 143, 119, 21, 168, 88, 41, 168, 88, 173, 178, 182, + 60, 66, 150, 127, 135, 163, 157, 182, 0, 109, 76, 83 }; +static const uint16_t methodStringsArrays[12] + = { 9, 18, 23, 22, 6, 16, 14, 21, 3, 0, 20, 12 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_current_process1_slim) + = { 12, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_CURRENT_PROCESS1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_open)(const char *uri, remote_handle64 *h) + __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_close)(remote_handle64 h) + __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_exit)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_exit)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_thread_exit)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_thread_exit)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method(_handle, _mid); } -static __inline int _stub_unpack(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +0; - return _nErr; +static __inline int +_stub_unpack(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 0; + return _nErr; } -static __inline int _stub_pack(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 1; - _ppraROutStart[0] += (_praROut - _praROutStart) +0; - return _nErr; +static __inline int +_stub_pack(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 1; + _ppraROutStart[0] += (_praROut - _praROutStart) + 0; + return _nErr; } -static __inline void _count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) { - _numIn[0] += 1; - _numROut[0] += 0; - _numInH[0] += 0; - _numROutH[0] += 0; +static __inline void +_count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) +{ + _numIn[0] += 1; + _numROut[0] += 0; + _numInH[0] += 0; + _numROutH[0] += 0; } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, uint16_t _in0[1], void* _in1[1], uint32_t _in1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg** _ppraIn = &_praIn; - remote_arg* _praROut = 0; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 2); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - if(_praHIn == 0) - { - _praHIn = ((_praIn + _numIn[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - _praROutPost = _praROut; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, uint16_t _in0[1], + void *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg **_ppraIn = &_praIn; + remote_arg *_praROut = 0; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 2); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + if(_praHIn == 0) { + _praHIn = ((_praIn + _numIn[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_in1[0]; + _ii < (int)_in1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + _praROutPost = _praROut; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_set_logging_params)(remote_handle64 _handle, unsigned short mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_1(_handle, _mid, (uint16_t*)&mask, (void**)&filesToLog, (uint32_t*)&filesToLogLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_set_logging_params)( + remote_handle64 _handle, unsigned short mask, + const _cstring1_t *filesToLog, int filesToLogLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_1(_handle, _mid, (uint16_t *)&mask, + (void **)&filesToLog, + (uint32_t *)&filesToLogLen); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid, uint32_t _rout0[1]) { - int _numIn[1] = {0}; - remote_arg _pra[1] = {0}; - uint32_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[(_numIn[0] + 0)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); - _COPY(_rout0, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid, uint32_t _rout0[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[1] = { 0 }; + uint32_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[(_numIn[0] + 0)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); + _COPY(_rout0, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_getASID)(remote_handle64 _handle, unsigned int* asid) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - return _stub_method_2(_handle, _mid, (uint32_t*)asid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_getASID)( + remote_handle64 _handle, unsigned int *asid) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + return _stub_method_2(_handle, _mid, (uint32_t *)asid); } -static __inline int _stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_setQoS)(remote_handle64 _handle, unsigned int latency) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 6; - return _stub_method_3(_handle, _mid, (uint32_t*)&latency); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_setQoS)( + remote_handle64 _handle, unsigned int latency) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 6; + return _stub_method_3(_handle, _mid, (uint32_t *)&latency); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_exception)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 7; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_exception)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 7; + return _stub_method(_handle, _mid); } -static __inline int _stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], void* _in1[1], uint32_t _in1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg** _ppraIn = &_praIn; - remote_arg* _praROut = 0; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - if(_praHIn == 0) - { - _praHIn = ((_praIn + _numIn[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - _praROutPost = _praROut; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; +static __inline int +_stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + void *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg **_ppraIn = &_praIn; + remote_arg *_praROut = 0; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + if(_praHIn == 0) { + _praHIn = ((_praIn + _numIn[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_in1[0]; + _ii < (int)_in1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + _praROutPost = _praROut; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_set_logging_params2)(remote_handle64 _handle, unsigned int mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 8; - return _stub_method_4(_handle, _mid, (uint32_t*)&mask, (void**)&filesToLog, (uint32_t*)&filesToLogLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_set_logging_params2)( + remote_handle64 _handle, unsigned int mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 8; + return _stub_method_4(_handle, _mid, (uint32_t *)&mask, + (void **)&filesToLog, + (uint32_t *)&filesToLogLen); } -static __inline int _stub_method_5(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[2]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_5(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[2] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_poll_mode)(remote_handle64 _handle, unsigned int enable, unsigned int timeout) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 9; - return _stub_method_5(_handle, _mid, (uint32_t*)&enable, (uint32_t*)&timeout); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_poll_mode)( + remote_handle64 _handle, unsigned int enable, + unsigned int timeout) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 9; + return _stub_method_5(_handle, _mid, (uint32_t *)&enable, + (uint32_t *)&timeout); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_enable_notifications)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 10; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_enable_notifications)( + remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 10; + return _stub_method(_handle, _mid); } -static __inline int _stub_method_6(remote_handle64 _handle, uint32_t _mid, char* _in0[1], uint32_t _in0Len[1]) { - remote_arg _pra[2] = {0}; - uint32_t _primIn[1]= {0}; - remote_arg* _praIn = 0; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (4 * _in0Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_6(remote_handle64 _handle, uint32_t _mid, char *_in0[1], + uint32_t _in0Len[1]) +{ + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[1] = { 0 }; + remote_arg *_praIn = 0; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (4 * _in0Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process1_panic_err_codes)(remote_handle64 _handle, const int* err_codes, int err_codesLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 11; - return _stub_method_6(_handle, _mid, (char**)&err_codes, (uint32_t*)&err_codesLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process1_panic_err_codes)( + remote_handle64 _handle, const int *err_codes, + int err_codesLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 11; + return _stub_method_6(_handle, _mid, (char **)&err_codes, + (uint32_t *)&err_codesLen); } #ifdef __cplusplus } diff --git a/src/adsp_current_process_stub.c b/src/adsp_current_process_stub.c index f1298e73..2d1d182d 100644 --- a/src/adsp_current_process_stub.c +++ b/src/adsp_current_process_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,159 +93,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_CURRENT_PROCESS_SLIM_H #define _ADSP_CURRENT_PROCESS_SLIM_H @@ -435,67 +446,129 @@ struct Interface { #endif static const Type types[1]; -static const SequenceType sequenceTypes[1] = {{&(types[0]),0x0,0x4,0x4,0x0}}; -static const Type types[1] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8)}}; -static const Parameter parameters[4] = {{0x2,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x2,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0}}; -static const Parameter* const parameterArrays[7] = {(&(parameters[3])),(&(parameters[3])),(&(parameters[3])),(&(parameters[1])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[6] = {{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,3,2,(&(parameterArrays[4])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x1,0x0,0x0),0x0,0x4,1,1,(&(parameterArrays[6])),0x1,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,3,2,(&(parameterArrays[2])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[0])),0x4,0x0}}; -static const Method* const methodArrays[9] = {&(methods[0]),&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[0]),&(methods[4]),&(methods[5]),&(methods[0])}; -static const char strings[152] = "enable_notifications\0set_logging_params2\0set_logging_params\0thread_exit\0filesToLog\0poll_mode\0exception\0timeout\0latency\0getASID\0enable\0setQoS\0asid\0mask\0"; -static const uint16_t methodStrings[17] = {83,127,103,21,146,72,41,146,72,134,111,119,141,0,93,60,67}; -static const uint16_t methodStringsArrays[9] = {16,15,6,11,9,14,3,0,13}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_current_process_slim) = {9,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const SequenceType sequenceTypes[1] + = { { &(types[0]), 0x0, 0x4, 0x4, 0x0 } }; +static const Type types[1] = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8) } }; +static const Parameter parameters[4] = { + { 0x2, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x2, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 } +}; +static const Parameter *const parameterArrays[7] + = { (&(parameters[3])), (&(parameters[3])), (&(parameters[3])), + (&(parameters[1])), (&(parameters[0])), (&(parameters[1])), + (&(parameters[2])) }; +static const Method methods[6] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 3, 2, + (&(parameterArrays[4])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x1, 0x0, 0x0), 0x0, 0x4, 1, 1, + (&(parameterArrays[6])), 0x1, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[0])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 3, 2, + (&(parameterArrays[2])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[0])), 0x4, 0x0 } }; +static const Method *const methodArrays[9] + = { &(methods[0]), &(methods[0]), &(methods[1]), + &(methods[2]), &(methods[3]), &(methods[0]), + &(methods[4]), &(methods[5]), &(methods[0]) }; +static const char strings[152] + = "enable_notifications\0set_logging_params2\0set_logging_params\0thread_" + "exit\0filesToLog\0poll_" + "mode\0exception\0timeout\0latency\0getASID\0enable\0setQoS\0asid\0mask" + "\0"; +static const uint16_t methodStrings[17] + = { 83, 127, 103, 21, 146, 72, 41, 146, 72, + 134, 111, 119, 141, 0, 93, 60, 67 }; +static const uint16_t methodStringsArrays[9] + = { 16, 15, 6, 11, 9, 14, 3, 0, 13 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_current_process_slim) + = { 9, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_CURRENT_PROCESS_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_adsp_current_process_handle -#define _const_adsp_current_process_handle ((remote_handle)-1) +#define _const_adsp_current_process_handle ((remote_handle) - 1) #endif //_const_adsp_current_process_handle -static void _adsp_current_process_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_adsp_current_process_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_adsp_current_process_handle; - } +static void +_adsp_current_process_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_adsp_current_process_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_adsp_current_process_handle; + } } -static int _adsp_current_process_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_adsp_current_process_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_adsp_current_process_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_adsp_current_process_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _adsp_current_process_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_adsp_current_process_handle, 0, sizeof(*ph), _adsp_current_process_pls_ctor, "adsp_current_process", _adsp_current_process_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_adsp_current_process_handle, 0, sizeof(*ph), _adsp_current_process_pls_ctor, "adsp_current_process", _adsp_current_process_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_adsp_current_process_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup( + (uint32_t)_adsp_current_process_handle, 0, sizeof(*ph), + _adsp_current_process_pls_ctor, "adsp_current_process", + _adsp_current_process_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup( + (uint32_t)_adsp_current_process_handle, 0, sizeof(*ph), + _adsp_current_process_pls_ctor, "adsp_current_process", + _adsp_current_process_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _adsp_current_process_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _adsp_current_process_atomic_CompareAndExchange( + uint32_t *volatile puDest, uint32_t uExchange, uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -503,31 +576,47 @@ uint32_t _adsp_current_process_atomic_CompareAndExchange(uint32_t * volatile puD #else #include "ntddk.h" #endif //_USRDLL -uint32_t _adsp_current_process_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_adsp_current_process_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _adsp_current_process_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_adsp_current_process_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _adsp_current_process_handle(void) { - static remote_handle handle = _const_adsp_current_process_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _adsp_current_process_pls_ctor("adsp_current_process", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adsp_current_process_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _adsp_current_process_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_adsp_current_process_handle(void) +{ + static remote_handle handle = _const_adsp_current_process_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr = _adsp_current_process_pls_ctor( + "adsp_current_process", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle) + _adsp_current_process_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _adsp_current_process_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -536,336 +625,437 @@ __QAIC_STUB_EXPORT remote_handle _adsp_current_process_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_method(remote_handle _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_exit)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_exit)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_thread_exit)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 1; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_thread_exit)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 1; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_unpack(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +0; - return _nErr; +static __inline int +_stub_unpack(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 0; + return _nErr; } -static __inline int _stub_pack(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 1; - _ppraROutStart[0] += (_praROut - _praROutStart) +0; - return _nErr; +static __inline int +_stub_pack(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 1; + _ppraROutStart[0] += (_praROut - _praROutStart) + 0; + return _nErr; } -static __inline void _count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) { - _numIn[0] += 1; - _numROut[0] += 0; - _numInH[0] += 0; - _numROutH[0] += 0; +static __inline void +_count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) +{ + _numIn[0] += 1; + _numROut[0] += 0; + _numInH[0] += 0; + _numROutH[0] += 0; } -static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid, uint16_t _in0[1], void* _in1[1], uint32_t _in1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg** _ppraIn = &_praIn; - remote_arg* _praROut = 0; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 2); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - if(_praHIn == 0) - { - _praHIn = ((_praIn + _numIn[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - _praROutPost = _praROut; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; +static __inline int +_stub_method_1(remote_handle _handle, uint32_t _mid, uint16_t _in0[1], + void *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg **_ppraIn = &_praIn; + remote_arg *_praROut = 0; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 2); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + if(_praHIn == 0) { + _praHIn = ((_praIn + _numIn[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_in1[0]; + _ii < (int)_in1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + _praROutPost = _praROut; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_set_logging_params)(unsigned short mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid, (uint16_t*)&mask, (void**)&filesToLog, (uint32_t*)&filesToLogLen); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_set_logging_params)( + unsigned short mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1(_handle, _mid, (uint16_t *)&mask, + (void **)&filesToLog, + (uint32_t *)&filesToLogLen); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_2(remote_handle _handle, uint32_t _mid, uint32_t _rout0[1]) { - int _numIn[1] = {0}; - remote_arg _pra[1] = {0}; - uint32_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[(_numIn[0] + 0)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); - _COPY(_rout0, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle _handle, uint32_t _mid, uint32_t _rout0[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[1] = { 0 }; + uint32_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[(_numIn[0] + 0)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); + _COPY(_rout0, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_getASID)(unsigned int* asid) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_2(_handle, _mid, (uint32_t*)asid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_getASID)(unsigned int *asid) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_2(_handle, _mid, (uint32_t *)asid); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_setQoS)(unsigned int latency) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_3(_handle, _mid, (uint32_t*)&latency); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_setQoS)(unsigned int latency) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_3(_handle, _mid, (uint32_t *)&latency); + } else { + return AEE_EINVHANDLE; + } } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_exception)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_exception)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_4(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], void* _in1[1], uint32_t _in1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg** _ppraIn = &_praIn; - remote_arg* _praROut = 0; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - if(_praHIn == 0) - { - _praHIn = ((_praIn + _numIn[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - _praROutPost = _praROut; - for(_ii = 0, _seq_nat1 = (char*)_in1[0];_ii < (int)_in1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; +static __inline int +_stub_method_4(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + void *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg **_ppraIn = &_praIn; + remote_arg *_praROut = 0; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + if(_praHIn == 0) { + _praHIn = ((_praIn + _numIn[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_in1[0]; + _ii < (int)_in1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + _praROutPost = _praROut; + for(_ii = 0, _seq_nat1 = (char *)_in1[0]; _ii < (int)_in1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_set_logging_params2)(unsigned int mask, const _cstring1_t* filesToLog, int filesToLogLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 6; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_4(_handle, _mid, (uint32_t*)&mask, (void**)&filesToLog, (uint32_t*)&filesToLogLen); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_set_logging_params2)( + unsigned int mask, const _cstring1_t *filesToLog, + int filesToLogLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 6; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_4(_handle, _mid, (uint32_t *)&mask, + (void **)&filesToLog, + (uint32_t *)&filesToLogLen); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_5(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[2]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_5(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[2] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_poll_mode)(unsigned int enable, unsigned int timeout) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 7; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_5(_handle, _mid, (uint32_t*)&enable, (uint32_t*)&timeout); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_poll_mode)( + unsigned int enable, unsigned int timeout) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 7; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_5(_handle, _mid, (uint32_t *)&enable, + (uint32_t *)&timeout); + } else { + return AEE_EINVHANDLE; + } } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_current_process_enable_notifications)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 8; - remote_handle _handle = _adsp_current_process_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_current_process_enable_notifications)(void) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 8; + remote_handle _handle = _adsp_current_process_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/adsp_default_listener.c b/src/adsp_default_listener.c index e37648ae..95ae2e0f 100644 --- a/src/adsp_default_listener.c +++ b/src/adsp_default_listener.c @@ -30,9 +30,9 @@ #define ROOTPD_NAME "rootpd" #define ATTACH_GUESTOS "attachguestos" #define CREATE_STATICPD "createstaticpd:" -#define POLL_TIMEOUT 10 * 1000 -#define EVENT_SIZE ( sizeof (struct inotify_event) ) -#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) +#define POLL_TIMEOUT 10 * 1000 +#define EVENT_SIZE (sizeof(struct inotify_event)) +#define EVENT_BUF_LEN (1024 * (EVENT_SIZE + 16)) #define ADSP_SECURE_DEVICE_NAME "fastrpc-adsp-secure" #define SDSP_SECURE_DEVICE_NAME "fastrpc-sdsp-secure" #define MDSP_SECURE_DEVICE_NAME "fastrpc-mdsp-secure" @@ -49,32 +49,34 @@ #define GDSP1_DEVICE_NAME "fastrpc-gdsp1" // Array of supported domain names and its corresponding ID's. -static domain_t supported_domains[] = {{ADSP_DOMAIN_ID, ADSP_DOMAIN}, - {MDSP_DOMAIN_ID, MDSP_DOMAIN}, - {SDSP_DOMAIN_ID, SDSP_DOMAIN}, - {CDSP_DOMAIN_ID, CDSP_DOMAIN}, - {CDSP1_DOMAIN_ID, CDSP1_DOMAIN}, - {GDSP0_DOMAIN_ID, GDSP0_DOMAIN}, - {GDSP1_DOMAIN_ID, GDSP1_DOMAIN}}; +static domain_t supported_domains[] + = { { ADSP_DOMAIN_ID, ADSP_DOMAIN }, { MDSP_DOMAIN_ID, MDSP_DOMAIN }, + { SDSP_DOMAIN_ID, SDSP_DOMAIN }, { CDSP_DOMAIN_ID, CDSP_DOMAIN }, + { CDSP1_DOMAIN_ID, CDSP1_DOMAIN }, { GDSP0_DOMAIN_ID, GDSP0_DOMAIN }, + { GDSP1_DOMAIN_ID, GDSP1_DOMAIN } }; // Get domain name for the domain id. -static domain_t *get_domain_uri(int domain_id) { - int i = 0; - int size = sizeof(supported_domains) / sizeof(domain_t); +static domain_t * +get_domain_uri(int domain_id) +{ + int i = 0; + int size = sizeof(supported_domains) / sizeof(domain_t); - for (i = 0; i < size; i++) { - if (supported_domains[i].id == domain_id) - return &supported_domains[i]; - } + for(i = 0; i < size; i++) { + if(supported_domains[i].id == domain_id) + return &supported_domains[i]; + } - return NULL; + return NULL; } -static const char *get_secure_device_name(int domain_id) { +static const char * +get_secure_device_name(int domain_id) +{ const char *name; int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - switch (domain) { + switch(domain) { case ADSP_DOMAIN_ID: name = ADSP_SECURE_DEVICE_NAME; break; @@ -104,11 +106,13 @@ static const char *get_secure_device_name(int domain_id) { return name; } -static const char *get_default_device_name(int domain_id) { +static const char * +get_default_device_name(int domain_id) +{ const char *name; int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - switch (domain) { + switch(domain) { case ADSP_DOMAIN_ID: name = ADSP_DEVICE_NAME; break; @@ -146,7 +150,8 @@ static const char *get_default_device_name(int domain_id) { * True: Device node exists * False: Device node does not exist */ -static bool fastrpc_dev_exists(const char* dev_name) +static bool +fastrpc_dev_exists(const char *dev_name) { struct stat buffer; char *path = NULL; @@ -169,7 +174,8 @@ static bool fastrpc_dev_exists(const char* dev_name) * 0 - Success * Non-zero - Failure */ -static int fastrpc_wait_for_device(int domain) +static int +fastrpc_wait_for_device(int domain) { int inotify_fd = -1, watch_fd = -1, err = 0; const char *sec_dev_name = NULL, *def_dev_name = NULL; @@ -178,63 +184,76 @@ static int fastrpc_wait_for_device(int domain) sec_dev_name = get_secure_device_name(domain); def_dev_name = get_default_device_name(domain); - if (fastrpc_dev_exists(sec_dev_name) || fastrpc_dev_exists(def_dev_name)) + if(fastrpc_dev_exists(sec_dev_name) + || fastrpc_dev_exists(def_dev_name)) return 0; inotify_fd = inotify_init(); - if (inotify_fd < 0) { - VERIFY_EPRINTF("Error: inotify_init failed, invalid fd errno = %s\n", strerror(errno)); + if(inotify_fd < 0) { + VERIFY_EPRINTF( + "Error: inotify_init failed, invalid fd errno = %s\n", + strerror(errno)); return AEE_EINVALIDFD; } watch_fd = inotify_add_watch(inotify_fd, "/dev/", IN_CREATE); - if (watch_fd < 0) { + if(watch_fd < 0) { close(inotify_fd); - VERIFY_EPRINTF("Error: inotify_add_watch failed, invalid fd errno = %s\n", strerror(errno)); + VERIFY_EPRINTF( + "Error: inotify_add_watch failed, invalid fd errno = %s\n", + strerror(errno)); return AEE_EINVALIDFD; } - if (fastrpc_dev_exists(sec_dev_name) || fastrpc_dev_exists(def_dev_name)) + if(fastrpc_dev_exists(sec_dev_name) + || fastrpc_dev_exists(def_dev_name)) goto bail; - memset(pfd, 0 , sizeof(pfd)); + memset(pfd, 0, sizeof(pfd)); pfd[0].fd = inotify_fd; pfd[0].events = POLLIN; - while (1) { + while(1) { int ret = 0; char buffer[EVENT_BUF_LEN]; struct inotify_event *event; ret = poll(pfd, 1, POLL_TIMEOUT); - if(ret < 0){ - VERIFY_EPRINTF("Error: %s: polling for event failed errno(%s)\n", __func__, strerror(errno)); + if(ret < 0) { + VERIFY_EPRINTF( + "Error: %s: polling for event failed errno(%s)\n", + __func__, strerror(errno)); err = AEE_EPOLL; break; } - if(ret == 0){ + if(ret == 0) { VERIFY_EPRINTF("Error: %s: Poll timeout\n", __func__); err = AEE_EPOLL; break; } /* read on inotify fd never reads partial events. */ ssize_t len = read(inotify_fd, buffer, sizeof(buffer)); - if (len < 0) { - VERIFY_EPRINTF("Error: %s: read failed, errno = %s\n", __func__, strerror(errno)); + if(len < 0) { + VERIFY_EPRINTF("Error: %s: read failed, errno = %s\n", + __func__, strerror(errno)); err = AEE_EEVENTREAD; break; } - /* Loop over all events in the buffer. */ - for (char *ptr = buffer; ptr < buffer + len; - ptr += sizeof(struct inotify_event) + event->len) { - event = (struct inotify_event *) ptr; - /* Check if the event corresponds to the creation of the device node. */ - if (event->wd == watch_fd && (event->mask & IN_CREATE) && - ((strcmp(sec_dev_name, event->name) == 0) || - (strcmp(def_dev_name, event->name) == 0))) { - /* Device node created, process proceed to open and use it. */ - VERIFY_IPRINTF("Device node %s created!\n", event->name); - goto bail; /* Exit the loop after device creation is detected. */ + /* Loop over all events in the buffer. */ + for(char *ptr = buffer; ptr < buffer + len; + ptr += sizeof(struct inotify_event) + event->len) { + event = (struct inotify_event *)ptr; + /* Check if the event corresponds to the creation of + * the device node. */ + if(event->wd == watch_fd && (event->mask & IN_CREATE) + && ((strcmp(sec_dev_name, event->name) == 0) + || (strcmp(def_dev_name, event->name) == 0))) { + /* Device node created, process proceed to open + * and use it. */ + VERIFY_IPRINTF("Device node %s created!\n", + event->name); + goto bail; /* Exit the loop after device + creation is detected. */ } } } @@ -245,205 +264,245 @@ static int fastrpc_wait_for_device(int domain) return err; } -int adsp_default_listener_start(int argc, char *argv[]) { - struct pollfd pfd; - eventfd_t event = 0; - remote_handle64 event_fd = INVALID_HANDLE; - remote_handle64 fd = INVALID_HANDLE; - remote_handle64 listener_fd = INVALID_HANDLE; - int nErr = AEE_SUCCESS, domain_id = INVALID_DOMAIN_ID; - char *name = NULL; - char *adsp_default_listener1_URI_domain = NULL; - int adsp_default_listener1_URI_domain_len = - strlen(adsp_default_listener1_URI) + MAX_DOMAIN_URI_SIZE; - domain_t *dsp_domain = NULL; - int namelen = 0; - char *eventfd_domain = NULL; - int eventfdlen = 0; - (void)argc; - (void)argv; - - if (argc > 2) { - /* Two arguments are passed in below format - * Example: ./adsprpcd audiopd adsp - * Get domain name from arguments and use domains API. - */ - VERIFY_IPRINTF("%s started with arguments %s and %s\n", __func__, argv[1], - argv[2]); - VERIFYC(INVALID_DOMAIN_ID != (domain_id = get_domain_from_name( - argv[2], DOMAIN_NAME_STAND_ALONE)), - AEE_EINVALIDDOMAIN); - VERIFYC(NULL != (dsp_domain = get_domain_uri(domain_id)), - AEE_EINVALIDDOMAIN); - - VERIFYC(AEE_SUCCESS == (nErr = fastrpc_wait_for_device(domain_id)), AEE_ECONNREFUSED); - // Allocate memory for URI. Example: "ITRANSPORT_PREFIX - // createstaticpd:audiopd&dom=adsp" - namelen = strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + strlen(argv[1]) + - strlen(ADSP_DOMAIN); - VERIFYC(NULL != (name = (char *)malloc((namelen + 1) * sizeof(char))), - AEE_ENOMEMORY); - - // Copy URI to allocated memory - if (!strncmp(argv[1], ROOTPD_NAME, strlen(argv[1]))) { - strlcpy(name, ITRANSPORT_PREFIX ATTACH_GUESTOS, - strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS) + 1); - } else { - strlcpy(name, ITRANSPORT_PREFIX CREATE_STATICPD, - strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + 1); - strlcat(name, argv[1], - strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + strlen(argv[1]) + - 1); - } - - // Concatenate domain to the URI - strlcat(name, dsp_domain->uri, namelen + 1); - - // Open static process handle - VERIFY(AEE_SUCCESS == (nErr = remote_handle64_open(name, &fd))); - goto start_listener; - } else if (argc > 1) { - /* One arguments is passed in below format - * Example: ./adsprpcd "createstaticpd:audiopd&dom=adsp" (or) ./adsprpcd - * audiopd Get domain name from arguments and use domains API. - */ - VERIFY_IPRINTF("%s started with arguments %s\n", __func__, argv[1]); - domain_id = get_domain_from_name(argv[1], DOMAIN_NAME_IN_URI); - - // If domain name part of arguments, use domains API - if (domain_id != INVALID_DOMAIN_ID) { - VERIFYC(AEE_SUCCESS == (nErr = fastrpc_wait_for_device(domain_id)), AEE_ECONNREFUSED); - VERIFY(AEE_SUCCESS == (nErr = remote_handle64_open(argv[1], &fd))); - goto start_listener; - } - - // Allocate memory for URI. Example: "ITRANSPORT_PREFIX - // createstaticpd:audiopd" - namelen = strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + strlen(argv[1]); - VERIFYC(NULL != (name = (char *)malloc((namelen + 1) * sizeof(char))), - AEE_ENOMEMORY); - - // Copy URI to allocated memory - strlcpy(name, ITRANSPORT_PREFIX CREATE_STATICPD, - strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + 1); - strlcat(name, argv[1], namelen + 1); - } else { - // If no arguments passed, default/rootpd daemon of remote subsystem - namelen = strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS); - VERIFYC(NULL != (name = (char *)malloc((namelen + 1) * sizeof(char))), - AEE_ENOMEMORY); - strlcpy(name, ITRANSPORT_PREFIX ATTACH_GUESTOS, - strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS) + 1); - } - - VERIFYC(AEE_SUCCESS == (nErr = fastrpc_wait_for_device(DEFAULT_DOMAIN_ID)), AEE_ECONNREFUSED); - // Default case: Open non-domain static process handle - VERIFY_IPRINTF("%s started with arguments %s\n", __func__, name); - VERIFY(AEE_SUCCESS == (nErr = remote_handle_open(name, (remote_handle *)&fd))); +int +adsp_default_listener_start(int argc, char *argv[]) +{ + struct pollfd pfd; + eventfd_t event = 0; + remote_handle64 event_fd = INVALID_HANDLE; + remote_handle64 fd = INVALID_HANDLE; + remote_handle64 listener_fd = INVALID_HANDLE; + int nErr = AEE_SUCCESS, domain_id = INVALID_DOMAIN_ID; + char *name = NULL; + char *adsp_default_listener1_URI_domain = NULL; + int adsp_default_listener1_URI_domain_len + = strlen(adsp_default_listener1_URI) + MAX_DOMAIN_URI_SIZE; + domain_t *dsp_domain = NULL; + int namelen = 0; + char *eventfd_domain = NULL; + int eventfdlen = 0; + (void)argc; + (void)argv; + + if(argc > 2) { + /* Two arguments are passed in below format + * Example: ./adsprpcd audiopd adsp + * Get domain name from arguments and use domains API. + */ + VERIFY_IPRINTF("%s started with arguments %s and %s\n", + __func__, argv[1], argv[2]); + VERIFYC(INVALID_DOMAIN_ID + != (domain_id = get_domain_from_name( + argv[2], DOMAIN_NAME_STAND_ALONE)), + AEE_EINVALIDDOMAIN); + VERIFYC(NULL != (dsp_domain = get_domain_uri(domain_id)), + AEE_EINVALIDDOMAIN); + + VERIFYC(AEE_SUCCESS + == (nErr = fastrpc_wait_for_device(domain_id)), + AEE_ECONNREFUSED); + // Allocate memory for URI. Example: "ITRANSPORT_PREFIX + // createstaticpd:audiopd&dom=adsp" + namelen = strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + + strlen(argv[1]) + strlen(ADSP_DOMAIN); + VERIFYC(NULL + != (name = (char *)malloc((namelen + 1) + * sizeof(char))), + AEE_ENOMEMORY); + + // Copy URI to allocated memory + if(!strncmp(argv[1], ROOTPD_NAME, strlen(argv[1]))) { + strlcpy(name, ITRANSPORT_PREFIX ATTACH_GUESTOS, + strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS) + 1); + } else { + strlcpy(name, ITRANSPORT_PREFIX CREATE_STATICPD, + strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + 1); + strlcat(name, argv[1], + strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + + strlen(argv[1]) + 1); + } + + // Concatenate domain to the URI + strlcat(name, dsp_domain->uri, namelen + 1); + + // Open static process handle + VERIFY(AEE_SUCCESS + == (nErr = remote_handle64_open(name, &fd))); + goto start_listener; + } else if(argc > 1) { + /* One arguments is passed in below format + * Example: ./adsprpcd "createstaticpd:audiopd&dom=adsp" (or) + * ./adsprpcd audiopd Get domain name from arguments and use + * domains API. + */ + VERIFY_IPRINTF("%s started with arguments %s\n", __func__, + argv[1]); + domain_id = get_domain_from_name(argv[1], DOMAIN_NAME_IN_URI); + + // If domain name part of arguments, use domains API + if(domain_id != INVALID_DOMAIN_ID) { + VERIFYC( + AEE_SUCCESS + == (nErr = fastrpc_wait_for_device(domain_id)), + AEE_ECONNREFUSED); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle64_open(argv[1], &fd))); + goto start_listener; + } + + // Allocate memory for URI. Example: "ITRANSPORT_PREFIX + // createstaticpd:audiopd" + namelen = strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + + strlen(argv[1]); + VERIFYC(NULL + != (name = (char *)malloc((namelen + 1) + * sizeof(char))), + AEE_ENOMEMORY); + + // Copy URI to allocated memory + strlcpy(name, ITRANSPORT_PREFIX CREATE_STATICPD, + strlen(ITRANSPORT_PREFIX CREATE_STATICPD) + 1); + strlcat(name, argv[1], namelen + 1); + } else { + // If no arguments passed, default/rootpd daemon of remote + // subsystem + namelen = strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS); + VERIFYC(NULL + != (name = (char *)malloc((namelen + 1) + * sizeof(char))), + AEE_ENOMEMORY); + strlcpy(name, ITRANSPORT_PREFIX ATTACH_GUESTOS, + strlen(ITRANSPORT_PREFIX ATTACH_GUESTOS) + 1); + } + + VERIFYC(AEE_SUCCESS + == (nErr = fastrpc_wait_for_device(DEFAULT_DOMAIN_ID)), + AEE_ECONNREFUSED); + // Default case: Open non-domain static process handle + VERIFY_IPRINTF("%s started with arguments %s\n", __func__, name); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_open(name, (remote_handle *)&fd))); start_listener: - VERIFYC(!setenv("ADSP_LISTENER_MEM_CACHE_SIZE", "1048576", 0), AEE_ESETENV); - - // If domain name part of arguments, use domains API - if (domain_id != INVALID_DOMAIN_ID) { - // Allocate memory and copy adsp_default_listener1 URI Example: - // "adsp_default_listener1_URI&dom=adsp" - VERIFYC(NULL != - (adsp_default_listener1_URI_domain = (char *)malloc( - (adsp_default_listener1_URI_domain_len) * sizeof(char))), - AEE_ENOMEMORY); - VERIFYC(NULL != (dsp_domain = get_domain_uri(domain_id)), - AEE_EINVALIDDOMAIN); - nErr = snprintf(adsp_default_listener1_URI_domain, - adsp_default_listener1_URI_domain_len, "%s%s", - adsp_default_listener1_URI, dsp_domain->uri); - if (nErr < 0) { - VERIFY_EPRINTF("ERROR: %s: %d returned from snprintf\n", __func__, nErr); - nErr = AEE_EFAILED; - goto bail; - } - - // Open default listener handle - nErr = adsp_default_listener1_open(adsp_default_listener1_URI_domain, - &listener_fd); - - // Register daemon as default listener to static process - if (nErr == AEE_SUCCESS) { - VERIFY(0 == (nErr = adsp_default_listener1_register(listener_fd))); - goto start_poll; - } - } - - // Default case: Register non-domain default listener - VERIFY_IPRINTF("%s domains support is not available for " - "adsp_default_listener1, using non-domain API\n", - __func__); - VERIFY(0 == - (nErr = remote_handle_open("adsp_default_listener", (remote_handle *)&listener_fd))); - VERIFY(0 == (nErr = adsp_default_listener_register())); + VERIFYC(!setenv("ADSP_LISTENER_MEM_CACHE_SIZE", "1048576", 0), + AEE_ESETENV); + + // If domain name part of arguments, use domains API + if(domain_id != INVALID_DOMAIN_ID) { + // Allocate memory and copy adsp_default_listener1 URI Example: + // "adsp_default_listener1_URI&dom=adsp" + VERIFYC( + NULL + != (adsp_default_listener1_URI_domain = (char *)malloc( + (adsp_default_listener1_URI_domain_len) + * sizeof(char))), + AEE_ENOMEMORY); + VERIFYC(NULL != (dsp_domain = get_domain_uri(domain_id)), + AEE_EINVALIDDOMAIN); + nErr = snprintf(adsp_default_listener1_URI_domain, + adsp_default_listener1_URI_domain_len, "%s%s", + adsp_default_listener1_URI, dsp_domain->uri); + if(nErr < 0) { + VERIFY_EPRINTF( + "ERROR: %s: %d returned from snprintf\n", __func__, + nErr); + nErr = AEE_EFAILED; + goto bail; + } + + // Open default listener handle + nErr = adsp_default_listener1_open( + adsp_default_listener1_URI_domain, &listener_fd); + + // Register daemon as default listener to static process + if(nErr == AEE_SUCCESS) { + VERIFY(0 + == (nErr = adsp_default_listener1_register( + listener_fd))); + goto start_poll; + } + } + + // Default case: Register non-domain default listener + VERIFY_IPRINTF("%s domains support is not available for " + "adsp_default_listener1, using non-domain API\n", + __func__); + VERIFY(0 + == (nErr = remote_handle_open("adsp_default_listener", + (remote_handle *)&listener_fd))); + VERIFY(0 == (nErr = adsp_default_listener_register())); start_poll: - // If domain name part of arguments, use domains API - if (domain_id != INVALID_DOMAIN_ID) { - // Allocate memory and copy geteventfd URI Example: "ITRANSPORT_PREFIX - // geteventfd&dom=adsp" - eventfdlen = strlen(ITRANSPORT_PREFIX "geteventfd") + MAX_DOMAIN_URI_SIZE; - VERIFYC(NULL != - (eventfd_domain = (char *)malloc((eventfdlen) * sizeof(char))), - AEE_ENOMEMORY); - nErr = snprintf(eventfd_domain, eventfdlen, "%s%s", - ITRANSPORT_PREFIX "geteventfd", dsp_domain->uri); - if (nErr < 0) { - VERIFY_EPRINTF("ERROR: %s: %d returned from snprintf\n", __func__, nErr); - nErr = AEE_EFAILED; - goto bail; - } - - // Get even FD to poll on listener thread - VERIFY(0 == (nErr = remote_handle64_open(eventfd_domain, &event_fd))); - pfd.fd = (remote_handle)event_fd; - } else { - VERIFY(0 == (nErr = remote_handle_open(ITRANSPORT_PREFIX "geteventfd", - (remote_handle *)&pfd.fd))); - } - if (name != NULL) { - free(name); - name = NULL; - } - if (eventfd_domain != NULL) { - free(eventfd_domain); - eventfd_domain = NULL; - } - if (adsp_default_listener1_URI_domain != NULL) { - free(adsp_default_listener1_URI_domain); - adsp_default_listener1_URI_domain = NULL; - } - // Poll on listener thread - pfd.events = POLLIN; - pfd.revents = 0; - while (1) { - VERIFYC(0 < poll(&pfd, 1, -1), AEE_EPOLL); - VERIFYC(0 == eventfd_read(pfd.fd, &event), AEE_EEVENTREAD); - if (event) { - break; - } - } + // If domain name part of arguments, use domains API + if(domain_id != INVALID_DOMAIN_ID) { + // Allocate memory and copy geteventfd URI Example: + // "ITRANSPORT_PREFIX geteventfd&dom=adsp" + eventfdlen = strlen(ITRANSPORT_PREFIX "geteventfd") + + MAX_DOMAIN_URI_SIZE; + VERIFYC(NULL + != (eventfd_domain + = (char *)malloc((eventfdlen) * sizeof(char))), + AEE_ENOMEMORY); + nErr = snprintf(eventfd_domain, eventfdlen, "%s%s", + ITRANSPORT_PREFIX "geteventfd", + dsp_domain->uri); + if(nErr < 0) { + VERIFY_EPRINTF( + "ERROR: %s: %d returned from snprintf\n", __func__, + nErr); + nErr = AEE_EFAILED; + goto bail; + } + + // Get even FD to poll on listener thread + VERIFY(0 + == (nErr + = remote_handle64_open(eventfd_domain, &event_fd))); + pfd.fd = (remote_handle)event_fd; + } else { + VERIFY(0 + == (nErr + = remote_handle_open(ITRANSPORT_PREFIX "geteventfd", + (remote_handle *)&pfd.fd))); + } + if(name != NULL) { + free(name); + name = NULL; + } + if(eventfd_domain != NULL) { + free(eventfd_domain); + eventfd_domain = NULL; + } + if(adsp_default_listener1_URI_domain != NULL) { + free(adsp_default_listener1_URI_domain); + adsp_default_listener1_URI_domain = NULL; + } + // Poll on listener thread + pfd.events = POLLIN; + pfd.revents = 0; + while(1) { + VERIFYC(0 < poll(&pfd, 1, -1), AEE_EPOLL); + VERIFYC(0 == eventfd_read(pfd.fd, &event), AEE_EEVENTREAD); + if(event) { + break; + } + } bail: - if (listener_fd != INVALID_HANDLE) { - adsp_default_listener1_close(listener_fd); - } - if (nErr != AEE_SUCCESS) { - if (name != NULL) { - free(name); - name = NULL; - } - if (eventfd_domain != NULL) { - free(eventfd_domain); - eventfd_domain = NULL; - } - if (adsp_default_listener1_URI_domain != NULL) { - free(adsp_default_listener1_URI_domain); - adsp_default_listener1_URI_domain = NULL; - } - VERIFY_EPRINTF("Error 0x%x: %s exiting\n", nErr, __func__); - } - return nErr; + if(listener_fd != INVALID_HANDLE) { + adsp_default_listener1_close(listener_fd); + } + if(nErr != AEE_SUCCESS) { + if(name != NULL) { + free(name); + name = NULL; + } + if(eventfd_domain != NULL) { + free(eventfd_domain); + eventfd_domain = NULL; + } + if(adsp_default_listener1_URI_domain != NULL) { + free(adsp_default_listener1_URI_domain); + adsp_default_listener1_URI_domain = NULL; + } + VERIFY_EPRINTF("Error 0x%x: %s exiting\n", nErr, __func__); + } + return nErr; } diff --git a/src/adsp_default_listener1_stub.c b/src/adsp_default_listener1_stub.c index 9ce10310..c292e9af 100644 --- a/src/adsp_default_listener1_stub.c +++ b/src/adsp_default_listener1_stub.c @@ -12,81 +12,88 @@ #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -94,175 +101,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_DEFAULT_LISTENER1_SLIM_H #define _ADSP_DEFAULT_LISTENER1_SLIM_H @@ -275,38 +279,85 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Parameter parameters[3] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0}}; -static const Parameter* const parameterArrays[3] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[3] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[0])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[2])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0}}; -static const Method* const methodArrays[3] = {&(methods[0]),&(methods[1]),&(methods[2])}; +static const Parameter parameters[3] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 } }; +static const Parameter *const parameterArrays[3] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[3] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[0])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[2])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 } }; +static const Method *const methodArrays[3] + = { &(methods[0]), &(methods[1]), &(methods[2]) }; static const char strings[27] = "register\0close\0open\0uri\0h\0"; -static const uint16_t methodStrings[6] = {15,20,24,9,24,0}; -static const uint16_t methodStringsArrays[3] = {0,3,5}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_default_listener1_slim) = {3,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const uint16_t methodStrings[6] = { 15, 20, 24, 9, 24, 0 }; +static const uint16_t methodStringsArrays[3] = { 0, 3, 5 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_default_listener1_slim) + = { 3, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_DEFAULT_LISTENER1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_default_listener1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_default_listener1_open)(const char *uri, remote_handle64 *h) + __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_default_listener1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_default_listener1_close)(remote_handle64 h) + __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_default_listener1_register)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_default_listener1_register)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid); } #ifdef __cplusplus } diff --git a/src/adsp_default_listener_stub.c b/src/adsp_default_listener_stub.c index beb0e749..5267676f 100644 --- a/src/adsp_default_listener_stub.c +++ b/src/adsp_default_listener_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,158 +93,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -252,175 +266,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_DEFAULT_LISTENER_SLIM_H #define _ADSP_DEFAULT_LISTENER_SLIM_H @@ -433,63 +444,90 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Method methods[1] = {{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0}}; -static const Method* const methodArrays[1] = {&(methods[0])}; +static const Method methods[1] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 } }; +static const Method *const methodArrays[1] = { &(methods[0]) }; static const char strings[10] = "register\0"; -static const uint16_t methodStrings[1] = {0}; -static const uint16_t methodStringsArrays[1] = {0}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_default_listener_slim) = {1,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const uint16_t methodStrings[1] = { 0 }; +static const uint16_t methodStringsArrays[1] = { 0 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_default_listener_slim) + = { 1, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_DEFAULT_LISTENER_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_adsp_default_listener_handle -#define _const_adsp_default_listener_handle ((remote_handle)-1) +#define _const_adsp_default_listener_handle ((remote_handle) - 1) #endif //_const_adsp_default_listener_handle -static void _adsp_default_listener_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_adsp_default_listener_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_adsp_default_listener_handle; - } +static void +_adsp_default_listener_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_adsp_default_listener_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_adsp_default_listener_handle; + } } -static int _adsp_default_listener_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_adsp_default_listener_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_adsp_default_listener_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_adsp_default_listener_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _adsp_default_listener_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_adsp_default_listener_handle, 0, sizeof(*ph), _adsp_default_listener_pls_ctor, "adsp_default_listener", _adsp_default_listener_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_adsp_default_listener_handle, 0, sizeof(*ph), _adsp_default_listener_pls_ctor, "adsp_default_listener", _adsp_default_listener_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_adsp_default_listener_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup( + (uint32_t)_adsp_default_listener_handle, 0, sizeof(*ph), + _adsp_default_listener_pls_ctor, + "adsp_default_listener", + _adsp_default_listener_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup( + (uint32_t)_adsp_default_listener_handle, 0, sizeof(*ph), + _adsp_default_listener_pls_ctor, + "adsp_default_listener", + _adsp_default_listener_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _adsp_default_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _adsp_default_listener_atomic_CompareAndExchange( + uint32_t *volatile puDest, uint32_t uExchange, uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -497,31 +535,47 @@ uint32_t _adsp_default_listener_atomic_CompareAndExchange(uint32_t * volatile pu #else #include "ntddk.h" #endif //_USRDLL -uint32_t _adsp_default_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_adsp_default_listener_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _adsp_default_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_adsp_default_listener_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _adsp_default_listener_handle(void) { - static remote_handle handle = _const_adsp_default_listener_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _adsp_default_listener_pls_ctor("adsp_default_listener", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adsp_default_listener_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _adsp_default_listener_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_adsp_default_listener_handle(void) +{ + static remote_handle handle = _const_adsp_default_listener_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr = _adsp_default_listener_pls_ctor( + "adsp_default_listener", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle) + _adsp_default_listener_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _adsp_default_listener_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -530,28 +584,30 @@ __QAIC_STUB_EXPORT remote_handle _adsp_default_listener_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_method(remote_handle _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_default_listener_register)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _adsp_default_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_default_listener_register)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _adsp_default_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/adsp_listener1_stub.c b/src/adsp_listener1_stub.c index 4ec9e0a3..091a44cf 100644 --- a/src/adsp_listener1_stub.c +++ b/src/adsp_listener1_stub.c @@ -12,81 +12,88 @@ #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -94,175 +101,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_LISTENER1_SLIM_H #define _ADSP_LISTENER1_SLIM_H @@ -276,370 +280,744 @@ struct Interface { #endif static const Type types[3]; -static const SequenceType sequenceTypes[1] = {{&(types[0]),0x0,0x4,0x4,0x0}}; -static const Type types[3] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8)},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}}; -static const Parameter parameters[14] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[2]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[26] = {(&(parameters[3])),(&(parameters[4])),(&(parameters[5])),(&(parameters[6])),(&(parameters[7])),(&(parameters[8])),(&(parameters[9])),(&(parameters[10])),(&(parameters[10])),(&(parameters[3])),(&(parameters[4])),(&(parameters[11])),(&(parameters[6])),(&(parameters[7])),(&(parameters[8])),(&(parameters[12])),(&(parameters[13])),(&(parameters[3])),(&(parameters[4])),(&(parameters[12])),(&(parameters[13])),(&(parameters[3])),(&(parameters[9])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[7] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[23])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[25])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x18,0xc,16,9,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,4,2,(&(parameterArrays[21])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x10,0x10,11,8,(&(parameterArrays[9])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0xc,0x4,6,4,(&(parameterArrays[17])),0x4,0x4}}; -static const Method* const methodArrays[8] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[4]),&(methods[5]),&(methods[6])}; -static const char strings[183] = "invoke_get_in_bufs\0routBufLenReq\0get_in_bufs2\0inBufLenReq\0next_invoke\0bufsLenReq\0prevResult\0inBuffers\0prevbufs\0outBufs\0prevCtx\0offset\0handle\0next2\0init2\0close\0init\0open\0ctx\0uri\0sc\0h\0"; -static const uint16_t methodStrings[34] = {58,119,81,111,169,134,177,92,46,19,141,119,81,102,169,134,177,14,70,33,169,127,14,70,0,169,92,164,173,180,153,180,147,159}; -static const uint16_t methodStringsArrays[8] = {27,30,0,24,33,32,10,19}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_listener1_slim) = {8,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const SequenceType sequenceTypes[1] + = { { &(types[0]), 0x0, 0x4, 0x4, 0x0 } }; +static const Type types[3] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8) }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 } }; +static const Parameter parameters[14] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[2]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[26] + = { (&(parameters[3])), (&(parameters[4])), (&(parameters[5])), + (&(parameters[6])), (&(parameters[7])), (&(parameters[8])), + (&(parameters[9])), (&(parameters[10])), (&(parameters[10])), + (&(parameters[3])), (&(parameters[4])), (&(parameters[11])), + (&(parameters[6])), (&(parameters[7])), (&(parameters[8])), + (&(parameters[12])), (&(parameters[13])), (&(parameters[3])), + (&(parameters[4])), (&(parameters[12])), (&(parameters[13])), + (&(parameters[3])), (&(parameters[9])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[7] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[23])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[25])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x18, 0xc, 16, 9, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 4, 2, + (&(parameterArrays[21])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x10, 0x10, 11, 8, + (&(parameterArrays[9])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0xc, 0x4, 6, 4, + (&(parameterArrays[17])), 0x4, 0x4 } }; +static const Method *const methodArrays[8] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[3]), + &(methods[4]), &(methods[4]), &(methods[5]), &(methods[6]) }; +static const char strings[183] + = "invoke_get_in_bufs\0routBufLenReq\0get_in_bufs2\0inBufLenReq\0next_" + "invoke\0bufsLenReq\0prevResult\0inBuffers\0prevbufs\0outBufs\0prevCtx\0" + "offset\0handle\0next2\0init2\0close\0init\0open\0ctx\0uri\0sc\0h\0"; +static const uint16_t methodStrings[34] + = { 58, 119, 81, 111, 169, 134, 177, 92, 46, 19, 141, 119, + 81, 102, 169, 134, 177, 14, 70, 33, 169, 127, 14, 70, + 0, 169, 92, 164, 173, 180, 153, 180, 147, 159 }; +static const uint16_t methodStringsArrays[8] + = { 27, 30, 0, 24, 33, 32, 10, 19 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_listener1_slim) + = { 8, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_LISTENER1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_open)(const char *uri, + remote_handle64 *h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_unpack(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +1; - return _nErr; +static __inline int +_stub_unpack(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 1; + return _nErr; } -static __inline int _stub_unpack_1(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +0; - return _nErr; +static __inline int +_stub_unpack_1(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 0; + return _nErr; } -static __inline int _stub_pack(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 0; - _ppraROutStart[0] += (_praROut - _praROutStart) +1; - return _nErr; +static __inline int +_stub_pack(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 0; + _ppraROutStart[0] += (_praROut - _praROutStart) + 1; + return _nErr; } -static __inline int _stub_pack_1(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 1; - _ppraROutStart[0] += (_praROut - _praROutStart) +0; - return _nErr; +static __inline int +_stub_pack_1(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 1; + _ppraROutStart[0] += (_praROut - _praROutStart) + 0; + return _nErr; } -static __inline void _count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1], _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - _numIn[0] += 0; - _numROut[0] += 1; - _numInH[0] += 0; - _numROutH[0] += 0; +static __inline void +_count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1], + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + _numIn[0] += 0; + _numROut[0] += 1; + _numInH[0] += 0; + _numROutH[0] += 0; } -static __inline void _count_1(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1], _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - _numIn[0] += 1; - _numROut[0] += 0; - _numInH[0] += 0; - _numROutH[0] += 0; +static __inline void +_count_1(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1], + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + _numIn[0] += 1; + _numROut[0] += 0; + _numInH[0] += 0; + _numROutH[0] += 0; } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], void* _in2[1], uint32_t _in2Len[1], uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], void* _rout6[1], uint32_t _rout6Len[1], char* _rout7[1], uint32_t _rout7Len[1], char* _rout8[1], uint32_t _rout8Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat2 = 0; - int _ii = 0; - char* _seq_nat6 = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[6]= {0}; - uint32_t _primROut[3]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - remote_arg** _ppraIn = &_praIn; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn2 = 0; - int _nErr = 0; - char* _seq_primIn6 = 0; - _numIn[0] = 2; - _numROut[0] = 2; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))){ - _count_1(_numIn, _numROut, _numInH, _numROutH, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2]))); - } - for(_ii = 0, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))){ - _count(_numIn, _numROut, _numInH, _numROutH, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat6)[0]), (char**)&(((uint64_t*)_seq_nat6)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat6)[1]), (uint32_t*)&(((uint32_t*)_seq_nat6)[2]))); - } - if(_numIn[0]>=255){ - _QAIC_FARF(RUNTIME_ERROR, "ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255){ - _QAIC_FARF(RUNTIME_ERROR, "ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 1) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROutPost = _praROut; - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2Len, 0, 4); - if(_praHIn == 0) - { - _praHIn = ((_praROut + _numROut[0]) + 1); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in2Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in2Len[0]); - for(_ii = 0, _seq_primIn2 = (char*)_praIn[0].buf.pv, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_primIn2 = (_seq_primIn2 + 4), _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_pack_1(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn2, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _COPY(_primIn, 12, _rout6Len, 0, 4); - _ALLOCATE(_nErr, _al, (_rout6Len[0] * 4), 4, _praIn[1].buf.pv); - _praIn[1].buf.nLen = (4 * _rout6Len[0]); - for(_ii = 0, _seq_primIn6 = (char*)_praIn[1].buf.pv, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_primIn6 = (_seq_primIn6 + 4), _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_pack(_al, (_praIn + 2), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn6, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat6)[0]), (char**)&(((uint64_t*)_seq_nat6)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat6)[1]), (uint32_t*)&(((uint32_t*)_seq_nat6)[2])))); - } - _COPY(_primIn, 16, _rout7Len, 0, 4); - _praROut[0].buf.pv = _rout7[0]; - _praROut[0].buf.nLen = (4 * _rout7Len[0]); - _COPY(_primIn, 20, _rout8Len, 0, 4); - _praROut[1].buf.pv = _rout8[0]; - _praROut[1].buf.nLen = (4 * _rout8Len[0]); - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - for(_ii = 0, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_unpack_1((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _COPY(_rout3, 0, _primROut, 0, 4); - _COPY(_rout4, 0, _primROut, 4, 4); - _COPY(_rout5, 0, _primROut, 8, 4); - for(_ii = 0, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat6)[0]), (char**)&(((uint64_t*)_seq_nat6)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat6)[1]), (uint32_t*)&(((uint32_t*)_seq_nat6)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), (_numInH[0] + 0), (_numROutH[0] + 0)), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], void *_in2[1], uint32_t _in2Len[1], + uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], + void *_rout6[1], uint32_t _rout6Len[1], char *_rout7[1], + uint32_t _rout7Len[1], char *_rout8[1], uint32_t _rout8Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat2 = 0; + int _ii = 0; + char *_seq_nat6 = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[6] = { 0 }; + uint32_t _primROut[3] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + remote_arg **_ppraIn = &_praIn; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn2 = 0; + int _nErr = 0; + char *_seq_primIn6 = 0; + _numIn[0] = 2; + _numROut[0] = 2; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat2 = (char *)_in2[0]; _ii < (int)_in2Len[0]; + ++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _count_1( + _numIn, _numROut, _numInH, _numROutH, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32((uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2]))); + } + for(_ii = 0, _seq_nat6 = (char *)_rout6[0]; _ii < (int)_rout6Len[0]; + ++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _count( + _numIn, _numROut, _numInH, _numROutH, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat6)[0]), + (char **)&(((uint64_t *)_seq_nat6)[0])), + SLIM_IFPTR32((uint32_t *)&(((uint32_t *)_seq_nat6)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat6)[2]))); + } + if(_numIn[0] >= 255) { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 1) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROutPost = _praROut; + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2Len, 0, 4); + if(_praHIn == 0) { + _praHIn = ((_praROut + _numROut[0]) + 1); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in2Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in2Len[0]); + for(_ii = 0, _seq_primIn2 = (char *)_praIn[0].buf.pv, + _seq_nat2 = (char *)_in2[0]; + _ii < (int)_in2Len[0]; ++_ii, _seq_primIn2 = (_seq_primIn2 + 4), + _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack_1( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn2, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _COPY(_primIn, 12, _rout6Len, 0, 4); + _ALLOCATE(_nErr, _al, (_rout6Len[0] * 4), 4, _praIn[1].buf.pv); + _praIn[1].buf.nLen = (4 * _rout6Len[0]); + for(_ii = 0, _seq_primIn6 = (char *)_praIn[1].buf.pv, + _seq_nat6 = (char *)_rout6[0]; + _ii < (int)_rout6Len[0]; ++_ii, _seq_primIn6 = (_seq_primIn6 + 4), + _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 2), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn6, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat6)[0]), + (char **)&(((uint64_t *)_seq_nat6)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat6)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat6)[2])))); + } + _COPY(_primIn, 16, _rout7Len, 0, 4); + _praROut[0].buf.pv = _rout7[0]; + _praROut[0].buf.nLen = (4 * _rout7Len[0]); + _COPY(_primIn, 20, _rout8Len, 0, 4); + _praROut[1].buf.pv = _rout8[0]; + _praROut[1].buf.nLen = (4 * _rout8Len[0]); + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + for(_ii = 0, _seq_nat2 = (char *)_in2[0]; _ii < (int)_in2Len[0]; + ++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack_1( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _COPY(_rout3, 0, _primROut, 0, 4); + _COPY(_rout4, 0, _primROut, 4, 4); + _COPY(_rout5, 0, _primROut, 8, 4); + for(_ii = 0, _seq_nat6 = (char *)_rout6[0]; _ii < (int)_rout6Len[0]; + ++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat6)[0]), + (char **)&(((uint64_t *)_seq_nat6)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat6)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat6)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _mid, __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_next_invoke)(remote_handle64 _handle, adsp_listener1_invoke_ctx prevCtx, int prevResult, const adsp_listener1_buffer* outBufs, int outBufsLen, adsp_listener1_invoke_ctx* ctx, adsp_listener1_remote_handle* handle, uint32_t* sc, adsp_listener1_buffer* inBuffers, int inBuffersLen, int* inBufLenReq, int inBufLenReqLen, int* routBufLenReq, int routBufLenReqLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid, (uint32_t*)&prevCtx, (uint32_t*)&prevResult, (void**)&outBufs, (uint32_t*)&outBufsLen, (uint32_t*)ctx, (uint32_t*)handle, (uint32_t*)sc, (void**)&inBuffers, (uint32_t*)&inBuffersLen, (char**)&inBufLenReq, (uint32_t*)&inBufLenReqLen, (char**)&routBufLenReq, (uint32_t*)&routBufLenReqLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_next_invoke)( + remote_handle64 _handle, adsp_listener1_invoke_ctx prevCtx, int prevResult, + const adsp_listener1_buffer *outBufs, int outBufsLen, + adsp_listener1_invoke_ctx *ctx, adsp_listener1_remote_handle *handle, + uint32_t *sc, adsp_listener1_buffer *inBuffers, int inBuffersLen, + int *inBufLenReq, int inBufLenReqLen, int *routBufLenReq, + int routBufLenReqLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method( + _handle, _mid, (uint32_t *)&prevCtx, (uint32_t *)&prevResult, + (void **)&outBufs, (uint32_t *)&outBufsLen, (uint32_t *)ctx, + (uint32_t *)handle, (uint32_t *)sc, (void **)&inBuffers, + (uint32_t *)&inBuffersLen, (char **)&inBufLenReq, + (uint32_t *)&inBufLenReqLen, (char **)&routBufLenReq, + (uint32_t *)&routBufLenReqLen); } -static __inline int _stub_unpack_2(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +1; - return _nErr; +static __inline int +_stub_unpack_2(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 1; + return _nErr; } -static __inline int _stub_pack_2(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 0; - _ppraROutStart[0] += (_praROut - _praROutStart) +1; - return _nErr; +static __inline int +_stub_pack_2(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 0; + _ppraROutStart[0] += (_praROut - _praROutStart) + 1; + return _nErr; } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], void* _rout1[1], uint32_t _rout1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - remote_arg** _ppraIn = &_praIn; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))){ - _count(_numIn, _numROut, _numInH, _numROutH, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2]))); - } - if(_numIn[0]>=255){ - _QAIC_FARF(RUNTIME_ERROR, "ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255){ - _QAIC_FARF(RUNTIME_ERROR, "ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - _praROutPost = _praROut; - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _rout1Len, 0, 4); - if(_praHIn == 0) - { - _praHIn = ((_praROut + _numROut[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_rout1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _rout1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_pack_2(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - for(_ii = 0, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))){ - _TRY(_nErr, _stub_unpack_2((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + void *_rout1[1], uint32_t _rout1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + remote_arg **_ppraIn = &_praIn; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_rout1[0]; _ii < (int)_rout1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count( + _numIn, _numROut, _numInH, _numROutH, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32((uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2]))); + } + if(_numIn[0] >= 255) { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + _praROutPost = _praROut; + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _rout1Len, 0, 4); + if(_praHIn == 0) { + _praHIn = ((_praROut + _numROut[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_rout1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _rout1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_rout1[0]; + _ii < (int)_rout1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack_2( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + for(_ii = 0, _seq_nat1 = (char *)_rout1[0]; _ii < (int)_rout1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack_2( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _mid, __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_invoke_get_in_bufs)(remote_handle64 _handle, adsp_listener1_invoke_ctx ctx, adsp_listener1_buffer* inBuffers, int inBuffersLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method_1(_handle, _mid, (uint32_t*)&ctx, (void**)&inBuffers, (uint32_t*)&inBuffersLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_invoke_get_in_bufs)( + remote_handle64 _handle, adsp_listener1_invoke_ctx ctx, + adsp_listener1_buffer *inBuffers, int inBuffersLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method_1(_handle, _mid, (uint32_t *)&ctx, + (void **)&inBuffers, (uint32_t *)&inBuffersLen); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_init)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_2(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_init)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_2(_handle, _mid); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_init2)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - return _stub_method_2(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_init2)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + return _stub_method_2(_handle, _mid); } -static __inline int _stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], char* _in2[1], uint32_t _in2Len[1], uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], char* _rout6[1], uint32_t _rout6Len[1], uint32_t _rout7[1]) { - int _numIn[1] = {0}; - remote_arg _pra[4] = {0}; - uint32_t _primIn[4]= {0}; - uint32_t _primROut[4]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 1; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in2[0]; - _praIn[0].buf.nLen = (1 * _in2Len[0]); - _COPY(_primIn, 12, _rout6Len, 0, 4); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout6[0]; - _praROut[0].buf.nLen = (1 * _rout6Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); - _COPY(_rout3, 0, _primROut, 0, 4); - _COPY(_rout4, 0, _primROut, 4, 4); - _COPY(_rout5, 0, _primROut, 8, 4); - _COPY(_rout7, 0, _primROut, 12, 4); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], char *_in2[1], uint32_t _in2Len[1], + uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], + char *_rout6[1], uint32_t _rout6Len[1], uint32_t _rout7[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[4] = { 0 }; + uint32_t _primIn[4] = { 0 }; + uint32_t _primROut[4] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 1; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in2[0]; + _praIn[0].buf.nLen = (1 * _in2Len[0]); + _COPY(_primIn, 12, _rout6Len, 0, 4); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout6[0]; + _praROut[0].buf.nLen = (1 * _rout6Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); + _COPY(_rout3, 0, _primROut, 0, 4); + _COPY(_rout4, 0, _primROut, 4, 4); + _COPY(_rout5, 0, _primROut, 8, 4); + _COPY(_rout7, 0, _primROut, 12, 4); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_next2)(remote_handle64 _handle, adsp_listener1_invoke_ctx prevCtx, int prevResult, const uint8_t* prevbufs, int prevbufsLen, adsp_listener1_invoke_ctx* ctx, adsp_listener1_remote_handle* handle, uint32_t* sc, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 6; - return _stub_method_3(_handle, _mid, (uint32_t*)&prevCtx, (uint32_t*)&prevResult, (char**)&prevbufs, (uint32_t*)&prevbufsLen, (uint32_t*)ctx, (uint32_t*)handle, (uint32_t*)sc, (char**)&bufs, (uint32_t*)&bufsLen, (uint32_t*)bufsLenReq); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_next2)( + remote_handle64 _handle, adsp_listener1_invoke_ctx prevCtx, int prevResult, + const uint8_t *prevbufs, int prevbufsLen, adsp_listener1_invoke_ctx *ctx, + adsp_listener1_remote_handle *handle, uint32_t *sc, uint8_t *bufs, + int bufsLen, int *bufsLenReq) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 6; + return _stub_method_3( + _handle, _mid, (uint32_t *)&prevCtx, (uint32_t *)&prevResult, + (char **)&prevbufs, (uint32_t *)&prevbufsLen, (uint32_t *)ctx, + (uint32_t *)handle, (uint32_t *)sc, (char **)&bufs, + (uint32_t *)&bufsLen, (uint32_t *)bufsLenReq); } -static __inline int _stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], char* _rout2[1], uint32_t _rout2Len[1], uint32_t _rout3[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[3]= {0}; - uint32_t _primROut[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _rout2Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout2[0]; - _praROut[0].buf.nLen = (1 * _rout2Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout3, 0, _primROut, 0, 4); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], char *_rout2[1], uint32_t _rout2Len[1], + uint32_t _rout3[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[3] = { 0 }; + uint32_t _primROut[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _rout2Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout2[0]; + _praROut[0].buf.nLen = (1 * _rout2Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout3, 0, _primROut, 0, 4); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener1_get_in_bufs2)(remote_handle64 _handle, adsp_listener1_invoke_ctx ctx, int offset, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 7; - return _stub_method_4(_handle, _mid, (uint32_t*)&ctx, (uint32_t*)&offset, (char**)&bufs, (uint32_t*)&bufsLen, (uint32_t*)bufsLenReq); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener1_get_in_bufs2)(remote_handle64 _handle, + adsp_listener1_invoke_ctx ctx, + int offset, uint8_t *bufs, + int bufsLen, + int *bufsLenReq) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 7; + return _stub_method_4(_handle, _mid, (uint32_t *)&ctx, + (uint32_t *)&offset, (char **)&bufs, + (uint32_t *)&bufsLen, (uint32_t *)bufsLenReq); } #ifdef __cplusplus } diff --git a/src/adsp_listener_stub.c b/src/adsp_listener_stub.c index f37b7ff1..d863a4f7 100644 --- a/src/adsp_listener_stub.c +++ b/src/adsp_listener_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,158 +93,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } -} -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } +} +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -252,175 +266,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_LISTENER_SLIM_H #define _ADSP_LISTENER_SLIM_H @@ -434,67 +445,160 @@ struct Interface { #endif static const Type types[3]; -static const SequenceType sequenceTypes[1] = {{&(types[0]),0x0,0x4,0x4,0x0}}; -static const Type types[3] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8)},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}}; -static const Parameter parameters[11] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[2]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[23] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[2])),(&(parameters[3])),(&(parameters[4])),(&(parameters[5])),(&(parameters[6])),(&(parameters[7])),(&(parameters[7])),(&(parameters[0])),(&(parameters[1])),(&(parameters[8])),(&(parameters[3])),(&(parameters[4])),(&(parameters[5])),(&(parameters[9])),(&(parameters[10])),(&(parameters[0])),(&(parameters[1])),(&(parameters[9])),(&(parameters[10])),(&(parameters[0])),(&(parameters[6]))}; -static const Method methods[5] = {{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x18,0xc,16,9,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0x8,0x0,4,2,(&(parameterArrays[21])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x10,0x10,11,8,(&(parameterArrays[9])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0xc,0x4,6,4,(&(parameterArrays[17])),0x4,0x4}}; -static const Method* const methodArrays[6] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[2]),&(methods[3]),&(methods[4])}; -static const char strings[166] = "invoke_get_in_bufs\0routBufLenReq\0get_in_bufs2\0inBufLenReq\0next_invoke\0bufsLenReq\0prevResult\0inBuffers\0prevbufs\0outBufs\0prevCtx\0offset\0handle\0next2\0init2\0init\0ctx\0sc\0"; -static const uint16_t methodStrings[29] = {58,119,81,111,158,134,162,92,46,19,141,119,81,102,158,134,162,14,70,33,158,127,14,70,0,158,92,147,153}; -static const uint16_t methodStringsArrays[6] = {0,24,28,27,10,19}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_listener_slim) = {6,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const SequenceType sequenceTypes[1] + = { { &(types[0]), 0x0, 0x4, 0x4, 0x0 } }; +static const Type types[3] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8) }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 } }; +static const Parameter parameters[11] = { + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[2]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[23] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[2])), + (&(parameters[3])), (&(parameters[4])), (&(parameters[5])), + (&(parameters[6])), (&(parameters[7])), (&(parameters[7])), + (&(parameters[0])), (&(parameters[1])), (&(parameters[8])), + (&(parameters[3])), (&(parameters[4])), (&(parameters[5])), + (&(parameters[9])), (&(parameters[10])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[9])), (&(parameters[10])), + (&(parameters[0])), (&(parameters[6])) }; +static const Method methods[5] + = { { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x18, 0xc, 16, 9, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0x8, 0x0, 4, 2, + (&(parameterArrays[21])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x10, 0x10, 11, 8, + (&(parameterArrays[9])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0xc, 0x4, 6, 4, + (&(parameterArrays[17])), 0x4, 0x4 } }; +static const Method *const methodArrays[6] + = { &(methods[0]), &(methods[1]), &(methods[2]), + &(methods[2]), &(methods[3]), &(methods[4]) }; +static const char strings[166] + = "invoke_get_in_bufs\0routBufLenReq\0get_in_bufs2\0inBufLenReq\0next_" + "invoke\0bufsLenReq\0prevResult\0inBuffers\0prevbufs\0outBufs\0prevCtx\0" + "offset\0handle\0next2\0init2\0init\0ctx\0sc\0"; +static const uint16_t methodStrings[29] + = { 58, 119, 81, 111, 158, 134, 162, 92, 46, 19, 141, 119, 81, 102, 158, + 134, 162, 14, 70, 33, 158, 127, 14, 70, 0, 158, 92, 147, 153 }; +static const uint16_t methodStringsArrays[6] = { 0, 24, 28, 27, 10, 19 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_listener_slim) + = { 6, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_LISTENER_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_adsp_listener_handle -#define _const_adsp_listener_handle ((remote_handle)-1) +#define _const_adsp_listener_handle ((remote_handle) - 1) #endif //_const_adsp_listener_handle -static void _adsp_listener_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_adsp_listener_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_adsp_listener_handle; - } +static void +_adsp_listener_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_adsp_listener_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_adsp_listener_handle; + } } -static int _adsp_listener_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_adsp_listener_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_adsp_listener_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_adsp_listener_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _adsp_listener_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_adsp_listener_handle, 0, sizeof(*ph), _adsp_listener_pls_ctor, "adsp_listener", _adsp_listener_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_adsp_listener_handle, 0, sizeof(*ph), _adsp_listener_pls_ctor, "adsp_listener", _adsp_listener_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_adsp_listener_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup( + (uint32_t)_adsp_listener_handle, 0, sizeof(*ph), + _adsp_listener_pls_ctor, "adsp_listener", + _adsp_listener_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup( + (uint32_t)_adsp_listener_handle, 0, sizeof(*ph), + _adsp_listener_pls_ctor, "adsp_listener", + _adsp_listener_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _adsp_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _adsp_listener_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -502,31 +606,45 @@ uint32_t _adsp_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, ui #else #include "ntddk.h" #endif //_USRDLL -uint32_t _adsp_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_adsp_listener_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _adsp_listener_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_adsp_listener_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _adsp_listener_handle(void) { - static remote_handle handle = _const_adsp_listener_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _adsp_listener_pls_ctor("adsp_listener", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adsp_listener_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _adsp_listener_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_adsp_listener_handle(void) +{ + static remote_handle handle = _const_adsp_listener_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr + = _adsp_listener_pls_ctor("adsp_listener", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle) + _adsp_listener_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _adsp_listener_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -535,401 +653,588 @@ __QAIC_STUB_EXPORT remote_handle _adsp_listener_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_unpack(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +1; - return _nErr; -} -static __inline int _stub_unpack_1(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +0; - return _nErr; -} -static __inline int _stub_pack(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 0; - _ppraROutStart[0] += (_praROut - _praROutStart) +1; - return _nErr; -} -static __inline int _stub_pack_1(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _in0[1], _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 1; - _ppraROutStart[0] += (_praROut - _praROutStart) +0; - return _nErr; -} -static __inline void _count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) { - _numIn[0] += 0; - _numROut[0] += 1; - _numInH[0] += 0; - _numROutH[0] += 0; -} -static __inline void _count_1(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) { - _numIn[0] += 1; - _numROut[0] += 0; - _numInH[0] += 0; - _numROutH[0] += 0; -} -static __inline int _stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], void* _in2[1], uint32_t _in2Len[1], uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], void* _rout6[1], uint32_t _rout6Len[1], char* _rout7[1], uint32_t _rout7Len[1], char* _rout8[1], uint32_t _rout8Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat2 = 0; - int _ii = 0; - char* _seq_nat6 = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[6]= {0}; - uint32_t _primROut[3]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - remote_arg** _ppraIn = &_praIn; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn2 = 0; - int _nErr = 0; - char* _seq_primIn6 = 0; - _numIn[0] = 2; - _numROut[0] = 2; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) - { - _count_1(_numIn, _numROut, _numInH, _numROutH); - } - for(_ii = 0, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 1) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROutPost = _praROut; - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2Len, 0, 4); - if(_praHIn == 0) - { - _praHIn = ((_praROut + _numROut[0]) + 1); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_in2Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _in2Len[0]); - for(_ii = 0, _seq_primIn2 = (char*)_praIn[0].buf.pv, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_primIn2 = (_seq_primIn2 + 4), _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack_1(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn2, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _COPY(_primIn, 12, _rout6Len, 0, 4); - _ALLOCATE(_nErr, _al, (_rout6Len[0] * 4), 4, _praIn[1].buf.pv); - _praIn[1].buf.nLen = (4 * _rout6Len[0]); - for(_ii = 0, _seq_primIn6 = (char*)_praIn[1].buf.pv, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_primIn6 = (_seq_primIn6 + 4), _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack(_al, (_praIn + 2), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn6, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat6)[0]), (char**)&(((uint64_t*)_seq_nat6)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat6)[1]), (uint32_t*)&(((uint32_t*)_seq_nat6)[2])))); - } - _COPY(_primIn, 16, _rout7Len, 0, 4); - _praROut[0].buf.pv = _rout7[0]; - _praROut[0].buf.nLen = (4 * _rout7Len[0]); - _COPY(_primIn, 20, _rout8Len, 0, 4); - _praROut[1].buf.pv = _rout8[0]; - _praROut[1].buf.nLen = (4 * _rout8Len[0]); - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - for(_ii = 0, _seq_nat2 = (char*)_in2[0];_ii < (int)_in2Len[0];++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack_1((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _COPY(_rout3, 0, _primROut, 0, 4); - _COPY(_rout4, 0, _primROut, 4, 4); - _COPY(_rout5, 0, _primROut, 8, 4); - for(_ii = 0, _seq_nat6 = (char*)_rout6[0];_ii < (int)_rout6Len[0];++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat6)[0]), (char**)&(((uint64_t*)_seq_nat6)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat6)[1]), (uint32_t*)&(((uint32_t*)_seq_nat6)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_next_invoke)(adsp_listener_invoke_ctx prevCtx, int prevResult, const adsp_listener_buffer* outBufs, int outBufsLen, adsp_listener_invoke_ctx* ctx, adsp_listener_remote_handle* handle, uint32_t* sc, adsp_listener_buffer* inBuffers, int inBuffersLen, int* inBufLenReq, int inBufLenReqLen, int* routBufLenReq, int routBufLenReqLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid, (uint32_t*)&prevCtx, (uint32_t*)&prevResult, (void**)&outBufs, (uint32_t*)&outBufsLen, (uint32_t*)ctx, (uint32_t*)handle, (uint32_t*)sc, (void**)&inBuffers, (uint32_t*)&inBuffersLen, (char**)&inBufLenReq, (uint32_t*)&inBufLenReqLen, (char**)&routBufLenReq, (uint32_t*)&routBufLenReqLen); - } - else - { - return AEE_EINVHANDLE; - } -} -static __inline int _stub_unpack_2(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +1; - return _nErr; -} -static __inline int _stub_pack_2(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _ppraInStart[0] += (_praIn - _praInStart) + 0; - _ppraROutStart[0] += (_praROut - _praROutStart) +1; - return _nErr; -} -static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], void* _rout1[1], uint32_t _rout1Len[1]) { - remote_arg* _pra = 0; - int _numIn[1] = {0}; - int _numROut[1] = {0}; - int _numInH[1] = {0}; - int _numROutH[1] = {0}; - char* _seq_nat1 = 0; - int _ii = 0; - _allocator _al[1] = {{0}}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - remote_arg** _ppraIn = &_praIn; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn1 = 0; - int _nErr = 0; - _numIn[0] = 1; - _numROut[0] = 0; - _numInH[0] = 0; - _numROutH[0] = 0; - for(_ii = 0, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _count(_numIn, _numROut, _numInH, _numROutH); - } - if(_numIn[0]>=255) - { - printf("ERROR: Unsupported number of input buffers\n"); - return AEE_EUNSUPPORTED; - } - if(_numROut[0]>=255) - { - printf("ERROR: Unsupported number of output buffers\n"); - return AEE_EUNSUPPORTED; - } - _allocator_init(_al, 0, 0); - _ALLOCATE(_nErr, _al, ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + 0) + 0) + 0) * sizeof(_pra[0])), 4, _pra); - _ASSERT(_nErr, _pra); - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - _praROutPost = _praROut; - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _rout1Len, 0, 4); - if(_praHIn == 0) - { - _praHIn = ((_praROut + _numROut[0]) + 0); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ALLOCATE(_nErr, _al, (_rout1Len[0] * 4), 4, _praIn[0].buf.pv); - _praIn[0].buf.nLen = (4 * _rout1Len[0]); - for(_ii = 0, _seq_primIn1 = (char*)_praIn[0].buf.pv, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_primIn1 = (_seq_primIn1 + 4), _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_pack_2(_al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn1, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _ASSERT(_nErr, (_numInH[0] + 0) <= 15); - _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), (_numInH[0] + 0), (_numROutH[0] + 0)), _pra)); - for(_ii = 0, _seq_nat1 = (char*)_rout1[0];_ii < (int)_rout1Len[0];++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _stub_unpack_2((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat1)[0]), (char**)&(((uint64_t*)_seq_nat1)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat1)[1]), (uint32_t*)&(((uint32_t*)_seq_nat1)[2])))); - } - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_invoke_get_in_bufs)(adsp_listener_invoke_ctx ctx, adsp_listener_buffer* inBuffers, int inBuffersLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 1; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid, (uint32_t*)&ctx, (void**)&inBuffers, (uint32_t*)&inBuffersLen); - } - else - { - return AEE_EINVHANDLE; - } -} -static __inline int _stub_method_2(remote_handle _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_init)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_2(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_init2)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_2(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } -} -static __inline int _stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], char* _in2[1], uint32_t _in2Len[1], uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], char* _rout6[1], uint32_t _rout6Len[1], uint32_t _rout7[1]) { - int _numIn[1] = {0}; - remote_arg _pra[4] = {0}; - uint32_t _primIn[4]= {0}; - uint32_t _primROut[4]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 1; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in2[0]; - _praIn[0].buf.nLen = (1 * _in2Len[0]); - _COPY(_primIn, 12, _rout6Len, 0, 4); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout6[0]; - _praROut[0].buf.nLen = (1 * _rout6Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); - _COPY(_rout3, 0, _primROut, 0, 4); - _COPY(_rout4, 0, _primROut, 4, 4); - _COPY(_rout5, 0, _primROut, 8, 4); - _COPY(_rout7, 0, _primROut, 12, 4); - _CATCH(_nErr) {} - return _nErr; -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_next2)(adsp_listener_invoke_ctx prevCtx, int prevResult, const uint8_t* prevbufs, int prevbufsLen, adsp_listener_invoke_ctx* ctx, adsp_listener_remote_handle* handle, uint32_t* sc, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_3(_handle, _mid, (uint32_t*)&prevCtx, (uint32_t*)&prevResult, (char**)&prevbufs, (uint32_t*)&prevbufsLen, (uint32_t*)ctx, (uint32_t*)handle, (uint32_t*)sc, (char**)&bufs, (uint32_t*)&bufsLen, (uint32_t*)bufsLenReq); - } - else - { - return AEE_EINVHANDLE; - } -} -static __inline int _stub_method_4(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], char* _rout2[1], uint32_t _rout2Len[1], uint32_t _rout3[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[3]= {0}; - uint32_t _primROut[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _rout2Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout2[0]; - _praROut[0].buf.nLen = (1 * _rout2Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout3, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; -} -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_listener_get_in_bufs2)(adsp_listener_invoke_ctx ctx, int offset, uint8_t* bufs, int bufsLen, int* bufsLenReq) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - remote_handle _handle = _adsp_listener_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_4(_handle, _mid, (uint32_t*)&ctx, (uint32_t*)&offset, (char**)&bufs, (uint32_t*)&bufsLen, (uint32_t*)bufsLenReq); - } - else - { - return AEE_EINVHANDLE; - } +static __inline int +_stub_unpack(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 1; + return _nErr; +} +static __inline int +_stub_unpack_1(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 0; + return _nErr; +} +static __inline int +_stub_pack(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 0; + _ppraROutStart[0] += (_praROut - _praROutStart) + 1; + return _nErr; +} +static __inline int +_stub_pack_1(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_in0[1], + _ATTRIBUTE_UNUSED uint32_t _in0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 1; + _ppraROutStart[0] += (_praROut - _praROutStart) + 0; + return _nErr; +} +static __inline void +_count(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) +{ + _numIn[0] += 0; + _numROut[0] += 1; + _numInH[0] += 0; + _numROutH[0] += 0; +} +static __inline void +_count_1(int _numIn[1], int _numROut[1], int _numInH[1], int _numROutH[1]) +{ + _numIn[0] += 1; + _numROut[0] += 0; + _numInH[0] += 0; + _numROutH[0] += 0; +} +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], void *_in2[1], uint32_t _in2Len[1], + uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], + void *_rout6[1], uint32_t _rout6Len[1], char *_rout7[1], + uint32_t _rout7Len[1], char *_rout8[1], uint32_t _rout8Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat2 = 0; + int _ii = 0; + char *_seq_nat6 = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[6] = { 0 }; + uint32_t _primROut[3] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + remote_arg **_ppraIn = &_praIn; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn2 = 0; + int _nErr = 0; + char *_seq_primIn6 = 0; + _numIn[0] = 2; + _numROut[0] = 2; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat2 = (char *)_in2[0]; _ii < (int)_in2Len[0]; + ++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _count_1(_numIn, _numROut, _numInH, _numROutH); + } + for(_ii = 0, _seq_nat6 = (char *)_rout6[0]; _ii < (int)_rout6Len[0]; + ++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 1) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROutPost = _praROut; + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2Len, 0, 4); + if(_praHIn == 0) { + _praHIn = ((_praROut + _numROut[0]) + 1); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_in2Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _in2Len[0]); + for(_ii = 0, _seq_primIn2 = (char *)_praIn[0].buf.pv, + _seq_nat2 = (char *)_in2[0]; + _ii < (int)_in2Len[0]; ++_ii, _seq_primIn2 = (_seq_primIn2 + 4), + _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack_1( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn2, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _COPY(_primIn, 12, _rout6Len, 0, 4); + _ALLOCATE(_nErr, _al, (_rout6Len[0] * 4), 4, _praIn[1].buf.pv); + _praIn[1].buf.nLen = (4 * _rout6Len[0]); + for(_ii = 0, _seq_primIn6 = (char *)_praIn[1].buf.pv, + _seq_nat6 = (char *)_rout6[0]; + _ii < (int)_rout6Len[0]; ++_ii, _seq_primIn6 = (_seq_primIn6 + 4), + _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack( + _al, (_praIn + 2), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn6, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat6)[0]), + (char **)&(((uint64_t *)_seq_nat6)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat6)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat6)[2])))); + } + _COPY(_primIn, 16, _rout7Len, 0, 4); + _praROut[0].buf.pv = _rout7[0]; + _praROut[0].buf.nLen = (4 * _rout7Len[0]); + _COPY(_primIn, 20, _rout8Len, 0, 4); + _praROut[1].buf.pv = _rout8[0]; + _praROut[1].buf.nLen = (4 * _rout8Len[0]); + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 1), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + for(_ii = 0, _seq_nat2 = (char *)_in2[0]; _ii < (int)_in2Len[0]; + ++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack_1( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _COPY(_rout3, 0, _primROut, 0, 4); + _COPY(_rout4, 0, _primROut, 4, 4); + _COPY(_rout5, 0, _primROut, 8, 4); + for(_ii = 0, _seq_nat6 = (char *)_rout6[0]; _ii < (int)_rout6Len[0]; + ++_ii, _seq_nat6 = (_seq_nat6 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat6)[0]), + (char **)&(((uint64_t *)_seq_nat6)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat6)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat6)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_next_invoke)( + adsp_listener_invoke_ctx prevCtx, int prevResult, + const adsp_listener_buffer *outBufs, int outBufsLen, + adsp_listener_invoke_ctx *ctx, adsp_listener_remote_handle *handle, + uint32_t *sc, adsp_listener_buffer *inBuffers, int inBuffersLen, + int *inBufLenReq, int inBufLenReqLen, int *routBufLenReq, + int routBufLenReqLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method( + _handle, _mid, (uint32_t *)&prevCtx, + (uint32_t *)&prevResult, (void **)&outBufs, + (uint32_t *)&outBufsLen, (uint32_t *)ctx, + (uint32_t *)handle, (uint32_t *)sc, (void **)&inBuffers, + (uint32_t *)&inBuffersLen, (char **)&inBufLenReq, + (uint32_t *)&inBufLenReqLen, (char **)&routBufLenReq, + (uint32_t *)&routBufLenReqLen); + } else { + return AEE_EINVHANDLE; + } +} +static __inline int +_stub_unpack_2(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 1; + return _nErr; +} +static __inline int +_stub_pack_2(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _ppraInStart[0] += (_praIn - _praInStart) + 0; + _ppraROutStart[0] += (_praROut - _praROutStart) + 1; + return _nErr; +} +static __inline int +_stub_method_1(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + void *_rout1[1], uint32_t _rout1Len[1]) +{ + remote_arg *_pra = 0; + int _numIn[1] = { 0 }; + int _numROut[1] = { 0 }; + int _numInH[1] = { 0 }; + int _numROutH[1] = { 0 }; + char *_seq_nat1 = 0; + int _ii = 0; + _allocator _al[1] = { { 0 } }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + remote_arg **_ppraIn = &_praIn; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn1 = 0; + int _nErr = 0; + _numIn[0] = 1; + _numROut[0] = 0; + _numInH[0] = 0; + _numROutH[0] = 0; + for(_ii = 0, _seq_nat1 = (char *)_rout1[0]; _ii < (int)_rout1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _count(_numIn, _numROut, _numInH, _numROutH); + } + if(_numIn[0] >= 255) { + printf("ERROR: Unsupported number of input buffers\n"); + return AEE_EUNSUPPORTED; + } + if(_numROut[0] >= 255) { + printf("ERROR: Unsupported number of output buffers\n"); + return AEE_EUNSUPPORTED; + } + _allocator_init(_al, 0, 0); + _ALLOCATE( + _nErr, _al, + ((((((((_numIn[0] + _numROut[0]) + _numInH[0]) + _numROutH[0]) + 1) + + 0) + + 0) + + 0) + * sizeof(_pra[0])), + 4, _pra); + _ASSERT(_nErr, _pra); + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + _praROutPost = _praROut; + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _rout1Len, 0, 4); + if(_praHIn == 0) { + _praHIn = ((_praROut + _numROut[0]) + 0); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ALLOCATE(_nErr, _al, (_rout1Len[0] * 4), 4, _praIn[0].buf.pv); + _praIn[0].buf.nLen = (4 * _rout1Len[0]); + for(_ii = 0, _seq_primIn1 = (char *)_praIn[0].buf.pv, + _seq_nat1 = (char *)_rout1[0]; + _ii < (int)_rout1Len[0]; ++_ii, _seq_primIn1 = (_seq_primIn1 + 4), + _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_pack_2( + _al, (_praIn + 1), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn1, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _ASSERT(_nErr, (_numInH[0] + 0) <= 15); + _ASSERT(_nErr, (_numROutH[0] + 0) <= 15); + _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)( + _handle, + REMOTE_SCALARS_MAKEX( + 0, _mid, (_numIn[0] + 1), (_numROut[0] + 0), + (_numInH[0] + 0), (_numROutH[0] + 0)), + _pra)); + for(_ii = 0, _seq_nat1 = (char *)_rout1[0]; _ii < (int)_rout1Len[0]; + ++_ii, _seq_nat1 = (_seq_nat1 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _stub_unpack_2( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat1)[0]), + (char **)&(((uint64_t *)_seq_nat1)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat1)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat1)[2])))); + } + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_invoke_get_in_bufs)( + adsp_listener_invoke_ctx ctx, adsp_listener_buffer *inBuffers, + int inBuffersLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 1; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1(_handle, _mid, (uint32_t *)&ctx, + (void **)&inBuffers, + (uint32_t *)&inBuffersLen); + } else { + return AEE_EINVHANDLE; + } +} +static __inline int +_stub_method_2(remote_handle _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_init)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_2(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_init2)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_2(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } +} +static __inline int +_stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], char *_in2[1], uint32_t _in2Len[1], + uint32_t _rout3[1], uint32_t _rout4[1], uint32_t _rout5[1], + char *_rout6[1], uint32_t _rout6Len[1], uint32_t _rout7[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[4] = { 0 }; + uint32_t _primIn[4] = { 0 }; + uint32_t _primROut[4] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 1; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in2[0]; + _praIn[0].buf.nLen = (1 * _in2Len[0]); + _COPY(_primIn, 12, _rout6Len, 0, 4); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout6[0]; + _praROut[0].buf.nLen = (1 * _rout6Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); + _COPY(_rout3, 0, _primROut, 0, 4); + _COPY(_rout4, 0, _primROut, 4, 4); + _COPY(_rout5, 0, _primROut, 8, 4); + _COPY(_rout7, 0, _primROut, 12, 4); + _CATCH(_nErr) {} + return _nErr; +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_next2)(adsp_listener_invoke_ctx prevCtx, + int prevResult, const uint8_t *prevbufs, + int prevbufsLen, + adsp_listener_invoke_ctx *ctx, + adsp_listener_remote_handle *handle, + uint32_t *sc, uint8_t *bufs, int bufsLen, + int *bufsLenReq) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_3( + _handle, _mid, (uint32_t *)&prevCtx, + (uint32_t *)&prevResult, (char **)&prevbufs, + (uint32_t *)&prevbufsLen, (uint32_t *)ctx, + (uint32_t *)handle, (uint32_t *)sc, (char **)&bufs, + (uint32_t *)&bufsLen, (uint32_t *)bufsLenReq); + } else { + return AEE_EINVHANDLE; + } +} +static __inline int +_stub_method_4(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], char *_rout2[1], uint32_t _rout2Len[1], + uint32_t _rout3[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[3] = { 0 }; + uint32_t _primROut[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _rout2Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout2[0]; + _praROut[0].buf.nLen = (1 * _rout2Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout3, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; +} +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_listener_get_in_bufs2)(adsp_listener_invoke_ctx ctx, + int offset, uint8_t *bufs, int bufsLen, + int *bufsLenReq) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + remote_handle _handle = _adsp_listener_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_4(_handle, _mid, (uint32_t *)&ctx, + (uint32_t *)&offset, (char **)&bufs, + (uint32_t *)&bufsLen, + (uint32_t *)bufsLenReq); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/adsp_perf1_stub.c b/src/adsp_perf1_stub.c index cc36f315..7183736e 100644 --- a/src/adsp_perf1_stub.c +++ b/src/adsp_perf1_stub.c @@ -12,81 +12,88 @@ #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -94,175 +101,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_PERF1_SLIM_H #define _ADSP_PERF1_SLIM_H @@ -276,98 +280,203 @@ struct Interface { #endif static const Type types[2]; -static const Type types[2] = {{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1}}; -static const Parameter parameters[7] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[8] = {(&(parameters[5])),(&(parameters[6])),(&(parameters[6])),(&(parameters[0])),(&(parameters[1])),(&(parameters[4])),(&(parameters[3])),(&(parameters[2]))}; -static const Method methods[5] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[3])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[7])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[6])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x4,0x0,3,1,(&(parameterArrays[5])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x4,0x8,5,3,(&(parameterArrays[0])),0x4,0x4}}; -static const Method* const methodArrays[5] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[4])}; -static const char strings[66] = "get_usecs\0get_keys\0numKeys\0maxLen\0enable\0close\0open\0dst\0uri\0ix\0h\0"; -static const uint16_t methodStrings[13] = {10,14,27,19,47,56,63,0,52,34,60,41,63}; -static const uint16_t methodStringsArrays[5] = {4,11,9,7,0}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_perf1_slim) = {5,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Type types[2] + = { { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8 }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 } }; +static const Parameter parameters[7] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[8] + = { (&(parameters[5])), (&(parameters[6])), (&(parameters[6])), + (&(parameters[0])), (&(parameters[1])), (&(parameters[4])), + (&(parameters[3])), (&(parameters[2])) }; +static const Method methods[5] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[3])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[7])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[6])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x4, 0x0, 3, 1, + (&(parameterArrays[5])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x4, 0x8, 5, 3, + (&(parameterArrays[0])), 0x4, 0x4 } }; +static const Method *const methodArrays[5] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[3]), + &(methods[4]) }; +static const char strings[66] + = "get_usecs\0get_" + "keys\0numKeys\0maxLen\0enable\0close\0open\0dst\0uri\0ix\0h\0"; +static const uint16_t methodStrings[13] + = { 10, 14, 27, 19, 47, 56, 63, 0, 52, 34, 60, 41, 63 }; +static const uint16_t methodStringsArrays[5] = { 4, 11, 9, 7, 0 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_perf1_slim) + = { 5, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_PERF1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf1_open)(const char *uri, + remote_handle64 *h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf1_enable)(remote_handle64 _handle, int ix) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid, (uint32_t*)&ix); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf1_enable)(remote_handle64 _handle, + int ix) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid, (uint32_t *)&ix); } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, char* _rout0[1], uint32_t _rout0Len[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint32_t _primIn[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (8 * _rout0Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, char *_rout0[1], + uint32_t _rout0Len[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (8 * _rout0Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf1_get_usecs)(remote_handle64 _handle, int64_t* dst, int dstLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method_1(_handle, _mid, (char**)&dst, (uint32_t*)&dstLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf1_get_usecs)(remote_handle64 _handle, int64_t *dst, + int dstLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method_1(_handle, _mid, (char **)&dst, + (uint32_t *)&dstLen); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid, char* _rout0[1], uint32_t _rout0Len[1], uint32_t _rout1[1], uint32_t _rout2[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[1]= {0}; - uint32_t _primROut[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout1, 0, _primROut, 0, 4); - _COPY(_rout2, 0, _primROut, 4, 4); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid, char *_rout0[1], + uint32_t _rout0Len[1], uint32_t _rout1[1], uint32_t _rout2[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[1] = { 0 }; + uint32_t _primROut[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout1, 0, _primROut, 0, 4); + _COPY(_rout2, 0, _primROut, 4, 4); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf1_get_keys)(remote_handle64 _handle, char* keys, int keysLen, int* maxLen, int* numKeys) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_2(_handle, _mid, (char**)&keys, (uint32_t*)&keysLen, (uint32_t*)maxLen, (uint32_t*)numKeys); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf1_get_keys)(remote_handle64 _handle, char *keys, + int keysLen, int *maxLen, + int *numKeys) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_2(_handle, _mid, (char **)&keys, + (uint32_t *)&keysLen, (uint32_t *)maxLen, + (uint32_t *)numKeys); } #ifdef __cplusplus } diff --git a/src/adsp_perf_stub.c b/src/adsp_perf_stub.c index 94f2d01e..4b841943 100644 --- a/src/adsp_perf_stub.c +++ b/src/adsp_perf_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,158 +93,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -252,175 +266,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSP_PERF_SLIM_H #define _ADSP_PERF_SLIM_H @@ -434,66 +445,117 @@ struct Interface { #endif static const Type types[2]; -static const Type types[2] = {{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1}}; -static const Parameter parameters[4] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[5] = {(&(parameters[2])),(&(parameters[3])),(&(parameters[3])),(&(parameters[1])),(&(parameters[0]))}; -static const Method methods[3] = {{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[4])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x4,0x0,3,1,(&(parameterArrays[3])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x4,0x8,5,3,(&(parameterArrays[0])),0x4,0x4}}; -static const Method* const methodArrays[3] = {&(methods[0]),&(methods[1]),&(methods[2])}; -static const char strings[49] = "get_usecs\0get_keys\0numKeys\0maxLen\0enable\0dst\0ix\0"; -static const uint16_t methodStrings[8] = {10,14,27,19,0,41,34,45}; -static const uint16_t methodStringsArrays[3] = {6,4,0}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_perf_slim) = {3,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Type types[2] + = { { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8 }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 } }; +static const Parameter parameters[4] = { + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[5] + = { (&(parameters[2])), (&(parameters[3])), (&(parameters[3])), + (&(parameters[1])), (&(parameters[0])) }; +static const Method methods[3] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[4])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x4, 0x0, 3, 1, + (&(parameterArrays[3])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x4, 0x8, 5, 3, + (&(parameterArrays[0])), 0x4, 0x4 } }; +static const Method *const methodArrays[3] + = { &(methods[0]), &(methods[1]), &(methods[2]) }; +static const char strings[49] + = "get_usecs\0get_keys\0numKeys\0maxLen\0enable\0dst\0ix\0"; +static const uint16_t methodStrings[8] = { 10, 14, 27, 19, 0, 41, 34, 45 }; +static const uint16_t methodStringsArrays[3] = { 6, 4, 0 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adsp_perf_slim) + = { 3, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSP_PERF_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_adsp_perf_handle -#define _const_adsp_perf_handle ((remote_handle)-1) +#define _const_adsp_perf_handle ((remote_handle) - 1) #endif //_const_adsp_perf_handle -static void _adsp_perf_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_adsp_perf_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_adsp_perf_handle; - } +static void +_adsp_perf_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_adsp_perf_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_adsp_perf_handle; + } } -static int _adsp_perf_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_adsp_perf_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_adsp_perf_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_adsp_perf_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _adsp_perf_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_adsp_perf_handle, 0, sizeof(*ph), _adsp_perf_pls_ctor, "adsp_perf", _adsp_perf_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_adsp_perf_handle, 0, sizeof(*ph), _adsp_perf_pls_ctor, "adsp_perf", _adsp_perf_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_adsp_perf_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup((uint32_t)_adsp_perf_handle, 0, + sizeof(*ph), _adsp_perf_pls_ctor, + "adsp_perf", _adsp_perf_pls_dtor, + (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup((uint32_t)_adsp_perf_handle, 0, + sizeof(*ph), _adsp_perf_pls_ctor, + "adsp_perf", _adsp_perf_pls_dtor, + (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _adsp_perf_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _adsp_perf_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -501,31 +563,43 @@ uint32_t _adsp_perf_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32 #else #include "ntddk.h" #endif //_USRDLL -uint32_t _adsp_perf_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_adsp_perf_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _adsp_perf_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_adsp_perf_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _adsp_perf_handle(void) { - static remote_handle handle = _const_adsp_perf_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _adsp_perf_pls_ctor("adsp_perf", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adsp_perf_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _adsp_perf_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_adsp_perf_handle(void) +{ + static remote_handle handle = _const_adsp_perf_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr = _adsp_perf_pls_ctor("adsp_perf", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle)_adsp_perf_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _adsp_perf_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -534,99 +608,114 @@ __QAIC_STUB_EXPORT remote_handle _adsp_perf_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf_enable)(int ix) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _adsp_perf_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid, (uint32_t*)&ix); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf_enable)(int ix) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _adsp_perf_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid, (uint32_t *)&ix); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid, char* _rout0[1], uint32_t _rout0Len[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint32_t _primIn[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 0); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (8 * _rout0Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_1(remote_handle _handle, uint32_t _mid, char *_rout0[1], + uint32_t _rout0Len[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 0); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (8 * _rout0Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf_get_usecs)(int64_t* dst, int dstLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 1; - remote_handle _handle = _adsp_perf_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid, (char**)&dst, (uint32_t*)&dstLen); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf_get_usecs)(int64_t *dst, + int dstLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 1; + remote_handle _handle = _adsp_perf_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1(_handle, _mid, (char **)&dst, + (uint32_t *)&dstLen); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_2(remote_handle _handle, uint32_t _mid, char* _rout0[1], uint32_t _rout0Len[1], uint32_t _rout1[1], uint32_t _rout2[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[1]= {0}; - uint32_t _primROut[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _rout0Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout0[0]; - _praROut[0].buf.nLen = (1 * _rout0Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout1, 0, _primROut, 0, 4); - _COPY(_rout2, 0, _primROut, 4, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle _handle, uint32_t _mid, char *_rout0[1], + uint32_t _rout0Len[1], uint32_t _rout1[1], uint32_t _rout2[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[1] = { 0 }; + uint32_t _primROut[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _rout0Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout0[0]; + _praROut[0].buf.nLen = (1 * _rout0Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout1, 0, _primROut, 0, 4); + _COPY(_rout2, 0, _primROut, 4, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adsp_perf_get_keys)(char* keys, int keysLen, int* maxLen, int* numKeys) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - remote_handle _handle = _adsp_perf_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_2(_handle, _mid, (char**)&keys, (uint32_t*)&keysLen, (uint32_t*)maxLen, (uint32_t*)numKeys); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adsp_perf_get_keys)(char *keys, int keysLen, int *maxLen, + int *numKeys) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + remote_handle _handle = _adsp_perf_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_2(_handle, _mid, (char **)&keys, + (uint32_t *)&keysLen, (uint32_t *)maxLen, + (uint32_t *)numKeys); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/adspmsgd.c b/src/adspmsgd.c index f09ad249..67e8947f 100644 --- a/src/adspmsgd.c +++ b/src/adspmsgd.c @@ -5,10 +5,10 @@ #define VERIFY_PRINT_ERROR #endif -#include #include #include #include +#include #include "AEEStdErr.h" #include "HAP_farf.h" @@ -18,159 +18,178 @@ #include "rpcmem.h" #include "verify.h" - #define BUFFER_SIZE 256 #define DEFAULT_MEMORY_SIZE 256 * 1024 #include "fastrpc_common.h" - extern char *fastrpc_config_get_runtime_farf_file(void); msgd androidmsgd_handle[NUM_DOMAINS_EXTEND]; -void readMessage(int domain) { - int index = 0; - msgd *msgd_handle = &androidmsgd_handle[domain]; - unsigned long long lreadIndex = msgd_handle->readIndex; - memset(msgd_handle->message, 0, BUFFER_SIZE); - if (msgd_handle->readIndex >= msgd_handle->bufferSize) { - lreadIndex = msgd_handle->readIndex = 0; - } - while ((lreadIndex != *(msgd_handle->currentIndex)) && - (msgd_handle->headPtr[lreadIndex] == '\0')) { - lreadIndex++; - if (lreadIndex >= msgd_handle->bufferSize) { - lreadIndex = 0; - } - } - while (msgd_handle->headPtr[lreadIndex] != '\0') { - *(msgd_handle->message + index) = msgd_handle->headPtr[lreadIndex]; - index++; - lreadIndex++; - if (lreadIndex >= msgd_handle->bufferSize) { - lreadIndex = 0; - } - if (index >= BUFFER_SIZE) { - break; - } - } - if (*(msgd_handle->message + 0) != '\0') { - if (msgd_handle->log_file_fd != NULL) { - fputs(msgd_handle->message, msgd_handle->log_file_fd); - fputs("\n", msgd_handle->log_file_fd); - } - adspmsgd_log_message("%s", msgd_handle->message); - msgd_handle->readIndex = lreadIndex + 1; - } +void +readMessage(int domain) +{ + int index = 0; + msgd *msgd_handle = &androidmsgd_handle[domain]; + unsigned long long lreadIndex = msgd_handle->readIndex; + memset(msgd_handle->message, 0, BUFFER_SIZE); + if(msgd_handle->readIndex >= msgd_handle->bufferSize) { + lreadIndex = msgd_handle->readIndex = 0; + } + while((lreadIndex != *(msgd_handle->currentIndex)) + && (msgd_handle->headPtr[lreadIndex] == '\0')) { + lreadIndex++; + if(lreadIndex >= msgd_handle->bufferSize) { + lreadIndex = 0; + } + } + while(msgd_handle->headPtr[lreadIndex] != '\0') { + *(msgd_handle->message + index) + = msgd_handle->headPtr[lreadIndex]; + index++; + lreadIndex++; + if(lreadIndex >= msgd_handle->bufferSize) { + lreadIndex = 0; + } + if(index >= BUFFER_SIZE) { + break; + } + } + if(*(msgd_handle->message + 0) != '\0') { + if(msgd_handle->log_file_fd != NULL) { + fputs(msgd_handle->message, msgd_handle->log_file_fd); + fputs("\n", msgd_handle->log_file_fd); + } + adspmsgd_log_message("%s", msgd_handle->message); + msgd_handle->readIndex = lreadIndex + 1; + } } // function to flush messages to logcat -static void *adspmsgd_reader(void *arg) { - remote_handle64 handle = (remote_handle64)arg; - int domain = DEFAULT_DOMAIN_ID; - int nErr = AEE_SUCCESS; - uint64_t bytesToRead = 0; - msgd *msgd_handle; +static void * +adspmsgd_reader(void *arg) +{ + remote_handle64 handle = (remote_handle64)arg; + int domain = DEFAULT_DOMAIN_ID; + int nErr = AEE_SUCCESS; + uint64_t bytesToRead = 0; + msgd *msgd_handle; - FARF(RUNTIME_RPC_HIGH, "%s thread starting for domain %d\n", __func__, - domain); - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(handle, &domain))); - msgd_handle = &androidmsgd_handle[domain]; - msgd_handle->threadStop = 0; - while (!(msgd_handle->threadStop)) { - if (*(msgd_handle->currentIndex) == msgd_handle->readIndex) { - // wait till messages are ready from DSP - adspmsgd_adsp1_wait(handle, &bytesToRead); - } - readMessage(domain); - } - while (*(msgd_handle->currentIndex) != msgd_handle->readIndex) { - readMessage(domain); - } - msgd_handle->threadStop = -1; + FARF(RUNTIME_RPC_HIGH, "%s thread starting for domain %d\n", __func__, + domain); + VERIFY(AEE_SUCCESS + == (nErr = get_domain_from_handle(handle, &domain))); + msgd_handle = &androidmsgd_handle[domain]; + msgd_handle->threadStop = 0; + while(!(msgd_handle->threadStop)) { + if(*(msgd_handle->currentIndex) == msgd_handle->readIndex) { + // wait till messages are ready from DSP + adspmsgd_adsp1_wait(handle, &bytesToRead); + } + readMessage(domain); + } + while(*(msgd_handle->currentIndex) != msgd_handle->readIndex) { + readMessage(domain); + } + msgd_handle->threadStop = -1; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s thread of domain %d for handle 0x%lx " - "exiting (errno %s)\n", - nErr, __func__, domain, handle, strerror(errno)); - } else { - FARF(ALWAYS, "%s thread exiting for domain %d\n", __func__, domain); - } - return (void *)(uintptr_t)nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: %s thread of domain %d for handle 0x%lx " + "exiting (errno %s)\n", + nErr, __func__, domain, handle, strerror(errno)); + } else { + FARF(ALWAYS, "%s thread exiting for domain %d\n", __func__, + domain); + } + return (void *)(uintptr_t)nErr; } // function to create msgd shared buffer and logger thread to flush messages to // logcat -int adspmsgd_init(remote_handle64 handle, int filter) { - int nErr = AEE_SUCCESS; - int domain = DEFAULT_DOMAIN_ID; - uint64_t vapps = 0; - errno = 0; - char *filename = NULL; - msgd *msgd_handle = &androidmsgd_handle[DEFAULT_DOMAIN_ID]; - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(handle, &domain))); - msgd_handle = &androidmsgd_handle[domain]; - if (msgd_handle->thread_running) { - androidmsgd_handle[domain].threadStop = 1; - adspmsgd_adsp1_deinit(handle); - adspmsgd_stop(domain); - } - msgd_handle->message = NULL; - // If daemon already running, adspmsgd_adsp1_init3 already happened, vapps - // return NULL - VERIFY(AEE_SUCCESS == - (nErr = adspmsgd_adsp1_init3(handle, 0, RPCMEM_HEAP_DEFAULT, filter, - DEFAULT_MEMORY_SIZE, &vapps))); - VERIFYC(vapps, AEE_EBADITEM); - msgd_handle->headPtr = (char *)vapps; - msgd_handle->bufferSize = - DEFAULT_MEMORY_SIZE - sizeof(*(msgd_handle->currentIndex)); - msgd_handle->readIndex = 0; - msgd_handle->currentIndex = (unsigned int *)(vapps + msgd_handle->bufferSize); - VERIFYC(0 != (msgd_handle->message = calloc(1, BUFFER_SIZE)), AEE_ENOMEMORY); - VERIFY(AEE_SUCCESS == - (nErr = pthread_create(&(msgd_handle->msgreader_thread), NULL, - adspmsgd_reader, (void *)handle))); - msgd_handle->thread_running = true; - filename = fastrpc_config_get_runtime_farf_file(); - if (filename) { // Check "Runtime farf logs collection into a file" is enabled - msgd_handle->log_file_fd = fopen(filename, "w"); - if (msgd_handle->log_file_fd == NULL) { - VERIFY_EPRINTF("Error 0x%x: %s failed to collect runtime farf logs into " - "file %s with errno %s\n", - nErr, __func__, filename, strerror(errno)); - } - } +int +adspmsgd_init(remote_handle64 handle, int filter) +{ + int nErr = AEE_SUCCESS; + int domain = DEFAULT_DOMAIN_ID; + uint64_t vapps = 0; + errno = 0; + char *filename = NULL; + msgd *msgd_handle = &androidmsgd_handle[DEFAULT_DOMAIN_ID]; + VERIFY(AEE_SUCCESS + == (nErr = get_domain_from_handle(handle, &domain))); + msgd_handle = &androidmsgd_handle[domain]; + if(msgd_handle->thread_running) { + androidmsgd_handle[domain].threadStop = 1; + adspmsgd_adsp1_deinit(handle); + adspmsgd_stop(domain); + } + msgd_handle->message = NULL; + // If daemon already running, adspmsgd_adsp1_init3 already happened, + // vapps return NULL + VERIFY(AEE_SUCCESS + == (nErr = adspmsgd_adsp1_init3(handle, 0, RPCMEM_HEAP_DEFAULT, + filter, DEFAULT_MEMORY_SIZE, + &vapps))); + VERIFYC(vapps, AEE_EBADITEM); + msgd_handle->headPtr = (char *)vapps; + msgd_handle->bufferSize + = DEFAULT_MEMORY_SIZE - sizeof(*(msgd_handle->currentIndex)); + msgd_handle->readIndex = 0; + msgd_handle->currentIndex + = (unsigned int *)(vapps + msgd_handle->bufferSize); + VERIFYC(0 != (msgd_handle->message = calloc(1, BUFFER_SIZE)), + AEE_ENOMEMORY); + VERIFY( + AEE_SUCCESS + == (nErr = pthread_create(&(msgd_handle->msgreader_thread), NULL, + adspmsgd_reader, (void *)handle))); + msgd_handle->thread_running = true; + filename = fastrpc_config_get_runtime_farf_file(); + if(filename) { // Check "Runtime farf logs collection into a file" is + // enabled + msgd_handle->log_file_fd = fopen(filename, "w"); + if(msgd_handle->log_file_fd == NULL) { + VERIFY_EPRINTF("Error 0x%x: %s failed to collect " + "runtime farf logs into " + "file %s with errno %s\n", + nErr, __func__, filename, + strerror(errno)); + } + } bail: - if ((nErr != AEE_SUCCESS) && - (nErr != (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET))) { - VERIFY_EPRINTF( - "Error 0x%x: %s failed for handle 0x%lx filter %d with errno %s\n", - nErr, __func__, handle, filter, strerror(errno)); - if (msgd_handle->message) { - free(msgd_handle->message); - msgd_handle->message = NULL; - } - adspmsgd_adsp1_deinit(handle); - } - return nErr; + if((nErr != AEE_SUCCESS) + && (nErr != (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET))) { + VERIFY_EPRINTF("Error 0x%x: %s failed for handle 0x%lx filter " + "%d with errno %s\n", + nErr, __func__, handle, filter, + strerror(errno)); + if(msgd_handle->message) { + free(msgd_handle->message); + msgd_handle->message = NULL; + } + adspmsgd_adsp1_deinit(handle); + } + return nErr; } // function to stop logger thread -void adspmsgd_stop(int dom) { - if (!androidmsgd_handle[dom].thread_running) - return; - if (androidmsgd_handle[dom].threadStop == 0) { - androidmsgd_handle[dom].threadStop = 1; - while (androidmsgd_handle[dom].threadStop != -1) - ; - pthread_join(androidmsgd_handle[dom].msgreader_thread, NULL); - androidmsgd_handle[dom].msgreader_thread = 0; - androidmsgd_handle[dom].thread_running = false; - if (androidmsgd_handle[dom].message) { - free(androidmsgd_handle[dom].message); - androidmsgd_handle[dom].message = NULL; - } - if (androidmsgd_handle[dom].log_file_fd) { - fclose(androidmsgd_handle[dom].log_file_fd); - } - } +void +adspmsgd_stop(int dom) +{ + if(!androidmsgd_handle[dom].thread_running) + return; + if(androidmsgd_handle[dom].threadStop == 0) { + androidmsgd_handle[dom].threadStop = 1; + while(androidmsgd_handle[dom].threadStop != -1) + ; + pthread_join(androidmsgd_handle[dom].msgreader_thread, NULL); + androidmsgd_handle[dom].msgreader_thread = 0; + androidmsgd_handle[dom].thread_running = false; + if(androidmsgd_handle[dom].message) { + free(androidmsgd_handle[dom].message); + androidmsgd_handle[dom].message = NULL; + } + if(androidmsgd_handle[dom].log_file_fd) { + fclose(androidmsgd_handle[dom].log_file_fd); + } + } } diff --git a/src/adspmsgd_adsp1_stub.c b/src/adspmsgd_adsp1_stub.c index a8d6ccc7..64aa2da2 100644 --- a/src/adspmsgd_adsp1_stub.c +++ b/src/adspmsgd_adsp1_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,159 +93,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSPMSGD_ADSP1_SLIM_H #define _ADSPMSGD_ADSP1_SLIM_H @@ -434,81 +445,159 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Parameter parameters[7] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,3,0}}; -static const Parameter* const parameterArrays[8] = {(&(parameters[3])),(&(parameters[4])),(&(parameters[4])),(&(parameters[5])),(&(parameters[6])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[5] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[5])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[7])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x18,0x8,7,5,(&(parameterArrays[0])),0x8,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x1,0x0,0x0),0x0,0x8,1,1,(&(parameterArrays[4])),0x1,0x8}}; -static const Method* const methodArrays[6] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[2]),&(methods[3]),&(methods[4])}; -static const char strings[99] = "bytes_to_read\0buff_addr\0ion_flags\0buf_size\0filter\0heapid\0deinit\0init3\0init2\0close\0wait\0open\0uri\0h\0"; -static const uint16_t methodStrings[15] = {64,50,24,43,34,14,87,92,96,82,0,76,96,57,70}; -static const uint16_t methodStringsArrays[6] = {6,11,14,13,0,9}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_adsp1_slim) = {6,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Parameter parameters[7] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 3, 0 } +}; +static const Parameter *const parameterArrays[8] + = { (&(parameters[3])), (&(parameters[4])), (&(parameters[4])), + (&(parameters[5])), (&(parameters[6])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[5] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[5])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[7])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x18, 0x8, 7, 5, + (&(parameterArrays[0])), 0x8, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x1, 0x0, 0x0), 0x0, 0x8, 1, 1, + (&(parameterArrays[4])), 0x1, 0x8 } }; +static const Method *const methodArrays[6] + = { &(methods[0]), &(methods[1]), &(methods[2]), + &(methods[2]), &(methods[3]), &(methods[4]) }; +static const char strings[99] = "bytes_to_read\0buff_addr\0ion_flags\0buf_" + "size\0filter\0heapid\0deinit\0init3\0init2\0c" + "lose\0wait\0open\0uri\0h\0"; +static const uint16_t methodStrings[15] + = { 64, 50, 24, 43, 34, 14, 87, 92, 96, 82, 0, 76, 96, 57, 70 }; +static const uint16_t methodStringsArrays[6] = { 6, 11, 14, 13, 0, 9 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_adsp1_slim) + = { 6, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSPMSGD_ADSP1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_open)(const char *uri, + remote_handle64 *h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_init2)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_init2)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid); } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_deinit)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method(_handle, _mid); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_deinit)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method(_handle, _mid); } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], uint32_t _in2[1], uint64_t _in3[1], uint64_t _rout4[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint64_t _primIn[3]= {0}; - uint64_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2, 0, 4); - _COPY(_primIn, 16, _in3, 0, 8); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _COPY(_rout4, 0, _primROut, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], uint32_t _in2[1], uint64_t _in3[1], + uint64_t _rout4[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint64_t _primIn[3] = { 0 }; + uint64_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2, 0, 4); + _COPY(_primIn, 16, _in3, 0, 8); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _COPY(_rout4, 0, _primROut, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_init3)(remote_handle64 _handle, int heapid, uint32_t ion_flags, uint32_t filter, uint64_t buf_size, uint64_t* buff_addr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_1(_handle, _mid, (uint32_t*)&heapid, (uint32_t*)&ion_flags, (uint32_t*)&filter, (uint64_t*)&buf_size, (uint64_t*)buff_addr); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_init3)(remote_handle64 _handle, int heapid, + uint32_t ion_flags, uint32_t filter, + uint64_t buf_size, + uint64_t *buff_addr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_1(_handle, _mid, (uint32_t *)&heapid, + (uint32_t *)&ion_flags, (uint32_t *)&filter, + (uint64_t *)&buf_size, (uint64_t *)buff_addr); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid, uint64_t _rout0[1]) { - int _numIn[1] = {0}; - remote_arg _pra[1] = {0}; - uint64_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[(_numIn[0] + 0)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); - _COPY(_rout0, 0, _primROut, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid, uint64_t _rout0[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[1] = { 0 }; + uint64_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[(_numIn[0] + 0)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); + _COPY(_rout0, 0, _primROut, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp1_wait)(remote_handle64 _handle, uint64_t* bytes_to_read) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - return _stub_method_2(_handle, _mid, (uint64_t*)bytes_to_read); +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp1_wait)(remote_handle64 _handle, + uint64_t *bytes_to_read) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + return _stub_method_2(_handle, _mid, (uint64_t *)bytes_to_read); } #ifdef __cplusplus } diff --git a/src/adspmsgd_adsp_stub.c b/src/adspmsgd_adsp_stub.c index 712b91b3..54379a26 100644 --- a/src/adspmsgd_adsp_stub.c +++ b/src/adspmsgd_adsp_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,158 +93,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -252,175 +266,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSPMSGD_ADSP_SLIM_H #define _ADSPMSGD_ADSP_SLIM_H @@ -433,65 +444,101 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Parameter parameters[3] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[5] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[1])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[2] = {{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x10,0x4,5,5,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0}}; -static const Method* const methodArrays[3] = {&(methods[0]),&(methods[1]),&(methods[1])}; -static const char strings[57] = "buff_addr\0ion_flags\0buf_size\0deinit\0filter\0heapid\0init2\0"; -static const uint16_t methodStrings[8] = {31,43,10,36,20,0,29,50}; -static const uint16_t methodStringsArrays[3] = {0,7,6}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_adsp_slim) = {3,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Parameter parameters[3] = { + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[5] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[1])), + (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[2] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x10, 0x4, 5, 5, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 } }; +static const Method *const methodArrays[3] + = { &(methods[0]), &(methods[1]), &(methods[1]) }; +static const char strings[57] + = "buff_addr\0ion_flags\0buf_size\0deinit\0filter\0heapid\0init2\0"; +static const uint16_t methodStrings[8] = { 31, 43, 10, 36, 20, 0, 29, 50 }; +static const uint16_t methodStringsArrays[3] = { 0, 7, 6 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_adsp_slim) + = { 3, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSPMSGD_ADSP_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_adspmsgd_adsp_handle -#define _const_adspmsgd_adsp_handle ((remote_handle)-1) +#define _const_adspmsgd_adsp_handle ((remote_handle) - 1) #endif //_const_adspmsgd_adsp_handle -static void _adspmsgd_adsp_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_adspmsgd_adsp_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_adspmsgd_adsp_handle; - } +static void +_adspmsgd_adsp_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_adspmsgd_adsp_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_adspmsgd_adsp_handle; + } } -static int _adspmsgd_adsp_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_adspmsgd_adsp_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_adspmsgd_adsp_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_adspmsgd_adsp_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _adspmsgd_adsp_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", _adspmsgd_adsp_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", _adspmsgd_adsp_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_adspmsgd_adsp_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup( + (uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), + _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", + _adspmsgd_adsp_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup( + (uint32_t)_adspmsgd_adsp_handle, 0, sizeof(*ph), + _adspmsgd_adsp_pls_ctor, "adspmsgd_adsp", + _adspmsgd_adsp_pls_dtor, (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -499,31 +546,45 @@ uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, ui #else #include "ntddk.h" #endif //_USRDLL -uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_adspmsgd_adsp_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _adspmsgd_adsp_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_adspmsgd_adsp_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _adspmsgd_adsp_handle(void) { - static remote_handle handle = _const_adspmsgd_adsp_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _adspmsgd_adsp_pls_ctor("adspmsgd_adsp", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_adspmsgd_adsp_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _adspmsgd_adsp_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_adspmsgd_adsp_handle(void) +{ + static remote_handle handle = _const_adspmsgd_adsp_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr + = _adspmsgd_adsp_pls_ctor("adspmsgd_adsp", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle) + _adspmsgd_adsp_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _adspmsgd_adsp_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -532,72 +593,83 @@ __QAIC_STUB_EXPORT remote_handle _adspmsgd_adsp_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], uint32_t _in2[1], uint32_t _in3[1], uint32_t _rout4[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint32_t _primIn[4]= {0}; - uint32_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2, 0, 4); - _COPY(_primIn, 12, _in3, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _COPY(_rout4, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], uint32_t _in2[1], uint32_t _in3[1], + uint32_t _rout4[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[4] = { 0 }; + uint32_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2, 0, 4); + _COPY(_primIn, 12, _in3, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _COPY(_rout4, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_init)(int heapid, uint32_t ion_flags, uint32_t filter, uint32_t buf_size, int* buff_addr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _adspmsgd_adsp_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid, (uint32_t*)&heapid, (uint32_t*)&ion_flags, (uint32_t*)&filter, (uint32_t*)&buf_size, (uint32_t*)buff_addr); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp_init)(int heapid, uint32_t ion_flags, + uint32_t filter, uint32_t buf_size, + int *buff_addr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _adspmsgd_adsp_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid, (uint32_t *)&heapid, + (uint32_t *)&ion_flags, + (uint32_t *)&filter, (uint32_t *)&buf_size, + (uint32_t *)buff_addr); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_1(remote_handle _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_init2)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 1; - remote_handle _handle = _adspmsgd_adsp_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp_init2)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 1; + remote_handle _handle = _adspmsgd_adsp_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } -__QAIC_STUB_EXPORT int __QAIC_STUB(adspmsgd_adsp_deinit)(void) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - remote_handle _handle = _adspmsgd_adsp_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(adspmsgd_adsp_deinit)(void) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + remote_handle _handle = _adspmsgd_adsp_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1(_handle, _mid); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/adspmsgd_apps_skel.c b/src/adspmsgd_apps_skel.c index ca06527f..ce0c5592 100644 --- a/src/adspmsgd_apps_skel.c +++ b/src/adspmsgd_apps_skel.c @@ -26,7 +26,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -36,7 +36,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -94,158 +94,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _ADSPMSGD_APPS_SLIM_H #define _ADSPMSGD_APPS_SLIM_H @@ -435,51 +446,71 @@ struct Interface { #endif static const Type types[1]; -static const Type types[1] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1}}; -static const Parameter parameters[1] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0}}; -static const Parameter* const parameterArrays[1] = {(&(parameters[0]))}; -static const Method methods[1] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x4,0x0,2,1,(&(parameterArrays[0])),0x4,0x0}}; -static const Method* const methodArrays[1] = {&(methods[0])}; +static const Type types[1] + = { { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 } }; +static const Parameter parameters[1] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 } }; +static const Parameter *const parameterArrays[1] = { (&(parameters[0])) }; +static const Method methods[1] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x4, 0x0, 2, 1, + (&(parameterArrays[0])), 0x4, 0x0 } }; +static const Method *const methodArrays[1] = { &(methods[0]) }; static const char strings[24] = "log_message_buffer\0log\0"; -static const uint16_t methodStrings[2] = {19,0}; -static const uint16_t methodStringsArrays[1] = {0}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_apps_slim) = {1,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const uint16_t methodStrings[2] = { 19, 0 }; +static const uint16_t methodStringsArrays[1] = { 0 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(adspmsgd_apps_slim) + = { 1, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_ADSPMSGD_APPS_SLIM_H extern int adsp_mmap_fd_getinfo(int, uint32_t *); #ifdef __cplusplus extern "C" { #endif _ATTRIBUTE_VISIBILITY uint32_t adspmsgd_apps_skel_invoke_qaic_version = 10042; -static __inline int _skel_method(int (*_pfn)(const unsigned char*, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _TRY(_nErr, _pfn((const unsigned char*)*_in0, (int)*_in0Len)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method(int (*_pfn)(const unsigned char *, int), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _TRY(_nErr, _pfn((const unsigned char *)*_in0, (int)*_in0Len)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_SKEL_EXPORT int __QAIC_SKEL(adspmsgd_apps_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_SKEL_ATTRIBUTE { - switch(REMOTE_SCALARS_METHOD(_sc)) - { - case 0: - return _skel_method(__QAIC_IMPL(adspmsgd_apps_log), _sc, _pra); - } - return AEE_EUNSUPPORTED; +__QAIC_SKEL_EXPORT int +__QAIC_SKEL(adspmsgd_apps_skel_invoke)(uint32_t _sc, + remote_arg *_pra) __QAIC_SKEL_ATTRIBUTE +{ + switch(REMOTE_SCALARS_METHOD(_sc)) { + case 0: + return _skel_method(__QAIC_IMPL(adspmsgd_apps_log), _sc, _pra); + } + return AEE_EUNSUPPORTED; } #ifdef __cplusplus } diff --git a/src/adspmsgd_printf.c b/src/adspmsgd_printf.c index 787d9c1c..ef46b9d4 100644 --- a/src/adspmsgd_printf.c +++ b/src/adspmsgd_printf.c @@ -8,16 +8,16 @@ #define LOG_NODE_SIZE 256 #define LOG_FILENAME_SIZE 30 -#define LOG_MSG_SIZE \ - LOG_NODE_SIZE - LOG_FILENAME_SIZE - sizeof(enum adspmsgd_apps_Level) - \ - (2 * sizeof(unsigned short)) +#define LOG_MSG_SIZE \ + LOG_NODE_SIZE - LOG_FILENAME_SIZE - sizeof(enum adspmsgd_apps_Level) \ + - (2 * sizeof(unsigned short)) typedef struct __attribute__((packed)) { - enum adspmsgd_apps_Level level; - unsigned short line; - unsigned short thread_id; - char str[LOG_MSG_SIZE]; - char file[LOG_FILENAME_SIZE]; + enum adspmsgd_apps_Level level; + unsigned short line; + unsigned short thread_id; + char str[LOG_MSG_SIZE]; + char file[LOG_FILENAME_SIZE]; } LogNode; #if 0 @@ -41,18 +41,23 @@ static inline android_LogPriority convert_level_to_android_priority( } #endif -int adspmsgd_apps_log(const unsigned char *log_message_buffer, - int log_message_bufferLen) { - LogNode *logMessage = (LogNode *)log_message_buffer; - while ((log_message_bufferLen > 0) && (logMessage != NULL)) { - printf("adsprpc: %s:%d:0x%x:%s", logMessage->file, logMessage->line, - logMessage->thread_id, logMessage->str); - logMessage++; - log_message_bufferLen -= sizeof(LogNode); - }; +int +adspmsgd_apps_log(const unsigned char *log_message_buffer, + int log_message_bufferLen) +{ + LogNode *logMessage = (LogNode *)log_message_buffer; + while((log_message_bufferLen > 0) && (logMessage != NULL)) { + printf("adsprpc: %s:%d:0x%x:%s", logMessage->file, + logMessage->line, logMessage->thread_id, + logMessage->str); + logMessage++; + log_message_bufferLen -= sizeof(LogNode); + }; - return 0; + return 0; } -void adspmsgd_log_message(char *format, char *msg) { - printf("adsprpc:dsp: %s\n", msg); +void +adspmsgd_log_message(char *format, char *msg) +{ + printf("adsprpc:dsp: %s\n", msg); } diff --git a/src/apps_mem_imp.c b/src/apps_mem_imp.c index f288d0a6..767295c6 100644 --- a/src/apps_mem_imp.c +++ b/src/apps_mem_imp.c @@ -9,9 +9,10 @@ #include "AEEStdErr.h" #include "AEEstd.h" #include "apps_mem.h" +#include "fastrpc_apps_user.h" #include "fastrpc_cap.h" #include "fastrpc_common.h" -#include "fastrpc_apps_user.h" +#include "fastrpc_hash_table.h" #include "fastrpc_mem.h" #include "fastrpc_trace.h" #include "remote64.h" @@ -22,14 +23,13 @@ #include #include #include -#include "fastrpc_hash_table.h" #define ADSP_MMAP_HEAP_ADDR 4 #define ADSP_MMAP_REMOTE_HEAP_ADDR 8 #define ADSP_MMAP_ADD_PAGES 0x1000 #define ADSP_MMAP_ADD_PAGES_LLC 0x3000 -#define FASTRPC_ALLOC_HLOS_FD \ - 0x10000 /* Flag to allocate HLOS FD to be shared with DSP */ +#define FASTRPC_ALLOC_HLOS_FD \ + 0x10000 /* Flag to allocate HLOS FD to be shared with DSP */ typedef struct { QList mem_list; @@ -41,21 +41,25 @@ typedef struct { DECLARE_HASH_TABLE(apps_mem, apps_mem_info); struct mem_info { - QNode qn; - uint64_t vapps; - uint64_t vadsp; - int32_t size; - int32_t mapped; - uint32_t rflags; + QNode qn; + uint64_t vapps; + uint64_t vadsp; + int32_t size; + int32_t mapped; + uint32_t rflags; }; /* Delete and free all nodes in hash-table */ -void apps_mem_table_deinit(void) { +void +apps_mem_table_deinit(void) +{ HASH_TABLE_CLEANUP(apps_mem_info); } /* Initialize hash-table */ -int apps_mem_table_init(void) { +int +apps_mem_table_init(void) +{ HASH_TABLE_INIT(apps_mem_info); return 0; } @@ -68,334 +72,372 @@ I moved them into fastrpc_apps_user.c because there is no gurantee in the order of when constructors are called. */ -int apps_mem_init(int domain) { - int nErr = AEE_SUCCESS; - apps_mem_info *me = NULL; - - GET_HASH_NODE(apps_mem_info, domain, me); - if (!me) { - ALLOC_AND_ADD_NEW_NODE_TO_TABLE(apps_mem_info, domain, me); - } - QList_Ctor(&me->mem_list); - pthread_mutex_init(&me->mem_mut, 0); - me->init = 1; +int +apps_mem_init(int domain) +{ + int nErr = AEE_SUCCESS; + apps_mem_info *me = NULL; + + GET_HASH_NODE(apps_mem_info, domain, me); + if(!me) { + ALLOC_AND_ADD_NEW_NODE_TO_TABLE(apps_mem_info, domain, me); + } + QList_Ctor(&me->mem_list); + pthread_mutex_init(&me->mem_mut, 0); + me->init = 1; bail: return nErr; } -void apps_mem_deinit(int domain) { - QNode *pn; - apps_mem_info *me = NULL; - - GET_HASH_NODE(apps_mem_info, domain, me); - if (!me) { - FARF(ALWAYS, "Warning: %s: unable to find hash-node for domain %d", - __func__, domain); - return; - } - - if (me->init) { - while ((pn = QList_PopZ(&me->mem_list)) != NULL) { - struct mem_info *mfree = STD_RECOVER_REC(struct mem_info, qn, pn); - if (mfree->vapps) { - if (mfree->mapped) { - munmap((void *)(uintptr_t)mfree->vapps, mfree->size); - } else { - rpcmem_free_internal((void *)(uintptr_t)mfree->vapps); - } - } - free(mfree); - mfree = NULL; - } - pthread_mutex_destroy(&me->mem_mut); - me->init = 0; - } +void +apps_mem_deinit(int domain) +{ + QNode *pn; + apps_mem_info *me = NULL; + + GET_HASH_NODE(apps_mem_info, domain, me); + if(!me) { + FARF(ALWAYS, + "Warning: %s: unable to find hash-node for domain %d", + __func__, domain); + return; + } + + if(me->init) { + while((pn = QList_PopZ(&me->mem_list)) != NULL) { + struct mem_info *mfree + = STD_RECOVER_REC(struct mem_info, qn, pn); + if(mfree->vapps) { + if(mfree->mapped) { + munmap((void *)(uintptr_t)mfree->vapps, + mfree->size); + } else { + rpcmem_free_internal( + (void *)(uintptr_t)mfree->vapps); + } + } + free(mfree); + mfree = NULL; + } + pthread_mutex_destroy(&me->mem_mut); + me->init = 0; + } } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_mem_request_map64)(int heapid, uint32_t lflags, uint32_t rflags, - uint64_t vin, int64_t len, uint64_t *vapps, - uint64_t *vadsp) __QAIC_IMPL_ATTRIBUTE { - struct mem_info *minfo = 0; - int nErr = 0, unsigned_module = 0, ualloc_support = 0; - void *buf = 0; - uint64_t pbuf; - int fd = -1; - int domain = get_current_domain(); - apps_mem_info *me = NULL; - - GET_HASH_NODE(apps_mem_info, domain, me); - VERIFYC(me, AEE_ERESOURCENOTFOUND); - VERIFY(AEE_SUCCESS == - (nErr = get_unsigned_pd_attribute(domain, &unsigned_module))); - FASTRPC_ATRACE_BEGIN_L("%s called with rflag 0x%x, lflags 0x%x, len 0x%llx, " - "heapid %d and unsigned PD %d", - __func__, rflags, lflags, len, heapid, - unsigned_module); - if (unsigned_module) { - ualloc_support = is_userspace_allocation_supported(); - } - (void)vin; - VERIFYC(len >= 0, AEE_EBADPARM); - VERIFYC(NULL != (minfo = malloc(sizeof(*minfo))), AEE_ENOMEMORY); - QNode_CtorZ(&minfo->qn); - *vadsp = 0; - if (rflags == ADSP_MMAP_HEAP_ADDR || rflags == ADSP_MMAP_REMOTE_HEAP_ADDR) { - VERIFY(AEE_SUCCESS == (nErr = remote_mmap64_internal(-1, rflags, 0, len, - (uint64_t *)vadsp))); - *vapps = 0; - minfo->vapps = 0; - } else if (rflags == FASTRPC_ALLOC_HLOS_FD) { - VERIFYC(NULL != (buf = rpcmem_alloc_internal(heapid, lflags, len)), - AEE_ENORPCMEMORY); - VERIFYC(0 < (fd = rpcmem_to_fd_internal(buf)), AEE_EBADFD); - rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags); - /* Using FASTRPC_MAP_FD_DELAYED as only HLOS mapping is reqd at this point - */ - VERIFY(AEE_SUCCESS == (nErr = fastrpc_mmap(domain, fd, buf, 0, len, - FASTRPC_MAP_FD_DELAYED))); - pbuf = (uint64_t)buf; - *vapps = pbuf; - minfo->vapps = *vapps; - - /* HLOS fd will be used to map memory on DSP later if required. - * fd here will act as the unique key between the memory mapped - * on HLOS and DSP. - */ - *vadsp = (uint64_t)fd; - } else { - /* Memory for unsignedPD's user-heap will be allocated in userspace for - * security reasons. Memory for signedPD's user-heap will be allocated in - * kernel. - */ - if (((rflags != ADSP_MMAP_ADD_PAGES) && - (rflags != ADSP_MMAP_ADD_PAGES_LLC)) || - (((rflags == ADSP_MMAP_ADD_PAGES) || - (rflags == ADSP_MMAP_ADD_PAGES_LLC)) && - (unsigned_module && ualloc_support))) { - VERIFYC(NULL != (buf = rpcmem_alloc_internal(heapid, lflags, len)), - AEE_ENORPCMEMORY); - fd = rpcmem_to_fd_internal(buf); - VERIFYC(fd > 0, AEE_EBADPARM); - rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags); - } - VERIFY(AEE_SUCCESS == - (nErr = remote_mmap64_internal(fd, rflags, (uint64_t)buf, len, - (uint64_t *)vadsp))); - pbuf = (uint64_t)buf; - *vapps = pbuf; - minfo->vapps = *vapps; - } - minfo->vadsp = *vadsp; - minfo->size = len; - minfo->mapped = 0; - minfo->rflags = rflags; - pthread_mutex_lock(&me->mem_mut); - QList_AppendNode(&me->mem_list, &minfo->qn); - pthread_mutex_unlock(&me->mem_mut); +__QAIC_IMPL(apps_mem_request_map64)(int heapid, uint32_t lflags, + uint32_t rflags, uint64_t vin, int64_t len, + uint64_t *vapps, + uint64_t *vadsp) __QAIC_IMPL_ATTRIBUTE +{ + struct mem_info *minfo = 0; + int nErr = 0, unsigned_module = 0, ualloc_support = 0; + void *buf = 0; + uint64_t pbuf; + int fd = -1; + int domain = get_current_domain(); + apps_mem_info *me = NULL; + + GET_HASH_NODE(apps_mem_info, domain, me); + VERIFYC(me, AEE_ERESOURCENOTFOUND); + VERIFY( + AEE_SUCCESS + == (nErr = get_unsigned_pd_attribute(domain, &unsigned_module))); + FASTRPC_ATRACE_BEGIN_L( + "%s called with rflag 0x%x, lflags 0x%x, len 0x%llx, " + "heapid %d and unsigned PD %d", + __func__, rflags, lflags, len, heapid, unsigned_module); + if(unsigned_module) { + ualloc_support = is_userspace_allocation_supported(); + } + (void)vin; + VERIFYC(len >= 0, AEE_EBADPARM); + VERIFYC(NULL != (minfo = malloc(sizeof(*minfo))), AEE_ENOMEMORY); + QNode_CtorZ(&minfo->qn); + *vadsp = 0; + if(rflags == ADSP_MMAP_HEAP_ADDR + || rflags == ADSP_MMAP_REMOTE_HEAP_ADDR) { + VERIFY(AEE_SUCCESS + == (nErr = remote_mmap64_internal(-1, rflags, 0, len, + (uint64_t *)vadsp))); + *vapps = 0; + minfo->vapps = 0; + } else if(rflags == FASTRPC_ALLOC_HLOS_FD) { + VERIFYC( + NULL != (buf = rpcmem_alloc_internal(heapid, lflags, len)), + AEE_ENORPCMEMORY); + VERIFYC(0 < (fd = rpcmem_to_fd_internal(buf)), AEE_EBADFD); + rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags); + /* Using FASTRPC_MAP_FD_DELAYED as only HLOS mapping is reqd at + * this point + */ + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_mmap(domain, fd, buf, 0, len, + FASTRPC_MAP_FD_DELAYED))); + pbuf = (uint64_t)buf; + *vapps = pbuf; + minfo->vapps = *vapps; + + /* HLOS fd will be used to map memory on DSP later if required. + * fd here will act as the unique key between the memory mapped + * on HLOS and DSP. + */ + *vadsp = (uint64_t)fd; + } else { + /* Memory for unsignedPD's user-heap will be allocated in + * userspace for security reasons. Memory for signedPD's + * user-heap will be allocated in kernel. + */ + if(((rflags != ADSP_MMAP_ADD_PAGES) + && (rflags != ADSP_MMAP_ADD_PAGES_LLC)) + || (((rflags == ADSP_MMAP_ADD_PAGES) + || (rflags == ADSP_MMAP_ADD_PAGES_LLC)) + && (unsigned_module && ualloc_support))) { + VERIFYC(NULL + != (buf = rpcmem_alloc_internal( + heapid, lflags, len)), + AEE_ENORPCMEMORY); + fd = rpcmem_to_fd_internal(buf); + VERIFYC(fd > 0, AEE_EBADPARM); + rpcmem_set_dmabuf_name("dsp", fd, heapid, buf, lflags); + } + VERIFY(AEE_SUCCESS + == (nErr + = remote_mmap64_internal(fd, rflags, (uint64_t)buf, + len, (uint64_t *)vadsp))); + pbuf = (uint64_t)buf; + *vapps = pbuf; + minfo->vapps = *vapps; + } + minfo->vadsp = *vadsp; + minfo->size = len; + minfo->mapped = 0; + minfo->rflags = rflags; + pthread_mutex_lock(&me->mem_mut); + QList_AppendNode(&me->mem_list, &minfo->qn); + pthread_mutex_unlock(&me->mem_mut); bail: - if (nErr) { - if (buf) { - rpcmem_free_internal(buf); - buf = NULL; - } - if (minfo) { - free(minfo); - minfo = NULL; - } - VERIFY_EPRINTF("Error 0x%x: apps_mem_request_mmap64 failed for fd 0x%x of " - "size %lld (lflags 0x%x, rflags 0x%x)\n", - nErr, fd, len, lflags, rflags); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr) { + if(buf) { + rpcmem_free_internal(buf); + buf = NULL; + } + if(minfo) { + free(minfo); + minfo = NULL; + } + VERIFY_EPRINTF("Error 0x%x: apps_mem_request_mmap64 failed " + "for fd 0x%x of " + "size %lld (lflags 0x%x, rflags 0x%x)\n", + nErr, fd, len, lflags, rflags); + } + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_request_map)(int heapid, uint32_t lflags, uint32_t rflags, uint32_t vin, int32_t len, uint32_t *vapps, - uint32_t *vadsp) __QAIC_IMPL_ATTRIBUTE { - uint64_t vin1, vapps1, vadsp1; - int64_t len1; - int nErr = AEE_SUCCESS; - vin1 = (uint64_t)vin; - len1 = (int64_t)len; - nErr = apps_mem_request_map64(heapid, lflags, rflags, vin1, len1, &vapps1, - &vadsp1); - *vapps = (uint32_t)vapps1; - *vadsp = (uint32_t)vadsp1; - return nErr; + uint32_t *vadsp) __QAIC_IMPL_ATTRIBUTE +{ + uint64_t vin1, vapps1, vadsp1; + int64_t len1; + int nErr = AEE_SUCCESS; + vin1 = (uint64_t)vin; + len1 = (int64_t)len; + nErr = apps_mem_request_map64(heapid, lflags, rflags, vin1, len1, + &vapps1, &vadsp1); + *vapps = (uint32_t)vapps1; + *vadsp = (uint32_t)vadsp1; + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_request_unmap64)(uint64_t vadsp, - int64_t len) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS, fd = -1; - struct mem_info *minfo, *mfree = 0; - QNode *pn, *pnn; - int domain = get_current_domain(); - apps_mem_info *me = NULL; - - FASTRPC_ATRACE_BEGIN_L("%s called with vadsp 0x%llx, len 0x%llx", __func__, - vadsp, len); - GET_HASH_NODE(apps_mem_info, domain, me); - VERIFYC(me, AEE_ERESOURCENOTFOUND); - - pthread_mutex_lock(&me->mem_mut); - QLIST_NEXTSAFE_FOR_ALL(&me->mem_list, pn, pnn) { - minfo = STD_RECOVER_REC(struct mem_info, qn, pn); - if (minfo->vadsp == vadsp) { - mfree = minfo; - break; - } - } - pthread_mutex_unlock(&me->mem_mut); - - /* If apps_mem_request_map64 was called with flag FASTRPC_ALLOC_HLOS_FD, - * use fastrpc_munmap else use remote_munmap64 to unmap. - */ - if(mfree && mfree->rflags == FASTRPC_ALLOC_HLOS_FD) { - fd = (int)vadsp; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_munmap(domain, fd, 0, len))); - } else if (mfree || fastrpc_get_pd_type(domain) == AUDIO_STATICPD){ - /* - * Map info not available for Audio static PD after daemon reconnect, - * So continue to unmap to avoid driver global maps leak. - */ - VERIFY(AEE_SUCCESS == (nErr = remote_munmap64((uint64_t)vadsp, len))); - if (!mfree) - goto bail; - } - VERIFYC(mfree, AEE_ENOSUCHMAP); - - /* Dequeue done after unmap to prevent leaks in case unmap fails */ - pthread_mutex_lock(&me->mem_mut); - QNode_Dequeue(&mfree->qn); - pthread_mutex_unlock(&me->mem_mut); - - if (mfree->mapped) { - munmap((void *)(uintptr_t)mfree->vapps, mfree->size); - } else { - if (mfree->vapps) - rpcmem_free_internal((void *)(uintptr_t)mfree->vapps); - } - free(mfree); - mfree = NULL; + int64_t len) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS, fd = -1; + struct mem_info *minfo, *mfree = 0; + QNode *pn, *pnn; + int domain = get_current_domain(); + apps_mem_info *me = NULL; + + FASTRPC_ATRACE_BEGIN_L("%s called with vadsp 0x%llx, len 0x%llx", + __func__, vadsp, len); + GET_HASH_NODE(apps_mem_info, domain, me); + VERIFYC(me, AEE_ERESOURCENOTFOUND); + + pthread_mutex_lock(&me->mem_mut); + QLIST_NEXTSAFE_FOR_ALL(&me->mem_list, pn, pnn) + { + minfo = STD_RECOVER_REC(struct mem_info, qn, pn); + if(minfo->vadsp == vadsp) { + mfree = minfo; + break; + } + } + pthread_mutex_unlock(&me->mem_mut); + + /* If apps_mem_request_map64 was called with flag + * FASTRPC_ALLOC_HLOS_FD, use fastrpc_munmap else use remote_munmap64 + * to unmap. + */ + if(mfree && mfree->rflags == FASTRPC_ALLOC_HLOS_FD) { + fd = (int)vadsp; + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_munmap(domain, fd, 0, len))); + } else if(mfree || fastrpc_get_pd_type(domain) == AUDIO_STATICPD) { + /* + * Map info not available for Audio static PD after daemon + * reconnect, So continue to unmap to avoid driver global maps + * leak. + */ + VERIFY(AEE_SUCCESS + == (nErr = remote_munmap64((uint64_t)vadsp, len))); + if(!mfree) + goto bail; + } + VERIFYC(mfree, AEE_ENOSUCHMAP); + + /* Dequeue done after unmap to prevent leaks in case unmap fails */ + pthread_mutex_lock(&me->mem_mut); + QNode_Dequeue(&mfree->qn); + pthread_mutex_unlock(&me->mem_mut); + + if(mfree->mapped) { + munmap((void *)(uintptr_t)mfree->vapps, mfree->size); + } else { + if(mfree->vapps) + rpcmem_free_internal((void *)(uintptr_t)mfree->vapps); + } + free(mfree); + mfree = NULL; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: apps_mem_request_unmap64 failed for size %lld " - "(vadsp 0x%llx)\n", - nErr, len, vadsp); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: apps_mem_request_unmap64 failed " + "for size %lld " + "(vadsp 0x%llx)\n", + nErr, len, vadsp); + } + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_request_unmap)(uint32_t vadsp, - int32_t len) __QAIC_IMPL_ATTRIBUTE { - uint64_t vadsp1 = (uint64_t)vadsp; - int64_t len1 = (int64_t)len; - int nErr = apps_mem_request_unmap64(vadsp1, len1); - return nErr; + int32_t len) __QAIC_IMPL_ATTRIBUTE +{ + uint64_t vadsp1 = (uint64_t)vadsp; + int64_t len1 = (int64_t)len; + int nErr = apps_mem_request_unmap64(vadsp1, len1); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_share_map)(int fd, int size, uint64_t *vapps, - uint64_t *vadsp) __QAIC_IMPL_ATTRIBUTE { - struct mem_info *minfo = 0; - int nErr = AEE_SUCCESS; - void *buf = 0; - uint64_t pbuf; - int domain = get_current_domain(); - apps_mem_info *me = NULL; - - GET_HASH_NODE(apps_mem_info, domain, me); - VERIFYC(me, AEE_ERESOURCENOTFOUND); - VERIFYC(fd > 0, AEE_EBADPARM); - VERIFYC(0 != (minfo = malloc(sizeof(*minfo))), AEE_ENOMEMORY); - QNode_CtorZ(&minfo->qn); - *vadsp = 0; - VERIFYC(MAP_FAILED != (buf = (void *)mmap(NULL, size, PROT_READ | PROT_WRITE, - MAP_SHARED, fd, 0)), - AEE_ERPC); - VERIFY(AEE_SUCCESS == (nErr = remote_mmap64_internal( - fd, 0, (uint64_t)buf, size, (uint64_t *)vadsp))); - pbuf = (uint64_t)buf; - *vapps = pbuf; - minfo->vapps = *vapps; - minfo->vadsp = *vadsp; - minfo->size = size; - minfo->mapped = 1; - pthread_mutex_lock(&me->mem_mut); - QList_AppendNode(&me->mem_list, &minfo->qn); - pthread_mutex_unlock(&me->mem_mut); + uint64_t *vadsp) __QAIC_IMPL_ATTRIBUTE +{ + struct mem_info *minfo = 0; + int nErr = AEE_SUCCESS; + void *buf = 0; + uint64_t pbuf; + int domain = get_current_domain(); + apps_mem_info *me = NULL; + + GET_HASH_NODE(apps_mem_info, domain, me); + VERIFYC(me, AEE_ERESOURCENOTFOUND); + VERIFYC(fd > 0, AEE_EBADPARM); + VERIFYC(0 != (minfo = malloc(sizeof(*minfo))), AEE_ENOMEMORY); + QNode_CtorZ(&minfo->qn); + *vadsp = 0; + VERIFYC(MAP_FAILED + != (buf = (void *)mmap(NULL, size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0)), + AEE_ERPC); + VERIFY(AEE_SUCCESS + == (nErr = remote_mmap64_internal(fd, 0, (uint64_t)buf, size, + (uint64_t *)vadsp))); + pbuf = (uint64_t)buf; + *vapps = pbuf; + minfo->vapps = *vapps; + minfo->vadsp = *vadsp; + minfo->size = size; + minfo->mapped = 1; + pthread_mutex_lock(&me->mem_mut); + QList_AppendNode(&me->mem_list, &minfo->qn); + pthread_mutex_unlock(&me->mem_mut); bail: - if (nErr) { - if (buf) { - munmap(buf, size); - } - if (minfo) { - free(minfo); - minfo = NULL; - } - VERIFY_EPRINTF( - "Error 0x%x: apps_mem_share_map failed for fd 0x%x of size %d\n", nErr, - fd, size); - } - return nErr; + if(nErr) { + if(buf) { + munmap(buf, size); + } + if(minfo) { + free(minfo); + minfo = NULL; + } + VERIFY_EPRINTF("Error 0x%x: apps_mem_share_map failed for fd " + "0x%x of size %d\n", + nErr, fd, size); + } + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_share_unmap)(uint64_t vadsp, int size) - __QAIC_IMPL_ATTRIBUTE { - int64_t len1 = (int64_t)size; - int nErr = AEE_SUCCESS; - nErr = apps_mem_request_unmap64(vadsp, len1); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF( - "Error 0x%x: apps_mem_share_unmap failed size %d (vadsp 0x%llx)\n", - nErr, size, vadsp); - } - return nErr; +__QAIC_IMPL_EXPORT int +__QAIC_IMPL(apps_mem_share_unmap)(uint64_t vadsp, + int size) __QAIC_IMPL_ATTRIBUTE +{ + int64_t len1 = (int64_t)size; + int nErr = AEE_SUCCESS; + nErr = apps_mem_request_unmap64(vadsp, len1); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: apps_mem_share_unmap failed size " + "%d (vadsp 0x%llx)\n", + nErr, size, vadsp); + } + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_mem_dma_handle_map)(int fd, int offset, - int size) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - uint32_t len = 0, attr = 0; - int flags = FASTRPC_MAP_FD_DELAYED; - int domain = get_current_domain(); - - VERIFYC(fd > 0 && size > 0, AEE_EBADPARM); - unregister_dma_handle(fd, &len, &attr); - // If attr is FASTRPC_ATTR_NOMAP, use flags FASTRPC_MAP_FD_NOMAP to skip CPU - // mapping - if (attr == FASTRPC_ATTR_NOMAP) { - VERIFYC(size <= (int)len, AEE_EBADPARM); - flags = FASTRPC_MAP_FD_NOMAP; - } - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_mmap(domain, fd, 0, offset, size, flags))); + int size) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + uint32_t len = 0, attr = 0; + int flags = FASTRPC_MAP_FD_DELAYED; + int domain = get_current_domain(); + + VERIFYC(fd > 0 && size > 0, AEE_EBADPARM); + unregister_dma_handle(fd, &len, &attr); + // If attr is FASTRPC_ATTR_NOMAP, use flags FASTRPC_MAP_FD_NOMAP to + // skip CPU mapping + if(attr == FASTRPC_ATTR_NOMAP) { + VERIFYC(size <= (int)len, AEE_EBADPARM); + flags = FASTRPC_MAP_FD_NOMAP; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_mmap(domain, fd, 0, offset, size, flags))); bail: - if (nErr) { - VERIFY_EPRINTF("Error 0x%x: %s failed for fd 0x%x of size %d\n", nErr, - __func__, fd, size); - } - return nErr; + if(nErr) { + VERIFY_EPRINTF( + "Error 0x%x: %s failed for fd 0x%x of size %d\n", nErr, + __func__, fd, size); + } + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_mem_dma_handle_unmap)(int fd, int size) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - int domain = get_current_domain(); +__QAIC_IMPL(apps_mem_dma_handle_unmap)(int fd, int size) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + int domain = get_current_domain(); - VERIFYC(fd > 0 && size > 0, AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_munmap(domain, fd, 0, size))); + VERIFYC(fd > 0 && size > 0, AEE_EBADPARM); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_munmap(domain, fd, 0, size))); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s failed for fd 0x%x of size %d\n", nErr, - __func__, fd, size); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: %s failed for fd 0x%x of size %d\n", nErr, + __func__, fd, size); + } + return nErr; } diff --git a/src/apps_mem_skel.c b/src/apps_mem_skel.c index 25a29acb..d9817e18 100644 --- a/src/apps_mem_skel.c +++ b/src/apps_mem_skel.c @@ -26,7 +26,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -36,7 +36,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -94,158 +94,172 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _APPS_MEM_SLIM_H #define _APPS_MEM_SLIM_H @@ -434,242 +445,346 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Parameter parameters[7] = {{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,3,0}}; -static const Parameter* const parameterArrays[23] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[1])),(&(parameters[4])),(&(parameters[5])),(&(parameters[6])),(&(parameters[6])),(&(parameters[0])),(&(parameters[1])),(&(parameters[1])),(&(parameters[1])),(&(parameters[2])),(&(parameters[3])),(&(parameters[3])),(&(parameters[0])),(&(parameters[0])),(&(parameters[6])),(&(parameters[6])),(&(parameters[0])),(&(parameters[0])),(&(parameters[0])),(&(parameters[4])),(&(parameters[0]))}; -static const Method methods[8] = {{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x14,0x8,7,7,(&(parameterArrays[7])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[10])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x20,0x10,11,7,(&(parameterArrays[0])),0x8,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x10,0x0,6,2,(&(parameterArrays[3])),0x8,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x8,0x10,4,4,(&(parameterArrays[14])),0x4,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0xc,0x0,4,2,(&(parameterArrays[21])),0x8,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0xc,0x0,3,3,(&(parameterArrays[18])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[14])),0x4,0x0}}; -static const Method* const methodArrays[8] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[5]),&(methods[6]),&(methods[7])}; -static const char strings[170] = "dma_handle_unmap\0request_unmap64\0dma_handle_map\0request_map64\0request_unmap\0share_unmap\0request_map\0share_map\0ion_flags\0offset\0rflags\0heapid\0vadsp\0vapps\0size\0len\0vin\0fd\0"; -static const uint16_t methodStrings[37] = {48,134,110,127,162,158,147,141,88,134,110,127,162,158,147,141,100,166,153,147,141,33,166,120,153,0,166,153,76,141,153,17,141,158,62,141,158}; -static const uint16_t methodStringsArrays[8] = {8,34,0,31,16,28,21,25}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_mem_slim) = {8,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Parameter parameters[7] = { + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 3, 0 } +}; +static const Parameter *const parameterArrays[23] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[1])), + (&(parameters[4])), (&(parameters[5])), (&(parameters[6])), + (&(parameters[6])), (&(parameters[0])), (&(parameters[1])), + (&(parameters[1])), (&(parameters[1])), (&(parameters[2])), + (&(parameters[3])), (&(parameters[3])), (&(parameters[0])), + (&(parameters[0])), (&(parameters[6])), (&(parameters[6])), + (&(parameters[0])), (&(parameters[0])), (&(parameters[0])), + (&(parameters[4])), (&(parameters[0])) }; +static const Method methods[8] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x14, 0x8, 7, 7, + (&(parameterArrays[7])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[10])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x20, 0x10, 11, 7, + (&(parameterArrays[0])), 0x8, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x10, 0x0, 6, 2, + (&(parameterArrays[3])), 0x8, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x8, 0x10, 4, 4, + (&(parameterArrays[14])), 0x4, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0xc, 0x0, 4, 2, + (&(parameterArrays[21])), 0x8, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0xc, 0x0, 3, 3, + (&(parameterArrays[18])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[14])), 0x4, 0x0 } }; +static const Method *const methodArrays[8] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[3]), + &(methods[4]), &(methods[5]), &(methods[6]), &(methods[7]) }; +static const char strings[170] + = "dma_handle_unmap\0request_unmap64\0dma_handle_map\0request_" + "map64\0request_unmap\0share_unmap\0request_map\0share_map\0ion_" + "flags\0offset\0rflags\0heapid\0vadsp\0vapps\0size\0len\0vin\0fd\0"; +static const uint16_t methodStrings[37] + = { 48, 134, 110, 127, 162, 158, 147, 141, 88, 134, 110, 127, 162, + 158, 147, 141, 100, 166, 153, 147, 141, 33, 166, 120, 153, 0, + 166, 153, 76, 141, 153, 17, 141, 158, 62, 141, 158 }; +static const uint16_t methodStringsArrays[8] + = { 8, 34, 0, 31, 16, 28, 21, 25 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_mem_slim) + = { 8, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_APPS_MEM_SLIM_H extern int adsp_mmap_fd_getinfo(int, uint32_t *); #ifdef __cplusplus extern "C" { #endif _ATTRIBUTE_VISIBILITY uint32_t apps_mem_skel_invoke_qaic_version = 10042; -static __inline int _skel_method(int (*_pfn)(int, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _TRY(_nErr, _pfn((int)*_in0, (int)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method(int (*_pfn)(int, int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _TRY(_nErr, _pfn((int)*_in0, (int)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_1(int (*_pfn)(int, int, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t _in2[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _COPY(_in2, 0, _primIn, 8, 4); - _TRY(_nErr, _pfn((int)*_in0, (int)*_in1, (int)*_in2)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_1(int (*_pfn)(int, int, int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _COPY(_in2, 0, _primIn, 8, 4); + _TRY(_nErr, _pfn((int)*_in0, (int)*_in1, (int)*_in2)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_2(int (*_pfn)(uint64_t, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint64_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint64_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 8); - _COPY(_in1, 0, _primIn, 8, 4); - _TRY(_nErr, _pfn((uint64_t)*_in0, (int)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_2(int (*_pfn)(uint64_t, int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint64_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint64_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 8); + _COPY(_in1, 0, _primIn, 8, 4); + _TRY(_nErr, _pfn((uint64_t)*_in0, (int)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_3(int (*_pfn)(int, int, uint64_t*, uint64_t*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint64_t _rout2[1] = {0}; - uint64_t _rout3[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint64_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 16); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _TRY(_nErr, _pfn((int)*_in0, (int)*_in1, (uint64_t*)_rout2, (uint64_t*)_rout3)); - _COPY(_primROut, 0, _rout2, 0, 8); - _COPY(_primROut, 8, _rout3, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_3(int (*_pfn)(int, int, uint64_t *, uint64_t *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint64_t _rout2[1] = { 0 }; + uint64_t _rout3[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint64_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 16); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _TRY(_nErr, _pfn((int)*_in0, (int)*_in1, (uint64_t *)_rout2, + (uint64_t *)_rout3)); + _COPY(_primROut, 0, _rout2, 0, 8); + _COPY(_primROut, 8, _rout3, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_4(int (*_pfn)(uint64_t, int64_t), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint64_t _in0[1] = {0}; - uint64_t _in1[1] = {0}; - uint64_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 16); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 8); - _COPY(_in1, 0, _primIn, 8, 8); - _TRY(_nErr, _pfn((uint64_t)*_in0, (int64_t)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_4(int (*_pfn)(uint64_t, int64_t), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint64_t _in0[1] = { 0 }; + uint64_t _in1[1] = { 0 }; + uint64_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 16); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 8); + _COPY(_in1, 0, _primIn, 8, 8); + _TRY(_nErr, _pfn((uint64_t)*_in0, (int64_t)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_5(int (*_pfn)(int, uint32_t, uint32_t, uint64_t, int64_t, uint64_t*, uint64_t*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t _in2[1] = {0}; - uint64_t _in3[1] = {0}; - uint64_t _in4[1] = {0}; - uint64_t _rout5[1] = {0}; - uint64_t _rout6[1] = {0}; - uint64_t* _primIn= 0; - int _numIn[1] = {0}; - uint64_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 32); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 16); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _COPY(_in2, 0, _primIn, 8, 4); - _COPY(_in3, 0, _primIn, 16, 8); - _COPY(_in4, 0, _primIn, 24, 8); - _TRY(_nErr, _pfn((int)*_in0, (uint32_t)*_in1, (uint32_t)*_in2, (uint64_t)*_in3, (int64_t)*_in4, (uint64_t*)_rout5, (uint64_t*)_rout6)); - _COPY(_primROut, 0, _rout5, 0, 8); - _COPY(_primROut, 8, _rout6, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_5(int (*_pfn)(int, uint32_t, uint32_t, uint64_t, int64_t, + uint64_t *, uint64_t *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint64_t _in3[1] = { 0 }; + uint64_t _in4[1] = { 0 }; + uint64_t _rout5[1] = { 0 }; + uint64_t _rout6[1] = { 0 }; + uint64_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint64_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 32); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 16); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _COPY(_in2, 0, _primIn, 8, 4); + _COPY(_in3, 0, _primIn, 16, 8); + _COPY(_in4, 0, _primIn, 24, 8); + _TRY(_nErr, _pfn((int)*_in0, (uint32_t)*_in1, (uint32_t)*_in2, + (uint64_t)*_in3, (int64_t)*_in4, (uint64_t *)_rout5, + (uint64_t *)_rout6)); + _COPY(_primROut, 0, _rout5, 0, 8); + _COPY(_primROut, 8, _rout6, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_6(int (*_pfn)(uint32_t, int32_t), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _TRY(_nErr, _pfn((uint32_t)*_in0, (int32_t)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_6(int (*_pfn)(uint32_t, int32_t), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _TRY(_nErr, _pfn((uint32_t)*_in0, (int32_t)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_7(int (*_pfn)(int, uint32_t, uint32_t, uint32_t, int32_t, uint32_t*, uint32_t*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t _in2[1] = {0}; - uint32_t _in3[1] = {0}; - uint32_t _in4[1] = {0}; - uint32_t _rout5[1] = {0}; - uint32_t _rout6[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 20); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _COPY(_in2, 0, _primIn, 8, 4); - _COPY(_in3, 0, _primIn, 12, 4); - _COPY(_in4, 0, _primIn, 16, 4); - _TRY(_nErr, _pfn((int)*_in0, (uint32_t)*_in1, (uint32_t)*_in2, (uint32_t)*_in3, (int32_t)*_in4, (uint32_t*)_rout5, (uint32_t*)_rout6)); - _COPY(_primROut, 0, _rout5, 0, 4); - _COPY(_primROut, 4, _rout6, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_7(int (*_pfn)(int, uint32_t, uint32_t, uint32_t, int32_t, + uint32_t *, uint32_t *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint32_t _in3[1] = { 0 }; + uint32_t _in4[1] = { 0 }; + uint32_t _rout5[1] = { 0 }; + uint32_t _rout6[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 20); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _COPY(_in2, 0, _primIn, 8, 4); + _COPY(_in3, 0, _primIn, 12, 4); + _COPY(_in4, 0, _primIn, 16, 4); + _TRY(_nErr, _pfn((int)*_in0, (uint32_t)*_in1, (uint32_t)*_in2, + (uint32_t)*_in3, (int32_t)*_in4, (uint32_t *)_rout5, + (uint32_t *)_rout6)); + _COPY(_primROut, 0, _rout5, 0, 4); + _COPY(_primROut, 4, _rout6, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_SKEL_EXPORT int __QAIC_SKEL(apps_mem_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_SKEL_ATTRIBUTE { - switch(REMOTE_SCALARS_METHOD(_sc)) - { - case 0: - return _skel_method_7(__QAIC_IMPL(apps_mem_request_map), _sc, _pra); - case 1: - return _skel_method_6(__QAIC_IMPL(apps_mem_request_unmap), _sc, _pra); - case 2: - return _skel_method_5(__QAIC_IMPL(apps_mem_request_map64), _sc, _pra); - case 3: - return _skel_method_4(__QAIC_IMPL(apps_mem_request_unmap64), _sc, _pra); - case 4: - return _skel_method_3(__QAIC_IMPL(apps_mem_share_map), _sc, _pra); - case 5: - return _skel_method_2(__QAIC_IMPL(apps_mem_share_unmap), _sc, _pra); - case 6: - return _skel_method_1(__QAIC_IMPL(apps_mem_dma_handle_map), _sc, _pra); - case 7: - return _skel_method(__QAIC_IMPL(apps_mem_dma_handle_unmap), _sc, _pra); - } - return AEE_EUNSUPPORTED; +__QAIC_SKEL_EXPORT int +__QAIC_SKEL(apps_mem_skel_invoke)(uint32_t _sc, + remote_arg *_pra) __QAIC_SKEL_ATTRIBUTE +{ + switch(REMOTE_SCALARS_METHOD(_sc)) { + case 0: + return _skel_method_7(__QAIC_IMPL(apps_mem_request_map), _sc, + _pra); + case 1: + return _skel_method_6(__QAIC_IMPL(apps_mem_request_unmap), _sc, + _pra); + case 2: + return _skel_method_5(__QAIC_IMPL(apps_mem_request_map64), _sc, + _pra); + case 3: + return _skel_method_4(__QAIC_IMPL(apps_mem_request_unmap64), + _sc, _pra); + case 4: + return _skel_method_3(__QAIC_IMPL(apps_mem_share_map), _sc, + _pra); + case 5: + return _skel_method_2(__QAIC_IMPL(apps_mem_share_unmap), _sc, + _pra); + case 6: + return _skel_method_1(__QAIC_IMPL(apps_mem_dma_handle_map), + _sc, _pra); + case 7: + return _skel_method(__QAIC_IMPL(apps_mem_dma_handle_unmap), + _sc, _pra); + } + return AEE_EUNSUPPORTED; } #ifdef __cplusplus } diff --git a/src/apps_remotectl_skel.c b/src/apps_remotectl_skel.c index 86778cfc..f5f695c2 100644 --- a/src/apps_remotectl_skel.c +++ b/src/apps_remotectl_skel.c @@ -26,7 +26,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -36,7 +36,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -94,159 +94,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -254,175 +268,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _APPS_REMOTECTL_SLIM_H #define _APPS_REMOTECTL_SLIM_H @@ -436,104 +447,148 @@ struct Interface { #endif static const Type types[1]; -static const Type types[1] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1}}; -static const Parameter parameters[4] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0}}; -static const Parameter* const parameterArrays[7] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[2])),(&(parameters[1])),(&(parameters[3])),(&(parameters[2])),(&(parameters[1]))}; -static const Method methods[2] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x8,0x8,6,4,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[4])),0x4,0x4}}; -static const Method* const methodArrays[2] = {&(methods[0]),&(methods[1])}; +static const Type types[1] + = { { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 } }; +static const Parameter parameters[4] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 } +}; +static const Parameter *const parameterArrays[7] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[2])), + (&(parameters[1])), (&(parameters[3])), (&(parameters[2])), + (&(parameters[1])) }; +static const Method methods[2] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x8, 0x8, 6, 4, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x8, 0x4, 5, 3, + (&(parameterArrays[4])), 0x4, 0x4 } }; +static const Method *const methodArrays[2] = { &(methods[0]), &(methods[1]) }; static const char strings[37] = "dlerror\0handle\0close\0nErr\0name\0open\0"; -static const uint16_t methodStrings[9] = {31,26,8,0,21,15,8,0,21}; -static const uint16_t methodStringsArrays[2] = {0,5}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_remotectl_slim) = {2,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const uint16_t methodStrings[9] = { 31, 26, 8, 0, 21, 15, 8, 0, 21 }; +static const uint16_t methodStringsArrays[2] = { 0, 5 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_remotectl_slim) + = { 2, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_APPS_REMOTECTL_SLIM_H extern int adsp_mmap_fd_getinfo(int, uint32_t *); #ifdef __cplusplus extern "C" { #endif _ATTRIBUTE_VISIBILITY uint32_t apps_remotectl_skel_invoke_qaic_version = 10042; -static __inline int _skel_method(int (*_pfn)(int, char*, int, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _rout1[1] = {0}; - uint32_t _rout1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_rout1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); - _rout1[0] = _praROut[0].buf.pv; - _TRY(_nErr, _pfn((int)*_in0, (char*)*_rout1, (int)*_rout1Len, (int*)_rout2)); - _COPY(_primROut, 0, _rout2, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method(int (*_pfn)(int, char *, int, int *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_rout1[1] = { 0 }; + uint32_t _rout1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_rout1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); + _rout1[0] = _praROut[0].buf.pv; + _TRY(_nErr, _pfn((int)*_in0, (char *)*_rout1, (int)*_rout1Len, + (int *)_rout2)); + _COPY(_primROut, 0, _rout2, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_1(int (*_pfn)(const char*, int*, char*, int, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint32_t _rout1[1] = {0}; - char* _rout2[1] = {0}; - uint32_t _rout2Len[1] = {0}; - uint32_t _rout3[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_rout2Len, 0, _primIn, 4, 4); - _praROut = (_praIn + _numIn[0] + 1); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout2Len[0])); - _rout2[0] = _praROut[0].buf.pv; - _TRY(_nErr, _pfn((const char*)*_in0, (int*)_rout1, (char*)*_rout2, (int)*_rout2Len, (int*)_rout3)); - _COPY(_primROut, 0, _rout1, 0, 4); - _COPY(_primROut, 4, _rout3, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_1(int (*_pfn)(const char *, int *, char *, int, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint32_t _rout1[1] = { 0 }; + char *_rout2[1] = { 0 }; + uint32_t _rout2Len[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_rout2Len, 0, _primIn, 4, 4); + _praROut = (_praIn + _numIn[0] + 1); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout2Len[0])); + _rout2[0] = _praROut[0].buf.pv; + _TRY(_nErr, _pfn((const char *)*_in0, (int *)_rout1, (char *)*_rout2, + (int)*_rout2Len, (int *)_rout3)); + _COPY(_primROut, 0, _rout1, 0, 4); + _COPY(_primROut, 4, _rout3, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_SKEL_EXPORT int __QAIC_SKEL(apps_remotectl_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_SKEL_ATTRIBUTE { - switch(REMOTE_SCALARS_METHOD(_sc)) - { - case 0: - return _skel_method_1(__QAIC_IMPL(apps_remotectl_open), _sc, _pra); - case 1: - return _skel_method(__QAIC_IMPL(apps_remotectl_close), _sc, _pra); - } - return AEE_EUNSUPPORTED; +__QAIC_SKEL_EXPORT int +__QAIC_SKEL(apps_remotectl_skel_invoke)(uint32_t _sc, + remote_arg *_pra) __QAIC_SKEL_ATTRIBUTE +{ + switch(REMOTE_SCALARS_METHOD(_sc)) { + case 0: + return _skel_method_1(__QAIC_IMPL(apps_remotectl_open), _sc, + _pra); + case 1: + return _skel_method(__QAIC_IMPL(apps_remotectl_close), _sc, + _pra); + } + return AEE_EUNSUPPORTED; } #ifdef __cplusplus } diff --git a/src/apps_std_imp.c b/src/apps_std_imp.c index 3458d8c4..9e7e669d 100644 --- a/src/apps_std_imp.c +++ b/src/apps_std_imp.c @@ -39,10 +39,10 @@ #include "rpcmem_internal.h" #include "verify.h" #include -#include #include #include #include +#include #include #include #include @@ -55,11 +55,11 @@ #endif // _WiN32 #ifndef C_ASSERT -#define C_ASSERT(test) \ - switch (0) { \ - case 0: \ - case test:; \ - } +#define C_ASSERT(test) \ + switch(0) { \ + case 0: \ + case test:; \ + } #endif // C_ASSERT #define APPS_FD_BASE 100 @@ -73,38 +73,38 @@ #define TESTSIG_FILE_NAME "testsig" #define RPC_VERSION_FILE_NAME "librpcversion_skel.so" -#define FREEIF(pv) \ - do { \ - if (pv) { \ - void *tmp = (void *)pv; \ - pv = 0; \ - free(tmp); \ - tmp = 0; \ - } \ - } while (0) +#define FREEIF(pv) \ + do { \ + if(pv) { \ + void *tmp = (void *)pv; \ + pv = 0; \ + free(tmp); \ + tmp = 0; \ + } \ + } while(0) struct apps_std_buf_info { - char *fbuf; - int flen; - int pos; + char *fbuf; + int flen; + int pos; }; struct apps_std_info { - QNode qn; - int type; - union { - FILE *stream; - struct apps_std_buf_info binfo; - } u; - apps_std_FILE fd; + QNode qn; + int type; + union { + FILE *stream; + struct apps_std_buf_info binfo; + } u; + apps_std_FILE fd; }; /* * Member of the linked list of valid directory handles */ struct apps_std_dir_info { - QNode qn; - uint64_t handle; + QNode qn; + uint64_t handle; }; static QList apps_std_qlst; @@ -114,17 +114,17 @@ static QList apps_std_dirlist; static pthread_mutex_t apps_std_mt; extern const char *SUBSYSTEM_NAME[]; struct mem_io_to_fd { - QNode qn; - int size; - int fd; - int fdfile; - FILE *stream; - void *buf; + QNode qn; + int size; + int fd; + int fdfile; + FILE *stream; + void *buf; }; struct mem_io_fd_list { - QList ql; - pthread_mutex_t mut; + QList ql; + pthread_mutex_t mut; }; static struct mem_io_fd_list fdlist; @@ -132,1032 +132,1150 @@ static struct mem_io_fd_list fdlist; int setenv(const char *name, const char *value, int overwrite); int unsetenv(const char *name); -int apps_std_get_dirinfo(const apps_std_DIR *dir, - struct apps_std_dir_info **pDirinfo) { - int nErr = AEE_SUCCESS; - QNode *pn = NULL, *pnn = NULL; - struct apps_std_dir_info *dirinfo = 0; - bool match = false; - - pthread_mutex_lock(&apps_std_mt); - QLIST_NEXTSAFE_FOR_ALL(&apps_std_dirlist, pn, pnn) { - dirinfo = STD_RECOVER_REC(struct apps_std_dir_info, qn, pn); - if (dirinfo && dirinfo->handle == dir->handle) { - match = true; - break; - } - } - pthread_mutex_unlock(&apps_std_mt); - - if (match) { - *pDirinfo = dirinfo; - } else { - nErr = ESTALE; - VERIFY_EPRINTF( - "Error 0x%x: %s: stale directory handle 0x%llx passed by DSP\n", nErr, - __func__, dir->handle); - goto bail; - } +int +apps_std_get_dirinfo(const apps_std_DIR *dir, + struct apps_std_dir_info **pDirinfo) +{ + int nErr = AEE_SUCCESS; + QNode *pn = NULL, *pnn = NULL; + struct apps_std_dir_info *dirinfo = 0; + bool match = false; + + pthread_mutex_lock(&apps_std_mt); + QLIST_NEXTSAFE_FOR_ALL(&apps_std_dirlist, pn, pnn) + { + dirinfo = STD_RECOVER_REC(struct apps_std_dir_info, qn, pn); + if(dirinfo && dirinfo->handle == dir->handle) { + match = true; + break; + } + } + pthread_mutex_unlock(&apps_std_mt); + + if(match) { + *pDirinfo = dirinfo; + } else { + nErr = ESTALE; + VERIFY_EPRINTF("Error 0x%x: %s: stale directory handle 0x%llx " + "passed by DSP\n", + nErr, __func__, dir->handle); + goto bail; + } bail: - return nErr; + return nErr; } -int apps_std_init(void) { - QList_Ctor(&apps_std_qlst); - QList_Ctor(&apps_std_dirlist); - pthread_mutex_init(&apps_std_mt, 0); - pthread_mutex_init(&fdlist.mut, 0); - QList_Ctor(&fdlist.ql); - return AEE_SUCCESS; +int +apps_std_init(void) +{ + QList_Ctor(&apps_std_qlst); + QList_Ctor(&apps_std_dirlist); + pthread_mutex_init(&apps_std_mt, 0); + pthread_mutex_init(&fdlist.mut, 0); + QList_Ctor(&fdlist.ql); + return AEE_SUCCESS; } -void apps_std_deinit(void) { - pthread_mutex_destroy(&apps_std_mt); - pthread_mutex_destroy(&fdlist.mut); +void +apps_std_deinit(void) +{ + pthread_mutex_destroy(&apps_std_mt); + pthread_mutex_destroy(&fdlist.mut); } PL_DEFINE(apps_std, apps_std_init, apps_std_deinit); -static void apps_std_FILE_free(struct apps_std_info *sfree) { +static void +apps_std_FILE_free(struct apps_std_info *sfree) +{ - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - pthread_mutex_lock(&apps_std_mt); - QNode_Dequeue(&sfree->qn); - pthread_mutex_unlock(&apps_std_mt); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + pthread_mutex_lock(&apps_std_mt); + QNode_Dequeue(&sfree->qn); + pthread_mutex_unlock(&apps_std_mt); - FREEIF(sfree); - FARF(RUNTIME_RPC_LOW, "Exiting %s", __func__); - return; + FREEIF(sfree); + FARF(RUNTIME_RPC_LOW, "Exiting %s", __func__); + return; } -static int apps_std_FILE_alloc(FILE *stream, apps_std_FILE *fd) { - struct apps_std_info *sinfo = 0, *info; - QNode *pn = 0; - apps_std_FILE prevfd = APPS_FD_BASE - 1; - int nErr = AEE_SUCCESS; - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFYC(0 != (sinfo = calloc(1, sizeof(*sinfo))), ENOMEM); - QNode_CtorZ(&sinfo->qn); - sinfo->type = APPS_STD_STREAM_FILE; - pthread_mutex_lock(&apps_std_mt); - pn = QList_GetFirst(&apps_std_qlst); - if (pn) { - info = STD_RECOVER_REC(struct apps_std_info, qn, pn); - prevfd = info->fd; - QLIST_FOR_REST(&apps_std_qlst, pn) { - info = STD_RECOVER_REC(struct apps_std_info, qn, pn); - if (info->fd != prevfd + 1) { - sinfo->fd = prevfd + 1; - QNode_InsPrev(pn, &sinfo->qn); - break; - } - prevfd = info->fd; - } - } - if (!QNode_IsQueuedZ(&sinfo->qn)) { - sinfo->fd = prevfd + 1; - QList_AppendNode(&apps_std_qlst, &sinfo->qn); - } - pthread_mutex_unlock(&apps_std_mt); - - sinfo->u.stream = stream; - *fd = sinfo->fd; +static int +apps_std_FILE_alloc(FILE *stream, apps_std_FILE *fd) +{ + struct apps_std_info *sinfo = 0, *info; + QNode *pn = 0; + apps_std_FILE prevfd = APPS_FD_BASE - 1; + int nErr = AEE_SUCCESS; + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFYC(0 != (sinfo = calloc(1, sizeof(*sinfo))), ENOMEM); + QNode_CtorZ(&sinfo->qn); + sinfo->type = APPS_STD_STREAM_FILE; + pthread_mutex_lock(&apps_std_mt); + pn = QList_GetFirst(&apps_std_qlst); + if(pn) { + info = STD_RECOVER_REC(struct apps_std_info, qn, pn); + prevfd = info->fd; + QLIST_FOR_REST(&apps_std_qlst, pn) + { + info = STD_RECOVER_REC(struct apps_std_info, qn, pn); + if(info->fd != prevfd + 1) { + sinfo->fd = prevfd + 1; + QNode_InsPrev(pn, &sinfo->qn); + break; + } + prevfd = info->fd; + } + } + if(!QNode_IsQueuedZ(&sinfo->qn)) { + sinfo->fd = prevfd + 1; + QList_AppendNode(&apps_std_qlst, &sinfo->qn); + } + pthread_mutex_unlock(&apps_std_mt); + + sinfo->u.stream = stream; + *fd = sinfo->fd; bail: - if (nErr) { - FREEIF(sinfo); - VERIFY_EPRINTF("Error 0x%x: apps_std_FILE_alloc failed, errno %s \n", nErr, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s fd 0x%x err %d", __func__, *fd, nErr); - return nErr; + if(nErr) { + FREEIF(sinfo); + VERIFY_EPRINTF( + "Error 0x%x: apps_std_FILE_alloc failed, errno %s \n", + nErr, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s fd 0x%x err %d", __func__, *fd, + nErr); + return nErr; } -static int apps_std_FILE_get(apps_std_FILE fd, struct apps_std_info **info) { - struct apps_std_info *sinfo = 0; - QNode *pn, *pnn; - int nErr = EBADF; - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - pthread_mutex_lock(&apps_std_mt); - QLIST_NEXTSAFE_FOR_ALL(&apps_std_qlst, pn, pnn) { - sinfo = STD_RECOVER_REC(struct apps_std_info, qn, pn); - if (sinfo->fd == fd) { - *info = sinfo; - nErr = AEE_SUCCESS; - break; - } - } - pthread_mutex_unlock(&apps_std_mt); - if (nErr) { - VERIFY_EPRINTF( - "Error 0x%x: apps_std_FILE_get failed for fd 0x%x, errno %s \n", nErr, - fd, strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s fd 0x%x err %d", __func__, fd, nErr); - return nErr; +static int +apps_std_FILE_get(apps_std_FILE fd, struct apps_std_info **info) +{ + struct apps_std_info *sinfo = 0; + QNode *pn, *pnn; + int nErr = EBADF; + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + pthread_mutex_lock(&apps_std_mt); + QLIST_NEXTSAFE_FOR_ALL(&apps_std_qlst, pn, pnn) + { + sinfo = STD_RECOVER_REC(struct apps_std_info, qn, pn); + if(sinfo->fd == fd) { + *info = sinfo; + nErr = AEE_SUCCESS; + break; + } + } + pthread_mutex_unlock(&apps_std_mt); + if(nErr) { + VERIFY_EPRINTF("Error 0x%x: apps_std_FILE_get failed for fd " + "0x%x, errno %s \n", + nErr, fd, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s fd 0x%x err %d", __func__, fd, nErr); + return nErr; } -static void apps_std_FILE_set_buffer_stream(struct apps_std_info *sinfo, - char *fbuf, int flen, int pos) { - pthread_mutex_lock(&apps_std_mt); - fclose(sinfo->u.stream); - sinfo->type = APPS_STD_STREAM_BUF; - sinfo->u.binfo.fbuf = fbuf; - sinfo->u.binfo.flen = flen; - sinfo->u.binfo.pos = pos; - pthread_mutex_unlock(&apps_std_mt); +static void +apps_std_FILE_set_buffer_stream(struct apps_std_info *sinfo, char *fbuf, + int flen, int pos) +{ + pthread_mutex_lock(&apps_std_mt); + fclose(sinfo->u.stream); + sinfo->type = APPS_STD_STREAM_BUF; + sinfo->u.binfo.fbuf = fbuf; + sinfo->u.binfo.flen = flen; + sinfo->u.binfo.pos = pos; + pthread_mutex_unlock(&apps_std_mt); } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fopen)(const char *name, const char *mode, - apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - FILE *stream = NULL; - uint64_t tdiff = 0; - - if (name) { - FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode", __func__, name, mode); - } - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFYC(name != NULL, AEE_EBADPARM); - PROFILE_ALWAYS(&tdiff, stream = fopen(name, mode);); - if (stream) { - FASTRPC_ATRACE_END_L("%s done, fopen for %s in mode %s done in %" PRIu64 - " us, fd 0x%x error_code 0x%x", - __func__, name, mode, tdiff, *psout, nErr); - return apps_std_FILE_alloc(stream, psout); - } else { - nErr = ERRNO; - } + apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + FILE *stream = NULL; + uint64_t tdiff = 0; + + if(name) { + FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode", __func__, name, + mode); + } + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFYC(name != NULL, AEE_EBADPARM); + PROFILE_ALWAYS(&tdiff, stream = fopen(name, mode);); + if(stream) { + FASTRPC_ATRACE_END_L( + "%s done, fopen for %s in mode %s done in %" PRIu64 + " us, fd 0x%x error_code 0x%x", + __func__, name, mode, tdiff, *psout, nErr); + return apps_std_FILE_alloc(stream, psout); + } else { + nErr = ERRNO; + } bail: - if (nErr != AEE_SUCCESS) { - // Ignoring this error, as fopen happens on all ADSP_LIBRARY_PATHs - VERIFY_IPRINTF("Error 0x%x: %s failed for %s (%s)\n", nErr, __func__, name, - strerror(ERRNO)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s err %d", __func__, name, - mode, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + // Ignoring this error, as fopen happens on all + // ADSP_LIBRARY_PATHs + VERIFY_IPRINTF("Error 0x%x: %s failed for %s (%s)\n", nErr, + __func__, name, strerror(ERRNO)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s err %d", __func__, + name, mode, nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fopen_fd)(const char *name, const char *mode, int *fd, - int *len) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct stat statbuf; - void *source = NULL; - int sz = 0, fdfile = 0; - struct mem_io_to_fd *tofd = 0; - int domain = get_current_domain(); - FILE *stream = NULL; - bool fopen_fail = false, mmap_pass = false; - uint64_t fopen_time = 0, read_time = 0, rpc_alloc_time = 0, mmap_time = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode", __func__, name, mode); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFYC(name != NULL, AEE_EBADPARM); - PROFILE_ALWAYS(&fopen_time, stream = fopen(name, mode);); - if (!stream) { - fopen_fail = true; - nErr = ERRNO; - goto bail; - } - VERIFYC(-1 != (fdfile = fileno(stream)), ERRNO); - VERIFYC(0 == fstat(fdfile, &statbuf), ERRNO); - PROFILE_ALWAYS( - &rpc_alloc_time, - source = rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, statbuf.st_size);); - VERIFYC(0 != source, AEE_ENORPCMEMORY); - PROFILE_ALWAYS(&read_time, sz = read(fdfile, source, statbuf.st_size);); - if (sz < 0) { - nErr = AEE_EFILE; - goto bail; - } - *fd = rpcmem_to_fd(source); - *len = statbuf.st_size; - PROFILE_ALWAYS(&mmap_time, nErr = fastrpc_mmap(domain, *fd, source, 0, *len, - FASTRPC_MAP_FD)); - VERIFY(AEE_SUCCESS == nErr); - VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), AEE_ENOMEMORY); - QNode_CtorZ(&tofd->qn); - tofd->size = *len; - tofd->fd = *fd; - tofd->fdfile = fdfile; - tofd->stream = stream; - tofd->buf = source; - pthread_mutex_lock(&fdlist.mut); - QList_AppendNode(&fdlist.ql, &tofd->qn); - pthread_mutex_unlock(&fdlist.mut); + int *len) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct stat statbuf; + void *source = NULL; + int sz = 0, fdfile = 0; + struct mem_io_to_fd *tofd = 0; + int domain = get_current_domain(); + FILE *stream = NULL; + bool fopen_fail = false, mmap_pass = false; + uint64_t fopen_time = 0, read_time = 0, rpc_alloc_time = 0, + mmap_time = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode", __func__, name, mode); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFYC(name != NULL, AEE_EBADPARM); + PROFILE_ALWAYS(&fopen_time, stream = fopen(name, mode);); + if(!stream) { + fopen_fail = true; + nErr = ERRNO; + goto bail; + } + VERIFYC(-1 != (fdfile = fileno(stream)), ERRNO); + VERIFYC(0 == fstat(fdfile, &statbuf), ERRNO); + PROFILE_ALWAYS(&rpc_alloc_time, + source = rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, + statbuf.st_size);); + VERIFYC(0 != source, AEE_ENORPCMEMORY); + PROFILE_ALWAYS(&read_time, + sz = read(fdfile, source, statbuf.st_size);); + if(sz < 0) { + nErr = AEE_EFILE; + goto bail; + } + *fd = rpcmem_to_fd(source); + *len = statbuf.st_size; + PROFILE_ALWAYS(&mmap_time, nErr = fastrpc_mmap(domain, *fd, source, 0, + *len, FASTRPC_MAP_FD)); + VERIFY(AEE_SUCCESS == nErr); + VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), AEE_ENOMEMORY); + QNode_CtorZ(&tofd->qn); + tofd->size = *len; + tofd->fd = *fd; + tofd->fdfile = fdfile; + tofd->stream = stream; + tofd->buf = source; + pthread_mutex_lock(&fdlist.mut); + QList_AppendNode(&fdlist.ql, &tofd->qn); + pthread_mutex_unlock(&fdlist.mut); bail: - if (nErr != AEE_SUCCESS) { - if (stream) { - fclose(stream); - } - // Ignore fopen error, as fopen happens on all ADSP_LIBRARY_PATHs - if (!fopen_fail) { - FARF(ERROR, "Error 0x%x: %s failed for %s (%s)\n", nErr, __func__, name, - strerror(ERRNO)); - } - if (mmap_pass) { - fastrpc_munmap(domain, *fd, source, *len); - } - FREEIF(tofd); - if (source) { - rpcmem_free_internal(source); - source = NULL; - } - } - FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s err %d", __func__, name, - mode, nErr); - FASTRPC_ATRACE_END_L("%s: done for %s with fopen:%" PRIu64 "us, read:%" PRIu64 - "us, rpc_alloc:%" PRIu64 "us, mmap:%" PRIu64 "us", - __func__, name, fopen_time, read_time, rpc_alloc_time, - mmap_time); - FARF(RUNTIME_RPC_CRITICAL, - "%s: done for %s with fopen:%" PRIu64 "us, read:%" PRIu64 - "us, rpc_alloc:%" PRIu64 "us, mmap:%" PRIu64 "us, fd 0x%x error_code 0x%x", - __func__, name, fopen_time, read_time, rpc_alloc_time, mmap_time, *fd, nErr); - return nErr; + if(nErr != AEE_SUCCESS) { + if(stream) { + fclose(stream); + } + // Ignore fopen error, as fopen happens on all + // ADSP_LIBRARY_PATHs + if(!fopen_fail) { + FARF(ERROR, "Error 0x%x: %s failed for %s (%s)\n", + nErr, __func__, name, strerror(ERRNO)); + } + if(mmap_pass) { + fastrpc_munmap(domain, *fd, source, *len); + } + FREEIF(tofd); + if(source) { + rpcmem_free_internal(source); + source = NULL; + } + } + FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s err %d", __func__, + name, mode, nErr); + FASTRPC_ATRACE_END_L( + "%s: done for %s with fopen:%" PRIu64 "us, read:%" PRIu64 + "us, rpc_alloc:%" PRIu64 "us, mmap:%" PRIu64 "us", + __func__, name, fopen_time, read_time, rpc_alloc_time, mmap_time); + FARF(RUNTIME_RPC_CRITICAL, + "%s: done for %s with fopen:%" PRIu64 "us, read:%" PRIu64 + "us, rpc_alloc:%" PRIu64 "us, mmap:%" PRIu64 + "us, fd 0x%x error_code 0x%x", + __func__, name, fopen_time, read_time, rpc_alloc_time, mmap_time, + *fd, nErr); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_freopen)(apps_std_FILE sin, const char *name, const char *mode, - apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - FILE *stream; - - if (name) { - FASTRPC_ATRACE_BEGIN_L("%s for %s (fd 0x%x) in %s mode", __func__, name, - sin, mode); - } - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFYC(name != NULL, AEE_EBADPARM); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - VERIFYC(sinfo->type == APPS_STD_STREAM_FILE, EBADF); - stream = freopen(name, mode, sinfo->u.stream); - if (stream) { - FARF(RUNTIME_RPC_HIGH, "freopen success: %s %x\n", name, stream); - return apps_std_FILE_alloc(stream, psout); - } else { - nErr = ERRNO; - } + apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + FILE *stream; + + if(name) { + FASTRPC_ATRACE_BEGIN_L("%s for %s (fd 0x%x) in %s mode", + __func__, name, sin, mode); + } + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFYC(name != NULL, AEE_EBADPARM); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + VERIFYC(sinfo->type == APPS_STD_STREAM_FILE, EBADF); + stream = freopen(name, mode, sinfo->u.stream); + if(stream) { + FARF(RUNTIME_RPC_HIGH, "freopen success: %s %x\n", name, + stream); + return apps_std_FILE_alloc(stream, psout); + } else { + nErr = ERRNO; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF( - "Error 0x%x: freopen for %s mode %s sin %x failed. errno: %s\n", nErr, - name, mode, sin, strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s sin %x err %d", __func__, - name, mode, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: freopen for %s mode %s sin %x " + "failed. errno: %s\n", + nErr, name, mode, sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s name %s mode %s sin %x err %d", + __func__, name, mode, sin, nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fflush)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - VERIFYC(0 == fflush(sinfo->u.stream), ERRNO); - } +__QAIC_IMPL(apps_std_fflush)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + VERIFYC(0 == fflush(sinfo->u.stream), ERRNO); + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: fflush for %x failed. errno: %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s sin %x err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: fflush for %x failed. errno: %s\n", + nErr, sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s sin %x err %d", __func__, sin, nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fclose)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - uint64_t tdiff = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - PROFILE_ALWAYS(&tdiff, - nErr = fclose(sinfo->u.stream); - ); - VERIFYC(nErr == AEE_SUCCESS, ERRNO); - } else { - if (sinfo->u.binfo.fbuf) { - rpcmem_free_internal(sinfo->u.binfo.fbuf); - sinfo->u.binfo.fbuf = NULL; - } - } - apps_std_FILE_free(sinfo); +__QAIC_IMPL(apps_std_fclose)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + uint64_t tdiff = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + PROFILE_ALWAYS(&tdiff, nErr = fclose(sinfo->u.stream);); + VERIFYC(nErr == AEE_SUCCESS, ERRNO); + } else { + if(sinfo->u.binfo.fbuf) { + rpcmem_free_internal(sinfo->u.binfo.fbuf); + sinfo->u.binfo.fbuf = NULL; + } + } + apps_std_FILE_free(sinfo); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: freopen for %x failed. errno: %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s sin %x err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END_L("%s fd 0x%x in %"PRIu64" us error_code 0x%x ", - __func__, sin, tdiff, nErr); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: freopen for %x failed. errno: %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s sin %x err %d", __func__, sin, nErr); + FASTRPC_ATRACE_END_L("%s fd 0x%x in %" PRIu64 " us error_code 0x%x ", + __func__, sin, tdiff, nErr); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fclose_fd)(int fd) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - int domain = get_current_domain(); - uint64_t tdiff = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, fd); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - QNode *pn, *pnn; - struct mem_io_to_fd *freefd = NULL; - pthread_mutex_lock(&fdlist.mut); - QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) { - struct mem_io_to_fd *tofd = STD_RECOVER_REC(struct mem_io_to_fd, qn, pn); - if (tofd->fd == fd) { - QNode_DequeueZ(&tofd->qn); - freefd = tofd; - tofd = NULL; - break; - } - } - pthread_mutex_unlock(&fdlist.mut); - if (freefd) { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_munmap(domain, fd, freefd->buf, freefd->size))); - if (freefd->buf) { - rpcmem_free_internal(freefd->buf); - freefd->buf = NULL; - } - PROFILE_ALWAYS(&tdiff, - nErr = fclose(freefd->stream); - ); - VERIFYC(nErr == AEE_SUCCESS, ERRNO); - } +__QAIC_IMPL(apps_std_fclose_fd)(int fd) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + int domain = get_current_domain(); + uint64_t tdiff = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, fd); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + QNode *pn, *pnn; + struct mem_io_to_fd *freefd = NULL; + pthread_mutex_lock(&fdlist.mut); + QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) + { + struct mem_io_to_fd *tofd + = STD_RECOVER_REC(struct mem_io_to_fd, qn, pn); + if(tofd->fd == fd) { + QNode_DequeueZ(&tofd->qn); + freefd = tofd; + tofd = NULL; + break; + } + } + pthread_mutex_unlock(&fdlist.mut); + if(freefd) { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_munmap(domain, fd, freefd->buf, + freefd->size))); + if(freefd->buf) { + rpcmem_free_internal(freefd->buf); + freefd->buf = NULL; + } + PROFILE_ALWAYS(&tdiff, nErr = fclose(freefd->stream);); + VERIFYC(nErr == AEE_SUCCESS, ERRNO); + } bail: - FREEIF(freefd); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s for %x failed. errno: %s\n", nErr, __func__, - fd, strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s fd %x err %d", __func__, fd, nErr); - FASTRPC_ATRACE_END_L("%s fd 0x%x in %"PRIu64" us error_code 0x%x", - __func__, fd, tdiff, nErr); - return nErr; + FREEIF(freefd); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s for %x failed. errno: %s\n", + nErr, __func__, fd, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s fd %x err %d", __func__, fd, nErr); + FASTRPC_ATRACE_END_L("%s fd 0x%x in %" PRIu64 " us error_code 0x%x", + __func__, fd, tdiff, nErr); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fread)(apps_std_FILE sin, unsigned char *buf, int bufLen, - int *bytesRead, int *bEOF) __QAIC_IMPL_ATTRIBUTE { - int out = 0, nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - uint64_t tdiff = 0; - - FASTRPC_ATRACE_BEGIN_L("%s requested for %d bytes with fd 0x%x", __func__, - bufLen, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - PROFILE_ALWAYS(&tdiff, out = fread(buf, 1, bufLen, sinfo->u.stream);); - *bEOF = false; - if (out <= bufLen) { - int err; - if (0 == out && (0 != (err = ferror(sinfo->u.stream)))) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: fread returning %d bytes in %"PRIu64" us, requested was %d " - "bytes, errno is %x\n", - nErr, out, tdiff, bufLen, err); - return nErr; - } - *bEOF = feof(sinfo->u.stream); - clearerr(sinfo->u.stream); - } - *bytesRead = out; - } else { - unsigned int read = STD_MIN(bufLen, - sinfo->u.binfo.flen - sinfo->u.binfo.pos); - memcpy(buf, sinfo->u.binfo.fbuf + sinfo->u.binfo.pos, read); - *bytesRead = read; - sinfo->u.binfo.pos += read; - *bEOF = sinfo->u.binfo.pos == sinfo->u.binfo.flen ? true : false; - } - FARF(RUNTIME_RPC_HIGH, "fread returning %d %d\n", out, bufLen); + int *bytesRead, int *bEOF) __QAIC_IMPL_ATTRIBUTE +{ + int out = 0, nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + uint64_t tdiff = 0; + + FASTRPC_ATRACE_BEGIN_L("%s requested for %d bytes with fd 0x%x", + __func__, bufLen, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + PROFILE_ALWAYS(&tdiff, + out = fread(buf, 1, bufLen, sinfo->u.stream);); + *bEOF = false; + if(out <= bufLen) { + int err; + if(0 == out + && (0 != (err = ferror(sinfo->u.stream)))) { + nErr = ERRNO; + VERIFY_EPRINTF("Error 0x%x: fread returning " + "%d bytes in %" PRIu64 + " us, requested was %d " + "bytes, errno is %x\n", + nErr, out, tdiff, bufLen, err); + return nErr; + } + *bEOF = feof(sinfo->u.stream); + clearerr(sinfo->u.stream); + } + *bytesRead = out; + } else { + unsigned int read = STD_MIN(bufLen, sinfo->u.binfo.flen + - sinfo->u.binfo.pos); + memcpy(buf, sinfo->u.binfo.fbuf + sinfo->u.binfo.pos, read); + *bytesRead = read; + sinfo->u.binfo.pos += read; + *bEOF + = sinfo->u.binfo.pos == sinfo->u.binfo.flen ? true : false; + } + FARF(RUNTIME_RPC_HIGH, "fread returning %d %d\n", out, bufLen); bail: - FARF(RUNTIME_RPC_LOW, - "Exiting %s returning %d bytes, requested was %d bytes for %x, err 0x%x", - __func__, out, bufLen, sin, nErr); - FASTRPC_ATRACE_END_L("%s done, read %d bytes in %"PRIu64" us requested %d bytes," - "fd 0x%x", __func__, out, tdiff, bufLen, sin); - return nErr; + FARF(RUNTIME_RPC_LOW, + "Exiting %s returning %d bytes, requested was %d bytes for %x, " + "err 0x%x", + __func__, out, bufLen, sin, nErr); + FASTRPC_ATRACE_END_L("%s done, read %d bytes in %" PRIu64 + " us requested %d bytes," + "fd 0x%x", + __func__, out, tdiff, bufLen, sin); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fwrite)(apps_std_FILE sin, const unsigned char *buf, int bufLen, - int *bytesRead, int *bEOF) __QAIC_IMPL_ATTRIBUTE { - int out = 0, nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s requested for %d bytes with fd 0x%x", __func__, - bufLen, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - out = fwrite(buf, 1, bufLen, sinfo->u.stream); - *bEOF = false; - if (out <= bufLen) { - int err; - if (0 == out && (0 != (err = ferror(sinfo->u.stream)))) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: fwrite returning %d bytes, requested was " - "%d bytes, errno is %x\n", - nErr, out, bufLen, err); - return nErr; - } - *bEOF = feof(sinfo->u.stream); - clearerr(sinfo->u.stream); - } - *bytesRead = out; - } else { - nErr = AEE_EFILE; - } +__QAIC_IMPL(apps_std_fwrite)(apps_std_FILE sin, const unsigned char *buf, + int bufLen, int *bytesRead, + int *bEOF) __QAIC_IMPL_ATTRIBUTE +{ + int out = 0, nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s requested for %d bytes with fd 0x%x", + __func__, bufLen, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + out = fwrite(buf, 1, bufLen, sinfo->u.stream); + *bEOF = false; + if(out <= bufLen) { + int err; + if(0 == out + && (0 != (err = ferror(sinfo->u.stream)))) { + nErr = ERRNO; + VERIFY_EPRINTF("Error 0x%x: fwrite returning " + "%d bytes, requested was " + "%d bytes, errno is %x\n", + nErr, out, bufLen, err); + return nErr; + } + *bEOF = feof(sinfo->u.stream); + clearerr(sinfo->u.stream); + } + *bytesRead = out; + } else { + nErr = AEE_EFILE; + } bail: - FARF(RUNTIME_RPC_LOW, - "Exiting %s returning %d bytes, requested was %d bytes for %x, err %d", - __func__, out, bufLen, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + FARF(RUNTIME_RPC_LOW, + "Exiting %s returning %d bytes, requested was %d bytes for %x, " + "err %d", + __func__, out, bufLen, sin, nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fgetpos)(apps_std_FILE sin, unsigned char *pos, int posLen, - int *posLenReq) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - fpos_t fpos; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x with posLen %d", __func__, - sin, posLen); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - if (0 == fgetpos(sinfo->u.stream, &fpos)) { - memmove(pos, &fpos, STD_MIN((int)sizeof(fpos), posLen)); - *posLenReq = sizeof(fpos); - } else { - nErr = ERRNO; - } - } else { - nErr = EBADF; - } +__QAIC_IMPL(apps_std_fgetpos)(apps_std_FILE sin, unsigned char *pos, + int posLen, int *posLenReq) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + fpos_t fpos; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x with posLen %d", + __func__, sin, posLen); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + if(0 == fgetpos(sinfo->u.stream, &fpos)) { + memmove(pos, &fpos, + STD_MIN((int)sizeof(fpos), posLen)); + *posLenReq = sizeof(fpos); + } else { + nErr = ERRNO; + } + } else { + nErr = EBADF; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: fgetpos failed for %x, errno is %s\n", nErr, - sin, strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: fgetpos failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, + nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fsetpos)(apps_std_FILE sin, const unsigned char *pos, - int posLen) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - fpos_t fpos; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x with posLen %d", __func__, - sin, posLen); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - if (sizeof(fpos) != posLen) { - nErr = EBADF; - goto bail; - } - memmove(&fpos, pos, sizeof(fpos)); - VERIFYC(0 == fsetpos(sinfo->u.stream, &fpos), ERRNO); - } else { - nErr = EBADF; - } + int posLen) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + fpos_t fpos; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x with posLen %d", + __func__, sin, posLen); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + if(sizeof(fpos) != posLen) { + nErr = EBADF; + goto bail; + } + memmove(&fpos, pos, sizeof(fpos)); + VERIFYC(0 == fsetpos(sinfo->u.stream, &fpos), ERRNO); + } else { + nErr = EBADF; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: fsetpos failed for %x, errno is %s\n", nErr, - sin, strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: fsetpos failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, + nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_ftell)(apps_std_FILE sin, int *pos) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - errno = 0; - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - VERIFYC((*pos = ftell(sinfo->u.stream)) >= 0, ERRNO); - } else { - *pos = sinfo->u.binfo.pos; - } +__QAIC_IMPL(apps_std_ftell)(apps_std_FILE sin, int *pos) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + errno = 0; + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + VERIFYC((*pos = ftell(sinfo->u.stream)) >= 0, ERRNO); + } else { + *pos = sinfo->u.binfo.pos; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: ftell failed for %x, errno is %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: ftell failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, + nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fseek)(apps_std_FILE sin, int offset, - apps_std_SEEK whence) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - int op = (int)whence; - struct apps_std_info *sinfo = 0; - uint64_t tdiff = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x for op %d on offset %d", - __func__, sin, whence, offset); - FARF(RUNTIME_RPC_LOW, "Entering %s op %d", __func__, op); - errno = 0; - C_ASSERT(APPS_STD_SEEK_SET == SEEK_SET); - C_ASSERT(APPS_STD_SEEK_CUR == SEEK_CUR); - C_ASSERT(APPS_STD_SEEK_END == SEEK_END); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - PROFILE(&tdiff, - VERIFYC(0 == fseek(sinfo->u.stream, offset, whence), ERRNO);); - } else { - switch (op) { - case APPS_STD_SEEK_SET: - VERIFYC(offset <= sinfo->u.binfo.flen, AEE_EFILE); - sinfo->u.binfo.pos = offset; - break; - case APPS_STD_SEEK_CUR: - VERIFYC(offset + sinfo->u.binfo.pos <= sinfo->u.binfo.flen, AEE_EFILE); - sinfo->u.binfo.pos += offset; - break; - case APPS_STD_SEEK_END: - VERIFYC(offset <= INT_MAX - sinfo->u.binfo.flen, AEE_EFILE); - sinfo->u.binfo.pos += offset + sinfo->u.binfo.flen; - break; - } - } + apps_std_SEEK whence) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + int op = (int)whence; + struct apps_std_info *sinfo = 0; + uint64_t tdiff = 0; + + FASTRPC_ATRACE_BEGIN_L( + "%s for file with fd 0x%x for op %d on offset %d", __func__, sin, + whence, offset); + FARF(RUNTIME_RPC_LOW, "Entering %s op %d", __func__, op); + errno = 0; + C_ASSERT(APPS_STD_SEEK_SET == SEEK_SET); + C_ASSERT(APPS_STD_SEEK_CUR == SEEK_CUR); + C_ASSERT(APPS_STD_SEEK_END == SEEK_END); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + PROFILE(&tdiff, + VERIFYC(0 == fseek(sinfo->u.stream, offset, whence), + ERRNO);); + } else { + switch(op) { + case APPS_STD_SEEK_SET: + VERIFYC(offset <= sinfo->u.binfo.flen, AEE_EFILE); + sinfo->u.binfo.pos = offset; + break; + case APPS_STD_SEEK_CUR: + VERIFYC(offset + sinfo->u.binfo.pos + <= sinfo->u.binfo.flen, + AEE_EFILE); + sinfo->u.binfo.pos += offset; + break; + case APPS_STD_SEEK_END: + VERIFYC(offset <= INT_MAX - sinfo->u.binfo.flen, + AEE_EFILE); + sinfo->u.binfo.pos += offset + sinfo->u.binfo.flen; + break; + } + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: fseek failed for %x, errno is %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x offset %d, err %d", __func__, sin, - offset, nErr); - FASTRPC_ATRACE_END_L("%s done for fd 0x%x, op %d on offset %d, time %" PRIu64 - " us, err %d", - __func__, sin, whence, offset, tdiff, nErr); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: fseek failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x offset %d, err %d", __func__, + sin, offset, nErr); + FASTRPC_ATRACE_END_L( + "%s done for fd 0x%x, op %d on offset %d, time %" PRIu64 + " us, err %d", + __func__, sin, whence, offset, tdiff, nErr); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_rewind)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - rewind(sinfo->u.stream); - } else { - sinfo->u.binfo.pos = 0; - } - if (errno != 0) - nErr = ERRNO; +__QAIC_IMPL(apps_std_rewind)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + rewind(sinfo->u.stream); + } else { + sinfo->u.binfo.pos = 0; + } + if(errno != 0) + nErr = ERRNO; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: rewind failed for %x, errno is %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: rewind failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, + nErr); + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_feof)(apps_std_FILE sin, int *bEOF) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - *bEOF = feof(sinfo->u.stream); - clearerr(sinfo->u.stream); - } else { - nErr = EBADF; - } +__QAIC_IMPL(apps_std_feof)(apps_std_FILE sin, int *bEOF) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + *bEOF = feof(sinfo->u.stream); + clearerr(sinfo->u.stream); + } else { + nErr = EBADF; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: feof failed for %x, errno is %s\n", nErr, sin, - strerror(nErr)); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, nErr); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: feof failed for %x, errno is %s\n", + nErr, sin, strerror(nErr)); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %x, err %d", __func__, sin, + nErr); + FASTRPC_ATRACE_END(); + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_ferror)(apps_std_FILE sin, int *err) - __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - *err = ferror(sinfo->u.stream); - } else { - nErr = EBADF; - } +__QAIC_IMPL_EXPORT int +__QAIC_IMPL(apps_std_ferror)(apps_std_FILE sin, int *err) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + *err = ferror(sinfo->u.stream); + } else { + nErr = EBADF; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: ferror failed for %x, errno is %s\n", nErr, sin, - strerror(nErr)); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: ferror failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_clearerr)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - clearerr(sinfo->u.stream); - } else { - nErr = EBADF; - } +__QAIC_IMPL(apps_std_clearerr)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + clearerr(sinfo->u.stream); + } else { + nErr = EBADF; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: clearerr failed for %x, errno is %s\n", nErr, - sin, strerror(nErr)); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: clearerr failed for %x, errno is %s\n", nErr, + sin, strerror(nErr)); + } + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_flen)(apps_std_FILE sin, - uint64_t *len) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - struct stat st_buf; - errno = 0; - int fd = fileno(sinfo->u.stream); - C_ASSERT(sizeof(st_buf.st_size) <= sizeof(*len)); - if (fd == -1) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: flen failed for %x, errno is %s\n", nErr, sin, - strerror(ERRNO)); - return nErr; - } - errno = 0; - if (0 != fstat(fd, &st_buf)) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: flen failed for %x, errno is %s\n", nErr, sin, - strerror(ERRNO)); - return nErr; - } - *len = st_buf.st_size; - } else { - *len = sinfo->u.binfo.flen; - } + uint64_t *len) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x", __func__, sin); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + struct stat st_buf; + errno = 0; + int fd = fileno(sinfo->u.stream); + C_ASSERT(sizeof(st_buf.st_size) <= sizeof(*len)); + if(fd == -1) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: flen failed for %x, errno is %s\n", + nErr, sin, strerror(ERRNO)); + return nErr; + } + errno = 0; + if(0 != fstat(fd, &st_buf)) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: flen failed for %x, errno is %s\n", + nErr, sin, strerror(ERRNO)); + return nErr; + } + *len = st_buf.st_size; + } else { + *len = sinfo->u.binfo.flen; + } bail: - FASTRPC_ATRACE_END(); - return nErr; + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_print_string)(const char *str) __QAIC_IMPL_ATTRIBUTE { - printf("%s\n", str); - return AEE_SUCCESS; +__QAIC_IMPL(apps_std_print_string)(const char *str) __QAIC_IMPL_ATTRIBUTE +{ + printf("%s\n", str); + return AEE_SUCCESS; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_getenv)(const char *name, char *val, int valLen, - int *valLenReq) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - errno = 0; - char *vv = getenv(name); - if (vv) { - *valLenReq = strlen(vv) + 1; - strlcpy(val, vv, STD_MIN(valLen, *valLenReq)); - return AEE_SUCCESS; - } - nErr = ERRNO; - FARF(RUNTIME_RPC_HIGH, "Error 0x%x: apps_std getenv failed: %s %s\n", nErr, - name, strerror(ERRNO)); - return nErr; + int *valLenReq) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + errno = 0; + char *vv = getenv(name); + if(vv) { + *valLenReq = strlen(vv) + 1; + strlcpy(val, vv, STD_MIN(valLen, *valLenReq)); + return AEE_SUCCESS; + } + nErr = ERRNO; + FARF(RUNTIME_RPC_HIGH, "Error 0x%x: apps_std getenv failed: %s %s\n", + nErr, name, strerror(ERRNO)); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_setenv)(const char *name, const char *val, - int override) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - errno = 0; + int override) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + errno = 0; #ifdef _WIN32 - return AEE_EUNSUPPORTED; -#else //_WIN32 - if (0 != setenv(name, val, override)) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: setenv failed for %s, errno is %s\n", nErr, - name, strerror(ERRNO)); - return nErr; - } - return AEE_SUCCESS; + return AEE_EUNSUPPORTED; +#else //_WIN32 + if(0 != setenv(name, val, override)) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: setenv failed for %s, errno is %s\n", nErr, + name, strerror(ERRNO)); + return nErr; + } + return AEE_SUCCESS; #endif //_WIN32 } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_unsetenv)(const char *name) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - errno = 0; +__QAIC_IMPL(apps_std_unsetenv)(const char *name) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + errno = 0; #ifdef _WIN32 - return AEE_EUNSUPPORTED; -#else //_WIN32 - if (0 != unsetenv(name)) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: unsetenv failed for %s, errno is %s\n", nErr, - name, strerror(ERRNO)); - return nErr; - } - return AEE_SUCCESS; + return AEE_EUNSUPPORTED; +#else //_WIN32 + if(0 != unsetenv(name)) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: unsetenv failed for %s, errno is %s\n", nErr, + name, strerror(ERRNO)); + return nErr; + } + return AEE_SUCCESS; #endif //_WIN32 } #define EMTPY_STR "" #define ENV_LEN_GUESS 256 -static int get_dirlist_from_env(const char *envvarname, char **ppDirList) { - char *envList = NULL; - char *envListBuf = NULL; - char *dirList = NULL; - char *dirListBuf = NULL; - char *srcStr = NULL; - int nErr = AEE_SUCCESS; - int envListLen = 0; - int envListPrependLen = 0; - int listLen = 0; - int envLenGuess = STD_MAX(ENV_LEN_GUESS, 1 + strlen(DSP_SEARCH_PATH)); - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFYC(NULL != ppDirList, AEE_ERPC); - - VERIFYC(envListBuf = (char *)malloc(sizeof(char) * envLenGuess), - AEE_ENOMEMORY); - envList = envListBuf; - *envList = '\0'; - if (0 == apps_std_getenv(envvarname, envList, envLenGuess, &envListLen)) { - if (strncmp(envvarname, ADSP_LIBRARY_PATH, - strlen(ADSP_LIBRARY_PATH)) == 0 || - strncmp(envvarname, DSP_LIBRARY_PATH, - strlen(DSP_LIBRARY_PATH)) == 0) { - // Calculate total length of env and DSP_SEARCH_PATH - envListPrependLen = envListLen + strlen(DSP_SEARCH_PATH); - if (envLenGuess < envListPrependLen) { - FREEIF(envListBuf); - VERIFYC(envListBuf = - realloc(envListBuf, sizeof(char) * envListPrependLen), - AEE_ENOMEMORY); - envList = envListBuf; - VERIFY(0 == (nErr = apps_std_getenv(envvarname, envList, - envListPrependLen, &listLen))); - } - // Append default DSP_SEARCH_PATH to user defined env - strlcat(envList, DSP_SEARCH_PATH, envListPrependLen); - envListLen = envListPrependLen; - } else if (strncmp(envvarname, ADSP_AVS_PATH, - strlen(ADSP_AVS_PATH)) == 0) { - envListPrependLen = envListLen + strlen(ADSP_AVS_CFG_PATH); - if (envLenGuess < envListPrependLen) { - FREEIF(envListBuf); - VERIFYC(envListBuf = - realloc(envListBuf, sizeof(char) * envListPrependLen), - AEE_ENOMEMORY); - envList = envListBuf; - VERIFY(0 == (nErr = apps_std_getenv(envvarname, envList, - envListPrependLen, &listLen))); - } - strlcat(envList, ADSP_AVS_CFG_PATH, envListPrependLen); - envListLen = envListPrependLen; - } else { - envListLen = listLen; - } - } else if (strncmp(envvarname, ADSP_LIBRARY_PATH, - strlen(ADSP_LIBRARY_PATH)) == 0 || - strncmp(envvarname, DSP_LIBRARY_PATH, - strlen(DSP_LIBRARY_PATH)) == 0) { - envListLen = listLen = - 1 + strlcpy(envListBuf, DSP_SEARCH_PATH, envLenGuess); - } else if (strncmp(envvarname, ADSP_AVS_PATH, - strlen(ADSP_AVS_PATH)) == 0) { - envListLen = listLen = - 1 + strlcpy(envListBuf, ADSP_AVS_CFG_PATH, envLenGuess); - } - - /* - * Allocate mem. to copy envvarname. - */ - if ('\0' != *envList) { - srcStr = envList; - } else { - envListLen = strlen(EMTPY_STR) + 1; - } - VERIFYC(dirListBuf = (char *)malloc(sizeof(char) * envListLen), - AEE_ENOMEMORY); - dirList = dirListBuf; - VERIFYC(srcStr != NULL, AEE_EBADPARM); - strlcpy(dirList, srcStr, envListLen); - *ppDirList = dirListBuf; +static int +get_dirlist_from_env(const char *envvarname, char **ppDirList) +{ + char *envList = NULL; + char *envListBuf = NULL; + char *dirList = NULL; + char *dirListBuf = NULL; + char *srcStr = NULL; + int nErr = AEE_SUCCESS; + int envListLen = 0; + int envListPrependLen = 0; + int listLen = 0; + int envLenGuess = STD_MAX(ENV_LEN_GUESS, 1 + strlen(DSP_SEARCH_PATH)); + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFYC(NULL != ppDirList, AEE_ERPC); + + VERIFYC(envListBuf = (char *)malloc(sizeof(char) * envLenGuess), + AEE_ENOMEMORY); + envList = envListBuf; + *envList = '\0'; + if(0 + == apps_std_getenv(envvarname, envList, envLenGuess, &envListLen)) { + if(strncmp(envvarname, ADSP_LIBRARY_PATH, + strlen(ADSP_LIBRARY_PATH)) + == 0 + || strncmp(envvarname, DSP_LIBRARY_PATH, + strlen(DSP_LIBRARY_PATH)) + == 0) { + // Calculate total length of env and DSP_SEARCH_PATH + envListPrependLen + = envListLen + strlen(DSP_SEARCH_PATH); + if(envLenGuess < envListPrependLen) { + FREEIF(envListBuf); + VERIFYC(envListBuf = realloc( + envListBuf, + sizeof(char) * envListPrependLen), + AEE_ENOMEMORY); + envList = envListBuf; + VERIFY(0 + == (nErr = apps_std_getenv( + envvarname, envList, + envListPrependLen, &listLen))); + } + // Append default DSP_SEARCH_PATH to user defined env + strlcat(envList, DSP_SEARCH_PATH, envListPrependLen); + envListLen = envListPrependLen; + } else if(strncmp(envvarname, ADSP_AVS_PATH, + strlen(ADSP_AVS_PATH)) + == 0) { + envListPrependLen + = envListLen + strlen(ADSP_AVS_CFG_PATH); + if(envLenGuess < envListPrependLen) { + FREEIF(envListBuf); + VERIFYC(envListBuf = realloc( + envListBuf, + sizeof(char) * envListPrependLen), + AEE_ENOMEMORY); + envList = envListBuf; + VERIFY(0 + == (nErr = apps_std_getenv( + envvarname, envList, + envListPrependLen, &listLen))); + } + strlcat(envList, ADSP_AVS_CFG_PATH, envListPrependLen); + envListLen = envListPrependLen; + } else { + envListLen = listLen; + } + } else if(strncmp(envvarname, ADSP_LIBRARY_PATH, + strlen(ADSP_LIBRARY_PATH)) + == 0 + || strncmp(envvarname, DSP_LIBRARY_PATH, + strlen(DSP_LIBRARY_PATH)) + == 0) { + envListLen = listLen + = 1 + strlcpy(envListBuf, DSP_SEARCH_PATH, envLenGuess); + } else if(strncmp(envvarname, ADSP_AVS_PATH, strlen(ADSP_AVS_PATH)) + == 0) { + envListLen = listLen + = 1 + strlcpy(envListBuf, ADSP_AVS_CFG_PATH, envLenGuess); + } + + /* + * Allocate mem. to copy envvarname. + */ + if('\0' != *envList) { + srcStr = envList; + } else { + envListLen = strlen(EMTPY_STR) + 1; + } + VERIFYC(dirListBuf = (char *)malloc(sizeof(char) * envListLen), + AEE_ENOMEMORY); + dirList = dirListBuf; + VERIFYC(srcStr != NULL, AEE_EBADPARM); + strlcpy(dirList, srcStr, envListLen); + *ppDirList = dirListBuf; bail: - FREEIF(envListBuf); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: get dirlist from env failed for %s\n", nErr, - envvarname); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for %s, err %d", __func__, envvarname, - nErr); - return nErr; + FREEIF(envListBuf); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: get dirlist from env failed for %s\n", nErr, + envvarname); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for %s, err %d", __func__, + envvarname, nErr); + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fopen_with_env)( +__QAIC_IMPL_EXPORT int +__QAIC_IMPL(apps_std_fopen_with_env)( const char *envvarname, const char *delim, const char *name, - const char *mode, apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE { - - int nErr = AEE_SUCCESS; - char *dirName = NULL; - char *pos = NULL; - char *dirListBuf = NULL; - char *dirList = NULL; - char *absName = NULL; - const char *envVar = NULL; - uint16_t absNameLen = 0; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFYC(NULL != mode, AEE_EBADPARM); - VERIFYC(NULL != delim, AEE_EBADPARM); - VERIFYC(NULL != name, AEE_EBADPARM); - VERIFYC(NULL != envvarname, AEE_EBADPARM); - FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode from path in environment " - "variable %s delimited with %s", - __func__, name, mode, envvarname, delim); - if (strncmp(envvarname, ADSP_LIBRARY_PATH, - strlen(ADSP_LIBRARY_PATH)) == 0) { - if (getenv(DSP_LIBRARY_PATH)) { - envVar = DSP_LIBRARY_PATH; - } else { - envVar = ADSP_LIBRARY_PATH; - } - } else { - envVar = envvarname; - } - - VERIFY(0 == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); - VERIFYC(NULL != (dirList = dirListBuf), AEE_EBADPARM); - FARF(RUNTIME_RPC_HIGH, "%s dirList %s", __func__, dirList); - - while (dirList) { - pos = strstr(dirList, delim); - dirName = dirList; - if (pos) { - *pos = '\0'; - dirList = pos + strlen(delim); - } else { - dirList = 0; - } - - // Append domain to path - absNameLen = - strlen(dirName) + strlen(name) + 2 + strlen("adsp") + 1; - VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - if ('\0' != *dirName) { - strlcpy(absName, dirName, absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, name, absNameLen); - } else { - strlcpy(absName, name, absNameLen); - } - - nErr = apps_std_fopen(absName, mode, psout); - if (AEE_SUCCESS == nErr) { - // Success - FARF(ALWAYS, "Successfully opened file %s", absName); - goto bail; - } - FREEIF(absName); - - // fallback: If not found in domain path /vendor/dsp/adsp try in /vendor/dsp - absNameLen = strlen(dirName) + strlen(name) + 2; - VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - if ('\0' != *dirName) { - strlcpy(absName, dirName, absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, name, absNameLen); - } else { - strlcpy(absName, name, absNameLen); - } - - nErr = apps_std_fopen(absName, mode, psout); - if (AEE_SUCCESS == nErr) { - // Success - if (name != NULL && - (strncmp(name, OEM_CONFIG_FILE_NAME, - strlen(OEM_CONFIG_FILE_NAME)) != 0) && - (strncmp(name, TESTSIG_FILE_NAME, - strlen(TESTSIG_FILE_NAME)) != 0)) - FARF(ALWAYS, "Successfully opened file %s", name); - goto bail; - } - FREEIF(absName); - } + const char *mode, apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE +{ + + int nErr = AEE_SUCCESS; + char *dirName = NULL; + char *pos = NULL; + char *dirListBuf = NULL; + char *dirList = NULL; + char *absName = NULL; + const char *envVar = NULL; + uint16_t absNameLen = 0; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFYC(NULL != mode, AEE_EBADPARM); + VERIFYC(NULL != delim, AEE_EBADPARM); + VERIFYC(NULL != name, AEE_EBADPARM); + VERIFYC(NULL != envvarname, AEE_EBADPARM); + FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode from path in environment " + "variable %s delimited with %s", + __func__, name, mode, envvarname, delim); + if(strncmp(envvarname, ADSP_LIBRARY_PATH, strlen(ADSP_LIBRARY_PATH)) + == 0) { + if(getenv(DSP_LIBRARY_PATH)) { + envVar = DSP_LIBRARY_PATH; + } else { + envVar = ADSP_LIBRARY_PATH; + } + } else { + envVar = envvarname; + } + + VERIFY(0 == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); + VERIFYC(NULL != (dirList = dirListBuf), AEE_EBADPARM); + FARF(RUNTIME_RPC_HIGH, "%s dirList %s", __func__, dirList); + + while(dirList) { + pos = strstr(dirList, delim); + dirName = dirList; + if(pos) { + *pos = '\0'; + dirList = pos + strlen(delim); + } else { + dirList = 0; + } + + // Append domain to path + absNameLen + = strlen(dirName) + strlen(name) + 2 + strlen("adsp") + 1; + VERIFYC(NULL + != (absName + = (char *)malloc(sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + if('\0' != *dirName) { + strlcpy(absName, dirName, absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, name, absNameLen); + } else { + strlcpy(absName, name, absNameLen); + } + + nErr = apps_std_fopen(absName, mode, psout); + if(AEE_SUCCESS == nErr) { + // Success + FARF(ALWAYS, "Successfully opened file %s", absName); + goto bail; + } + FREEIF(absName); + + // fallback: If not found in domain path /vendor/dsp/adsp try + // in /vendor/dsp + absNameLen = strlen(dirName) + strlen(name) + 2; + VERIFYC(NULL + != (absName + = (char *)malloc(sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + if('\0' != *dirName) { + strlcpy(absName, dirName, absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, name, absNameLen); + } else { + strlcpy(absName, name, absNameLen); + } + + nErr = apps_std_fopen(absName, mode, psout); + if(AEE_SUCCESS == nErr) { + // Success + if(name != NULL + && (strncmp(name, OEM_CONFIG_FILE_NAME, + strlen(OEM_CONFIG_FILE_NAME)) + != 0) + && (strncmp(name, TESTSIG_FILE_NAME, + strlen(TESTSIG_FILE_NAME)) + != 0)) + FARF(ALWAYS, "Successfully opened file %s", + name); + goto bail; + } + FREEIF(absName); + } bail: - FREEIF(absName); - FREEIF(dirListBuf); - if (nErr != AEE_SUCCESS) { - if (ERRNO != ENOENT || - (name != NULL && - strncmp(name, OEM_CONFIG_FILE_NAME, - strlen(OEM_CONFIG_FILE_NAME)) != 0 && - strncmp(name, RPC_VERSION_FILE_NAME, - strlen(RPC_VERSION_FILE_NAME)) != 0 && - strncmp(name, TESTSIG_FILE_NAME, strlen(TESTSIG_FILE_NAME)) != - 0)) - VERIFY_WPRINTF(" Warning: %s failed with 0x%x for %s (%s)", __func__, - nErr, name, strerror(ERRNO)); - } - FARF(RUNTIME_RPC_LOW, - "Exiting %s for %s envvarname %s mode %s delim %s, err %d", __func__, - name, envvarname, mode, delim, nErr); - if (name && mode && envvarname && delim) { - FASTRPC_ATRACE_END(); - } - return nErr; + FREEIF(absName); + FREEIF(dirListBuf); + if(nErr != AEE_SUCCESS) { + if(ERRNO != ENOENT + || (name != NULL + && strncmp(name, OEM_CONFIG_FILE_NAME, + strlen(OEM_CONFIG_FILE_NAME)) + != 0 + && strncmp(name, RPC_VERSION_FILE_NAME, + strlen(RPC_VERSION_FILE_NAME)) + != 0 + && strncmp(name, TESTSIG_FILE_NAME, + strlen(TESTSIG_FILE_NAME)) + != 0)) + VERIFY_WPRINTF( + " Warning: %s failed with 0x%x for %s (%s)", + __func__, nErr, name, strerror(ERRNO)); + } + FARF(RUNTIME_RPC_LOW, + "Exiting %s for %s envvarname %s mode %s delim %s, err %d", + __func__, name, envvarname, mode, delim, nErr); + if(name && mode && envvarname && delim) { + FASTRPC_ATRACE_END(); + } + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fopen_with_env_fd)( - const char *envvarname, const char *delim, const char *name, - const char *mode, int *fd, int *len) __QAIC_IMPL_ATTRIBUTE { - - int nErr = ENOENT, err = ENOENT; - char *dirName = NULL; - char *pos = NULL; - char *dirListBuf = NULL; - char *dirList = NULL; - char *absName = NULL; - char *errabsName = NULL; - const char *envVar = NULL; - uint16_t absNameLen = 0; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFYC(NULL != mode, AEE_EBADPARM); - VERIFYC(NULL != delim, AEE_EBADPARM); - VERIFYC(NULL != name, AEE_EBADPARM); - VERIFYC(NULL != envvarname, AEE_EBADPARM); -#if 0 //TODO: Bharath +__QAIC_IMPL_EXPORT int +__QAIC_IMPL(apps_std_fopen_with_env_fd)(const char *envvarname, + const char *delim, const char *name, + const char *mode, int *fd, + int *len) __QAIC_IMPL_ATTRIBUTE +{ + + int nErr = ENOENT, err = ENOENT; + char *dirName = NULL; + char *pos = NULL; + char *dirListBuf = NULL; + char *dirList = NULL; + char *absName = NULL; + char *errabsName = NULL; + const char *envVar = NULL; + uint16_t absNameLen = 0; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFYC(NULL != mode, AEE_EBADPARM); + VERIFYC(NULL != delim, AEE_EBADPARM); + VERIFYC(NULL != name, AEE_EBADPARM); + VERIFYC(NULL != envvarname, AEE_EBADPARM); +#if 0 // TODO: Bharath char *tempName = name; tempName += 2; if (tempName[0] == '\0') { @@ -1165,615 +1283,667 @@ __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fopen_with_env_fd)( goto bail; } #endif - FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode from path in environment " - "variable %s delimited with %s", - __func__, name, mode, envvarname, delim); - if (strncmp(envvarname, ADSP_LIBRARY_PATH, - strlen(ADSP_LIBRARY_PATH)) == 0) { - if (getenv(DSP_LIBRARY_PATH)) { - envVar = DSP_LIBRARY_PATH; - } else { - envVar = ADSP_LIBRARY_PATH; - } - } else { - envVar = envvarname; - } - - VERIFY(0 == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); - VERIFYC(NULL != (dirList = dirListBuf), AEE_EBADPARM); - - while (dirList) { - pos = strstr(dirList, delim); - dirName = dirList; - if (pos) { - *pos = '\0'; - dirList = pos + strlen(delim); - } else { - dirList = 0; - } - - // Append domain to path - absNameLen = - strlen(dirName) + strlen(name) + 2 + strlen("adsp") + 1; - VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - if ('\0' != *dirName) { - strlcpy(absName, dirName, absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, name, absNameLen); - } else { - strlcpy(absName, name, absNameLen); - } - - err = apps_std_fopen_fd(absName, mode, fd, len); - if (AEE_SUCCESS == err) { - // Success - FARF(ALWAYS, "Successfully opened file %s", absName); - goto bail; - } - /* Do not Update nErr if error is no such file, as it may not be - * genuine error until we find in all path's. - */ - if (err != ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) { - nErr = err; - errabsName = absName; - absName = NULL; - } - FREEIF(absName); - - // fallback: If not found in domain path /vendor/dsp/adsp try in /vendor/dsp - absNameLen = strlen(dirName) + strlen(name) + 2; - VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - if ('\0' != *dirName) { - strlcpy(absName, dirName, absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, name, absNameLen); - } else { - strlcpy(absName, name, absNameLen); - } - - err = apps_std_fopen_fd(absName, mode, fd, len); - if (AEE_SUCCESS == err) { - // Success - FARF(ALWAYS, "Successfully opened file %s", absName); - nErr = err; - goto bail; - } - /* Do not Update nErr if error is no such file, as it may not be - * genuine error until we find in all path's. - */ - if (err != ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) { - nErr = err; - errabsName = absName; - absName = NULL; - } - FREEIF(absName); - } - /* In case if file is not present in any path update - * error code to no such file. - */ - if (err == ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) - nErr = err; + FASTRPC_ATRACE_BEGIN_L("%s for %s in %s mode from path in environment " + "variable %s delimited with %s", + __func__, name, mode, envvarname, delim); + if(strncmp(envvarname, ADSP_LIBRARY_PATH, strlen(ADSP_LIBRARY_PATH)) + == 0) { + if(getenv(DSP_LIBRARY_PATH)) { + envVar = DSP_LIBRARY_PATH; + } else { + envVar = ADSP_LIBRARY_PATH; + } + } else { + envVar = envvarname; + } + + VERIFY(0 == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); + VERIFYC(NULL != (dirList = dirListBuf), AEE_EBADPARM); + + while(dirList) { + pos = strstr(dirList, delim); + dirName = dirList; + if(pos) { + *pos = '\0'; + dirList = pos + strlen(delim); + } else { + dirList = 0; + } + + // Append domain to path + absNameLen + = strlen(dirName) + strlen(name) + 2 + strlen("adsp") + 1; + VERIFYC(NULL + != (absName + = (char *)malloc(sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + if('\0' != *dirName) { + strlcpy(absName, dirName, absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, name, absNameLen); + } else { + strlcpy(absName, name, absNameLen); + } + + err = apps_std_fopen_fd(absName, mode, fd, len); + if(AEE_SUCCESS == err) { + // Success + FARF(ALWAYS, "Successfully opened file %s", absName); + goto bail; + } + /* Do not Update nErr if error is no such file, as it may not + * be genuine error until we find in all path's. + */ + if(err != ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) { + nErr = err; + errabsName = absName; + absName = NULL; + } + FREEIF(absName); + + // fallback: If not found in domain path /vendor/dsp/adsp try + // in /vendor/dsp + absNameLen = strlen(dirName) + strlen(name) + 2; + VERIFYC(NULL + != (absName + = (char *)malloc(sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + if('\0' != *dirName) { + strlcpy(absName, dirName, absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, name, absNameLen); + } else { + strlcpy(absName, name, absNameLen); + } + + err = apps_std_fopen_fd(absName, mode, fd, len); + if(AEE_SUCCESS == err) { + // Success + FARF(ALWAYS, "Successfully opened file %s", absName); + nErr = err; + goto bail; + } + /* Do not Update nErr if error is no such file, as it may not + * be genuine error until we find in all path's. + */ + if(err != ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) { + nErr = err; + errabsName = absName; + absName = NULL; + } + FREEIF(absName); + } + /* In case if file is not present in any path update + * error code to no such file. + */ + if(err == ENOENT && (nErr == ENOENT || nErr == AEE_SUCCESS)) + nErr = err; bail: - if (nErr != AEE_SUCCESS) { - if (ERRNO != ENOENT || - (name != NULL && - strncmp(name, OEM_CONFIG_FILE_NAME, - strlen(OEM_CONFIG_FILE_NAME)) != 0 && - strncmp(name, RPC_VERSION_FILE_NAME, - strlen(RPC_VERSION_FILE_NAME)) != 0 && - strncmp(name, TESTSIG_FILE_NAME, strlen(TESTSIG_FILE_NAME)) != - 0)) { - if (errabsName) { - VERIFY_WPRINTF(" Warning: %s failed with 0x%x for path %s name %s (%s)", - __func__, nErr, errabsName, name, strerror(ERRNO)); - } else { - VERIFY_WPRINTF(" Warning: %s failed with 0x%x for %s (%s)", __func__, - nErr, name, strerror(ERRNO)); - } - } - } - - FREEIF(errabsName); - FREEIF(absName); - FREEIF(dirListBuf); - FARF(RUNTIME_RPC_LOW, - "Exiting %s for %s envvarname %s mode %s delim %s, err %d", __func__, - name, envvarname, mode, delim, nErr); - if (name && mode && envvarname && delim) { - FASTRPC_ATRACE_END(); - } - return nErr; + if(nErr != AEE_SUCCESS) { + if(ERRNO != ENOENT + || (name != NULL + && strncmp(name, OEM_CONFIG_FILE_NAME, + strlen(OEM_CONFIG_FILE_NAME)) + != 0 + && strncmp(name, RPC_VERSION_FILE_NAME, + strlen(RPC_VERSION_FILE_NAME)) + != 0 + && strncmp(name, TESTSIG_FILE_NAME, + strlen(TESTSIG_FILE_NAME)) + != 0)) { + if(errabsName) { + VERIFY_WPRINTF(" Warning: %s failed with 0x%x " + "for path %s name %s (%s)", + __func__, nErr, errabsName, + name, strerror(ERRNO)); + } else { + VERIFY_WPRINTF(" Warning: %s failed with 0x%x " + "for %s (%s)", + __func__, nErr, name, + strerror(ERRNO)); + } + } + } + + FREEIF(errabsName); + FREEIF(absName); + FREEIF(dirListBuf); + FARF(RUNTIME_RPC_LOW, + "Exiting %s for %s envvarname %s mode %s delim %s, err %d", + __func__, name, envvarname, mode, delim, nErr); + if(name && mode && envvarname && delim) { + FASTRPC_ATRACE_END(); + } + return nErr; } -__QAIC_HEADER_EXPORT int __QAIC_IMPL(apps_std_get_search_paths_with_env)( - const char *envvarname, const char *delim, _cstring1_t *paths, int pathsLen, - uint32_t *numPaths, uint16_t *maxPathLen) __QAIC_IMPL_ATTRIBUTE { - - char *path = NULL; - char *pathDomain = NULL; - int pathDomainLen = 0; - int nErr = AEE_SUCCESS; - char *dirListBuf = NULL; - int i = 0; - char *saveptr = NULL; - const char *envVar = NULL; - struct stat st; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); - - FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); - VERIFYC(NULL != numPaths, AEE_EBADPARM); - VERIFYC(NULL != delim, AEE_EBADPARM); - VERIFYC(NULL != maxPathLen, AEE_EBADPARM); - - if (strncmp(envvarname, ADSP_LIBRARY_PATH, - strlen(ADSP_LIBRARY_PATH)) == 0) { - if (getenv(DSP_LIBRARY_PATH)) { - envVar = DSP_LIBRARY_PATH; - } else { - envVar = ADSP_LIBRARY_PATH; - } - } else { - envVar = envvarname; - } - - VERIFY(AEE_SUCCESS == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); - - *numPaths = 0; - *maxPathLen = 0; - - // Get the number of folders - path = strtok_r(dirListBuf, delim, &saveptr); - while (path != NULL) { - pathDomainLen = strlen(path) + 1 + strlen("adsp") + 1; - VERIFYC(pathDomain = (char *)malloc(sizeof(char) * (pathDomainLen)), - AEE_ENOMEMORY); - strlcpy(pathDomain, path, pathDomainLen); - strlcat(pathDomain, "/", pathDomainLen); - strlcat(pathDomain, SUBSYSTEM_NAME[domain], pathDomainLen); - // If the path exists, add it to the return - if ((stat(pathDomain, &st) == 0) && (S_ISDIR(st.st_mode))) { - *maxPathLen = STD_MAX(*maxPathLen, strlen(pathDomain) + 1); - if (paths && i < pathsLen && paths[i].data && - paths[i].dataLen >= (int)strlen(path)) { - strlcpy(paths[i].data, pathDomain, paths[i].dataLen); - } - i++; - } - if ((stat(path, &st) == 0) && (S_ISDIR(st.st_mode))) { - *maxPathLen = STD_MAX(*maxPathLen, strlen(path) + 1); - if (paths && i < pathsLen && paths[i].data && - paths[i].dataLen >= (int)strlen(path)) { - strlcpy(paths[i].data, path, paths[i].dataLen); - } - i++; - } - path = strtok_r(NULL, delim, &saveptr); - FREEIF(pathDomain); - } - *numPaths = i; +__QAIC_HEADER_EXPORT int +__QAIC_IMPL(apps_std_get_search_paths_with_env)( + const char *envvarname, const char *delim, _cstring1_t *paths, + int pathsLen, uint32_t *numPaths, + uint16_t *maxPathLen) __QAIC_IMPL_ATTRIBUTE +{ + + char *path = NULL; + char *pathDomain = NULL; + int pathDomainLen = 0; + int nErr = AEE_SUCCESS; + char *dirListBuf = NULL; + int i = 0; + char *saveptr = NULL; + const char *envVar = NULL; + struct stat st; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(get_current_domain()); + + FARF(RUNTIME_RPC_LOW, "Entering %s", __func__); + VERIFYC(NULL != numPaths, AEE_EBADPARM); + VERIFYC(NULL != delim, AEE_EBADPARM); + VERIFYC(NULL != maxPathLen, AEE_EBADPARM); + + if(strncmp(envvarname, ADSP_LIBRARY_PATH, strlen(ADSP_LIBRARY_PATH)) + == 0) { + if(getenv(DSP_LIBRARY_PATH)) { + envVar = DSP_LIBRARY_PATH; + } else { + envVar = ADSP_LIBRARY_PATH; + } + } else { + envVar = envvarname; + } + + VERIFY(AEE_SUCCESS + == (nErr = get_dirlist_from_env(envVar, &dirListBuf))); + + *numPaths = 0; + *maxPathLen = 0; + + // Get the number of folders + path = strtok_r(dirListBuf, delim, &saveptr); + while(path != NULL) { + pathDomainLen = strlen(path) + 1 + strlen("adsp") + 1; + VERIFYC(pathDomain + = (char *)malloc(sizeof(char) * (pathDomainLen)), + AEE_ENOMEMORY); + strlcpy(pathDomain, path, pathDomainLen); + strlcat(pathDomain, "/", pathDomainLen); + strlcat(pathDomain, SUBSYSTEM_NAME[domain], pathDomainLen); + // If the path exists, add it to the return + if((stat(pathDomain, &st) == 0) && (S_ISDIR(st.st_mode))) { + *maxPathLen + = STD_MAX(*maxPathLen, strlen(pathDomain) + 1); + if(paths && i < pathsLen && paths[i].data + && paths[i].dataLen >= (int)strlen(path)) { + strlcpy(paths[i].data, pathDomain, + paths[i].dataLen); + } + i++; + } + if((stat(path, &st) == 0) && (S_ISDIR(st.st_mode))) { + *maxPathLen = STD_MAX(*maxPathLen, strlen(path) + 1); + if(paths && i < pathsLen && paths[i].data + && paths[i].dataLen >= (int)strlen(path)) { + strlcpy(paths[i].data, path, paths[i].dataLen); + } + i++; + } + path = strtok_r(NULL, delim, &saveptr); + FREEIF(pathDomain); + } + *numPaths = i; bail: - FREEIF(dirListBuf); - FREEIF(pathDomain); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: apps_std_get_search_paths_with_env failed\n", - nErr); - } - FARF(RUNTIME_RPC_LOW, "Exiting %s for envvarname %s delim %s, err %d", - __func__, envvarname, delim, nErr); - return nErr; + FREEIF(dirListBuf); + FREEIF(pathDomain); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: apps_std_get_search_paths_with_env failed\n", + nErr); + } + FARF(RUNTIME_RPC_LOW, "Exiting %s for envvarname %s delim %s, err %d", + __func__, envvarname, delim, nErr); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fgets)(apps_std_FILE sin, unsigned char *buf, int bufLen, - int *bEOF) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x for buflen %d", __func__, - sin, bufLen); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - char *out = fgets((char *)buf, bufLen, sinfo->u.stream); - *bEOF = false; - if (!out) { - int err = 0; - if (0 != (err = ferror(sinfo->u.stream))) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: fgets failed for %x, errno is %s\n", nErr, - sin, strerror(ERRNO)); - goto bail; - } - *bEOF = feof(sinfo->u.stream); - } - } else { - nErr = EBADF; - } + int *bEOF) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x for buflen %d", + __func__, sin, bufLen); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + char *out = fgets((char *)buf, bufLen, sinfo->u.stream); + *bEOF = false; + if(!out) { + int err = 0; + if(0 != (err = ferror(sinfo->u.stream))) { + nErr = ERRNO; + VERIFY_EPRINTF("Error 0x%x: fgets failed for " + "%x, errno is %s\n", + nErr, sin, strerror(ERRNO)); + goto bail; + } + *bEOF = feof(sinfo->u.stream); + } + } else { + nErr = EBADF; + } bail: - FASTRPC_ATRACE_END(); - return nErr; + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_fileExists)(const char *path, - bool *exists) __QAIC_HEADER_ATTRIBUTE { - int nErr = AEE_SUCCESS, err = 0; - struct stat buffer; + bool *exists) __QAIC_HEADER_ATTRIBUTE +{ + int nErr = AEE_SUCCESS, err = 0; + struct stat buffer; - VERIFYC(path != NULL, AEE_EBADPARM); - VERIFYC(exists != NULL, AEE_EBADPARM); + VERIFYC(path != NULL, AEE_EBADPARM); + VERIFYC(exists != NULL, AEE_EBADPARM); - errno = 0; - *exists = (stat(path, &buffer) == 0); - err = errno; + errno = 0; + *exists = (stat(path, &buffer) == 0); + err = errno; bail: - if (nErr != AEE_SUCCESS || err) { - FARF(RUNTIME_RPC_HIGH, - "Warniing 0x%x: fileExists failed for path %s, errno is %s\n", nErr, - path, strerror(err)); - } - return nErr; + if(nErr != AEE_SUCCESS || err) { + FARF(RUNTIME_RPC_HIGH, + "Warniing 0x%x: fileExists failed for path %s, errno is " + "%s\n", + nErr, path, strerror(err)); + } + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fsync)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_info *sinfo = 0; - - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - // This flushes the given sin file stream to user-space buffer. - // NOTE: this does NOT ensure data is physically sotred on disk - nErr = fflush(sinfo->u.stream); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: apps_std fsync failed,errno is %s\n", nErr, - strerror(ERRNO)); - } - } else { - nErr = EBADF; - } +__QAIC_IMPL(apps_std_fsync)(apps_std_FILE sin) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_info *sinfo = 0; + + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + // This flushes the given sin file stream to user-space buffer. + // NOTE: this does NOT ensure data is physically sotred on disk + nErr = fflush(sinfo->u.stream); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: apps_std fsync failed,errno is %s\n", + nErr, strerror(ERRNO)); + } + } else { + nErr = EBADF; + } bail: - return nErr; + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_std_fremove)(const char *name) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - - if (NULL == name) { - return EINVAL; - } - FASTRPC_ATRACE_BEGIN_L("%s for file %s", __func__, name); - nErr = remove(name); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: failed to remove file %s,errno is %s\n", nErr, - name, strerror(ERRNO)); - } - FASTRPC_ATRACE_END(); - return nErr; +__QAIC_IMPL(apps_std_fremove)(const char *name) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + + if(NULL == name) { + return EINVAL; + } + FASTRPC_ATRACE_BEGIN_L("%s for file %s", __func__, name); + nErr = remove(name); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: failed to remove file %s,errno is %s\n", nErr, + name, strerror(ERRNO)); + } + FASTRPC_ATRACE_END(); + return nErr; } -static int decrypt_int(char *fbuf, int size) { - int nErr = 0, fd; - void *handle = 0; - int32_t (*l_init)(void); - int32_t (*l_deinit)(void); - int32_t (*l_decrypt)(int32_t, int32_t); - - VERIFYC(NULL != (handle = dlopen("liblmclient.so", RTLD_NOW)), - AEE_EINVHANDLE); - VERIFYM(NULL != (l_init = dlsym(handle, "license_manager_init")), AEE_ERPC, - "Error: %s failed symbol license_manager_init not found err 0x%x " - "errno is %s", - __func__, nErr, strerror(ERRNO)); - VERIFYM(NULL != (l_deinit = dlsym(handle, "license_manager_deinit")), - AEE_ERPC, - "Error: %s failed symbol license_manager_deinit not found err 0x%x " - "errno is %s", - __func__, nErr, strerror(ERRNO)); - VERIFYM(NULL != (l_decrypt = dlsym(handle, "license_manager_decrypt")), - AEE_ERPC, - "Error: %s failed symbol license_manager_decrypt not found err 0x%x " - "errno is %s", - __func__, nErr, strerror(ERRNO)); - VERIFY(0 == (nErr = l_init())); - VERIFYC(-1 != (fd = rpcmem_to_fd_internal(fbuf)), AEE_ERPC); - VERIFY(0 == (nErr = l_decrypt(fd, size))); - VERIFY(0 == (nErr = l_deinit())); +static int +decrypt_int(char *fbuf, int size) +{ + int nErr = 0, fd; + void *handle = 0; + int32_t (*l_init)(void); + int32_t (*l_deinit)(void); + int32_t (*l_decrypt)(int32_t, int32_t); + + VERIFYC(NULL != (handle = dlopen("liblmclient.so", RTLD_NOW)), + AEE_EINVHANDLE); + VERIFYM( + NULL != (l_init = dlsym(handle, "license_manager_init")), AEE_ERPC, + "Error: %s failed symbol license_manager_init not found err 0x%x " + "errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFYM(NULL != (l_deinit = dlsym(handle, "license_manager_deinit")), + AEE_ERPC, + "Error: %s failed symbol license_manager_deinit not found err " + "0x%x " + "errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFYM(NULL != (l_decrypt = dlsym(handle, "license_manager_decrypt")), + AEE_ERPC, + "Error: %s failed symbol license_manager_decrypt not found " + "err 0x%x " + "errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFY(0 == (nErr = l_init())); + VERIFYC(-1 != (fd = rpcmem_to_fd_internal(fbuf)), AEE_ERPC); + VERIFY(0 == (nErr = l_decrypt(fd, size))); + VERIFY(0 == (nErr = l_deinit())); bail: - if (nErr) { - VERIFY_EPRINTF("Error 0x%x: dlopen for licmgr failed. errno: %s\n", nErr, - dlerror()); - } - if (handle) { - dlclose(handle); - } - return nErr; + if(nErr) { + VERIFY_EPRINTF( + "Error 0x%x: dlopen for licmgr failed. errno: %s\n", nErr, + dlerror()); + } + if(handle) { + dlclose(handle); + } + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_fdopen_decrypt)( - apps_std_FILE sin, apps_std_FILE *psout) __QAIC_IMPL_ATTRIBUTE { - int fd, nErr = AEE_SUCCESS; - struct stat st_buf; - struct apps_std_info *sinfo = 0; - int sz, pos; - char *fbuf = 0; - - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - if (sinfo->type == APPS_STD_STREAM_FILE) { - pos = ftell(sinfo->u.stream); - VERIFYM(-1 != (fd = fileno(sinfo->u.stream)), AEE_EFILE, - "Error: %s failed file len is not proper err 0x%x errno is %s", - __func__, nErr, strerror(ERRNO)); - VERIFYM(0 == fstat(fd, &st_buf), AEE_EFILE, - "Error: %s failed file len is not proper err 0x%x errno is %s", - __func__, nErr, strerror(ERRNO)); - sz = (int)st_buf.st_size; - VERIFYC( - 0 != (fbuf = rpcmem_alloc_internal(ION_HEAP_ID_QSEECOM, 1, (size_t)sz)), - AEE_ENORPCMEMORY); - VERIFYM(0 == fseek(sinfo->u.stream, 0, SEEK_SET), AEE_EFILE, - "Error: %s failed as fseek failed err 0x%x errno is %s", __func__, - nErr, strerror(ERRNO)); - VERIFYM(sz == (int)fread(fbuf, 1, sz, sinfo->u.stream), AEE_EFILE, - "Error: %s failed as fread failed err 0x%x errno is %s", __func__, - nErr, strerror(ERRNO)); - VERIFY(0 == (nErr = decrypt_int(fbuf, sz))); - apps_std_FILE_set_buffer_stream(sinfo, fbuf, sz, pos); - *psout = sin; - } else { - nErr = EBADF; - } +__QAIC_IMPL_EXPORT int +__QAIC_IMPL(apps_std_fdopen_decrypt)(apps_std_FILE sin, apps_std_FILE *psout) + __QAIC_IMPL_ATTRIBUTE +{ + int fd, nErr = AEE_SUCCESS; + struct stat st_buf; + struct apps_std_info *sinfo = 0; + int sz, pos; + char *fbuf = 0; + + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + if(sinfo->type == APPS_STD_STREAM_FILE) { + pos = ftell(sinfo->u.stream); + VERIFYM(-1 != (fd = fileno(sinfo->u.stream)), AEE_EFILE, + "Error: %s failed file len is not proper err 0x%x " + "errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFYM(0 == fstat(fd, &st_buf), AEE_EFILE, + "Error: %s failed file len is not proper err 0x%x " + "errno is %s", + __func__, nErr, strerror(ERRNO)); + sz = (int)st_buf.st_size; + VERIFYC(0 + != (fbuf = rpcmem_alloc_internal( + ION_HEAP_ID_QSEECOM, 1, (size_t)sz)), + AEE_ENORPCMEMORY); + VERIFYM( + 0 == fseek(sinfo->u.stream, 0, SEEK_SET), AEE_EFILE, + "Error: %s failed as fseek failed err 0x%x errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFYM( + sz == (int)fread(fbuf, 1, sz, sinfo->u.stream), AEE_EFILE, + "Error: %s failed as fread failed err 0x%x errno is %s", + __func__, nErr, strerror(ERRNO)); + VERIFY(0 == (nErr = decrypt_int(fbuf, sz))); + apps_std_FILE_set_buffer_stream(sinfo, fbuf, sz, pos); + *psout = sin; + } else { + nErr = EBADF; + } bail: - if (nErr) { - if (fbuf) { - rpcmem_free_internal(fbuf); - fbuf = NULL; - } - } - return nErr; + if(nErr) { + if(fbuf) { + rpcmem_free_internal(fbuf); + fbuf = NULL; + } + } + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_HEADER(apps_std_opendir)(const char *name, - apps_std_DIR *dir) __QAIC_IMPL_ATTRIBUTE { - int nErr = 0; - DIR *odir; - struct apps_std_dir_info *dirinfo = 0; - - if (NULL == dir) { - return EINVAL; - } - if (name == NULL) - return AEE_EBADPARM; - errno = 0; - odir = opendir(name); - if (odir != NULL) { - dir->handle = (uint64_t)odir; - dirinfo = - (struct apps_std_dir_info *)calloc(1, sizeof(struct apps_std_dir_info)); - VERIFYC(dirinfo != NULL, ENOMEM); - dirinfo->handle = dir->handle; - pthread_mutex_lock(&apps_std_mt); - QList_AppendNode(&apps_std_dirlist, &dirinfo->qn); - pthread_mutex_unlock(&apps_std_mt); - } else { - nErr = ERRNO; - } + apps_std_DIR *dir) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = 0; + DIR *odir; + struct apps_std_dir_info *dirinfo = 0; + + if(NULL == dir) { + return EINVAL; + } + if(name == NULL) + return AEE_EBADPARM; + errno = 0; + odir = opendir(name); + if(odir != NULL) { + dir->handle = (uint64_t)odir; + dirinfo = (struct apps_std_dir_info *)calloc( + 1, sizeof(struct apps_std_dir_info)); + VERIFYC(dirinfo != NULL, ENOMEM); + dirinfo->handle = dir->handle; + pthread_mutex_lock(&apps_std_mt); + QList_AppendNode(&apps_std_dirlist, &dirinfo->qn); + pthread_mutex_unlock(&apps_std_mt); + } else { + nErr = ERRNO; + } bail: - if (nErr) { - VERIFY_EPRINTF("Error 0x%x: failed to opendir %s,errno is %s\n", nErr, name, - strerror(ERRNO)); - } - return nErr; + if(nErr) { + VERIFY_EPRINTF( + "Error 0x%x: failed to opendir %s,errno is %s\n", nErr, + name, strerror(ERRNO)); + } + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_HEADER(apps_std_closedir)(const apps_std_DIR *dir) - __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_dir_info *dirinfo = 0; - - if ((NULL == dir) || (0 == dir->handle)) { - return EINVAL; - } - - errno = 0; - VERIFY(AEE_SUCCESS == (nErr = apps_std_get_dirinfo(dir, &dirinfo))); - - nErr = closedir((DIR *)dir->handle); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - goto bail; - } else { - pthread_mutex_lock(&apps_std_mt); - QNode_Dequeue(&dirinfo->qn); - pthread_mutex_unlock(&apps_std_mt); - free(dirinfo); - dirinfo = NULL; - } +__QAIC_IMPL_EXPORT int +__QAIC_HEADER(apps_std_closedir)(const apps_std_DIR *dir) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_dir_info *dirinfo = 0; + + if((NULL == dir) || (0 == dir->handle)) { + return EINVAL; + } + + errno = 0; + VERIFY(AEE_SUCCESS == (nErr = apps_std_get_dirinfo(dir, &dirinfo))); + + nErr = closedir((DIR *)dir->handle); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + goto bail; + } else { + pthread_mutex_lock(&apps_std_mt); + QNode_Dequeue(&dirinfo->qn); + pthread_mutex_unlock(&apps_std_mt); + free(dirinfo); + dirinfo = NULL; + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: failed to closedir, errno is %s\n", nErr, - strerror(ERRNO)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: failed to closedir, errno is %s\n", + nErr, strerror(ERRNO)); + } + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_HEADER(apps_std_readdir)(const apps_std_DIR *dir, apps_std_DIRENT *dirent, - int *bEOF) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - struct apps_std_dir_info *dirinfo = 0; - struct dirent *odirent; - - if ((NULL == dir) || (0 == dir->handle)) { - return EINVAL; - } - - errno = 0; - VERIFY(AEE_SUCCESS == (nErr = apps_std_get_dirinfo(dir, &dirinfo))); - *bEOF = 0; - odirent = readdir((DIR *)dir->handle); - if (odirent != NULL) { - dirent->ino = (int)odirent->d_ino; - strlcpy(dirent->name, odirent->d_name, sizeof(dirent->name)); - } else { - if (errno == 0) { - *bEOF = 1; - } else { - nErr = ERRNO; - goto bail; - } - } + int *bEOF) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + struct apps_std_dir_info *dirinfo = 0; + struct dirent *odirent; + + if((NULL == dir) || (0 == dir->handle)) { + return EINVAL; + } + + errno = 0; + VERIFY(AEE_SUCCESS == (nErr = apps_std_get_dirinfo(dir, &dirinfo))); + *bEOF = 0; + odirent = readdir((DIR *)dir->handle); + if(odirent != NULL) { + dirent->ino = (int)odirent->d_ino; + strlcpy(dirent->name, odirent->d_name, sizeof(dirent->name)); + } else { + if(errno == 0) { + *bEOF = 1; + } else { + nErr = ERRNO; + goto bail; + } + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: failed to readdir,errno is %s\n", nErr, - strerror(ERRNO)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: failed to readdir,errno is %s\n", + nErr, strerror(ERRNO)); + } + return nErr; } -__QAIC_IMPL_EXPORT int __QAIC_HEADER(apps_std_mkdir)(const char *name, int mode) - __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - uint64_t tdiff = 0; - - if (NULL == name) { - return EINVAL; - } - FASTRPC_ATRACE_BEGIN(); - errno = 0; - PROFILE_ALWAYS(&tdiff, - nErr = mkdir(name, mode); - ); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: failed to mkdir %s,errno is %s\n", nErr, name, - strerror(ERRNO)); - } - FASTRPC_ATRACE_END_L("%s done for %s mode %d in %"PRIu64" us error_code 0x%x", - __func__, name, mode, tdiff, nErr); - return nErr; +__QAIC_IMPL_EXPORT int +__QAIC_HEADER(apps_std_mkdir)(const char *name, int mode) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + uint64_t tdiff = 0; + + if(NULL == name) { + return EINVAL; + } + FASTRPC_ATRACE_BEGIN(); + errno = 0; + PROFILE_ALWAYS(&tdiff, nErr = mkdir(name, mode);); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + VERIFY_EPRINTF("Error 0x%x: failed to mkdir %s,errno is %s\n", + nErr, name, strerror(ERRNO)); + } + FASTRPC_ATRACE_END_L("%s done for %s mode %d in %" PRIu64 + " us error_code 0x%x", + __func__, name, mode, tdiff, nErr); + return nErr; } __QAIC_IMPL_EXPORT int -__QAIC_HEADER(apps_std_rmdir)(const char *name) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - - if (NULL == name) { - return EINVAL; - } - errno = 0; - nErr = rmdir(name); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: failed to rmdir %s,errno is %s\n", nErr, name, - strerror(ERRNO)); - } - - return nErr; +__QAIC_HEADER(apps_std_rmdir)(const char *name) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + + if(NULL == name) { + return EINVAL; + } + errno = 0; + nErr = rmdir(name); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + VERIFY_EPRINTF("Error 0x%x: failed to rmdir %s,errno is %s\n", + nErr, name, strerror(ERRNO)); + } + + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_HEADER(apps_std_stat)(const char *name, - apps_std_STAT *ist) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS, nOpenErr = AEE_SUCCESS, fd = -1; - apps_std_FILE ps; - struct apps_std_info *sinfo = 0; - struct stat st; - uint64_t tdiff = 0; - - if ((NULL == name) || (NULL == ist)) { - return EINVAL; - } - FASTRPC_ATRACE_BEGIN_L("%s for file %s", __func__, name); - errno = 0; - VERIFYM(0 == (nOpenErr = apps_std_fopen_with_env(ADSP_LIBRARY_PATH, ";", name, - "r", &ps)), - AEE_EFILE, "Error: %s failed as fopen failed err 0x%x", __func__, - nErr); - VERIFY(0 == (nErr = apps_std_FILE_get(ps, &sinfo))); - VERIFYC(-1 != (fd = fileno(sinfo->u.stream)), ERRNO); - PROFILE_ALWAYS(&tdiff, - nErr = fstat(fd, &st);; - ); - VERIFYC(nErr == AEE_SUCCESS, ERRNO); - ist->dev = st.st_dev; - ist->ino = st.st_ino; - ist->mode = st.st_mode; - ist->nlink = st.st_nlink; - ist->rdev = st.st_rdev; - ist->size = st.st_size; - ist->atime = (int64_t)st.st_atim.tv_sec; - ist->atimensec = (int64_t)st.st_atim.tv_nsec; - ist->mtime = (int64_t)st.st_mtim.tv_sec; - ist->mtimensec = (int64_t)st.st_mtim.tv_nsec; - ist->ctime = (int64_t)st.st_ctim.tv_nsec; - ist->ctimensec = (int64_t)st.st_ctim.tv_nsec; + apps_std_STAT *ist) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS, nOpenErr = AEE_SUCCESS, fd = -1; + apps_std_FILE ps; + struct apps_std_info *sinfo = 0; + struct stat st; + uint64_t tdiff = 0; + + if((NULL == name) || (NULL == ist)) { + return EINVAL; + } + FASTRPC_ATRACE_BEGIN_L("%s for file %s", __func__, name); + errno = 0; + VERIFYM(0 + == (nOpenErr = apps_std_fopen_with_env( + ADSP_LIBRARY_PATH, ";", name, "r", &ps)), + AEE_EFILE, "Error: %s failed as fopen failed err 0x%x", + __func__, nErr); + VERIFY(0 == (nErr = apps_std_FILE_get(ps, &sinfo))); + VERIFYC(-1 != (fd = fileno(sinfo->u.stream)), ERRNO); + PROFILE_ALWAYS(&tdiff, nErr = fstat(fd, &st);;); + VERIFYC(nErr == AEE_SUCCESS, ERRNO); + ist->dev = st.st_dev; + ist->ino = st.st_ino; + ist->mode = st.st_mode; + ist->nlink = st.st_nlink; + ist->rdev = st.st_rdev; + ist->size = st.st_size; + ist->atime = (int64_t)st.st_atim.tv_sec; + ist->atimensec = (int64_t)st.st_atim.tv_nsec; + ist->mtime = (int64_t)st.st_mtim.tv_sec; + ist->mtimensec = (int64_t)st.st_mtim.tv_nsec; + ist->ctime = (int64_t)st.st_ctim.tv_nsec; + ist->ctimensec = (int64_t)st.st_ctim.tv_nsec; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF( - "Error 0x%x: %s: failed to stat %s, file open returned 0x%x (%s)\n", - nErr, __func__, name, nOpenErr, strerror(ERRNO)); - nErr = ERRNO; - } - if (nOpenErr == AEE_SUCCESS) { - apps_std_fclose(ps); - sinfo = 0; - } - if (sinfo) { - apps_std_FILE_free(sinfo); - } - FASTRPC_ATRACE_END_L("%s done for %s in %"PRIu64" us \ - fd 0x%x error_code 0x%x", __func__, name, tdiff, ps, nErr); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s: failed to stat %s, file open " + "returned 0x%x (%s)\n", + nErr, __func__, name, nOpenErr, + strerror(ERRNO)); + nErr = ERRNO; + } + if(nOpenErr == AEE_SUCCESS) { + apps_std_fclose(ps); + sinfo = 0; + } + if(sinfo) { + apps_std_FILE_free(sinfo); + } + FASTRPC_ATRACE_END_L("%s done for %s in %" PRIu64 " us \ + fd 0x%x error_code 0x%x", + __func__, name, tdiff, ps, nErr); + return nErr; } __QAIC_HEADER_EXPORT int __QAIC_HEADER(apps_std_ftrunc)(apps_std_FILE sin, - int offset) __QAIC_HEADER_ATTRIBUTE { - int nErr = 0, fd = -1; - struct apps_std_info *sinfo = 0; - - FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x for length %d", __func__, - sin, offset); - VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); - errno = 0; - VERIFYC(-1 != (fd = fileno(sinfo->u.stream)), ERRNO); - - VERIFYC(0 == ftruncate(fd, offset), ERRNO); + int offset) __QAIC_HEADER_ATTRIBUTE +{ + int nErr = 0, fd = -1; + struct apps_std_info *sinfo = 0; + + FASTRPC_ATRACE_BEGIN_L("%s for file with fd 0x%x for length %d", + __func__, sin, offset); + VERIFY(0 == (nErr = apps_std_FILE_get(sin, &sinfo))); + errno = 0; + VERIFYC(-1 != (fd = fileno(sinfo->u.stream)), ERRNO); + + VERIFYC(0 == ftruncate(fd, offset), ERRNO); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: failed to ftrunc file, errno is %s\n", nErr, - strerror(ERRNO)); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: failed to ftrunc file, errno is %s\n", nErr, + strerror(ERRNO)); + } + FASTRPC_ATRACE_END(); + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_std_frename)(const char *oldname, - const char *newname) __QAIC_IMPL_ATTRIBUTE { - int nErr = AEE_SUCCESS; - - if (NULL == oldname || NULL == newname) - return EINVAL; - FASTRPC_ATRACE_BEGIN_L("%s for file with oldname %s to new name %s", __func__, - oldname, newname); - nErr = rename(oldname, newname); - if (nErr != AEE_SUCCESS) { - nErr = ERRNO; - VERIFY_EPRINTF("Error 0x%x: failed to rename file, errno is %s\n", nErr, - strerror(ERRNO)); - } - FASTRPC_ATRACE_END(); - return nErr; + const char *newname) __QAIC_IMPL_ATTRIBUTE +{ + int nErr = AEE_SUCCESS; + + if(NULL == oldname || NULL == newname) + return EINVAL; + FASTRPC_ATRACE_BEGIN_L("%s for file with oldname %s to new name %s", + __func__, oldname, newname); + nErr = rename(oldname, newname); + if(nErr != AEE_SUCCESS) { + nErr = ERRNO; + VERIFY_EPRINTF( + "Error 0x%x: failed to rename file, errno is %s\n", nErr, + strerror(ERRNO)); + } + FASTRPC_ATRACE_END(); + return nErr; } diff --git a/src/apps_std_skel.c b/src/apps_std_skel.c index 94056eef..430c1df3 100644 --- a/src/apps_std_skel.c +++ b/src/apps_std_skel.c @@ -26,7 +26,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -36,7 +36,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -94,159 +94,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) - -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) - -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -254,175 +268,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _APPS_STD_SLIM_H #define _APPS_STD_SLIM_H @@ -436,1016 +447,1438 @@ struct Interface { #endif static const Type types[8]; -static const Type* const typeArrays[15] = {&(types[2]),&(types[2]),&(types[2]),&(types[6]),&(types[6]),&(types[2]),&(types[2]),&(types[7]),&(types[7]),&(types[7]),&(types[7]),&(types[7]),&(types[7]),&(types[3]),&(types[4])}; -static const StructType structTypes[3] = {{0x1,&(typeArrays[0]),0x8,0x0,0x8,0x8,0x1,0x8},{0x2,&(typeArrays[13]),0x104,0x0,0x104,0x4,0x1,0x4},{0xd,&(typeArrays[0]),0x60,0x0,0x60,0x8,0x1,0x8}}; -static const SequenceType sequenceTypes[1] = {{&(types[1]),0x0,0x4,0x4,0x0}}; -static const Type types[8] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8)},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4},{0xff,{{(const uintptr_t)&(types[5]),(const uintptr_t)0xff}}, 8,0x1},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8}}; -static const Parameter parameters[18] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{0,0}}, 3,0x4,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(sequenceTypes[0]),0}}, 25,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x2,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x2,3,0},{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1,3,0},{0x8,{{(const uintptr_t)&(structTypes[0]),0}}, 6,0x8,3,0},{0x8,{{(const uintptr_t)&(structTypes[0]),0}}, 6,0x8,0,0},{0x104,{{(const uintptr_t)&(structTypes[1]),0}}, 6,0x4,3,0},{0x60,{{(const uintptr_t)&(structTypes[2]),0}}, 6,0x8,3,0}}; -static const Parameter* const parameterArrays[52] = {(&(parameters[0])),(&(parameters[0])),(&(parameters[0])),(&(parameters[0])),(&(parameters[4])),(&(parameters[4])),(&(parameters[0])),(&(parameters[0])),(&(parameters[10])),(&(parameters[11])),(&(parameters[12])),(&(parameters[0])),(&(parameters[0])),(&(parameters[0])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2])),(&(parameters[5])),(&(parameters[4])),(&(parameters[4])),(&(parameters[2])),(&(parameters[3])),(&(parameters[4])),(&(parameters[4])),(&(parameters[2])),(&(parameters[0])),(&(parameters[0])),(&(parameters[1])),(&(parameters[15])),(&(parameters[16])),(&(parameters[4])),(&(parameters[0])),(&(parameters[0])),(&(parameters[6])),(&(parameters[0])),(&(parameters[9])),(&(parameters[4])),(&(parameters[2])),(&(parameters[6])),(&(parameters[7])),(&(parameters[0])),(&(parameters[17])),(&(parameters[0])),(&(parameters[14])),(&(parameters[2])),(&(parameters[1])),(&(parameters[0])),(&(parameters[13])),(&(parameters[2])),(&(parameters[8])),(&(parameters[2])),(&(parameters[4]))}; -static const Method methods[27] = {{REMOTE_SCALARS_MAKEX(0,0,0x3,0x1,0x0,0x0),0x8,0x4,3,3,(&(parameterArrays[13])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x1,0x0,0x0),0xc,0x4,4,4,(&(parameterArrays[24])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[16])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x8,6,4,(&(parameterArrays[20])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x1,0x0,0x0),0x8,0x8,5,4,(&(parameterArrays[16])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[20])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x8,0x0,3,2,(&(parameterArrays[16])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x4,0x4,2,2,(&(parameterArrays[50])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0xc,0x0,3,3,(&(parameterArrays[37])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x4,0x8,2,2,(&(parameterArrays[48])),0x4,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[34])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x0,0x0,0x0),0xc,0x0,3,3,(&(parameterArrays[31])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x5,0x1,0x0,0x0),0x10,0x4,5,5,(&(parameterArrays[11])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,255,255,15,15),0xc,0x6,7,5,(&(parameterArrays[6])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x1,0x0,0x0),0x4,0x1,2,2,(&(parameterArrays[46])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x4,0x4,2,2,(&(parameterArrays[44])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x1,0x0,0x0),0x4,0x8,2,2,(&(parameterArrays[42])),0x4,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,1,1,(&(parameterArrays[28])),0x8,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x8,0x108,3,3,(&(parameterArrays[28])),0x8,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[32])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x1,0x0,0x0),0x4,0x60,2,2,(&(parameterArrays[40])),0x4,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[37])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[0])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x3,0x1,0x0,0x0),0x8,0x8,4,4,(&(parameterArrays[2])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[33])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x5,0x1,0x0,0x0),0x10,0x8,6,6,(&(parameterArrays[0])),0x4,0x4}}; -static const Method* const methodArrays[37] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[5]),&(methods[6]),&(methods[7]),&(methods[8]),&(methods[9]),&(methods[2]),&(methods[7]),&(methods[7]),&(methods[2]),&(methods[10]),&(methods[11]),&(methods[12]),&(methods[10]),&(methods[13]),&(methods[5]),&(methods[14]),&(methods[15]),&(methods[2]),&(methods[10]),&(methods[16]),&(methods[17]),&(methods[18]),&(methods[19]),&(methods[20]),&(methods[10]),&(methods[21]),&(methods[22]),&(methods[23]),&(methods[24]),&(methods[25]),&(methods[26])}; -static const char strings[568] = "get_search_paths_with_env\0fopen_with_env_fd\0fdopen_decrypt\0fopen_with_env\0print_string\0bytesWritten\0fileExists\0maxPathLen\0envvarname\0fclose_fd\0ctimensec\0mtimensec\0atimensec\0valLenReq\0posLenReq\0bytesRead\0fopen_fd\0closedir\0numPaths\0unsetenv\0override\0clearerr\0newname\0oldname\0frename\0readdir\0opendir\0fremove\0fsetpos\0fgetpos\0freopen\0ftrunc\0dirent\0handle\0exists\0getenv\0ferror\0rewind\0whence\0offset\0fwrite\0fclose\0fflush\0ctime\0mtime\0atime\0nlink\0rmdir\0mkdir\0fsync\0paths\0fgets\0delim\0fseek\0ftell\0fread\0psout\0fopen\0size\0rdev\0stat\0path\0feof\0flen\0bEOF\0mode\0tsz\0ino\0val\0str\0buf\0sin\0"; -static const uint16_t methodStrings[143] = {513,128,513,543,509,547,538,431,508,503,425,163,419,153,413,143,26,122,467,128,538,41,529,281,217,343,336,547,128,533,0,122,467,455,221,111,59,122,467,128,538,491,203,128,538,41,529,392,563,559,87,533,485,563,559,193,533,321,563,128,538,491,289,128,217,343,461,563,559,533,232,128,551,239,357,128,551,173,473,563,385,378,313,563,309,183,497,128,538,491,273,265,257,329,563,385,443,128,538,212,217,343,44,563,491,100,518,350,364,563,253,523,563,533,528,563,529,479,563,309,305,563,309,133,41,437,128,297,128,449,563,230,128,74,555,248,563,371,563,399,563,406,563}; -static const uint16_t methodStringsArrays[37] = {86,57,141,139,52,47,82,120,117,78,114,137,111,108,135,133,74,70,131,36,66,30,105,129,127,102,62,99,23,96,125,0,93,90,42,123,16}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_std_slim) = {37,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Type *const typeArrays[15] + = { &(types[2]), &(types[2]), &(types[2]), &(types[6]), &(types[6]), + &(types[2]), &(types[2]), &(types[7]), &(types[7]), &(types[7]), + &(types[7]), &(types[7]), &(types[7]), &(types[3]), &(types[4]) }; +static const StructType structTypes[3] + = { { 0x1, &(typeArrays[0]), 0x8, 0x0, 0x8, 0x8, 0x1, 0x8 }, + { 0x2, &(typeArrays[13]), 0x104, 0x0, 0x104, 0x4, 0x1, 0x4 }, + { 0xd, &(typeArrays[0]), 0x60, 0x0, 0x60, 0x8, 0x1, 0x8 } }; +static const SequenceType sequenceTypes[1] + = { { &(types[1]), 0x0, 0x4, 0x4, 0x0 } }; +static const Type types[8] + = { { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8) }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 }, + { 0xff, + { { (const uintptr_t)&(types[5]), (const uintptr_t)0xff } }, + 8, + 0x1 }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8 } }; +static const Parameter parameters[18] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { 0, 0 } }, 3, 0x4, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(sequenceTypes[0]), 0 } }, + 25, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { 0x2, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x2, 3, 0 }, + { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1, 3, 0 }, + { 0x8, { { (const uintptr_t)&(structTypes[0]), 0 } }, 6, 0x8, 3, 0 }, + { 0x8, { { (const uintptr_t)&(structTypes[0]), 0 } }, 6, 0x8, 0, 0 }, + { 0x104, { { (const uintptr_t)&(structTypes[1]), 0 } }, 6, 0x4, 3, 0 }, + { 0x60, { { (const uintptr_t)&(structTypes[2]), 0 } }, 6, 0x8, 3, 0 } +}; +static const Parameter *const parameterArrays[52] + = { (&(parameters[0])), (&(parameters[0])), (&(parameters[0])), + (&(parameters[0])), (&(parameters[4])), (&(parameters[4])), + (&(parameters[0])), (&(parameters[0])), (&(parameters[10])), + (&(parameters[11])), (&(parameters[12])), (&(parameters[0])), + (&(parameters[0])), (&(parameters[0])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[2])), (&(parameters[5])), + (&(parameters[4])), (&(parameters[4])), (&(parameters[2])), + (&(parameters[3])), (&(parameters[4])), (&(parameters[4])), + (&(parameters[2])), (&(parameters[0])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[15])), (&(parameters[16])), + (&(parameters[4])), (&(parameters[0])), (&(parameters[0])), + (&(parameters[6])), (&(parameters[0])), (&(parameters[9])), + (&(parameters[4])), (&(parameters[2])), (&(parameters[6])), + (&(parameters[7])), (&(parameters[0])), (&(parameters[17])), + (&(parameters[0])), (&(parameters[14])), (&(parameters[2])), + (&(parameters[1])), (&(parameters[0])), (&(parameters[13])), + (&(parameters[2])), (&(parameters[8])), (&(parameters[2])), + (&(parameters[4])) }; +static const Method methods[27] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x3, 0x1, 0x0, 0x0), 0x8, 0x4, 3, 3, + (&(parameterArrays[13])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x3, 0x1, 0x0, 0x0), 0xc, 0x4, 4, 4, + (&(parameterArrays[24])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[16])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x8, 0x8, 6, 4, + (&(parameterArrays[20])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x1, 0x0, 0x0), 0x8, 0x8, 5, 4, + (&(parameterArrays[16])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x8, 0x4, 5, 3, + (&(parameterArrays[20])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x8, 0x0, 3, 2, + (&(parameterArrays[16])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x4, 0x4, 2, 2, + (&(parameterArrays[50])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0xc, 0x0, 3, 3, + (&(parameterArrays[37])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x4, 0x8, 2, 2, + (&(parameterArrays[48])), 0x4, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[0])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x8, 0x4, 5, 3, + (&(parameterArrays[34])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x3, 0x0, 0x0, 0x0), 0xc, 0x0, 3, 3, + (&(parameterArrays[31])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x5, 0x1, 0x0, 0x0), 0x10, 0x4, 5, 5, + (&(parameterArrays[11])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 255, 255, 15, 15), 0xc, 0x6, 7, 5, + (&(parameterArrays[6])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x1, 0x0, 0x0), 0x4, 0x1, 2, 2, + (&(parameterArrays[46])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x4, 0x4, 2, 2, + (&(parameterArrays[44])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x1, 0x0, 0x0), 0x4, 0x8, 2, 2, + (&(parameterArrays[42])), 0x4, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 1, 1, + (&(parameterArrays[28])), 0x8, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x8, 0x108, 3, 3, + (&(parameterArrays[28])), 0x8, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[32])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x1, 0x0, 0x0), 0x4, 0x60, 2, 2, + (&(parameterArrays[40])), 0x4, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[37])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x3, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[0])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x3, 0x1, 0x0, 0x0), 0x8, 0x8, 4, 4, + (&(parameterArrays[2])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[33])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x5, 0x1, 0x0, 0x0), 0x10, 0x8, 6, 6, + (&(parameterArrays[0])), 0x4, 0x4 } }; +static const Method *const methodArrays[37] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[2]), + &(methods[3]), &(methods[4]), &(methods[5]), &(methods[6]), + &(methods[7]), &(methods[8]), &(methods[9]), &(methods[2]), + &(methods[7]), &(methods[7]), &(methods[2]), &(methods[10]), + &(methods[11]), &(methods[12]), &(methods[10]), &(methods[13]), + &(methods[5]), &(methods[14]), &(methods[15]), &(methods[2]), + &(methods[10]), &(methods[16]), &(methods[17]), &(methods[18]), + &(methods[19]), &(methods[20]), &(methods[10]), &(methods[21]), + &(methods[22]), &(methods[23]), &(methods[24]), &(methods[25]), + &(methods[26]) }; +static const char strings[568] + = "get_search_paths_with_env\0fopen_with_env_fd\0fdopen_decrypt\0fopen_" + "with_env\0print_" + "string\0bytesWritten\0fileExists\0maxPathLen\0envvarname\0fclose_" + "fd\0ctimensec\0mtimensec\0atimensec\0valLenReq\0posLenReq\0bytesRead\0f" + "open_" + "fd\0closedir\0numPaths\0unsetenv\0override\0clearerr\0newname\0oldname" + "\0frename\0readdir\0opendir\0fremove\0fsetpos\0fgetpos\0freopen\0ftrunc" + "\0dirent\0handle\0exists\0getenv\0ferror\0rewind\0whence\0offset\0fwrit" + "e\0fclose\0fflush\0ctime\0mtime\0atime\0nlink\0rmdir\0mkdir\0fsync\0pat" + "hs\0fgets\0delim\0fseek\0ftell\0fread\0psout\0fopen\0size\0rdev\0stat\0" + "path\0feof\0flen\0bEOF\0mode\0tsz\0ino\0val\0str\0buf\0sin\0"; +static const uint16_t methodStrings[143] + = { 513, 128, 513, 543, 509, 547, 538, 431, 508, 503, 425, 163, 419, + 153, 413, 143, 26, 122, 467, 128, 538, 41, 529, 281, 217, 343, + 336, 547, 128, 533, 0, 122, 467, 455, 221, 111, 59, 122, 467, + 128, 538, 491, 203, 128, 538, 41, 529, 392, 563, 559, 87, 533, + 485, 563, 559, 193, 533, 321, 563, 128, 538, 491, 289, 128, 217, + 343, 461, 563, 559, 533, 232, 128, 551, 239, 357, 128, 551, 173, + 473, 563, 385, 378, 313, 563, 309, 183, 497, 128, 538, 491, 273, + 265, 257, 329, 563, 385, 443, 128, 538, 212, 217, 343, 44, 563, + 491, 100, 518, 350, 364, 563, 253, 523, 563, 533, 528, 563, 529, + 479, 563, 309, 305, 563, 309, 133, 41, 437, 128, 297, 128, 449, + 563, 230, 128, 74, 555, 248, 563, 371, 563, 399, 563, 406, 563 }; +static const uint16_t methodStringsArrays[37] + = { 86, 57, 141, 139, 52, 47, 82, 120, 117, 78, 114, 137, 111, + 108, 135, 133, 74, 70, 131, 36, 66, 30, 105, 129, 127, 102, + 62, 99, 23, 96, 125, 0, 93, 90, 42, 123, 16 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_std_slim) + = { 37, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_APPS_STD_SLIM_H extern int adsp_mmap_fd_getinfo(int, uint32_t *); #ifdef __cplusplus extern "C" { #endif _ATTRIBUTE_VISIBILITY uint32_t apps_std_skel_invoke_qaic_version = 10042; -static __inline int _skel_method(int (*_pfn)(const char*, const char*, const char*, const char*, int*, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - char* _in2[1] = {0}; - uint32_t _in2Len[1] = {0}; - char* _in3[1] = {0}; - uint32_t _in3Len[1] = {0}; - char* _in4[1] = {0}; - uint32_t _in4Len[1] = {0}; - uint32_t _rout5[1] = {0}; - uint32_t _rout6[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==5); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((5 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 20); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2Len, 0, _primIn, 8, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); - _in2[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); - _COPY(_in3Len, 0, _primIn, 12, 4); - _ASSERT(_nErr, ((_praIn[2].buf.nLen / 1)) >= (size_t)(_in3Len[0])); - _in3[0] = _praIn[2].buf.pv; - _ASSERT(_nErr, (_in3Len[0] > 0) && (_in3[0][(_in3Len[0] - 1)] == 0)); - _COPY(_in4Len, 0, _primIn, 16, 4); - _ASSERT(_nErr, ((_praIn[3].buf.nLen / 1)) >= (size_t)(_in4Len[0])); - _in4[0] = _praIn[3].buf.pv; - _ASSERT(_nErr, (_in4Len[0] > 0) && (_in4[0][(_in4Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in1, (const char*)*_in2, (const char*)*_in3, (const char*)*_in4, (int*)_rout5, (int*)_rout6)); - _COPY(_primROut, 0, _rout5, 0, 4); - _COPY(_primROut, 4, _rout6, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method(int (*_pfn)(const char *, const char *, const char *, + const char *, int *, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + char *_in2[1] = { 0 }; + uint32_t _in2Len[1] = { 0 }; + char *_in3[1] = { 0 }; + uint32_t _in3Len[1] = { 0 }; + char *_in4[1] = { 0 }; + uint32_t _in4Len[1] = { 0 }; + uint32_t _rout5[1] = { 0 }; + uint32_t _rout6[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 5); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((5 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 20); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2Len, 0, _primIn, 8, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); + _in2[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); + _COPY(_in3Len, 0, _primIn, 12, 4); + _ASSERT(_nErr, ((_praIn[2].buf.nLen / 1)) >= (size_t)(_in3Len[0])); + _in3[0] = _praIn[2].buf.pv; + _ASSERT(_nErr, (_in3Len[0] > 0) && (_in3[0][(_in3Len[0] - 1)] == 0)); + _COPY(_in4Len, 0, _primIn, 16, 4); + _ASSERT(_nErr, ((_praIn[3].buf.nLen / 1)) >= (size_t)(_in4Len[0])); + _in4[0] = _praIn[3].buf.pv; + _ASSERT(_nErr, (_in4Len[0] > 0) && (_in4[0][(_in4Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in1, (const char *)*_in2, + (const char *)*_in3, (const char *)*_in4, + (int *)_rout5, (int *)_rout6)); + _COPY(_primROut, 0, _rout5, 0, 4); + _COPY(_primROut, 4, _rout6, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_1(int (*_pfn)(int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _TRY(_nErr, _pfn((int)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_1(int (*_pfn)(int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _TRY(_nErr, _pfn((int)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_2(int (*_pfn)(const char*, const char*, int*, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - char* _in2[1] = {0}; - uint32_t _in2Len[1] = {0}; - uint32_t _rout3[1] = {0}; - uint32_t _rout4[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==3); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2Len, 0, _primIn, 8, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); - _in2[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in1, (const char*)*_in2, (int*)_rout3, (int*)_rout4)); - _COPY(_primROut, 0, _rout3, 0, 4); - _COPY(_primROut, 4, _rout4, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_2(int (*_pfn)(const char *, const char *, int *, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + char *_in2[1] = { 0 }; + uint32_t _in2Len[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint32_t _rout4[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 3); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2Len, 0, _primIn, 8, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); + _in2[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in1, (const char *)*_in2, + (int *)_rout3, (int *)_rout4)); + _COPY(_primROut, 0, _rout3, 0, 4); + _COPY(_primROut, 4, _rout4, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_3(int (*_pfn)(const char*, const char*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - char* _in2[1] = {0}; - uint32_t _in2Len[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==3); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((3 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2Len, 0, _primIn, 8, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); - _in2[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in1, (const char*)*_in2)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_3(int (*_pfn)(const char *, const char *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + char *_in2[1] = { 0 }; + uint32_t _in2Len[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 3); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((3 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2Len, 0, _primIn, 8, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); + _in2[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in1, (const char *)*_in2)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_4(int (*_pfn)(apps_std_FILE, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t _in2[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _COPY(_in2, 0, _primIn, 8, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in1, (int)*_in2)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_4(int (*_pfn)(apps_std_FILE, int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _COPY(_in2, 0, _primIn, 8, 4); + _TRY(_nErr, _pfn((apps_std_FILE)*_in1, (int)*_in2)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_5(int (*_pfn)(const char*, apps_std_STAT*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - uint64_t _rout2[12] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint64_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 96); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in1, (apps_std_STAT*)_rout2)); - _COPY(_primROut, 0, _rout2, 0, 96); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_5(int (*_pfn)(const char *, apps_std_STAT *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + uint64_t _rout2[12] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint64_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 96); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in1, (apps_std_STAT *)_rout2)); + _COPY(_primROut, 0, _rout2, 0, 96); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_invoke(uint32_t _mid, uint32_t _sc, remote_arg* _pra) { - switch(_mid) - { - case 31: - return _skel_method_5(__QAIC_IMPL(apps_std_stat), _sc, _pra); - case 32: - return _skel_method_4(__QAIC_IMPL(apps_std_ftrunc), _sc, _pra); - case 33: - return _skel_method_3(__QAIC_IMPL(apps_std_frename), _sc, _pra); - case 34: - return _skel_method_2(__QAIC_IMPL(apps_std_fopen_fd), _sc, _pra); - case 35: - return _skel_method_1(__QAIC_IMPL(apps_std_fclose_fd), _sc, _pra); - case 36: - return _skel_method(__QAIC_IMPL(apps_std_fopen_with_env_fd), _sc, _pra); - } - return AEE_EUNSUPPORTED; +static __inline int +_skel_invoke(uint32_t _mid, uint32_t _sc, remote_arg *_pra) +{ + switch(_mid) { + case 31: + return _skel_method_5(__QAIC_IMPL(apps_std_stat), _sc, _pra); + case 32: + return _skel_method_4(__QAIC_IMPL(apps_std_ftrunc), _sc, _pra); + case 33: + return _skel_method_3(__QAIC_IMPL(apps_std_frename), _sc, + _pra); + case 34: + return _skel_method_2(__QAIC_IMPL(apps_std_fopen_fd), _sc, + _pra); + case 35: + return _skel_method_1(__QAIC_IMPL(apps_std_fclose_fd), _sc, + _pra); + case 36: + return _skel_method(__QAIC_IMPL(apps_std_fopen_with_env_fd), + _sc, _pra); + } + return AEE_EUNSUPPORTED; } -static __inline int _skel_method_6(int (*_pfn)(const char*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in0)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_6(int (*_pfn)(const char *), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in0)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_7(int (*_pfn)(const char*, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_in1, 0, _primIn, 4, 4); - _TRY(_nErr, _pfn((const char*)*_in0, (int)*_in1)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_7(int (*_pfn)(const char *, int), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_in1, 0, _primIn, 4, 4); + _TRY(_nErr, _pfn((const char *)*_in0, (int)*_in1)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_8(int (*_pfn)(const apps_std_DIR*, apps_std_DIRENT*, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint64_t _in0[1] = {0}; - uint32_t _rout1[65] = {0}; - uint32_t _rout2[1] = {0}; - uint64_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 264); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 8); - _TRY(_nErr, _pfn((const apps_std_DIR*)_in0, (apps_std_DIRENT*)_rout1, (int*)_rout2)); - _COPY(_primROut, 0, _rout1, 0, 260); - _COPY(_primROut, 260, _rout2, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_8(int (*_pfn)(const apps_std_DIR *, apps_std_DIRENT *, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint64_t _in0[1] = { 0 }; + uint32_t _rout1[65] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint64_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 264); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 8); + _TRY(_nErr, _pfn((const apps_std_DIR *)_in0, (apps_std_DIRENT *)_rout1, + (int *)_rout2)); + _COPY(_primROut, 0, _rout1, 0, 260); + _COPY(_primROut, 260, _rout2, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_9(int (*_pfn)(const apps_std_DIR*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint64_t _in0[1] = {0}; - uint64_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 8); - _TRY(_nErr, _pfn((const apps_std_DIR*)_in0)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_9(int (*_pfn)(const apps_std_DIR *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint64_t _in0[1] = { 0 }; + uint64_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 8); + _TRY(_nErr, _pfn((const apps_std_DIR *)_in0)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_10(int (*_pfn)(const char*, apps_std_DIR*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint64_t _rout1[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint64_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in0, (apps_std_DIR*)_rout1)); - _COPY(_primROut, 0, _rout1, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_10(int (*_pfn)(const char *, apps_std_DIR *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint64_t _rout1[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint64_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in0, (apps_std_DIR *)_rout1)); + _COPY(_primROut, 0, _rout1, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_11(int (*_pfn)(apps_std_FILE, apps_std_FILE*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _rout1[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (apps_std_FILE*)_rout1)); - _COPY(_primROut, 0, _rout1, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_11(int (*_pfn)(apps_std_FILE, apps_std_FILE *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _rout1[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (apps_std_FILE *)_rout1)); + _COPY(_primROut, 0, _rout1, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_12(int (*_pfn)(apps_std_FILE), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_12(int (*_pfn)(apps_std_FILE), uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _TRY(_nErr, _pfn((apps_std_FILE)*_in0)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_13(int (*_pfn)(const char*, bool*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - uint8_t _rout1[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint8_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 1); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in0, (bool*)_rout1)); - _COPY(_primROut, 0, _rout1, 0, 1); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_13(int (*_pfn)(const char *, bool *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + uint8_t _rout1[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint8_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 1); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in0, (bool *)_rout1)); + _COPY(_primROut, 0, _rout1, 0, 1); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_pack(_ATTRIBUTE_UNUSED remote_arg* _praROutPost, _ATTRIBUTE_UNUSED remote_arg* _ppraROutPost[1], _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praROutPostStart = _praROutPost; - remote_arg** _ppraROutPostStart = _ppraROutPost; - _ppraROutPost = &_praROutPost; - _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) +1; - return _nErr; +static __inline int +_skel_pack(_ATTRIBUTE_UNUSED remote_arg *_praROutPost, + _ATTRIBUTE_UNUSED remote_arg *_ppraROutPost[1], + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praROutPostStart = _praROutPost; + remote_arg **_ppraROutPostStart = _ppraROutPost; + _ppraROutPost = &_praROutPost; + _ppraROutPostStart[0] += (_praROutPost - _praROutPostStart) + 1; + return _nErr; } -static __inline int _skel_unpack(_ATTRIBUTE_UNUSED _allocator* _al, _ATTRIBUTE_UNUSED remote_arg* _praIn, _ATTRIBUTE_UNUSED remote_arg* _ppraIn[1], _ATTRIBUTE_UNUSED remote_arg* _praROut, _ATTRIBUTE_UNUSED remote_arg* _ppraROut[1], _ATTRIBUTE_UNUSED remote_arg* _praHIn, _ATTRIBUTE_UNUSED remote_arg* _ppraHIn[1], _ATTRIBUTE_UNUSED remote_arg* _praHROut, _ATTRIBUTE_UNUSED remote_arg* _ppraHROut[1], _ATTRIBUTE_UNUSED void* _primIn, _ATTRIBUTE_UNUSED void* _primROut, _ATTRIBUTE_UNUSED char* _rout0[1], _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) { - int _nErr = 0; - remote_arg* _praInStart = _praIn; - remote_arg** _ppraInStart = _ppraIn; - remote_arg* _praROutStart = _praROut; - remote_arg** _ppraROutStart = _ppraROut; - _ppraIn = &_praIn; - _ppraROut = &_praROut; - _COPY(_rout0Len, 0, _primIn, 0, 4); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout0Len[0])); - _rout0[0] = _praROut[0].buf.pv; - _ppraInStart[0] += (_praIn - _praInStart) + 0; - _ppraROutStart[0] += (_praROut - _praROutStart) +1; - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_unpack(_ATTRIBUTE_UNUSED _allocator *_al, + _ATTRIBUTE_UNUSED remote_arg *_praIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraROut[1], + _ATTRIBUTE_UNUSED remote_arg *_praHIn, + _ATTRIBUTE_UNUSED remote_arg *_ppraHIn[1], + _ATTRIBUTE_UNUSED remote_arg *_praHROut, + _ATTRIBUTE_UNUSED remote_arg *_ppraHROut[1], + _ATTRIBUTE_UNUSED void *_primIn, + _ATTRIBUTE_UNUSED void *_primROut, + _ATTRIBUTE_UNUSED char *_rout0[1], + _ATTRIBUTE_UNUSED uint32_t _rout0Len[1]) +{ + int _nErr = 0; + remote_arg *_praInStart = _praIn; + remote_arg **_ppraInStart = _ppraIn; + remote_arg *_praROutStart = _praROut; + remote_arg **_ppraROutStart = _ppraROut; + _ppraIn = &_praIn; + _ppraROut = &_praROut; + _COPY(_rout0Len, 0, _primIn, 0, 4); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout0Len[0])); + _rout0[0] = _praROut[0].buf.pv; + _ppraInStart[0] += (_praIn - _praInStart) + 0; + _ppraROutStart[0] += (_praROut - _praROutStart) + 1; + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_14(int (*_pfn)(const char*, const char*, _cstring1_t*, int, uint32_t*, uint16_t*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - void* _rout2[1] = {0}; - uint32_t _rout2Len[1] = {0}; - uint32_t _rout3[1] = {0}; - uint16_t _rout4[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - int _numInH[1] = {0}; - int _numROut[1] = {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - remote_arg* _praROutPost = 0; - remote_arg** _ppraROutPost = &_praROutPost; - _allocator _al[1] = {{0}}; - remote_arg** _ppraIn = &_praIn; - remote_arg** _ppraROut = &_praROut; - remote_arg* _praHIn = 0; - remote_arg** _ppraHIn = &_praHIn; - remote_arg* _praHROut = 0; - remote_arg** _ppraHROut = &_praHROut; - char* _seq_primIn2 = 0; - char* _seq_nat2 = 0; - int _ii = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)>=1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)>=1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((4 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 6); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _numInH[0] = REMOTE_SCALARS_INHANDLES(_sc); - _numROut[0] = REMOTE_SCALARS_OUTBUFS(_sc); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROutPost = _praROut; - _COPY(_in0Len, 0, _primIn, 0, 4); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_in1Len, 0, _primIn, 4, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_rout2Len, 0, _primIn, 8, 4); - _allocator_init(_al, 0, 0); - if(_praHIn == 0) - { - _praHIn = ((_praROut + _numROut[0]) + 1); - } - if(_praHROut == 0) - (_praHROut = _praHIn + _numInH[0] + 0); - _ASSERT(_nErr, ((_praIn[2].buf.nLen / 4)) >= (size_t)(_rout2Len[0])); - _ALLOCATE(_nErr, _al, (_rout2Len[0] * SLIM_IFPTR32(8, 16)), SLIM_IFPTR32(4, 8), _rout2[0]); - for(_ii = 0, _seq_primIn2 = (char*)_praIn[2].buf.pv, _seq_nat2 = (char*)_rout2[0];_ii < (int)_rout2Len[0];++_ii, _seq_primIn2 = (_seq_primIn2 + 4), _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _skel_unpack(_al, (_praIn + 3), _ppraIn, (_praROut + 0), _ppraROut, _praHIn, _ppraHIn, _praHROut, _ppraHROut, _seq_primIn2, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _TRY(_nErr, _pfn((const char*)*_in0, (const char*)*_in1, (_cstring1_t*)*_rout2, (int)*_rout2Len, (uint32_t*)_rout3, (uint16_t*)_rout4)); - for(_ii = 0, _seq_nat2 = (char*)_rout2[0];_ii < (int)_rout2Len[0];++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) - { - _TRY(_nErr, _skel_pack((_praROutPost + 0), _ppraROutPost, 0, SLIM_IFPTR32((char**)&(((uint32_t*)_seq_nat2)[0]), (char**)&(((uint64_t*)_seq_nat2)[0])), SLIM_IFPTR32((uint32_t*)&(((uint32_t*)_seq_nat2)[1]), (uint32_t*)&(((uint32_t*)_seq_nat2)[2])))); - } - _COPY(_primROut, 0, _rout3, 0, 4); - _COPY(_primROut, 4, _rout4, 0, 2); - _CATCH(_nErr) {} - _allocator_deinit(_al); - return _nErr; +static __inline int +_skel_method_14(int (*_pfn)(const char *, const char *, _cstring1_t *, int, + uint32_t *, uint16_t *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + void *_rout2[1] = { 0 }; + uint32_t _rout2Len[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint16_t _rout4[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + int _numInH[1] = { 0 }; + int _numROut[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + remote_arg *_praROutPost = 0; + remote_arg **_ppraROutPost = &_praROutPost; + _allocator _al[1] = { { 0 } }; + remote_arg **_ppraIn = &_praIn; + remote_arg **_ppraROut = &_praROut; + remote_arg *_praHIn = 0; + remote_arg **_ppraHIn = &_praHIn; + remote_arg *_praHROut = 0; + remote_arg **_ppraHROut = &_praHROut; + char *_seq_primIn2 = 0; + char *_seq_nat2 = 0; + int _ii = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) >= 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) >= 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((4 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 6); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _numInH[0] = REMOTE_SCALARS_INHANDLES(_sc); + _numROut[0] = REMOTE_SCALARS_OUTBUFS(_sc); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROutPost = _praROut; + _COPY(_in0Len, 0, _primIn, 0, 4); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_in1Len, 0, _primIn, 4, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_rout2Len, 0, _primIn, 8, 4); + _allocator_init(_al, 0, 0); + if(_praHIn == 0) { + _praHIn = ((_praROut + _numROut[0]) + 1); + } + if(_praHROut == 0) + (_praHROut = _praHIn + _numInH[0] + 0); + _ASSERT(_nErr, ((_praIn[2].buf.nLen / 4)) >= (size_t)(_rout2Len[0])); + _ALLOCATE(_nErr, _al, (_rout2Len[0] * SLIM_IFPTR32(8, 16)), + SLIM_IFPTR32(4, 8), _rout2[0]); + for(_ii = 0, _seq_primIn2 = (char *)_praIn[2].buf.pv, + _seq_nat2 = (char *)_rout2[0]; + _ii < (int)_rout2Len[0]; ++_ii, _seq_primIn2 = (_seq_primIn2 + 4), + _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _skel_unpack( + _al, (_praIn + 3), _ppraIn, (_praROut + 0), _ppraROut, + _praHIn, _ppraHIn, _praHROut, _ppraHROut, + _seq_primIn2, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _TRY(_nErr, _pfn((const char *)*_in0, (const char *)*_in1, + (_cstring1_t *)*_rout2, (int)*_rout2Len, + (uint32_t *)_rout3, (uint16_t *)_rout4)); + for(_ii = 0, _seq_nat2 = (char *)_rout2[0]; _ii < (int)_rout2Len[0]; + ++_ii, _seq_nat2 = (_seq_nat2 + SLIM_IFPTR32(8, 16))) { + _TRY(_nErr, + _skel_pack( + (_praROutPost + 0), _ppraROutPost, 0, + SLIM_IFPTR32((char **)&(((uint32_t *)_seq_nat2)[0]), + (char **)&(((uint64_t *)_seq_nat2)[0])), + SLIM_IFPTR32( + (uint32_t *)&(((uint32_t *)_seq_nat2)[1]), + (uint32_t *)&(((uint32_t *)_seq_nat2)[2])))); + } + _COPY(_primROut, 0, _rout3, 0, 4); + _COPY(_primROut, 4, _rout4, 0, 2); + _CATCH(_nErr) {} + _allocator_deinit(_al); + return _nErr; } -static __inline int _skel_method_15(int (*_pfn)(apps_std_FILE, unsigned char*, int, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _rout1[1] = {0}; - uint32_t _rout1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_rout1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); - _rout1[0] = _praROut[0].buf.pv; - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (unsigned char*)*_rout1, (int)*_rout1Len, (int*)_rout2)); - _COPY(_primROut, 0, _rout2, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_15(int (*_pfn)(apps_std_FILE, unsigned char *, int, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_rout1[1] = { 0 }; + uint32_t _rout1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_rout1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); + _rout1[0] = _praROut[0].buf.pv; + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (unsigned char *)*_rout1, + (int)*_rout1Len, (int *)_rout2)); + _COPY(_primROut, 0, _rout2, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_16(int (*_pfn)(const char*, const char*, const char*, const char*, apps_std_FILE*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - char* _in2[1] = {0}; - uint32_t _in2Len[1] = {0}; - char* _in3[1] = {0}; - uint32_t _in3Len[1] = {0}; - uint32_t _rout4[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==5); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((5 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 16); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_in1Len, 0, _primIn, 4, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2Len, 0, _primIn, 8, 4); - _ASSERT(_nErr, ((_praIn[2].buf.nLen / 1)) >= (size_t)(_in2Len[0])); - _in2[0] = _praIn[2].buf.pv; - _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); - _COPY(_in3Len, 0, _primIn, 12, 4); - _ASSERT(_nErr, ((_praIn[3].buf.nLen / 1)) >= (size_t)(_in3Len[0])); - _in3[0] = _praIn[3].buf.pv; - _ASSERT(_nErr, (_in3Len[0] > 0) && (_in3[0][(_in3Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in0, (const char*)*_in1, (const char*)*_in2, (const char*)*_in3, (apps_std_FILE*)_rout4)); - _COPY(_primROut, 0, _rout4, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_16(int (*_pfn)(const char *, const char *, const char *, + const char *, apps_std_FILE *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + char *_in2[1] = { 0 }; + uint32_t _in2Len[1] = { 0 }; + char *_in3[1] = { 0 }; + uint32_t _in3Len[1] = { 0 }; + uint32_t _rout4[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 5); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((5 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 16); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_in1Len, 0, _primIn, 4, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2Len, 0, _primIn, 8, 4); + _ASSERT(_nErr, ((_praIn[2].buf.nLen / 1)) >= (size_t)(_in2Len[0])); + _in2[0] = _praIn[2].buf.pv; + _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); + _COPY(_in3Len, 0, _primIn, 12, 4); + _ASSERT(_nErr, ((_praIn[3].buf.nLen / 1)) >= (size_t)(_in3Len[0])); + _in3[0] = _praIn[3].buf.pv; + _ASSERT(_nErr, (_in3Len[0] > 0) && (_in3[0][(_in3Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in0, (const char *)*_in1, + (const char *)*_in2, (const char *)*_in3, + (apps_std_FILE *)_rout4)); + _COPY(_primROut, 0, _rout4, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_17(int (*_pfn)(const char*, const char*, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - uint32_t _in2[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==3); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((3 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_in1Len, 0, _primIn, 4, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2, 0, _primIn, 8, 4); - _TRY(_nErr, _pfn((const char*)*_in0, (const char*)*_in1, (int)*_in2)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_17(int (*_pfn)(const char *, const char *, int), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 3); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((3 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_in1Len, 0, _primIn, 4, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2, 0, _primIn, 8, 4); + _TRY(_nErr, + _pfn((const char *)*_in0, (const char *)*_in1, (int)*_in2)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_18(int (*_pfn)(const char*, char*, int, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - char* _rout1[1] = {0}; - uint32_t _rout1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_rout1Len, 0, _primIn, 4, 4); - _praROut = (_praIn + _numIn[0] + 1); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); - _rout1[0] = _praROut[0].buf.pv; - _TRY(_nErr, _pfn((const char*)*_in0, (char*)*_rout1, (int)*_rout1Len, (int*)_rout2)); - _COPY(_primROut, 0, _rout2, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_18(int (*_pfn)(const char *, char *, int, int *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + char *_rout1[1] = { 0 }; + uint32_t _rout1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_rout1Len, 0, _primIn, 4, 4); + _praROut = (_praIn + _numIn[0] + 1); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); + _rout1[0] = _praROut[0].buf.pv; + _TRY(_nErr, _pfn((const char *)*_in0, (char *)*_rout1, (int)*_rout1Len, + (int *)_rout2)); + _COPY(_primROut, 0, _rout2, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_19(int (*_pfn)(apps_std_FILE, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _rout1[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (int*)_rout1)); - _COPY(_primROut, 0, _rout1, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_19(int (*_pfn)(apps_std_FILE, int *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _rout1[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (int *)_rout1)); + _COPY(_primROut, 0, _rout1, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_20(int (*_pfn)(apps_std_FILE, uint64_t*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint64_t _rout1[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint64_t* _primROut= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 4); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (uint64_t*)_rout1)); - _COPY(_primROut, 0, _rout1, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_20(int (*_pfn)(apps_std_FILE, uint64_t *), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint64_t _rout1[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint64_t *_primROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 4); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (uint64_t *)_rout1)); + _COPY(_primROut, 0, _rout1, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_21(int (*_pfn)(apps_std_FILE, int, apps_std_SEEK), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - uint32_t _in1[1] = {0}; - uint32_t _in2[1] = {0}; - uint32_t* _primIn= 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1, 0, _primIn, 4, 4); - _COPY(_in2, 0, _primIn, 8, 4); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (int)*_in1, (apps_std_SEEK)*_in2)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_21(int (*_pfn)(apps_std_FILE, int, apps_std_SEEK), uint32_t _sc, + remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + uint32_t _in1[1] = { 0 }; + uint32_t _in2[1] = { 0 }; + uint32_t *_primIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1, 0, _primIn, 4, 4); + _COPY(_in2, 0, _primIn, 8, 4); + _TRY(_nErr, + _pfn((apps_std_FILE)*_in0, (int)*_in1, (apps_std_SEEK)*_in2)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_22(int (*_pfn)(apps_std_FILE, const unsigned char*, int), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - uint32_t* _primIn= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const unsigned char*)*_in1, (int)*_in1Len)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_22(int (*_pfn)(apps_std_FILE, const unsigned char *, int), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + uint32_t *_primIn = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 0) + (((0 + 0) + 0) + 0))) <= _praEnd); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const unsigned char *)*_in1, + (int)*_in1Len)); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_23(int (*_pfn)(apps_std_FILE, const unsigned char*, int, int*, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t _rout3[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const unsigned char*)*_in1, (int)*_in1Len, (int*)_rout2, (int*)_rout3)); - _COPY(_primROut, 0, _rout2, 0, 4); - _COPY(_primROut, 4, _rout3, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_23(int (*_pfn)(apps_std_FILE, const unsigned char *, int, int *, + int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((2 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const unsigned char *)*_in1, + (int)*_in1Len, (int *)_rout2, (int *)_rout3)); + _COPY(_primROut, 0, _rout2, 0, 4); + _COPY(_primROut, 4, _rout3, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_24(int (*_pfn)(apps_std_FILE, unsigned char*, int, int*, int*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _rout1[1] = {0}; - uint32_t _rout1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t _rout3[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==2); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_rout1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); - _rout1[0] = _praROut[0].buf.pv; - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (unsigned char*)*_rout1, (int)*_rout1Len, (int*)_rout2, (int*)_rout3)); - _COPY(_primROut, 0, _rout2, 0, 4); - _COPY(_primROut, 4, _rout3, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_24(int (*_pfn)(apps_std_FILE, unsigned char *, int, int *, int *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_rout1[1] = { 0 }; + uint32_t _rout1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 2); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((1 + 2) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_rout1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _ASSERT(_nErr, ((_praROut[0].buf.nLen / 1)) >= (size_t)(_rout1Len[0])); + _rout1[0] = _praROut[0].buf.pv; + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (unsigned char *)*_rout1, + (int)*_rout1Len, (int *)_rout2, (int *)_rout3)); + _COPY(_primROut, 0, _rout2, 0, 4); + _COPY(_primROut, 4, _rout3, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_25(int (*_pfn)(apps_std_FILE, const char*, const char*, apps_std_FILE*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - uint32_t _in0[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - char* _in2[1] = {0}; - uint32_t _in2Len[1] = {0}; - uint32_t _rout3[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==3); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 12); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0, 0, _primIn, 0, 4); - _COPY(_in1Len, 0, _primIn, 4, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _COPY(_in2Len, 0, _primIn, 8, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); - _in2[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const char*)*_in1, (const char*)*_in2, (apps_std_FILE*)_rout3)); - _COPY(_primROut, 0, _rout3, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_25(int (*_pfn)(apps_std_FILE, const char *, const char *, + apps_std_FILE *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + uint32_t _in0[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + char *_in2[1] = { 0 }; + uint32_t _in2Len[1] = { 0 }; + uint32_t _rout3[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 3); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 12); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0, 0, _primIn, 0, 4); + _COPY(_in1Len, 0, _primIn, 4, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _COPY(_in2Len, 0, _primIn, 8, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in2Len[0])); + _in2[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in2Len[0] > 0) && (_in2[0][(_in2Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((apps_std_FILE)*_in0, (const char *)*_in1, + (const char *)*_in2, (apps_std_FILE *)_rout3)); + _COPY(_primROut, 0, _rout3, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -static __inline int _skel_method_26(int (*_pfn)(const char*, const char*, apps_std_FILE*), uint32_t _sc, remote_arg* _pra) { - remote_arg* _praEnd = 0; - char* _in0[1] = {0}; - uint32_t _in0Len[1] = {0}; - char* _in1[1] = {0}; - uint32_t _in1Len[1] = {0}; - uint32_t _rout2[1] = {0}; - uint32_t* _primIn= 0; - int _numIn[1] = {0}; - uint32_t* _primROut= 0; - remote_arg* _praIn = 0; - int _nErr = 0; - _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + REMOTE_SCALARS_OUTHANDLES(_sc)); - _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc)==3); - _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc)==1); - _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc)==0); - _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc)==0); - _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); - _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); - _ASSERT(_nErr, _pra[0].buf.nLen >= 8); - _primIn = _pra[0].buf.pv; - _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); - _primROut = _pra[(_numIn[0] + 1)].buf.pv; - _COPY(_in0Len, 0, _primIn, 0, 4); - _praIn = (_pra + 1); - _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); - _in0[0] = _praIn[0].buf.pv; - _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); - _COPY(_in1Len, 0, _primIn, 4, 4); - _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); - _in1[0] = _praIn[1].buf.pv; - _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); - _TRY(_nErr, _pfn((const char*)*_in0, (const char*)*_in1, (apps_std_FILE*)_rout2)); - _COPY(_primROut, 0, _rout2, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_skel_method_26(int (*_pfn)(const char *, const char *, apps_std_FILE *), + uint32_t _sc, remote_arg *_pra) +{ + remote_arg *_praEnd = 0; + char *_in0[1] = { 0 }; + uint32_t _in0Len[1] = { 0 }; + char *_in1[1] = { 0 }; + uint32_t _in1Len[1] = { 0 }; + uint32_t _rout2[1] = { 0 }; + uint32_t *_primIn = 0; + int _numIn[1] = { 0 }; + uint32_t *_primROut = 0; + remote_arg *_praIn = 0; + int _nErr = 0; + _praEnd + = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + + REMOTE_SCALARS_OUTBUFS(_sc) + REMOTE_SCALARS_INHANDLES(_sc) + + REMOTE_SCALARS_OUTHANDLES(_sc)); + _ASSERT(_nErr, REMOTE_SCALARS_INBUFS(_sc) == 3); + _ASSERT(_nErr, REMOTE_SCALARS_OUTBUFS(_sc) == 1); + _ASSERT(_nErr, REMOTE_SCALARS_INHANDLES(_sc) == 0); + _ASSERT(_nErr, REMOTE_SCALARS_OUTHANDLES(_sc) == 0); + _ASSERT(_nErr, (_pra + ((3 + 1) + (((0 + 0) + 0) + 0))) <= _praEnd); + _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1); + _ASSERT(_nErr, _pra[0].buf.nLen >= 8); + _primIn = _pra[0].buf.pv; + _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4); + _primROut = _pra[(_numIn[0] + 1)].buf.pv; + _COPY(_in0Len, 0, _primIn, 0, 4); + _praIn = (_pra + 1); + _ASSERT(_nErr, ((_praIn[0].buf.nLen / 1)) >= (size_t)(_in0Len[0])); + _in0[0] = _praIn[0].buf.pv; + _ASSERT(_nErr, (_in0Len[0] > 0) && (_in0[0][(_in0Len[0] - 1)] == 0)); + _COPY(_in1Len, 0, _primIn, 4, 4); + _ASSERT(_nErr, ((_praIn[1].buf.nLen / 1)) >= (size_t)(_in1Len[0])); + _in1[0] = _praIn[1].buf.pv; + _ASSERT(_nErr, (_in1Len[0] > 0) && (_in1[0][(_in1Len[0] - 1)] == 0)); + _TRY(_nErr, _pfn((const char *)*_in0, (const char *)*_in1, + (apps_std_FILE *)_rout2)); + _COPY(_primROut, 0, _rout2, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_SKEL_EXPORT int __QAIC_SKEL(apps_std_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_SKEL_ATTRIBUTE { - switch(REMOTE_SCALARS_METHOD(_sc)) - { - case 0: - return _skel_method_26(__QAIC_IMPL(apps_std_fopen), _sc, _pra); - case 1: - return _skel_method_25(__QAIC_IMPL(apps_std_freopen), _sc, _pra); - case 2: - return _skel_method_12(__QAIC_IMPL(apps_std_fflush), _sc, _pra); - case 3: - return _skel_method_12(__QAIC_IMPL(apps_std_fclose), _sc, _pra); - case 4: - return _skel_method_24(__QAIC_IMPL(apps_std_fread), _sc, _pra); - case 5: - return _skel_method_23(__QAIC_IMPL(apps_std_fwrite), _sc, _pra); - case 6: - return _skel_method_15(__QAIC_IMPL(apps_std_fgetpos), _sc, _pra); - case 7: - return _skel_method_22(__QAIC_IMPL(apps_std_fsetpos), _sc, _pra); - case 8: - return _skel_method_19(__QAIC_IMPL(apps_std_ftell), _sc, _pra); - case 9: - return _skel_method_21(__QAIC_IMPL(apps_std_fseek), _sc, _pra); - case 10: - return _skel_method_20(__QAIC_IMPL(apps_std_flen), _sc, _pra); - case 11: - return _skel_method_12(__QAIC_IMPL(apps_std_rewind), _sc, _pra); - case 12: - return _skel_method_19(__QAIC_IMPL(apps_std_feof), _sc, _pra); - case 13: - return _skel_method_19(__QAIC_IMPL(apps_std_ferror), _sc, _pra); - case 14: - return _skel_method_12(__QAIC_IMPL(apps_std_clearerr), _sc, _pra); - case 15: - return _skel_method_6(__QAIC_IMPL(apps_std_print_string), _sc, _pra); - case 16: - return _skel_method_18(__QAIC_IMPL(apps_std_getenv), _sc, _pra); - case 17: - return _skel_method_17(__QAIC_IMPL(apps_std_setenv), _sc, _pra); - case 18: - return _skel_method_6(__QAIC_IMPL(apps_std_unsetenv), _sc, _pra); - case 19: - return _skel_method_16(__QAIC_IMPL(apps_std_fopen_with_env), _sc, _pra); - case 20: - return _skel_method_15(__QAIC_IMPL(apps_std_fgets), _sc, _pra); - case 21: - return _skel_method_14(__QAIC_IMPL(apps_std_get_search_paths_with_env), _sc, _pra); - case 22: - return _skel_method_13(__QAIC_IMPL(apps_std_fileExists), _sc, _pra); - case 23: - return _skel_method_12(__QAIC_IMPL(apps_std_fsync), _sc, _pra); - case 24: - return _skel_method_6(__QAIC_IMPL(apps_std_fremove), _sc, _pra); - case 25: - return _skel_method_11(__QAIC_IMPL(apps_std_fdopen_decrypt), _sc, _pra); - case 26: - return _skel_method_10(__QAIC_IMPL(apps_std_opendir), _sc, _pra); - case 27: - return _skel_method_9(__QAIC_IMPL(apps_std_closedir), _sc, _pra); - case 28: - return _skel_method_8(__QAIC_IMPL(apps_std_readdir), _sc, _pra); - case 29: - return _skel_method_7(__QAIC_IMPL(apps_std_mkdir), _sc, _pra); - case 30: - return _skel_method_6(__QAIC_IMPL(apps_std_rmdir), _sc, _pra); - case 31: - { - uint32_t* _mid; - if(REMOTE_SCALARS_INBUFS(_sc) < 1 || _pra[0].buf.nLen < 4) { return AEE_EBADPARM; } - _mid = (uint32_t*)_pra[0].buf.pv; - return _skel_invoke(*_mid, _sc, _pra); - } - } - return AEE_EUNSUPPORTED; +__QAIC_SKEL_EXPORT int +__QAIC_SKEL(apps_std_skel_invoke)(uint32_t _sc, + remote_arg *_pra) __QAIC_SKEL_ATTRIBUTE +{ + switch(REMOTE_SCALARS_METHOD(_sc)) { + case 0: + return _skel_method_26(__QAIC_IMPL(apps_std_fopen), _sc, _pra); + case 1: + return _skel_method_25(__QAIC_IMPL(apps_std_freopen), _sc, + _pra); + case 2: + return _skel_method_12(__QAIC_IMPL(apps_std_fflush), _sc, + _pra); + case 3: + return _skel_method_12(__QAIC_IMPL(apps_std_fclose), _sc, + _pra); + case 4: + return _skel_method_24(__QAIC_IMPL(apps_std_fread), _sc, _pra); + case 5: + return _skel_method_23(__QAIC_IMPL(apps_std_fwrite), _sc, + _pra); + case 6: + return _skel_method_15(__QAIC_IMPL(apps_std_fgetpos), _sc, + _pra); + case 7: + return _skel_method_22(__QAIC_IMPL(apps_std_fsetpos), _sc, + _pra); + case 8: + return _skel_method_19(__QAIC_IMPL(apps_std_ftell), _sc, _pra); + case 9: + return _skel_method_21(__QAIC_IMPL(apps_std_fseek), _sc, _pra); + case 10: + return _skel_method_20(__QAIC_IMPL(apps_std_flen), _sc, _pra); + case 11: + return _skel_method_12(__QAIC_IMPL(apps_std_rewind), _sc, + _pra); + case 12: + return _skel_method_19(__QAIC_IMPL(apps_std_feof), _sc, _pra); + case 13: + return _skel_method_19(__QAIC_IMPL(apps_std_ferror), _sc, + _pra); + case 14: + return _skel_method_12(__QAIC_IMPL(apps_std_clearerr), _sc, + _pra); + case 15: + return _skel_method_6(__QAIC_IMPL(apps_std_print_string), _sc, + _pra); + case 16: + return _skel_method_18(__QAIC_IMPL(apps_std_getenv), _sc, + _pra); + case 17: + return _skel_method_17(__QAIC_IMPL(apps_std_setenv), _sc, + _pra); + case 18: + return _skel_method_6(__QAIC_IMPL(apps_std_unsetenv), _sc, + _pra); + case 19: + return _skel_method_16(__QAIC_IMPL(apps_std_fopen_with_env), + _sc, _pra); + case 20: + return _skel_method_15(__QAIC_IMPL(apps_std_fgets), _sc, _pra); + case 21: + return _skel_method_14( + __QAIC_IMPL(apps_std_get_search_paths_with_env), _sc, + _pra); + case 22: + return _skel_method_13(__QAIC_IMPL(apps_std_fileExists), _sc, + _pra); + case 23: + return _skel_method_12(__QAIC_IMPL(apps_std_fsync), _sc, _pra); + case 24: + return _skel_method_6(__QAIC_IMPL(apps_std_fremove), _sc, + _pra); + case 25: + return _skel_method_11(__QAIC_IMPL(apps_std_fdopen_decrypt), + _sc, _pra); + case 26: + return _skel_method_10(__QAIC_IMPL(apps_std_opendir), _sc, + _pra); + case 27: + return _skel_method_9(__QAIC_IMPL(apps_std_closedir), _sc, + _pra); + case 28: + return _skel_method_8(__QAIC_IMPL(apps_std_readdir), _sc, + _pra); + case 29: + return _skel_method_7(__QAIC_IMPL(apps_std_mkdir), _sc, _pra); + case 30: + return _skel_method_6(__QAIC_IMPL(apps_std_rmdir), _sc, _pra); + case 31: { + uint32_t *_mid; + if(REMOTE_SCALARS_INBUFS(_sc) < 1 || _pra[0].buf.nLen < 4) { + return AEE_EBADPARM; + } + _mid = (uint32_t *)_pra[0].buf.pv; + return _skel_invoke(*_mid, _sc, _pra); + } + } + return AEE_EUNSUPPORTED; } #ifdef __cplusplus } diff --git a/src/dspqueue/dspqueue_cpu.c b/src/dspqueue/dspqueue_cpu.c index 66092fa6..a347ddd2 100644 --- a/src/dspqueue/dspqueue_cpu.c +++ b/src/dspqueue/dspqueue_cpu.c @@ -1,7 +1,6 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause - #ifndef VERIFY_PRINT_ERROR #define VERIFY_PRINT_ERROR #endif @@ -11,12 +10,12 @@ #define FARF_ERROR 1 #define FARF_HIGH 0 #define FARF_MEDIUM 0 -//#ifndef _DEBUG -//# define _DEBUG -//#endif -//#ifdef NDEBUG -//# undef NDEBUG -//#endif +// #ifndef _DEBUG +// # define _DEBUG +// #endif +// #ifdef NDEBUG +// # undef NDEBUG +// #endif #include "AEEQList.h" // Needed by fastrpc_mem.h #include "dspqueue.h" @@ -24,9 +23,9 @@ #include "dspqueue_shared.h" #include "dspsignal.h" #include "fastrpc_apps_user.h" +#include "fastrpc_context.h" #include "fastrpc_internal.h" #include "fastrpc_mem.h" -#include "fastrpc_context.h" #include "remote.h" #include "verify.h" #include @@ -40,84 +39,87 @@ #include struct dspqueue { - unsigned id; - int domain; - struct dspqueue_multidomain mdq; - struct dspqueue_header *header; - void *user_queue; - int user_queue_fd; - uint32_t user_queue_size; - remote_handle64 dsp_handle; - uint64_t dsp_id; - uint16_t seq_no; - pthread_mutex_t mutex; - uint32_t read_packet_count; - uint32_t write_packet_count; - uint32_t req_packet_count; - uint32_t req_space_count; - uint32_t resp_packet_count; - uint32_t resp_space_count; - uint32_t packet_mask; - pthread_mutex_t packet_mutex; - pthread_cond_t packet_cond; - uint32_t space_mask; - pthread_mutex_t space_mutex; - pthread_cond_t space_cond; - int signal_threads; - dspqueue_callback_t packet_callback; - dspqueue_callback_t error_callback; - void *callback_context; - pthread_t packet_callback_thread; - uint64_t early_wakeup_wait; - uint32_t early_wakeup_misses; - uint32_t queue_count; - int have_wait_counts; - int have_driver_signaling; - pthread_t error_callback_thread; + unsigned id; + int domain; + struct dspqueue_multidomain mdq; + struct dspqueue_header *header; + void *user_queue; + int user_queue_fd; + uint32_t user_queue_size; + remote_handle64 dsp_handle; + uint64_t dsp_id; + uint16_t seq_no; + pthread_mutex_t mutex; + uint32_t read_packet_count; + uint32_t write_packet_count; + uint32_t req_packet_count; + uint32_t req_space_count; + uint32_t resp_packet_count; + uint32_t resp_space_count; + uint32_t packet_mask; + pthread_mutex_t packet_mutex; + pthread_cond_t packet_cond; + uint32_t space_mask; + pthread_mutex_t space_mutex; + pthread_cond_t space_cond; + int signal_threads; + dspqueue_callback_t packet_callback; + dspqueue_callback_t error_callback; + void *callback_context; + pthread_t packet_callback_thread; + uint64_t early_wakeup_wait; + uint32_t early_wakeup_misses; + uint32_t queue_count; + int have_wait_counts; + int have_driver_signaling; + pthread_t error_callback_thread; }; struct dspqueue_domain_queues { - int domain; - unsigned num_queues; - pthread_mutex_t - queue_list_mutex; // Hold this to manipulate queues[] or max_queue - unsigned max_queue; - struct dspqueue *queues[DSPQUEUE_MAX_PROCESS_QUEUES]; - struct dspqueue_process_queue_state *state; - int state_fd; - remote_handle64 dsp_handle; - pthread_t send_signal_thread; - pthread_mutex_t send_signal_mutex; - pthread_cond_t send_signal_cond; - uint32_t send_signal_mask; - pthread_t receive_signal_thread; - int dsp_error; - int have_dspsignal; + int domain; + unsigned num_queues; + pthread_mutex_t + queue_list_mutex; // Hold this to manipulate queues[] or max_queue + unsigned max_queue; + struct dspqueue *queues[DSPQUEUE_MAX_PROCESS_QUEUES]; + struct dspqueue_process_queue_state *state; + int state_fd; + remote_handle64 dsp_handle; + pthread_t send_signal_thread; + pthread_mutex_t send_signal_mutex; + pthread_cond_t send_signal_cond; + uint32_t send_signal_mask; + pthread_t receive_signal_thread; + int dsp_error; + int have_dspsignal; }; -static inline void free_skel_uri(remote_rpc_get_uri_t *dspqueue_skel) { - if (dspqueue_skel->domain_name) { - free(dspqueue_skel->domain_name); - } - if (dspqueue_skel->module_uri) { - free(dspqueue_skel->module_uri); - } - if (dspqueue_skel->uri) { - free(dspqueue_skel->uri); - } +static inline void +free_skel_uri(remote_rpc_get_uri_t *dspqueue_skel) +{ + if(dspqueue_skel->domain_name) { + free(dspqueue_skel->domain_name); + } + if(dspqueue_skel->module_uri) { + free(dspqueue_skel->module_uri); + } + if(dspqueue_skel->uri) { + free(dspqueue_skel->uri); + } } #define UNUSED_QUEUE ((struct dspqueue *)NULL) #define INVALID_QUEUE ((struct dspqueue *)-1) struct dspqueue_process_queues { - pthread_mutex_t mutex; // Hold this to manipulate domain_queues or - // domain_queues[i]->num_queues; In other words, must - // hold this mutex to decide when to create/destroy a - // new struct dspqueue_domain_queues. - struct dspqueue_domain_queues *domain_queues[NUM_DOMAINS_EXTEND]; - uint32_t count; - int notif_registered[NUM_DOMAINS_EXTEND]; + pthread_mutex_t + mutex; // Hold this to manipulate domain_queues or + // domain_queues[i]->num_queues; In other words, must + // hold this mutex to decide when to create/destroy a + // new struct dspqueue_domain_queues. + struct dspqueue_domain_queues *domain_queues[NUM_DOMAINS_EXTEND]; + uint32_t count; + int notif_registered[NUM_DOMAINS_EXTEND]; }; static struct dspqueue_process_queues proc_queues; @@ -129,8 +131,8 @@ static void *dspqueue_receive_signal_thread(void *arg); static void *dspqueue_packet_callback_thread(void *arg); #define QUEUE_CACHE_ALIGN 256 -#define CACHE_ALIGN_SIZE(x) \ - ((x + (QUEUE_CACHE_ALIGN - 1)) & (~(QUEUE_CACHE_ALIGN - 1))) +#define CACHE_ALIGN_SIZE(x) \ + ((x + (QUEUE_CACHE_ALIGN - 1)) & (~(QUEUE_CACHE_ALIGN - 1))) // Cache maintenance ops. No-op for now - assuming cache coherency. // Leave macros in place in case we want to make the buffer non-coherent @@ -142,7 +144,7 @@ static void *dspqueue_packet_callback_thread(void *arg); #define barrier_full() __asm__ __volatile__("dmb sy" : : : "memory") #define barrier_store() __asm__ __volatile__("dmb st" : : : "memory"); #else -#define barrier_full() /* FIXME */ +#define barrier_full() /* FIXME */ #define barrier_store() /* FIXME */ #endif #define cache_flush(a, l) @@ -154,8 +156,9 @@ static void *dspqueue_packet_callback_thread(void *arg); #define EARLY_WAKEUP_SLEEP 100 // Signal ID to match a specific queue signal -#define QUEUE_SIGNAL(queue_id, signal_no) \ - ((DSPQUEUE_NUM_SIGNALS * queue_id) + signal_no + DSPSIGNAL_DSPQUEUE_MIN) +#define QUEUE_SIGNAL(queue_id, signal_no) \ + ((DSPQUEUE_NUM_SIGNALS * queue_id) + signal_no \ + + DSPSIGNAL_DSPQUEUE_MIN) // Packet/space/send signal bit mask values #define SIGNAL_BIT_SIGNAL 1 @@ -166,591 +169,664 @@ static int dspqueue_notif_callback(void *context, int domain, int session, // Initialize process static queue structure. This should realistically never // fail. -static void init_process_queues_once(void) { - if (pthread_mutex_init(&queues->mutex, NULL) != 0) { - FARF(ERROR, "Mutex init failed"); - return; - } - queues->count = 1; // Start non-zero to help spot certain errors +static void +init_process_queues_once(void) +{ + if(pthread_mutex_init(&queues->mutex, NULL) != 0) { + FARF(ERROR, "Mutex init failed"); + return; + } + queues->count = 1; // Start non-zero to help spot certain errors } // Dynamically initialize process queue structure. This allocates memory and // creates threads for queue signaling. The resources will be freed after // the last queue in the process is closed. // Must hold queues->mutex. -static AEEResult init_domain_queues_locked(int domain) { - - AEEResult nErr = AEE_SUCCESS; - pthread_attr_t tattr; - int sendmutex = 0, sendcond = 0, sendthread = 0, recvthread = 0, - dom = domain & DOMAIN_ID_MASK; - struct dspqueue_domain_queues *dq = NULL; - remote_rpc_get_uri_t dspqueue_skel = {0}; - int state_mapped = 0; - uint32_t cap = 0; - - errno = 0; - assert(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); - if (queues->domain_queues[domain] != NULL) { - return AEE_SUCCESS; - } - - VERIFYC((dq = calloc(1, sizeof(*dq))) != NULL, AEE_ENOMEMORY); - dq->domain = domain; - - /* Get URI of session */ - dspqueue_skel.domain_name_len = (dom == CDSP1_DOMAIN_ID) ? - strlen(CDSP1_DOMAIN_NAME) + 1 : strlen(CDSP_DOMAIN_NAME) + 1; - VERIFYC((dspqueue_skel.domain_name = (char *)calloc( - dspqueue_skel.domain_name_len, sizeof(char))) != NULL, - AEE_ENOMEMORY); - - // Open session on the right DSP - if (dom == CDSP_DOMAIN_ID) { - strlcpy(dspqueue_skel.domain_name, CDSP_DOMAIN_NAME, - dspqueue_skel.domain_name_len); - } else if (dom == ADSP_DOMAIN_ID) { - strlcpy(dspqueue_skel.domain_name, ADSP_DOMAIN_NAME, - dspqueue_skel.domain_name_len); - } else if (dom == CDSP1_DOMAIN_ID) { - strlcpy(dspqueue_skel.domain_name, CDSP1_DOMAIN_NAME, - dspqueue_skel.domain_name_len); - } else { - nErr = AEE_EUNSUPPORTED; - goto bail; - } - dspqueue_skel.session_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); - - /* One extra character for NULL termination */ - dspqueue_skel.module_uri_len = strlen(dspqueue_rpc_URI) + 1; - VERIFYC((dspqueue_skel.module_uri = (char *)calloc( - dspqueue_skel.module_uri_len, sizeof(char))) != NULL, - AEE_ENOMEMORY); - strlcpy(dspqueue_skel.module_uri, dspqueue_rpc_URI, - dspqueue_skel.module_uri_len); - - /* One extra character for NULL termination is already part of module_uri_len - */ - dspqueue_skel.uri_len = dspqueue_skel.module_uri_len + FASTRPC_URI_BUF_LEN; - VERIFYC((dspqueue_skel.uri = - (char *)calloc(dspqueue_skel.uri_len, sizeof(char))) != NULL, - AEE_ENOMEMORY); - if ((nErr = remote_session_control(FASTRPC_GET_URI, (void *)&dspqueue_skel, - sizeof(dspqueue_skel))) != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s: obtaining session URI for %s on domain %d, session " - "%u failed\n", - nErr, __func__, dspqueue_rpc_URI, domain, dspqueue_skel.session_id); - /* In case of failure due to SSR, return corresponding error to client */ - if (nErr != AEE_ECONNRESET) - nErr = AEE_EUNSUPPORTED; - goto bail; - } - - if ((nErr = dspqueue_rpc_open(dspqueue_skel.uri, &dq->dsp_handle)) != 0) { - FARF(ERROR, - "dspqueue_rpc_open failed with %x on domain %d - packet queue support " - "likely not present on DSP", - nErr, domain); - /* In case of failure due to SSR, return corresponding error to client */ - if (nErr != AEE_ECONNRESET) - nErr = AEE_EUNSUPPORTED; - goto bail; - } - - if (!queues->notif_registered[domain]) { - // Register for process exit notifications. Only do this once for the - // lifetime of the process to avoid multiple registrations and leaks. - remote_rpc_notif_register_t reg = {.context = queues, - .domain = domain, - .notifier_fn = dspqueue_notif_callback}; - nErr = remote_session_control(FASTRPC_REGISTER_STATUS_NOTIFICATIONS, - (void *)®, sizeof(reg)); - if (nErr == AEE_EUNSUPPORTED) { - FARF(ERROR, "Warning 0x%x: %s: DSP doesn't support status notification", - nErr, __func__); - nErr = 0; - } else if (!nErr) { - queues->notif_registered[domain] = 1; - } else { - goto bail; - } - } - - // Allocate shared state structure and pass to DSP - VERIFYC((dq->state = rpcmem_alloc_internal( - RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS | RPCMEM_HEAP_NOREG, - sizeof(struct dspqueue_process_queue_state))) != NULL, - AEE_ENORPCMEMORY); - VERIFYC((((uintptr_t)dq->state) & 4095) == 0, AEE_ERPC); - VERIFYC((dq->state_fd = rpcmem_to_fd(dq->state)) > 0, AEE_ERPC); - VERIFY((nErr = fastrpc_mmap(domain, dq->state_fd, dq->state, 0, - sizeof(struct dspqueue_process_queue_state), - FASTRPC_MAP_FD)) == 0); - state_mapped = 1; - VERIFY((nErr = dspqueue_rpc_init_process_state(dq->dsp_handle, - dq->state_fd)) == 0); - - // Check if we have driver signaling (a.k.a. dspsignal) support - nErr = fastrpc_get_cap(domain, DSPSIGNAL_DSP_SUPPORT, &cap); - if ((nErr != 0) || (cap == 0)) { - FARF(HIGH, "dspqueue: No driver signaling support on DSP"); - } else { - nErr = fastrpc_get_cap(domain, DSPSIGNAL_DRIVER_SUPPORT, &cap); - if ((nErr != 0) || (cap == 0)) { - FARF(HIGH, "dspqueue: No driver signaling support in CPU driver"); - } else { - FARF(HIGH, "dspqueue: Optimized driver signaling supported"); - dq->have_dspsignal = 1; - } - } - - if (!dq->have_dspsignal) { - // Create thread and resources to send signals to the DSP - VERIFY((nErr = pthread_mutex_init(&dq->send_signal_mutex, NULL)) == 0); - sendmutex = 1; - VERIFY((nErr = pthread_cond_init(&dq->send_signal_cond, NULL)) == 0); - sendcond = 1; - dq->send_signal_mask = 0; - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - VERIFY((nErr = pthread_create(&dq->send_signal_thread, &tattr, - dspqueue_send_signal_thread, dq)) == 0); - sendthread = 1; - - // Create thread to receive signals from the DSP - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - VERIFY((nErr = pthread_create(&dq->receive_signal_thread, &tattr, - dspqueue_receive_signal_thread, dq)) == 0); - recvthread = 1; - } - - free_skel_uri(&dspqueue_skel); - queues->domain_queues[domain] = dq; - return AEE_SUCCESS; +static AEEResult +init_domain_queues_locked(int domain) +{ + + AEEResult nErr = AEE_SUCCESS; + pthread_attr_t tattr; + int sendmutex = 0, sendcond = 0, sendthread = 0, recvthread = 0, + dom = domain & DOMAIN_ID_MASK; + struct dspqueue_domain_queues *dq = NULL; + remote_rpc_get_uri_t dspqueue_skel = { 0 }; + int state_mapped = 0; + uint32_t cap = 0; + + errno = 0; + assert(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); + if(queues->domain_queues[domain] != NULL) { + return AEE_SUCCESS; + } + + VERIFYC((dq = calloc(1, sizeof(*dq))) != NULL, AEE_ENOMEMORY); + dq->domain = domain; + + /* Get URI of session */ + dspqueue_skel.domain_name_len = (dom == CDSP1_DOMAIN_ID) + ? strlen(CDSP1_DOMAIN_NAME) + 1 + : strlen(CDSP_DOMAIN_NAME) + 1; + VERIFYC((dspqueue_skel.domain_name + = (char *)calloc(dspqueue_skel.domain_name_len, sizeof(char))) + != NULL, + AEE_ENOMEMORY); + + // Open session on the right DSP + if(dom == CDSP_DOMAIN_ID) { + strlcpy(dspqueue_skel.domain_name, CDSP_DOMAIN_NAME, + dspqueue_skel.domain_name_len); + } else if(dom == ADSP_DOMAIN_ID) { + strlcpy(dspqueue_skel.domain_name, ADSP_DOMAIN_NAME, + dspqueue_skel.domain_name_len); + } else if(dom == CDSP1_DOMAIN_ID) { + strlcpy(dspqueue_skel.domain_name, CDSP1_DOMAIN_NAME, + dspqueue_skel.domain_name_len); + } else { + nErr = AEE_EUNSUPPORTED; + goto bail; + } + dspqueue_skel.session_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); + + /* One extra character for NULL termination */ + dspqueue_skel.module_uri_len = strlen(dspqueue_rpc_URI) + 1; + VERIFYC((dspqueue_skel.module_uri + = (char *)calloc(dspqueue_skel.module_uri_len, sizeof(char))) + != NULL, + AEE_ENOMEMORY); + strlcpy(dspqueue_skel.module_uri, dspqueue_rpc_URI, + dspqueue_skel.module_uri_len); + + /* One extra character for NULL termination is already part of + * module_uri_len + */ + dspqueue_skel.uri_len + = dspqueue_skel.module_uri_len + FASTRPC_URI_BUF_LEN; + VERIFYC((dspqueue_skel.uri + = (char *)calloc(dspqueue_skel.uri_len, sizeof(char))) + != NULL, + AEE_ENOMEMORY); + if((nErr + = remote_session_control(FASTRPC_GET_URI, (void *)&dspqueue_skel, + sizeof(dspqueue_skel))) + != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s: obtaining session URI for %s on domain " + "%d, session " + "%u failed\n", + nErr, __func__, dspqueue_rpc_URI, domain, + dspqueue_skel.session_id); + /* In case of failure due to SSR, return corresponding error to + * client */ + if(nErr != AEE_ECONNRESET) + nErr = AEE_EUNSUPPORTED; + goto bail; + } + + if((nErr = dspqueue_rpc_open(dspqueue_skel.uri, &dq->dsp_handle)) + != 0) { + FARF(ERROR, + "dspqueue_rpc_open failed with %x on domain %d - packet " + "queue support " + "likely not present on DSP", + nErr, domain); + /* In case of failure due to SSR, return corresponding error to + * client */ + if(nErr != AEE_ECONNRESET) + nErr = AEE_EUNSUPPORTED; + goto bail; + } + + if(!queues->notif_registered[domain]) { + // Register for process exit notifications. Only do this once + // for the lifetime of the process to avoid multiple + // registrations and leaks. + remote_rpc_notif_register_t reg + = { .context = queues, + .domain = domain, + .notifier_fn = dspqueue_notif_callback }; + nErr = remote_session_control( + FASTRPC_REGISTER_STATUS_NOTIFICATIONS, (void *)®, + sizeof(reg)); + if(nErr == AEE_EUNSUPPORTED) { + FARF(ERROR, + "Warning 0x%x: %s: DSP doesn't support status " + "notification", + nErr, __func__); + nErr = 0; + } else if(!nErr) { + queues->notif_registered[domain] = 1; + } else { + goto bail; + } + } + + // Allocate shared state structure and pass to DSP + VERIFYC((dq->state = rpcmem_alloc_internal( + RPCMEM_HEAP_ID_SYSTEM, + RPCMEM_DEFAULT_FLAGS | RPCMEM_HEAP_NOREG, + sizeof(struct dspqueue_process_queue_state))) + != NULL, + AEE_ENORPCMEMORY); + VERIFYC((((uintptr_t)dq->state) & 4095) == 0, AEE_ERPC); + VERIFYC((dq->state_fd = rpcmem_to_fd(dq->state)) > 0, AEE_ERPC); + VERIFY( + (nErr = fastrpc_mmap(domain, dq->state_fd, dq->state, 0, + sizeof(struct dspqueue_process_queue_state), + FASTRPC_MAP_FD)) + == 0); + state_mapped = 1; + VERIFY((nErr = dspqueue_rpc_init_process_state(dq->dsp_handle, + dq->state_fd)) + == 0); + + // Check if we have driver signaling (a.k.a. dspsignal) support + nErr = fastrpc_get_cap(domain, DSPSIGNAL_DSP_SUPPORT, &cap); + if((nErr != 0) || (cap == 0)) { + FARF(HIGH, "dspqueue: No driver signaling support on DSP"); + } else { + nErr = fastrpc_get_cap(domain, DSPSIGNAL_DRIVER_SUPPORT, &cap); + if((nErr != 0) || (cap == 0)) { + FARF(HIGH, "dspqueue: No driver signaling support in " + "CPU driver"); + } else { + FARF(HIGH, + "dspqueue: Optimized driver signaling supported"); + dq->have_dspsignal = 1; + } + } + + if(!dq->have_dspsignal) { + // Create thread and resources to send signals to the DSP + VERIFY( + (nErr = pthread_mutex_init(&dq->send_signal_mutex, NULL)) + == 0); + sendmutex = 1; + VERIFY((nErr = pthread_cond_init(&dq->send_signal_cond, NULL)) + == 0); + sendcond = 1; + dq->send_signal_mask = 0; + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + VERIFY((nErr = pthread_create(&dq->send_signal_thread, &tattr, + dspqueue_send_signal_thread, dq)) + == 0); + sendthread = 1; + + // Create thread to receive signals from the DSP + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + VERIFY( + (nErr = pthread_create(&dq->receive_signal_thread, &tattr, + dspqueue_receive_signal_thread, dq)) + == 0); + recvthread = 1; + } + + free_skel_uri(&dspqueue_skel); + queues->domain_queues[domain] = dq; + return AEE_SUCCESS; bail: - if (dq) { - if (recvthread) { - void *res; - dspqueue_rpc_cancel_wait_signal(dq->dsp_handle); - pthread_join(dq->receive_signal_thread, &res); - } - if (sendthread) { - void *res; - pthread_mutex_lock(&dq->send_signal_mutex); - dq->send_signal_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_signal(&dq->send_signal_cond); - pthread_mutex_unlock(&dq->send_signal_mutex); - pthread_join(dq->send_signal_thread, &res); - } - if (sendcond) { - pthread_cond_destroy(&dq->send_signal_cond); - } - if (sendmutex) { - pthread_mutex_destroy(&dq->send_signal_mutex); - } - if (state_mapped) { - fastrpc_munmap(domain, dq->state_fd, dq->state, - sizeof(struct dspqueue_process_queue_state)); - } - if (dq->dsp_handle) { - dspqueue_rpc_close(dq->dsp_handle); - } - if (dq->state) { - rpcmem_free(dq->state); - } - free(dq); - } - free_skel_uri(&dspqueue_skel); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, __func__, - domain, strerror(errno)); - } - return nErr; + if(dq) { + if(recvthread) { + void *res; + dspqueue_rpc_cancel_wait_signal(dq->dsp_handle); + pthread_join(dq->receive_signal_thread, &res); + } + if(sendthread) { + void *res; + pthread_mutex_lock(&dq->send_signal_mutex); + dq->send_signal_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_signal(&dq->send_signal_cond); + pthread_mutex_unlock(&dq->send_signal_mutex); + pthread_join(dq->send_signal_thread, &res); + } + if(sendcond) { + pthread_cond_destroy(&dq->send_signal_cond); + } + if(sendmutex) { + pthread_mutex_destroy(&dq->send_signal_mutex); + } + if(state_mapped) { + fastrpc_munmap( + domain, dq->state_fd, dq->state, + sizeof(struct dspqueue_process_queue_state)); + } + if(dq->dsp_handle) { + dspqueue_rpc_close(dq->dsp_handle); + } + if(dq->state) { + rpcmem_free(dq->state); + } + free(dq); + } + free_skel_uri(&dspqueue_skel); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, + __func__, domain, strerror(errno)); + } + return nErr; } // Must hold queues->mutex. -static AEEResult destroy_domain_queues_locked(int domain) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue_domain_queues *dq = NULL; - void *ret; - - errno = 0; - FARF(HIGH, "destroy_domain_queues_locked"); - assert(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); - assert(queues->domain_queues[domain] != NULL); - dq = queues->domain_queues[domain]; - assert(dq->num_queues == 0); - - if (!dq->have_dspsignal) { - if (dq->dsp_error) { - // Ignore errors if the DSP process died - dspqueue_rpc_cancel_wait_signal(dq->dsp_handle); - } else { - VERIFY((nErr = dspqueue_rpc_cancel_wait_signal(dq->dsp_handle)) == 0); - } - FARF(MEDIUM, "Join receive signal thread"); - VERIFY((nErr = pthread_join(dq->receive_signal_thread, &ret)) == 0); - FARF(MEDIUM, " - Join receive signal thread done"); - if (!dq->dsp_error) { - VERIFY(((uintptr_t)ret) == 0); - } - - pthread_mutex_lock(&dq->send_signal_mutex); - dq->send_signal_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_signal(&dq->send_signal_cond); - pthread_mutex_unlock(&dq->send_signal_mutex); - FARF(MEDIUM, "Join send signal thread"); - VERIFY((nErr = pthread_join(dq->send_signal_thread, &ret)) == 0); - if (!dq->dsp_error) { - VERIFY(((uintptr_t)ret) == 0); - } - FARF(MEDIUM, " - Join send signal thread done"); - - pthread_cond_destroy(&dq->send_signal_cond); - pthread_mutex_destroy(&dq->send_signal_mutex); - } - - if (dq->dsp_error) { - dspqueue_rpc_close(dq->dsp_handle); - fastrpc_munmap(dq->domain, dq->state_fd, dq->state, - sizeof(struct dspqueue_process_queue_state)); - } else { - VERIFY((nErr = dspqueue_rpc_close(dq->dsp_handle)) == 0); - VERIFY((nErr = fastrpc_munmap( - dq->domain, dq->state_fd, dq->state, - sizeof(struct dspqueue_process_queue_state))) == 0); - } - - rpcmem_free(dq->state); - free(dq); - - queues->domain_queues[domain] = NULL; +static AEEResult +destroy_domain_queues_locked(int domain) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue_domain_queues *dq = NULL; + void *ret; + + errno = 0; + FARF(HIGH, "destroy_domain_queues_locked"); + assert(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); + assert(queues->domain_queues[domain] != NULL); + dq = queues->domain_queues[domain]; + assert(dq->num_queues == 0); + + if(!dq->have_dspsignal) { + if(dq->dsp_error) { + // Ignore errors if the DSP process died + dspqueue_rpc_cancel_wait_signal(dq->dsp_handle); + } else { + VERIFY((nErr = dspqueue_rpc_cancel_wait_signal( + dq->dsp_handle)) + == 0); + } + FARF(MEDIUM, "Join receive signal thread"); + VERIFY((nErr = pthread_join(dq->receive_signal_thread, &ret)) + == 0); + FARF(MEDIUM, " - Join receive signal thread done"); + if(!dq->dsp_error) { + VERIFY(((uintptr_t)ret) == 0); + } + + pthread_mutex_lock(&dq->send_signal_mutex); + dq->send_signal_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_signal(&dq->send_signal_cond); + pthread_mutex_unlock(&dq->send_signal_mutex); + FARF(MEDIUM, "Join send signal thread"); + VERIFY((nErr = pthread_join(dq->send_signal_thread, &ret)) + == 0); + if(!dq->dsp_error) { + VERIFY(((uintptr_t)ret) == 0); + } + FARF(MEDIUM, " - Join send signal thread done"); + + pthread_cond_destroy(&dq->send_signal_cond); + pthread_mutex_destroy(&dq->send_signal_mutex); + } + + if(dq->dsp_error) { + dspqueue_rpc_close(dq->dsp_handle); + fastrpc_munmap(dq->domain, dq->state_fd, dq->state, + sizeof(struct dspqueue_process_queue_state)); + } else { + VERIFY((nErr = dspqueue_rpc_close(dq->dsp_handle)) == 0); + VERIFY((nErr = fastrpc_munmap( + dq->domain, dq->state_fd, dq->state, + sizeof(struct dspqueue_process_queue_state))) + == 0); + } + + rpcmem_free(dq->state); + free(dq); + + queues->domain_queues[domain] = NULL; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, __func__, - domain, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, + __func__, domain, strerror(errno)); + } + return nErr; } -AEEResult dspqueue_create(int domain, uint32_t flags, uint32_t req_queue_size, - uint32_t resp_queue_size, - dspqueue_callback_t packet_callback, - dspqueue_callback_t error_callback, - void *callback_context, dspqueue_t *queue) { - - struct dspqueue *q = NULL; - AEEResult nErr = AEE_SUCCESS; - uint32_t o; - int mutex_init = 0; - pthread_attr_t tattr; - unsigned id = DSPQUEUE_MAX_PROCESS_QUEUES; - struct dspqueue_domain_queues *dq = NULL; - int packetmutex = 0, packetcond = 0, spacemutex = 0, spacecond = 0; - int callbackthread = 0; - uint32_t queue_count; - int queue_mapped = 0; - unsigned signals = 0; - - VERIFYC(queue, AEE_EBADPARM); - *queue = NULL; - errno = 0; - - if (domain == -1) { - domain = get_current_domain(); - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { - return AEE_ERPC; - } - } else if (!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { - return AEE_EBADPARM; - } - - // Initialize process-level and per-domain queue structures and signaling - if (pthread_once(&queues_once, init_process_queues_once) != 0) { - FARF(ERROR, "dspqueue init failed"); - return AEE_ERPC; - } - pthread_mutex_lock(&queues->mutex); - if ((nErr = init_domain_queues_locked(domain)) != 0) { - pthread_mutex_unlock(&queues->mutex); - return nErr; - } - dq = queues->domain_queues[domain]; - if (!dq) { - FARF(ERROR, "No queues in process for domain %d", domain); - pthread_mutex_unlock(&queues->mutex); - return AEE_EBADPARM; - } - if ((dq && (dq->num_queues >= DSPQUEUE_MAX_PROCESS_QUEUES))) { - FARF(ERROR, "Too many queues in process for domain %d", domain); - pthread_mutex_unlock(&queues->mutex); - return AEE_EBADPARM; - } - dq->num_queues++; - queue_count = queues->count++; - pthread_mutex_unlock(&queues->mutex); - - // Find a free queue slot - pthread_mutex_lock(&dq->queue_list_mutex); - for (id = 0; id < DSPQUEUE_MAX_PROCESS_QUEUES; id++) { - if (dq->queues[id] == UNUSED_QUEUE) { - if (dq->max_queue < id) { - dq->max_queue = id; - } - break; - } - } - if (id >= DSPQUEUE_MAX_PROCESS_QUEUES) { - FARF(ERROR, "Queue list corrupt"); - pthread_mutex_unlock(&dq->queue_list_mutex); - nErr = AEE_ERPC; - goto bail; - } - dq->queues[id] = INVALID_QUEUE; - pthread_mutex_unlock(&dq->queue_list_mutex); - - VERIFYC(flags == 0, AEE_EBADPARM); - - // Check queue size limits - VERIFYC(req_queue_size <= DSPQUEUE_MAX_QUEUE_SIZE, AEE_EBADPARM); - VERIFYC(resp_queue_size <= DSPQUEUE_MAX_QUEUE_SIZE, AEE_EBADPARM); - - // Allocate internal queue structure - VERIFYC((q = calloc(1, sizeof(*q))) != NULL, AEE_ENOMEMORY); - VERIFY((nErr = pthread_mutex_init(&q->mutex, NULL)) == 0); - mutex_init = 1; - q->packet_callback = packet_callback; - q->error_callback = error_callback; - q->callback_context = callback_context; - q->id = id; - q->domain = domain; - - // Use defaults for unspecified parameters - if (req_queue_size == 0) { - req_queue_size = DSPQUEUE_DEFAULT_REQ_SIZE; - } - if (resp_queue_size == 0) { - resp_queue_size = DSPQUEUE_DEFAULT_RESP_SIZE; - } - - // Determine queue shared memory size and allocate memory. The memory - // contains: - // - Queue headers - // - Read and write states for both request and response queues (four total) - // - Request and response queues - // All are aligned to QUEUE_CACHE_ALIGN. - q->user_queue_size = - CACHE_ALIGN_SIZE(sizeof(struct dspqueue_header)) + - 4 * CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)) + - CACHE_ALIGN_SIZE(req_queue_size) + CACHE_ALIGN_SIZE(resp_queue_size); - - // Allocate queue shared memory and map to DSP - VERIFYC((q->user_queue = rpcmem_alloc_internal( - RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS | RPCMEM_HEAP_NOREG, - q->user_queue_size)) != NULL, - AEE_ENOMEMORY); - VERIFYC((((uintptr_t)q->user_queue) & 4095) == 0, AEE_ERPC); - VERIFYC((q->user_queue_fd = rpcmem_to_fd(q->user_queue)) > 0, AEE_ERPC); - VERIFY((nErr = fastrpc_mmap(domain, q->user_queue_fd, q->user_queue, 0, - q->user_queue_size, FASTRPC_MAP_FD)) == 0); - queue_mapped = 1; - q->header = q->user_queue; - - // Initialize queue header, including all offsets, and clear the queue - memset(q->header, 0, q->user_queue_size); - q->header->version = 1; - q->header->queue_count = queue_count; - q->queue_count = queue_count; - - // Request packet queue (CPU->DSP) - o = CACHE_ALIGN_SIZE(sizeof(struct dspqueue_header)); - q->header->req_queue.queue_offset = o; - q->header->req_queue.queue_length = req_queue_size; - o += CACHE_ALIGN_SIZE(req_queue_size); - q->header->req_queue.read_state_offset = o; - o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); - q->header->req_queue.write_state_offset = o; - o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); - - // Response packet queue (DSP->CPU) - q->header->resp_queue.queue_offset = o; - q->header->resp_queue.queue_length = resp_queue_size; - o += CACHE_ALIGN_SIZE(resp_queue_size); - q->header->resp_queue.read_state_offset = o; - o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); - q->header->resp_queue.write_state_offset = o; - o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); - - assert(o == q->user_queue_size); - - dq->state->req_packet_count[id] = 0; - cache_flush_word(&dq->state->req_packet_count[id]); - dq->state->resp_space_count[id] = 0; - cache_flush_word(&dq->state->resp_space_count[id]); - - // Try to create driver signals - if (dq->have_dspsignal) { - q->have_driver_signaling = 1; - for (signals = 0; signals < DSPQUEUE_NUM_SIGNALS; signals++) { - VERIFY((nErr = dspsignal_create(domain, QUEUE_SIGNAL(id, signals), 0)) == - AEE_SUCCESS); - } - } - - // First attempt to create the queue with an invalid version. If the call - // succeeds we know the DSP side is ignoring the version and flags and does - // not support wait counts in the header, driver signaling, or any other - // post-v1 features. Unfortunately the initial DSP codebase ignores the - // version and flags... - q->header->version = UINT32_MAX; - nErr = dspqueue_rpc_create_queue(dq->dsp_handle, q->id, q->user_queue_fd, - queue_count, &q->dsp_id); - if ((nErr == AEE_EUNSUPPORTED) || - (nErr == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED))) { - // OK, the DSP does pay attention to the version. It should also support - // wait counts and optionally driver signaling. Create the queue. - FARF(HIGH, "Initial queue create failed with %0x%x as expected", nErr); - q->header->version = DSPQUEUE_HEADER_CURRENT_VERSION; - q->header->flags = DSPQUEUE_HEADER_FLAG_WAIT_COUNTS; - if (q->have_driver_signaling) { - q->header->flags |= DSPQUEUE_HEADER_FLAG_DRIVER_SIGNALING; - } - VERIFY((nErr = dspqueue_rpc_create_queue(dq->dsp_handle, q->id, - q->user_queue_fd, queue_count, - &q->dsp_id)) == 0); - q->have_wait_counts = 1; - // Note that we expect the DSP will support both wait counts and driver - // signaling or neither. However we can operate with wait counts only in - // case we have an updated DSP image but an older CPU kernel driver without - // driver signaling support. - } else if (nErr != AEE_SUCCESS) { - FARF(ERROR, "dspqueue_rpc_create_queue failed: 0x%x", nErr); - goto bail; - } else { - FARF(HIGH, "First-cut queue create succeeded unexpectedly? 0x%x", nErr); - // No new features available, including driver signaling - if (q->have_driver_signaling) { - unsigned i; - FARF(HIGH, "Driver signaling not supported on DSP, fall back to FastRPC " - "signaling"); - for (i = 0; i < signals; i++) { - VERIFY((nErr = dspsignal_destroy(domain, QUEUE_SIGNAL(id, i))) == 0); - } - signals = 0; - } - q->have_driver_signaling = 0; - } - - // Create synchronization resources - VERIFY((nErr = pthread_mutex_init(&q->packet_mutex, NULL)) == 0); - packetmutex = 1; - VERIFY((nErr = pthread_mutex_init(&q->space_mutex, NULL)) == 0); - spacemutex = 1; - if (!q->have_driver_signaling) { - VERIFY((nErr = pthread_cond_init(&q->packet_cond, NULL)) == 0); - packetcond = 1; - VERIFY((nErr = pthread_cond_init(&q->space_cond, NULL)) == 0); - packetcond = 1; - } - - // Callback thread (if we have a message callback) - if (q->packet_callback) { - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - VERIFY((nErr = pthread_create(&q->packet_callback_thread, &tattr, - dspqueue_packet_callback_thread, q)) == 0); - callbackthread = 1; - } - - *queue = q; - pthread_mutex_lock(&dq->queue_list_mutex); - dq->queues[id] = q; - pthread_mutex_unlock(&dq->queue_list_mutex); - FARF(ALWAYS, "%s: created Queue %u, %p, DSP 0x%08x for domain %d", __func__, - q->id, q, (unsigned)q->dsp_id, q->domain); - - return AEE_SUCCESS; +AEEResult +dspqueue_create(int domain, uint32_t flags, uint32_t req_queue_size, + uint32_t resp_queue_size, dspqueue_callback_t packet_callback, + dspqueue_callback_t error_callback, void *callback_context, + dspqueue_t *queue) +{ + + struct dspqueue *q = NULL; + AEEResult nErr = AEE_SUCCESS; + uint32_t o; + int mutex_init = 0; + pthread_attr_t tattr; + unsigned id = DSPQUEUE_MAX_PROCESS_QUEUES; + struct dspqueue_domain_queues *dq = NULL; + int packetmutex = 0, packetcond = 0, spacemutex = 0, spacecond = 0; + int callbackthread = 0; + uint32_t queue_count; + int queue_mapped = 0; + unsigned signals = 0; + + VERIFYC(queue, AEE_EBADPARM); + *queue = NULL; + errno = 0; + + if(domain == -1) { + domain = get_current_domain(); + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { + return AEE_ERPC; + } + } else if(!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { + return AEE_EBADPARM; + } + + // Initialize process-level and per-domain queue structures and + // signaling + if(pthread_once(&queues_once, init_process_queues_once) != 0) { + FARF(ERROR, "dspqueue init failed"); + return AEE_ERPC; + } + pthread_mutex_lock(&queues->mutex); + if((nErr = init_domain_queues_locked(domain)) != 0) { + pthread_mutex_unlock(&queues->mutex); + return nErr; + } + dq = queues->domain_queues[domain]; + if(!dq) { + FARF(ERROR, "No queues in process for domain %d", domain); + pthread_mutex_unlock(&queues->mutex); + return AEE_EBADPARM; + } + if((dq && (dq->num_queues >= DSPQUEUE_MAX_PROCESS_QUEUES))) { + FARF(ERROR, "Too many queues in process for domain %d", + domain); + pthread_mutex_unlock(&queues->mutex); + return AEE_EBADPARM; + } + dq->num_queues++; + queue_count = queues->count++; + pthread_mutex_unlock(&queues->mutex); + + // Find a free queue slot + pthread_mutex_lock(&dq->queue_list_mutex); + for(id = 0; id < DSPQUEUE_MAX_PROCESS_QUEUES; id++) { + if(dq->queues[id] == UNUSED_QUEUE) { + if(dq->max_queue < id) { + dq->max_queue = id; + } + break; + } + } + if(id >= DSPQUEUE_MAX_PROCESS_QUEUES) { + FARF(ERROR, "Queue list corrupt"); + pthread_mutex_unlock(&dq->queue_list_mutex); + nErr = AEE_ERPC; + goto bail; + } + dq->queues[id] = INVALID_QUEUE; + pthread_mutex_unlock(&dq->queue_list_mutex); + + VERIFYC(flags == 0, AEE_EBADPARM); + + // Check queue size limits + VERIFYC(req_queue_size <= DSPQUEUE_MAX_QUEUE_SIZE, AEE_EBADPARM); + VERIFYC(resp_queue_size <= DSPQUEUE_MAX_QUEUE_SIZE, AEE_EBADPARM); + + // Allocate internal queue structure + VERIFYC((q = calloc(1, sizeof(*q))) != NULL, AEE_ENOMEMORY); + VERIFY((nErr = pthread_mutex_init(&q->mutex, NULL)) == 0); + mutex_init = 1; + q->packet_callback = packet_callback; + q->error_callback = error_callback; + q->callback_context = callback_context; + q->id = id; + q->domain = domain; + + // Use defaults for unspecified parameters + if(req_queue_size == 0) { + req_queue_size = DSPQUEUE_DEFAULT_REQ_SIZE; + } + if(resp_queue_size == 0) { + resp_queue_size = DSPQUEUE_DEFAULT_RESP_SIZE; + } + + // Determine queue shared memory size and allocate memory. The memory + // contains: + // - Queue headers + // - Read and write states for both request and response queues (four + // total) + // - Request and response queues + // All are aligned to QUEUE_CACHE_ALIGN. + q->user_queue_size = CACHE_ALIGN_SIZE(sizeof(struct dspqueue_header)) + + 4 + * CACHE_ALIGN_SIZE(sizeof( + struct dspqueue_packet_queue_state)) + + CACHE_ALIGN_SIZE(req_queue_size) + + CACHE_ALIGN_SIZE(resp_queue_size); + + // Allocate queue shared memory and map to DSP + VERIFYC((q->user_queue = rpcmem_alloc_internal(RPCMEM_HEAP_ID_SYSTEM, + RPCMEM_DEFAULT_FLAGS + | RPCMEM_HEAP_NOREG, + q->user_queue_size)) + != NULL, + AEE_ENOMEMORY); + VERIFYC((((uintptr_t)q->user_queue) & 4095) == 0, AEE_ERPC); + VERIFYC((q->user_queue_fd = rpcmem_to_fd(q->user_queue)) > 0, + AEE_ERPC); + VERIFY((nErr = fastrpc_mmap(domain, q->user_queue_fd, q->user_queue, 0, + q->user_queue_size, FASTRPC_MAP_FD)) + == 0); + queue_mapped = 1; + q->header = q->user_queue; + + // Initialize queue header, including all offsets, and clear the queue + memset(q->header, 0, q->user_queue_size); + q->header->version = 1; + q->header->queue_count = queue_count; + q->queue_count = queue_count; + + // Request packet queue (CPU->DSP) + o = CACHE_ALIGN_SIZE(sizeof(struct dspqueue_header)); + q->header->req_queue.queue_offset = o; + q->header->req_queue.queue_length = req_queue_size; + o += CACHE_ALIGN_SIZE(req_queue_size); + q->header->req_queue.read_state_offset = o; + o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); + q->header->req_queue.write_state_offset = o; + o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); + + // Response packet queue (DSP->CPU) + q->header->resp_queue.queue_offset = o; + q->header->resp_queue.queue_length = resp_queue_size; + o += CACHE_ALIGN_SIZE(resp_queue_size); + q->header->resp_queue.read_state_offset = o; + o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); + q->header->resp_queue.write_state_offset = o; + o += CACHE_ALIGN_SIZE(sizeof(struct dspqueue_packet_queue_state)); + + assert(o == q->user_queue_size); + + dq->state->req_packet_count[id] = 0; + cache_flush_word(&dq->state->req_packet_count[id]); + dq->state->resp_space_count[id] = 0; + cache_flush_word(&dq->state->resp_space_count[id]); + + // Try to create driver signals + if(dq->have_dspsignal) { + q->have_driver_signaling = 1; + for(signals = 0; signals < DSPQUEUE_NUM_SIGNALS; signals++) { + VERIFY((nErr = dspsignal_create( + domain, QUEUE_SIGNAL(id, signals), 0)) + == AEE_SUCCESS); + } + } + + // First attempt to create the queue with an invalid version. If the + // call succeeds we know the DSP side is ignoring the version and flags + // and does not support wait counts in the header, driver signaling, or + // any other post-v1 features. Unfortunately the initial DSP codebase + // ignores the version and flags... + q->header->version = UINT32_MAX; + nErr = dspqueue_rpc_create_queue( + dq->dsp_handle, q->id, q->user_queue_fd, queue_count, &q->dsp_id); + if((nErr == AEE_EUNSUPPORTED) + || (nErr == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED))) { + // OK, the DSP does pay attention to the version. It should + // also support wait counts and optionally driver signaling. + // Create the queue. + FARF(HIGH, + "Initial queue create failed with %0x%x as expected", + nErr); + q->header->version = DSPQUEUE_HEADER_CURRENT_VERSION; + q->header->flags = DSPQUEUE_HEADER_FLAG_WAIT_COUNTS; + if(q->have_driver_signaling) { + q->header->flags + |= DSPQUEUE_HEADER_FLAG_DRIVER_SIGNALING; + } + VERIFY((nErr = dspqueue_rpc_create_queue( + dq->dsp_handle, q->id, q->user_queue_fd, + queue_count, &q->dsp_id)) + == 0); + q->have_wait_counts = 1; + // Note that we expect the DSP will support both wait counts + // and driver signaling or neither. However we can operate with + // wait counts only in case we have an updated DSP image but an + // older CPU kernel driver without driver signaling support. + } else if(nErr != AEE_SUCCESS) { + FARF(ERROR, "dspqueue_rpc_create_queue failed: 0x%x", nErr); + goto bail; + } else { + FARF(HIGH, + "First-cut queue create succeeded unexpectedly? 0x%x", + nErr); + // No new features available, including driver signaling + if(q->have_driver_signaling) { + unsigned i; + FARF(HIGH, "Driver signaling not supported on DSP, " + "fall back to FastRPC " + "signaling"); + for(i = 0; i < signals; i++) { + VERIFY((nErr = dspsignal_destroy( + domain, QUEUE_SIGNAL(id, i))) + == 0); + } + signals = 0; + } + q->have_driver_signaling = 0; + } + + // Create synchronization resources + VERIFY((nErr = pthread_mutex_init(&q->packet_mutex, NULL)) == 0); + packetmutex = 1; + VERIFY((nErr = pthread_mutex_init(&q->space_mutex, NULL)) == 0); + spacemutex = 1; + if(!q->have_driver_signaling) { + VERIFY((nErr = pthread_cond_init(&q->packet_cond, NULL)) == 0); + packetcond = 1; + VERIFY((nErr = pthread_cond_init(&q->space_cond, NULL)) == 0); + packetcond = 1; + } + + // Callback thread (if we have a message callback) + if(q->packet_callback) { + pthread_attr_init(&tattr); + pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); + VERIFY( + (nErr = pthread_create(&q->packet_callback_thread, &tattr, + dspqueue_packet_callback_thread, q)) + == 0); + callbackthread = 1; + } + + *queue = q; + pthread_mutex_lock(&dq->queue_list_mutex); + dq->queues[id] = q; + pthread_mutex_unlock(&dq->queue_list_mutex); + FARF(ALWAYS, "%s: created Queue %u, %p, DSP 0x%08x for domain %d", + __func__, q->id, q, (unsigned)q->dsp_id, q->domain); + + return AEE_SUCCESS; bail: - if (q) { - if (callbackthread) { - if (q->have_driver_signaling) { - dspsignal_cancel_wait(domain, - QUEUE_SIGNAL(id, DSPQUEUE_SIGNAL_RESP_PACKET)); - } else { - pthread_mutex_lock(&q->packet_mutex); - q->packet_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_signal(&q->packet_cond); - pthread_mutex_unlock(&q->packet_mutex); - } - } - if (q->have_driver_signaling && (signals > 0)) { - unsigned i; - for (i = 0; i < signals; i++) { - dspsignal_destroy(domain, QUEUE_SIGNAL(id, i)); - } - } - if (packetmutex) { - pthread_mutex_destroy(&q->packet_mutex); - } - if (packetcond) { - pthread_cond_destroy(&q->packet_cond); - } - if (spacemutex) { - pthread_mutex_destroy(&q->space_mutex); - } - if (spacecond) { - pthread_cond_destroy(&q->space_cond); - } - if (q->dsp_id) { - dspqueue_rpc_destroy_queue(dq->dsp_handle, q->dsp_id); - } - if (queue_mapped) { - fastrpc_munmap(domain, q->user_queue_fd, q->user_queue, - q->user_queue_size); - } - if (q->user_queue) { - rpcmem_free(q->user_queue); - } - if (mutex_init) { - pthread_mutex_destroy(&q->mutex); - } - free(q); - } - if (dq != NULL) { - if (id < DSPQUEUE_MAX_PROCESS_QUEUES) { - pthread_mutex_lock(&dq->queue_list_mutex); - dq->queues[id] = UNUSED_QUEUE; - pthread_mutex_unlock(&dq->queue_list_mutex); - } - pthread_mutex_lock(&queues->mutex); - assert(dq->num_queues > 0); - dq->num_queues--; - if (dq->num_queues == 0) { - // This would have been the first queue for this domain - destroy_domain_queues_locked(domain); - } - pthread_mutex_unlock(&queues->mutex); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed (domain %d, flags 0x%x, sizes %u, %u errno %s)", - nErr, __func__, domain, (unsigned)flags, (unsigned)req_queue_size, - (unsigned)resp_queue_size, strerror(errno)); - } - return nErr; + if(q) { + if(callbackthread) { + if(q->have_driver_signaling) { + dspsignal_cancel_wait( + domain, + QUEUE_SIGNAL(id, + DSPQUEUE_SIGNAL_RESP_PACKET)); + } else { + pthread_mutex_lock(&q->packet_mutex); + q->packet_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_signal(&q->packet_cond); + pthread_mutex_unlock(&q->packet_mutex); + } + } + if(q->have_driver_signaling && (signals > 0)) { + unsigned i; + for(i = 0; i < signals; i++) { + dspsignal_destroy(domain, QUEUE_SIGNAL(id, i)); + } + } + if(packetmutex) { + pthread_mutex_destroy(&q->packet_mutex); + } + if(packetcond) { + pthread_cond_destroy(&q->packet_cond); + } + if(spacemutex) { + pthread_mutex_destroy(&q->space_mutex); + } + if(spacecond) { + pthread_cond_destroy(&q->space_cond); + } + if(q->dsp_id) { + dspqueue_rpc_destroy_queue(dq->dsp_handle, q->dsp_id); + } + if(queue_mapped) { + fastrpc_munmap(domain, q->user_queue_fd, q->user_queue, + q->user_queue_size); + } + if(q->user_queue) { + rpcmem_free(q->user_queue); + } + if(mutex_init) { + pthread_mutex_destroy(&q->mutex); + } + free(q); + } + if(dq != NULL) { + if(id < DSPQUEUE_MAX_PROCESS_QUEUES) { + pthread_mutex_lock(&dq->queue_list_mutex); + dq->queues[id] = UNUSED_QUEUE; + pthread_mutex_unlock(&dq->queue_list_mutex); + } + pthread_mutex_lock(&queues->mutex); + assert(dq->num_queues > 0); + dq->num_queues--; + if(dq->num_queues == 0) { + // This would have been the first queue for this domain + destroy_domain_queues_locked(domain); + } + pthread_mutex_unlock(&queues->mutex); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, flags 0x%x, sizes %u, " + "%u errno %s)", + nErr, __func__, domain, (unsigned)flags, + (unsigned)req_queue_size, (unsigned)resp_queue_size, + strerror(errno)); + } + return nErr; } /* * Clean-up multi-domain queue * This function calls 'dspqueue_close' on each individual queue. */ -static int dspqueue_multidomain_close(struct dspqueue *q, bool queue_mut) { +static int +dspqueue_multidomain_close(struct dspqueue *q, bool queue_mut) +{ int nErr = AEE_SUCCESS, err = AEE_SUCCESS; struct dspqueue_multidomain *mdq = NULL; dspqueue_t queue = NULL; @@ -760,228 +836,247 @@ static int dspqueue_multidomain_close(struct dspqueue *q, bool queue_mut) { mdq = &q->mdq; VERIFYC(mdq->is_mdq, AEE_EINVALIDITEM); - if (queue_mut) { + if(queue_mut) { pthread_mutex_lock(&q->mutex); } // Close individual queues - for (unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { + for(unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { queue = mdq->queues[ii]; - if (!queue) + if(!queue) continue; err = dspqueue_close(queue); - if (err) { + if(err) { // Return the first failure's error code to client nErr = nErr ? nErr : err; } } - if (mdq->effec_domain_ids) { + if(mdq->effec_domain_ids) { free(mdq->effec_domain_ids); } - if (mdq->queues) { + if(mdq->queues) { free(mdq->queues); } - if (mdq->dsp_ids) { + if(mdq->dsp_ids) { free(mdq->dsp_ids); } - if (queue_mut) { + if(queue_mut) { pthread_mutex_unlock(&q->mutex); pthread_mutex_destroy(&q->mutex); } - FARF(ALWAYS, "%s: closed queue %p (ctx 0x%"PRIx64"), num domains %u", - __func__, q, mdq->ctx, mdq->num_domain_ids); + FARF(ALWAYS, "%s: closed queue %p (ctx 0x%" PRIx64 "), num domains %u", + __func__, q, mdq->ctx, mdq->num_domain_ids); free(q); bail: - if (nErr) { - FARF(ALWAYS, "Error 0x%x: %s: failed for queue %p", - nErr, __func__, q); + if(nErr) { + FARF(ALWAYS, "Error 0x%x: %s: failed for queue %p", nErr, + __func__, q); } return nErr; } -AEEResult dspqueue_close(dspqueue_t queue) { - - struct dspqueue *q = queue; - struct dspqueue_domain_queues *dq = NULL; - AEEResult nErr = AEE_SUCCESS; - int32_t imported; - unsigned i; - - errno = 0; - VERIFYC(q, AEE_EBADPARM); - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_close' on each individual queue - return dspqueue_multidomain_close(q, true); - } - - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(q->domain), AEE_EINVALIDDOMAIN); - pthread_mutex_lock(&queues->mutex); - dq = queues->domain_queues[q->domain]; - if (dq == NULL) { - FARF(ERROR, "No domain queues"); - pthread_mutex_unlock(&queues->mutex); - return AEE_ERPC; - } - pthread_mutex_unlock(&queues->mutex); - - // Check if the queue is still imported on the DSP - if (!dq->dsp_error) { - VERIFY((nErr = dspqueue_rpc_is_imported(dq->dsp_handle, q->dsp_id, - &imported)) == 0); - if (imported) { - FARF(ERROR, "Attempting to close queue 0x%p still open on the DSP", - queue); - nErr = AEE_EBADPARM; - goto bail; - } - } - - VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); - - pthread_mutex_lock(&dq->queue_list_mutex); - dq->queues[q->id] = INVALID_QUEUE; - pthread_mutex_unlock(&dq->queue_list_mutex); - - if (q->error_callback_thread) { - nErr = pthread_join(q->error_callback_thread, NULL); - if (nErr == EDEADLK || nErr == EINVAL) { - FARF(ERROR, - "Error %d: %s: Error callback thread join failed for thread : %d", - nErr, __func__, q->error_callback_thread); - nErr = AEE_ERPC; - q->error_callback_thread = 0; - goto bail; - } - nErr = AEE_SUCCESS; - q->error_callback_thread = 0; - } - - // Cancel any outstanding blocking read/write calls (from callback threads) - if (q->have_driver_signaling) { - /* - * Cancel driver signal waits - * Not required in case of SSR (i.e AEE_ECONNRESET) - * as signals are cancelled by the SSR handle. - */ - if (dq->dsp_error != AEE_ECONNRESET) { - for (i = 0; i < DSPQUEUE_NUM_SIGNALS; i++) { - nErr = dspsignal_cancel_wait(q->domain, QUEUE_SIGNAL(q->id, i)); - if (nErr && nErr != AEE_EBADSTATE) { - goto bail; - } - } - } - } else { - pthread_mutex_lock(&q->packet_mutex); - q->packet_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_broadcast(&q->packet_cond); - pthread_mutex_unlock(&q->packet_mutex); - pthread_mutex_lock(&q->space_mutex); - q->space_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_broadcast(&q->space_cond); - pthread_mutex_unlock(&q->space_mutex); - } - - if (q->packet_callback) { - void *ret; - FARF(MEDIUM, "Join packet callback thread"); - nErr = pthread_join(q->packet_callback_thread, &ret); - /* Ignore error if thread has already exited */ - if (nErr && nErr != ESRCH) { - FARF( - ERROR, - "Error: %s: packet callback thread for queue %p joined with error %d", - __func__, q, nErr); - goto bail; - } - FARF(MEDIUM, " - Join packet callback thread done"); - VERIFY((uintptr_t)ret == 0); - } - - if (dq->dsp_error) { - // Ignore errors if the process died - dspqueue_rpc_destroy_queue(dq->dsp_handle, q->dsp_id); - fastrpc_munmap(dq->domain, q->user_queue_fd, q->user_queue, - q->user_queue_size); - } else { - VERIFY((nErr = dspqueue_rpc_destroy_queue(dq->dsp_handle, q->dsp_id)) == 0); - VERIFY((nErr = fastrpc_munmap(dq->domain, q->user_queue_fd, q->user_queue, - q->user_queue_size)) == 0); - } - rpcmem_free(q->user_queue); - /* - * In case of SSR (i.e., AEE_ECONNRESET), there is no need to call - * dspsignal_destroy as the process close during SSR cleans up - * signals. - */ - if (q->have_driver_signaling) { - if (dq->dsp_error != AEE_ECONNRESET) { - FARF(MEDIUM, "%s: Destroy signals", __func__); - for (i = 0; i < DSPQUEUE_NUM_SIGNALS; i++) { - nErr = dspsignal_destroy(q->domain, QUEUE_SIGNAL(q->id, i)); - if (nErr && nErr != AEE_EBADSTATE) { - goto bail; - } - } - } - } - - if (!q->have_driver_signaling) { - pthread_cond_destroy(&q->packet_cond); - pthread_cond_destroy(&q->space_cond); - } - pthread_mutex_destroy(&q->packet_mutex); - pthread_mutex_destroy(&q->space_mutex); - pthread_mutex_destroy(&q->mutex); - - pthread_mutex_lock(&dq->queue_list_mutex); - dq->queues[q->id] = UNUSED_QUEUE; - dq->max_queue = 0; - for (i = 0; i < DSPQUEUE_MAX_PROCESS_QUEUES; i++) { - if (dq->queues[i] != UNUSED_QUEUE) { - dq->max_queue = i; - } - } - pthread_mutex_unlock(&dq->queue_list_mutex); - - pthread_mutex_lock(&queues->mutex); - dq->num_queues--; - if (dq->num_queues == 0) { - FARF(ALWAYS, "%s: destroying queues and signals for domain %d", __func__, - q->domain); - destroy_domain_queues_locked(q->domain); - if (q->have_driver_signaling) - dspsignal_domain_deinit(q->domain); - } - pthread_mutex_unlock(&queues->mutex); - FARF(ALWAYS, "%s: closed Queue %u, %p, DSP 0x%08x for domain %d", __func__, - q->id, q, (unsigned)q->dsp_id, q->domain); - free(q); +AEEResult +dspqueue_close(dspqueue_t queue) +{ + + struct dspqueue *q = queue; + struct dspqueue_domain_queues *dq = NULL; + AEEResult nErr = AEE_SUCCESS; + int32_t imported; + unsigned i; + + errno = 0; + VERIFYC(q, AEE_EBADPARM); + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_close' on each individual queue + return dspqueue_multidomain_close(q, true); + } + + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(q->domain), AEE_EINVALIDDOMAIN); + pthread_mutex_lock(&queues->mutex); + dq = queues->domain_queues[q->domain]; + if(dq == NULL) { + FARF(ERROR, "No domain queues"); + pthread_mutex_unlock(&queues->mutex); + return AEE_ERPC; + } + pthread_mutex_unlock(&queues->mutex); + + // Check if the queue is still imported on the DSP + if(!dq->dsp_error) { + VERIFY((nErr = dspqueue_rpc_is_imported(dq->dsp_handle, + q->dsp_id, &imported)) + == 0); + if(imported) { + FARF(ERROR, + "Attempting to close queue 0x%p still open on " + "the DSP", + queue); + nErr = AEE_EBADPARM; + goto bail; + } + } + + VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); + + pthread_mutex_lock(&dq->queue_list_mutex); + dq->queues[q->id] = INVALID_QUEUE; + pthread_mutex_unlock(&dq->queue_list_mutex); + + if(q->error_callback_thread) { + nErr = pthread_join(q->error_callback_thread, NULL); + if(nErr == EDEADLK || nErr == EINVAL) { + FARF(ERROR, + "Error %d: %s: Error callback thread join failed " + "for thread : %d", + nErr, __func__, q->error_callback_thread); + nErr = AEE_ERPC; + q->error_callback_thread = 0; + goto bail; + } + nErr = AEE_SUCCESS; + q->error_callback_thread = 0; + } + + // Cancel any outstanding blocking read/write calls (from callback + // threads) + if(q->have_driver_signaling) { + /* + * Cancel driver signal waits + * Not required in case of SSR (i.e AEE_ECONNRESET) + * as signals are cancelled by the SSR handle. + */ + if(dq->dsp_error != AEE_ECONNRESET) { + for(i = 0; i < DSPQUEUE_NUM_SIGNALS; i++) { + nErr = dspsignal_cancel_wait( + q->domain, QUEUE_SIGNAL(q->id, i)); + if(nErr && nErr != AEE_EBADSTATE) { + goto bail; + } + } + } + } else { + pthread_mutex_lock(&q->packet_mutex); + q->packet_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_broadcast(&q->packet_cond); + pthread_mutex_unlock(&q->packet_mutex); + pthread_mutex_lock(&q->space_mutex); + q->space_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_broadcast(&q->space_cond); + pthread_mutex_unlock(&q->space_mutex); + } + + if(q->packet_callback) { + void *ret; + FARF(MEDIUM, "Join packet callback thread"); + nErr = pthread_join(q->packet_callback_thread, &ret); + /* Ignore error if thread has already exited */ + if(nErr && nErr != ESRCH) { + FARF(ERROR, + "Error: %s: packet callback thread for queue %p " + "joined with error %d", + __func__, q, nErr); + goto bail; + } + FARF(MEDIUM, " - Join packet callback thread done"); + VERIFY((uintptr_t)ret == 0); + } + + if(dq->dsp_error) { + // Ignore errors if the process died + dspqueue_rpc_destroy_queue(dq->dsp_handle, q->dsp_id); + fastrpc_munmap(dq->domain, q->user_queue_fd, q->user_queue, + q->user_queue_size); + } else { + VERIFY((nErr = dspqueue_rpc_destroy_queue(dq->dsp_handle, + q->dsp_id)) + == 0); + VERIFY( + (nErr = fastrpc_munmap(dq->domain, q->user_queue_fd, + q->user_queue, q->user_queue_size)) + == 0); + } + rpcmem_free(q->user_queue); + /* + * In case of SSR (i.e., AEE_ECONNRESET), there is no need to call + * dspsignal_destroy as the process close during SSR cleans up + * signals. + */ + if(q->have_driver_signaling) { + if(dq->dsp_error != AEE_ECONNRESET) { + FARF(MEDIUM, "%s: Destroy signals", __func__); + for(i = 0; i < DSPQUEUE_NUM_SIGNALS; i++) { + nErr = dspsignal_destroy( + q->domain, QUEUE_SIGNAL(q->id, i)); + if(nErr && nErr != AEE_EBADSTATE) { + goto bail; + } + } + } + } + + if(!q->have_driver_signaling) { + pthread_cond_destroy(&q->packet_cond); + pthread_cond_destroy(&q->space_cond); + } + pthread_mutex_destroy(&q->packet_mutex); + pthread_mutex_destroy(&q->space_mutex); + pthread_mutex_destroy(&q->mutex); + + pthread_mutex_lock(&dq->queue_list_mutex); + dq->queues[q->id] = UNUSED_QUEUE; + dq->max_queue = 0; + for(i = 0; i < DSPQUEUE_MAX_PROCESS_QUEUES; i++) { + if(dq->queues[i] != UNUSED_QUEUE) { + dq->max_queue = i; + } + } + pthread_mutex_unlock(&dq->queue_list_mutex); + + pthread_mutex_lock(&queues->mutex); + dq->num_queues--; + if(dq->num_queues == 0) { + FARF(ALWAYS, "%s: destroying queues and signals for domain %d", + __func__, q->domain); + destroy_domain_queues_locked(q->domain); + if(q->have_driver_signaling) + dspsignal_domain_deinit(q->domain); + } + pthread_mutex_unlock(&queues->mutex); + FARF(ALWAYS, "%s: closed Queue %u, %p, DSP 0x%08x for domain %d", + __func__, q->id, q, (unsigned)q->dsp_id, q->domain); + free(q); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed errno %s", nErr, __func__, - strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed errno %s", nErr, __func__, + strerror(errno)); + } + return nErr; } -AEEResult dspqueue_export(dspqueue_t queue, uint64_t *queue_id) { +AEEResult +dspqueue_export(dspqueue_t queue, uint64_t *queue_id) +{ - struct dspqueue *q = queue; + struct dspqueue *q = queue; - if (q->mdq.is_mdq) { - FARF(ALWAYS, "Warning: %s not supported for multi-domain queue, already exported during create", - __func__); - return AEE_EUNSUPPORTED; - } - *queue_id = q->dsp_id; - return AEE_SUCCESS; + if(q->mdq.is_mdq) { + FARF(ALWAYS, + "Warning: %s not supported for multi-domain queue, " + "already exported during create", + __func__); + return AEE_EUNSUPPORTED; + } + *queue_id = q->dsp_id; + return AEE_SUCCESS; } -static int dspqueue_multidomain_create(dspqueue_create_req *create) { +static int +dspqueue_multidomain_create(dspqueue_create_req *create) +{ int nErr = AEE_SUCCESS; bool queue_mut = false; unsigned int *effec_domain_ids = NULL; @@ -989,12 +1084,13 @@ static int dspqueue_multidomain_create(dspqueue_create_req *create) { struct dspqueue *q = NULL; struct dspqueue_multidomain *mdq = NULL; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_context_get_domains(create->ctx, - &effec_domain_ids, &num_domain_ids))); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_context_get_domains( + create->ctx, &effec_domain_ids, &num_domain_ids))); // Validate output parameter pointers VERIFYC(create->ids && !create->priority && !create->flags, - AEE_EBADPARM); + AEE_EBADPARM); VERIFYC(create->num_ids >= num_domain_ids, AEE_EBADPARM); create->queue = NULL; @@ -1002,8 +1098,10 @@ static int dspqueue_multidomain_create(dspqueue_create_req *create) { memset(create->ids, 0, size); errno = 0; - VERIFYC(AEE_SUCCESS == (nErr = pthread_once(&queues_once, - init_process_queues_once)), AEE_ENOTINITIALIZED); + VERIFYC(AEE_SUCCESS + == (nErr = pthread_once(&queues_once, + init_process_queues_once)), + AEE_ENOTINITIALIZED); // Alloc & init queue struct VERIFYC(NULL != (q = calloc(1, sizeof(*q))), AEE_ENOMEMORY); @@ -1012,7 +1110,7 @@ static int dspqueue_multidomain_create(dspqueue_create_req *create) { mdq->ctx = create->ctx; VERIFYC(AEE_SUCCESS == (nErr = pthread_mutex_init(&q->mutex, NULL)), - AEE_ENOTINITIALIZED); + AEE_ENOTINITIALIZED); queue_mut = true; // Alloc & init multi-domain queue specific info @@ -1020,311 +1118,339 @@ static int dspqueue_multidomain_create(dspqueue_create_req *create) { size = num_domain_ids * sizeof(*(mdq->effec_domain_ids)); VERIFYC(NULL != (mdq->effec_domain_ids = calloc(1, size)), - AEE_ENOMEMORY); + AEE_ENOMEMORY); memcpy(mdq->effec_domain_ids, effec_domain_ids, size); - VERIFYC(NULL != (mdq->queues = calloc(num_domain_ids, - sizeof(*(mdq->queues)))), AEE_ENOMEMORY); + VERIFYC(NULL + != (mdq->queues + = calloc(num_domain_ids, sizeof(*(mdq->queues)))), + AEE_ENOMEMORY); size = num_domain_ids * sizeof(*(mdq->dsp_ids)); VERIFYC(NULL != (mdq->dsp_ids = calloc(1, size)), AEE_ENOMEMORY); // Create queue on each individual domain - for (unsigned int ii = 0; ii < num_domain_ids; ii++) { - VERIFY(AEE_SUCCESS == (nErr = dspqueue_create(effec_domain_ids[ii], - create->flags, create->req_queue_size, create->resp_queue_size, - create->packet_callback, create->error_callback, - create->callback_context, &mdq->queues[ii]))); + for(unsigned int ii = 0; ii < num_domain_ids; ii++) { + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_create( + effec_domain_ids[ii], create->flags, + create->req_queue_size, create->resp_queue_size, + create->packet_callback, create->error_callback, + create->callback_context, &mdq->queues[ii]))); // Export queue and get queue id for that domain - VERIFY(AEE_SUCCESS == (nErr = dspqueue_export(mdq->queues[ii], - &mdq->dsp_ids[ii]))); + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_export(mdq->queues[ii], + &mdq->dsp_ids[ii]))); } // Return queue handle and list of queue ids to user create->queue = q; memcpy(create->ids, mdq->dsp_ids, size); - FARF(ALWAYS, "%s: created queue %p for ctx 0x%"PRIx64", sizes: req %u, rsp %u, num domains %u", - __func__, q, create->ctx, create->req_queue_size, - create->resp_queue_size, num_domain_ids); + FARF(ALWAYS, + "%s: created queue %p for ctx 0x%" PRIx64 + ", sizes: req %u, rsp %u, num domains %u", + __func__, q, create->ctx, create->req_queue_size, + create->resp_queue_size, num_domain_ids); bail: - if (nErr) { - FARF(ERROR, "Error 0x%x: %s failed for ctx 0x%"PRIx64", queue sizes: req %u, rsp %u, num ids %u", - nErr, __func__, create->ctx, create->req_queue_size, - create->resp_queue_size, create->num_ids); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed for ctx 0x%" PRIx64 + ", queue sizes: req %u, rsp %u, num ids %u", + nErr, __func__, create->ctx, create->req_queue_size, + create->resp_queue_size, create->num_ids); dspqueue_multidomain_close(q, queue_mut); } return nErr; } -int dspqueue_request(dspqueue_request_payload *req) { +int +dspqueue_request(dspqueue_request_payload *req) +{ int nErr = AEE_SUCCESS, req_id = -1; VERIFYC(req, AEE_EBADPARM); req_id = req->id; switch(req_id) { - case DSPQUEUE_CREATE: - { - VERIFY(AEE_SUCCESS == (nErr = - dspqueue_multidomain_create(&req->create))); - break; - } - default: - nErr = AEE_EUNSUPPORTED; - break; + case DSPQUEUE_CREATE: { + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_multidomain_create(&req->create))); + break; + } + default: + nErr = AEE_EUNSUPPORTED; + break; } bail: - if (nErr) + if(nErr) FARF(ALWAYS, "Error 0x%x: %s failed", nErr, __func__); return nErr; } -static void get_queue_state_write(void *memory, - struct dspqueue_packet_queue_header *pq, - uint32_t *space_left, uint32_t *read_pos, - uint32_t *write_pos) { - - struct dspqueue_packet_queue_state *read_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + - pq->read_state_offset); - struct dspqueue_packet_queue_state *write_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + - pq->write_state_offset); - uint32_t qsize = pq->queue_length; - uint32_t r, w, qleft; - - cache_invalidate_word(&read_state->position); - r = read_state->position; - barrier_full(); - w = write_state->position; - assert(((r & 7) == 0) && ((w & 7) == 0)); - if (space_left != NULL) { - if (r == w) { - qleft = qsize - 8; - } else if (w > r) { - qleft = qsize - w + r - 8; - } else { - qleft = r - w - 8; - } - assert((qleft & 7) == 0); - *space_left = qleft; - } - if (read_pos != NULL) { - *read_pos = r; - } - if (write_pos != NULL) { - *write_pos = w; - } +static void +get_queue_state_write(void *memory, struct dspqueue_packet_queue_header *pq, + uint32_t *space_left, uint32_t *read_pos, + uint32_t *write_pos) +{ + + struct dspqueue_packet_queue_state *read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + + pq->read_state_offset); + struct dspqueue_packet_queue_state *write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + + pq->write_state_offset); + uint32_t qsize = pq->queue_length; + uint32_t r, w, qleft; + + cache_invalidate_word(&read_state->position); + r = read_state->position; + barrier_full(); + w = write_state->position; + assert(((r & 7) == 0) && ((w & 7) == 0)); + if(space_left != NULL) { + if(r == w) { + qleft = qsize - 8; + } else if(w > r) { + qleft = qsize - w + r - 8; + } else { + qleft = r - w - 8; + } + assert((qleft & 7) == 0); + *space_left = qleft; + } + if(read_pos != NULL) { + *read_pos = r; + } + if(write_pos != NULL) { + *write_pos = w; + } } -static void get_queue_state_read(void *memory, - struct dspqueue_packet_queue_header *pq, - uint32_t *data_left, uint32_t *read_pos, - uint32_t *write_pos) { - - struct dspqueue_packet_queue_state *read_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + - pq->read_state_offset); - struct dspqueue_packet_queue_state *write_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + - pq->write_state_offset); - uint32_t qsize = pq->queue_length; - uint32_t r, w, qleft; - - cache_invalidate_word(&write_state->position); - w = write_state->position; - barrier_full(); - r = read_state->position; - assert(((r & 7) == 0) && ((w & 7) == 0)); - if (data_left != NULL) { - if (r == w) { - qleft = 0; - } else if (w > r) { - qleft = w - r; - } else { - qleft = qsize - r + w; - } - assert((qleft & 7) == 0); - *data_left = qleft; - } - if (read_pos != NULL) { - *read_pos = r; - } - if (write_pos != NULL) { - *write_pos = w; - } +static void +get_queue_state_read(void *memory, struct dspqueue_packet_queue_header *pq, + uint32_t *data_left, uint32_t *read_pos, + uint32_t *write_pos) +{ + + struct dspqueue_packet_queue_state *read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + + pq->read_state_offset); + struct dspqueue_packet_queue_state *write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)memory) + + pq->write_state_offset); + uint32_t qsize = pq->queue_length; + uint32_t r, w, qleft; + + cache_invalidate_word(&write_state->position); + w = write_state->position; + barrier_full(); + r = read_state->position; + assert(((r & 7) == 0) && ((w & 7) == 0)); + if(data_left != NULL) { + if(r == w) { + qleft = 0; + } else if(w > r) { + qleft = w - r; + } else { + qleft = qsize - r + w; + } + assert((qleft & 7) == 0); + *data_left = qleft; + } + if(read_pos != NULL) { + *read_pos = r; + } + if(write_pos != NULL) { + *write_pos = w; + } } -static inline uint32_t write_64(volatile uint8_t *packet_queue, - uint32_t write_pos, uint32_t queue_len, - uint64_t data) { - *(volatile uint64_t *)((uintptr_t)packet_queue + write_pos) = data; - cache_flush_line((void *)((uintptr_t)packet_queue + write_pos)); - write_pos += 8; - if (write_pos >= queue_len) { - write_pos = 0; - } - return write_pos; +static inline uint32_t +write_64(volatile uint8_t *packet_queue, uint32_t write_pos, + uint32_t queue_len, uint64_t data) +{ + *(volatile uint64_t *)((uintptr_t)packet_queue + write_pos) = data; + cache_flush_line((void *)((uintptr_t)packet_queue + write_pos)); + write_pos += 8; + if(write_pos >= queue_len) { + write_pos = 0; + } + return write_pos; } -static inline uint32_t write_data(volatile uint8_t *packet_queue, - uint32_t write_pos, uint32_t queue_len, - const void *data, uint32_t data_len) { +static inline uint32_t +write_data(volatile uint8_t *packet_queue, uint32_t write_pos, + uint32_t queue_len, const void *data, uint32_t data_len) +{ - uintptr_t qp = (uintptr_t)packet_queue; + uintptr_t qp = (uintptr_t)packet_queue; - assert(data != NULL); - assert(data_len > 0); - assert((write_pos & 7) == 0); - assert((queue_len - write_pos) >= data_len); + assert(data != NULL); + assert(data_len > 0); + assert((write_pos & 7) == 0); + assert((queue_len - write_pos) >= data_len); - memcpy((void *)(qp + write_pos), data, data_len); - cache_flush((void *)(qp + write_pos), data_len); - write_pos += (data_len + 7) & (~7); - assert(write_pos <= queue_len); - if (write_pos >= queue_len) { - write_pos = 0; - } + memcpy((void *)(qp + write_pos), data, data_len); + cache_flush((void *)(qp + write_pos), data_len); + write_pos += (data_len + 7) & (~7); + assert(write_pos <= queue_len); + if(write_pos >= queue_len) { + write_pos = 0; + } - return write_pos; + return write_pos; } // Timespec difference in microseconds (a-b). If aUINT32_MAX returns UINT32_MAX -static uint32_t timespec_diff_us(struct timespec *a, struct timespec *b) { - int64_t diffsec = ((int64_t)a->tv_sec) - ((int64_t)b->tv_sec); - int64_t diffnsec = a->tv_nsec - b->tv_nsec; - int64_t diffusec; - - if ((diffsec < 0) || ((diffsec == 0) && (diffnsec < 0))) { - return 0; - } - if (diffsec > UINT32_MAX) { - // Would overflow for sure - return UINT32_MAX; - } - diffusec = (diffsec * 1000000LL) + (diffnsec / 1000LL); - if (diffusec > UINT32_MAX) { - return UINT32_MAX; - } - return (uint32_t)diffusec; +static uint32_t +timespec_diff_us(struct timespec *a, struct timespec *b) +{ + int64_t diffsec = ((int64_t)a->tv_sec) - ((int64_t)b->tv_sec); + int64_t diffnsec = a->tv_nsec - b->tv_nsec; + int64_t diffusec; + + if((diffsec < 0) || ((diffsec == 0) && (diffnsec < 0))) { + return 0; + } + if(diffsec > UINT32_MAX) { + // Would overflow for sure + return UINT32_MAX; + } + diffusec = (diffsec * 1000000LL) + (diffnsec / 1000LL); + if(diffusec > UINT32_MAX) { + return UINT32_MAX; + } + return (uint32_t)diffusec; } // Send a signal -static AEEResult send_signal(struct dspqueue *q, uint32_t signal_no) { - - struct dspqueue_domain_queues *dq = queues->domain_queues[q->domain]; - int nErr = AEE_SUCCESS; - - if (q->have_driver_signaling) { - VERIFYC(signal_no < DSPQUEUE_NUM_SIGNALS, AEE_EBADPARM); - VERIFY((nErr = dspsignal_signal(q->domain, - QUEUE_SIGNAL(q->id, signal_no))) == 0); - } else { - pthread_mutex_lock(&dq->send_signal_mutex); - dq->send_signal_mask |= SIGNAL_BIT_SIGNAL; - pthread_cond_signal(&dq->send_signal_cond); - pthread_mutex_unlock(&dq->send_signal_mutex); - } +static AEEResult +send_signal(struct dspqueue *q, uint32_t signal_no) +{ + + struct dspqueue_domain_queues *dq = queues->domain_queues[q->domain]; + int nErr = AEE_SUCCESS; + + if(q->have_driver_signaling) { + VERIFYC(signal_no < DSPQUEUE_NUM_SIGNALS, AEE_EBADPARM); + VERIFY((nErr = dspsignal_signal( + q->domain, QUEUE_SIGNAL(q->id, signal_no))) + == 0); + } else { + pthread_mutex_lock(&dq->send_signal_mutex); + dq->send_signal_mask |= SIGNAL_BIT_SIGNAL; + pthread_cond_signal(&dq->send_signal_cond); + pthread_mutex_unlock(&dq->send_signal_mutex); + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for queue %p signal %u", nErr, __func__, - q, (unsigned)signal_no); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for queue %p signal %u", + nErr, __func__, q, (unsigned)signal_no); + } + return nErr; } // Wait for a signal with an optional timeout. // Set timeout to the expiry time (not length of timeout) or NULL for an -// infinite wait. Only DSPQUEUE_SIGNAL_REQ_SPACE and DSPQUEUE_SIGNAL_RESP_PACKET -// supported. The appropriate mutex must be locked. -static AEEResult wait_signal_locked(struct dspqueue *q, uint32_t signal_no, - struct timespec *timeout) { - - AEEResult nErr = AEE_SUCCESS; - - if (q->have_driver_signaling) { - uint32_t to_now; - - if (timeout) { - struct timespec now; - VERIFYC(clock_gettime(CLOCK_REALTIME, &now) == 0, AEE_EFAILED); - to_now = timespec_diff_us(timeout, &now); // microseconds until expiry - if (to_now == 0) { - return AEE_EEXPIRED; - } - } else { - to_now = DSPSIGNAL_TIMEOUT_NONE; - } - - VERIFY((nErr = dspsignal_wait(q->domain, QUEUE_SIGNAL(q->id, signal_no), - to_now)) == 0); - - } else { - // Not using driver signaling, wait for the appropriate condition variable - // and its associated state - uint32_t *count; - uint32_t *mask; - pthread_mutex_t *mutex; - pthread_cond_t *cond; - uint32_t c; - - if (signal_no == DSPQUEUE_SIGNAL_REQ_SPACE) { - count = &q->req_space_count; - mask = &q->space_mask; - mutex = &q->space_mutex; - cond = &q->space_cond; - } else if (signal_no == DSPQUEUE_SIGNAL_RESP_PACKET) { - count = &q->resp_packet_count; - mask = &q->packet_mask; - mutex = &q->packet_mutex; - cond = &q->packet_cond; - } else { - nErr = AEE_EBADPARM; - goto bail; - } - - c = *count; - if (timeout) { - int rc = 0; - while ((c == *count) && (rc == 0)) { - if (*mask & 2) { - return AEE_EINTERRUPTED; - } - rc = pthread_cond_timedwait(cond, mutex, timeout); - if (rc == ETIMEDOUT) { - return AEE_EEXPIRED; - } - VERIFY(rc == 0); - } - } else { - while (c == *count) { - pthread_cond_wait(cond, mutex); - if (*mask & 2) { - return AEE_EINTERRUPTED; - } - } - } - } +// infinite wait. Only DSPQUEUE_SIGNAL_REQ_SPACE and +// DSPQUEUE_SIGNAL_RESP_PACKET supported. The appropriate mutex must be locked. +static AEEResult +wait_signal_locked(struct dspqueue *q, uint32_t signal_no, + struct timespec *timeout) +{ + + AEEResult nErr = AEE_SUCCESS; + + if(q->have_driver_signaling) { + uint32_t to_now; + + if(timeout) { + struct timespec now; + VERIFYC(clock_gettime(CLOCK_REALTIME, &now) == 0, + AEE_EFAILED); + to_now = timespec_diff_us( + timeout, &now); // microseconds until expiry + if(to_now == 0) { + return AEE_EEXPIRED; + } + } else { + to_now = DSPSIGNAL_TIMEOUT_NONE; + } + + VERIFY((nErr = dspsignal_wait( + q->domain, QUEUE_SIGNAL(q->id, signal_no), to_now)) + == 0); + + } else { + // Not using driver signaling, wait for the appropriate + // condition variable and its associated state + uint32_t *count; + uint32_t *mask; + pthread_mutex_t *mutex; + pthread_cond_t *cond; + uint32_t c; + + if(signal_no == DSPQUEUE_SIGNAL_REQ_SPACE) { + count = &q->req_space_count; + mask = &q->space_mask; + mutex = &q->space_mutex; + cond = &q->space_cond; + } else if(signal_no == DSPQUEUE_SIGNAL_RESP_PACKET) { + count = &q->resp_packet_count; + mask = &q->packet_mask; + mutex = &q->packet_mutex; + cond = &q->packet_cond; + } else { + nErr = AEE_EBADPARM; + goto bail; + } + + c = *count; + if(timeout) { + int rc = 0; + while((c == *count) && (rc == 0)) { + if(*mask & 2) { + return AEE_EINTERRUPTED; + } + rc = pthread_cond_timedwait(cond, mutex, + timeout); + if(rc == ETIMEDOUT) { + return AEE_EEXPIRED; + } + VERIFY(rc == 0); + } + } else { + while(c == *count) { + pthread_cond_wait(cond, mutex); + if(*mask & 2) { + return AEE_EINTERRUPTED; + } + } + } + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for queue %p signal %u", nErr, __func__, - q, (unsigned)signal_no); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for queue %p signal %u", + nErr, __func__, q, (unsigned)signal_no); + } + return nErr; } /* Write packet to multi-domain queue */ -static int dspqueue_multidomain_write(struct dspqueue *q, uint32_t flags, - uint32_t num_buffers, struct dspqueue_buffer *buffers, - uint32_t message_length, const uint8_t *message, - uint32_t timeout_us, bool block) { +static int +dspqueue_multidomain_write(struct dspqueue *q, uint32_t flags, + uint32_t num_buffers, + struct dspqueue_buffer *buffers, + uint32_t message_length, const uint8_t *message, + uint32_t timeout_us, bool block) +{ int nErr = AEE_SUCCESS; struct dspqueue_multidomain *mdq = NULL; bool locked = false; @@ -1339,397 +1465,439 @@ static int dspqueue_multidomain_write(struct dspqueue *q, uint32_t flags, locked = true; // Write packet to individual queues - for (unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { - if (block) { + for(unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { + if(block) { /* - * Multi-domain blocking write operation will serially block - * on each individual queue. + * Multi-domain blocking write operation will serially + * block on each individual queue. */ - VERIFY(AEE_SUCCESS == (nErr = dspqueue_write(mdq->queues[ii], - flags, num_buffers, buffers, message_length, message, - timeout_us))); + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_write( + mdq->queues[ii], flags, num_buffers, + buffers, message_length, message, + timeout_us))); } else { - VERIFY(AEE_SUCCESS == (nErr = dspqueue_write_noblock( - mdq->queues[ii], flags, num_buffers, buffers, - message_length, message))); + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_write_noblock( + mdq->queues[ii], flags, num_buffers, + buffers, message_length, message))); } } bail: - if (locked) + if(locked) pthread_mutex_unlock(&q->mutex); - if (nErr) { + if(nErr) { /* * If multi-domain write operation failed on some but not all * queues, then the MDQ is now in an irrecoverable bad-state as * the packet was partially written to some domains but not all - * and it cannot be "erased". Client is expected to close queue. + * and it cannot be "erased". Client is expected to close + * queue. */ nErr = AEE_EBADSTATE; - FARF(ERROR, "Error 0x%x: %s (block %d): failed for queue %p, flags 0x%x, num bufs %u, msg len %u, timeout %u", - nErr, __func__, block, q, flags, num_buffers, - message_length, timeout_us); + FARF(ERROR, + "Error 0x%x: %s (block %d): failed for queue %p, flags " + "0x%x, num bufs %u, msg len %u, timeout %u", + nErr, __func__, block, q, flags, num_buffers, + message_length, timeout_us); } return nErr; } -AEEResult dspqueue_write_noblock(dspqueue_t queue, uint32_t flags, - uint32_t num_buffers, - struct dspqueue_buffer *buffers, - uint32_t message_length, - const uint8_t *message) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_packet_queue_header *pq = NULL; - volatile uint8_t *qp = NULL; - struct dspqueue_packet_queue_state *read_state = NULL; - struct dspqueue_packet_queue_state *write_state = NULL; - struct dspqueue_domain_queues *dq = NULL; - unsigned len, alen; - uint32_t r, w; - uint32_t qleft = 0, qsize = 0; - int locked = 0; - uint64_t phdr; - int wrap = 0; - uint32_t i; - uint32_t buf_refs = 0; - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_write_noblock' on individual queues - return dspqueue_multidomain_write(q, flags, num_buffers, buffers, - message_length, message, 0, false); - } - - pq = &q->header->req_queue; - qp = (volatile uint8_t*) (((uintptr_t)q->header) + pq->queue_offset); - read_state = (struct dspqueue_packet_queue_state*) (((uintptr_t)q->header) - + pq->read_state_offset); - write_state = (struct dspqueue_packet_queue_state*) (((uintptr_t)q->header) - + pq->write_state_offset); - dq = queues->domain_queues[q->domain]; - qsize = pq->queue_length; - - // Check properties - VERIFYC(num_buffers <= DSPQUEUE_MAX_BUFFERS, AEE_EBADPARM); - VERIFYC(message_length <= DSPQUEUE_MAX_MESSAGE_SIZE, AEE_EBADPARM); - - // Prepare flags - if (num_buffers > 0) { - flags |= DSPQUEUE_PACKET_FLAG_BUFFERS; - VERIFYC(buffers != NULL, AEE_EBADPARM); - } else { - flags &= ~DSPQUEUE_PACKET_FLAG_BUFFERS; - } - if (message_length > 0) { - flags |= DSPQUEUE_PACKET_FLAG_MESSAGE; - VERIFYC(message != NULL, AEE_EBADPARM); - } else { - flags &= ~DSPQUEUE_PACKET_FLAG_MESSAGE; - } - - // Calculate packet length in the queue - assert(sizeof(struct dspqueue_buffer) == 24); - len = 8 + num_buffers * sizeof(struct dspqueue_buffer) + message_length; - alen = (len + 7) & (~7); - - if (alen > (qsize - 8)) { - FARF(ERROR, "Packet size %u too large for queue size %u", (unsigned)len, - (unsigned)qsize); - nErr = AEE_EBADPARM; - goto bail; - } - - pthread_mutex_lock(&q->mutex); - locked = 1; - - VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); - - // Check that we have space for the packet in the queue - get_queue_state_write(q->header, pq, &qleft, &r, &w); - if (qleft < alen) { - pthread_mutex_unlock(&q->mutex); - return AEE_EWOULDBLOCK; - } - if ((qsize - w) < alen) { - // Don't wrap the packet around queue end, but rather move it to the - // beginning, replicating the header - wrap = 1; - if ((qleft - (qsize - w)) < alen) { - pthread_mutex_unlock(&q->mutex); - return AEE_EWOULDBLOCK; - } - } - - // Go through buffers - for (i = 0; i < num_buffers; i++) { - struct dspqueue_buffer *b = &buffers[i]; - void *va; - size_t size; - - // Find buffer in internal FastRPC structures and handle refcounts - if (b->flags & DSPQUEUE_BUFFER_FLAG_REF) { - VERIFYC((b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) == 0, AEE_EBADPARM); - nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, &va, &size); - } else if (b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { - nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, &va, &size); - } else { - nErr = fastrpc_buffer_ref(q->domain, b->fd, 0, &va, &size); - } - if (nErr == AEE_ENOSUCHMAP) { - FARF(ERROR, "Buffer FD %d in queue message not mapped to domain %d", - b->fd, q->domain); - goto bail; - } - VERIFY(nErr == 0); - buf_refs = i + 1; - - // Ensure buffer offset and size are within the buffer as mapped. - // Use mapped size if not specified by the client - if (b->size != 0) { - uint64_t bend = ((uint64_t)b->offset) + ((uint64_t)b->size); - VERIFYC(bend <= size, AEE_EBADPARM); - // Calculate new bounds for cache ops - va = (void *)(((uintptr_t)va) + b->offset); - size = b->size; - } else { - VERIFYC(b->offset == 0, AEE_EBADPARM); - } - } - - // Write packet header - flags |= DSPQUEUE_PACKET_FLAG_USER_READY; - phdr = - (((uint64_t)(len & 0xffffffff)) | (((uint64_t)(flags & 0xffff)) << 32) | - (((uint64_t)(num_buffers & 0xff)) << 48) | - (((uint64_t)(q->seq_no & 0xff)) << 56)); - w = write_64(qp, w, qsize, phdr); - if (wrap) { - // Write the packet at the beginning of the queue, - // replicating the header - w = write_64(qp, 0, qsize, phdr); - } - - // Write buffer information - if (num_buffers > 0) { - w = write_data(qp, w, qsize, buffers, - num_buffers * sizeof(struct dspqueue_buffer)); - } - - // Write message - if (message_length > 0) { - w = write_data(qp, w, qsize, message, message_length); - } - - // Update write pointer. This marks the message available in the user queue - q->write_packet_count++; - barrier_store(); - write_state->position = w; - write_state->packet_count = q->write_packet_count; - cache_flush_line(write_state); - - // Signal that we've written a packet - q->req_packet_count++; - dq->state->req_packet_count[q->id] = q->req_packet_count; - FARF(LOW, "Queue %u req_packet_count %u", (unsigned)q->id, - (unsigned)q->req_packet_count); - cache_flush_word(&dq->state->req_packet_count[q->id]); - if (q->have_wait_counts) { - // Only send a signal if the other end is potentially waiting - barrier_full(); - cache_invalidate_word(&read_state->wait_count); - if (read_state->wait_count) { - FARF(MEDIUM, "%s: Send signal", __func__); - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_REQ_PACKET)) == 0); - } else { - FARF(MEDIUM, "%s: Don't send signal", __func__); - } - } else { - FARF(MEDIUM, "%s: No wait counts - send signal", __func__); - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_REQ_PACKET)) == 0); - } - - q->seq_no++; - - pthread_mutex_unlock(&q->mutex); - locked = 0; - return 0; +AEEResult +dspqueue_write_noblock(dspqueue_t queue, uint32_t flags, uint32_t num_buffers, + struct dspqueue_buffer *buffers, + uint32_t message_length, const uint8_t *message) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_packet_queue_header *pq = NULL; + volatile uint8_t *qp = NULL; + struct dspqueue_packet_queue_state *read_state = NULL; + struct dspqueue_packet_queue_state *write_state = NULL; + struct dspqueue_domain_queues *dq = NULL; + unsigned len, alen; + uint32_t r, w; + uint32_t qleft = 0, qsize = 0; + int locked = 0; + uint64_t phdr; + int wrap = 0; + uint32_t i; + uint32_t buf_refs = 0; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_write_noblock' on individual + // queues + return dspqueue_multidomain_write(q, flags, num_buffers, + buffers, message_length, + message, 0, false); + } + + pq = &q->header->req_queue; + qp = (volatile uint8_t *)(((uintptr_t)q->header) + pq->queue_offset); + read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->read_state_offset); + write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->write_state_offset); + dq = queues->domain_queues[q->domain]; + qsize = pq->queue_length; + + // Check properties + VERIFYC(num_buffers <= DSPQUEUE_MAX_BUFFERS, AEE_EBADPARM); + VERIFYC(message_length <= DSPQUEUE_MAX_MESSAGE_SIZE, AEE_EBADPARM); + + // Prepare flags + if(num_buffers > 0) { + flags |= DSPQUEUE_PACKET_FLAG_BUFFERS; + VERIFYC(buffers != NULL, AEE_EBADPARM); + } else { + flags &= ~DSPQUEUE_PACKET_FLAG_BUFFERS; + } + if(message_length > 0) { + flags |= DSPQUEUE_PACKET_FLAG_MESSAGE; + VERIFYC(message != NULL, AEE_EBADPARM); + } else { + flags &= ~DSPQUEUE_PACKET_FLAG_MESSAGE; + } + + // Calculate packet length in the queue + assert(sizeof(struct dspqueue_buffer) == 24); + len = 8 + num_buffers * sizeof(struct dspqueue_buffer) + + message_length; + alen = (len + 7) & (~7); + + if(alen > (qsize - 8)) { + FARF(ERROR, "Packet size %u too large for queue size %u", + (unsigned)len, (unsigned)qsize); + nErr = AEE_EBADPARM; + goto bail; + } + + pthread_mutex_lock(&q->mutex); + locked = 1; + + VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); + + // Check that we have space for the packet in the queue + get_queue_state_write(q->header, pq, &qleft, &r, &w); + if(qleft < alen) { + pthread_mutex_unlock(&q->mutex); + return AEE_EWOULDBLOCK; + } + if((qsize - w) < alen) { + // Don't wrap the packet around queue end, but rather move it + // to the beginning, replicating the header + wrap = 1; + if((qleft - (qsize - w)) < alen) { + pthread_mutex_unlock(&q->mutex); + return AEE_EWOULDBLOCK; + } + } + + // Go through buffers + for(i = 0; i < num_buffers; i++) { + struct dspqueue_buffer *b = &buffers[i]; + void *va; + size_t size; + + // Find buffer in internal FastRPC structures and handle + // refcounts + if(b->flags & DSPQUEUE_BUFFER_FLAG_REF) { + VERIFYC((b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) == 0, + AEE_EBADPARM); + nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, &va, + &size); + } else if(b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { + nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, &va, + &size); + } else { + nErr = fastrpc_buffer_ref(q->domain, b->fd, 0, &va, + &size); + } + if(nErr == AEE_ENOSUCHMAP) { + FARF(ERROR, + "Buffer FD %d in queue message not mapped to " + "domain %d", + b->fd, q->domain); + goto bail; + } + VERIFY(nErr == 0); + buf_refs = i + 1; + + // Ensure buffer offset and size are within the buffer as + // mapped. Use mapped size if not specified by the client + if(b->size != 0) { + uint64_t bend + = ((uint64_t)b->offset) + ((uint64_t)b->size); + VERIFYC(bend <= size, AEE_EBADPARM); + // Calculate new bounds for cache ops + va = (void *)(((uintptr_t)va) + b->offset); + size = b->size; + } else { + VERIFYC(b->offset == 0, AEE_EBADPARM); + } + } + + // Write packet header + flags |= DSPQUEUE_PACKET_FLAG_USER_READY; + phdr = (((uint64_t)(len & 0xffffffff)) + | (((uint64_t)(flags & 0xffff)) << 32) + | (((uint64_t)(num_buffers & 0xff)) << 48) + | (((uint64_t)(q->seq_no & 0xff)) << 56)); + w = write_64(qp, w, qsize, phdr); + if(wrap) { + // Write the packet at the beginning of the queue, + // replicating the header + w = write_64(qp, 0, qsize, phdr); + } + + // Write buffer information + if(num_buffers > 0) { + w = write_data(qp, w, qsize, buffers, + num_buffers * sizeof(struct dspqueue_buffer)); + } + + // Write message + if(message_length > 0) { + w = write_data(qp, w, qsize, message, message_length); + } + + // Update write pointer. This marks the message available in the user + // queue + q->write_packet_count++; + barrier_store(); + write_state->position = w; + write_state->packet_count = q->write_packet_count; + cache_flush_line(write_state); + + // Signal that we've written a packet + q->req_packet_count++; + dq->state->req_packet_count[q->id] = q->req_packet_count; + FARF(LOW, "Queue %u req_packet_count %u", (unsigned)q->id, + (unsigned)q->req_packet_count); + cache_flush_word(&dq->state->req_packet_count[q->id]); + if(q->have_wait_counts) { + // Only send a signal if the other end is potentially waiting + barrier_full(); + cache_invalidate_word(&read_state->wait_count); + if(read_state->wait_count) { + FARF(MEDIUM, "%s: Send signal", __func__); + VERIFY( + (nErr = send_signal(q, DSPQUEUE_SIGNAL_REQ_PACKET)) + == 0); + } else { + FARF(MEDIUM, "%s: Don't send signal", __func__); + } + } else { + FARF(MEDIUM, "%s: No wait counts - send signal", __func__); + VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_REQ_PACKET)) + == 0); + } + + q->seq_no++; + + pthread_mutex_unlock(&q->mutex); + locked = 0; + return 0; bail: - for (i = 0; i < buf_refs; i++) { - // Undo buffer reference changes - struct dspqueue_buffer *b = &buffers[i]; - if (b->flags & DSPQUEUE_BUFFER_FLAG_REF) { - fastrpc_buffer_ref(q->domain, b->fd, -1, NULL, NULL); - } else if (b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { - fastrpc_buffer_ref(q->domain, b->fd, 1, NULL, NULL); - } - } - if (locked) { - pthread_mutex_unlock(&q->mutex); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for queue %p (flags 0x%x, num_buffers %u, " - "message_length %u)", - nErr, __func__, queue, (unsigned)flags, (unsigned)num_buffers, - (unsigned)message_length); - } - return nErr; + for(i = 0; i < buf_refs; i++) { + // Undo buffer reference changes + struct dspqueue_buffer *b = &buffers[i]; + if(b->flags & DSPQUEUE_BUFFER_FLAG_REF) { + fastrpc_buffer_ref(q->domain, b->fd, -1, NULL, NULL); + } else if(b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { + fastrpc_buffer_ref(q->domain, b->fd, 1, NULL, NULL); + } + } + if(locked) { + pthread_mutex_unlock(&q->mutex); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for queue %p (flags 0x%x, " + "num_buffers %u, " + "message_length %u)", + nErr, __func__, queue, (unsigned)flags, + (unsigned)num_buffers, (unsigned)message_length); + } + return nErr; } -static void timespec_add_us(struct timespec *ts, uint32_t us) { - uint64_t ns = (uint64_t)ts->tv_nsec + (uint64_t)(1000 * (us % 1000000)); - if (ns > 1000000000ULL) { - ts->tv_nsec = (long)(ns - 1000000000ULL); - ts->tv_sec += (us / 1000000) + 1; - } else { - ts->tv_nsec = ns; - ts->tv_sec += us / 1000000; - } +static void +timespec_add_us(struct timespec *ts, uint32_t us) +{ + uint64_t ns + = (uint64_t)ts->tv_nsec + (uint64_t)(1000 * (us % 1000000)); + if(ns > 1000000000ULL) { + ts->tv_nsec = (long)(ns - 1000000000ULL); + ts->tv_sec += (us / 1000000) + 1; + } else { + ts->tv_nsec = ns; + ts->tv_sec += us / 1000000; + } } -AEEResult dspqueue_write(dspqueue_t queue, uint32_t flags, uint32_t num_buffers, - struct dspqueue_buffer *buffers, - uint32_t message_length, const uint8_t *message, - uint32_t timeout_us) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_packet_queue_header *pq = NULL; - struct dspqueue_packet_queue_state *write_state = NULL; - _Atomic uint32_t *wait_count = NULL; - int waiting = 0; - struct timespec *timeout_ts = NULL; // no timeout by default - struct timespec ts; - - errno = 0; - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_write' on individual queues. - return dspqueue_multidomain_write(q, flags, num_buffers, buffers, - message_length, message, timeout_us, true); - } - - pq = &q->header->req_queue; - write_state = (struct dspqueue_packet_queue_state*)(((uintptr_t)q->header) - + pq->write_state_offset); - wait_count = (_Atomic uint32_t*) &write_state->wait_count; - - pthread_mutex_lock(&q->space_mutex); - - // Try a write first before dealing with timeouts - nErr = dspqueue_write_noblock(queue, flags, num_buffers, buffers, - message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - // Write got through or failed permanently - goto bail; - } - - if (q->have_wait_counts) { - // Flag that we're potentially waiting and try again - atomic_fetch_add(wait_count, 1); - cache_flush_word(wait_count); - waiting = 1; - nErr = dspqueue_write_noblock(queue, flags, num_buffers, buffers, - message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - goto bail; - } - } - - if (timeout_us != DSPQUEUE_TIMEOUT_NONE) { - // Calculate timeout expiry and use timeout - VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); - timespec_add_us(&ts, timeout_us); - timeout_ts = &ts; - } - - while (1) { - FARF(LOW, "Queue %u wait space", (unsigned)q->id); - VERIFY((nErr = wait_signal_locked(q, DSPQUEUE_SIGNAL_REQ_SPACE, - timeout_ts)) == 0); - FARF(LOW, "Queue %u got space", (unsigned)q->id); - nErr = dspqueue_write_noblock(queue, flags, num_buffers, buffers, - message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - goto bail; - } - } +AEEResult +dspqueue_write(dspqueue_t queue, uint32_t flags, uint32_t num_buffers, + struct dspqueue_buffer *buffers, uint32_t message_length, + const uint8_t *message, uint32_t timeout_us) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_packet_queue_header *pq = NULL; + struct dspqueue_packet_queue_state *write_state = NULL; + _Atomic uint32_t *wait_count = NULL; + int waiting = 0; + struct timespec *timeout_ts = NULL; // no timeout by default + struct timespec ts; + + errno = 0; + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_write' on individual queues. + return dspqueue_multidomain_write(q, flags, num_buffers, + buffers, message_length, + message, timeout_us, true); + } + + pq = &q->header->req_queue; + write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->write_state_offset); + wait_count = (_Atomic uint32_t *)&write_state->wait_count; + + pthread_mutex_lock(&q->space_mutex); + + // Try a write first before dealing with timeouts + nErr = dspqueue_write_noblock(queue, flags, num_buffers, buffers, + message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + // Write got through or failed permanently + goto bail; + } + + if(q->have_wait_counts) { + // Flag that we're potentially waiting and try again + atomic_fetch_add(wait_count, 1); + cache_flush_word(wait_count); + waiting = 1; + nErr + = dspqueue_write_noblock(queue, flags, num_buffers, + buffers, message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + goto bail; + } + } + + if(timeout_us != DSPQUEUE_TIMEOUT_NONE) { + // Calculate timeout expiry and use timeout + VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); + timespec_add_us(&ts, timeout_us); + timeout_ts = &ts; + } + + while(1) { + FARF(LOW, "Queue %u wait space", (unsigned)q->id); + VERIFY((nErr = wait_signal_locked(q, DSPQUEUE_SIGNAL_REQ_SPACE, + timeout_ts)) + == 0); + FARF(LOW, "Queue %u got space", (unsigned)q->id); + nErr + = dspqueue_write_noblock(queue, flags, num_buffers, + buffers, message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + goto bail; + } + } bail: - if (waiting) { - atomic_fetch_sub(wait_count, 1); - cache_flush_word(wait_count); - } - pthread_mutex_unlock(&q->space_mutex); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for queue %p (flags 0x%x, num_buffers %u, " - "message_length %u errno %s)", - nErr, __func__, queue, (unsigned)flags, (unsigned)num_buffers, - (unsigned)message_length, strerror(errno)); - } - return nErr; + if(waiting) { + atomic_fetch_sub(wait_count, 1); + cache_flush_word(wait_count); + } + pthread_mutex_unlock(&q->space_mutex); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for queue %p (flags 0x%x, " + "num_buffers %u, " + "message_length %u errno %s)", + nErr, __func__, queue, (unsigned)flags, + (unsigned)num_buffers, (unsigned)message_length, + strerror(errno)); + } + return nErr; } -AEEResult dspqueue_write_early_wakeup_noblock(dspqueue_t queue, - uint32_t wakeup_delay, - uint32_t packet_flags) { - - uint32_t flags = packet_flags | DSPQUEUE_PACKET_FLAG_WAKEUP; - struct dspqueue *q = queue; - const uint8_t *msg = wakeup_delay ? (const uint8_t *)&wakeup_delay : NULL; - uint32_t msg_len = wakeup_delay ? sizeof(wakeup_delay) : 0; - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_write_noblock' on individual queues - return dspqueue_multidomain_write(q, flags, 0, NULL, - msg_len, msg, 0, false); - } - return dspqueue_write_noblock(queue, flags, 0, NULL, msg_len, msg); +AEEResult +dspqueue_write_early_wakeup_noblock(dspqueue_t queue, uint32_t wakeup_delay, + uint32_t packet_flags) +{ + + uint32_t flags = packet_flags | DSPQUEUE_PACKET_FLAG_WAKEUP; + struct dspqueue *q = queue; + const uint8_t *msg + = wakeup_delay ? (const uint8_t *)&wakeup_delay : NULL; + uint32_t msg_len = wakeup_delay ? sizeof(wakeup_delay) : 0; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_write_noblock' on individual + // queues + return dspqueue_multidomain_write(q, flags, 0, NULL, msg_len, + msg, 0, false); + } + return dspqueue_write_noblock(queue, flags, 0, NULL, msg_len, msg); } -static AEEResult peek_locked(volatile const uint8_t *qp, uint32_t r, - uint32_t *flags, uint32_t *num_buffers, - uint32_t *message_length, uint64_t *raw_header) { - - AEEResult nErr = 0; - uint32_t f, nb, len; - uint64_t d; - - // Read packet header - cache_invalidate_line((void *)((uintptr_t)qp + r)); - d = *((uint64_t *)((uintptr_t)qp + r)); - len = d & 0xffffffff; - f = (d >> 32) & 0xffff; - if (f & DSPQUEUE_PACKET_FLAG_BUFFERS) { - nb = (d >> 48) & 0xff; - } else { - nb = 0; - } - VERIFYC(len >= (8 + nb * sizeof(struct dspqueue_buffer)), AEE_EBADITEM); - - // Populate response - if (flags != NULL) { - *flags = f; - } - if (num_buffers != NULL) { - *num_buffers = nb; - } - if (message_length != NULL) { - if (f & DSPQUEUE_PACKET_FLAG_MESSAGE) { - *message_length = len - 8 - nb * sizeof(struct dspqueue_buffer); - } else { - *message_length = 0; - } - } - if (raw_header != NULL) { - *raw_header = d; - } - - // Fall through +static AEEResult +peek_locked(volatile const uint8_t *qp, uint32_t r, uint32_t *flags, + uint32_t *num_buffers, uint32_t *message_length, + uint64_t *raw_header) +{ + + AEEResult nErr = 0; + uint32_t f, nb, len; + uint64_t d; + + // Read packet header + cache_invalidate_line((void *)((uintptr_t)qp + r)); + d = *((uint64_t *)((uintptr_t)qp + r)); + len = d & 0xffffffff; + f = (d >> 32) & 0xffff; + if(f & DSPQUEUE_PACKET_FLAG_BUFFERS) { + nb = (d >> 48) & 0xff; + } else { + nb = 0; + } + VERIFYC(len >= (8 + nb * sizeof(struct dspqueue_buffer)), + AEE_EBADITEM); + + // Populate response + if(flags != NULL) { + *flags = f; + } + if(num_buffers != NULL) { + *num_buffers = nb; + } + if(message_length != NULL) { + if(f & DSPQUEUE_PACKET_FLAG_MESSAGE) { + *message_length + = len - 8 - nb * sizeof(struct dspqueue_buffer); + } else { + *message_length = 0; + } + } + if(raw_header != NULL) { + *raw_header = d; + } + + // Fall through bail: - return nErr; + return nErr; } /* @@ -1748,11 +1916,14 @@ static AEEResult peek_locked(volatile const uint8_t *qp, uint32_t r, * * If all the individual queues are empty, then no packet is read. */ -static int dspqueue_multidomain_read(struct dspqueue *q, uint32_t *flags, - uint32_t max_buffers, uint32_t *num_buffers, - struct dspqueue_buffer *buffers, - uint32_t max_message_length, uint32_t *message_length, - uint8_t *message, uint32_t timeout_us, bool read, bool block) { +static int +dspqueue_multidomain_read(struct dspqueue *q, uint32_t *flags, + uint32_t max_buffers, uint32_t *num_buffers, + struct dspqueue_buffer *buffers, + uint32_t max_message_length, + uint32_t *message_length, uint8_t *message, + uint32_t timeout_us, bool read, bool block) +{ int nErr = AEE_SUCCESS; struct dspqueue_multidomain *mdq = NULL; bool locked = false; @@ -1763,52 +1934,56 @@ static int dspqueue_multidomain_read(struct dspqueue *q, uint32_t *flags, mdq = &q->mdq; VERIFYC(mdq->is_mdq, AEE_EINVALIDITEM); - if (block && mdq->num_domain_ids > 1) { + if(block && mdq->num_domain_ids > 1) { /* - * Blocked read cannot be supported on multi-domain queues because - * the read operation is done in a serial manner on the individual - * queues of each domain and the first queue with a valid packet - * is returned to client. - * Say if the first domain's queue does not have any response - * packets to consume but the second domain's queue does, then - * the read call will just block indefinitely on the first queue - * without ever checking the subsequence queues. + * Blocked read cannot be supported on multi-domain queues + * because the read operation is done in a serial manner on the + * individual queues of each domain and the first queue with a + * valid packet is returned to client. Say if the first + * domain's queue does not have any response packets to consume + * but the second domain's queue does, then the read call will + * just block indefinitely on the first queue without ever + * checking the subsequence queues. */ - nErr = AEE_EUNSUPPORTED; - FARF(ALWAYS, "Error 0x%x: %s: not supported for multi-domain queue %p", - nErr, __func__, q); - return nErr; + nErr = AEE_EUNSUPPORTED; + FARF(ALWAYS, + "Error 0x%x: %s: not supported for multi-domain queue %p", + nErr, __func__, q); + return nErr; } // Only one multi-domain read request at a time. pthread_mutex_lock(&q->mutex); locked = true; // Read packet from individual queues - for (unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { + for(unsigned int ii = 0; ii < mdq->num_domain_ids; ii++) { cq = mdq->queues[ii]; - if (read) { - if (block) { - nErr = dspqueue_read(cq, flags, max_buffers, - num_buffers, buffers, max_message_length, - message_length, message, timeout_us); + if(read) { + if(block) { + nErr = dspqueue_read( + cq, flags, max_buffers, num_buffers, + buffers, max_message_length, + message_length, message, timeout_us); } else { - nErr = dspqueue_read_noblock(cq, flags, - max_buffers, num_buffers, buffers, - max_message_length, message_length, message); + nErr = dspqueue_read_noblock( + cq, flags, max_buffers, num_buffers, + buffers, max_message_length, + message_length, message); } } else { - if (block) { - nErr = dspqueue_peek(cq, flags, - num_buffers, message_length, timeout_us); + if(block) { + nErr = dspqueue_peek(cq, flags, num_buffers, + message_length, + timeout_us); } else { - nErr = dspqueue_peek_noblock(cq, flags, - num_buffers, message_length); + nErr = dspqueue_peek_noblock( + cq, flags, num_buffers, message_length); } } - if (!nErr) { + if(!nErr) { // Packet found in an individual queue break; - } else if (nErr == AEE_EWOULDBLOCK) { + } else if(nErr == AEE_EWOULDBLOCK) { // If queue is empty, proceed to next queue continue; } else { @@ -1817,539 +1992,599 @@ static int dspqueue_multidomain_read(struct dspqueue *q, uint32_t *flags, } } bail: - if (locked) + if(locked) pthread_mutex_unlock(&q->mutex); - if (nErr && nErr != AEE_EWOULDBLOCK) { - FARF(ALWAYS, "Error 0x%x: %s (read %d, block %d): failed for queue %p, max bufs %u, max msg len %u", - nErr, __func__, read, block, q, max_buffers, max_message_length); + if(nErr && nErr != AEE_EWOULDBLOCK) { + FARF(ALWAYS, + "Error 0x%x: %s (read %d, block %d): failed for queue " + "%p, max bufs %u, max msg len %u", + nErr, __func__, read, block, q, max_buffers, + max_message_length); } return nErr; } -AEEResult dspqueue_peek_noblock(dspqueue_t queue, uint32_t *flags, - uint32_t *num_buffers, - uint32_t *message_length) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_packet_queue_header *pq = NULL; - volatile const uint8_t *qp = NULL; - uint32_t r, qleft; - int locked = 0; - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_peek_noblock' on individual queues - return dspqueue_multidomain_read(q, flags, 0, num_buffers, - NULL, 0, message_length, NULL, 0, false, false); - } - - pq = &q->header->resp_queue; - qp = (volatile const uint8_t*) (((uintptr_t)q->header) - + pq->queue_offset); - - pthread_mutex_lock(&q->mutex); - locked = 1; - - // Check if we have a packet available - get_queue_state_read(q->header, pq, &qleft, &r, NULL); - if (qleft < 8) { - pthread_mutex_unlock(&q->mutex); - return AEE_EWOULDBLOCK; - } - - VERIFY((nErr = peek_locked(qp, r, flags, num_buffers, message_length, - NULL)) == 0); - - // Fall through +AEEResult +dspqueue_peek_noblock(dspqueue_t queue, uint32_t *flags, uint32_t *num_buffers, + uint32_t *message_length) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_packet_queue_header *pq = NULL; + volatile const uint8_t *qp = NULL; + uint32_t r, qleft; + int locked = 0; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_peek_noblock' on individual + // queues + return dspqueue_multidomain_read(q, flags, 0, num_buffers, + NULL, 0, message_length, NULL, + 0, false, false); + } + + pq = &q->header->resp_queue; + qp = (volatile const uint8_t *)(((uintptr_t)q->header) + + pq->queue_offset); + + pthread_mutex_lock(&q->mutex); + locked = 1; + + // Check if we have a packet available + get_queue_state_read(q->header, pq, &qleft, &r, NULL); + if(qleft < 8) { + pthread_mutex_unlock(&q->mutex); + return AEE_EWOULDBLOCK; + } + + VERIFY((nErr + = peek_locked(qp, r, flags, num_buffers, message_length, NULL)) + == 0); + + // Fall through bail: - if (locked) { - pthread_mutex_unlock(&q->mutex); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for queue %p", nErr, __func__, queue); - } - return nErr; + if(locked) { + pthread_mutex_unlock(&q->mutex); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for queue %p", nErr, + __func__, queue); + } + return nErr; } -AEEResult dspqueue_peek(dspqueue_t queue, uint32_t *flags, - uint32_t *num_buffers, uint32_t *message_length, - uint32_t timeout_us) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_packet_queue_header *pq = NULL; - struct dspqueue_packet_queue_state *read_state = NULL; - _Atomic uint32_t *wait_count = NULL; - int waiting = 0; - struct timespec *timeout_ts = NULL; // no timeout by default - struct timespec ts; - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_read_noblock' on individual queues - return dspqueue_multidomain_read(q, flags, 0, num_buffers, - NULL, 0, message_length, NULL, timeout_us, false, true); - } - - pq = &q->header->resp_queue; - read_state =(struct dspqueue_packet_queue_state *) (((uintptr_t)q->header) - + pq->read_state_offset); - wait_count = (_Atomic uint32_t *) &read_state->wait_count; - - pthread_mutex_lock(&q->packet_mutex); - - // Try a read first before dealing with timeouts - nErr = dspqueue_peek_noblock(queue, flags, num_buffers, message_length); - if (nErr != AEE_EWOULDBLOCK) { - // Have a packet or got an error - goto bail; - } - - if (q->have_wait_counts) { - // Mark that we're potentially waiting and try again - atomic_fetch_add(wait_count, 1); - cache_flush_word(wait_count); - waiting = 1; - nErr = dspqueue_peek_noblock(queue, flags, num_buffers, message_length); - if (nErr != AEE_EWOULDBLOCK) { - goto bail; - } - } - - if (timeout_us != DSPQUEUE_TIMEOUT_NONE) { - // Calculate timeout expiry and use timeout - VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); - timespec_add_us(&ts, timeout_us); - timeout_ts = &ts; - } - - while (1) { - FARF(LOW, "Queue %u wait packet", (unsigned)q->id); - VERIFY((nErr = wait_signal_locked(q, DSPQUEUE_SIGNAL_RESP_PACKET, - timeout_ts)) == 0); - FARF(LOW, "Queue %u got packet", (unsigned)q->id); - nErr = dspqueue_peek_noblock(queue, flags, num_buffers, message_length); - if (nErr != AEE_EWOULDBLOCK) { - // Have a packet or got an error - goto bail; - } - } +AEEResult +dspqueue_peek(dspqueue_t queue, uint32_t *flags, uint32_t *num_buffers, + uint32_t *message_length, uint32_t timeout_us) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_packet_queue_header *pq = NULL; + struct dspqueue_packet_queue_state *read_state = NULL; + _Atomic uint32_t *wait_count = NULL; + int waiting = 0; + struct timespec *timeout_ts = NULL; // no timeout by default + struct timespec ts; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_read_noblock' on individual + // queues + return dspqueue_multidomain_read(q, flags, 0, num_buffers, + NULL, 0, message_length, NULL, + timeout_us, false, true); + } + + pq = &q->header->resp_queue; + read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->read_state_offset); + wait_count = (_Atomic uint32_t *)&read_state->wait_count; + + pthread_mutex_lock(&q->packet_mutex); + + // Try a read first before dealing with timeouts + nErr + = dspqueue_peek_noblock(queue, flags, num_buffers, message_length); + if(nErr != AEE_EWOULDBLOCK) { + // Have a packet or got an error + goto bail; + } + + if(q->have_wait_counts) { + // Mark that we're potentially waiting and try again + atomic_fetch_add(wait_count, 1); + cache_flush_word(wait_count); + waiting = 1; + nErr = dspqueue_peek_noblock(queue, flags, num_buffers, + message_length); + if(nErr != AEE_EWOULDBLOCK) { + goto bail; + } + } + + if(timeout_us != DSPQUEUE_TIMEOUT_NONE) { + // Calculate timeout expiry and use timeout + VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); + timespec_add_us(&ts, timeout_us); + timeout_ts = &ts; + } + + while(1) { + FARF(LOW, "Queue %u wait packet", (unsigned)q->id); + VERIFY((nErr = wait_signal_locked( + q, DSPQUEUE_SIGNAL_RESP_PACKET, timeout_ts)) + == 0); + FARF(LOW, "Queue %u got packet", (unsigned)q->id); + nErr = dspqueue_peek_noblock(queue, flags, num_buffers, + message_length); + if(nErr != AEE_EWOULDBLOCK) { + // Have a packet or got an error + goto bail; + } + } bail: - if (waiting) { - atomic_fetch_sub(wait_count, 1); - cache_flush_word(wait_count); - } - pthread_mutex_unlock(&q->packet_mutex); - return nErr; + if(waiting) { + atomic_fetch_sub(wait_count, 1); + cache_flush_word(wait_count); + } + pthread_mutex_unlock(&q->packet_mutex); + return nErr; } -static uint64_t get_time_usec(uint64_t *t) { +static uint64_t +get_time_usec(uint64_t *t) +{ - struct timespec ts; - int err = clock_gettime(CLOCK_MONOTONIC, &ts); - *t = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000; - return err; + struct timespec ts; + int err = clock_gettime(CLOCK_MONOTONIC, &ts); + *t = ts.tv_sec * 1000000ULL + ts.tv_nsec / 1000; + return err; } -static inline uint32_t read_data(volatile const uint8_t *packet_queue, - uint32_t read_pos, uint32_t queue_len, - void *data, uint32_t data_len) { +static inline uint32_t +read_data(volatile const uint8_t *packet_queue, uint32_t read_pos, + uint32_t queue_len, void *data, uint32_t data_len) +{ - uintptr_t qp = (uintptr_t)packet_queue; + uintptr_t qp = (uintptr_t)packet_queue; - assert(data != NULL); - assert(data_len > 0); - assert((read_pos & 7) == 0); - assert((queue_len - read_pos) >= data_len); + assert(data != NULL); + assert(data_len > 0); + assert((read_pos & 7) == 0); + assert((queue_len - read_pos) >= data_len); - cache_invalidate((void *)(qp + read_pos), data_len); - memcpy(data, (void *)(qp + read_pos), data_len); - read_pos += (data_len + 7) & (~7); - assert(read_pos <= queue_len); - if (read_pos >= queue_len) { - read_pos = 0; - } + cache_invalidate((void *)(qp + read_pos), data_len); + memcpy(data, (void *)(qp + read_pos), data_len); + read_pos += (data_len + 7) & (~7); + assert(read_pos <= queue_len); + if(read_pos >= queue_len) { + read_pos = 0; + } - return read_pos; + return read_pos; } -AEEResult dspqueue_read_noblock(dspqueue_t queue, uint32_t *flags, - uint32_t max_buffers, uint32_t *num_buffers, - struct dspqueue_buffer *buffers, - uint32_t max_message_length, - uint32_t *message_length, uint8_t *message) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_domain_queues *dq = NULL; - struct dspqueue_packet_queue_header *pq = NULL; - volatile const uint8_t *qp = NULL; - struct dspqueue_packet_queue_state *read_state = NULL; - struct dspqueue_packet_queue_state *write_state = NULL; - uint32_t r, qleft; - uint32_t f, num_b, msg_l, qsize = 0; - uint32_t len; - int locked = 0; - unsigned i; - uint32_t buf_refs = 0; - uint64_t header; - - errno = 0; - -if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_read_noblock' on individual queues - return dspqueue_multidomain_read(q, flags, max_buffers, - num_buffers, buffers, max_message_length, - message_length, message, 0, true, false); - } - - dq = queues->domain_queues[q->domain]; - pq = &q->header->resp_queue; - qp = (volatile const uint8_t *) (((uintptr_t)q->header) + pq->queue_offset); - read_state = (struct dspqueue_packet_queue_state *) (((uintptr_t)q->header) - + pq->read_state_offset); - write_state = (struct dspqueue_packet_queue_state *) (((uintptr_t)q->header) - + pq->write_state_offset); - qsize = pq->queue_length; - - pthread_mutex_lock(&q->mutex); - locked = 1; - - VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); - - // Check if we have a packet available - FARF(LOW, "Queue %u wp %u", (unsigned)q->id, (unsigned)write_state->position); - get_queue_state_read(q->header, pq, &qleft, &r, NULL); - if (qleft < 8) { - pthread_mutex_unlock(&q->mutex); - return AEE_EWOULDBLOCK; - } - - // Get and parse packet header - VERIFY((nErr = peek_locked(qp, r, &f, &num_b, &msg_l, &header)) == 0); - - // Check if this is an early wakeup packet; handle accordingly - if (f & DSPQUEUE_PACKET_FLAG_WAKEUP) { - uint32_t wakeup = 0; - uint32_t waittime = DEFAULT_EARLY_WAKEUP_WAIT; - uint64_t t1 = 0; - - // Read packet, handling possible wraparound - VERIFYC(num_b == 0, AEE_ERPC); - len = 8 + msg_l; - if ((qsize - r) < len) { - assert((qleft - (qsize - r)) >= len); - r = 8; - } else { - r += 8; - } - if (msg_l > 0) { - VERIFYC(msg_l == 4, AEE_EBADITEM); - r = read_data(qp, r, qsize, (uint8_t *)&wakeup, 4); - if (wakeup > MAX_EARLY_WAKEUP_WAIT) { - waittime = MAX_EARLY_WAKEUP_WAIT; - } else { - if (wakeup != 0) { - waittime = wakeup; - } - } - } - - // Update read pointer - q->read_packet_count++; - barrier_full(); - read_state->position = r; - read_state->packet_count = q->read_packet_count; - cache_flush_line(read_state); - - // Signal that we've consumed a packet - q->resp_space_count++; - dq->state->resp_space_count[q->id] = q->resp_space_count; - FARF(LOW, "Queue %u resp_space_count %u", (unsigned)q->id, - (unsigned)q->resp_space_count); - cache_flush_word(&dq->state->resp_space_count[q->id]); - if (q->have_wait_counts) { - // Only signal if the other end is potentially waiting - cache_invalidate_word(&write_state->wait_count); - if (write_state->wait_count) { - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) == - AEE_SUCCESS); - } - } else { - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) == - AEE_SUCCESS); - } - - // Wait for a packet to become available - FARF(LOW, "Early wakeup, %u usec", (unsigned)waittime); - get_queue_state_read(q->header, pq, &qleft, &r, NULL); - if (qleft < 8) { - VERIFY((nErr = get_time_usec(&t1)) == 0); - uint64_t t2 = 0; - do { - VERIFY((nErr = get_time_usec(&t2)) == 0); - if (((t1 + waittime) > t2) && - (((t1 + waittime) - t2) > EARLY_WAKEUP_SLEEP)) { - FARF(LOW, "No sleep %u", (unsigned)EARLY_WAKEUP_SLEEP); - } - get_queue_state_read(q->header, pq, &qleft, &r, NULL); - if (qleft >= 8) { - if (t2 != 0) { - q->early_wakeup_wait += t2 - t1; - FARF(LOW, "Got packet after %uus", (unsigned)(t2 - t1)); - } else { - FARF(LOW, "Got packet"); - } - break; - } - } while ((t1 + waittime) > t2); - - if (qleft < 8) { - // The next packet didn't get here in time - q->early_wakeup_wait += t2 - t1; - q->early_wakeup_misses++; - FARF(LOW, "Didn't get packet after %uus", (unsigned)(t2 - t1)); - pthread_mutex_unlock(&q->mutex); - return AEE_EWOULDBLOCK; - } - } - - // Have the next packet. Parse header and continue - VERIFY((nErr = peek_locked(qp, r, &f, &num_b, &msg_l, &header)) == 0); - } - - // Check the client has provided enough space for the packet - if ((f & DSPQUEUE_PACKET_FLAG_BUFFERS) && (buffers != NULL)) { - if (max_buffers < num_b) { - FARF(ERROR, - "Too many buffer references in packet to fit in output buffer"); - nErr = AEE_EBADPARM; - goto bail; - } - } - VERIFYC(num_b <= DSPQUEUE_MAX_BUFFERS, AEE_EBADITEM); - if ((f & DSPQUEUE_PACKET_FLAG_MESSAGE) && (message != NULL)) { - if (max_message_length < msg_l) { - FARF(ERROR, "Message in packet too large to fit in output buffer"); - nErr = AEE_EBADPARM; - goto bail; - } - } - - // Check if the packet can fit to the queue without being split by the - // queue end. If not, the writer has wrapped it around to the - // beginning of the queue - len = 8 + num_b * sizeof(struct dspqueue_buffer) + msg_l; - if ((qsize - r) < len) { - assert((qleft - (qsize - r)) >= len); - r = 8; - } else { - r += 8; - } - - VERIFYC(f & DSPQUEUE_PACKET_FLAG_USER_READY, AEE_EBADITEM); - - // Read packet data - if (flags != NULL) { - *flags = f; - } - if (num_b > 0) { - if (buffers != NULL) { - r = read_data(qp, r, qsize, buffers, - num_b * sizeof(struct dspqueue_buffer)); - } else { - r += num_b * sizeof(struct dspqueue_buffer); - } - } - if (msg_l > 0) { - if (message != NULL) { - r = read_data(qp, r, qsize, message, msg_l); - } else { - r += (msg_l + 7) & (~7); - } - } - if (message_length != NULL) { - *message_length = msg_l; - } - - // Update read pointer - assert(r <= qsize); - if (r >= qsize) { - r = 0; - } - q->read_packet_count++; - barrier_full(); - read_state->position = r; - read_state->packet_count = q->read_packet_count; - cache_flush_line(read_state); - - // Signal that we've consumed a packet - q->resp_space_count++; - dq->state->resp_space_count[q->id] = q->resp_space_count; - FARF(LOW, "Queue %u resp_space_count %u", (unsigned)q->id, - (unsigned)q->resp_space_count); - cache_flush_word(&dq->state->resp_space_count[q->id]); - if (q->have_wait_counts) { - // Only signal if the other end is potentially waiting - cache_invalidate_word(&write_state->wait_count); - if (write_state->wait_count) { - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) == - AEE_SUCCESS); - } - } else { - VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) == AEE_SUCCESS); - } - - // Go through buffers - if ((buffers != NULL) && (num_b > 0)) { - for (i = 0; i < num_b; i++) { - struct dspqueue_buffer *b = &buffers[i]; - void *va; - size_t size; - - // Find buffer in internal FastRPC structures and handle refcounts - if (b->flags & DSPQUEUE_BUFFER_FLAG_REF) { - VERIFYC((b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) == 0, AEE_EBADPARM); - nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, &va, &size); - } else if (b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { - nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, &va, &size); - } else { - nErr = fastrpc_buffer_ref(q->domain, b->fd, 0, &va, &size); - } - if (nErr == AEE_ENOSUCHMAP) { - FARF(ERROR, "Buffer FD %d in queue message not mapped to domain %d", - b->fd, q->domain); - goto bail; - } - VERIFY(nErr == 0); - buf_refs = i + 1; - - // Check and use offset and size from the packet if specified - if (b->size != 0) { - uint64_t bend = ((uint64_t)b->offset) + ((uint64_t)b->size); - VERIFYC(bend <= size, AEE_EBADITEM); - va = (void *)(((uintptr_t)va) + b->offset); - b->ptr = va; - size = b->size; - } else { - VERIFYC(b->offset == 0, AEE_EBADITEM); - b->ptr = va; - b->size = size; - } - } - } - - if (num_buffers != NULL) { - *num_buffers = num_b; - } - - pthread_mutex_unlock(&q->mutex); - locked = 0; - return AEE_SUCCESS; +AEEResult +dspqueue_read_noblock(dspqueue_t queue, uint32_t *flags, uint32_t max_buffers, + uint32_t *num_buffers, struct dspqueue_buffer *buffers, + uint32_t max_message_length, uint32_t *message_length, + uint8_t *message) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_domain_queues *dq = NULL; + struct dspqueue_packet_queue_header *pq = NULL; + volatile const uint8_t *qp = NULL; + struct dspqueue_packet_queue_state *read_state = NULL; + struct dspqueue_packet_queue_state *write_state = NULL; + uint32_t r, qleft; + uint32_t f, num_b, msg_l, qsize = 0; + uint32_t len; + int locked = 0; + unsigned i; + uint32_t buf_refs = 0; + uint64_t header; + + errno = 0; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_read_noblock' on individual + // queues + return dspqueue_multidomain_read( + q, flags, max_buffers, num_buffers, buffers, + max_message_length, message_length, message, 0, true, + false); + } + + dq = queues->domain_queues[q->domain]; + pq = &q->header->resp_queue; + qp = (volatile const uint8_t *)(((uintptr_t)q->header) + + pq->queue_offset); + read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->read_state_offset); + write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->write_state_offset); + qsize = pq->queue_length; + + pthread_mutex_lock(&q->mutex); + locked = 1; + + VERIFYC(q->header->queue_count == q->queue_count, AEE_ERPC); + + // Check if we have a packet available + FARF(LOW, "Queue %u wp %u", (unsigned)q->id, + (unsigned)write_state->position); + get_queue_state_read(q->header, pq, &qleft, &r, NULL); + if(qleft < 8) { + pthread_mutex_unlock(&q->mutex); + return AEE_EWOULDBLOCK; + } + + // Get and parse packet header + VERIFY((nErr = peek_locked(qp, r, &f, &num_b, &msg_l, &header)) == 0); + + // Check if this is an early wakeup packet; handle accordingly + if(f & DSPQUEUE_PACKET_FLAG_WAKEUP) { + uint32_t wakeup = 0; + uint32_t waittime = DEFAULT_EARLY_WAKEUP_WAIT; + uint64_t t1 = 0; + + // Read packet, handling possible wraparound + VERIFYC(num_b == 0, AEE_ERPC); + len = 8 + msg_l; + if((qsize - r) < len) { + assert((qleft - (qsize - r)) >= len); + r = 8; + } else { + r += 8; + } + if(msg_l > 0) { + VERIFYC(msg_l == 4, AEE_EBADITEM); + r = read_data(qp, r, qsize, (uint8_t *)&wakeup, 4); + if(wakeup > MAX_EARLY_WAKEUP_WAIT) { + waittime = MAX_EARLY_WAKEUP_WAIT; + } else { + if(wakeup != 0) { + waittime = wakeup; + } + } + } + + // Update read pointer + q->read_packet_count++; + barrier_full(); + read_state->position = r; + read_state->packet_count = q->read_packet_count; + cache_flush_line(read_state); + + // Signal that we've consumed a packet + q->resp_space_count++; + dq->state->resp_space_count[q->id] = q->resp_space_count; + FARF(LOW, "Queue %u resp_space_count %u", (unsigned)q->id, + (unsigned)q->resp_space_count); + cache_flush_word(&dq->state->resp_space_count[q->id]); + if(q->have_wait_counts) { + // Only signal if the other end is potentially waiting + cache_invalidate_word(&write_state->wait_count); + if(write_state->wait_count) { + VERIFY((nErr = send_signal( + q, DSPQUEUE_SIGNAL_RESP_SPACE)) + == AEE_SUCCESS); + } + } else { + VERIFY( + (nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) + == AEE_SUCCESS); + } + + // Wait for a packet to become available + FARF(LOW, "Early wakeup, %u usec", (unsigned)waittime); + get_queue_state_read(q->header, pq, &qleft, &r, NULL); + if(qleft < 8) { + VERIFY((nErr = get_time_usec(&t1)) == 0); + uint64_t t2 = 0; + do { + VERIFY((nErr = get_time_usec(&t2)) == 0); + if(((t1 + waittime) > t2) + && (((t1 + waittime) - t2) + > EARLY_WAKEUP_SLEEP)) { + FARF(LOW, "No sleep %u", + (unsigned)EARLY_WAKEUP_SLEEP); + } + get_queue_state_read(q->header, pq, &qleft, &r, + NULL); + if(qleft >= 8) { + if(t2 != 0) { + q->early_wakeup_wait + += t2 - t1; + FARF(LOW, + "Got packet after %uus", + (unsigned)(t2 - t1)); + } else { + FARF(LOW, "Got packet"); + } + break; + } + } while((t1 + waittime) > t2); + + if(qleft < 8) { + // The next packet didn't get here in time + q->early_wakeup_wait += t2 - t1; + q->early_wakeup_misses++; + FARF(LOW, "Didn't get packet after %uus", + (unsigned)(t2 - t1)); + pthread_mutex_unlock(&q->mutex); + return AEE_EWOULDBLOCK; + } + } + + // Have the next packet. Parse header and continue + VERIFY((nErr = peek_locked(qp, r, &f, &num_b, &msg_l, &header)) + == 0); + } + + // Check the client has provided enough space for the packet + if((f & DSPQUEUE_PACKET_FLAG_BUFFERS) && (buffers != NULL)) { + if(max_buffers < num_b) { + FARF(ERROR, "Too many buffer references in packet to " + "fit in output buffer"); + nErr = AEE_EBADPARM; + goto bail; + } + } + VERIFYC(num_b <= DSPQUEUE_MAX_BUFFERS, AEE_EBADITEM); + if((f & DSPQUEUE_PACKET_FLAG_MESSAGE) && (message != NULL)) { + if(max_message_length < msg_l) { + FARF(ERROR, "Message in packet too large to fit in " + "output buffer"); + nErr = AEE_EBADPARM; + goto bail; + } + } + + // Check if the packet can fit to the queue without being split by the + // queue end. If not, the writer has wrapped it around to the + // beginning of the queue + len = 8 + num_b * sizeof(struct dspqueue_buffer) + msg_l; + if((qsize - r) < len) { + assert((qleft - (qsize - r)) >= len); + r = 8; + } else { + r += 8; + } + + VERIFYC(f & DSPQUEUE_PACKET_FLAG_USER_READY, AEE_EBADITEM); + + // Read packet data + if(flags != NULL) { + *flags = f; + } + if(num_b > 0) { + if(buffers != NULL) { + r = read_data(qp, r, qsize, buffers, + num_b * sizeof(struct dspqueue_buffer)); + } else { + r += num_b * sizeof(struct dspqueue_buffer); + } + } + if(msg_l > 0) { + if(message != NULL) { + r = read_data(qp, r, qsize, message, msg_l); + } else { + r += (msg_l + 7) & (~7); + } + } + if(message_length != NULL) { + *message_length = msg_l; + } + + // Update read pointer + assert(r <= qsize); + if(r >= qsize) { + r = 0; + } + q->read_packet_count++; + barrier_full(); + read_state->position = r; + read_state->packet_count = q->read_packet_count; + cache_flush_line(read_state); + + // Signal that we've consumed a packet + q->resp_space_count++; + dq->state->resp_space_count[q->id] = q->resp_space_count; + FARF(LOW, "Queue %u resp_space_count %u", (unsigned)q->id, + (unsigned)q->resp_space_count); + cache_flush_word(&dq->state->resp_space_count[q->id]); + if(q->have_wait_counts) { + // Only signal if the other end is potentially waiting + cache_invalidate_word(&write_state->wait_count); + if(write_state->wait_count) { + VERIFY( + (nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) + == AEE_SUCCESS); + } + } else { + VERIFY((nErr = send_signal(q, DSPQUEUE_SIGNAL_RESP_SPACE)) + == AEE_SUCCESS); + } + + // Go through buffers + if((buffers != NULL) && (num_b > 0)) { + for(i = 0; i < num_b; i++) { + struct dspqueue_buffer *b = &buffers[i]; + void *va; + size_t size; + + // Find buffer in internal FastRPC structures and + // handle refcounts + if(b->flags & DSPQUEUE_BUFFER_FLAG_REF) { + VERIFYC((b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) + == 0, + AEE_EBADPARM); + nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, + &va, &size); + } else if(b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { + nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, + &va, &size); + } else { + nErr = fastrpc_buffer_ref(q->domain, b->fd, 0, + &va, &size); + } + if(nErr == AEE_ENOSUCHMAP) { + FARF(ERROR, + "Buffer FD %d in queue message not " + "mapped to domain %d", + b->fd, q->domain); + goto bail; + } + VERIFY(nErr == 0); + buf_refs = i + 1; + + // Check and use offset and size from the packet if + // specified + if(b->size != 0) { + uint64_t bend = ((uint64_t)b->offset) + + ((uint64_t)b->size); + VERIFYC(bend <= size, AEE_EBADITEM); + va = (void *)(((uintptr_t)va) + b->offset); + b->ptr = va; + size = b->size; + } else { + VERIFYC(b->offset == 0, AEE_EBADITEM); + b->ptr = va; + b->size = size; + } + } + } + + if(num_buffers != NULL) { + *num_buffers = num_b; + } + + pthread_mutex_unlock(&q->mutex); + locked = 0; + return AEE_SUCCESS; bail: - for (i = 0; i < buf_refs; i++) { - // Undo buffer reference changes - struct dspqueue_buffer *b = &buffers[i]; - if (b->flags & DSPQUEUE_BUFFER_FLAG_REF) { - nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, NULL, NULL); - } else if (b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { - nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, NULL, NULL); - } - } - if (locked) { - pthread_mutex_unlock(&q->mutex); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for queue %p errno %s", nErr, __func__, - queue, strerror(errno)); - } - return nErr; + for(i = 0; i < buf_refs; i++) { + // Undo buffer reference changes + struct dspqueue_buffer *b = &buffers[i]; + if(b->flags & DSPQUEUE_BUFFER_FLAG_REF) { + nErr = fastrpc_buffer_ref(q->domain, b->fd, -1, NULL, + NULL); + } else if(b->flags & DSPQUEUE_BUFFER_FLAG_DEREF) { + nErr = fastrpc_buffer_ref(q->domain, b->fd, 1, NULL, + NULL); + } + } + if(locked) { + pthread_mutex_unlock(&q->mutex); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for queue %p errno %s", + nErr, __func__, queue, strerror(errno)); + } + return nErr; } -AEEResult dspqueue_read(dspqueue_t queue, uint32_t *flags, uint32_t max_buffers, - uint32_t *num_buffers, struct dspqueue_buffer *buffers, - uint32_t max_message_length, uint32_t *message_length, - uint8_t *message, uint32_t timeout_us) { - - AEEResult nErr = AEE_SUCCESS; - struct dspqueue *q = queue; - struct dspqueue_packet_queue_header *pq = NULL; - struct dspqueue_packet_queue_state *read_state = NULL; - _Atomic uint32_t *wait_count = NULL; - int waiting = 0; - struct timespec *timeout_ts = NULL; // no timeout by default - struct timespec ts; - - if (q->mdq.is_mdq) { - // Recursively call 'dspqueue_read_noblock' on individual queues - return dspqueue_multidomain_read(q, flags, max_buffers, - num_buffers, buffers, max_message_length, - message_length, message, timeout_us, true, true); - } - - pq = &q->header->resp_queue; - read_state = (struct dspqueue_packet_queue_state *) (((uintptr_t)q->header) - + pq->read_state_offset); - wait_count = (_Atomic uint32_t *) &read_state->wait_count; - - pthread_mutex_lock(&q->packet_mutex); - - // Try a read first before dealing with timeouts - nErr = dspqueue_read_noblock(queue, flags, max_buffers, num_buffers, buffers, - max_message_length, message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - // Have a packet or got an error - goto bail; - } - - if (q->have_wait_counts) { - // Mark that we're potentially waiting and try again - atomic_fetch_add(wait_count, 1); - cache_flush_word(wait_count); - waiting = 1; - nErr = - dspqueue_read_noblock(queue, flags, max_buffers, num_buffers, buffers, - max_message_length, message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - goto bail; - } - } - - if (timeout_us != DSPQUEUE_TIMEOUT_NONE) { - // Calculate timeout expiry and use timeout - VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); - timespec_add_us(&ts, timeout_us); - timeout_ts = &ts; - } - - while (1) { - FARF(LOW, "Queue %u wait packet", (unsigned)q->id); - VERIFY((nErr = wait_signal_locked(q, DSPQUEUE_SIGNAL_RESP_PACKET, - timeout_ts)) == 0); - FARF(LOW, "Queue %u got packet", (unsigned)q->id); - nErr = - dspqueue_read_noblock(queue, flags, max_buffers, num_buffers, buffers, - max_message_length, message_length, message); - if (nErr != AEE_EWOULDBLOCK) { - // Have a packet or got an error - goto bail; - } - } +AEEResult +dspqueue_read(dspqueue_t queue, uint32_t *flags, uint32_t max_buffers, + uint32_t *num_buffers, struct dspqueue_buffer *buffers, + uint32_t max_message_length, uint32_t *message_length, + uint8_t *message, uint32_t timeout_us) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspqueue *q = queue; + struct dspqueue_packet_queue_header *pq = NULL; + struct dspqueue_packet_queue_state *read_state = NULL; + _Atomic uint32_t *wait_count = NULL; + int waiting = 0; + struct timespec *timeout_ts = NULL; // no timeout by default + struct timespec ts; + + if(q->mdq.is_mdq) { + // Recursively call 'dspqueue_read_noblock' on individual + // queues + return dspqueue_multidomain_read( + q, flags, max_buffers, num_buffers, buffers, + max_message_length, message_length, message, timeout_us, + true, true); + } + + pq = &q->header->resp_queue; + read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->read_state_offset); + wait_count = (_Atomic uint32_t *)&read_state->wait_count; + + pthread_mutex_lock(&q->packet_mutex); + + // Try a read first before dealing with timeouts + nErr = dspqueue_read_noblock(queue, flags, max_buffers, num_buffers, + buffers, max_message_length, + message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + // Have a packet or got an error + goto bail; + } + + if(q->have_wait_counts) { + // Mark that we're potentially waiting and try again + atomic_fetch_add(wait_count, 1); + cache_flush_word(wait_count); + waiting = 1; + nErr = dspqueue_read_noblock( + queue, flags, max_buffers, num_buffers, buffers, + max_message_length, message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + goto bail; + } + } + + if(timeout_us != DSPQUEUE_TIMEOUT_NONE) { + // Calculate timeout expiry and use timeout + VERIFYC(clock_gettime(CLOCK_REALTIME, &ts) == 0, AEE_EFAILED); + timespec_add_us(&ts, timeout_us); + timeout_ts = &ts; + } + + while(1) { + FARF(LOW, "Queue %u wait packet", (unsigned)q->id); + VERIFY((nErr = wait_signal_locked( + q, DSPQUEUE_SIGNAL_RESP_PACKET, timeout_ts)) + == 0); + FARF(LOW, "Queue %u got packet", (unsigned)q->id); + nErr = dspqueue_read_noblock( + queue, flags, max_buffers, num_buffers, buffers, + max_message_length, message_length, message); + if(nErr != AEE_EWOULDBLOCK) { + // Have a packet or got an error + goto bail; + } + } bail: - if (waiting) { - atomic_fetch_sub(wait_count, 1); - cache_flush_word(wait_count); - } - pthread_mutex_unlock(&q->packet_mutex); - return nErr; + if(waiting) { + atomic_fetch_sub(wait_count, 1); + cache_flush_word(wait_count); + } + pthread_mutex_unlock(&q->packet_mutex); + return nErr; } /* Get stats of multi-domain queue */ -static int dspqueue_multidomain_get_stat(struct dspqueue *q, - enum dspqueue_stat stat, uint64_t *value) { +static int +dspqueue_multidomain_get_stat(struct dspqueue *q, enum dspqueue_stat stat, + uint64_t *value) +{ int nErr = AEE_SUCCESS; struct dspqueue_multidomain *mdq = NULL; bool locked = false; @@ -2359,7 +2594,7 @@ static int dspqueue_multidomain_get_stat(struct dspqueue *q, mdq = &q->mdq; VERIFYC(mdq->is_mdq, AEE_EINVALIDITEM); - if (mdq->num_domain_ids > 1) { + if(mdq->num_domain_ids > 1) { /* Stats requests are not supported for multi-domain queues */ nErr = AEE_EUNSUPPORTED; goto bail; @@ -2373,369 +2608,420 @@ static int dspqueue_multidomain_get_stat(struct dspqueue *q, * Always return stats from first queue only as this api is currently * supported for single-domain queues only. */ - VERIFY(AEE_SUCCESS == (nErr = dspqueue_get_stat(mdq->queues[0], - stat, value))); + VERIFY(AEE_SUCCESS + == (nErr = dspqueue_get_stat(mdq->queues[0], stat, value))); bail: - if (locked) + if(locked) pthread_mutex_unlock(&q->mutex); - if (nErr) { + if(nErr) { FARF(ALWAYS, "Error 0x%x: %s: failed for queue %p, stat %d", - nErr, __func__, q, stat); + nErr, __func__, q, stat); } return nErr; } -AEEResult dspqueue_get_stat(dspqueue_t queue, enum dspqueue_stat stat, - uint64_t *value) { - - AEEResult nErr = 0; - struct dspqueue *q = queue; - - if (q->mdq.is_mdq) - return dspqueue_multidomain_get_stat(q, stat, value); - - pthread_mutex_lock(&q->mutex); - - switch (stat) { - case DSPQUEUE_STAT_EARLY_WAKEUP_WAIT_TIME: - *value = q->early_wakeup_wait; - q->early_wakeup_wait = 0; - break; - - case DSPQUEUE_STAT_EARLY_WAKEUP_MISSES: - *value = q->early_wakeup_misses; - q->early_wakeup_misses = 0; - break; - - case DSPQUEUE_STAT_READ_QUEUE_PACKETS: { - struct dspqueue_packet_queue_header *pq = &q->header->resp_queue; - struct dspqueue_packet_queue_state *write_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + - pq->write_state_offset); - uint32_t c; - cache_invalidate_word(&write_state->packet_count); - c = write_state->packet_count - q->read_packet_count; - *value = c; - break; - } - - case DSPQUEUE_STAT_WRITE_QUEUE_PACKETS: { - struct dspqueue_packet_queue_header *pq = &q->header->req_queue; - struct dspqueue_packet_queue_state *read_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + - pq->read_state_offset); - uint32_t c; - cache_invalidate_word(&read_state->packet_count); - c = q->write_packet_count - read_state->packet_count; - *value = c; - break; - } - - case DSPQUEUE_STAT_READ_QUEUE_BYTES: { - struct dspqueue_packet_queue_header *pq = &q->header->resp_queue; - uint32_t b; - get_queue_state_read(q->header, pq, &b, NULL, NULL); - *value = b; - break; - } - - case DSPQUEUE_STAT_WRITE_QUEUE_BYTES: { - struct dspqueue_packet_queue_header *pq = &q->header->req_queue; - uint32_t b; - get_queue_state_write(q->header, pq, &b, NULL, NULL); - *value = pq->queue_length - b - 8; - break; - } - - case DSPQUEUE_STAT_SIGNALING_PERF: { - if (q->have_driver_signaling) { - *value = DSPQUEUE_SIGNALING_PERF_OPTIMIZED_SIGNALING; - } else if (q->have_wait_counts) { - *value = DSPQUEUE_SIGNALING_PERF_REDUCED_SIGNALING; - } else { - *value = 0; - } - break; - } - - default: - FARF(ERROR, "Unsupported statistic %d", (int)stat); - nErr = AEE_EBADPARM; - goto bail; - } +AEEResult +dspqueue_get_stat(dspqueue_t queue, enum dspqueue_stat stat, uint64_t *value) +{ + + AEEResult nErr = 0; + struct dspqueue *q = queue; + + if(q->mdq.is_mdq) + return dspqueue_multidomain_get_stat(q, stat, value); + + pthread_mutex_lock(&q->mutex); + + switch(stat) { + case DSPQUEUE_STAT_EARLY_WAKEUP_WAIT_TIME: + *value = q->early_wakeup_wait; + q->early_wakeup_wait = 0; + break; + + case DSPQUEUE_STAT_EARLY_WAKEUP_MISSES: + *value = q->early_wakeup_misses; + q->early_wakeup_misses = 0; + break; + + case DSPQUEUE_STAT_READ_QUEUE_PACKETS: { + struct dspqueue_packet_queue_header *pq + = &q->header->resp_queue; + struct dspqueue_packet_queue_state *write_state + = (struct dspqueue_packet_queue_state + *)(((uintptr_t)q->header) + pq->write_state_offset); + uint32_t c; + cache_invalidate_word(&write_state->packet_count); + c = write_state->packet_count - q->read_packet_count; + *value = c; + break; + } + + case DSPQUEUE_STAT_WRITE_QUEUE_PACKETS: { + struct dspqueue_packet_queue_header *pq + = &q->header->req_queue; + struct dspqueue_packet_queue_state *read_state + = (struct dspqueue_packet_queue_state + *)(((uintptr_t)q->header) + pq->read_state_offset); + uint32_t c; + cache_invalidate_word(&read_state->packet_count); + c = q->write_packet_count - read_state->packet_count; + *value = c; + break; + } + + case DSPQUEUE_STAT_READ_QUEUE_BYTES: { + struct dspqueue_packet_queue_header *pq + = &q->header->resp_queue; + uint32_t b; + get_queue_state_read(q->header, pq, &b, NULL, NULL); + *value = b; + break; + } + + case DSPQUEUE_STAT_WRITE_QUEUE_BYTES: { + struct dspqueue_packet_queue_header *pq + = &q->header->req_queue; + uint32_t b; + get_queue_state_write(q->header, pq, &b, NULL, NULL); + *value = pq->queue_length - b - 8; + break; + } + + case DSPQUEUE_STAT_SIGNALING_PERF: { + if(q->have_driver_signaling) { + *value = DSPQUEUE_SIGNALING_PERF_OPTIMIZED_SIGNALING; + } else if(q->have_wait_counts) { + *value = DSPQUEUE_SIGNALING_PERF_REDUCED_SIGNALING; + } else { + *value = 0; + } + break; + } + + default: + FARF(ERROR, "Unsupported statistic %d", (int)stat); + nErr = AEE_EBADPARM; + goto bail; + } bail: - pthread_mutex_unlock(&q->mutex); - return nErr; + pthread_mutex_unlock(&q->mutex); + return nErr; } struct error_callback_args { - struct dspqueue *queue; - AEEResult error; + struct dspqueue *queue; + AEEResult error; }; -static void *error_callback_thread(void *arg) { - struct error_callback_args *a = (struct error_callback_args *)arg; - assert(a->queue->error_callback); - FARF(ALWAYS, "%s starting for queue %p with id %u", __func__, a->queue, - a->queue->id); - a->queue->error_callback(a->queue, a->error, a->queue->callback_context); - free(a); - return NULL; +static void * +error_callback_thread(void *arg) +{ + struct error_callback_args *a = (struct error_callback_args *)arg; + assert(a->queue->error_callback); + FARF(ALWAYS, "%s starting for queue %p with id %u", __func__, a->queue, + a->queue->id); + a->queue->error_callback(a->queue, a->error, + a->queue->callback_context); + free(a); + return NULL; } // Make an error callback in a separate thread. We do this to ensure the queue // can be destroyed safely from the callback - all regular threads can exit // while the callback is in progres. This function won't return error codes; if // error reporting fails there isn't much we can do to report errors... -static void error_callback(struct dspqueue_domain_queues *dq, AEEResult error) { - - unsigned i; - - FARF(HIGH, "error_callback %d", (int)error); - - // Only report errors once per domain - if (dq->dsp_error != 0) { - return; - } - - if ((error == (AEEResult)0x8000040d) || (error == -1)) { - // Process died (probably) - error = AEE_ECONNRESET; - } - dq->dsp_error = error; - - // Send error callbacks to all queues attached to this domain - pthread_mutex_lock(&dq->queue_list_mutex); - for (i = 0; i <= dq->max_queue; i++) { - if ((dq->queues[i] != UNUSED_QUEUE) && (dq->queues[i] != INVALID_QUEUE)) { - struct dspqueue *q = dq->queues[i]; - // Cancel pending waits - if (q->have_driver_signaling) { - int s; - FARF(HIGH, "%s: Cancel all signal waits", __func__); - for (s = 0; s < DSPQUEUE_NUM_SIGNALS; s++) { - dspsignal_cancel_wait(q->domain, QUEUE_SIGNAL(q->id, s)); - } - } else { - pthread_mutex_lock(&q->packet_mutex); - q->packet_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_broadcast(&q->packet_cond); - pthread_mutex_unlock(&q->packet_mutex); - pthread_mutex_lock(&q->space_mutex); - q->space_mask |= SIGNAL_BIT_CANCEL; - pthread_cond_broadcast(&q->space_cond); - pthread_mutex_unlock(&q->space_mutex); - } - if (q->error_callback != NULL) { - struct error_callback_args *a; - pthread_attr_t tattr; - a = calloc(1, sizeof(*a)); - if (a != NULL) { - int err; - pthread_attr_init(&tattr); - pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_JOINABLE); - a->queue = q; - a->error = error; - err = pthread_create(&q->error_callback_thread, &tattr, - error_callback_thread, a); - if (err != 0) { - FARF(ERROR, "Error callback thread creation failed: %d", err); - free(a); - } - } else { - FARF(ERROR, "Out of memory"); - } - } - } - } - pthread_mutex_unlock(&dq->queue_list_mutex); +static void +error_callback(struct dspqueue_domain_queues *dq, AEEResult error) +{ + + unsigned i; + + FARF(HIGH, "error_callback %d", (int)error); + + // Only report errors once per domain + if(dq->dsp_error != 0) { + return; + } + + if((error == (AEEResult)0x8000040d) || (error == -1)) { + // Process died (probably) + error = AEE_ECONNRESET; + } + dq->dsp_error = error; + + // Send error callbacks to all queues attached to this domain + pthread_mutex_lock(&dq->queue_list_mutex); + for(i = 0; i <= dq->max_queue; i++) { + if((dq->queues[i] != UNUSED_QUEUE) + && (dq->queues[i] != INVALID_QUEUE)) { + struct dspqueue *q = dq->queues[i]; + // Cancel pending waits + if(q->have_driver_signaling) { + int s; + FARF(HIGH, "%s: Cancel all signal waits", + __func__); + for(s = 0; s < DSPQUEUE_NUM_SIGNALS; s++) { + dspsignal_cancel_wait( + q->domain, QUEUE_SIGNAL(q->id, s)); + } + } else { + pthread_mutex_lock(&q->packet_mutex); + q->packet_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_broadcast(&q->packet_cond); + pthread_mutex_unlock(&q->packet_mutex); + pthread_mutex_lock(&q->space_mutex); + q->space_mask |= SIGNAL_BIT_CANCEL; + pthread_cond_broadcast(&q->space_cond); + pthread_mutex_unlock(&q->space_mutex); + } + if(q->error_callback != NULL) { + struct error_callback_args *a; + pthread_attr_t tattr; + a = calloc(1, sizeof(*a)); + if(a != NULL) { + int err; + pthread_attr_init(&tattr); + pthread_attr_setdetachstate( + &tattr, PTHREAD_CREATE_JOINABLE); + a->queue = q; + a->error = error; + err = pthread_create( + &q->error_callback_thread, &tattr, + error_callback_thread, a); + if(err != 0) { + FARF(ERROR, + "Error callback thread " + "creation failed: %d", + err); + free(a); + } + } else { + FARF(ERROR, "Out of memory"); + } + } + } + } + pthread_mutex_unlock(&dq->queue_list_mutex); } -static void *dspqueue_send_signal_thread(void *arg) { - - struct dspqueue_domain_queues *dq = (struct dspqueue_domain_queues *)arg; - AEEResult nErr = 0; - - errno = 0; - while (1) { - pthread_mutex_lock(&dq->send_signal_mutex); - while (dq->send_signal_mask == 0) { - pthread_cond_wait(&dq->send_signal_cond, &dq->send_signal_mutex); - } - if (dq->send_signal_mask & SIGNAL_BIT_CANCEL) { - // Exit - pthread_mutex_unlock(&dq->send_signal_mutex); - return NULL; - } else if (dq->send_signal_mask & SIGNAL_BIT_SIGNAL) { - dq->send_signal_mask = dq->send_signal_mask & (~SIGNAL_BIT_SIGNAL); - pthread_mutex_unlock(&dq->send_signal_mutex); - FARF(LOW, "Send signal"); - VERIFY((nErr = dspqueue_rpc_signal(dq->dsp_handle)) == 0); - } - } +static void * +dspqueue_send_signal_thread(void *arg) +{ + + struct dspqueue_domain_queues *dq + = (struct dspqueue_domain_queues *)arg; + AEEResult nErr = 0; + + errno = 0; + while(1) { + pthread_mutex_lock(&dq->send_signal_mutex); + while(dq->send_signal_mask == 0) { + pthread_cond_wait(&dq->send_signal_cond, + &dq->send_signal_mutex); + } + if(dq->send_signal_mask & SIGNAL_BIT_CANCEL) { + // Exit + pthread_mutex_unlock(&dq->send_signal_mutex); + return NULL; + } else if(dq->send_signal_mask & SIGNAL_BIT_SIGNAL) { + dq->send_signal_mask + = dq->send_signal_mask & (~SIGNAL_BIT_SIGNAL); + pthread_mutex_unlock(&dq->send_signal_mutex); + FARF(LOW, "Send signal"); + VERIFY((nErr = dspqueue_rpc_signal(dq->dsp_handle)) + == 0); + } + } bail: - FARF(ERROR, "dspqueue_send_signal_thread failed with %d errno %s", nErr, - strerror(errno)); - error_callback(dq, nErr); - return (void *)(uintptr_t)nErr; + FARF(ERROR, "dspqueue_send_signal_thread failed with %d errno %s", + nErr, strerror(errno)); + error_callback(dq, nErr); + return (void *)(uintptr_t)nErr; } -static void *dspqueue_receive_signal_thread(void *arg) { - - struct dspqueue_domain_queues *dq = (struct dspqueue_domain_queues *)arg; - AEEResult nErr = 0; - unsigned i; - - errno = 0; - while (1) { - int32_t signal; - VERIFY((nErr = dspqueue_rpc_wait_signal(dq->dsp_handle, &signal)) == 0); - - if (signal == -1) { - // Exit - assert(dq->num_queues == 0); - return NULL; - } - - // Got a signal - at least one queue has more packets or space. Find out - // which one and signal it. - FARF(LOW, "Got signal"); - - // Ensure we have visibility into updates from the DSP - cache_invalidate(dq->state->req_space_count, - sizeof(dq->state->req_space_count)); - cache_invalidate(dq->state->resp_packet_count, - sizeof(dq->state->resp_packet_count)); - - pthread_mutex_lock(&dq->queue_list_mutex); - FARF(LOW, "Go through queues"); - for (i = 0; i <= dq->max_queue; i++) { - if ((dq->queues[i] != UNUSED_QUEUE) && (dq->queues[i] != INVALID_QUEUE)) { - struct dspqueue *q = dq->queues[i]; - assert(!q->have_driver_signaling); - pthread_mutex_lock(&q->packet_mutex); - if (q->resp_packet_count != dq->state->resp_packet_count[i]) { - q->resp_packet_count = dq->state->resp_packet_count[i]; - FARF(LOW, "Queue %u new resp_packet_count %u", i, - (unsigned)q->resp_packet_count); - pthread_cond_broadcast(&q->packet_cond); - } - pthread_mutex_unlock(&q->packet_mutex); - pthread_mutex_lock(&q->space_mutex); - if (q->req_space_count != dq->state->req_space_count[i]) { - q->req_space_count = dq->state->req_space_count[i]; - FARF(LOW, "Queue %u new req_space_count %u", i, - (unsigned)q->req_space_count); - pthread_cond_broadcast(&q->space_cond); - } - pthread_mutex_unlock(&q->space_mutex); - } - } - FARF(LOW, "Done"); - pthread_mutex_unlock(&dq->queue_list_mutex); - } +static void * +dspqueue_receive_signal_thread(void *arg) +{ + + struct dspqueue_domain_queues *dq + = (struct dspqueue_domain_queues *)arg; + AEEResult nErr = 0; + unsigned i; + + errno = 0; + while(1) { + int32_t signal; + VERIFY( + (nErr = dspqueue_rpc_wait_signal(dq->dsp_handle, &signal)) + == 0); + + if(signal == -1) { + // Exit + assert(dq->num_queues == 0); + return NULL; + } + + // Got a signal - at least one queue has more packets or space. + // Find out which one and signal it. + FARF(LOW, "Got signal"); + + // Ensure we have visibility into updates from the DSP + cache_invalidate(dq->state->req_space_count, + sizeof(dq->state->req_space_count)); + cache_invalidate(dq->state->resp_packet_count, + sizeof(dq->state->resp_packet_count)); + + pthread_mutex_lock(&dq->queue_list_mutex); + FARF(LOW, "Go through queues"); + for(i = 0; i <= dq->max_queue; i++) { + if((dq->queues[i] != UNUSED_QUEUE) + && (dq->queues[i] != INVALID_QUEUE)) { + struct dspqueue *q = dq->queues[i]; + assert(!q->have_driver_signaling); + pthread_mutex_lock(&q->packet_mutex); + if(q->resp_packet_count + != dq->state->resp_packet_count[i]) { + q->resp_packet_count + = dq->state->resp_packet_count[i]; + FARF(LOW, + "Queue %u new resp_packet_count " + "%u", + i, + (unsigned)q->resp_packet_count); + pthread_cond_broadcast( + &q->packet_cond); + } + pthread_mutex_unlock(&q->packet_mutex); + pthread_mutex_lock(&q->space_mutex); + if(q->req_space_count + != dq->state->req_space_count[i]) { + q->req_space_count + = dq->state->req_space_count[i]; + FARF(LOW, + "Queue %u new req_space_count %u", + i, (unsigned)q->req_space_count); + pthread_cond_broadcast(&q->space_cond); + } + pthread_mutex_unlock(&q->space_mutex); + } + } + FARF(LOW, "Done"); + pthread_mutex_unlock(&dq->queue_list_mutex); + } bail: - FARF(ERROR, "dspqueue_receive_signal_thread failed with %d errno %s", nErr, - strerror(errno)); - if (nErr == -1) { - // Process died (probably) - nErr = AEE_ECONNRESET; - } - error_callback(dq, nErr); - return (void *)(uintptr_t)nErr; + FARF(ERROR, "dspqueue_receive_signal_thread failed with %d errno %s", + nErr, strerror(errno)); + if(nErr == -1) { + // Process died (probably) + nErr = AEE_ECONNRESET; + } + error_callback(dq, nErr); + return (void *)(uintptr_t)nErr; } -static void *dspqueue_packet_callback_thread(void *arg) { - - struct dspqueue *q = (struct dspqueue *)arg; - struct dspqueue_packet_queue_header *pq = &q->header->resp_queue; - struct dspqueue_packet_queue_state *read_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + - pq->read_state_offset); - struct dspqueue_packet_queue_state *write_state = - (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + - pq->write_state_offset); - _Atomic uint32_t *wait_count = (_Atomic uint32_t *)&read_state->wait_count; - uint32_t packet_count = 0; - AEEResult nErr = AEE_SUCCESS; - - FARF(ALWAYS, "%s starting for queue %p", __func__, q); - while (1) { - pthread_mutex_lock(&q->packet_mutex); - - // Call the callback if we have any packets we haven't seen yet. - cache_invalidate_word(&write_state->packet_count); - if (packet_count != write_state->packet_count) { - packet_count = write_state->packet_count; - q->packet_callback(q, 0, q->callback_context); - } - - // Mark we're waiting and call again if we just got more packets - if (q->have_wait_counts) { - atomic_fetch_add(wait_count, 1); - cache_flush_word(wait_count); - } - cache_invalidate_word(&write_state->packet_count); - if (packet_count != write_state->packet_count) { - packet_count = write_state->packet_count; - q->packet_callback(q, 0, q->callback_context); - } - - // Wait for a signal - nErr = wait_signal_locked(q, DSPQUEUE_SIGNAL_RESP_PACKET, NULL); - if (nErr == AEE_EINTERRUPTED || nErr == AEE_EBADSTATE) { - FARF(HIGH, "Queue %u exit callback thread", (unsigned)q->id); - if (q->have_wait_counts) { - atomic_fetch_sub(wait_count, 1); - cache_flush_word(wait_count); - } - pthread_mutex_unlock(&q->packet_mutex); - goto bail; - } else if (nErr != AEE_SUCCESS) { - pthread_mutex_unlock(&q->packet_mutex); - FARF(ERROR, "Error: %s: wait_signal failed with 0x%x (queue %p)", - __func__, nErr, q); - return (void *)((intptr_t)nErr); - } - - // Mark we aren't waiting right now - if (q->have_wait_counts) { - atomic_fetch_sub(wait_count, 1); - cache_flush_word(wait_count); - } - - pthread_mutex_unlock(&q->packet_mutex); - } +static void * +dspqueue_packet_callback_thread(void *arg) +{ + + struct dspqueue *q = (struct dspqueue *)arg; + struct dspqueue_packet_queue_header *pq = &q->header->resp_queue; + struct dspqueue_packet_queue_state *read_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->read_state_offset); + struct dspqueue_packet_queue_state *write_state + = (struct dspqueue_packet_queue_state *)(((uintptr_t)q->header) + + pq->write_state_offset); + _Atomic uint32_t *wait_count + = (_Atomic uint32_t *)&read_state->wait_count; + uint32_t packet_count = 0; + AEEResult nErr = AEE_SUCCESS; + + FARF(ALWAYS, "%s starting for queue %p", __func__, q); + while(1) { + pthread_mutex_lock(&q->packet_mutex); + + // Call the callback if we have any packets we haven't seen + // yet. + cache_invalidate_word(&write_state->packet_count); + if(packet_count != write_state->packet_count) { + packet_count = write_state->packet_count; + q->packet_callback(q, 0, q->callback_context); + } + + // Mark we're waiting and call again if we just got more + // packets + if(q->have_wait_counts) { + atomic_fetch_add(wait_count, 1); + cache_flush_word(wait_count); + } + cache_invalidate_word(&write_state->packet_count); + if(packet_count != write_state->packet_count) { + packet_count = write_state->packet_count; + q->packet_callback(q, 0, q->callback_context); + } + + // Wait for a signal + nErr + = wait_signal_locked(q, DSPQUEUE_SIGNAL_RESP_PACKET, NULL); + if(nErr == AEE_EINTERRUPTED || nErr == AEE_EBADSTATE) { + FARF(HIGH, "Queue %u exit callback thread", + (unsigned)q->id); + if(q->have_wait_counts) { + atomic_fetch_sub(wait_count, 1); + cache_flush_word(wait_count); + } + pthread_mutex_unlock(&q->packet_mutex); + goto bail; + } else if(nErr != AEE_SUCCESS) { + pthread_mutex_unlock(&q->packet_mutex); + FARF(ERROR, + "Error: %s: wait_signal failed with 0x%x (queue " + "%p)", + __func__, nErr, q); + return (void *)((intptr_t)nErr); + } + + // Mark we aren't waiting right now + if(q->have_wait_counts) { + atomic_fetch_sub(wait_count, 1); + cache_flush_word(wait_count); + } + + pthread_mutex_unlock(&q->packet_mutex); + } bail: - FARF(ALWAYS, "%s exiting", __func__); - return NULL; + FARF(ALWAYS, "%s exiting", __func__); + return NULL; } -static int dspqueue_notif_callback(void *context, int domain, int session, - remote_rpc_status_flags_t status) { - int nErr = AEE_SUCCESS, effec_domain_id = domain; - - if (status == FASTRPC_USER_PD_UP) { - return 0; - } - // All other statuses are some kind of process exit or DSP crash. - assert(context == queues); - if (session && domain < NUM_DOMAINS) { - // Did not receive effective domain ID for extended session. Compute it. - effec_domain_id = GET_EFFECTIVE_DOMAIN_ID(domain, session); - } - FARF(ALWAYS, "%s for domain %d, session %d, status %u", __func__, domain, - session, status); - assert(IS_VALID_EFFECTIVE_DOMAIN_ID(effec_domain_id)); - - // Send different error codes for SSR and remote-process exit - nErr = (status == FASTRPC_DSP_SSR) ? AEE_ECONNRESET : AEE_ENOSUCH; - if (queues->domain_queues[effec_domain_id] != NULL) { - error_callback(queues->domain_queues[effec_domain_id], nErr); - } - return 0; +static int +dspqueue_notif_callback(void *context, int domain, int session, + remote_rpc_status_flags_t status) +{ + int nErr = AEE_SUCCESS, effec_domain_id = domain; + + if(status == FASTRPC_USER_PD_UP) { + return 0; + } + // All other statuses are some kind of process exit or DSP crash. + assert(context == queues); + if(session && domain < NUM_DOMAINS) { + // Did not receive effective domain ID for extended session. + // Compute it. + effec_domain_id = GET_EFFECTIVE_DOMAIN_ID(domain, session); + } + FARF(ALWAYS, "%s for domain %d, session %d, status %u", __func__, + domain, session, status); + assert(IS_VALID_EFFECTIVE_DOMAIN_ID(effec_domain_id)); + + // Send different error codes for SSR and remote-process exit + nErr = (status == FASTRPC_DSP_SSR) ? AEE_ECONNRESET : AEE_ENOSUCH; + if(queues->domain_queues[effec_domain_id] != NULL) { + error_callback(queues->domain_queues[effec_domain_id], nErr); + } + return 0; } diff --git a/src/dspqueue/dspqueue_rpc_stub.c b/src/dspqueue/dspqueue_rpc_stub.c index 9c84a16a..4772560e 100644 --- a/src/dspqueue/dspqueue_rpc_stub.c +++ b/src/dspqueue/dspqueue_rpc_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,159 +93,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _DSPQUEUE_RPC_SLIM_H #define _DSPQUEUE_RPC_SLIM_H @@ -434,131 +445,241 @@ struct Interface { #define __QAIC_SLIM_EXPORT #endif -static const Parameter parameters[8] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,3,0},{0x8,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x8,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0}}; -static const Parameter* const parameterArrays[9] = {(&(parameters[4])),(&(parameters[3])),(&(parameters[4])),(&(parameters[5])),(&(parameters[6])),(&(parameters[7])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[8] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[6])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[8])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x4,0x0,1,1,(&(parameterArrays[1])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0xc,0x8,4,4,(&(parameterArrays[0])),0x4,0x8},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,3,1,(&(parameterArrays[4])),0x8,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x1,0x0,0x0),0x8,0x4,4,2,(&(parameterArrays[4])),0x8,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x1,0x0,0x0),0x0,0x4,1,1,(&(parameterArrays[5])),0x1,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x0,0x0),0x0,0x0,0,0,0,0x0,0x0}}; -static const Method* const methodArrays[9] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[5]),&(methods[6]),&(methods[7]),&(methods[7])}; -static const char strings[136] = "cancel_wait_signal\0init_process_state\0process_state_fd\0destroy_queue\0create_queue\0is_imported\0queue_id\0queue_fd\0count\0close\0open\0uri\0h\0"; -static const uint16_t methodStrings[20] = {69,100,103,112,94,82,94,85,124,129,133,7,12,55,94,19,38,118,133,0}; -static const uint16_t methodStringsArrays[9] = {8,17,15,0,13,5,11,19,12}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(dspqueue_rpc_slim) = {9,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Parameter parameters[8] = { + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 3, 0 }, + { 0x8, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x8, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 } +}; +static const Parameter *const parameterArrays[9] + = { (&(parameters[4])), (&(parameters[3])), (&(parameters[4])), + (&(parameters[5])), (&(parameters[6])), (&(parameters[7])), + (&(parameters[0])), (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[8] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[6])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[8])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x4, 0x0, 1, 1, + (&(parameterArrays[1])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0xc, 0x8, 4, 4, + (&(parameterArrays[0])), 0x4, 0x8 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 3, 1, + (&(parameterArrays[4])), 0x8, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x1, 0x0, 0x0), 0x8, 0x4, 4, 2, + (&(parameterArrays[4])), 0x8, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x1, 0x0, 0x0), 0x0, 0x4, 1, 1, + (&(parameterArrays[5])), 0x1, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x0, 0x0), 0x0, 0x0, 0, 0, 0, + 0x0, 0x0 } }; +static const Method *const methodArrays[9] + = { &(methods[0]), &(methods[1]), &(methods[2]), + &(methods[3]), &(methods[4]), &(methods[5]), + &(methods[6]), &(methods[7]), &(methods[7]) }; +static const char strings[136] + = "cancel_wait_signal\0init_process_state\0process_state_fd\0destroy_" + "queue\0create_queue\0is_imported\0queue_id\0queue_" + "fd\0count\0close\0open\0uri\0h\0"; +static const uint16_t methodStrings[20] + = { 69, 100, 103, 112, 94, 82, 94, 85, 124, 129, + 133, 7, 12, 55, 94, 19, 38, 118, 133, 0 }; +static const uint16_t methodStringsArrays[9] + = { 8, 17, 15, 0, 13, 5, 11, 19, 12 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(dspqueue_rpc_slim) + = { 9, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_DSPQUEUE_RPC_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(dspqueue_rpc_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(dspqueue_rpc_open)(const char *uri, + remote_handle64 *h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(dspqueue_rpc_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(dspqueue_rpc_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_init_process_state)(remote_handle64 _handle, int32_t process_state_fd) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid, (uint32_t*)&process_state_fd); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_init_process_state)( + remote_handle64 _handle, int32_t process_state_fd) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid, (uint32_t *)&process_state_fd); } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1], uint32_t _in2[1], uint64_t _rout3[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint32_t _primIn[3]= {0}; - uint64_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _COPY(_primIn, 8, _in2, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _COPY(_rout3, 0, _primROut, 0, 8); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1], uint32_t _in2[1], uint64_t _rout3[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[3] = { 0 }; + uint64_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _COPY(_primIn, 8, _in2, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _COPY(_rout3, 0, _primROut, 0, 8); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_create_queue)(remote_handle64 _handle, uint32_t id, int32_t queue_fd, uint32_t count, uint64_t* queue_id) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method_1(_handle, _mid, (uint32_t*)&id, (uint32_t*)&queue_fd, (uint32_t*)&count, (uint64_t*)queue_id); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_create_queue)( + remote_handle64 _handle, uint32_t id, int32_t queue_fd, uint32_t count, + uint64_t *queue_id) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method_1(_handle, _mid, (uint32_t *)&id, + (uint32_t *)&queue_fd, (uint32_t *)&count, + (uint64_t *)queue_id); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid, uint64_t _in0[1]) { - remote_arg _pra[1] = {0}; - uint64_t _primIn[1]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 8); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid, uint64_t _in0[1]) +{ + remote_arg _pra[1] = { 0 }; + uint64_t _primIn[1] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 8); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_destroy_queue)(remote_handle64 _handle, uint64_t queue_id) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_2(_handle, _mid, (uint64_t*)&queue_id); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_destroy_queue)( + remote_handle64 _handle, uint64_t queue_id) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_2(_handle, _mid, (uint64_t *)&queue_id); } -static __inline int _stub_method_3(remote_handle64 _handle, uint32_t _mid, uint64_t _in0[1], uint32_t _rout1[1]) { - int _numIn[1] = {0}; - remote_arg _pra[2] = {0}; - uint64_t _primIn[1]= {0}; - uint32_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 8); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); - _COPY(_rout1, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_3(remote_handle64 _handle, uint32_t _mid, uint64_t _in0[1], + uint32_t _rout1[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[2] = { 0 }; + uint64_t _primIn[1] = { 0 }; + uint32_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 8); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 1, 0, 0), _pra)); + _COPY(_rout1, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_is_imported)(remote_handle64 _handle, uint64_t queue_id, int32_t* imported) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - return _stub_method_3(_handle, _mid, (uint64_t*)&queue_id, (uint32_t*)imported); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_is_imported)(remote_handle64 _handle, + uint64_t queue_id, + int32_t *imported) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + return _stub_method_3(_handle, _mid, (uint64_t *)&queue_id, + (uint32_t *)imported); } -static __inline int _stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _rout0[1]) { - int _numIn[1] = {0}; - remote_arg _pra[1] = {0}; - uint32_t _primROut[1]= {0}; - int _nErr = 0; - _numIn[0] = 0; - _pra[(_numIn[0] + 0)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); - _COPY(_rout0, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_4(remote_handle64 _handle, uint32_t _mid, uint32_t _rout0[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[1] = { 0 }; + uint32_t _primROut[1] = { 0 }; + int _nErr = 0; + _numIn[0] = 0; + _pra[(_numIn[0] + 0)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 0)].buf.nLen = sizeof(_primROut); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 1, 0, 0), _pra)); + _COPY(_rout0, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_wait_signal)(remote_handle64 _handle, int32_t* signal) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 6; - return _stub_method_4(_handle, _mid, (uint32_t*)signal); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_wait_signal)(remote_handle64 _handle, + int32_t *signal) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 6; + return _stub_method_4(_handle, _mid, (uint32_t *)signal); } -static __inline int _stub_method_5(remote_handle64 _handle, uint32_t _mid) { - remote_arg* _pra = 0; - int _nErr = 0; - _TRY(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_5(remote_handle64 _handle, uint32_t _mid) +{ + remote_arg *_pra = 0; + int _nErr = 0; + _TRY(_nErr, + __QAIC_REMOTE(remote_handle64_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 0, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_cancel_wait_signal)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 7; - return _stub_method_5(_handle, _mid); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_cancel_wait_signal)(remote_handle64 _handle) + __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 7; + return _stub_method_5(_handle, _mid); } -__QAIC_STUB_EXPORT AEEResult __QAIC_STUB(dspqueue_rpc_signal)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 8; - return _stub_method_5(_handle, _mid); +__QAIC_STUB_EXPORT AEEResult +__QAIC_STUB(dspqueue_rpc_signal)(remote_handle64 _handle) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 8; + return _stub_method_5(_handle, _mid); } #ifdef __cplusplus } diff --git a/src/dsprpcd.c b/src/dsprpcd.c index b3d01f8e..6e33057e 100644 --- a/src/dsprpcd.c +++ b/src/dsprpcd.c @@ -8,12 +8,12 @@ #include "AEEStdErr.h" #include "HAP_farf.h" -#include "verify.h" #include "fastrpc_common.h" +#include "verify.h" #include #include -#include #include +#include #ifndef ADSP_DEFAULT_LISTENER_NAME #define ADSP_DEFAULT_LISTENER_NAME "libadsp_default_listener.so" @@ -30,54 +30,63 @@ typedef int (*dsp_default_listener_start_t)(int argc, char *argv[]); -int main(int argc, char *argv[]) { - int nErr = 0; - void *dsphandler = NULL; - const char* lib_name; - const char* dsp_name; - dsp_default_listener_start_t listener_start; +int +main(int argc, char *argv[]) +{ + int nErr = 0; + void *dsphandler = NULL; + const char *lib_name; + const char *dsp_name; + dsp_default_listener_start_t listener_start; + +#ifdef USE_ADSP + lib_name = ADSP_DEFAULT_LISTENER_NAME; + dsp_name = "ADSP"; +#elif defined(USE_SDSP) + lib_name = SDSP_DEFAULT_LISTENER_NAME; + dsp_name = "SDSP"; +#elif defined(USE_CDSP) + lib_name = CDSP_DEFAULT_LISTENER_NAME; + dsp_name = "CDSP"; +#elif defined(USE_GDSP) + lib_name = GDSP_DEFAULT_LISTENER_NAME; + dsp_name = "GDSP"; +#else + goto bail; +#endif + VERIFY_EPRINTF("%s daemon starting", dsp_name); - #ifdef USE_ADSP - lib_name = ADSP_DEFAULT_LISTENER_NAME; - dsp_name = "ADSP"; - #elif defined(USE_SDSP) - lib_name = SDSP_DEFAULT_LISTENER_NAME; - dsp_name = "SDSP"; - #elif defined(USE_CDSP) - lib_name = CDSP_DEFAULT_LISTENER_NAME; - dsp_name = "CDSP"; - #elif defined(USE_GDSP) - lib_name = GDSP_DEFAULT_LISTENER_NAME; - dsp_name = "GDSP"; - #else - goto bail; - #endif - VERIFY_EPRINTF("%s daemon starting", dsp_name); - - while (1) { - if (NULL != (dsphandler = dlopen(lib_name,RTLD_NOW))) { - if (NULL != (listener_start = (dsp_default_listener_start_t)dlsym( - dsphandler, "adsp_default_listener_start"))) { - VERIFY_IPRINTF("adsp_default_listener_start called"); - nErr = listener_start(argc, argv); - } - if (0 != dlclose(dsphandler)) { - VERIFY_EPRINTF("dlclose failed for %s", lib_name); - } - } else { - VERIFY_EPRINTF("%s daemon error %s", dsp_name, dlerror()); - } + while(1) { + if(NULL != (dsphandler = dlopen(lib_name, RTLD_NOW))) { + if(NULL + != (listener_start = (dsp_default_listener_start_t) + dlsym(dsphandler, + "adsp_default_listener_start"))) { + VERIFY_IPRINTF( + "adsp_default_listener_start called"); + nErr = listener_start(argc, argv); + } + if(0 != dlclose(dsphandler)) { + VERIFY_EPRINTF("dlclose failed for %s", + lib_name); + } + } else { + VERIFY_EPRINTF("%s daemon error %s", dsp_name, + dlerror()); + } - if (nErr == AEE_ECONNREFUSED) { - VERIFY_EPRINTF("fastRPC device is not accessible, daemon exiting..."); - break; - } + if(nErr == AEE_ECONNREFUSED) { + VERIFY_EPRINTF("fastRPC device is not accessible, " + "daemon exiting..."); + break; + } - VERIFY_EPRINTF("%s daemon will restart after 100ms...", dsp_name); - usleep(100000); - } + VERIFY_EPRINTF("%s daemon will restart after 100ms...", + dsp_name); + usleep(100000); + } - bail: - VERIFY_EPRINTF("daemon exiting %x", nErr); - return nErr; +bail: + VERIFY_EPRINTF("daemon exiting %x", nErr); + return nErr; } diff --git a/src/dspsignal.c b/src/dspsignal.c index 01c1c1c7..07367344 100644 --- a/src/dspsignal.c +++ b/src/dspsignal.c @@ -8,29 +8,28 @@ #define FARF_HIGH 0 #define FARF_MEDIUM 0 -#include #include #include #include +#include #include - +#include "AEEStdErr.h" +#include "HAP_farf.h" #include "dspsignal.h" #include "fastrpc_common.h" #include "fastrpc_internal.h" #include "remote.h" #include "verify.h" -#include "AEEStdErr.h" -#include "HAP_farf.h" struct dspsignal_domain_signals { - int domain; - int dev; + int domain; + int dev; }; struct dspsignal_process_signals { - struct dspsignal_domain_signal *domain_signals[NUM_DOMAINS_EXTEND]; - pthread_mutex_t mutex; + struct dspsignal_domain_signal *domain_signals[NUM_DOMAINS_EXTEND]; + pthread_mutex_t mutex; }; static struct dspsignal_process_signals *signals; @@ -38,235 +37,281 @@ static pthread_once_t signals_once = PTHREAD_ONCE_INIT; // Initialize process static signal structure. This should realistically never // fail. -static void init_process_signals_once(void) { - - signals = calloc(1, sizeof(*signals)); - if (signals == NULL) { - FARF(ERROR, "Out of memory"); - return; - } - if (pthread_mutex_init(&signals->mutex, NULL) != 0) { - FARF(ERROR, "Mutex init failed"); - free(signals); - signals = NULL; - return; - } +static void +init_process_signals_once(void) +{ + + signals = calloc(1, sizeof(*signals)); + if(signals == NULL) { + FARF(ERROR, "Out of memory"); + return; + } + if(pthread_mutex_init(&signals->mutex, NULL) != 0) { + FARF(ERROR, "Mutex init failed"); + free(signals); + signals = NULL; + return; + } } -void deinit_process_signals() { - if (signals) { - pthread_mutex_destroy(&signals->mutex); - free(signals); - signals = NULL; - } +void +deinit_process_signals() +{ + if(signals) { + pthread_mutex_destroy(&signals->mutex); + free(signals); + signals = NULL; + } } // Dynamically initialize process signals structure. -static AEEResult init_domain_signals(int domain) { +static AEEResult +init_domain_signals(int domain) +{ - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; - VERIFY(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); + VERIFY(IS_VALID_EFFECTIVE_DOMAIN_ID(domain)); - // Initialize process-level structure - if ((pthread_once(&signals_once, init_process_signals_once) != 0) || - (signals == NULL)) { - FARF(ERROR, "dspsignal init failed"); - return AEE_ERPC; - } + // Initialize process-level structure + if((pthread_once(&signals_once, init_process_signals_once) != 0) + || (signals == NULL)) { + FARF(ERROR, "dspsignal init failed"); + return AEE_ERPC; + } - pthread_mutex_lock(&signals->mutex); - if (signals->domain_signals[domain] != NULL) { - // Already initialized - goto bail; - } + pthread_mutex_lock(&signals->mutex); + if(signals->domain_signals[domain] != NULL) { + // Already initialized + goto bail; + } - VERIFYC((ds = calloc(1, sizeof(*ds))) != NULL, AEE_ENOMEMORY); - ds->domain = domain; + VERIFYC((ds = calloc(1, sizeof(*ds))) != NULL, AEE_ENOMEMORY); + ds->domain = domain; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &ds->dev))); - VERIFYC(-1 != ds->dev, AEE_ERPC); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &ds->dev))); + VERIFYC(-1 != ds->dev, AEE_ERPC); - signals->domain_signals[domain] = (struct dspsignal_domain_signal *)ds; + signals->domain_signals[domain] = (struct dspsignal_domain_signal *)ds; bail: - pthread_mutex_unlock(&signals->mutex); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, __func__, - domain, strerror(errno)); - } - return nErr; + pthread_mutex_unlock(&signals->mutex); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed (domain %d) errno %s", nErr, + __func__, domain, strerror(errno)); + } + return nErr; } -static int get_domain(int domain) { - if (domain == -1) { - domain = get_current_domain(); - } - return domain; +static int +get_domain(int domain) +{ + if(domain == -1) { + domain = get_current_domain(); + } + return domain; } -void dspsignal_domain_deinit(int domain) { - AEEResult nErr = AEE_SUCCESS; - - if (!signals) - return; - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - pthread_mutex_lock(&signals->mutex); - if (signals->domain_signals[domain]) { - free(signals->domain_signals[domain]); - signals->domain_signals[domain] = NULL; - } - pthread_mutex_unlock(&signals->mutex); - FARF(ALWAYS, "%s done for domain %d", __func__, domain); +void +dspsignal_domain_deinit(int domain) +{ + AEEResult nErr = AEE_SUCCESS; + + if(!signals) + return; + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + pthread_mutex_lock(&signals->mutex); + if(signals->domain_signals[domain]) { + free(signals->domain_signals[domain]); + signals->domain_signals[domain] = NULL; + } + pthread_mutex_unlock(&signals->mutex); + FARF(ALWAYS, "%s done for domain %d", __func__, domain); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d)", nErr, __func__, domain); - } - return; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed (domain %d)", nErr, + __func__, domain); + } + return; } -AEEResult dspsignal_create(int domain, uint32_t id, uint32_t flags) { - - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; - - VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); - domain = get_domain(domain); - VERIFYC(flags == 0, AEE_EBADPARM); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFY((nErr = init_domain_signals(domain)) == 0); - VERIFYC((ds = (struct dspsignal_domain_signals *)signals->domain_signals[domain]) != NULL, AEE_EBADSTATE); - errno = 0; - nErr = ioctl_signal_create(ds->dev, id, flags); - if (nErr) { - if (errno == ENOTTY) { - FARF(HIGH, "dspsignal support not present in the FastRPC driver"); - nErr = AEE_EUNSUPPORTED; - } else { - nErr = convert_kernel_to_user_error(nErr, errno); - } - goto bail; - } - FARF(HIGH, "%s: Signal %u created", __func__, id); +AEEResult +dspsignal_create(int domain, uint32_t id, uint32_t flags) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; + + VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); + domain = get_domain(domain); + VERIFYC(flags == 0, AEE_EBADPARM); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFY((nErr = init_domain_signals(domain)) == 0); + VERIFYC((ds = (struct dspsignal_domain_signals *) + signals->domain_signals[domain]) + != NULL, + AEE_EBADSTATE); + errno = 0; + nErr = ioctl_signal_create(ds->dev, id, flags); + if(nErr) { + if(errno == ENOTTY) { + FARF(HIGH, "dspsignal support not present in the " + "FastRPC driver"); + nErr = AEE_EUNSUPPORTED; + } else { + nErr = convert_kernel_to_user_error(nErr, errno); + } + goto bail; + } + FARF(HIGH, "%s: Signal %u created", __func__, id); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, ID %u, flags 0x%x) errno %s", - nErr, __func__, domain, id, flags, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, ID %u, flags 0x%x) " + "errno %s", + nErr, __func__, domain, id, flags, strerror(errno)); + } + return nErr; } -AEEResult dspsignal_destroy(int domain, uint32_t id) { - - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; - - VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); - domain = get_domain(domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC((ds = (struct dspsignal_domain_signals *)signals->domain_signals[domain]) != NULL, AEE_EBADSTATE); - errno = 0; - nErr = ioctl_signal_destroy(ds->dev, id); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } - FARF(HIGH, "%s: Signal %u destroyed", __func__, id); +AEEResult +dspsignal_destroy(int domain, uint32_t id) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; + + VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); + domain = get_domain(domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC((ds = (struct dspsignal_domain_signals *) + signals->domain_signals[domain]) + != NULL, + AEE_EBADSTATE); + errno = 0; + nErr = ioctl_signal_destroy(ds->dev, id); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } + FARF(HIGH, "%s: Signal %u destroyed", __func__, id); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, - __func__, domain, id, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, + __func__, domain, id, strerror(errno)); + } + return nErr; } -AEEResult dspsignal_signal(int domain, uint32_t id) { - - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; - - VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); - domain = get_domain(domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC((ds = (struct dspsignal_domain_signals *)signals->domain_signals[domain]) != NULL, AEE_EBADSTATE); - - FARF(MEDIUM, "%s: Send signal %u", __func__, id); - errno = 0; - nErr = ioctl_signal_signal(ds->dev, id); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } +AEEResult +dspsignal_signal(int domain, uint32_t id) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; + + VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); + domain = get_domain(domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC((ds = (struct dspsignal_domain_signals *) + signals->domain_signals[domain]) + != NULL, + AEE_EBADSTATE); + + FARF(MEDIUM, "%s: Send signal %u", __func__, id); + errno = 0; + nErr = ioctl_signal_signal(ds->dev, id); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, - __func__, domain, id, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, + __func__, domain, id, strerror(errno)); + } + return nErr; } -AEEResult dspsignal_wait(int domain, uint32_t id, uint32_t timeout_usec) { - - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; - - VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); - domain = get_domain(domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC((ds = (struct dspsignal_domain_signals *)signals->domain_signals[domain]) != NULL, AEE_EBADSTATE); - fastrpc_qos_activity(domain); - - FARF(MEDIUM, "%s: Wait signal %u timeout %u", __func__, id, timeout_usec); - errno = 0; - nErr = ioctl_signal_wait(ds->dev, id, timeout_usec); - if (nErr) { - if (errno == ETIMEDOUT) { - FARF(MEDIUM, "%s: Signal %u timed out", __func__, id); - return AEE_EEXPIRED; - } else if (errno == EINTR) { - FARF(MEDIUM, "%s: Signal %u canceled", __func__, id); - return AEE_EINTERRUPTED; - } else { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } - } +AEEResult +dspsignal_wait(int domain, uint32_t id, uint32_t timeout_usec) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; + + VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); + domain = get_domain(domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC((ds = (struct dspsignal_domain_signals *) + signals->domain_signals[domain]) + != NULL, + AEE_EBADSTATE); + fastrpc_qos_activity(domain); + + FARF(MEDIUM, "%s: Wait signal %u timeout %u", __func__, id, + timeout_usec); + errno = 0; + nErr = ioctl_signal_wait(ds->dev, id, timeout_usec); + if(nErr) { + if(errno == ETIMEDOUT) { + FARF(MEDIUM, "%s: Signal %u timed out", __func__, id); + return AEE_EEXPIRED; + } else if(errno == EINTR) { + FARF(MEDIUM, "%s: Signal %u canceled", __func__, id); + return AEE_EINTERRUPTED; + } else { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, ID %u, timeout %u) errno %s", - nErr, __func__, domain, id, timeout_usec, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, ID %u, timeout %u) " + "errno %s", + nErr, __func__, domain, id, timeout_usec, + strerror(errno)); + } + return nErr; } -AEEResult dspsignal_cancel_wait(int domain, uint32_t id) { - - AEEResult nErr = AEE_SUCCESS; - struct dspsignal_domain_signals *ds = NULL; - - VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); - domain = get_domain(domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC((ds = (struct dspsignal_domain_signals *)signals->domain_signals[domain]) != NULL, AEE_EBADSTATE); - - FARF(MEDIUM, "%s: Cancel wait signal %u", __func__, id); - errno = 0; - nErr = ioctl_signal_cancel_wait(ds->dev, id); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } +AEEResult +dspsignal_cancel_wait(int domain, uint32_t id) +{ + + AEEResult nErr = AEE_SUCCESS; + struct dspsignal_domain_signals *ds = NULL; + + VERIFYC(id < DSPSIGNAL_NUM_SIGNALS, AEE_EBADPARM); + domain = get_domain(domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC((ds = (struct dspsignal_domain_signals *) + signals->domain_signals[domain]) + != NULL, + AEE_EBADSTATE); + + FARF(MEDIUM, "%s: Cancel wait signal %u", __func__, id); + errno = 0; + nErr = ioctl_signal_cancel_wait(ds->dev, id); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, - __func__, domain, id, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed (domain %d, ID %u) errno %s", nErr, + __func__, domain, id, strerror(errno)); + } + return nErr; } diff --git a/src/fastrpc_apps_user.c b/src/fastrpc_apps_user.c index 81fef0ab..81422143 100644 --- a/src/fastrpc_apps_user.c +++ b/src/fastrpc_apps_user.c @@ -1,12 +1,12 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause -//#ifndef VERIFY_PRINT_ERROR -//#define VERIFY_PRINT_ERROR -//#endif // VERIFY_PRINT_ERROR -//#ifndef VERIFY_PRINT_INFO -//#define VERIFY_PRINT_INFO -//#endif // VERIFY_PRINT_INFO +// #ifndef VERIFY_PRINT_ERROR +// #define VERIFY_PRINT_ERROR +// #endif // VERIFY_PRINT_ERROR +// #ifndef VERIFY_PRINT_INFO +// #define VERIFY_PRINT_INFO +// #endif // VERIFY_PRINT_INFO #define _GNU_SOURCE #ifndef VERIFY_PRINT_WARN #define VERIFY_PRINT_WARN @@ -56,6 +56,7 @@ #include "fastrpc_cap.h" #include "fastrpc_common.h" #include "fastrpc_config.h" +#include "fastrpc_context.h" #include "fastrpc_internal.h" #include "fastrpc_latency.h" #include "fastrpc_log.h" @@ -64,6 +65,8 @@ #include "fastrpc_perf.h" #include "fastrpc_pm.h" #include "fastrpc_procbuf.h" +#include "fastrpc_process_attributes.h" +#include "fastrpc_trace.h" #include "listener_android.h" #include "log_config.h" #include "platform_libs.h" @@ -72,9 +75,6 @@ #include "rpcmem_internal.h" #include "shared.h" #include "verify.h" -#include "fastrpc_context.h" -#include "fastrpc_process_attributes.h" -#include "fastrpc_trace.h" #ifndef ENABLE_UPSTREAM_DRIVER_INTERFACE #define DSP_MOUNT_LOCATION "/dsp/" @@ -87,9 +87,9 @@ #define VENDOR_DOM_LOCATION "/vendor/dsp/xdsp/" #ifdef LE_ENABLE -#define PROPERTY_VALUE_MAX \ - 92 // as this macro is defined in cutils for Android platforms, defined - // explicitly for LE platform +#define PROPERTY_VALUE_MAX \ + 92 // as this macro is defined in cutils for Android platforms, defined + // explicitly for LE platform #elif (defined _ANDROID) || (defined ANDROID) /// TODO: Bharath #include "cutils/properties.h" #define PROPERTY_VALUE_MAX 92 @@ -118,10 +118,10 @@ #define FASTRPC_TRACE_INVOKE_START "fastrpc_trace_invoke_start" #define FASTRPC_TRACE_INVOKE_END "fastrpc_trace_invoke_end" -#define FASTRPC_TRACE_LOG(k, handle, sc) \ - if (fastrpc_trace == 1 && !IS_STATIC_HANDLE(handle)) { \ - FARF(ALWAYS, "%s: sc 0x%x", (k), (sc)); \ - } +#define FASTRPC_TRACE_LOG(k, handle, sc) \ + if(fastrpc_trace == 1 && !IS_STATIC_HANDLE(handle)) { \ + FARF(ALWAYS, "%s: sc 0x%x", (k), (sc)); \ + } /* Number of dsp library instances allowed per process. */ #define MAX_LIB_INSTANCE_ALLOWED 1 @@ -130,64 +130,70 @@ static void check_multilib_util(void); /* Array to store fastrpc library names. */ -static const char *fastrpc_library[NUM_DOMAINS] = { - "libadsprpc.so", "libmdsprpc.so", "libsdsprpc.so", "libcdsprpc.so", "libcdsprpc.so", "libcdsprpc.so", "libcdsprpc.so"}; +static const char *fastrpc_library[NUM_DOMAINS] + = { "libadsprpc.so", "libmdsprpc.so", "libsdsprpc.so", "libcdsprpc.so", + "libcdsprpc.so", "libcdsprpc.so", "libcdsprpc.so" }; /* Array to store env variable names. */ static char *fastrpc_dsp_lib_refcnt[NUM_DOMAINS]; static int total_dsp_lib_refcnt = 0; /* Function to free the memory allocated for env variable names */ -inline static void deinit_fastrpc_dsp_lib_refcnt(void) { - int ii = 0; - - FOR_EACH_DOMAIN_ID(ii) { - if (fastrpc_dsp_lib_refcnt[ii]) { - unsetenv(fastrpc_dsp_lib_refcnt[ii]); - free(fastrpc_dsp_lib_refcnt[ii]); - fastrpc_dsp_lib_refcnt[ii] = NULL; - } - } +inline static void +deinit_fastrpc_dsp_lib_refcnt(void) +{ + int ii = 0; + + FOR_EACH_DOMAIN_ID(ii) + { + if(fastrpc_dsp_lib_refcnt[ii]) { + unsetenv(fastrpc_dsp_lib_refcnt[ii]); + free(fastrpc_dsp_lib_refcnt[ii]); + fastrpc_dsp_lib_refcnt[ii] = NULL; + } + } } enum fastrpc_proc_attr { - FASTRPC_MODE_DEBUG = 0x1, - FASTRPC_MODE_PTRACE = 0x2, - FASTRPC_MODE_CRC = 0x4, - FASTRPC_MODE_UNSIGNED_MODULE = 0x8, - FASTRPC_MODE_ADAPTIVE_QOS = 0x10, - FASTRPC_MODE_SYSTEM_PROCESS = 0x20, - FASTRPC_MODE_PRIVILEGED = 0x40, // this attribute will be populated in kernel - // Attribute to enable pd dump feature for both signed/unsigned pd - FASTRPC_MODE_ENABLE_PDDUMP = 0x80, - // System attribute to enable pd dump debug data collection on rooted devices - FASTRPC_MODE_DEBUG_PDDUMP = 0x100, - // Attribute to enable kernel perf keys data collection - FASTRPC_MODE_PERF_KERNEL = 0x200, - // Attribute to enable dsp perf keys data collection - FASTRPC_MODE_PERF_DSP = 0x400, - // Attribute to log iregion buffer - FASTRPC_MODE_ENABLE_IREGION_LOG = 0x800, - // Attribute to enable QTF tracing on DSP - FASTRPC_MODE_ENABLE_QTF_TRACING = 0x1000, - // Attribute to enable debug logging - FASTRPC_MODE_ENABLE_DEBUG_LOGGING = 0x2000, - // Attribute to set caller level for heap - FASTRPC_MODE_CALLER_LEVEL_MASK = 0xE000, - // Attribute to enable uaf for heap - FASTRPC_MODE_ENABLE_UAF = 0x10000, - // Attribute to launch system unsignedPD on CDSP - FASTRPC_MODE_SYSTEM_UNSIGNED_PD = 0x20000, - // Reserved attribute bit for sys mon application - FASTRPC_MODE_SYSMON_RESERVED_BIT = 0x40000000, - // Attribute to enable log packet - FASTRPC_MODE_LOG_PACKET = 0x40000, - // Attribute to set Leak detect for heap. Bits 19-20 are reserved for leak - // detect. - FASTRPC_MODE_ENABLE_LEAK_DETECT = 0x180000, - // Attribute to change caller stack for heap. Bits 21-23 are reserved the call - // stack num - FASTRPC_MODE_CALLER_STACK_NUM = 0xE00000, + FASTRPC_MODE_DEBUG = 0x1, + FASTRPC_MODE_PTRACE = 0x2, + FASTRPC_MODE_CRC = 0x4, + FASTRPC_MODE_UNSIGNED_MODULE = 0x8, + FASTRPC_MODE_ADAPTIVE_QOS = 0x10, + FASTRPC_MODE_SYSTEM_PROCESS = 0x20, + FASTRPC_MODE_PRIVILEGED + = 0x40, // this attribute will be populated in kernel + // Attribute to enable pd dump feature for both signed/unsigned pd + FASTRPC_MODE_ENABLE_PDDUMP = 0x80, + // System attribute to enable pd dump debug data collection on rooted + // devices + FASTRPC_MODE_DEBUG_PDDUMP = 0x100, + // Attribute to enable kernel perf keys data collection + FASTRPC_MODE_PERF_KERNEL = 0x200, + // Attribute to enable dsp perf keys data collection + FASTRPC_MODE_PERF_DSP = 0x400, + // Attribute to log iregion buffer + FASTRPC_MODE_ENABLE_IREGION_LOG = 0x800, + // Attribute to enable QTF tracing on DSP + FASTRPC_MODE_ENABLE_QTF_TRACING = 0x1000, + // Attribute to enable debug logging + FASTRPC_MODE_ENABLE_DEBUG_LOGGING = 0x2000, + // Attribute to set caller level for heap + FASTRPC_MODE_CALLER_LEVEL_MASK = 0xE000, + // Attribute to enable uaf for heap + FASTRPC_MODE_ENABLE_UAF = 0x10000, + // Attribute to launch system unsignedPD on CDSP + FASTRPC_MODE_SYSTEM_UNSIGNED_PD = 0x20000, + // Reserved attribute bit for sys mon application + FASTRPC_MODE_SYSMON_RESERVED_BIT = 0x40000000, + // Attribute to enable log packet + FASTRPC_MODE_LOG_PACKET = 0x40000, + // Attribute to set Leak detect for heap. Bits 19-20 are reserved for + // leak detect. + FASTRPC_MODE_ENABLE_LEAK_DETECT = 0x180000, + // Attribute to change caller stack for heap. Bits 21-23 are reserved + // the call stack num + FASTRPC_MODE_CALLER_STACK_NUM = 0xE00000, }; #define M_CRCLIST (64) @@ -195,14 +201,14 @@ enum fastrpc_proc_attr { #define IS_CRC_CHECK_ENABLED(var) (var & FASTRPC_MODE_CRC) extern int perf_v2_kernel; extern int perf_v2_dsp; -#define IS_KERNEL_PERF_ENABLED(var) \ - ((var & FASTRPC_MODE_PERF_KERNEL) && perf_v2_kernel) +#define IS_KERNEL_PERF_ENABLED(var) \ + ((var & FASTRPC_MODE_PERF_KERNEL) && perf_v2_kernel) #define IS_DSP_PERF_ENABLED(var) ((var & FASTRPC_MODE_PERF_DSP) && perf_v2_dsp) #define IS_QTF_TRACING_ENABLED(var) (var & FASTRPC_MODE_ENABLE_QTF_TRACING) -#define POLY32 \ - 0x04C11DB7 // G(x) = x^32+x^26+x^23+x^22+x^16+x^12 - // +x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1 +#define POLY32 \ + 0x04C11DB7 // G(x) = x^32+x^26+x^23+x^22+x^16+x^12 + // +x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1 #define DEFAULT_UTHREAD_PRIORITY 0xC0 #define DEFAULT_UTHREAD_STACK_SIZE 16 * 1024 @@ -223,89 +229,91 @@ extern int perf_v2_dsp; #define PM_TIMEOUT_MS 5 enum handle_list_id { - MULTI_DOMAIN_HANDLE_LIST_ID = 1, - NON_DOMAIN_HANDLE_LIST_ID = 2, - REVERSE_HANDLE_LIST_ID = 3, + MULTI_DOMAIN_HANDLE_LIST_ID = 1, + NON_DOMAIN_HANDLE_LIST_ID = 2, + REVERSE_HANDLE_LIST_ID = 3, }; -const char *ENV_DEBUG_VAR_NAME[] = {"FASTRPC_PROCESS_ATTRS", - "FASTRPC_DEBUG_TRACE", - "FASTRPC_DEBUG_TESTSIG", - "FASTRPC_PERF_KERNEL", - "FASTRPC_PERF_ADSP", - "FASTRPC_PERF_FREQ", - "FASTRPC_DEBUG_SYSTRACE", - "FASTRPC_DEBUG_PDDUMP", - "FASTRPC_PROCESS_ATTRS_PERSISTENT", - "ro.debuggable"}; -const char *ANDROIDP_DEBUG_VAR_NAME[] = {"vendor.fastrpc.process.attrs", - "vendor.fastrpc.debug.trace", - "vendor.fastrpc.debug.testsig", - "vendor.fastrpc.perf.kernel", - "vendor.fastrpc.perf.adsp", - "vendor.fastrpc.perf.freq", - "vendor.fastrpc.debug.systrace", - "vendor.fastrpc.debug.pddump", - "persist.vendor.fastrpc.process.attrs", - "ro.build.type"}; -const char *ANDROID_DEBUG_VAR_NAME[] = {"fastrpc.process.attrs", - "fastrpc.debug.trace", - "fastrpc.debug.testsig", - "fastrpc.perf.kernel", - "fastrpc.perf.adsp", - "fastrpc.perf.freq", - "fastrpc.debug.systrace", - "fastrpc.debug.pddump", - "persist.fastrpc.process.attrs", - "ro.build.type"}; - -const char *SUBSYSTEM_NAME[] = {"adsp", "mdsp", "sdsp", "cdsp", "cdsp1", "gdsp0", "gdsp1", "reserved"}; +const char *ENV_DEBUG_VAR_NAME[] = { "FASTRPC_PROCESS_ATTRS", + "FASTRPC_DEBUG_TRACE", + "FASTRPC_DEBUG_TESTSIG", + "FASTRPC_PERF_KERNEL", + "FASTRPC_PERF_ADSP", + "FASTRPC_PERF_FREQ", + "FASTRPC_DEBUG_SYSTRACE", + "FASTRPC_DEBUG_PDDUMP", + "FASTRPC_PROCESS_ATTRS_PERSISTENT", + "ro.debuggable" }; +const char *ANDROIDP_DEBUG_VAR_NAME[] + = { "vendor.fastrpc.process.attrs", + "vendor.fastrpc.debug.trace", + "vendor.fastrpc.debug.testsig", + "vendor.fastrpc.perf.kernel", + "vendor.fastrpc.perf.adsp", + "vendor.fastrpc.perf.freq", + "vendor.fastrpc.debug.systrace", + "vendor.fastrpc.debug.pddump", + "persist.vendor.fastrpc.process.attrs", + "ro.build.type" }; +const char *ANDROID_DEBUG_VAR_NAME[] = { "fastrpc.process.attrs", + "fastrpc.debug.trace", + "fastrpc.debug.testsig", + "fastrpc.perf.kernel", + "fastrpc.perf.adsp", + "fastrpc.perf.freq", + "fastrpc.debug.systrace", + "fastrpc.debug.pddump", + "persist.fastrpc.process.attrs", + "ro.build.type" }; + +const char *SUBSYSTEM_NAME[] = { "adsp", "mdsp", "sdsp", "cdsp", + "cdsp1", "gdsp0", "gdsp1", "reserved" }; /* Strings for trace event logging */ #define INVOKE_BEGIN_TRACE_STR "fastrpc_msg: userspace_call: begin" #define INVOKE_END_TRACE_STR "fastrpc_msg: userspace_call: end" -static const size_t invoke_begin_trace_strlen = - sizeof(INVOKE_BEGIN_TRACE_STR) - 1; +static const size_t invoke_begin_trace_strlen + = sizeof(INVOKE_BEGIN_TRACE_STR) - 1; static const size_t invoke_end_trace_strlen = sizeof(INVOKE_END_TRACE_STR) - 1; -int NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS = - sizeof(ENV_DEBUG_VAR_NAME) / sizeof(char *); -int NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS = - sizeof(ANDROIDP_DEBUG_VAR_NAME) / sizeof(char *); -int NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS = - sizeof(ANDROID_DEBUG_VAR_NAME) / sizeof(char *); +int NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS + = sizeof(ENV_DEBUG_VAR_NAME) / sizeof(char *); +int NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS + = sizeof(ANDROIDP_DEBUG_VAR_NAME) / sizeof(char *); +int NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS + = sizeof(ANDROID_DEBUG_VAR_NAME) / sizeof(char *); /* Shell prefix for signed and unsigned */ const char *const SIGNED_SHELL = "fastrpc_shell_"; const char *const UNSIGNED_SHELL = "fastrpc_shell_unsigned_"; struct handle_info { - QNode qn; - struct handle_list *hlist; - remote_handle64 local; - remote_handle64 remote; - char *name; + QNode qn; + struct handle_list *hlist; + remote_handle64 local; + remote_handle64 remote; + char *name; }; // Fastrpc client notification request node to be queued to struct fastrpc_notif { - QNode qn; - remote_rpc_notif_register_t notif; + QNode qn; + remote_rpc_notif_register_t notif; }; struct other_handle_list { // For non-domain and reverse handle list - QList ql; + QList ql; }; // Fastrpc timer function for RPC timeout typedef struct fastrpc_timer_info { - timer_t timer; - uint64_t timeout_millis; - int domain; - int sc; - int handle; - pid_t tid; + timer_t timer; + uint64_t timeout_millis; + int domain; + int sc; + int handle; + pid_t tid; } fastrpc_timer; // Macro to check if a remote session is already open on given domain @@ -321,7 +329,7 @@ static pthread_key_t tlsKey = INVALID_KEY; // Flag to check if there is any client notification request static bool fastrpc_notif_flag = false; static int fastrpc_trace = 0; -static uint32_t fastrpc_wake_lock_enable[NUM_DOMAINS_EXTEND] = {0}; +static uint32_t fastrpc_wake_lock_enable[NUM_DOMAINS_EXTEND] = { 0 }; static int domain_init(int domain, int *dev); static void domain_deinit(int domain); @@ -332,236 +340,284 @@ extern void apps_mem_table_deinit(void); static uint32_t crc_table[256]; static atomic_bool timer_expired = false; -void set_thread_context(int domain) { - if (tlsKey != INVALID_KEY) { - pthread_setspecific(tlsKey, (void *)&hlist[domain]); - } +void +set_thread_context(int domain) +{ + if(tlsKey != INVALID_KEY) { + pthread_setspecific(tlsKey, (void *)&hlist[domain]); + } } -int get_device_fd(int domain) { - if (hlist && (hlist[domain].dev != -1)) { - return hlist[domain].dev; - } else { - return -1; - } +int +get_device_fd(int domain) +{ + if(hlist && (hlist[domain].dev != -1)) { + return hlist[domain].dev; + } else { + return -1; + } } -int fastrpc_session_open(int domain, int *dev) { - int device = -1; +int +fastrpc_session_open(int domain, int *dev) +{ + int device = -1; - if (IS_SESSION_OPEN_ALREADY(domain)) { - *dev = hlist[domain].dev; - return 0; - } + if(IS_SESSION_OPEN_ALREADY(domain)) { + *dev = hlist[domain].dev; + return 0; + } - device = open_device_node(domain); - if (device >= 0) { - *dev = device; - return 0; - } - return AEE_ECONNREFUSED; + device = open_device_node(domain); + if(device >= 0) { + *dev = device; + return 0; + } + return AEE_ECONNREFUSED; } -void fastrpc_session_close(int domain, int dev) { - if (!hlist) - return; - if ((hlist[domain].dev == INVALID_DEVICE) && - (dev != INVALID_DEVICE)) { - close(dev); - } else if ((hlist[domain].dev != INVALID_DEVICE) && - (dev == INVALID_DEVICE)) { - close(hlist[domain].dev); - hlist[domain].dev = INVALID_DEVICE; - } - return; +void +fastrpc_session_close(int domain, int dev) +{ + if(!hlist) + return; + if((hlist[domain].dev == INVALID_DEVICE) && (dev != INVALID_DEVICE)) { + close(dev); + } else if((hlist[domain].dev != INVALID_DEVICE) + && (dev == INVALID_DEVICE)) { + close(hlist[domain].dev); + hlist[domain].dev = INVALID_DEVICE; + } + return; } -int fastrpc_session_get(int domain) { - int ref = -1; - do { - if (hlist) { - pthread_mutex_lock(&hlist[domain].mut); - if (hlist[domain].state == FASTRPC_DOMAIN_STATE_DEINIT) { - pthread_mutex_unlock(&hlist[domain].mut); - return AEE_ENOTINITIALIZED; - } - hlist[domain].ref++; - ref = hlist[domain].ref; - pthread_mutex_unlock(&hlist[domain].mut); - set_thread_context(domain); - FARF(RUNTIME_RPC_HIGH, "%s, domain %d, state %d, ref %d\n", __func__, domain, - hlist[domain].state, ref); - } else { - return AEE_ENOTINITIALIZED; - } - } while (0); - return 0; +int +fastrpc_session_get(int domain) +{ + int ref = -1; + do { + if(hlist) { + pthread_mutex_lock(&hlist[domain].mut); + if(hlist[domain].state + == FASTRPC_DOMAIN_STATE_DEINIT) { + pthread_mutex_unlock(&hlist[domain].mut); + return AEE_ENOTINITIALIZED; + } + hlist[domain].ref++; + ref = hlist[domain].ref; + pthread_mutex_unlock(&hlist[domain].mut); + set_thread_context(domain); + FARF(RUNTIME_RPC_HIGH, + "%s, domain %d, state %d, ref %d\n", __func__, + domain, hlist[domain].state, ref); + } else { + return AEE_ENOTINITIALIZED; + } + } while(0); + return 0; } -int fastrpc_session_put(int domain) { - int ref = -1; - do { - if (hlist) { - pthread_mutex_lock(&hlist[domain].mut); - hlist[domain].ref--; - ref = hlist[domain].ref; - pthread_mutex_unlock(&hlist[domain].mut); - FARF(RUNTIME_RPC_HIGH, "%s, domain %d, state %d, ref %d\n", __func__, domain, - hlist[domain].state, ref); - } else { - return AEE_ENOTINITIALIZED; - } - } while (0); - return ref; +int +fastrpc_session_put(int domain) +{ + int ref = -1; + do { + if(hlist) { + pthread_mutex_lock(&hlist[domain].mut); + hlist[domain].ref--; + ref = hlist[domain].ref; + pthread_mutex_unlock(&hlist[domain].mut); + FARF(RUNTIME_RPC_HIGH, + "%s, domain %d, state %d, ref %d\n", __func__, + domain, hlist[domain].state, ref); + } else { + return AEE_ENOTINITIALIZED; + } + } while(0); + return ref; } -int fastrpc_session_dev(int domain, int *dev) { - *dev = INVALID_DEVICE; - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) - return AEE_ENOTINITIALIZED; - do { - if (hlist) { - pthread_mutex_lock(&hlist[domain].mut); - if (hlist[domain].state == FASTRPC_DOMAIN_STATE_DEINIT) { - pthread_mutex_unlock(&hlist[domain].mut); - return AEE_ENOTINITIALIZED; - } - if (hlist[domain].dev < 0) { - pthread_mutex_unlock(&hlist[domain].mut); - return AEE_ENOTINITIALIZED; - } else { - *dev = hlist[domain].dev; - pthread_mutex_unlock(&hlist[domain].mut); - return AEE_SUCCESS; - } - pthread_mutex_unlock(&hlist[domain].mut); - } else { - return AEE_ENOTINITIALIZED; - } - } while (0); - return AEE_ENOTINITIALIZED; +int +fastrpc_session_dev(int domain, int *dev) +{ + *dev = INVALID_DEVICE; + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) + return AEE_ENOTINITIALIZED; + do { + if(hlist) { + pthread_mutex_lock(&hlist[domain].mut); + if(hlist[domain].state + == FASTRPC_DOMAIN_STATE_DEINIT) { + pthread_mutex_unlock(&hlist[domain].mut); + return AEE_ENOTINITIALIZED; + } + if(hlist[domain].dev < 0) { + pthread_mutex_unlock(&hlist[domain].mut); + return AEE_ENOTINITIALIZED; + } else { + *dev = hlist[domain].dev; + pthread_mutex_unlock(&hlist[domain].mut); + return AEE_SUCCESS; + } + pthread_mutex_unlock(&hlist[domain].mut); + } else { + return AEE_ENOTINITIALIZED; + } + } while(0); + return AEE_ENOTINITIALIZED; } -int check_rpc_error(int err) { - if (check_error_code_change_present() == 1) { - if (err > KERNEL_ERRNO_START && err <= HLOS_ERR_END) // driver or HLOS err - return 0; - else if (err > (int)DSP_AEE_EOFFSET && - err <= (int)DSP_AEE_EOFFSET + 1024) // DSP err - return 0; - else if (err == AEE_ENOSUCH || - err == AEE_EINTERRUPTED) // common DSP HLOS err - return 0; - else - return -1; - } else - return 0; +int +check_rpc_error(int err) +{ + if(check_error_code_change_present() == 1) { + if(err > KERNEL_ERRNO_START + && err <= HLOS_ERR_END) // driver or HLOS err + return 0; + else if(err > (int)DSP_AEE_EOFFSET + && err <= (int)DSP_AEE_EOFFSET + 1024) // DSP err + return 0; + else if(err == AEE_ENOSUCH + || err == AEE_EINTERRUPTED) // common DSP HLOS err + return 0; + else + return -1; + } else + return 0; } -static void GenCrc32Tab(uint32_t GenPoly, uint32_t *crctab) { - uint32_t crc; - int i, j; - - for (i = 0; i < 256; i++) { - crc = i << 24; - for (j = 0; j < 8; j++) { - crc = (crc << 1) ^ (crc & 0x80000000 ? GenPoly : 0); - } - crctab[i] = crc; - } +static void +GenCrc32Tab(uint32_t GenPoly, uint32_t *crctab) +{ + uint32_t crc; + int i, j; + + for(i = 0; i < 256; i++) { + crc = i << 24; + for(j = 0; j < 8; j++) { + crc = (crc << 1) ^ (crc & 0x80000000 ? GenPoly : 0); + } + crctab[i] = crc; + } +} + +static uint32_t +crc32_lut(unsigned char *data, int nbyte, uint32_t *crctab) +{ + uint32_t crc = 0; + if(!data || !crctab) + return 0; + + while(nbyte--) { + crc = (crc << 8) ^ crctab[(crc >> 24) ^ *data++]; + } + return crc; } -static uint32_t crc32_lut(unsigned char *data, int nbyte, uint32_t *crctab) { - uint32_t crc = 0; - if (!data || !crctab) - return 0; +int +property_get_int32(const char *name, int value) +{ + return 0; +} - while (nbyte--) { - crc = (crc << 8) ^ crctab[(crc >> 24) ^ *data++]; - } - return crc; +int +property_get(const char *name, int *def, int *value) +{ + return 0; } -int property_get_int32(const char *name, int value) { return 0; } - -int property_get(const char *name, int *def, int *value) { return 0; } - -int fastrpc_get_property_int(fastrpc_properties UserPropKey, int defValue) { - if (((int)UserPropKey > NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF(ERROR, - "%s: Index %d out-of-bound for ENV_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return defValue; - } - const char *env = getenv(ENV_DEBUG_VAR_NAME[UserPropKey]); - if (env != 0) - return (int)atoi(env); -#if !defined(LE_ENABLE) // Android platform +int +fastrpc_get_property_int(fastrpc_properties UserPropKey, int defValue) +{ + if(((int)UserPropKey > NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ENV_DEBUG_VAR_NAME array " + "of len %d", + __func__, UserPropKey, + NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return defValue; + } + const char *env = getenv(ENV_DEBUG_VAR_NAME[UserPropKey]); + if(env != 0) + return (int)atoi(env); +#if !defined(LE_ENABLE) // Android platform #if !defined(SYSTEM_RPC_LIBRARY) // vendor library - if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF( - ERROR, - "%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return defValue; - } - return (int)property_get_int32(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], - defValue); + if(((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME " + "array of len %d", + __func__, UserPropKey, + NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return defValue; + } + return (int)property_get_int32(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], + defValue); #else // system library - if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF(ERROR, - "%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return defValue; - } - return (int)property_get_int32(ANDROID_DEBUG_VAR_NAME[UserPropKey], defValue); + if(((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME " + "array of len %d", + __func__, UserPropKey, + NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return defValue; + } + return (int)property_get_int32(ANDROID_DEBUG_VAR_NAME[UserPropKey], + defValue); #endif #else // non-Android platforms - return defValue; + return defValue; #endif } -int fastrpc_get_property_string(fastrpc_properties UserPropKey, char *value, - char *defValue) { - int len = 0; - if (((int)UserPropKey > NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF(ERROR, - "%s: Index %d out-of-bound for ENV_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return len; - } - char *env = getenv(ENV_DEBUG_VAR_NAME[UserPropKey]); - if (env != 0) { - strncpy(value, env, PROPERTY_VALUE_MAX - 1); - value[PROPERTY_VALUE_MAX - 1] = '\0'; - return strlen(env); - } -#if !defined(LE_ENABLE) // Android platform +int +fastrpc_get_property_string(fastrpc_properties UserPropKey, char *value, + char *defValue) +{ + int len = 0; + if(((int)UserPropKey > NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ENV_DEBUG_VAR_NAME array " + "of len %d", + __func__, UserPropKey, + NO_ENV_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return len; + } + char *env = getenv(ENV_DEBUG_VAR_NAME[UserPropKey]); + if(env != 0) { + strncpy(value, env, PROPERTY_VALUE_MAX - 1); + value[PROPERTY_VALUE_MAX - 1] = '\0'; + return strlen(env); + } +#if !defined(LE_ENABLE) // Android platform #if !defined(SYSTEM_RPC_LIBRARY) // vendor library - if (((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF( - ERROR, - "%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return len; - } - return property_get(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], (int *)value, - (int *)defValue); + if(((int)UserPropKey > NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ANDROIDP_DEBUG_VAR_NAME " + "array of len %d", + __func__, UserPropKey, + NO_ANDROIDP_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return len; + } + return property_get(ANDROIDP_DEBUG_VAR_NAME[UserPropKey], (int *)value, + (int *)defValue); #else // system library - if (((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { - FARF(ERROR, - "%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME array of len %d", - __func__, UserPropKey, NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS); - return len; - } - return property_get(ANDROID_DEBUG_VAR_NAME[UserPropKey], value, defValue); + if(((int)UserPropKey > NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS)) { + FARF(ERROR, + "%s: Index %d out-of-bound for ANDROID_DEBUG_VAR_NAME " + "array of len %d", + __func__, UserPropKey, + NO_ANDROID_DEBUG_VAR_NAME_ARRAY_ELEMENTS); + return len; + } + return property_get(ANDROID_DEBUG_VAR_NAME[UserPropKey], value, + defValue); #endif #else // non-Android platforms - if (defValue != NULL) { - strncpy(value, defValue, PROPERTY_VALUE_MAX - 1); - value[PROPERTY_VALUE_MAX - 1] = '\0'; - return strlen(defValue); - } - return len; + if(defValue != NULL) { + strncpy(value, defValue, PROPERTY_VALUE_MAX - 1); + value[PROPERTY_VALUE_MAX - 1] = '\0'; + return strlen(defValue); + } + return len; #endif } @@ -577,163 +633,199 @@ int fastrpc_get_property_string(fastrpc_properties UserPropKey, char *value, 0 - otherwise */ -static inline int is_first_reverse_rpc_call(int domain, remote_handle handle, - uint32_t sc) { - int ret = 0; - - if (IS_REVERSE_RPC_CALL(handle, sc) && IS_SESSION_OPEN_ALREADY(domain)) { - if (hlist[domain].first_revrpc_done) - ret = 0; - else { - hlist[domain].first_revrpc_done = 1; - ret = 1; - } - } - return ret; +static inline int +is_first_reverse_rpc_call(int domain, remote_handle handle, uint32_t sc) +{ + int ret = 0; + + if(IS_REVERSE_RPC_CALL(handle, sc) + && IS_SESSION_OPEN_ALREADY(domain)) { + if(hlist[domain].first_revrpc_done) + ret = 0; + else { + hlist[domain].first_revrpc_done = 1; + ret = 1; + } + } + return ret; } -static inline void trace_marker_init(int domain) { - const char TRACE_MARKER_FILE[] = "/sys/kernel/tracing/trace_marker"; - - if (IS_QTF_TRACING_ENABLED(hlist[domain].procattrs)) { - hlist[domain].trace_marker_fd = open(TRACE_MARKER_FILE, O_WRONLY); - ; - if (hlist[domain].trace_marker_fd < 0) { - FARF(ERROR, "Error: %s: failed to open '%s' for domain %d, errno %d (%s)", - __func__, TRACE_MARKER_FILE, domain, errno, strerror(errno)); - } - } +static inline void +trace_marker_init(int domain) +{ + const char TRACE_MARKER_FILE[] = "/sys/kernel/tracing/trace_marker"; + + if(IS_QTF_TRACING_ENABLED(hlist[domain].procattrs)) { + hlist[domain].trace_marker_fd + = open(TRACE_MARKER_FILE, O_WRONLY); + ; + if(hlist[domain].trace_marker_fd < 0) { + FARF(ERROR, + "Error: %s: failed to open '%s' for domain %d, " + "errno %d (%s)", + __func__, TRACE_MARKER_FILE, domain, errno, + strerror(errno)); + } + } } -static inline void trace_marker_deinit(int domain) { - if (hlist[domain].trace_marker_fd > 0) { - close(hlist[domain].trace_marker_fd); - hlist[domain].trace_marker_fd = -1; - } +static inline void +trace_marker_deinit(int domain) +{ + if(hlist[domain].trace_marker_fd > 0) { + close(hlist[domain].trace_marker_fd); + hlist[domain].trace_marker_fd = -1; + } } -int get_logger_state(int domain) { - int ret = AEE_EFAILED; +int +get_logger_state(int domain) +{ + int ret = AEE_EFAILED; - if (hlist && hlist[domain].disable_exit_logs) { - ret = AEE_SUCCESS; - } - return ret; + if(hlist && hlist[domain].disable_exit_logs) { + ret = AEE_SUCCESS; + } + return ret; } /* Thread function that will be invoked to update remote user PD parameters */ -int fastrpc_set_remote_uthread_params(int domain) { - int nErr = AEE_SUCCESS, paramsLen = 2; - remote_handle64 handle = INVALID_HANDLE; - struct fastrpc_thread_params *th_params = &hlist[domain].th_params; - - VERIFYC(th_params != NULL, AEE_ERPC); - if ((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { - nErr = remotectl1_set_param(handle, th_params->reqID, (uint32_t *)th_params, - paramsLen); - if (nErr) { - FARF(ALWAYS, - "Warning 0x%x: %s: remotectl1 domains not supported for domain %d\n", - nErr, __func__, domain); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, - _const_remotectl1_handle, NULL, NULL); - - // Set remotectlhandle to INVALID_HANDLE, so that all subsequent calls are - // non-domain calls - hlist[domain].remotectlhandle = INVALID_HANDLE; - VERIFY(AEE_SUCCESS == - (nErr = remotectl_set_param(th_params->reqID, - (uint32_t *)th_params, paramsLen))); - } - } else { - VERIFY(AEE_SUCCESS == - (nErr = remotectl_set_param(th_params->reqID, (uint32_t *)th_params, - paramsLen))); - } +int +fastrpc_set_remote_uthread_params(int domain) +{ + int nErr = AEE_SUCCESS, paramsLen = 2; + remote_handle64 handle = INVALID_HANDLE; + struct fastrpc_thread_params *th_params = &hlist[domain].th_params; + + VERIFYC(th_params != NULL, AEE_ERPC); + if((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { + nErr = remotectl1_set_param(handle, th_params->reqID, + (uint32_t *)th_params, paramsLen); + if(nErr) { + FARF(ALWAYS, + "Warning 0x%x: %s: remotectl1 domains not " + "supported for domain %d\n", + nErr, __func__, domain); + fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, + _const_remotectl1_handle, + NULL, NULL); + + // Set remotectlhandle to INVALID_HANDLE, so that all + // subsequent calls are non-domain calls + hlist[domain].remotectlhandle = INVALID_HANDLE; + VERIFY(AEE_SUCCESS + == (nErr = remotectl_set_param( + th_params->reqID, (uint32_t *)th_params, + paramsLen))); + } + } else { + VERIFY(AEE_SUCCESS + == (nErr = remotectl_set_param(th_params->reqID, + (uint32_t *)th_params, + paramsLen))); + } bail: - if (nErr != AEE_SUCCESS) { - if (th_params) { - FARF(ERROR, - "Error 0x%x: %s failed domain %d thread priority %d stack size %d " - "(errno %s)", - nErr, __func__, domain, th_params->thread_priority, - th_params->stack_size, strerror(errno)); - } else { - FARF(ERROR, "Error 0x%x: %s failed", nErr, __func__); - } - } else { - FARF(ALWAYS, - "Successfully set remote user thread priority to %d and stack size to " - "%d for domain %d", - th_params->thread_priority, th_params->stack_size, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + if(th_params) { + FARF(ERROR, + "Error 0x%x: %s failed domain %d thread priority " + "%d stack size %d " + "(errno %s)", + nErr, __func__, domain, + th_params->thread_priority, th_params->stack_size, + strerror(errno)); + } else { + FARF(ERROR, "Error 0x%x: %s failed", nErr, __func__); + } + } else { + FARF(ALWAYS, + "Successfully set remote user thread priority to %d and " + "stack size to " + "%d for domain %d", + th_params->thread_priority, th_params->stack_size, + domain); + } + return nErr; } -static inline bool is_valid_local_handle(int domain, struct handle_info *hinfo) { - QNode *pn; - int ii = 0; - if(domain == -1) { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - pthread_mutex_lock(&hlist[ii].lmut); - QLIST_FOR_ALL(&hlist[ii].ql, pn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - if (hi == hinfo) { - pthread_mutex_unlock(&hlist[ii].lmut); - return true; - } - } - pthread_mutex_unlock(&hlist[ii].lmut); - } - } else { - pthread_mutex_lock(&hlist[domain].lmut); - QLIST_FOR_ALL(&hlist[domain].ql, pn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - if (hi == hinfo) { - pthread_mutex_unlock(&hlist[domain].lmut); - return true; - } - } - pthread_mutex_unlock(&hlist[domain].lmut); - } - return false; +static inline bool +is_valid_local_handle(int domain, struct handle_info *hinfo) +{ + QNode *pn; + int ii = 0; + if(domain == -1) { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + pthread_mutex_lock(&hlist[ii].lmut); + QLIST_FOR_ALL(&hlist[ii].ql, pn) + { + struct handle_info *hi = STD_RECOVER_REC( + struct handle_info, qn, pn); + if(hi == hinfo) { + pthread_mutex_unlock(&hlist[ii].lmut); + return true; + } + } + pthread_mutex_unlock(&hlist[ii].lmut); + } + } else { + pthread_mutex_lock(&hlist[domain].lmut); + QLIST_FOR_ALL(&hlist[domain].ql, pn) + { + struct handle_info *hi + = STD_RECOVER_REC(struct handle_info, qn, pn); + if(hi == hinfo) { + pthread_mutex_unlock(&hlist[domain].lmut); + return true; + } + } + pthread_mutex_unlock(&hlist[domain].lmut); + } + return false; } -static int verify_local_handle(int domain, remote_handle64 local) { - struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; - int nErr = AEE_SUCCESS; +static int +verify_local_handle(int domain, remote_handle64 local) +{ + struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; + int nErr = AEE_SUCCESS; - VERIFYC((local != (remote_handle64)-1) && hinfo, AEE_EINVHANDLE); - VERIFYC(is_valid_local_handle(domain, hinfo), AEE_EINVHANDLE); - VERIFYC((hinfo->hlist >= &hlist[0]) && - (hinfo->hlist < &hlist[NUM_DOMAINS_EXTEND]), - AEE_ERPC); - VERIFYC(QNode_IsQueuedZ(&hinfo->qn), AEE_EINVHANDLE); + VERIFYC((local != (remote_handle64)-1) && hinfo, AEE_EINVHANDLE); + VERIFYC(is_valid_local_handle(domain, hinfo), AEE_EINVHANDLE); + VERIFYC((hinfo->hlist >= &hlist[0]) + && (hinfo->hlist < &hlist[NUM_DOMAINS_EXTEND]), + AEE_ERPC); + VERIFYC(QNode_IsQueuedZ(&hinfo->qn), AEE_EINVHANDLE); bail: - if (nErr != AEE_SUCCESS) { - FARF(RUNTIME_RPC_HIGH, "Error 0x%x: %s failed. handle 0x%" PRIx64 "\n", - nErr, __func__, local); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(RUNTIME_RPC_HIGH, + "Error 0x%x: %s failed. handle 0x%" PRIx64 "\n", nErr, + __func__, local); + } + return nErr; } -int get_domain_from_handle(remote_handle64 local, int *domain) { - struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; - int dom, nErr = AEE_SUCCESS; - - VERIFY(AEE_SUCCESS == (nErr = verify_local_handle(-1, local))); - dom = (int)(hinfo->hlist - &hlist[0]); - VERIFYM(IS_VALID_EFFECTIVE_DOMAIN_ID(dom), AEE_EINVHANDLE, - "Error 0x%x: domain mapped to handle is out of range domain %d " - "handle 0x%" PRIx64 "\n", - nErr, dom, local); - *domain = dom; +int +get_domain_from_handle(remote_handle64 local, int *domain) +{ + struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; + int dom, nErr = AEE_SUCCESS; + + VERIFY(AEE_SUCCESS == (nErr = verify_local_handle(-1, local))); + dom = (int)(hinfo->hlist - &hlist[0]); + VERIFYM( + IS_VALID_EFFECTIVE_DOMAIN_ID(dom), AEE_EINVHANDLE, + "Error 0x%x: domain mapped to handle is out of range domain %d " + "handle 0x%" PRIx64 "\n", + nErr, dom, local); + *domain = dom; bail: - if (nErr != AEE_SUCCESS) { - FARF(RUNTIME_RPC_HIGH, "Error 0x%x: %s failed. handle 0x%" PRIx64 "\n", - nErr, __func__, local); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(RUNTIME_RPC_HIGH, + "Error 0x%x: %s failed. handle 0x%" PRIx64 "\n", nErr, + __func__, local); + } + return nErr; } /** @@ -742,94 +834,106 @@ int get_domain_from_handle(remote_handle64 local, int *domain) { * @param[int]: Domain name length * @return : Domain ID */ -static int get_domain_from_domain_name(const char *domain_name, - int domain_name_len) { - int domain = INVALID_DOMAIN_ID; - - if (domain_name_len < strlen(SUBSYSTEM_NAME[ADSP_DOMAIN_ID])) { - FARF(ERROR, "ERROR: %s Invalid domain name length: %u\n", __func__, - domain_name_len); - goto bail; - } - if (domain_name) { - if (!strncmp(domain_name, SUBSYSTEM_NAME[ADSP_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[ADSP_DOMAIN_ID]))) { - domain = ADSP_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[MDSP_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[MDSP_DOMAIN_ID]))) { - domain = MDSP_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[SDSP_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[SDSP_DOMAIN_ID]))) { - domain = SDSP_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[CDSP1_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[CDSP1_DOMAIN_ID]))) { - domain = CDSP1_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[CDSP_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[CDSP_DOMAIN_ID]))) { - domain = CDSP_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[GDSP0_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[GDSP0_DOMAIN_ID]))) { - domain = GDSP0_DOMAIN_ID; - } else if (!strncmp(domain_name, SUBSYSTEM_NAME[GDSP1_DOMAIN_ID], - strlen(SUBSYSTEM_NAME[GDSP1_DOMAIN_ID]))) { - domain = GDSP1_DOMAIN_ID; - } else { - FARF(ERROR, "ERROR: %s Invalid domain name: %s\n", __func__, domain_name); - } - } - VERIFY_IPRINTF("%s: %d\n", __func__, domain); +static int +get_domain_from_domain_name(const char *domain_name, int domain_name_len) +{ + int domain = INVALID_DOMAIN_ID; + + if(domain_name_len < strlen(SUBSYSTEM_NAME[ADSP_DOMAIN_ID])) { + FARF(ERROR, "ERROR: %s Invalid domain name length: %u\n", + __func__, domain_name_len); + goto bail; + } + if(domain_name) { + if(!strncmp(domain_name, SUBSYSTEM_NAME[ADSP_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[ADSP_DOMAIN_ID]))) { + domain = ADSP_DOMAIN_ID; + } else if(!strncmp(domain_name, SUBSYSTEM_NAME[MDSP_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[MDSP_DOMAIN_ID]))) { + domain = MDSP_DOMAIN_ID; + } else if(!strncmp(domain_name, SUBSYSTEM_NAME[SDSP_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[SDSP_DOMAIN_ID]))) { + domain = SDSP_DOMAIN_ID; + } else if(!strncmp(domain_name, + SUBSYSTEM_NAME[CDSP1_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[CDSP1_DOMAIN_ID]))) { + domain = CDSP1_DOMAIN_ID; + } else if(!strncmp(domain_name, SUBSYSTEM_NAME[CDSP_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[CDSP_DOMAIN_ID]))) { + domain = CDSP_DOMAIN_ID; + } else if(!strncmp(domain_name, + SUBSYSTEM_NAME[GDSP0_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[GDSP0_DOMAIN_ID]))) { + domain = GDSP0_DOMAIN_ID; + } else if(!strncmp(domain_name, + SUBSYSTEM_NAME[GDSP1_DOMAIN_ID], + strlen(SUBSYSTEM_NAME[GDSP1_DOMAIN_ID]))) { + domain = GDSP1_DOMAIN_ID; + } else { + FARF(ERROR, "ERROR: %s Invalid domain name: %s\n", + __func__, domain_name); + } + } + VERIFY_IPRINTF("%s: %d\n", __func__, domain); bail: - return domain; + return domain; } -static const char *get_domain_from_id(int domain_id) { - const char *uri_domain_suffix; - switch (domain_id) { - case ADSP_DOMAIN_ID: - uri_domain_suffix = ADSP_DOMAIN; - break; - case CDSP_DOMAIN_ID: - uri_domain_suffix = CDSP_DOMAIN; - break; - case CDSP1_DOMAIN_ID: - uri_domain_suffix = CDSP1_DOMAIN; - break; - case MDSP_DOMAIN_ID: - uri_domain_suffix = MDSP_DOMAIN; - break; - case SDSP_DOMAIN_ID: - uri_domain_suffix = SDSP_DOMAIN; - break; - case GDSP0_DOMAIN_ID: - uri_domain_suffix = GDSP0_DOMAIN; - break; - case GDSP1_DOMAIN_ID: - uri_domain_suffix = GDSP1_DOMAIN; - break; - default: - uri_domain_suffix = "invalid domain"; - break; - } - return uri_domain_suffix; +static const char * +get_domain_from_id(int domain_id) +{ + const char *uri_domain_suffix; + switch(domain_id) { + case ADSP_DOMAIN_ID: + uri_domain_suffix = ADSP_DOMAIN; + break; + case CDSP_DOMAIN_ID: + uri_domain_suffix = CDSP_DOMAIN; + break; + case CDSP1_DOMAIN_ID: + uri_domain_suffix = CDSP1_DOMAIN; + break; + case MDSP_DOMAIN_ID: + uri_domain_suffix = MDSP_DOMAIN; + break; + case SDSP_DOMAIN_ID: + uri_domain_suffix = SDSP_DOMAIN; + break; + case GDSP0_DOMAIN_ID: + uri_domain_suffix = GDSP0_DOMAIN; + break; + case GDSP1_DOMAIN_ID: + uri_domain_suffix = GDSP1_DOMAIN; + break; + default: + uri_domain_suffix = "invalid domain"; + break; + } + return uri_domain_suffix; } #define IS_CONST_HANDLE(h) (((h) < 0xff) ? 1 : 0) -static int get_handle_remote(remote_handle64 local, remote_handle64 *remote) { - struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; - int nErr = AEE_SUCCESS; +static int +get_handle_remote(remote_handle64 local, remote_handle64 *remote) +{ + struct handle_info *hinfo = (struct handle_info *)(uintptr_t)local; + int nErr = AEE_SUCCESS; - VERIFY(AEE_SUCCESS == (nErr = verify_local_handle(-1, local))); - *remote = hinfo->remote; + VERIFY(AEE_SUCCESS == (nErr = verify_local_handle(-1, local))); + *remote = hinfo->remote; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error %x: get handle remote failed %p\n", nErr, &local); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error %x: get handle remote failed %p\n", nErr, + &local); + } + return nErr; } -inline int is_smmu_enabled(void) { - return hlist[get_current_domain()].info & FASTRPC_INFO_SMMU; +inline int +is_smmu_enabled(void) +{ + return hlist[get_current_domain()].info & FASTRPC_INFO_SMMU; } /** @@ -837,17 +941,20 @@ inline int is_smmu_enabled(void) { * @domain: domain of handles to be printed. * Return: void. */ -static void print_open_handles(int domain) { +static void +print_open_handles(int domain) +{ struct handle_info *hi = NULL; QNode *pn = NULL; FARF(RUNTIME_RPC_HIGH, "List of open handles on domain %d:\n", domain); pthread_mutex_lock(&hlist[domain].mut); - QLIST_FOR_ALL(&hlist[domain].ql, pn) { + QLIST_FOR_ALL(&hlist[domain].ql, pn) + { hi = STD_RECOVER_REC(struct handle_info, qn, pn); - if (hi->name) - FARF(RUNTIME_RPC_HIGH, "%s, handle 0x%"PRIx64"", - hi->name, hi->remote); + if(hi->name) + FARF(RUNTIME_RPC_HIGH, "%s, handle 0x%" PRIx64 "", + hi->name, hi->remote); } pthread_mutex_unlock(&hlist[domain].mut); } @@ -857,7 +964,9 @@ static void print_open_handles(int domain) { * @uri: uri for the lib. * Return: @lib_name or NULL */ -static char* get_lib_name(const char *uri) { +static char * +get_lib_name(const char *uri) +{ char *library_name = NULL; const char SO_EXTN[] = ".so"; const char LIB_EXTN[] = "lib"; @@ -865,1256 +974,1450 @@ static char* get_lib_name(const char *uri) { unsigned int length = 0; int nErr = AEE_SUCCESS; - VERIFY(uri); - start = strstr(uri, LIB_EXTN); - if (start) { + VERIFY(uri); + start = strstr(uri, LIB_EXTN); + if(start) { end = strstr(start, SO_EXTN); - if (end && end > start) { + if(end && end > start) { /* add extension size to print .so also */ length = (unsigned int)(end - start) + strlen(SO_EXTN); /* allocate length + 1 to include \0 */ - VERIFYC(NULL != (library_name = - (char*)calloc(1, length + 1)), AEE_ENOMEMORY); + VERIFYC(NULL + != (library_name + = (char *)calloc(1, length + 1)), + AEE_ENOMEMORY); strlcpy(library_name, start, length + 1); return library_name; } } bail: - FARF(RUNTIME_RPC_ERROR, "Warning 0x%x: %s failed for uri %s", - nErr, __func__, uri); - return NULL; + FARF(RUNTIME_RPC_ERROR, "Warning 0x%x: %s failed for uri %s", nErr, + __func__, uri); + return NULL; } -static int fastrpc_alloc_handle(int domain, QList *me, remote_handle64 remote, - remote_handle64 *local, const char *name) { - struct handle_info *hinfo = {0}; - int nErr = 0; - char *libname = NULL; - - VERIFYC(NULL != (hinfo = calloc(1, sizeof(*hinfo))), AEE_ENOMEMORY); - hinfo->local = (remote_handle64)(uintptr_t)hinfo; - hinfo->remote = remote; - libname = get_lib_name(name); - hinfo->name = libname; - hinfo->hlist = &hlist[domain]; - *local = hinfo->local; - - QNode_CtorZ(&hinfo->qn); - pthread_mutex_lock(&hlist[domain].lmut); - QList_PrependNode(me, &hinfo->qn); - pthread_mutex_unlock(&hlist[domain].lmut); +static int +fastrpc_alloc_handle(int domain, QList *me, remote_handle64 remote, + remote_handle64 *local, const char *name) +{ + struct handle_info *hinfo = { 0 }; + int nErr = 0; + char *libname = NULL; + + VERIFYC(NULL != (hinfo = calloc(1, sizeof(*hinfo))), AEE_ENOMEMORY); + hinfo->local = (remote_handle64)(uintptr_t)hinfo; + hinfo->remote = remote; + libname = get_lib_name(name); + hinfo->name = libname; + hinfo->hlist = &hlist[domain]; + *local = hinfo->local; + + QNode_CtorZ(&hinfo->qn); + pthread_mutex_lock(&hlist[domain].lmut); + QList_PrependNode(me, &hinfo->qn); + pthread_mutex_unlock(&hlist[domain].lmut); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for local handle 0x%x, remote handle 0x%x, " - "domain %d\n", - nErr, __func__, local, remote, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for local handle 0x%x, remote " + "handle 0x%x, " + "domain %d\n", + nErr, __func__, local, remote, domain); + } + return nErr; } -static int fastrpc_free_handle(int domain, QList *me, remote_handle64 remote) { - pthread_mutex_lock(&hlist[domain].lmut); - if (!QList_IsEmpty(me)) { - QNode *pn = NULL, *pnn = NULL; - QLIST_NEXTSAFE_FOR_ALL(me, pn, pnn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - if (hi->remote == remote) { - QNode_DequeueZ(&hi->qn); - if(hi->name) - free(hi->name); - free(hi); - hi = NULL; - break; - } - } - } - pthread_mutex_unlock(&hlist[domain].lmut); - return 0; +static int +fastrpc_free_handle(int domain, QList *me, remote_handle64 remote) +{ + pthread_mutex_lock(&hlist[domain].lmut); + if(!QList_IsEmpty(me)) { + QNode *pn = NULL, *pnn = NULL; + QLIST_NEXTSAFE_FOR_ALL(me, pn, pnn) + { + struct handle_info *hi + = STD_RECOVER_REC(struct handle_info, qn, pn); + if(hi->remote == remote) { + QNode_DequeueZ(&hi->qn); + if(hi->name) + free(hi->name); + free(hi); + hi = NULL; + break; + } + } + } + pthread_mutex_unlock(&hlist[domain].lmut); + return 0; } -int fastrpc_update_module_list(uint32_t req, int domain, remote_handle64 h, - remote_handle64 *local, const char *name) { - int nErr = AEE_SUCCESS; - - switch (req) { - case DOMAIN_LIST_PREPEND: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_alloc_handle(domain, &hlist[domain].ql, h, local, name))); - if(IS_CONST_HANDLE(h)) { - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].constCount++; - pthread_mutex_unlock(&hlist[domain].lmut); - } else { - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].domainsCount++; - pthread_mutex_unlock(&hlist[domain].lmut); - } - break; - } - case DOMAIN_LIST_DEQUEUE: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_free_handle(domain, &hlist[domain].ql, h))); - if(IS_CONST_HANDLE(h)) { - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].constCount--; - pthread_mutex_unlock(&hlist[domain].lmut); - } else { - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].domainsCount--; - pthread_mutex_unlock(&hlist[domain].lmut); - } - break; - } - case NON_DOMAIN_LIST_PREPEND: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_alloc_handle(domain, &hlist[domain].nql, h, local, name))); - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].nondomainsCount++; - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - case NON_DOMAIN_LIST_DEQUEUE: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_free_handle(domain, &hlist[domain].nql, h))); - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].nondomainsCount--; - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - case REVERSE_HANDLE_LIST_PREPEND: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_alloc_handle(domain, &hlist[domain].rql, h, local, name))); - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].reverseCount++; - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - case REVERSE_HANDLE_LIST_DEQUEUE: { - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_free_handle(domain, &hlist[domain].rql, h))); - pthread_mutex_lock(&hlist[domain].lmut); - hlist[domain].reverseCount--; - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - default: { - nErr = AEE_EUNSUPPORTEDAPI; - goto bail; - } - } +int +fastrpc_update_module_list(uint32_t req, int domain, remote_handle64 h, + remote_handle64 *local, const char *name) +{ + int nErr = AEE_SUCCESS; + + switch(req) { + case DOMAIN_LIST_PREPEND: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_alloc_handle( + domain, &hlist[domain].ql, h, local, name))); + if(IS_CONST_HANDLE(h)) { + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].constCount++; + pthread_mutex_unlock(&hlist[domain].lmut); + } else { + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].domainsCount++; + pthread_mutex_unlock(&hlist[domain].lmut); + } + break; + } + case DOMAIN_LIST_DEQUEUE: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_free_handle(domain, + &hlist[domain].ql, h))); + if(IS_CONST_HANDLE(h)) { + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].constCount--; + pthread_mutex_unlock(&hlist[domain].lmut); + } else { + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].domainsCount--; + pthread_mutex_unlock(&hlist[domain].lmut); + } + break; + } + case NON_DOMAIN_LIST_PREPEND: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_alloc_handle( + domain, &hlist[domain].nql, h, local, name))); + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].nondomainsCount++; + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + case NON_DOMAIN_LIST_DEQUEUE: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_free_handle(domain, + &hlist[domain].nql, h))); + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].nondomainsCount--; + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + case REVERSE_HANDLE_LIST_PREPEND: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_alloc_handle( + domain, &hlist[domain].rql, h, local, name))); + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].reverseCount++; + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + case REVERSE_HANDLE_LIST_DEQUEUE: { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_free_handle(domain, + &hlist[domain].rql, h))); + pthread_mutex_lock(&hlist[domain].lmut); + hlist[domain].reverseCount--; + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + default: { + nErr = AEE_EUNSUPPORTEDAPI; + goto bail; + } + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for request ID %u, handle 0x%x, domain %d\n", - nErr, __func__, req, h, domain); - } else { - FARF(RUNTIME_RPC_HIGH, "Library D count %d, C count %d, N count %d, R count %d\n", hlist[domain].domainsCount, hlist[domain].constCount, hlist[domain].nondomainsCount, hlist[domain].reverseCount); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %u, handle 0x%x, " + "domain %d\n", + nErr, __func__, req, h, domain); + } else { + FARF( + RUNTIME_RPC_HIGH, + "Library D count %d, C count %d, N count %d, R count %d\n", + hlist[domain].domainsCount, hlist[domain].constCount, + hlist[domain].nondomainsCount, hlist[domain].reverseCount); + } + return nErr; } -static void fastrpc_clear_handle_list(uint32_t req, int domain) { - int nErr = AEE_SUCCESS; - QNode *pn = NULL; - char dlerrstr[MAX_DLERRSTR_LEN]; - int dlerr = 0; - - switch (req) { - case MULTI_DOMAIN_HANDLE_LIST_ID: { - pthread_mutex_lock(&hlist[domain].lmut); - if (!QList_IsNull(&hlist[domain].ql)) { - while ((pn = QList_Pop(&hlist[domain].ql))) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - free(hi); - hi = NULL; - } - } - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - case NON_DOMAIN_HANDLE_LIST_ID: { - pthread_mutex_lock(&hlist[domain].lmut); - if (!QList_IsNull(&hlist[domain].nql)) { - while ((pn = QList_Pop(&hlist[domain].nql))) { - struct handle_info *h = STD_RECOVER_REC(struct handle_info, qn, pn); - free(h); - h = NULL; - } - } - pthread_mutex_unlock(&hlist[domain].lmut); - break; - } - case REVERSE_HANDLE_LIST_ID: { - if (!QList_IsNull(&hlist[domain].rql)) { - while ((pn = QList_Pop(&hlist[domain].rql))) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - close_reverse_handle(hi->local, dlerrstr, sizeof(dlerrstr), &dlerr); - free(hi); - hi = NULL; - } - } - break; - } - default: { - nErr = AEE_EUNSUPPORTEDAPI; - goto bail; - } - } +static void +fastrpc_clear_handle_list(uint32_t req, int domain) +{ + int nErr = AEE_SUCCESS; + QNode *pn = NULL; + char dlerrstr[MAX_DLERRSTR_LEN]; + int dlerr = 0; + + switch(req) { + case MULTI_DOMAIN_HANDLE_LIST_ID: { + pthread_mutex_lock(&hlist[domain].lmut); + if(!QList_IsNull(&hlist[domain].ql)) { + while((pn = QList_Pop(&hlist[domain].ql))) { + struct handle_info *hi = STD_RECOVER_REC( + struct handle_info, qn, pn); + free(hi); + hi = NULL; + } + } + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + case NON_DOMAIN_HANDLE_LIST_ID: { + pthread_mutex_lock(&hlist[domain].lmut); + if(!QList_IsNull(&hlist[domain].nql)) { + while((pn = QList_Pop(&hlist[domain].nql))) { + struct handle_info *h = STD_RECOVER_REC( + struct handle_info, qn, pn); + free(h); + h = NULL; + } + } + pthread_mutex_unlock(&hlist[domain].lmut); + break; + } + case REVERSE_HANDLE_LIST_ID: { + if(!QList_IsNull(&hlist[domain].rql)) { + while((pn = QList_Pop(&hlist[domain].rql))) { + struct handle_info *hi = STD_RECOVER_REC( + struct handle_info, qn, pn); + close_reverse_handle(hi->local, dlerrstr, + sizeof(dlerrstr), &dlerr); + free(hi); + hi = NULL; + } + } + break; + } + default: { + nErr = AEE_EUNSUPPORTEDAPI; + goto bail; + } + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %u, domain %d\n", nErr, - __func__, req, domain); - } - return; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %u, domain %d\n", + nErr, __func__, req, domain); + } + return; } // Notify kernel to awake PM -static int wakelock_control_kernel_pm(int domain, int dev, uint32_t timeout) { - int nErr = AEE_SUCCESS; - struct fastrpc_ctrl_pm pm = {0}; - - pm.timeout = timeout; - nErr = ioctl_control(dev, DSPRPC_PM, &pm); - if (nErr) { - if (errno == EBADRQC || errno == ENOTTY) { - VERIFY_WPRINTF("Warning: %s: kernel does not support PM management (%s)", - __func__, strerror(errno)); - } else if (errno == EACCES || errno == EPERM) { - VERIFY_WPRINTF("Warning: %s: application does not have permission for PM " - "management (%s)", - __func__, strerror(errno)); - } - FARF(ERROR, - "Error 0x%x: %s PM control failed for domain %d, dev %d with timeout " - "%d (errno %s)", - nErr, __func__, domain, dev, timeout, strerror(errno)); - } - return nErr; +static int +wakelock_control_kernel_pm(int domain, int dev, uint32_t timeout) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_ctrl_pm pm = { 0 }; + + pm.timeout = timeout; + nErr = ioctl_control(dev, DSPRPC_PM, &pm); + if(nErr) { + if(errno == EBADRQC || errno == ENOTTY) { + VERIFY_WPRINTF("Warning: %s: kernel does not support " + "PM management (%s)", + __func__, strerror(errno)); + } else if(errno == EACCES || errno == EPERM) { + VERIFY_WPRINTF("Warning: %s: application does not " + "have permission for PM " + "management (%s)", + __func__, strerror(errno)); + } + FARF(ERROR, + "Error 0x%x: %s PM control failed for domain %d, dev %d " + "with timeout " + "%d (errno %s)", + nErr, __func__, domain, dev, timeout, strerror(errno)); + } + return nErr; } // Callback function for posix timer -static void fastrpc_timer_callback(void *ptr) { - fastrpc_timer *frpc_timer = (fastrpc_timer *)ptr; - int nErr = AEE_SUCCESS; - remote_rpc_process_exception data; - bool expected = false; - - atomic_compare_exchange_strong(&timer_expired, &expected, true); - if (expected == true) - return; - - FARF(ALWAYS, - "%s fastrpc time out of %d ms on thread %d on domain %d sc 0x%x handle 0x%x\n", - __func__, frpc_timer->timeout_millis, frpc_timer->tid, - frpc_timer->domain, frpc_timer->sc, frpc_timer->handle); - data.domain = frpc_timer->domain; - nErr = remote_session_control(FASTRPC_REMOTE_PROCESS_EXCEPTION, &data, - sizeof(remote_rpc_process_exception)); - if (nErr) { - FARF(ERROR, - "%s: Failed to create exception in the remote process on domain %d " - "(errno %s)", - __func__, data.domain, strerror(errno)); - } +static void +fastrpc_timer_callback(void *ptr) +{ + fastrpc_timer *frpc_timer = (fastrpc_timer *)ptr; + int nErr = AEE_SUCCESS; + remote_rpc_process_exception data; + bool expected = false; + + atomic_compare_exchange_strong(&timer_expired, &expected, true); + if(expected == true) + return; + + FARF(ALWAYS, + "%s fastrpc time out of %d ms on thread %d on domain %d sc 0x%x " + "handle 0x%x\n", + __func__, frpc_timer->timeout_millis, frpc_timer->tid, + frpc_timer->domain, frpc_timer->sc, frpc_timer->handle); + data.domain = frpc_timer->domain; + nErr = remote_session_control(FASTRPC_REMOTE_PROCESS_EXCEPTION, &data, + sizeof(remote_rpc_process_exception)); + if(nErr) { + FARF(ERROR, + "%s: Failed to create exception in the remote process on " + "domain %d " + "(errno %s)", + __func__, data.domain, strerror(errno)); + } } // Function to add timer before remote RPC call -static void fastrpc_add_timer(fastrpc_timer *frpc_timer) { - struct sigevent sigevent; - struct itimerspec time_spec; - int err = 0; - - memset(&sigevent, 0, sizeof(sigevent)); - sigevent.sigev_notify = SIGEV_THREAD; - sigevent.sigev_notify_function = - (void (*)(union sigval))fastrpc_timer_callback; - sigevent.sigev_value.sival_ptr = frpc_timer; - err = timer_create(CLOCK_MONOTONIC, &sigevent, &(frpc_timer->timer)); - if (err) { - FARF(ERROR, "%s: failed to create timer with error 0x%x\n", __func__, err); - goto bail; - } - - time_spec.it_value.tv_sec = frpc_timer->timeout_millis / 1000; - time_spec.it_value.tv_nsec = - (frpc_timer->timeout_millis % 1000) * 1000 * 1000; - err = timer_settime(frpc_timer->timer, 0, &time_spec, NULL); - if (err) { - FARF(ERROR, "%s: failed to set timer with error 0x%x\n", __func__, err); - goto bail; - } +static void +fastrpc_add_timer(fastrpc_timer *frpc_timer) +{ + struct sigevent sigevent; + struct itimerspec time_spec; + int err = 0; + + memset(&sigevent, 0, sizeof(sigevent)); + sigevent.sigev_notify = SIGEV_THREAD; + sigevent.sigev_notify_function + = (void (*)(union sigval))fastrpc_timer_callback; + sigevent.sigev_value.sival_ptr = frpc_timer; + err = timer_create(CLOCK_MONOTONIC, &sigevent, &(frpc_timer->timer)); + if(err) { + FARF(ERROR, "%s: failed to create timer with error 0x%x\n", + __func__, err); + goto bail; + } + + time_spec.it_value.tv_sec = frpc_timer->timeout_millis / 1000; + time_spec.it_value.tv_nsec + = (frpc_timer->timeout_millis % 1000) * 1000 * 1000; + err = timer_settime(frpc_timer->timer, 0, &time_spec, NULL); + if(err) { + FARF(ERROR, "%s: failed to set timer with error 0x%x\n", + __func__, err); + goto bail; + } bail: - return; + return; } // Function to delete timer after remote RPC call -static void fastrpc_delete_timer(timer_t *timer) { - int nErr = AEE_SUCCESS; - nErr = timer_delete(*timer); - if (nErr) { - FARF(ERROR, "%s: Failed to delete timer", __func__); - } +static void +fastrpc_delete_timer(timer_t *timer) +{ + int nErr = AEE_SUCCESS; + nErr = timer_delete(*timer); + if(nErr) { + FARF(ERROR, "%s: Failed to delete timer", __func__); + } } -int remote_handle_invoke_domain(int domain, remote_handle handle, - fastrpc_async_descriptor_t *desc, uint32_t sc, - remote_arg *pra) { - int dev, total, bufs, handles, i, nErr = 0, wake_lock = 0, rpc_timeout = 0; - unsigned req; - uint32_t len; - struct handle_list *list; - uint32_t *crc_remote = NULL; - uint32_t *crc_local = NULL; - uint64_t *perf_kernel = NULL; - uint64_t *perf_dsp = NULL; - struct fastrpc_async_job asyncjob = {0}, *job = NULL; - fastrpc_timer frpc_timer; - int trace_marker_fd = hlist[domain].trace_marker_fd; - bool trace_enabled = false; - struct fastrpc_invoke_args* args = NULL; - - if (IS_QTF_TRACING_ENABLED(hlist[domain].procattrs) && - !IS_STATIC_HANDLE(handle) && trace_marker_fd > 0) { - write(trace_marker_fd, INVOKE_BEGIN_TRACE_STR, invoke_begin_trace_strlen); - trace_enabled = true; - } - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - - errno = 0; - if (fastrpc_wake_lock_enable[domain]) { - if (!IS_REVERSE_RPC_CALL(handle, sc) || - is_first_reverse_rpc_call(domain, handle, sc)) { - if (!fastrpc_wake_lock()) - wake_lock = 1; - } else if (IS_REVERSE_RPC_CALL(handle, sc)) - /* Since wake-lock is not released at the end of previous - * "remote_handle_invoke" for subsequent reverse RPC calls, it doesn't - * have to be taken again here. - * It will be released before "ioctl invoke" call to kernel */ - wake_lock = 1; - } - - list = &hlist[domain]; - if (list->setmode) { - list->setmode = 0; - nErr = ioctl_setmode(dev, list->mode); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } - } - - bufs = REMOTE_SCALARS_INBUFS(sc) + REMOTE_SCALARS_OUTBUFS(sc); - handles = REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc); - total = bufs + handles; - - INITIALIZE_REMOTE_ARGS(total); - - if (desc) { - struct timespec time_spec; - // Check for valid user async descriptor - VERIFYC(desc->type >= FASTRPC_ASYNC_NO_SYNC && - desc->type < FASTRPC_ASYNC_TYPE_MAX, - AEE_EBADPARM); - VERIFYC(!(desc->type == FASTRPC_ASYNC_CALLBACK && desc->cb.fn == NULL), - AEE_EBADPARM); - pthread_mutex_lock(&hlist[domain].async_init_deinit_mut); - if (AEE_SUCCESS != (nErr = fastrpc_async_domain_init(domain))) { - pthread_mutex_unlock(&hlist[domain].async_init_deinit_mut); - goto bail; - } - asyncjob.jobid = ++list->jobid; - pthread_mutex_unlock(&hlist[domain].async_init_deinit_mut); - clock_gettime(CLOCK_MONOTONIC, &time_spec); - asyncjob.jobid = ((((time_spec.tv_sec) / SECONDS_PER_HOUR) - << (FASTRPC_ASYNC_TIME_SPEC_POS / 2)) - << ((FASTRPC_ASYNC_TIME_SPEC_POS + 1) / 2) | - (asyncjob.jobid << FASTRPC_ASYNC_JOB_POS) | domain); - asyncjob.isasyncjob = 1; - fastrpc_save_async_job(domain, &asyncjob, desc); - job = &asyncjob; - } - - req = INVOKE; - VERIFYC(!(NULL == pra && total > 0), AEE_EBADPARM); - for (i = 0; i < bufs; i++) { - set_args(i, pra[i].buf.pv, pra[i].buf.nLen, -1, 0); - if (pra[i].buf.nLen) { - void *base; - int nova = 0, attr = 0, fd = -1; - VERIFY(AEE_SUCCESS == - (nErr = fdlist_fd_from_buf(pra[i].buf.pv, (int)pra[i].buf.nLen, - &nova, &base, &attr, &fd))); - if (fd != -1) { - set_args_fd(i, fd); - req = INVOKE_FD; - } - // AsyncRPC doesn't support Non-ion output buffers - if (asyncjob.isasyncjob && i >= (int)REMOTE_SCALARS_INBUFS(sc)) { - VERIFYM(fd != -1, AEE_EBADPARM, - "AsyncRPC doesn't support Non-ion output buffers"); - } - if (nova) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_NOVA); - // pra[i].buf.pv = (void*)((uintptr_t)pra[i].buf.pv - (uintptr_t)base); - VERIFY_IPRINTF("nova buffer idx: %d addr: %p size: %d", i, - pra[i].buf.pv, pra[i].buf.nLen); - } - if (attr & FASTRPC_ATTR_NON_COHERENT) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_NON_COHERENT); - VERIFY_IPRINTF("non-coherent buffer idx: %d addr: %p size: %d", i, - pra[i].buf.pv, pra[i].buf.nLen); - } - if (attr & FASTRPC_ATTR_COHERENT) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_COHERENT); - VERIFY_IPRINTF("coherent buffer idx: %d addr: %p size: %d", i, - pra[i].buf.pv, pra[i].buf.nLen); - } - if (attr & FASTRPC_ATTR_FORCE_NOFLUSH) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_FORCE_NOFLUSH); - VERIFY_IPRINTF("force no flush for buffer idx: %d addr: %p size: %d", i, - pra[i].buf.pv, pra[i].buf.nLen); - } - if (attr & FASTRPC_ATTR_FORCE_NOINVALIDATE) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_FORCE_NOINVALIDATE); - VERIFY_IPRINTF("force no invalidate buffer idx: %d addr: %p size: %d", - i, pra[i].buf.pv, pra[i].buf.nLen); - } - if (attr & FASTRPC_ATTR_KEEP_MAP) { - req = INVOKE_ATTRS; - append_args_attr(i, FASTRPC_ATTR_KEEP_MAP); - VERIFY_IPRINTF("invoke: mapping with attribute KEEP_MAP"); - } - } - } - - for (i = bufs; i < total; i++) { - unsigned int attr = 0; - int dma_fd = -1; - - req = INVOKE_ATTRS; - unregister_dma_handle(pra[i].dma.fd, &len, &attr); - if (hlist[domain].dma_handle_reverse_rpc_map_capability && - (attr & FASTRPC_ATTR_NOMAP)) { - // Register fd again, for reverse RPC call to retrive FASTRPC_ATTR_NOMAP - // flag for fd - remote_register_dma_handle_attr(pra[i].dma.fd, len, FASTRPC_ATTR_NOMAP); - } - dma_fd = pra[i].dma.fd; - set_args(i, (void *)(uintptr_t)pra[i].dma.offset, len, dma_fd, attr); - append_args_attr(i, FASTRPC_ATTR_NOVA); - } - - if (IS_CRC_CHECK_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { - int nInBufs = REMOTE_SCALARS_INBUFS(sc); - crc_local = (uint32_t *)calloc(M_CRCLIST, sizeof(uint32_t)); - crc_remote = (uint32_t *)calloc(M_CRCLIST, sizeof(uint32_t)); - VERIFYC(crc_local != NULL && crc_remote != NULL, AEE_ENOMEMORY); - VERIFYC(!(NULL == pra && nInBufs > 0), AEE_EBADPARM); - for (i = 0; (i < nInBufs) && (i < M_CRCLIST); i++) - crc_local[i] = crc32_lut((unsigned char *)pra[i].buf.pv, - (int)pra[i].buf.nLen, crc_table); - req = INVOKE_CRC; - } - - if (IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle))) { - perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); - req = INVOKE_PERF; - } - if (IS_DSP_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle))) { - perf_dsp = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); - req = INVOKE_PERF; - } - - if (!IS_STATIC_HANDLE(handle)) { - fastrpc_latency_invoke_incr(&hlist[domain].qos); - if ((rpc_timeout = fastrpc_config_get_rpctimeout()) > 0) { - frpc_timer.domain = domain; - frpc_timer.sc = sc; - frpc_timer.handle = handle; - frpc_timer.timeout_millis = rpc_timeout; - frpc_timer.tid = gettid(); - fastrpc_add_timer(&frpc_timer); - } - } - - FASTRPC_TRACE_LOG(FASTRPC_TRACE_INVOKE_START, handle, sc); - if (wake_lock) { - wakelock_control_kernel_pm(domain, dev, PM_TIMEOUT_MS); - fastrpc_wake_unlock(); - wake_lock = 0; - } - // Macros are initializing and destroying pfds and pattrs. - nErr = ioctl_invoke(dev, req, handle, sc, get_args(), pfds, pattrs, job, - crc_remote, perf_kernel, perf_dsp); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - } - - if (fastrpc_wake_lock_enable[domain]) { - if (!fastrpc_wake_lock()) - wake_lock = 1; - } - FASTRPC_TRACE_LOG(FASTRPC_TRACE_INVOKE_END, handle, sc); - if (!IS_STATIC_HANDLE(handle) && rpc_timeout > 0) { - fastrpc_delete_timer(&(frpc_timer.timer)); - } - - if (IS_CRC_CHECK_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { - int nInBufs = REMOTE_SCALARS_INBUFS(sc); - VERIFYC(crc_local != NULL && crc_remote != NULL, AEE_ENOMEMORY); - for (i = nInBufs; i < bufs; i++) - crc_local[i] = crc32_lut((unsigned char *)pra[i].buf.pv, - (int)pra[i].buf.nLen, crc_table); - for (i = 0; (i < bufs) && (i < M_CRCLIST); i++) { - if (crc_local[i] != crc_remote[i]) { - FARF(ERROR, "CRC mismatch for buffer %d[%d], crc local %x remote %x", i, - bufs, crc_local[i], crc_remote[i]); - break; - } - } - } - - if (IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { - VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); - FARF(ALWAYS, - "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 " ns M:%" PRIu64 - " ns CP:%" PRIu64 " ns L:%" PRIu64 " ns G:%" PRIu64 " ns P:%" PRIu64 - " ns INV:%" PRIu64 " ns INVOKE:%" PRIu64 " ns\n", - handle, sc, perf_kernel[0], perf_kernel[1], perf_kernel[2], - perf_kernel[3], perf_kernel[4], perf_kernel[5], perf_kernel[6], - perf_kernel[7], perf_kernel[8]); - } - if (IS_DSP_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { - VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); - FARF(ALWAYS, - "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 " us M:%" PRIu64 - " us G:%" PRIu64 " us INVOKE:%" PRIu64 " us P:%" PRIu64 - " us CACHE:%" PRIu64 " us UM:%" PRIu64 " us " - "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 - " us J_S_T:%" PRIu64 " us\n", - handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], perf_dsp[3], - perf_dsp[4], perf_dsp[5], perf_dsp[6], perf_dsp[7], perf_dsp[8], - perf_dsp[9], perf_dsp[10], perf_dsp[11]); - } - - if (!(perf_v2_kernel && perf_v2_dsp)) { - fastrpc_perf_update(dev, handle, sc); - } -bail: - if (asyncjob.isasyncjob) { - if (!nErr) { - FARF(RUNTIME_RPC_HIGH, "adsprpc : %s Async job Queued, job 0x%" PRIx64 "", - __func__, asyncjob.jobid); - desc->jobid = asyncjob.jobid; - } else { - fastrpc_remove_async_job(asyncjob.jobid, false); - desc->jobid = -1; - } - } - DESTROY_REMOTE_ARGS(); - if (crc_local) { - free(crc_local); - crc_local = NULL; - } - if (crc_remote) { - free(crc_remote); - crc_remote = NULL; - } - if (perf_kernel && !asyncjob.isasyncjob) { - free(perf_kernel); - perf_kernel = NULL; - } - if (perf_dsp && !asyncjob.isasyncjob) { - free(perf_dsp); - perf_dsp = NULL; - } - if (wake_lock) { - // Keep holding wake-lock for reverse RPC calls to keep CPU awake for any - // further processing - if (!IS_REVERSE_RPC_CALL(handle, sc)) { - fastrpc_wake_unlock(); - wake_lock = 0; - } - } - if (trace_enabled) { - write(trace_marker_fd, INVOKE_END_TRACE_STR, invoke_end_trace_strlen); - } - if (nErr != AEE_SUCCESS) { - if ((nErr == -1) && (errno == ECONNRESET)) { - nErr = AEE_ECONNRESET; - } - // FARF(ERROR, "Error 0x%x: %s failed for handle 0x%x on domain %d (sc - // 0x%x)\n", nErr, __func__, (int)handle, domain, sc); - } - return nErr; -} +int +remote_handle_invoke_domain(int domain, remote_handle handle, + fastrpc_async_descriptor_t *desc, uint32_t sc, + remote_arg *pra) +{ + int dev, total, bufs, handles, i, nErr = 0, wake_lock = 0, + rpc_timeout = 0; + unsigned req; + uint32_t len; + struct handle_list *list; + uint32_t *crc_remote = NULL; + uint32_t *crc_local = NULL; + uint64_t *perf_kernel = NULL; + uint64_t *perf_dsp = NULL; + struct fastrpc_async_job asyncjob = { 0 }, *job = NULL; + fastrpc_timer frpc_timer; + int trace_marker_fd = hlist[domain].trace_marker_fd; + bool trace_enabled = false; + struct fastrpc_invoke_args *args = NULL; + + if(IS_QTF_TRACING_ENABLED(hlist[domain].procattrs) + && !IS_STATIC_HANDLE(handle) && trace_marker_fd > 0) { + write(trace_marker_fd, INVOKE_BEGIN_TRACE_STR, + invoke_begin_trace_strlen); + trace_enabled = true; + } + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + + errno = 0; + if(fastrpc_wake_lock_enable[domain]) { + if(!IS_REVERSE_RPC_CALL(handle, sc) + || is_first_reverse_rpc_call(domain, handle, sc)) { + if(!fastrpc_wake_lock()) + wake_lock = 1; + } else if(IS_REVERSE_RPC_CALL(handle, sc)) + /* Since wake-lock is not released at the end of + * previous "remote_handle_invoke" for subsequent + * reverse RPC calls, it doesn't have to be taken again + * here. It will be released before "ioctl invoke" call + * to kernel */ + wake_lock = 1; + } + + list = &hlist[domain]; + if(list->setmode) { + list->setmode = 0; + nErr = ioctl_setmode(dev, list->mode); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } + } -int remote_handle_invoke(remote_handle handle, uint32_t sc, remote_arg *pra) { - int domain = -1, nErr = AEE_SUCCESS, ref = 0; + bufs = REMOTE_SCALARS_INBUFS(sc) + REMOTE_SCALARS_OUTBUFS(sc); + handles = REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc); + total = bufs + handles; + + INITIALIZE_REMOTE_ARGS(total); + + if(desc) { + struct timespec time_spec; + // Check for valid user async descriptor + VERIFYC(desc->type >= FASTRPC_ASYNC_NO_SYNC + && desc->type < FASTRPC_ASYNC_TYPE_MAX, + AEE_EBADPARM); + VERIFYC(!(desc->type == FASTRPC_ASYNC_CALLBACK + && desc->cb.fn == NULL), + AEE_EBADPARM); + pthread_mutex_lock(&hlist[domain].async_init_deinit_mut); + if(AEE_SUCCESS != (nErr = fastrpc_async_domain_init(domain))) { + pthread_mutex_unlock( + &hlist[domain].async_init_deinit_mut); + goto bail; + } + asyncjob.jobid = ++list->jobid; + pthread_mutex_unlock(&hlist[domain].async_init_deinit_mut); + clock_gettime(CLOCK_MONOTONIC, &time_spec); + asyncjob.jobid + = ((((time_spec.tv_sec) / SECONDS_PER_HOUR) + << (FASTRPC_ASYNC_TIME_SPEC_POS / 2)) + << ((FASTRPC_ASYNC_TIME_SPEC_POS + 1) / 2) + | (asyncjob.jobid << FASTRPC_ASYNC_JOB_POS) | domain); + asyncjob.isasyncjob = 1; + fastrpc_save_async_job(domain, &asyncjob, desc); + job = &asyncjob; + } + + req = INVOKE; + VERIFYC(!(NULL == pra && total > 0), AEE_EBADPARM); + for(i = 0; i < bufs; i++) { + set_args(i, pra[i].buf.pv, pra[i].buf.nLen, -1, 0); + if(pra[i].buf.nLen) { + void *base; + int nova = 0, attr = 0, fd = -1; + VERIFY(AEE_SUCCESS + == (nErr = fdlist_fd_from_buf( + pra[i].buf.pv, (int)pra[i].buf.nLen, + &nova, &base, &attr, &fd))); + if(fd != -1) { + set_args_fd(i, fd); + req = INVOKE_FD; + } + // AsyncRPC doesn't support Non-ion output buffers + if(asyncjob.isasyncjob + && i >= (int)REMOTE_SCALARS_INBUFS(sc)) { + VERIFYM(fd != -1, AEE_EBADPARM, + "AsyncRPC doesn't support Non-ion " + "output buffers"); + } + if(nova) { + req = INVOKE_ATTRS; + append_args_attr(i, FASTRPC_ATTR_NOVA); + // pra[i].buf.pv = + // (void*)((uintptr_t)pra[i].buf.pv - + // (uintptr_t)base); + VERIFY_IPRINTF( + "nova buffer idx: %d addr: %p size: %d", i, + pra[i].buf.pv, pra[i].buf.nLen); + } + if(attr & FASTRPC_ATTR_NON_COHERENT) { + req = INVOKE_ATTRS; + append_args_attr(i, FASTRPC_ATTR_NON_COHERENT); + VERIFY_IPRINTF("non-coherent buffer idx: %d " + "addr: %p size: %d", + i, pra[i].buf.pv, + pra[i].buf.nLen); + } + if(attr & FASTRPC_ATTR_COHERENT) { + req = INVOKE_ATTRS; + append_args_attr(i, FASTRPC_ATTR_COHERENT); + VERIFY_IPRINTF("coherent buffer idx: %d addr: " + "%p size: %d", + i, pra[i].buf.pv, + pra[i].buf.nLen); + } + if(attr & FASTRPC_ATTR_FORCE_NOFLUSH) { + req = INVOKE_ATTRS; + append_args_attr(i, + FASTRPC_ATTR_FORCE_NOFLUSH); + VERIFY_IPRINTF("force no flush for buffer " + "idx: %d addr: %p size: %d", + i, pra[i].buf.pv, + pra[i].buf.nLen); + } + if(attr & FASTRPC_ATTR_FORCE_NOINVALIDATE) { + req = INVOKE_ATTRS; + append_args_attr( + i, FASTRPC_ATTR_FORCE_NOINVALIDATE); + VERIFY_IPRINTF("force no invalidate buffer " + "idx: %d addr: %p size: %d", + i, pra[i].buf.pv, + pra[i].buf.nLen); + } + if(attr & FASTRPC_ATTR_KEEP_MAP) { + req = INVOKE_ATTRS; + append_args_attr(i, FASTRPC_ATTR_KEEP_MAP); + VERIFY_IPRINTF( + "invoke: mapping with attribute KEEP_MAP"); + } + } + } + + for(i = bufs; i < total; i++) { + unsigned int attr = 0; + int dma_fd = -1; + + req = INVOKE_ATTRS; + unregister_dma_handle(pra[i].dma.fd, &len, &attr); + if(hlist[domain].dma_handle_reverse_rpc_map_capability + && (attr & FASTRPC_ATTR_NOMAP)) { + // Register fd again, for reverse RPC call to retrive + // FASTRPC_ATTR_NOMAP flag for fd + remote_register_dma_handle_attr(pra[i].dma.fd, len, + FASTRPC_ATTR_NOMAP); + } + dma_fd = pra[i].dma.fd; + set_args(i, (void *)(uintptr_t)pra[i].dma.offset, len, dma_fd, + attr); + append_args_attr(i, FASTRPC_ATTR_NOVA); + } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + if(IS_CRC_CHECK_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { + int nInBufs = REMOTE_SCALARS_INBUFS(sc); + crc_local = (uint32_t *)calloc(M_CRCLIST, sizeof(uint32_t)); + crc_remote = (uint32_t *)calloc(M_CRCLIST, sizeof(uint32_t)); + VERIFYC(crc_local != NULL && crc_remote != NULL, + AEE_ENOMEMORY); + VERIFYC(!(NULL == pra && nInBufs > 0), AEE_EBADPARM); + for(i = 0; (i < nInBufs) && (i < M_CRCLIST); i++) + crc_local[i] + = crc32_lut((unsigned char *)pra[i].buf.pv, + (int)pra[i].buf.nLen, crc_table); + req = INVOKE_CRC; + } - FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %u sc %X remote_arg %p\n", - __func__, handle, sc, pra); - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", __func__, - (int)handle, sc); - VERIFYC(handle != (remote_handle)-1, AEE_EINVHANDLE); + if(IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle))) { + perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, + sizeof(uint64_t)); + VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); + req = INVOKE_PERF; + } + if(IS_DSP_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle))) { + perf_dsp + = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); + VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); + req = INVOKE_PERF; + } + + if(!IS_STATIC_HANDLE(handle)) { + fastrpc_latency_invoke_incr(&hlist[domain].qos); + if((rpc_timeout = fastrpc_config_get_rpctimeout()) > 0) { + frpc_timer.domain = domain; + frpc_timer.sc = sc; + frpc_timer.handle = handle; + frpc_timer.timeout_millis = rpc_timeout; + frpc_timer.tid = gettid(); + fastrpc_add_timer(&frpc_timer); + } + } - domain = get_current_domain(); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_invoke_domain(domain, handle, NULL, sc, pra))); + FASTRPC_TRACE_LOG(FASTRPC_TRACE_INVOKE_START, handle, sc); + if(wake_lock) { + wakelock_control_kernel_pm(domain, dev, PM_TIMEOUT_MS); + fastrpc_wake_unlock(); + wake_lock = 0; + } + // Macros are initializing and destroying pfds and pattrs. + nErr = ioctl_invoke(dev, req, handle, sc, get_args(), pfds, pattrs, + job, crc_remote, perf_kernel, perf_dsp); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + } + + if(fastrpc_wake_lock_enable[domain]) { + if(!fastrpc_wake_lock()) + wake_lock = 1; + } + FASTRPC_TRACE_LOG(FASTRPC_TRACE_INVOKE_END, handle, sc); + if(!IS_STATIC_HANDLE(handle) && rpc_timeout > 0) { + fastrpc_delete_timer(&(frpc_timer.timer)); + } + + if(IS_CRC_CHECK_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { + int nInBufs = REMOTE_SCALARS_INBUFS(sc); + VERIFYC(crc_local != NULL && crc_remote != NULL, + AEE_ENOMEMORY); + for(i = nInBufs; i < bufs; i++) + crc_local[i] + = crc32_lut((unsigned char *)pra[i].buf.pv, + (int)pra[i].buf.nLen, crc_table); + for(i = 0; (i < bufs) && (i < M_CRCLIST); i++) { + if(crc_local[i] != crc_remote[i]) { + FARF(ERROR, + "CRC mismatch for buffer %d[%d], crc " + "local %x remote %x", + i, bufs, crc_local[i], crc_remote[i]); + break; + } + } + } + + if(IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { + VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); + FARF(ALWAYS, + "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 + " ns M:%" PRIu64 " ns CP:%" PRIu64 " ns L:%" PRIu64 + " ns G:%" PRIu64 " ns P:%" PRIu64 " ns INV:%" PRIu64 + " ns INVOKE:%" PRIu64 " ns\n", + handle, sc, perf_kernel[0], perf_kernel[1], + perf_kernel[2], perf_kernel[3], perf_kernel[4], + perf_kernel[5], perf_kernel[6], perf_kernel[7], + perf_kernel[8]); + } + if(IS_DSP_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle)) && !asyncjob.isasyncjob) { + VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); + FARF(ALWAYS, + "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 + " us M:%" PRIu64 " us G:%" PRIu64 " us INVOKE:%" PRIu64 + " us P:%" PRIu64 " us CACHE:%" PRIu64 " us UM:%" PRIu64 + " us " + "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 + " us J_S_T:%" PRIu64 " us\n", + handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], + perf_dsp[3], perf_dsp[4], perf_dsp[5], perf_dsp[6], + perf_dsp[7], perf_dsp[8], perf_dsp[9], perf_dsp[10], + perf_dsp[11]); + } + + if(!(perf_v2_kernel && perf_v2_dsp)) { + fastrpc_perf_update(dev, handle, sc); + } bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - if (is_process_exiting(domain)) { - return 0; - } - /* - * handle_info or so name cannot be obtained from remote handles which - * are used for non-domain calls. - */ - if (0 == check_rpc_error(nErr)) { - if (get_logger_state(domain)) { - FARF(ERROR, - "Error 0x%x: %s failed for handle 0x%x, method %d on domain %d " - "(sc 0x%x) (errno %s)\n", - nErr, __func__, (int)handle, REMOTE_SCALARS_METHOD(sc), domain, sc, - strerror(errno)); - } - } - } - FASTRPC_ATRACE_END(); - return nErr; + if(asyncjob.isasyncjob) { + if(!nErr) { + FARF(RUNTIME_RPC_HIGH, + "adsprpc : %s Async job Queued, job 0x%" PRIx64 + "", + __func__, asyncjob.jobid); + desc->jobid = asyncjob.jobid; + } else { + fastrpc_remove_async_job(asyncjob.jobid, false); + desc->jobid = -1; + } + } + DESTROY_REMOTE_ARGS(); + if(crc_local) { + free(crc_local); + crc_local = NULL; + } + if(crc_remote) { + free(crc_remote); + crc_remote = NULL; + } + if(perf_kernel && !asyncjob.isasyncjob) { + free(perf_kernel); + perf_kernel = NULL; + } + if(perf_dsp && !asyncjob.isasyncjob) { + free(perf_dsp); + perf_dsp = NULL; + } + if(wake_lock) { + // Keep holding wake-lock for reverse RPC calls to keep CPU + // awake for any further processing + if(!IS_REVERSE_RPC_CALL(handle, sc)) { + fastrpc_wake_unlock(); + wake_lock = 0; + } + } + if(trace_enabled) { + write(trace_marker_fd, INVOKE_END_TRACE_STR, + invoke_end_trace_strlen); + } + if(nErr != AEE_SUCCESS) { + if((nErr == -1) && (errno == ECONNRESET)) { + nErr = AEE_ECONNRESET; + } + // FARF(ERROR, "Error 0x%x: %s failed for handle 0x%x on domain + // %d (sc 0x%x)\n", nErr, __func__, (int)handle, domain, sc); + } + return nErr; } -int remote_handle64_invoke(remote_handle64 local, uint32_t sc, - remote_arg *pra) { - remote_handle64 remote = 0; - int nErr = AEE_SUCCESS, domain = -1, ref = 0; - struct handle_info *h = (struct handle_info*)local; - - if (IS_STATICPD_HANDLE(local)) { - nErr = AEE_EINVHANDLE; - FARF(ERROR, "Error 0x%x: %s cannot be called for staticPD handle 0x%"PRIx64"\n", - nErr, __func__, local); - goto bail; - } - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", __func__, - (int)local, sc); - VERIFYC(local != (remote_handle64)-1, AEE_EINVHANDLE); - - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(local, &domain))); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(local, &remote))); - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_invoke_domain(domain, remote, NULL, sc, pra))); +int +remote_handle_invoke(remote_handle handle, uint32_t sc, remote_arg *pra) +{ + int domain = -1, nErr = AEE_SUCCESS, ref = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %u sc %X remote_arg %p\n", + __func__, handle, sc, pra); + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", + __func__, (int)handle, sc); + VERIFYC(handle != (remote_handle)-1, AEE_EINVHANDLE); + + domain = get_current_domain(); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_invoke_domain(domain, handle, NULL, sc, + pra))); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - if (is_process_exiting(domain)) { - return 0; - } - if (0 == check_rpc_error(nErr)) { - if (get_logger_state(domain)) { - FARF(ERROR, - "Error 0x%x: %s failed for module %s, handle 0x%" PRIx64 - ", method %d on domain %d (sc 0x%x) (errno %s)\n", - nErr, __func__, h->name, local, REMOTE_SCALARS_METHOD(sc), domain, sc, - strerror(errno)); - } - } - } - FASTRPC_ATRACE_END(); - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + if(is_process_exiting(domain)) { + return 0; + } + /* + * handle_info or so name cannot be obtained from remote + * handles which are used for non-domain calls. + */ + if(0 == check_rpc_error(nErr)) { + if(get_logger_state(domain)) { + FARF(ERROR, + "Error 0x%x: %s failed for handle 0x%x, " + "method %d on domain %d " + "(sc 0x%x) (errno %s)\n", + nErr, __func__, (int)handle, + REMOTE_SCALARS_METHOD(sc), domain, sc, + strerror(errno)); + } + } + } + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle_invoke_async(remote_handle handle, - fastrpc_async_descriptor_t *desc, uint32_t sc, - remote_arg *pra) { - int domain = -1, nErr = AEE_SUCCESS, ref = 0; +int +remote_handle64_invoke(remote_handle64 local, uint32_t sc, remote_arg *pra) +{ + remote_handle64 remote = 0; + int nErr = AEE_SUCCESS, domain = -1, ref = 0; + struct handle_info *h = (struct handle_info *)local; + + if(IS_STATICPD_HANDLE(local)) { + nErr = AEE_EINVHANDLE; + FARF(ERROR, + "Error 0x%x: %s cannot be called for staticPD handle " + "0x%" PRIx64 "\n", + nErr, __func__, local); + goto bail; + } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %u desc %p sc %X remote_arg %p\n", - __func__, handle, desc, sc, pra); - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", __func__, - (int)handle, sc); - VERIFYC(handle != (remote_handle)-1, AEE_EINVHANDLE); + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", + __func__, (int)local, sc); + VERIFYC(local != (remote_handle64)-1, AEE_EINVHANDLE); - domain = get_current_domain(); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_invoke_domain(domain, handle, desc, sc, pra))); + VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(local, &domain))); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(local, &remote))); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_invoke_domain(domain, remote, NULL, sc, + pra))); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: %s failed for handle 0x%x, method %d async type %d on " - "domain %d (sc 0x%x) (errno %s)\n", - nErr, __func__, (int)handle, REMOTE_SCALARS_METHOD(sc), desc->type, - domain, sc, strerror(errno)); - } - } - FASTRPC_ATRACE_END(); - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + if(is_process_exiting(domain)) { + return 0; + } + if(0 == check_rpc_error(nErr)) { + if(get_logger_state(domain)) { + FARF(ERROR, + "Error 0x%x: %s failed for module %s, " + "handle 0x%" PRIx64 + ", method %d on domain %d (sc 0x%x) " + "(errno %s)\n", + nErr, __func__, h->name, local, + REMOTE_SCALARS_METHOD(sc), domain, sc, + strerror(errno)); + } + } + } + FASTRPC_ATRACE_END(); + return nErr; +} + +int +remote_handle_invoke_async(remote_handle handle, + fastrpc_async_descriptor_t *desc, uint32_t sc, + remote_arg *pra) +{ + int domain = -1, nErr = AEE_SUCCESS, ref = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, + "Entering %s, handle %u desc %p sc %X remote_arg %p\n", __func__, + handle, desc, sc, pra); + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", + __func__, (int)handle, sc); + VERIFYC(handle != (remote_handle)-1, AEE_EINVHANDLE); + + domain = get_current_domain(); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_invoke_domain(domain, handle, desc, sc, + pra))); +bail: + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for handle 0x%x, method " + "%d async type %d on " + "domain %d (sc 0x%x) (errno %s)\n", + nErr, __func__, (int)handle, + REMOTE_SCALARS_METHOD(sc), desc->type, domain, sc, + strerror(errno)); + } + } + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle64_invoke_async(remote_handle64 local, - fastrpc_async_descriptor_t *desc, uint32_t sc, - remote_arg *pra) { - remote_handle64 remote = 0; - int nErr = AEE_SUCCESS, domain = -1, ref = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %llu desc %p sc %X remote_arg %p\n", __func__, - local, desc, sc, pra); - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", __func__, - (int)local, sc); - VERIFYC(local != (remote_handle64)-1, AEE_EINVHANDLE); - - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(local, &domain))); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(local, &remote))); - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_invoke_domain(domain, remote, desc, sc, pra))); +int +remote_handle64_invoke_async(remote_handle64 local, + fastrpc_async_descriptor_t *desc, uint32_t sc, + remote_arg *pra) +{ + remote_handle64 remote = 0; + int nErr = AEE_SUCCESS, domain = -1, ref = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, + "Entering %s, handle %llu desc %p sc %X remote_arg %p\n", + __func__, local, desc, sc, pra); + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", + __func__, (int)local, sc); + VERIFYC(local != (remote_handle64)-1, AEE_EINVHANDLE); + + VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(local, &domain))); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(local, &remote))); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_invoke_domain(domain, remote, desc, sc, + pra))); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: %s failed for handle 0x%" PRIx64 - ", method %d on domain %d (sc 0x%x) (errno %s)\n", - nErr, __func__, local, REMOTE_SCALARS_METHOD(sc), domain, sc, - strerror(errno)); - } - } - FASTRPC_ATRACE_END(); - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for handle 0x%" PRIx64 + ", method %d on domain %d (sc 0x%x) (errno %s)\n", + nErr, __func__, local, REMOTE_SCALARS_METHOD(sc), + domain, sc, strerror(errno)); + } + } + FASTRPC_ATRACE_END(); + return nErr; } int listener_android_geteventfd(int domain, int *fd); -int remote_handle_open_domain(int domain, const char *name, remote_handle *ph, - uint64_t *t_spawn, uint64_t *t_load) { - char dlerrstr[255]; - int dlerr = 0, nErr = AEE_SUCCESS; - int dev = -1; - char *pdname_uri = NULL; - int name_len = 0; - remote_handle64 handle = INVALID_HANDLE; - - FASTRPC_ATRACE_BEGIN_L("%s called with domain %d, name %s, handle 0x%x", - __func__, domain, name, ph); - /* If the total reference count exceeds one then exit the application. */ - if (total_dsp_lib_refcnt > MAX_LIB_INSTANCE_ALLOWED) { - FARF(ERROR, - "Error: aborting due to %d instances of libxdsprpc. Only %d allowed\n", - total_dsp_lib_refcnt, MAX_LIB_INSTANCE_ALLOWED); - deinit_fastrpc_dsp_lib_refcnt(); - exit(EXIT_FAILURE); - } - if (!strncmp(name, ITRANSPORT_PREFIX "geteventfd", - strlen(ITRANSPORT_PREFIX "geteventfd"))) { - FARF(RUNTIME_RPC_HIGH, "getting event fd"); - return listener_android_geteventfd(domain, (int *)ph); - } - if (!strncmp(name, ITRANSPORT_PREFIX "attachguestos", - strlen(ITRANSPORT_PREFIX "attachguestos"))) { - FARF(RUNTIME_RPC_HIGH, "setting attach mode to guestos : %d", domain); - *ph = ATTACHGUESTOS_HANDLE; - hlist[domain].dsppd = ROOT_PD; - return AEE_SUCCESS; - } - if (!strncmp(name, ITRANSPORT_PREFIX "createstaticpd", - strlen(ITRANSPORT_PREFIX "createstaticpd"))) { - FARF(RUNTIME_RPC_HIGH, "creating static pd on domain: %d", domain); - name_len = strlen(name); - VERIFYC(NULL != - (pdname_uri = (char *)malloc((name_len + 1) * sizeof(char))), - AEE_ENOMEMORY); - strlcpy(pdname_uri, name, name_len + 1); - char *pdName = pdname_uri + strlen(ITRANSPORT_PREFIX "createstaticpd:"); - - /* - * Support sessions feature for static PDs. - * For eg, the same app can call 'remote_handle64_open' with - * "createstaticpd:sensorspd&_dom=adsp&_session=0" and - * "createstaticpd:oispd&_dom=adsp&_session=1" to create a session - * on both static PDs. - */ - if (strstr(pdName, get_domain_from_id(GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain))) && - strstr(pdName, FASTRPC_SESSION_URI)) { - strlcpy(pdName, pdName, - (strlen(pdName) - - strlen(get_domain_from_id(GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain))) - - strlen(FASTRPC_SESSION1_URI) + 1)); - } else if (strstr(pdName, get_domain_from_id(domain))) { - strlcpy( - pdName, pdName, - (strlen(pdName) - strlen(get_domain_from_id(domain)) + 1)); - } - VERIFYC(MAX_DSPPD_NAMELEN > strlen(pdName), AEE_EBADPARM); - strlcpy(hlist[domain].dsppdname, pdName, strlen(pdName) + 1); - if (!strncmp(pdName, "audiopd", strlen("audiopd"))) { - *ph = AUDIOPD_HANDLE; - hlist[domain].dsppd = AUDIO_STATICPD; - } else if (!strncmp(pdName, "securepd", strlen("securepd"))) { - FARF(ALWAYS, "%s: attaching to securePD\n", __func__); - *ph = SECUREPD_HANDLE; - hlist[domain].dsppd = SECURE_STATICPD; - } else if (!strncmp(pdName, "sensorspd", strlen("sensorspd"))) { - *ph = SENSORPD_HANDLE; - hlist[domain].dsppd = SENSORS_STATICPD; - } else if (!strncmp(pdName, "rootpd", strlen("rootpd"))) { - *ph = ROOTPD_HANDLE; - hlist[domain].dsppd = GUEST_OS_SHARED; - } else if (!strncmp(pdName, "oispd", strlen("oispd"))) { - *ph = OISPD_HANDLE; - hlist[domain].dsppd = OIS_STATICPD; - } - return AEE_SUCCESS; - } - if (!strncmp(name, ITRANSPORT_PREFIX "attachuserpd", - strlen(ITRANSPORT_PREFIX "attachuserpd"))) { - FARF(RUNTIME_RPC_HIGH, "setting attach mode to userpd : %d", domain); - hlist[domain].dsppd = USERPD; - return AEE_SUCCESS; - } - PROFILE_ALWAYS(t_spawn, - VERIFY(AEE_SUCCESS == (nErr = domain_init(domain, &dev))); - VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n");); - PROFILE_ALWAYS( - t_load, - if ((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { - nErr = remotectl1_open1(handle, name, (int *)ph, dlerrstr, - sizeof(dlerrstr), &dlerr); - if (nErr) { - FARF(ALWAYS, - "Warning 0x%x: %s: remotectl1 domains not supported for domain " - "%d\n", - nErr, __func__, domain); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, - _const_remotectl1_handle, NULL, NULL); - - // Set remotectlhandle to INVALID_HANDLE, so that all subsequent calls - // are non-domain calls - hlist[domain].remotectlhandle = INVALID_HANDLE; - VERIFY(AEE_SUCCESS == - (nErr = remotectl_open(name, (int *)ph, dlerrstr, - sizeof(dlerrstr), &dlerr))); - } - } else { - VERIFY(AEE_SUCCESS == - (nErr = remotectl_open(name, (int *)ph, dlerrstr, - sizeof(dlerrstr), &dlerr))); - } VERIFY(AEE_SUCCESS == (nErr = dlerr));); +int +remote_handle_open_domain(int domain, const char *name, remote_handle *ph, + uint64_t *t_spawn, uint64_t *t_load) +{ + char dlerrstr[255]; + int dlerr = 0, nErr = AEE_SUCCESS; + int dev = -1; + char *pdname_uri = NULL; + int name_len = 0; + remote_handle64 handle = INVALID_HANDLE; + + FASTRPC_ATRACE_BEGIN_L( + "%s called with domain %d, name %s, handle 0x%x", __func__, domain, + name, ph); + /* If the total reference count exceeds one then exit the application. + */ + if(total_dsp_lib_refcnt > MAX_LIB_INSTANCE_ALLOWED) { + FARF(ERROR, + "Error: aborting due to %d instances of libxdsprpc. Only " + "%d allowed\n", + total_dsp_lib_refcnt, MAX_LIB_INSTANCE_ALLOWED); + deinit_fastrpc_dsp_lib_refcnt(); + exit(EXIT_FAILURE); + } + if(!strncmp(name, ITRANSPORT_PREFIX "geteventfd", + strlen(ITRANSPORT_PREFIX "geteventfd"))) { + FARF(RUNTIME_RPC_HIGH, "getting event fd"); + return listener_android_geteventfd(domain, (int *)ph); + } + if(!strncmp(name, ITRANSPORT_PREFIX "attachguestos", + strlen(ITRANSPORT_PREFIX "attachguestos"))) { + FARF(RUNTIME_RPC_HIGH, "setting attach mode to guestos : %d", + domain); + *ph = ATTACHGUESTOS_HANDLE; + hlist[domain].dsppd = ROOT_PD; + return AEE_SUCCESS; + } + if(!strncmp(name, ITRANSPORT_PREFIX "createstaticpd", + strlen(ITRANSPORT_PREFIX "createstaticpd"))) { + FARF(RUNTIME_RPC_HIGH, "creating static pd on domain: %d", + domain); + name_len = strlen(name); + VERIFYC(NULL + != (pdname_uri = (char *)malloc((name_len + 1) + * sizeof(char))), + AEE_ENOMEMORY); + strlcpy(pdname_uri, name, name_len + 1); + char *pdName + = pdname_uri + strlen(ITRANSPORT_PREFIX "createstaticpd:"); + + /* + * Support sessions feature for static PDs. + * For eg, the same app can call 'remote_handle64_open' with + * "createstaticpd:sensorspd&_dom=adsp&_session=0" and + * "createstaticpd:oispd&_dom=adsp&_session=1" to create a + * session on both static PDs. + */ + if(strstr(pdName, get_domain_from_id( + GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain))) + && strstr(pdName, FASTRPC_SESSION_URI)) { + strlcpy(pdName, pdName, + (strlen(pdName) + - strlen(get_domain_from_id( + GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain))) + - strlen(FASTRPC_SESSION1_URI) + 1)); + } else if(strstr(pdName, get_domain_from_id(domain))) { + strlcpy(pdName, pdName, + (strlen(pdName) + - strlen(get_domain_from_id(domain)) + 1)); + } + VERIFYC(MAX_DSPPD_NAMELEN > strlen(pdName), AEE_EBADPARM); + strlcpy(hlist[domain].dsppdname, pdName, strlen(pdName) + 1); + if(!strncmp(pdName, "audiopd", strlen("audiopd"))) { + *ph = AUDIOPD_HANDLE; + hlist[domain].dsppd = AUDIO_STATICPD; + } else if(!strncmp(pdName, "securepd", strlen("securepd"))) { + FARF(ALWAYS, "%s: attaching to securePD\n", __func__); + *ph = SECUREPD_HANDLE; + hlist[domain].dsppd = SECURE_STATICPD; + } else if(!strncmp(pdName, "sensorspd", strlen("sensorspd"))) { + *ph = SENSORPD_HANDLE; + hlist[domain].dsppd = SENSORS_STATICPD; + } else if(!strncmp(pdName, "rootpd", strlen("rootpd"))) { + *ph = ROOTPD_HANDLE; + hlist[domain].dsppd = GUEST_OS_SHARED; + } else if(!strncmp(pdName, "oispd", strlen("oispd"))) { + *ph = OISPD_HANDLE; + hlist[domain].dsppd = OIS_STATICPD; + } + return AEE_SUCCESS; + } + if(!strncmp(name, ITRANSPORT_PREFIX "attachuserpd", + strlen(ITRANSPORT_PREFIX "attachuserpd"))) { + FARF(RUNTIME_RPC_HIGH, "setting attach mode to userpd : %d", + domain); + hlist[domain].dsppd = USERPD; + return AEE_SUCCESS; + } + PROFILE_ALWAYS( + t_spawn, VERIFY(AEE_SUCCESS == (nErr = domain_init(domain, &dev))); + VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n");); + PROFILE_ALWAYS( + t_load, + if((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { + nErr = remotectl1_open1(handle, name, (int *)ph, dlerrstr, + sizeof(dlerrstr), &dlerr); + if(nErr) { + FARF(ALWAYS, + "Warning 0x%x: %s: remotectl1 domains not " + "supported for domain " + "%d\n", + nErr, __func__, domain); + fastrpc_update_module_list( + DOMAIN_LIST_DEQUEUE, domain, + _const_remotectl1_handle, NULL, NULL); + + // Set remotectlhandle to INVALID_HANDLE, so that + // all subsequent calls are non-domain calls + hlist[domain].remotectlhandle = INVALID_HANDLE; + VERIFY(AEE_SUCCESS + == (nErr = remotectl_open( + name, (int *)ph, dlerrstr, + sizeof(dlerrstr), &dlerr))); + } + } else { + VERIFY( + AEE_SUCCESS + == (nErr = remotectl_open(name, (int *)ph, dlerrstr, + sizeof(dlerrstr), &dlerr))); + } VERIFY(AEE_SUCCESS == (nErr = dlerr));); bail: - if (dlerr != 0) { - FARF(ERROR, - "Error 0x%x: %s: dynamic loading failed for %s on domain %d (dlerror " - "%s) (errno %s)\n", - nErr, __func__, name, domain, dlerrstr, strerror(errno)); - } - if (pdname_uri) { - free(pdname_uri); - pdname_uri = NULL; - } - if (nErr == AEE_ECONNRESET) { - if (!hlist[domain].domainsCount && !hlist[domain].nondomainsCount) { - /* Close session if there are no open remote handles */ - hlist[domain].disable_exit_logs = 1; - domain_deinit(domain); - } - } - FASTRPC_ATRACE_END(); - return nErr; + if(dlerr != 0) { + FARF(ERROR, + "Error 0x%x: %s: dynamic loading failed for %s on domain " + "%d (dlerror " + "%s) (errno %s)\n", + nErr, __func__, name, domain, dlerrstr, strerror(errno)); + } + if(pdname_uri) { + free(pdname_uri); + pdname_uri = NULL; + } + if(nErr == AEE_ECONNRESET) { + if(!hlist[domain].domainsCount + && !hlist[domain].nondomainsCount) { + /* Close session if there are no open remote handles */ + hlist[domain].disable_exit_logs = 1; + domain_deinit(domain); + } + } + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle_open(const char *name, remote_handle *ph) { - int nErr = 0, domain = -1, ref = 0; - uint64_t t_spawn = 0, t_load = 0; - remote_handle64 local; +int +remote_handle_open(const char *name, remote_handle *ph) +{ + int nErr = 0, domain = -1, ref = 0; + uint64_t t_spawn = 0, t_load = 0; + remote_handle64 local; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - FARF(RUNTIME_RPC_HIGH, "Entering %s, name %s\n", __func__, name); - FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, name); + FARF(RUNTIME_RPC_HIGH, "Entering %s, name %s\n", __func__, name); + FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, name); - if (!name || !ph) { - FARF(ERROR, "%s: Invalid input", __func__); - return AEE_EBADPARM; - } + if(!name || !ph) { + FARF(ERROR, "%s: Invalid input", __func__); + return AEE_EBADPARM; + } - domain = get_current_domain(); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = remote_handle_open_domain(domain, name, ph, - &t_spawn, &t_load))); - fastrpc_update_module_list(NON_DOMAIN_LIST_PREPEND, domain, *ph, &local, name); + domain = get_current_domain(); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_open_domain(domain, name, ph, &t_spawn, + &t_load))); + fastrpc_update_module_list(NON_DOMAIN_LIST_PREPEND, domain, *ph, + &local, name); bail: - if (nErr) { - if (*ph) { - remote_handle64_close(*ph); - } else { - FASTRPC_PUT_REF(domain); - } - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for %s (errno %s)", nErr, __func__, name, - strerror(errno)); - } - } else { - FARF(ALWAYS, - "%s: Successfully opened handle 0x%x for %s on domain %d (spawn time " - "%" PRIu64 " us, load time %" PRIu64 " us)", - __func__, (int)(*ph), name, domain, t_spawn, t_load); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr) { + if(*ph) { + remote_handle64_close(*ph); + } else { + FASTRPC_PUT_REF(domain); + } + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, "Error 0x%x: %s failed for %s (errno %s)", + nErr, __func__, name, strerror(errno)); + } + } else { + FARF(ALWAYS, + "%s: Successfully opened handle 0x%x for %s on domain %d " + "(spawn time " + "%" PRIu64 " us, load time %" PRIu64 " us)", + __func__, (int)(*ph), name, domain, t_spawn, t_load); + } + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle64_open(const char *name, remote_handle64 *ph) { - remote_handle h = 0; - remote_handle64 remote = 0, local; - int domain = -1, nErr = 0, ref = 0; - uint64_t t_spawn = 0, t_load = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - FARF(RUNTIME_RPC_HIGH, "Entering %s, name %s\n", __func__, name); - FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, name); - - if (!name || !ph) { - FARF(ERROR, "%s: Invalid input", __func__); - return AEE_EBADPARM; - } - - domain = get_domain_from_name(name, DOMAIN_NAME_IN_URI); - VERIFYC(domain >= 0, AEE_EBADPARM); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = remote_handle_open_domain(domain, name, &h, - &t_spawn, &t_load))); - /* Returning local handle to "geteventd" call causes bad fd error when daemon - polls on it, hence return remote handle (which is the actual fd) for - "geteventd" call*/ - if (!strncmp(name, ITRANSPORT_PREFIX "geteventfd", - strlen(ITRANSPORT_PREFIX "geteventfd")) || - IS_STATICPD_HANDLE(h)) { - *ph = h; - } else { - fastrpc_update_module_list(DOMAIN_LIST_PREPEND, domain, h, &local, name); - get_handle_remote(local, &remote); - *ph = local; - } +int +remote_handle64_open(const char *name, remote_handle64 *ph) +{ + remote_handle h = 0; + remote_handle64 remote = 0, local; + int domain = -1, nErr = 0, ref = 0; + uint64_t t_spawn = 0, t_load = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + FARF(RUNTIME_RPC_HIGH, "Entering %s, name %s\n", __func__, name); + FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, name); + + if(!name || !ph) { + FARF(ERROR, "%s: Invalid input", __func__); + return AEE_EBADPARM; + } + + domain = get_domain_from_name(name, DOMAIN_NAME_IN_URI); + VERIFYC(domain >= 0, AEE_EBADPARM); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_open_domain(domain, name, &h, &t_spawn, + &t_load))); + /* Returning local handle to "geteventd" call causes bad fd error when + daemon polls on it, hence return remote handle (which is the actual + fd) for "geteventd" call*/ + if(!strncmp(name, ITRANSPORT_PREFIX "geteventfd", + strlen(ITRANSPORT_PREFIX "geteventfd")) + || IS_STATICPD_HANDLE(h)) { + *ph = h; + } else { + fastrpc_update_module_list(DOMAIN_LIST_PREPEND, domain, h, + &local, name); + get_handle_remote(local, &remote); + *ph = local; + } bail: - if (nErr) { - if (h) - remote_handle_close(h); - else - FASTRPC_PUT_REF(domain); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for %s (errno %s)\n", nErr, __func__, - name, strerror(errno)); - } - } else { - FARF(ALWAYS, - "%s: Successfully opened handle 0x%" PRIx64 " (remote 0x%" PRIx64 - ") for %s on domain %d (spawn time %" PRIu64 " us, load time %" PRIu64 - " us), num handles %u", - __func__, (*ph), remote, name, domain, t_spawn, t_load, - hlist[domain].domainsCount); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr) { + if(h) + remote_handle_close(h); + else + FASTRPC_PUT_REF(domain); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for %s (errno %s)\n", nErr, + __func__, name, strerror(errno)); + } + } else { + FARF(ALWAYS, + "%s: Successfully opened handle 0x%" PRIx64 + " (remote 0x%" PRIx64 + ") for %s on domain %d (spawn time %" PRIu64 + " us, load time %" PRIu64 " us), num handles %u", + __func__, (*ph), remote, name, domain, t_spawn, t_load, + hlist[domain].domainsCount); + } + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle_close_domain(int domain, remote_handle h) { - char *dlerrstr = NULL; - int dlerr = 0, nErr = AEE_SUCCESS; - size_t err_str_len = MAX_DLERRSTR_LEN * sizeof(char); - uint64_t t_close = 0; - remote_handle64 handle = INVALID_HANDLE; - - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x", __func__, (int)h); - VERIFYC(h != (remote_handle)-1, AEE_EINVHANDLE); - VERIFYC(NULL != (dlerrstr = (char *)calloc(1, err_str_len)), AEE_ENOMEMORY); - PROFILE_ALWAYS( - &t_close, - if ((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { - nErr = remotectl1_close1(handle, h, dlerrstr, err_str_len, &dlerr); - if (nErr) { - FARF(ALWAYS, - "Warning 0x%x: %s: remotectl1 domains not supported for domain " - "%d\n", - nErr, __func__, domain); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, - _const_remotectl1_handle, NULL, NULL); - - // Set remotectlhandle to INVALID_HANDLE, so that all subsequent calls - // are non-domain calls - hlist[domain].remotectlhandle = INVALID_HANDLE; - nErr = remotectl_close(h, dlerrstr, err_str_len, &dlerr); - } else if (nErr) - goto bail; - } else { - VERIFY(AEE_SUCCESS == - (nErr = remotectl_close(h, dlerrstr, err_str_len, &dlerr))); - } VERIFY(AEE_SUCCESS == (nErr = dlerr));); +int +remote_handle_close_domain(int domain, remote_handle h) +{ + char *dlerrstr = NULL; + int dlerr = 0, nErr = AEE_SUCCESS; + size_t err_str_len = MAX_DLERRSTR_LEN * sizeof(char); + uint64_t t_close = 0; + remote_handle64 handle = INVALID_HANDLE; + + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x", __func__, (int)h); + VERIFYC(h != (remote_handle)-1, AEE_EINVHANDLE); + VERIFYC(NULL != (dlerrstr = (char *)calloc(1, err_str_len)), + AEE_ENOMEMORY); + PROFILE_ALWAYS( + &t_close, + if((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { + nErr = remotectl1_close1(handle, h, dlerrstr, err_str_len, + &dlerr); + if(nErr) { + FARF(ALWAYS, + "Warning 0x%x: %s: remotectl1 domains not " + "supported for domain " + "%d\n", + nErr, __func__, domain); + fastrpc_update_module_list( + DOMAIN_LIST_DEQUEUE, domain, + _const_remotectl1_handle, NULL, NULL); + + // Set remotectlhandle to INVALID_HANDLE, so that + // all subsequent calls are non-domain calls + hlist[domain].remotectlhandle = INVALID_HANDLE; + nErr = remotectl_close(h, dlerrstr, err_str_len, + &dlerr); + } else if(nErr) + goto bail; + } else { + VERIFY(AEE_SUCCESS + == (nErr = remotectl_close(h, dlerrstr, err_str_len, + &dlerr))); + } VERIFY(AEE_SUCCESS == (nErr = dlerr));); bail: - if (nErr != AEE_SUCCESS) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: %s failed for handle 0x%x, domain %d (dlerr %s) (errno " - "%s)\n", - nErr, __func__, h, domain, dlerrstr, strerror(errno)); - } - } else { - FARF(RUNTIME_RPC_HIGH, "%s: closed module with handle 0x%x (skel unload time %" PRIu64 " us)", - __func__, h, t_close); - } - if (dlerrstr) { - free(dlerrstr); - dlerrstr = NULL; - } - if (domain != -1) - print_open_handles(domain); - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for handle 0x%x, domain " + "%d (dlerr %s) (errno " + "%s)\n", + nErr, __func__, h, domain, dlerrstr, + strerror(errno)); + } + } else { + FARF(RUNTIME_RPC_HIGH, + "%s: closed module with handle 0x%x (skel unload time " + "%" PRIu64 " us)", + __func__, h, t_close); + } + if(dlerrstr) { + free(dlerrstr); + dlerrstr = NULL; + } + if(domain != -1) + print_open_handles(domain); + FASTRPC_ATRACE_END(); + return nErr; } -int remote_handle_close(remote_handle h) { - int nErr = AEE_SUCCESS, domain = get_current_domain(), ref = 1; +int +remote_handle_close(remote_handle h) +{ + int nErr = AEE_SUCCESS, domain = get_current_domain(), ref = 1; - FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %lu\n", __func__, h); + FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %lu\n", __func__, h); - VERIFY(AEE_SUCCESS == (nErr = remote_handle_close_domain(domain, h))); - FASTRPC_PUT_REF(domain); - fastrpc_update_module_list(NON_DOMAIN_LIST_DEQUEUE, domain, h, NULL, NULL); + VERIFY(AEE_SUCCESS == (nErr = remote_handle_close_domain(domain, h))); + FASTRPC_PUT_REF(domain); + fastrpc_update_module_list(NON_DOMAIN_LIST_DEQUEUE, domain, h, NULL, + NULL); bail: - if (nErr != AEE_SUCCESS) { - if (is_process_exiting(domain)) { - return 0; - } - /* - * handle_info or so name cannot be obtained from remote handles which - * are used for non-domain calls. - */ - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for handle 0x%x\n", nErr, __func__, h); - } - } - return nErr; + if(nErr != AEE_SUCCESS) { + if(is_process_exiting(domain)) { + return 0; + } + /* + * handle_info or so name cannot be obtained from remote + * handles which are used for non-domain calls. + */ + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, "Error 0x%x: %s failed for handle 0x%x\n", + nErr, __func__, h); + } + } + return nErr; } -int remote_handle64_close(remote_handle64 handle) { - remote_handle64 remote = 0; - int domain = -1, nErr = AEE_SUCCESS, ref = 1; - bool start_deinit = false; - struct handle_info *hi = (struct handle_info*)handle; - - if (IS_STATICPD_HANDLE(handle)) - return AEE_SUCCESS; - FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %llu\n", __func__, handle); - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%" PRIx64 "\n", __func__, - handle); - VERIFYC(handle != (remote_handle64)-1, AEE_EINVHANDLE); - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(handle, &domain))); - VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(handle, &remote))); - set_thread_context(domain); - /* - * Terminate remote session if - * 1. there are no open non-domain handles AND - * 2. there are no open multi-domain handles, OR - * only 1 multi-domain handle is open (for perf reason, - * skip closing of it) - */ - if (hlist[domain].domainsCount <= 1 && !hlist[domain].nondomainsCount) - start_deinit = true; - /* - * If session termination is not initiated and the remote handle is valid, - * then close the remote handle on DSP. - */ - if (!start_deinit && remote) { - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_close_domain(domain, (remote_handle)remote))); - } - FARF(ALWAYS, "%s: closed module %s with handle 0x%" PRIx64 " remote handle 0x%" PRIx64 - ", num of open handles: %u", - __func__, hi->name, handle, remote, hlist[domain].domainsCount - 1); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, handle, NULL, NULL); - FASTRPC_PUT_REF(domain); +int +remote_handle64_close(remote_handle64 handle) +{ + remote_handle64 remote = 0; + int domain = -1, nErr = AEE_SUCCESS, ref = 1; + bool start_deinit = false; + struct handle_info *hi = (struct handle_info *)handle; + + if(IS_STATICPD_HANDLE(handle)) + return AEE_SUCCESS; + FARF(RUNTIME_RPC_HIGH, "Entering %s, handle %llu\n", __func__, handle); + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%" PRIx64 "\n", + __func__, handle); + VERIFYC(handle != (remote_handle64)-1, AEE_EINVHANDLE); + VERIFY(AEE_SUCCESS + == (nErr = get_domain_from_handle(handle, &domain))); + VERIFY(AEE_SUCCESS == (nErr = get_handle_remote(handle, &remote))); + set_thread_context(domain); + /* + * Terminate remote session if + * 1. there are no open non-domain handles AND + * 2. there are no open multi-domain handles, OR + * only 1 multi-domain handle is open (for perf reason, + * skip closing of it) + */ + if(hlist[domain].domainsCount <= 1 && !hlist[domain].nondomainsCount) + start_deinit = true; + /* + * If session termination is not initiated and the remote handle is + * valid, then close the remote handle on DSP. + */ + if(!start_deinit && remote) { + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_close_domain( + domain, (remote_handle)remote))); + } + FARF(ALWAYS, + "%s: closed module %s with handle 0x%" PRIx64 + " remote handle 0x%" PRIx64 ", num of open handles: %u", + __func__, hi->name, handle, remote, + hlist[domain].domainsCount - 1); + fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, handle, NULL, + NULL); + FASTRPC_PUT_REF(domain); bail: - if (nErr != AEE_EINVHANDLE && IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { - if (start_deinit) { - hlist[domain].disable_exit_logs = 1; - domain_deinit(domain); - } - if (nErr != AEE_SUCCESS) { - if (is_process_exiting(domain)) - return 0; - if (0 == check_rpc_error(nErr)) - FARF(ERROR, - "Error 0x%x: %s close module %s failed for handle 0x%" PRIx64 - " remote handle 0x%" PRIx64 " (errno %s), num of open handles: %u\n", - nErr, __func__, hi->name, handle, remote, strerror(errno), - hlist[domain].domainsCount); - } - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_EINVHANDLE && IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { + if(start_deinit) { + hlist[domain].disable_exit_logs = 1; + domain_deinit(domain); + } + if(nErr != AEE_SUCCESS) { + if(is_process_exiting(domain)) + return 0; + if(0 == check_rpc_error(nErr)) + FARF(ERROR, + "Error 0x%x: %s close module %s failed " + "for handle 0x%" PRIx64 + " remote handle 0x%" PRIx64 + " (errno %s), num of open handles: %u\n", + nErr, __func__, hi->name, handle, remote, + strerror(errno), + hlist[domain].domainsCount); + } + } + FASTRPC_ATRACE_END(); + return nErr; } -static int manage_pm_qos(int domain, remote_handle64 h, uint32_t enable, - uint32_t latency) { - return fastrpc_set_pm_qos(&hlist[domain].qos, enable, latency); +static int +manage_pm_qos(int domain, remote_handle64 h, uint32_t enable, uint32_t latency) +{ + return fastrpc_set_pm_qos(&hlist[domain].qos, enable, latency); } -static int manage_adaptive_qos(int domain, uint32_t enable) { - int nErr = AEE_SUCCESS; - remote_handle64 handle = INVALID_HANDLE; - - /* If adaptive QoS is already enabled/disabled, then just return */ - if ((enable && hlist[domain].qos.adaptive_qos) || - (!enable && !hlist[domain].qos.adaptive_qos)) - return nErr; - - if (hlist[domain].dev != -1) { - /* If session is already open on DSP, then make rpc call directly to user PD - */ - if ((handle = get_remotectl1_handle(domain)) != INVALID_HANDLE) { - nErr = remotectl1_set_param(handle, RPC_ADAPTIVE_QOS, &enable, 1); - if (nErr) { - FARF(ALWAYS, - "Warning 0x%x: %s: remotectl1 domains not supported for domain " - "%d\n", - nErr, __func__, domain); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, - _const_remotectl1_handle, NULL, NULL); - - // Set remotectlhandle to INVALID_HANDLE, so that all subsequent calls - // are non-domain calls - hlist[domain].remotectlhandle = INVALID_HANDLE; - nErr = remotectl_set_param(RPC_ADAPTIVE_QOS, &enable, 1); - } - } else { - nErr = remotectl_set_param(RPC_ADAPTIVE_QOS, &enable, 1); - } - if (nErr) { - FARF(ERROR, - "Error: %s: remotectl_set_param failed to reset adaptive QoS on DSP " - "to %d on domain %d", - __func__, enable, domain); - goto bail; - } else { - hlist[domain].qos.adaptive_qos = ((enable == RPC_ADAPTIVE_QOS) ? 1 : 0); - } - } else { - /* If session is not created already, then just set process attribute */ - hlist[domain].qos.adaptive_qos = ((enable == RPC_ADAPTIVE_QOS) ? 1 : 0); - } - - if (enable) - FARF(ALWAYS, "%s: Successfully enabled adaptive QoS on domain %d", __func__, - domain); - else - FARF(ALWAYS, "%s: Disabled adaptive QoS on domain %d", __func__, domain); +static int +manage_adaptive_qos(int domain, uint32_t enable) +{ + int nErr = AEE_SUCCESS; + remote_handle64 handle = INVALID_HANDLE; + + /* If adaptive QoS is already enabled/disabled, then just return */ + if((enable && hlist[domain].qos.adaptive_qos) + || (!enable && !hlist[domain].qos.adaptive_qos)) + return nErr; + + if(hlist[domain].dev != -1) { + /* If session is already open on DSP, then make rpc call + * directly to user PD + */ + if((handle = get_remotectl1_handle(domain)) + != INVALID_HANDLE) { + nErr = remotectl1_set_param(handle, RPC_ADAPTIVE_QOS, + &enable, 1); + if(nErr) { + FARF(ALWAYS, + "Warning 0x%x: %s: remotectl1 domains " + "not supported for domain " + "%d\n", + nErr, __func__, domain); + fastrpc_update_module_list( + DOMAIN_LIST_DEQUEUE, domain, + _const_remotectl1_handle, NULL, NULL); + + // Set remotectlhandle to INVALID_HANDLE, so + // that all subsequent calls are non-domain + // calls + hlist[domain].remotectlhandle = INVALID_HANDLE; + nErr = remotectl_set_param(RPC_ADAPTIVE_QOS, + &enable, 1); + } + } else { + nErr = remotectl_set_param(RPC_ADAPTIVE_QOS, &enable, + 1); + } + if(nErr) { + FARF(ERROR, + "Error: %s: remotectl_set_param failed to reset " + "adaptive QoS on DSP " + "to %d on domain %d", + __func__, enable, domain); + goto bail; + } else { + hlist[domain].qos.adaptive_qos + = ((enable == RPC_ADAPTIVE_QOS) ? 1 : 0); + } + } else { + /* If session is not created already, then just set process + * attribute */ + hlist[domain].qos.adaptive_qos + = ((enable == RPC_ADAPTIVE_QOS) ? 1 : 0); + } + + if(enable) + FARF(ALWAYS, + "%s: Successfully enabled adaptive QoS on domain %d", + __func__, domain); + else + FARF(ALWAYS, "%s: Disabled adaptive QoS on domain %d", + __func__, domain); bail: - return nErr; + return nErr; } -static int manage_poll_qos(int domain, remote_handle64 h, uint32_t enable, - uint32_t latency) { - int nErr = AEE_SUCCESS, dev = -1; - const unsigned int MAX_POLL_TIMEOUT = 10000; - struct fastrpc_ctrl_latency lp = {0}; - - /* Handle will be -1 in non-domains invocation. Create DSP session if - * necessary */ - if (h == INVALID_HANDLE) { - if (!hlist || (hlist && hlist[domain].dev == -1)) { - VERIFY(AEE_SUCCESS == (nErr = domain_init(domain, &dev))); - VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); - } - } - /* If the multi-domain handle is valid, then verify that session is created - * already */ - VERIFYC((hlist) && (-1 != (dev = hlist[domain].dev)), AEE_ERPC); - - // Max poll timeout allowed is 10 ms - VERIFYC(latency < MAX_POLL_TIMEOUT, AEE_EBADPARM); - - /* Update polling mode in kernel */ - lp.enable = enable; - lp.latency = latency; - nErr = ioctl_control(dev, DSPRPC_RPC_POLL, &lp); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } - - /* Update polling mode in DSP */ - if (h == INVALID_HANDLE) { - VERIFY(AEE_SUCCESS == - (nErr = adsp_current_process_poll_mode(enable, latency))); - } else { - remote_handle64 handle = get_adsp_current_process1_handle(domain); - VERIFY(AEE_SUCCESS == - (nErr = adsp_current_process1_poll_mode(handle, enable, latency))); - } - FARF(ALWAYS, - "%s: poll mode updated to %u for domain %d, handle 0x%" PRIx64 - " for timeout %u\n", - __func__, enable, domain, h, latency); +static int +manage_poll_qos(int domain, remote_handle64 h, uint32_t enable, + uint32_t latency) +{ + int nErr = AEE_SUCCESS, dev = -1; + const unsigned int MAX_POLL_TIMEOUT = 10000; + struct fastrpc_ctrl_latency lp = { 0 }; + + /* Handle will be -1 in non-domains invocation. Create DSP session if + * necessary */ + if(h == INVALID_HANDLE) { + if(!hlist || (hlist && hlist[domain].dev == -1)) { + VERIFY(AEE_SUCCESS + == (nErr = domain_init(domain, &dev))); + VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); + } + } + /* If the multi-domain handle is valid, then verify that session is + * created already */ + VERIFYC((hlist) && (-1 != (dev = hlist[domain].dev)), AEE_ERPC); + + // Max poll timeout allowed is 10 ms + VERIFYC(latency < MAX_POLL_TIMEOUT, AEE_EBADPARM); + + /* Update polling mode in kernel */ + lp.enable = enable; + lp.latency = latency; + nErr = ioctl_control(dev, DSPRPC_RPC_POLL, &lp); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } + + /* Update polling mode in DSP */ + if(h == INVALID_HANDLE) { + VERIFY(AEE_SUCCESS + == (nErr + = adsp_current_process_poll_mode(enable, latency))); + } else { + remote_handle64 handle + = get_adsp_current_process1_handle(domain); + VERIFY(AEE_SUCCESS + == (nErr = adsp_current_process1_poll_mode( + handle, enable, latency))); + } + FARF(ALWAYS, + "%s: poll mode updated to %u for domain %d, handle 0x%" PRIx64 + " for timeout %u\n", + __func__, enable, domain, h, latency); bail: - if (nErr) { - FARF(ERROR, - "Error 0x%x (errno %d): %s failed for domain %d, handle 0x%" PRIx64 - ", enable %u, timeout %u (%s)\n", - nErr, errno, __func__, domain, h, enable, latency, strerror(errno)); - } - return nErr; + if(nErr) { + FARF(ERROR, + "Error 0x%x (errno %d): %s failed for domain %d, handle " + "0x%" PRIx64 ", enable %u, timeout %u (%s)\n", + nErr, errno, __func__, domain, h, enable, latency, + strerror(errno)); + } + return nErr; } // Notify FastRPC QoS logic of activity outside of the invoke code path. // This function needs to be in this file to be able to access hlist. -void fastrpc_qos_activity(int domain) { - if (IS_VALID_EFFECTIVE_DOMAIN_ID(domain) && hlist) { - fastrpc_latency_invoke_incr(&hlist[domain].qos); - } +void +fastrpc_qos_activity(int domain) +{ + if(IS_VALID_EFFECTIVE_DOMAIN_ID(domain) && hlist) { + fastrpc_latency_invoke_incr(&hlist[domain].qos); + } } -static inline int enable_process_state_notif_on_dsp(int domain) { - int nErr = AEE_SUCCESS; - remote_handle64 notif_handle = 0; - - fastrpc_notif_domain_init(domain); - if ((notif_handle = get_adsp_current_process1_handle(domain)) != - INVALID_HANDLE) { - VERIFY(AEE_SUCCESS == - (nErr = adsp_current_process1_enable_notifications(notif_handle))); - } else { - VERIFY(AEE_SUCCESS == (nErr = adsp_current_process_enable_notifications())); - } +static inline int +enable_process_state_notif_on_dsp(int domain) +{ + int nErr = AEE_SUCCESS; + remote_handle64 notif_handle = 0; + + fastrpc_notif_domain_init(domain); + if((notif_handle = get_adsp_current_process1_handle(domain)) + != INVALID_HANDLE) { + VERIFY(AEE_SUCCESS + == (nErr = adsp_current_process1_enable_notifications( + notif_handle))); + } else { + VERIFY( + AEE_SUCCESS + == (nErr = adsp_current_process_enable_notifications())); + } bail: - return nErr; + return nErr; } /* @@ -2125,71 +2428,79 @@ static inline int enable_process_state_notif_on_dsp(int domain) { * job information returns 0 on success * */ -int get_remote_async_response(int domain, fastrpc_async_jobid *jobid, - int *result) { - int nErr = AEE_SUCCESS, dev = -1; - uint64_t *perf_kernel = NULL, *perf_dsp = NULL; - fastrpc_async_jobid job = -1; - int res = -1; - remote_handle handle = -1; - uint32_t sc = 0; - - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = domain_init(domain, &dev))); - VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); - if (IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs)) { - perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); - } - if (IS_DSP_PERF_ENABLED(hlist[domain].procattrs)) { - perf_dsp = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); - } - nErr = ioctl_invoke2_response(dev, &job, &handle, &sc, &res, perf_kernel, - perf_dsp); - if (IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle))) { - VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); - FARF(ALWAYS, - "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 " ns M:%" PRIu64 - " ns CP:%" PRIu64 " ns L:%" PRIu64 " ns G:%" PRIu64 " ns P:%" PRIu64 - " ns INV:%" PRIu64 " ns INVOKE:%" PRIu64 " ns\n", - handle, sc, perf_kernel[0], perf_kernel[1], perf_kernel[2], - perf_kernel[3], perf_kernel[4], perf_kernel[5], perf_kernel[6], - perf_kernel[7], perf_kernel[8]); - } - if (IS_DSP_PERF_ENABLED(hlist[domain].procattrs) && - (!IS_STATIC_HANDLE(handle))) { - VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); - FARF(ALWAYS, - "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 " us M:%" PRIu64 - " us G:%" PRIu64 " us INVOKE:%" PRIu64 " us P:%" PRIu64 - " us CACHE:%" PRIu64 " us UM:%" PRIu64 " us " - "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 - " us J_S_T:%" PRIu64 " us\n", - handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], perf_dsp[3], - perf_dsp[4], perf_dsp[5], perf_dsp[6], perf_dsp[7], perf_dsp[8], - perf_dsp[9], perf_dsp[10], perf_dsp[11]); - } - *jobid = job; - *result = res; +int +get_remote_async_response(int domain, fastrpc_async_jobid *jobid, int *result) +{ + int nErr = AEE_SUCCESS, dev = -1; + uint64_t *perf_kernel = NULL, *perf_dsp = NULL; + fastrpc_async_jobid job = -1; + int res = -1; + remote_handle handle = -1; + uint32_t sc = 0; + + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFY(AEE_SUCCESS == (nErr = domain_init(domain, &dev))); + VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); + if(IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs)) { + perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, + sizeof(uint64_t)); + VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); + } + if(IS_DSP_PERF_ENABLED(hlist[domain].procattrs)) { + perf_dsp + = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); + VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); + } + nErr = ioctl_invoke2_response(dev, &job, &handle, &sc, &res, + perf_kernel, perf_dsp); + if(IS_KERNEL_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle))) { + VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); + FARF(ALWAYS, + "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 + " ns M:%" PRIu64 " ns CP:%" PRIu64 " ns L:%" PRIu64 + " ns G:%" PRIu64 " ns P:%" PRIu64 " ns INV:%" PRIu64 + " ns INVOKE:%" PRIu64 " ns\n", + handle, sc, perf_kernel[0], perf_kernel[1], + perf_kernel[2], perf_kernel[3], perf_kernel[4], + perf_kernel[5], perf_kernel[6], perf_kernel[7], + perf_kernel[8]); + } + if(IS_DSP_PERF_ENABLED(hlist[domain].procattrs) + && (!IS_STATIC_HANDLE(handle))) { + VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); + FARF(ALWAYS, + "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 + " us M:%" PRIu64 " us G:%" PRIu64 " us INVOKE:%" PRIu64 + " us P:%" PRIu64 " us CACHE:%" PRIu64 " us UM:%" PRIu64 + " us " + "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 + " us J_S_T:%" PRIu64 " us\n", + handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], + perf_dsp[3], perf_dsp[4], perf_dsp[5], perf_dsp[6], + perf_dsp[7], perf_dsp[8], perf_dsp[9], perf_dsp[10], + perf_dsp[11]); + } + *jobid = job; + *result = res; bail: - if (perf_kernel) { - free(perf_kernel); - perf_kernel = NULL; - } - if (perf_dsp) { - free(perf_dsp); - perf_dsp = NULL; - } - if (nErr) { - FARF(ERROR, - "Error 0x%x: %s failed to get async response data for domain %d errno " - "%s", - nErr, __func__, domain, strerror(errno)); - } - return nErr; + if(perf_kernel) { + free(perf_kernel); + perf_kernel = NULL; + } + if(perf_dsp) { + free(perf_dsp); + perf_dsp = NULL; + } + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed to get async response data for " + "domain %d errno " + "%s", + nErr, __func__, domain, strerror(errno)); + } + return nErr; } /* fastrpc_set_qos_latency: @@ -2198,830 +2509,1016 @@ int get_remote_async_response(int domain, fastrpc_async_jobid *jobid, FastRPC driver tries to meet latency requirement but may not be guaranteed. */ -static int fastrpc_set_qos_latency(int domain, remote_handle64 h, - uint32_t latency) { - int nErr = 0; - - if (h == (remote_handle64)-1) { - nErr = adsp_current_process_setQoS(latency); - } else { - remote_handle64 handle = get_adsp_current_process1_handle(domain); - nErr = adsp_current_process1_setQoS(handle, latency); - } - return nErr; +static int +fastrpc_set_qos_latency(int domain, remote_handle64 h, uint32_t latency) +{ + int nErr = 0; + + if(h == (remote_handle64)-1) { + nErr = adsp_current_process_setQoS(latency); + } else { + remote_handle64 handle + = get_adsp_current_process1_handle(domain); + nErr = adsp_current_process1_setQoS(handle, latency); + } + return nErr; } // Notify kernel to enable/disable wakelock control between calls to DSP -static int update_kernel_wakelock_status(int domain, int dev, - uint32_t wl_enable) { - int nErr = AEE_SUCCESS; - struct fastrpc_ctrl_wakelock wl = {0}; - - wl.enable = wl_enable; - nErr = ioctl_control(dev, DSPRPC_CONTROL_WAKELOCK, &wl); - if (nErr) { - if (errno == EBADRQC || errno == ENOTTY || errno == ENXIO || - errno == EINVAL || nErr == AEE_EUNSUPPORTED) { - VERIFY_WPRINTF( - "Warning: %s: kernel does not support wakelock management (%s)", - __func__, strerror(errno)); - fastrpc_wake_lock_enable[domain] = 0; - fastrpc_wake_lock_deinit(); - return AEE_SUCCESS; - } - FARF(ERROR, - "Error 0x%x: %s failed for domain %d, dev %d, wakelock control %d " - "errno %s", - nErr, __func__, domain, dev, wl_enable, strerror(errno)); - } else - FARF(ALWAYS, - "%s: updated kernel wakelock control status to %d for domain %d", - __func__, wl_enable, domain); - return nErr; +static int +update_kernel_wakelock_status(int domain, int dev, uint32_t wl_enable) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_ctrl_wakelock wl = { 0 }; + + wl.enable = wl_enable; + nErr = ioctl_control(dev, DSPRPC_CONTROL_WAKELOCK, &wl); + if(nErr) { + if(errno == EBADRQC || errno == ENOTTY || errno == ENXIO + || errno == EINVAL || nErr == AEE_EUNSUPPORTED) { + VERIFY_WPRINTF("Warning: %s: kernel does not support " + "wakelock management (%s)", + __func__, strerror(errno)); + fastrpc_wake_lock_enable[domain] = 0; + fastrpc_wake_lock_deinit(); + return AEE_SUCCESS; + } + FARF(ERROR, + "Error 0x%x: %s failed for domain %d, dev %d, wakelock " + "control %d " + "errno %s", + nErr, __func__, domain, dev, wl_enable, strerror(errno)); + } else + FARF(ALWAYS, + "%s: updated kernel wakelock control status to %d for " + "domain %d", + __func__, wl_enable, domain); + return nErr; } // Update wakelock status in userspace and notify kernel if necessary -static int wakelock_control(int domain, remote_handle64 h, uint32_t wl_enable) { - int nErr = AEE_SUCCESS; - - if (fastrpc_wake_lock_enable[domain] == wl_enable) - goto bail; - - if (wl_enable) { - VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_lock_init())); - } else { - VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_lock_deinit())); - } - if (IS_SESSION_OPEN_ALREADY(domain)) - VERIFY(AEE_SUCCESS == (nErr = update_kernel_wakelock_status( - domain, hlist[domain].dev, wl_enable))); - fastrpc_wake_lock_enable[domain] = wl_enable; +static int +wakelock_control(int domain, remote_handle64 h, uint32_t wl_enable) +{ + int nErr = AEE_SUCCESS; + + if(fastrpc_wake_lock_enable[domain] == wl_enable) + goto bail; + + if(wl_enable) { + VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_lock_init())); + } else { + VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_lock_deinit())); + } + if(IS_SESSION_OPEN_ALREADY(domain)) + VERIFY(AEE_SUCCESS + == (nErr = update_kernel_wakelock_status( + domain, hlist[domain].dev, wl_enable))); + fastrpc_wake_lock_enable[domain] = wl_enable; bail: - if (nErr) - FARF(ERROR, "Error 0x%x: %s failed for domain %d, handle 0x%x, enable %d", - nErr, __func__, domain, h, wl_enable); - else { - if (wl_enable) - FARF(ALWAYS, "%s: enabled wakelock control for domain %d", __func__, - domain); - else - FARF(ALWAYS, "%s: disable wakelock control for domain %d", __func__, - domain); - } - return nErr; + if(nErr) + FARF(ERROR, + "Error 0x%x: %s failed for domain %d, handle 0x%x, " + "enable %d", + nErr, __func__, domain, h, wl_enable); + else { + if(wl_enable) + FARF(ALWAYS, + "%s: enabled wakelock control for domain %d", + __func__, domain); + else + FARF(ALWAYS, + "%s: disable wakelock control for domain %d", + __func__, domain); + } + return nErr; } // Make IOCTL call to kill remote process -static int fastrpc_dsp_process_clean(int domain) { - int nErr = AEE_SUCCESS, dev; - - VERIFYM(IS_SESSION_OPEN_ALREADY(domain), AEE_ERPC, - "Session not open for domain %d", domain); - dev = hlist[domain].dev; - nErr = ioctl_control(dev, DSPRPC_REMOTE_PROCESS_KILL, NULL); +static int +fastrpc_dsp_process_clean(int domain) +{ + int nErr = AEE_SUCCESS, dev; + + VERIFYM(IS_SESSION_OPEN_ALREADY(domain), AEE_ERPC, + "Session not open for domain %d", domain); + dev = hlist[domain].dev; + nErr = ioctl_control(dev, DSPRPC_REMOTE_PROCESS_KILL, NULL); bail: - if (nErr) - FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno: %s) ", nErr, - __func__, domain, strerror(errno)); - return nErr; + if(nErr) + FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno: %s) ", + nErr, __func__, domain, strerror(errno)); + return nErr; } -int remote_handle_control_domain(int domain, remote_handle64 h, uint32_t req, - void *data, uint32_t len) { - int nErr = AEE_SUCCESS; - const unsigned int POLL_MODE_PM_QOS_LATENCY = 100; - - FARF(RUNTIME_RPC_HIGH, "Entering %s, domain %d, handle %llu, req %d, data %p, size %d\n", - __func__, domain, h, req, data, len); - - switch (req) { - case DSPRPC_CONTROL_LATENCY: { - struct remote_rpc_control_latency *lp = - (struct remote_rpc_control_latency *)data; - VERIFYC(lp, AEE_EBADPARM); - VERIFYC(len == sizeof(struct remote_rpc_control_latency), AEE_EBADPARM); - - switch (lp->enable) { - /* Only one of PM QoS or adaptive QoS can be enabled */ - case RPC_DISABLE_QOS: { - VERIFY(AEE_SUCCESS == - (nErr = manage_adaptive_qos(domain, RPC_DISABLE_QOS))); - VERIFY(AEE_SUCCESS == - (nErr = manage_pm_qos(domain, h, RPC_DISABLE_QOS, lp->latency))); - VERIFY(AEE_SUCCESS == - (nErr = manage_poll_qos(domain, h, RPC_DISABLE_QOS, lp->latency))); - /* Error ignored, currently meeting qos requirement is optional. Consider - * to error out in later targets */ - fastrpc_set_qos_latency(domain, h, FASTRPC_QOS_MAX_LATENCY_USEC); - break; - } - case RPC_PM_QOS: { - VERIFY(AEE_SUCCESS == - (nErr = manage_adaptive_qos(domain, RPC_DISABLE_QOS))); - VERIFY(AEE_SUCCESS == - (nErr = manage_pm_qos(domain, h, RPC_PM_QOS, lp->latency))); - /* Error ignored, currently meeting qos requirement is optional. Consider - * to error out in later targets */ - fastrpc_set_qos_latency(domain, h, lp->latency); - break; - } - case RPC_ADAPTIVE_QOS: { - /* Disable PM QoS if enabled and then enable adaptive QoS */ - VERIFY(AEE_SUCCESS == - (nErr = manage_pm_qos(domain, h, RPC_DISABLE_QOS, lp->latency))); - VERIFY(AEE_SUCCESS == - (nErr = manage_adaptive_qos(domain, RPC_ADAPTIVE_QOS))); - /* Error ignored, currently meeting qos requirement is optional. Consider - * to error out in later targets */ - fastrpc_set_qos_latency(domain, h, lp->latency); - break; - } - case RPC_POLL_QOS: { - VERIFY(AEE_SUCCESS == - (nErr = manage_poll_qos(domain, h, RPC_POLL_QOS, lp->latency))); - - /* - * Poll QoS option also enables PM QoS to enable early response from DSP - * and stop the CPU cores from going into deep sleep low power modes. - */ - VERIFY(AEE_SUCCESS == (nErr = manage_pm_qos(domain, h, RPC_PM_QOS, - POLL_MODE_PM_QOS_LATENCY))); - break; - } - default: - nErr = AEE_EBADPARM; - FARF(ERROR, "Error: %s: Bad enable parameter %d passed for QoS control", - __func__, lp->enable); - goto bail; - } - FARF(ALWAYS, - "%s: requested QOS %d, latency %u for domain %d handle 0x%" PRIx64 - "\n", - __func__, lp->enable, lp->latency, domain, h); - break; - } - case DSPRPC_GET_DSP_INFO: { - int dev = -1; - struct remote_dsp_capability *cap = (struct remote_dsp_capability *)data; - - (void)dev; - VERIFYC(cap, AEE_EBADPARM); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(cap->domain), AEE_EBADPARM); - - nErr = fastrpc_get_cap(cap->domain, cap->attribute_ID, &cap->capability); - VERIFY(AEE_SUCCESS == nErr); - break; - } - case DSPRPC_CONTROL_WAKELOCK: { - struct remote_rpc_control_wakelock *wp = - (struct remote_rpc_control_wakelock *)data; - - VERIFYC(wp, AEE_EBADPARM); - VERIFYC(len == sizeof(struct remote_rpc_control_wakelock), AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = wakelock_control(domain, h, wp->enable))); - break; - } - case DSPRPC_GET_DOMAIN: { - remote_rpc_get_domain_t *pGet = (remote_rpc_get_domain_t *)data; - - VERIFYC(pGet, AEE_EBADPARM); - VERIFYC(len == sizeof(remote_rpc_get_domain_t), AEE_EBADPARM); - pGet->domain = domain; - break; - } - default: - nErr = AEE_EUNSUPPORTED; - FARF(RUNTIME_RPC_LOW, - "Error: %s: remote handle control called with unsupported request ID " - "%d", - __func__, req); - break; - } +int +remote_handle_control_domain(int domain, remote_handle64 h, uint32_t req, + void *data, uint32_t len) +{ + int nErr = AEE_SUCCESS; + const unsigned int POLL_MODE_PM_QOS_LATENCY = 100; + + FARF(RUNTIME_RPC_HIGH, + "Entering %s, domain %d, handle %llu, req %d, data %p, size %d\n", + __func__, domain, h, req, data, len); + + switch(req) { + case DSPRPC_CONTROL_LATENCY: { + struct remote_rpc_control_latency *lp + = (struct remote_rpc_control_latency *)data; + VERIFYC(lp, AEE_EBADPARM); + VERIFYC(len == sizeof(struct remote_rpc_control_latency), + AEE_EBADPARM); + + switch(lp->enable) { + /* Only one of PM QoS or adaptive QoS can be enabled */ + case RPC_DISABLE_QOS: { + VERIFY(AEE_SUCCESS + == (nErr = manage_adaptive_qos( + domain, RPC_DISABLE_QOS))); + VERIFY(AEE_SUCCESS + == (nErr + = manage_pm_qos(domain, h, RPC_DISABLE_QOS, + lp->latency))); + VERIFY(AEE_SUCCESS + == (nErr = manage_poll_qos(domain, h, + RPC_DISABLE_QOS, + lp->latency))); + /* Error ignored, currently meeting qos requirement is + * optional. Consider to error out in later targets */ + fastrpc_set_qos_latency(domain, h, + FASTRPC_QOS_MAX_LATENCY_USEC); + break; + } + case RPC_PM_QOS: { + VERIFY(AEE_SUCCESS + == (nErr = manage_adaptive_qos( + domain, RPC_DISABLE_QOS))); + VERIFY(AEE_SUCCESS + == (nErr = manage_pm_qos(domain, h, RPC_PM_QOS, + lp->latency))); + /* Error ignored, currently meeting qos requirement is + * optional. Consider to error out in later targets */ + fastrpc_set_qos_latency(domain, h, lp->latency); + break; + } + case RPC_ADAPTIVE_QOS: { + /* Disable PM QoS if enabled and then enable adaptive + * QoS */ + VERIFY(AEE_SUCCESS + == (nErr + = manage_pm_qos(domain, h, RPC_DISABLE_QOS, + lp->latency))); + VERIFY(AEE_SUCCESS + == (nErr = manage_adaptive_qos( + domain, RPC_ADAPTIVE_QOS))); + /* Error ignored, currently meeting qos requirement is + * optional. Consider to error out in later targets */ + fastrpc_set_qos_latency(domain, h, lp->latency); + break; + } + case RPC_POLL_QOS: { + VERIFY(AEE_SUCCESS + == (nErr = manage_poll_qos( + domain, h, RPC_POLL_QOS, lp->latency))); + + /* + * Poll QoS option also enables PM QoS to enable early + * response from DSP and stop the CPU cores from going + * into deep sleep low power modes. + */ + VERIFY(AEE_SUCCESS + == (nErr + = manage_pm_qos(domain, h, RPC_PM_QOS, + POLL_MODE_PM_QOS_LATENCY))); + break; + } + default: + nErr = AEE_EBADPARM; + FARF(ERROR, + "Error: %s: Bad enable parameter %d passed for " + "QoS control", + __func__, lp->enable); + goto bail; + } + FARF(ALWAYS, + "%s: requested QOS %d, latency %u for domain %d handle " + "0x%" PRIx64 "\n", + __func__, lp->enable, lp->latency, domain, h); + break; + } + case DSPRPC_GET_DSP_INFO: { + int dev = -1; + struct remote_dsp_capability *cap + = (struct remote_dsp_capability *)data; + + (void)dev; + VERIFYC(cap, AEE_EBADPARM); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(cap->domain), + AEE_EBADPARM); + + nErr = fastrpc_get_cap(cap->domain, cap->attribute_ID, + &cap->capability); + VERIFY(AEE_SUCCESS == nErr); + break; + } + case DSPRPC_CONTROL_WAKELOCK: { + struct remote_rpc_control_wakelock *wp + = (struct remote_rpc_control_wakelock *)data; + + VERIFYC(wp, AEE_EBADPARM); + VERIFYC(len == sizeof(struct remote_rpc_control_wakelock), + AEE_EBADPARM); + VERIFY(AEE_SUCCESS + == (nErr = wakelock_control(domain, h, wp->enable))); + break; + } + case DSPRPC_GET_DOMAIN: { + remote_rpc_get_domain_t *pGet + = (remote_rpc_get_domain_t *)data; + + VERIFYC(pGet, AEE_EBADPARM); + VERIFYC(len == sizeof(remote_rpc_get_domain_t), AEE_EBADPARM); + pGet->domain = domain; + break; + } + default: + nErr = AEE_EUNSUPPORTED; + FARF(RUNTIME_RPC_LOW, + "Error: %s: remote handle control called with " + "unsupported request ID " + "%d", + __func__, req); + break; + } bail: - if (nErr != AEE_SUCCESS) - FARF(ERROR, - "Error 0x%x: %s failed for request ID %d on domain %d (errno %s)", - nErr, __func__, req, domain, strerror(errno)); - return nErr; + if(nErr != AEE_SUCCESS) + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d on domain %d " + "(errno %s)", + nErr, __func__, req, domain, strerror(errno)); + return nErr; } -int remote_handle_control(uint32_t req, void *data, uint32_t len) { - int domain = -1, nErr = AEE_SUCCESS, ref = 0; +int +remote_handle_control(uint32_t req, void *data, uint32_t len) +{ + int domain = -1, nErr = AEE_SUCCESS, ref = 0; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - FARF(RUNTIME_HIGH, "Entering %s, req %d, data %p, size %d\n", __func__, req, - data, len); + FARF(RUNTIME_HIGH, "Entering %s, req %d, data %p, size %d\n", __func__, + req, data, len); - domain = get_current_domain(); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = remote_handle_control_domain( - domain, INVALID_HANDLE, req, data, len))); + domain = get_current_domain(); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_control_domain(domain, INVALID_HANDLE, + req, data, len))); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - } - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno %s)", + nErr, __func__, req, strerror(errno)); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno " + "%s)", + nErr, __func__, req, strerror(errno)); + } + } + return nErr; } -int remote_handle64_control(remote_handle64 handle, uint32_t req, void *data, - uint32_t len) { - int nErr = AEE_SUCCESS, domain = -1, ref = 0; +int +remote_handle64_control(remote_handle64 handle, uint32_t req, void *data, + uint32_t len) +{ + int nErr = AEE_SUCCESS, domain = -1, ref = 0; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - FARF(RUNTIME_HIGH, "Entering %s, handle %llu, req %d, data %p, size %d\n", - __func__, handle, req, data, len); + FARF(RUNTIME_HIGH, + "Entering %s, handle %llu, req %d, data %p, size %d\n", __func__, + handle, req, data, len); - VERIFY(AEE_SUCCESS == (nErr = get_domain_from_handle(handle, &domain))); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == - (nErr = remote_handle_control_domain(domain, handle, req, data, len))); + VERIFY(AEE_SUCCESS + == (nErr = get_domain_from_handle(handle, &domain))); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS + == (nErr = remote_handle_control_domain(domain, handle, req, + data, len))); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - } - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno %s)", + nErr, __func__, req, strerror(errno)); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno " + "%s)", + nErr, __func__, req, strerror(errno)); + } + } + return nErr; } -static int close_domain_session(int domain) { - QNode *pn = NULL, *pnn = NULL; - char dlerrstr[255]; - int dlerr = 0, nErr = AEE_SUCCESS; - remote_handle64 proc_handle = 0; - - FARF(ALWAYS, - "%s: user requested to close fastrpc session on domain %d, dev %d\n", - __func__, domain, hlist[domain].dev); - VERIFY(hlist[domain].dev != -1); - proc_handle = get_adsp_current_process1_handle(domain); - if (proc_handle != INVALID_HANDLE) { - adsp_current_process1_exit(proc_handle); - } else { - adsp_current_process_exit(); - } - pthread_mutex_lock(&hlist[domain].lmut); - if (!QList_IsEmpty(&hlist[domain].nql)) { - QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].nql, pn, pnn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - VERIFYC(NULL != hi, AEE_EINVHANDLE); - pthread_mutex_unlock(&hlist[domain].lmut); - remote_handle_close(hi->remote); - pthread_mutex_lock(&hlist[domain].lmut); - } - } - if (!QList_IsEmpty(&hlist[domain].rql)) { - QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].rql, pn, pnn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - VERIFYC(NULL != hi, AEE_EINVHANDLE); - pthread_mutex_unlock(&hlist[domain].lmut); - close_reverse_handle(hi->local, dlerrstr, sizeof(dlerrstr), &dlerr); - pthread_mutex_lock(&hlist[domain].lmut); - } - } - if (!QList_IsEmpty(&hlist[domain].ql)) { - QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].ql, pn, pnn) { - struct handle_info *hi = STD_RECOVER_REC(struct handle_info, qn, pn); - VERIFYC(NULL != hi, AEE_EINVHANDLE); - pthread_mutex_unlock(&hlist[domain].lmut); - remote_handle64_close(hi->local); - pthread_mutex_lock(&hlist[domain].lmut); - } - } - pthread_mutex_unlock(&hlist[domain].lmut); +static int +close_domain_session(int domain) +{ + QNode *pn = NULL, *pnn = NULL; + char dlerrstr[255]; + int dlerr = 0, nErr = AEE_SUCCESS; + remote_handle64 proc_handle = 0; + + FARF(ALWAYS, + "%s: user requested to close fastrpc session on domain %d, dev " + "%d\n", + __func__, domain, hlist[domain].dev); + VERIFY(hlist[domain].dev != -1); + proc_handle = get_adsp_current_process1_handle(domain); + if(proc_handle != INVALID_HANDLE) { + adsp_current_process1_exit(proc_handle); + } else { + adsp_current_process_exit(); + } + pthread_mutex_lock(&hlist[domain].lmut); + if(!QList_IsEmpty(&hlist[domain].nql)) { + QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].nql, pn, pnn) + { + struct handle_info *hi + = STD_RECOVER_REC(struct handle_info, qn, pn); + VERIFYC(NULL != hi, AEE_EINVHANDLE); + pthread_mutex_unlock(&hlist[domain].lmut); + remote_handle_close(hi->remote); + pthread_mutex_lock(&hlist[domain].lmut); + } + } + if(!QList_IsEmpty(&hlist[domain].rql)) { + QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].rql, pn, pnn) + { + struct handle_info *hi + = STD_RECOVER_REC(struct handle_info, qn, pn); + VERIFYC(NULL != hi, AEE_EINVHANDLE); + pthread_mutex_unlock(&hlist[domain].lmut); + close_reverse_handle(hi->local, dlerrstr, + sizeof(dlerrstr), &dlerr); + pthread_mutex_lock(&hlist[domain].lmut); + } + } + if(!QList_IsEmpty(&hlist[domain].ql)) { + QLIST_NEXTSAFE_FOR_ALL(&hlist[domain].ql, pn, pnn) + { + struct handle_info *hi + = STD_RECOVER_REC(struct handle_info, qn, pn); + VERIFYC(NULL != hi, AEE_EINVHANDLE); + pthread_mutex_unlock(&hlist[domain].lmut); + remote_handle64_close(hi->local); + pthread_mutex_lock(&hlist[domain].lmut); + } + } + pthread_mutex_unlock(&hlist[domain].lmut); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno %s)", nErr, - __func__, domain, strerror(errno)); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno %s)", + nErr, __func__, domain, strerror(errno)); + } + return nErr; } -int get_unsigned_pd_attribute(uint32_t domain, int *unsigned_module) { - int nErr = AEE_SUCCESS; +int +get_unsigned_pd_attribute(uint32_t domain, int *unsigned_module) +{ + int nErr = AEE_SUCCESS; - VERIFYC(hlist, AEE_EBADPARM); - VERIFYC(unsigned_module, AEE_EBADPARM); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - *unsigned_module = hlist[domain].unsigned_module; + VERIFYC(hlist, AEE_EBADPARM); + VERIFYC(unsigned_module, AEE_EBADPARM); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + *unsigned_module = hlist[domain].unsigned_module; bail: - return nErr; + return nErr; } -static int set_unsigned_pd_attribute(int domain, int enable) { - int nErr = AEE_SUCCESS; - - VERIFYC(hlist, AEE_EBADPARM); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - if (hlist[domain].dev != -1) { - if (hlist[domain].unsigned_module == enable) { - FARF(HIGH, "%s: %s session already open on domain %d , enable %d ", - __func__, hlist[domain].unsigned_module ? "Unsigned" : "Signed", - domain, enable); - } else { - nErr = AEE_EALREADYLOADED; - FARF(ERROR, - "Error 0x%x: %s: %s session already open on domain %d , enable %d ", - nErr, __func__, - hlist[domain].unsigned_module ? "Unsigned" : "Signed", domain, - enable); - } - goto bail; - } - hlist[domain].unsigned_module = enable ? 1 : 0; +static int +set_unsigned_pd_attribute(int domain, int enable) +{ + int nErr = AEE_SUCCESS; + + VERIFYC(hlist, AEE_EBADPARM); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + if(hlist[domain].dev != -1) { + if(hlist[domain].unsigned_module == enable) { + FARF(HIGH, + "%s: %s session already open on domain %d , " + "enable %d ", + __func__, + hlist[domain].unsigned_module ? "Unsigned" + : "Signed", + domain, enable); + } else { + nErr = AEE_EALREADYLOADED; + FARF(ERROR, + "Error 0x%x: %s: %s session already open on " + "domain %d , enable %d ", + nErr, __func__, + hlist[domain].unsigned_module ? "Unsigned" + : "Signed", + domain, enable); + } + goto bail; + } + hlist[domain].unsigned_module = enable ? 1 : 0; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, __func__, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, + __func__, domain); + } + return nErr; } -static int store_domain_thread_params(int domain, int thread_priority, - int stack_size) { - int nErr = AEE_SUCCESS; - - VERIFYC(hlist, AEE_EBADPARM); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - if (thread_priority != -1) { - if ((thread_priority < MIN_THREAD_PRIORITY) || - (thread_priority > MAX_THREAD_PRIORITY)) { - nErr = AEE_EBADPARM; - FARF(ERROR, - "%s: Thread priority %d is invalid! Should be between %d and %d", - __func__, thread_priority, MIN_THREAD_PRIORITY, MAX_THREAD_PRIORITY); - goto bail; - } else { - hlist[domain].th_params.thread_priority = (uint32_t)thread_priority; - } - } - if (stack_size != -1) { - if ((stack_size < MIN_UTHREAD_STACK_SIZE) || - (stack_size > MAX_UTHREAD_STACK_SIZE)) { - nErr = AEE_EBADPARM; - FARF(ERROR, "%s: Stack size %d is invalid! Should be between %d and %d", - __func__, stack_size, MIN_UTHREAD_STACK_SIZE, - MAX_UTHREAD_STACK_SIZE); - goto bail; - } else - hlist[domain].th_params.stack_size = (uint32_t)stack_size; - } - hlist[domain].th_params.reqID = FASTRPC_THREAD_PARAMS; - hlist[domain].th_params.update_requested = 1; - if (hlist[domain].dev != -1) { - VERIFY(AEE_SUCCESS == (nErr = fastrpc_set_remote_uthread_params(domain))); - FARF(ALWAYS, - "Dynamically set remote user thread priority to %d and stack size to " - "%d for domain %d", - thread_priority, stack_size, domain); - } +static int +store_domain_thread_params(int domain, int thread_priority, int stack_size) +{ + int nErr = AEE_SUCCESS; + + VERIFYC(hlist, AEE_EBADPARM); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + if(thread_priority != -1) { + if((thread_priority < MIN_THREAD_PRIORITY) + || (thread_priority > MAX_THREAD_PRIORITY)) { + nErr = AEE_EBADPARM; + FARF(ERROR, + "%s: Thread priority %d is invalid! Should be " + "between %d and %d", + __func__, thread_priority, MIN_THREAD_PRIORITY, + MAX_THREAD_PRIORITY); + goto bail; + } else { + hlist[domain].th_params.thread_priority + = (uint32_t)thread_priority; + } + } + if(stack_size != -1) { + if((stack_size < MIN_UTHREAD_STACK_SIZE) + || (stack_size > MAX_UTHREAD_STACK_SIZE)) { + nErr = AEE_EBADPARM; + FARF(ERROR, + "%s: Stack size %d is invalid! Should be between " + "%d and %d", + __func__, stack_size, MIN_UTHREAD_STACK_SIZE, + MAX_UTHREAD_STACK_SIZE); + goto bail; + } else + hlist[domain].th_params.stack_size + = (uint32_t)stack_size; + } + hlist[domain].th_params.reqID = FASTRPC_THREAD_PARAMS; + hlist[domain].th_params.update_requested = 1; + if(hlist[domain].dev != -1) { + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_set_remote_uthread_params(domain))); + FARF(ALWAYS, + "Dynamically set remote user thread priority to %d and " + "stack size to " + "%d for domain %d", + thread_priority, stack_size, domain); + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for domain %d for thread priority %d, stack " - "size %d", - nErr, __func__, domain, thread_priority, stack_size); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for domain %d for thread priority " + "%d, stack " + "size %d", + nErr, __func__, domain, thread_priority, stack_size); + } + return nErr; } /* Set attribute to enable/disable pd dump */ -static int set_pd_dump_attribute(int domain, int enable) { - int nErr = AEE_SUCCESS; - - VERIFYC(hlist, AEE_ERPC); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - if (hlist[domain].dev != -1) { - nErr = AEE_ERPC; - FARF(ERROR, - "%s: Session already open on domain %d ! Request unsigned offload " - "before making any RPC calls", - __func__, domain); - goto bail; - } - hlist[domain].pd_dump = enable ? true : false; +static int +set_pd_dump_attribute(int domain, int enable) +{ + int nErr = AEE_SUCCESS; + + VERIFYC(hlist, AEE_ERPC); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + if(hlist[domain].dev != -1) { + nErr = AEE_ERPC; + FARF(ERROR, + "%s: Session already open on domain %d ! Request " + "unsigned offload " + "before making any RPC calls", + __func__, domain); + goto bail; + } + hlist[domain].pd_dump = enable ? true : false; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed to enable %d for domain %d", nErr, - __func__, enable, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed to enable %d for domain %d", + nErr, __func__, enable, domain); + } + return nErr; } /* Set userpd memlen for a requested domain */ -static int store_domain_pd_initmem_size(int domain, uint32_t pd_initmem_size) { - int nErr = AEE_SUCCESS; - - if ((pd_initmem_size < MIN_PD_INITMEM_SIZE) || - (pd_initmem_size > MAX_PD_INITMEM_SIZE)) { - nErr = AEE_EBADPARM; - goto bail; - } else { - hlist[domain].pd_initmem_size = pd_initmem_size; - } +static int +store_domain_pd_initmem_size(int domain, uint32_t pd_initmem_size) +{ + int nErr = AEE_SUCCESS; + + if((pd_initmem_size < MIN_PD_INITMEM_SIZE) + || (pd_initmem_size > MAX_PD_INITMEM_SIZE)) { + nErr = AEE_EBADPARM; + goto bail; + } else { + hlist[domain].pd_initmem_size = pd_initmem_size; + } bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for domain %d for pd init mem size :0x%x", nErr, - __func__, domain, pd_initmem_size); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for domain %d for pd init mem " + "size :0x%x", + nErr, __func__, domain, pd_initmem_size); + } + return nErr; } -/* Set remote session parameters like thread stack size, running on unsigned PD, - * killing remote process PD etc */ -int remote_session_control(uint32_t req, void *data, uint32_t datalen) { - int nErr = AEE_SUCCESS, domain = DEFAULT_DOMAIN_ID, ref = 0, ii = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FARF(RUNTIME_RPC_HIGH, "Entering %s, req %d, data %p, size %d\n", __func__, req, data, - datalen); - FASTRPC_GET_REF(domain); - switch (req) { - case FASTRPC_THREAD_PARAMS: { - struct remote_rpc_thread_params *params = - (struct remote_rpc_thread_params *)data; - if (!params) { - nErr = AEE_EBADPARM; - FARF(RUNTIME_RPC_LOW, "%s: Thread params struct passed is %p", __func__, - params); - goto bail; - } - VERIFYC(datalen == sizeof(struct remote_rpc_thread_params), AEE_EBADPARM); - if (params->domain != -1) { - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain)) { - nErr = AEE_EBADPARM; - FARF(RUNTIME_RPC_LOW, "%s: Invalid domain ID %d passed", __func__, - params->domain); - goto bail; - } - VERIFY(AEE_SUCCESS == - (nErr = store_domain_thread_params(params->domain, params->prio, - params->stack_size))); - } else { - /* If domain is -1, then set parameters for all domains */ - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFY(AEE_SUCCESS == (nErr = store_domain_thread_params( - ii, params->prio, params->stack_size))); - } - } - FARF(ALWAYS, - "%s DSP info request for domain %d, thread priority %d, stack size %d", - __func__, params->domain, params->prio, params->stack_size); - break; - } - case DSPRPC_CONTROL_UNSIGNED_MODULE: { - // Handle the unsigned module offload request - struct remote_rpc_control_unsigned_module *um = - (struct remote_rpc_control_unsigned_module *)data; - VERIFYC(datalen == sizeof(struct remote_rpc_control_unsigned_module), - AEE_EBADPARM); - VERIFYC(um != NULL, AEE_EBADPARM); - if (um->domain != -1) { - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(um->domain), - AEE_EBADPARM); - VERIFY(AEE_SUCCESS == - (nErr = set_unsigned_pd_attribute(um->domain, um->enable))); - } else { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFY(AEE_SUCCESS == - (nErr = set_unsigned_pd_attribute(ii, um->enable))); - } - } - FARF(ALWAYS, "%s Unsigned PD enable %d request for domain %d", __func__, - um->enable, um->domain); - break; - } - case FASTRPC_RELATIVE_THREAD_PRIORITY: { - int thread_priority = DEFAULT_UTHREAD_PRIORITY, rel_thread_prio = 0; - struct remote_rpc_relative_thread_priority *params = - (struct remote_rpc_relative_thread_priority *)data; - - VERIFYC(datalen == sizeof(struct remote_rpc_relative_thread_priority), - AEE_EBADPARM); - VERIFYC(params, AEE_EBADPARM); - rel_thread_prio = params->relative_thread_priority; - - // handle thread priority overflow and out-of-range conditions - if (rel_thread_prio < 0) { - thread_priority = ((~rel_thread_prio) >= DEFAULT_UTHREAD_PRIORITY - 1) - ? MIN_THREAD_PRIORITY - : (thread_priority + rel_thread_prio); - } else { - thread_priority = - (rel_thread_prio > (MAX_THREAD_PRIORITY - DEFAULT_UTHREAD_PRIORITY)) - ? MAX_THREAD_PRIORITY - : (thread_priority + rel_thread_prio); - } - if (params->domain != -1) { - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain), - AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = store_domain_thread_params( - params->domain, thread_priority, -1))); - } else { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFY(AEE_SUCCESS == - (nErr = store_domain_thread_params(ii, thread_priority, -1))); - } - } - FARF(ALWAYS, "%s DSP thread priority request for domain %d, priority %d", - __func__, req, params->domain, thread_priority); - break; - } - case FASTRPC_REMOTE_PROCESS_KILL: { - struct remote_rpc_process_clean_params *dp = - (struct remote_rpc_process_clean_params *)data; - - VERIFYC(datalen == sizeof(struct remote_rpc_process_clean_params), - AEE_EBADPARM); - VERIFYC(dp, AEE_EBADPARM); - domain = dp->domain; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_dsp_process_clean(domain))); - FARF(ALWAYS, "%s Remote process kill request for domain %d", __func__, - domain); - break; - } - case FASTRPC_SESSION_CLOSE: { - struct remote_rpc_session_close *sclose = - (struct remote_rpc_session_close *)data; - if (!sclose) { - nErr = AEE_EBADPARM; - FARF(RUNTIME_RPC_LOW, - "Error: %s: session close data pointer passed is NULL\n", __func__); - goto bail; - } - VERIFYC(datalen == sizeof(struct remote_rpc_session_close), AEE_EBADPARM); - if (sclose->domain != -1) { - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(sclose->domain), - AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = close_domain_session(sclose->domain))); - } else { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFY(AEE_SUCCESS == (nErr = close_domain_session(ii))); - } - } - FARF(ALWAYS, "%s Fastrpc session close request for domain %d\n", __func__, - sclose->domain); - break; - } - case FASTRPC_CONTROL_PD_DUMP: { - // Handle pd dump enable/disable request - struct remote_rpc_control_pd_dump *pddump = - (struct remote_rpc_control_pd_dump *)data; - VERIFYC(datalen == sizeof(struct remote_rpc_control_pd_dump), AEE_EBADPARM); - VERIFYC(pddump != NULL, AEE_EBADPARM); - if (pddump->domain != -1) { - VERIFY(AEE_SUCCESS == - (nErr = set_pd_dump_attribute(pddump->domain, pddump->enable))); - } else { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFY(AEE_SUCCESS == - (nErr = set_pd_dump_attribute(ii, pddump->enable))); - } - } - FARF(ALWAYS, "%s PD dump request to enable(%d) for domain %d", __func__, - pddump->enable, pddump->domain); - break; - } - case FASTRPC_REMOTE_PROCESS_EXCEPTION: { - // Trigger non fatal exception in the User PD of DSP. - remote_rpc_process_exception *dp = (remote_rpc_process_exception *)data; - remote_handle64 handle = 0; - int ret = 0; - - VERIFYC(datalen == sizeof(remote_rpc_process_exception), AEE_EBADPARM); - VERIFYC(dp, AEE_EBADPARM); - domain = dp->domain; - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - /* - * If any request causes exception on DSP, DSP returns AEE_EBADSTATE for the - * request thread. - */ - if ((handle = get_adsp_current_process1_handle(domain)) != INVALID_HANDLE) { - ret = adsp_current_process1_exception(handle); - } else { - ret = adsp_current_process_exception(); - } - ret = (ret == AEE_SUCCESS) ? AEE_ERPC : ret; - VERIFYC(ret == (int)(DSP_AEE_EOFFSET + AEE_EBADSTATE), ret); - FARF(ALWAYS, - "%s Remote process exception request for domain %d, handle 0x%" PRIx64 - "\n", - __func__, domain, handle); - break; - } - case FASTRPC_REMOTE_PROCESS_TYPE: { - struct remote_process_type *typ = (struct remote_process_type *)data; - int ret_val = -1; - VERIFYC(datalen == sizeof(struct remote_process_type), AEE_EBADPARM); - VERIFYC(typ, AEE_EBADPARM); - domain = typ->domain; - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - ret_val = hlist[domain].unsigned_module; - if (ret_val != PROCESS_TYPE_UNSIGNED && ret_val != PROCESS_TYPE_SIGNED) { - typ->process_type = -1; - nErr = AEE_EBADPARM; - } else { - typ->process_type = ret_val; - } - break; - } - case FASTRPC_REGISTER_STATUS_NOTIFICATIONS: { - // Handle DSP PD notification request - struct remote_rpc_notif_register *notif = - (struct remote_rpc_notif_register *)data; - VERIFYC(datalen == sizeof(struct remote_rpc_notif_register), AEE_EBADPARM); - VERIFYC(notif != NULL, AEE_EBADPARM); - domain = notif->domain; - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - if (domain != -1) { - VERIFYC(is_status_notif_version2_supported(domain), AEE_EUNSUPPORTED); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_notif_register(domain, notif))); - } else { - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - VERIFYC(is_status_notif_version2_supported(ii), AEE_EUNSUPPORTED); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_notif_register(ii, notif))); - } - } - FARF(RUNTIME_RPC_HIGH, "%s Register PD status notification request for domain %d\n", - __func__, domain); - break; - } - case FASTRPC_PD_INITMEM_SIZE: { - // Handle DSP User PD init memory size request - struct remote_rpc_pd_initmem_size *params = - (struct remote_rpc_pd_initmem_size *)data; - VERIFYC(datalen == sizeof(struct remote_rpc_pd_initmem_size), AEE_EBADPARM); - VERIFYC(params != NULL, AEE_EBADPARM); - if (params->domain != -1) { - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain)) { - nErr = AEE_EBADPARM; - FARF(ERROR, "%s: Invalid domain ID %d passed", __func__, - params->domain); - goto bail; - } - if (hlist[params->domain].unsigned_module) { - nErr = AEE_EUNSUPPORTED; - FARF(ERROR, "Configuring User PD init mem length is not supported for " - "unsigned PDs"); - goto bail; - } - VERIFY(AEE_SUCCESS == (nErr = store_domain_pd_initmem_size( - params->domain, params->pd_initmem_size))); - } else { - /* If domain is -1, then set parameters for all domains */ - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - if (hlist[ii].unsigned_module) { - FARF(ALWAYS, - "Warning: %s: Configuring User PD init mem length for domain %d " - "is not supported for unsigned PDs", - __func__, ii); - } else { - VERIFY(AEE_SUCCESS == (nErr = store_domain_pd_initmem_size( - ii, params->pd_initmem_size))); - } - } - } - FARF(ALWAYS, - "%s DSP userpd memlen request for domain %d, userpd memlen 0x%x", - __func__, params->domain, params->pd_initmem_size); - break; - } - case FASTRPC_RESERVE_NEW_SESSION: { - remote_rpc_reserve_new_session_t *sess = - (remote_rpc_reserve_new_session_t *)data; - int ii = 0, jj = 0; - - VERIFYC(datalen == sizeof(remote_rpc_reserve_new_session_t), AEE_EBADPARM); - VERIFYC(sess && sess->domain_name != NULL && sess->domain_name_len > 0 && - sess->session_name && sess->session_name_len > 0, - AEE_EBADPARM); - domain = get_domain_from_name(sess->domain_name, DOMAIN_NAME_STAND_ALONE); - VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); - // Initialize effective domain ID to 2nd session of domain, first session is - // default usage and cannot be reserved - ii = domain + NUM_DOMAINS; - // Initialize session to 1, session 0 is default session - jj = 1; - // Set effective_domain_id and session_id to invalid IDs - sess->effective_domain_id = NUM_DOMAINS_EXTEND; - sess->session_id = NUM_SESSIONS; - do { - pthread_mutex_lock(&hlist[ii].init); - if (!hlist[ii].is_session_reserved) { - hlist[ii].is_session_reserved = true; - sess->effective_domain_id = ii; - sess->session_id = jj; - strlcpy(hlist[ii].sessionname, sess->session_name, - STD_MIN(sess->session_name_len, (MAX_DSPPD_NAMELEN - 1))); - pthread_mutex_unlock(&hlist[ii].init); - break; - } - pthread_mutex_unlock(&hlist[ii].init); - // Increment to next session of domain - ii = ii + NUM_DOMAINS; - // Increment the session - jj++; - } while (IS_VALID_EFFECTIVE_DOMAIN_ID(ii)); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(sess->effective_domain_id), AEE_ENOSESSION); - break; - } - case FASTRPC_GET_EFFECTIVE_DOMAIN_ID: { - remote_rpc_effective_domain_id_t *effec_domain_id = - (remote_rpc_effective_domain_id_t *)data; - VERIFYC(datalen == sizeof(remote_rpc_effective_domain_id_t), AEE_EBADPARM); - VERIFYC(effec_domain_id && effec_domain_id->domain_name && - effec_domain_id->domain_name_len > 0 && - effec_domain_id->session_id < NUM_SESSIONS, - AEE_EBADPARM); - domain = get_domain_from_name(effec_domain_id->domain_name, - DOMAIN_NAME_STAND_ALONE); - VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); - effec_domain_id->effective_domain_id = - GET_EFFECTIVE_DOMAIN_ID(domain, effec_domain_id->session_id); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(effec_domain_id->effective_domain_id), - AEE_ENOSESSION); - break; - } - case FASTRPC_GET_URI: { - remote_rpc_get_uri_t *rpc_uri = (remote_rpc_get_uri_t *)data; - int ret_val = -1; - - VERIFYC(datalen == sizeof(remote_rpc_get_uri_t), AEE_EBADPARM); - VERIFYC(rpc_uri && rpc_uri->domain_name && rpc_uri->domain_name_len > 0 && - rpc_uri->session_id < NUM_SESSIONS, - AEE_EBADPARM); - domain = - get_domain_from_name(rpc_uri->domain_name, DOMAIN_NAME_STAND_ALONE); - VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC(rpc_uri->module_uri != NULL && rpc_uri->module_uri_len > 0, - AEE_EBADPARM); - VERIFYC(rpc_uri->uri != NULL && rpc_uri->uri_len > rpc_uri->module_uri_len, - AEE_EBADPARM); - ret_val = snprintf(0, 0, "%s%s%s%s%d", rpc_uri->module_uri, - FASTRPC_DOMAIN_URI, SUBSYSTEM_NAME[domain], - FASTRPC_SESSION_URI, rpc_uri->session_id); - if (rpc_uri->uri_len <= ret_val) { - nErr = AEE_EBADSIZE; - FARF(ERROR, - "ERROR 0x%x: %s Session URI length %u is not enough, need %u " - "characters", - nErr, __func__, rpc_uri->uri_len, ret_val); - } - ret_val = snprintf(rpc_uri->uri, rpc_uri->uri_len, "%s%s%s%s%d", - rpc_uri->module_uri, FASTRPC_DOMAIN_URI, - SUBSYSTEM_NAME[domain], FASTRPC_SESSION_URI, - rpc_uri->session_id); - if (ret_val < 0) { - nErr = AEE_EBADSIZE; - FARF(ERROR, "ERROR 0x%x: %s Invalid Session URI length %u", nErr, - __func__, rpc_uri->uri_len); - } - break; - } - case FASTRPC_CONTEXT_CREATE: - VERIFYC(datalen == sizeof(fastrpc_context_create) - && data, AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_create_context(data))); - break; - case FASTRPC_CONTEXT_DESTROY: - { - fastrpc_context_destroy *dest = (fastrpc_context_destroy *)data; - - VERIFYC(datalen == sizeof(fastrpc_context_destroy) - && dest && !dest->flags, AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_destroy_context(dest->ctx))); - break; - } - default: - nErr = AEE_EUNSUPPORTED; - FARF(ERROR, "ERROR 0x%x: %s Unsupported request ID %d", nErr, __func__, - req); - break; - } +/* Set remote session parameters like thread stack size, running on unsigned + * PD, killing remote process PD etc */ +int +remote_session_control(uint32_t req, void *data, uint32_t datalen) +{ + int nErr = AEE_SUCCESS, domain = DEFAULT_DOMAIN_ID, ref = 0, ii = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, "Entering %s, req %d, data %p, size %d\n", + __func__, req, data, datalen); + FASTRPC_GET_REF(domain); + switch(req) { + case FASTRPC_THREAD_PARAMS: { + struct remote_rpc_thread_params *params + = (struct remote_rpc_thread_params *)data; + if(!params) { + nErr = AEE_EBADPARM; + FARF(RUNTIME_RPC_LOW, + "%s: Thread params struct passed is %p", __func__, + params); + goto bail; + } + VERIFYC(datalen == sizeof(struct remote_rpc_thread_params), + AEE_EBADPARM); + if(params->domain != -1) { + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain)) { + nErr = AEE_EBADPARM; + FARF(RUNTIME_RPC_LOW, + "%s: Invalid domain ID %d passed", + __func__, params->domain); + goto bail; + } + VERIFY(AEE_SUCCESS + == (nErr = store_domain_thread_params( + params->domain, params->prio, + params->stack_size))); + } else { + /* If domain is -1, then set parameters for all domains + */ + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFY(AEE_SUCCESS + == (nErr = store_domain_thread_params( + ii, params->prio, + params->stack_size))); + } + } + FARF(ALWAYS, + "%s DSP info request for domain %d, thread priority %d, " + "stack size %d", + __func__, params->domain, params->prio, + params->stack_size); + break; + } + case DSPRPC_CONTROL_UNSIGNED_MODULE: { + // Handle the unsigned module offload request + struct remote_rpc_control_unsigned_module *um + = (struct remote_rpc_control_unsigned_module *)data; + VERIFYC( + datalen + == sizeof(struct remote_rpc_control_unsigned_module), + AEE_EBADPARM); + VERIFYC(um != NULL, AEE_EBADPARM); + if(um->domain != -1) { + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(um->domain), + AEE_EBADPARM); + VERIFY(AEE_SUCCESS + == (nErr = set_unsigned_pd_attribute( + um->domain, um->enable))); + } else { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFY(AEE_SUCCESS + == (nErr = set_unsigned_pd_attribute( + ii, um->enable))); + } + } + FARF(ALWAYS, "%s Unsigned PD enable %d request for domain %d", + __func__, um->enable, um->domain); + break; + } + case FASTRPC_RELATIVE_THREAD_PRIORITY: { + int thread_priority = DEFAULT_UTHREAD_PRIORITY, + rel_thread_prio = 0; + struct remote_rpc_relative_thread_priority *params + = (struct remote_rpc_relative_thread_priority *)data; + + VERIFYC( + datalen + == sizeof(struct remote_rpc_relative_thread_priority), + AEE_EBADPARM); + VERIFYC(params, AEE_EBADPARM); + rel_thread_prio = params->relative_thread_priority; + + // handle thread priority overflow and out-of-range conditions + if(rel_thread_prio < 0) { + thread_priority + = ((~rel_thread_prio) + >= DEFAULT_UTHREAD_PRIORITY - 1) + ? MIN_THREAD_PRIORITY + : (thread_priority + rel_thread_prio); + } else { + thread_priority + = (rel_thread_prio > (MAX_THREAD_PRIORITY + - DEFAULT_UTHREAD_PRIORITY)) + ? MAX_THREAD_PRIORITY + : (thread_priority + rel_thread_prio); + } + if(params->domain != -1) { + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain), + AEE_EBADPARM); + VERIFY(AEE_SUCCESS + == (nErr = store_domain_thread_params( + params->domain, thread_priority, -1))); + } else { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFY(AEE_SUCCESS + == (nErr = store_domain_thread_params( + ii, thread_priority, -1))); + } + } + FARF(ALWAYS, + "%s DSP thread priority request for domain %d, priority " + "%d", + __func__, req, params->domain, thread_priority); + break; + } + case FASTRPC_REMOTE_PROCESS_KILL: { + struct remote_rpc_process_clean_params *dp + = (struct remote_rpc_process_clean_params *)data; + + VERIFYC(datalen + == sizeof(struct remote_rpc_process_clean_params), + AEE_EBADPARM); + VERIFYC(dp, AEE_EBADPARM); + domain = dp->domain; + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_dsp_process_clean(domain))); + FARF(ALWAYS, "%s Remote process kill request for domain %d", + __func__, domain); + break; + } + case FASTRPC_SESSION_CLOSE: { + struct remote_rpc_session_close *sclose + = (struct remote_rpc_session_close *)data; + if(!sclose) { + nErr = AEE_EBADPARM; + FARF(RUNTIME_RPC_LOW, + "Error: %s: session close data pointer passed is " + "NULL\n", + __func__); + goto bail; + } + VERIFYC(datalen == sizeof(struct remote_rpc_session_close), + AEE_EBADPARM); + if(sclose->domain != -1) { + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(sclose->domain), + AEE_EBADPARM); + VERIFY( + AEE_SUCCESS + == (nErr = close_domain_session(sclose->domain))); + } else { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFY(AEE_SUCCESS + == (nErr = close_domain_session(ii))); + } + } + FARF(ALWAYS, + "%s Fastrpc session close request for domain %d\n", + __func__, sclose->domain); + break; + } + case FASTRPC_CONTROL_PD_DUMP: { + // Handle pd dump enable/disable request + struct remote_rpc_control_pd_dump *pddump + = (struct remote_rpc_control_pd_dump *)data; + VERIFYC(datalen == sizeof(struct remote_rpc_control_pd_dump), + AEE_EBADPARM); + VERIFYC(pddump != NULL, AEE_EBADPARM); + if(pddump->domain != -1) { + VERIFY(AEE_SUCCESS + == (nErr = set_pd_dump_attribute( + pddump->domain, pddump->enable))); + } else { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFY(AEE_SUCCESS + == (nErr = set_pd_dump_attribute( + ii, pddump->enable))); + } + } + FARF(ALWAYS, "%s PD dump request to enable(%d) for domain %d", + __func__, pddump->enable, pddump->domain); + break; + } + case FASTRPC_REMOTE_PROCESS_EXCEPTION: { + // Trigger non fatal exception in the User PD of DSP. + remote_rpc_process_exception *dp + = (remote_rpc_process_exception *)data; + remote_handle64 handle = 0; + int ret = 0; + + VERIFYC(datalen == sizeof(remote_rpc_process_exception), + AEE_EBADPARM); + VERIFYC(dp, AEE_EBADPARM); + domain = dp->domain; + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + /* + * If any request causes exception on DSP, DSP returns + * AEE_EBADSTATE for the request thread. + */ + if((handle = get_adsp_current_process1_handle(domain)) + != INVALID_HANDLE) { + ret = adsp_current_process1_exception(handle); + } else { + ret = adsp_current_process_exception(); + } + ret = (ret == AEE_SUCCESS) ? AEE_ERPC : ret; + VERIFYC(ret == (int)(DSP_AEE_EOFFSET + AEE_EBADSTATE), ret); + FARF(ALWAYS, + "%s Remote process exception request for domain %d, " + "handle 0x%" PRIx64 "\n", + __func__, domain, handle); + break; + } + case FASTRPC_REMOTE_PROCESS_TYPE: { + struct remote_process_type *typ + = (struct remote_process_type *)data; + int ret_val = -1; + VERIFYC(datalen == sizeof(struct remote_process_type), + AEE_EBADPARM); + VERIFYC(typ, AEE_EBADPARM); + domain = typ->domain; + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + ret_val = hlist[domain].unsigned_module; + if(ret_val != PROCESS_TYPE_UNSIGNED + && ret_val != PROCESS_TYPE_SIGNED) { + typ->process_type = -1; + nErr = AEE_EBADPARM; + } else { + typ->process_type = ret_val; + } + break; + } + case FASTRPC_REGISTER_STATUS_NOTIFICATIONS: { + // Handle DSP PD notification request + struct remote_rpc_notif_register *notif + = (struct remote_rpc_notif_register *)data; + VERIFYC(datalen == sizeof(struct remote_rpc_notif_register), + AEE_EBADPARM); + VERIFYC(notif != NULL, AEE_EBADPARM); + domain = notif->domain; + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + if(domain != -1) { + VERIFYC(is_status_notif_version2_supported(domain), + AEE_EUNSUPPORTED); + VERIFY( + AEE_SUCCESS + == (nErr = fastrpc_notif_register(domain, notif))); + } else { + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + VERIFYC(is_status_notif_version2_supported(ii), + AEE_EUNSUPPORTED); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_notif_register( + ii, notif))); + } + } + FARF(RUNTIME_RPC_HIGH, + "%s Register PD status notification request for domain " + "%d\n", + __func__, domain); + break; + } + case FASTRPC_PD_INITMEM_SIZE: { + // Handle DSP User PD init memory size request + struct remote_rpc_pd_initmem_size *params + = (struct remote_rpc_pd_initmem_size *)data; + VERIFYC(datalen == sizeof(struct remote_rpc_pd_initmem_size), + AEE_EBADPARM); + VERIFYC(params != NULL, AEE_EBADPARM); + if(params->domain != -1) { + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(params->domain)) { + nErr = AEE_EBADPARM; + FARF(ERROR, "%s: Invalid domain ID %d passed", + __func__, params->domain); + goto bail; + } + if(hlist[params->domain].unsigned_module) { + nErr = AEE_EUNSUPPORTED; + FARF(ERROR, "Configuring User PD init mem " + "length is not supported for " + "unsigned PDs"); + goto bail; + } + VERIFY( + AEE_SUCCESS + == (nErr = store_domain_pd_initmem_size( + params->domain, params->pd_initmem_size))); + } else { + /* If domain is -1, then set parameters for all domains + */ + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + if(hlist[ii].unsigned_module) { + FARF( + ALWAYS, + "Warning: %s: Configuring User PD " + "init mem length for domain %d " + "is not supported for unsigned " + "PDs", + __func__, ii); + } else { + VERIFY( + AEE_SUCCESS + == (nErr + = store_domain_pd_initmem_size( + ii, + params->pd_initmem_size))); + } + } + } + FARF(ALWAYS, + "%s DSP userpd memlen request for domain %d, userpd " + "memlen 0x%x", + __func__, params->domain, params->pd_initmem_size); + break; + } + case FASTRPC_RESERVE_NEW_SESSION: { + remote_rpc_reserve_new_session_t *sess + = (remote_rpc_reserve_new_session_t *)data; + int ii = 0, jj = 0; + + VERIFYC(datalen == sizeof(remote_rpc_reserve_new_session_t), + AEE_EBADPARM); + VERIFYC(sess && sess->domain_name != NULL + && sess->domain_name_len > 0 && sess->session_name + && sess->session_name_len > 0, + AEE_EBADPARM); + domain = get_domain_from_name(sess->domain_name, + DOMAIN_NAME_STAND_ALONE); + VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); + // Initialize effective domain ID to 2nd session of domain, + // first session is default usage and cannot be reserved + ii = domain + NUM_DOMAINS; + // Initialize session to 1, session 0 is default session + jj = 1; + // Set effective_domain_id and session_id to invalid IDs + sess->effective_domain_id = NUM_DOMAINS_EXTEND; + sess->session_id = NUM_SESSIONS; + do { + pthread_mutex_lock(&hlist[ii].init); + if(!hlist[ii].is_session_reserved) { + hlist[ii].is_session_reserved = true; + sess->effective_domain_id = ii; + sess->session_id = jj; + strlcpy(hlist[ii].sessionname, + sess->session_name, + STD_MIN(sess->session_name_len, + (MAX_DSPPD_NAMELEN - 1))); + pthread_mutex_unlock(&hlist[ii].init); + break; + } + pthread_mutex_unlock(&hlist[ii].init); + // Increment to next session of domain + ii = ii + NUM_DOMAINS; + // Increment the session + jj++; + } while(IS_VALID_EFFECTIVE_DOMAIN_ID(ii)); + VERIFYC( + IS_VALID_EFFECTIVE_DOMAIN_ID(sess->effective_domain_id), + AEE_ENOSESSION); + break; + } + case FASTRPC_GET_EFFECTIVE_DOMAIN_ID: { + remote_rpc_effective_domain_id_t *effec_domain_id + = (remote_rpc_effective_domain_id_t *)data; + VERIFYC(datalen == sizeof(remote_rpc_effective_domain_id_t), + AEE_EBADPARM); + VERIFYC(effec_domain_id && effec_domain_id->domain_name + && effec_domain_id->domain_name_len > 0 + && effec_domain_id->session_id < NUM_SESSIONS, + AEE_EBADPARM); + domain = get_domain_from_name(effec_domain_id->domain_name, + DOMAIN_NAME_STAND_ALONE); + VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); + effec_domain_id->effective_domain_id = GET_EFFECTIVE_DOMAIN_ID( + domain, effec_domain_id->session_id); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID( + effec_domain_id->effective_domain_id), + AEE_ENOSESSION); + break; + } + case FASTRPC_GET_URI: { + remote_rpc_get_uri_t *rpc_uri = (remote_rpc_get_uri_t *)data; + int ret_val = -1; + + VERIFYC(datalen == sizeof(remote_rpc_get_uri_t), AEE_EBADPARM); + VERIFYC(rpc_uri && rpc_uri->domain_name + && rpc_uri->domain_name_len > 0 + && rpc_uri->session_id < NUM_SESSIONS, + AEE_EBADPARM); + domain = get_domain_from_name(rpc_uri->domain_name, + DOMAIN_NAME_STAND_ALONE); + VERIFYC(IS_VALID_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC(rpc_uri->module_uri != NULL + && rpc_uri->module_uri_len > 0, + AEE_EBADPARM); + VERIFYC(rpc_uri->uri != NULL + && rpc_uri->uri_len > rpc_uri->module_uri_len, + AEE_EBADPARM); + ret_val = snprintf(0, 0, "%s%s%s%s%d", rpc_uri->module_uri, + FASTRPC_DOMAIN_URI, SUBSYSTEM_NAME[domain], + FASTRPC_SESSION_URI, rpc_uri->session_id); + if(rpc_uri->uri_len <= ret_val) { + nErr = AEE_EBADSIZE; + FARF(ERROR, + "ERROR 0x%x: %s Session URI length %u is not " + "enough, need %u " + "characters", + nErr, __func__, rpc_uri->uri_len, ret_val); + } + ret_val = snprintf(rpc_uri->uri, rpc_uri->uri_len, + "%s%s%s%s%d", rpc_uri->module_uri, + FASTRPC_DOMAIN_URI, SUBSYSTEM_NAME[domain], + FASTRPC_SESSION_URI, rpc_uri->session_id); + if(ret_val < 0) { + nErr = AEE_EBADSIZE; + FARF(ERROR, + "ERROR 0x%x: %s Invalid Session URI length %u", + nErr, __func__, rpc_uri->uri_len); + } + break; + } + case FASTRPC_CONTEXT_CREATE: + VERIFYC(datalen == sizeof(fastrpc_context_create) && data, + AEE_EBADPARM); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_create_context(data))); + break; + case FASTRPC_CONTEXT_DESTROY: { + fastrpc_context_destroy *dest + = (fastrpc_context_destroy *)data; + + VERIFYC(datalen == sizeof(fastrpc_context_destroy) && dest + && !dest->flags, + AEE_EBADPARM); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_destroy_context(dest->ctx))); + break; + } + default: + nErr = AEE_EUNSUPPORTED; + FARF(ERROR, "ERROR 0x%x: %s Unsupported request ID %d", nErr, + __func__, req); + break; + } bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for request ID %d (errno %s)", nErr, - __func__, req, strerror(errno)); - } - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno %s)", + nErr, __func__, req, strerror(errno)); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for request ID %d (errno " + "%s)", + nErr, __func__, req, strerror(errno)); + } + } + return nErr; } /* Function to get domain id from URI @@ -3029,124 +3526,137 @@ int remote_session_control(uint32_t req, void *data, uint32_t datalen) { * @type: Type of URI * @returns: 0 on success, valid non-zero error code on failure */ -int get_domain_from_name(const char *uri, uint32_t type) { - int domain = DEFAULT_DOMAIN_ID; - char *session_uri = NULL; - int session_id = 0; - - if (uri && type == DOMAIN_NAME_STAND_ALONE) { - if (!strncmp(uri, ADSP_DOMAIN_NAME, strlen(ADSP_DOMAIN_NAME))) { - domain = ADSP_DOMAIN_ID; - } else if (!strncmp(uri, MDSP_DOMAIN_NAME, - strlen(MDSP_DOMAIN_NAME))) { - domain = MDSP_DOMAIN_ID; - } else if (!strncmp(uri, SDSP_DOMAIN_NAME, - strlen(SDSP_DOMAIN_NAME))) { - domain = SDSP_DOMAIN_ID; - } else if (!strncmp(uri, CDSP1_DOMAIN_NAME, - strlen(CDSP1_DOMAIN_NAME))) { - domain = CDSP1_DOMAIN_ID; - } else if (!strncmp(uri, CDSP_DOMAIN_NAME, - strlen(CDSP_DOMAIN_NAME))) { - domain = CDSP_DOMAIN_ID; - } else if (!strncmp(uri, GDSP0_DOMAIN_NAME, - strlen(GDSP0_DOMAIN_NAME))) { - domain = GDSP0_DOMAIN_ID; - } else if (!strncmp(uri, GDSP1_DOMAIN_NAME, - strlen(GDSP1_DOMAIN_NAME))) { - domain = GDSP1_DOMAIN_ID; - } else { - domain = INVALID_DOMAIN_ID; - FARF(ERROR, "Invalid domain name: %s\n", uri); - return domain; - } - } - if (uri && type == DOMAIN_NAME_IN_URI) { - if (strstr(uri, ADSP_DOMAIN)) { - domain = ADSP_DOMAIN_ID; - } else if (strstr(uri, MDSP_DOMAIN)) { - domain = MDSP_DOMAIN_ID; - } else if (strstr(uri, SDSP_DOMAIN)) { - domain = SDSP_DOMAIN_ID; - } else if (strstr(uri, CDSP1_DOMAIN)) { - domain = CDSP1_DOMAIN_ID; - } else if (strstr(uri, CDSP_DOMAIN)) { - domain = CDSP_DOMAIN_ID; - } else if (strstr(uri, GDSP0_DOMAIN)) { - domain = GDSP0_DOMAIN_ID; - } else if (strstr(uri, GDSP1_DOMAIN)) { - domain = GDSP1_DOMAIN_ID; - } else { - domain = INVALID_DOMAIN_ID; - FARF(ERROR, "Invalid domain name: %s\n", uri); - goto bail; - } - if (NULL != (session_uri = strstr(uri, FASTRPC_SESSION_URI))) { - session_uri = session_uri + strlen(FASTRPC_SESSION_URI); - // Get Session ID from URI - session_id = strtol(session_uri, NULL, 10); - if (session_id < NUM_SESSIONS) { - domain = GET_EFFECTIVE_DOMAIN_ID(domain, session_id); - } else { - domain = INVALID_DOMAIN_ID; - FARF(ERROR, "Invalid domain name: %s\n", uri); - } - } - } +int +get_domain_from_name(const char *uri, uint32_t type) +{ + int domain = DEFAULT_DOMAIN_ID; + char *session_uri = NULL; + int session_id = 0; + + if(uri && type == DOMAIN_NAME_STAND_ALONE) { + if(!strncmp(uri, ADSP_DOMAIN_NAME, strlen(ADSP_DOMAIN_NAME))) { + domain = ADSP_DOMAIN_ID; + } else if(!strncmp(uri, MDSP_DOMAIN_NAME, + strlen(MDSP_DOMAIN_NAME))) { + domain = MDSP_DOMAIN_ID; + } else if(!strncmp(uri, SDSP_DOMAIN_NAME, + strlen(SDSP_DOMAIN_NAME))) { + domain = SDSP_DOMAIN_ID; + } else if(!strncmp(uri, CDSP1_DOMAIN_NAME, + strlen(CDSP1_DOMAIN_NAME))) { + domain = CDSP1_DOMAIN_ID; + } else if(!strncmp(uri, CDSP_DOMAIN_NAME, + strlen(CDSP_DOMAIN_NAME))) { + domain = CDSP_DOMAIN_ID; + } else if(!strncmp(uri, GDSP0_DOMAIN_NAME, + strlen(GDSP0_DOMAIN_NAME))) { + domain = GDSP0_DOMAIN_ID; + } else if(!strncmp(uri, GDSP1_DOMAIN_NAME, + strlen(GDSP1_DOMAIN_NAME))) { + domain = GDSP1_DOMAIN_ID; + } else { + domain = INVALID_DOMAIN_ID; + FARF(ERROR, "Invalid domain name: %s\n", uri); + return domain; + } + } + if(uri && type == DOMAIN_NAME_IN_URI) { + if(strstr(uri, ADSP_DOMAIN)) { + domain = ADSP_DOMAIN_ID; + } else if(strstr(uri, MDSP_DOMAIN)) { + domain = MDSP_DOMAIN_ID; + } else if(strstr(uri, SDSP_DOMAIN)) { + domain = SDSP_DOMAIN_ID; + } else if(strstr(uri, CDSP1_DOMAIN)) { + domain = CDSP1_DOMAIN_ID; + } else if(strstr(uri, CDSP_DOMAIN)) { + domain = CDSP_DOMAIN_ID; + } else if(strstr(uri, GDSP0_DOMAIN)) { + domain = GDSP0_DOMAIN_ID; + } else if(strstr(uri, GDSP1_DOMAIN)) { + domain = GDSP1_DOMAIN_ID; + } else { + domain = INVALID_DOMAIN_ID; + FARF(ERROR, "Invalid domain name: %s\n", uri); + goto bail; + } + if(NULL != (session_uri = strstr(uri, FASTRPC_SESSION_URI))) { + session_uri + = session_uri + strlen(FASTRPC_SESSION_URI); + // Get Session ID from URI + session_id = strtol(session_uri, NULL, 10); + if(session_id < NUM_SESSIONS) { + domain = GET_EFFECTIVE_DOMAIN_ID(domain, + session_id); + } else { + domain = INVALID_DOMAIN_ID; + FARF(ERROR, "Invalid domain name: %s\n", uri); + } + } + } bail: - VERIFY_IPRINTF("%s: %d\n", __func__, domain); - return domain; + VERIFY_IPRINTF("%s: %d\n", __func__, domain); + return domain; } -int fastrpc_get_pd_type(int domain) { - if (hlist && (hlist[domain].dev != -1)) { +int +fastrpc_get_pd_type(int domain) +{ + if(hlist && (hlist[domain].dev != -1)) { return hlist[domain].dsppd; } else { return -1; } } -int get_current_domain(void) { - struct handle_list *list; - int domain = -1; - - /* user hint to pick default domain id - * first try tlskey before using default domain - */ - list = (struct handle_list *)pthread_getspecific(tlsKey); - if (list) { - domain = (int)(list - &hlist[0]); - } - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { - // use default domain if thread tlskey not found - domain = DEFAULT_DOMAIN_ID; - } - return domain; +int +get_current_domain(void) +{ + struct handle_list *list; + int domain = -1; + + /* user hint to pick default domain id + * first try tlskey before using default domain + */ + list = (struct handle_list *)pthread_getspecific(tlsKey); + if(list) { + domain = (int)(list - &hlist[0]); + } + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { + // use default domain if thread tlskey not found + domain = DEFAULT_DOMAIN_ID; + } + return domain; } -bool is_process_exiting(int domain) { - int nErr = 0, state = 1; - - (void)nErr; - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADDOMAIN); - pthread_mutex_lock(&hlist[domain].mut); - state = hlist[domain].state; - pthread_mutex_unlock(&hlist[domain].mut); - if (state != FASTRPC_DOMAIN_STATE_INIT) - return true; - else - return false; +bool +is_process_exiting(int domain) +{ + int nErr = 0, state = 1; + + (void)nErr; + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADDOMAIN); + pthread_mutex_lock(&hlist[domain].mut); + state = hlist[domain].state; + pthread_mutex_unlock(&hlist[domain].mut); + if(state != FASTRPC_DOMAIN_STATE_INIT) + return true; + else + return false; bail: - return true; + return true; } -int remote_set_mode(uint32_t mode) { - int i; - FOR_EACH_EFFECTIVE_DOMAIN_ID(i) { - hlist[i].mode = mode; - hlist[i].setmode = 1; - } - return AEE_SUCCESS; +int +remote_set_mode(uint32_t mode) +{ + int i; + FOR_EACH_EFFECTIVE_DOMAIN_ID(i) + { + hlist[i].mode = mode; + hlist[i].setmode = 1; + } + return AEE_SUCCESS; } PL_DEP(fastrpc_apps_user); @@ -3156,380 +3666,430 @@ PL_DEP(rpcmem); PL_DEP(listener_android); PL_DEP(fastrpc_async); -static int attach_guestos(int domain) { - int attach; - - switch (GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain)) { - case MDSP_DOMAIN_ID: - case ADSP_DOMAIN_ID: - case CDSP_DOMAIN_ID: - case SDSP_DOMAIN_ID: - case CDSP1_DOMAIN_ID: - case GDSP0_DOMAIN_ID: - case GDSP1_DOMAIN_ID: - attach = USERPD; - break; - default: - attach = ROOT_PD; - break; - } - return attach; +static int +attach_guestos(int domain) +{ + int attach; + + switch(GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain)) { + case MDSP_DOMAIN_ID: + case ADSP_DOMAIN_ID: + case CDSP_DOMAIN_ID: + case SDSP_DOMAIN_ID: + case CDSP1_DOMAIN_ID: + case GDSP0_DOMAIN_ID: + case GDSP1_DOMAIN_ID: + attach = USERPD; + break; + default: + attach = ROOT_PD; + break; + } + return attach; } -static void domain_deinit(int domain) { - int olddev; - remote_handle64 handle = 0; - uint64_t t_kill; - - if (!hlist) { - return; - } - olddev = hlist[domain].dev; - FARF(RUNTIME_RPC_HIGH, "%s for domain %d: dev %d", __func__, domain, olddev); - if (olddev != -1) { - - FASTRPC_ATRACE_BEGIN_L("%s called for handle 0x%x, domain %d, dev %d", - __func__, handle, domain, olddev); - - handle = get_adsp_current_process1_handle(domain); - if (handle != INVALID_HANDLE) { - adsp_current_process1_exit(handle); - } else { - adsp_current_process_exit(); - } - - pthread_mutex_lock(&hlist[domain].mut); - hlist[domain].state = FASTRPC_DOMAIN_STATE_DEINIT; - pthread_mutex_unlock(&hlist[domain].mut); - - dspsignal_domain_deinit(domain); - listener_android_domain_deinit(domain); - hlist[domain].first_revrpc_done = 0; - pthread_mutex_lock(&hlist[domain].async_init_deinit_mut); - fastrpc_async_domain_deinit(domain); - pthread_mutex_unlock(&hlist[domain].async_init_deinit_mut); - fastrpc_notif_domain_deinit(domain); - fastrpc_clear_handle_list(MULTI_DOMAIN_HANDLE_LIST_ID, domain); - fastrpc_clear_handle_list(REVERSE_HANDLE_LIST_ID, domain); - if (domain == DEFAULT_DOMAIN_ID) { - fastrpc_clear_handle_list(NON_DOMAIN_HANDLE_LIST_ID, domain); - } - fastrpc_perf_deinit(); - fastrpc_latency_deinit(&hlist[domain].qos); - trace_marker_deinit(domain); - deinitFileWatcher(domain); - adspmsgd_stop(domain); - fastrpc_mem_close(domain); - apps_mem_deinit(domain); - hlist[domain].state = 0; - hlist[domain].ref = 0; - - hlist[domain].cphandle = 0; - hlist[domain].msghandle = 0; - hlist[domain].remotectlhandle = 0; - hlist[domain].listenerhandle = 0; - hlist[domain].dev = -1; - hlist[domain].info = -1; - hlist[domain].dsppd = attach_guestos(domain); - memset(hlist[domain].dsppdname, 0, MAX_DSPPD_NAMELEN); - memset(hlist[domain].sessionname, 0, MAX_DSPPD_NAMELEN); - PROFILE_ALWAYS(&t_kill, close_device_node(domain, olddev);); - FARF(RUNTIME_RPC_HIGH, "%s: closed device %d on domain %d (kill time %" PRIu64 " us)", - __func__, olddev, domain, t_kill); - FARF(ALWAYS, "%s done for domain %d.", __func__, domain); - FASTRPC_ATRACE_END(); - } - hlist[domain].proc_sharedbuf_cur_addr = NULL; - if (hlist[domain].proc_sharedbuf) { - rpcmem_free_internal(hlist[domain].proc_sharedbuf); - hlist[domain].proc_sharedbuf = NULL; - } - // Free the session, on session deinit - pthread_mutex_lock(&hlist[domain].init); - hlist[domain].is_session_reserved = false; - pthread_mutex_unlock(&hlist[domain].init); - pthread_mutex_lock(&hlist[domain].mut); - hlist[domain].state = FASTRPC_DOMAIN_STATE_CLEAN; - pthread_mutex_unlock(&hlist[domain].mut); +static void +domain_deinit(int domain) +{ + int olddev; + remote_handle64 handle = 0; + uint64_t t_kill; + + if(!hlist) { + return; + } + olddev = hlist[domain].dev; + FARF(RUNTIME_RPC_HIGH, "%s for domain %d: dev %d", __func__, domain, + olddev); + if(olddev != -1) { + + FASTRPC_ATRACE_BEGIN_L( + "%s called for handle 0x%x, domain %d, dev %d", __func__, + handle, domain, olddev); + + handle = get_adsp_current_process1_handle(domain); + if(handle != INVALID_HANDLE) { + adsp_current_process1_exit(handle); + } else { + adsp_current_process_exit(); + } + + pthread_mutex_lock(&hlist[domain].mut); + hlist[domain].state = FASTRPC_DOMAIN_STATE_DEINIT; + pthread_mutex_unlock(&hlist[domain].mut); + + dspsignal_domain_deinit(domain); + listener_android_domain_deinit(domain); + hlist[domain].first_revrpc_done = 0; + pthread_mutex_lock(&hlist[domain].async_init_deinit_mut); + fastrpc_async_domain_deinit(domain); + pthread_mutex_unlock(&hlist[domain].async_init_deinit_mut); + fastrpc_notif_domain_deinit(domain); + fastrpc_clear_handle_list(MULTI_DOMAIN_HANDLE_LIST_ID, domain); + fastrpc_clear_handle_list(REVERSE_HANDLE_LIST_ID, domain); + if(domain == DEFAULT_DOMAIN_ID) { + fastrpc_clear_handle_list(NON_DOMAIN_HANDLE_LIST_ID, + domain); + } + fastrpc_perf_deinit(); + fastrpc_latency_deinit(&hlist[domain].qos); + trace_marker_deinit(domain); + deinitFileWatcher(domain); + adspmsgd_stop(domain); + fastrpc_mem_close(domain); + apps_mem_deinit(domain); + hlist[domain].state = 0; + hlist[domain].ref = 0; + + hlist[domain].cphandle = 0; + hlist[domain].msghandle = 0; + hlist[domain].remotectlhandle = 0; + hlist[domain].listenerhandle = 0; + hlist[domain].dev = -1; + hlist[domain].info = -1; + hlist[domain].dsppd = attach_guestos(domain); + memset(hlist[domain].dsppdname, 0, MAX_DSPPD_NAMELEN); + memset(hlist[domain].sessionname, 0, MAX_DSPPD_NAMELEN); + PROFILE_ALWAYS(&t_kill, close_device_node(domain, olddev);); + FARF(RUNTIME_RPC_HIGH, + "%s: closed device %d on domain %d (kill time %" PRIu64 + " us)", + __func__, olddev, domain, t_kill); + FARF(ALWAYS, "%s done for domain %d.", __func__, domain); + FASTRPC_ATRACE_END(); + } + hlist[domain].proc_sharedbuf_cur_addr = NULL; + if(hlist[domain].proc_sharedbuf) { + rpcmem_free_internal(hlist[domain].proc_sharedbuf); + hlist[domain].proc_sharedbuf = NULL; + } + // Free the session, on session deinit + pthread_mutex_lock(&hlist[domain].init); + hlist[domain].is_session_reserved = false; + pthread_mutex_unlock(&hlist[domain].init); + pthread_mutex_lock(&hlist[domain].mut); + hlist[domain].state = FASTRPC_DOMAIN_STATE_CLEAN; + pthread_mutex_unlock(&hlist[domain].mut); } -static const char *get_domain_name(int domain_id) { - const char *name; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - - switch (domain) { - case ADSP_DOMAIN_ID: - name = ADSPRPC_DEVICE; - break; - case SDSP_DOMAIN_ID: - name = SDSPRPC_DEVICE; - break; - case MDSP_DOMAIN_ID: - name = MDSPRPC_DEVICE; - break; - case CDSP_DOMAIN_ID: - name = CDSPRPC_DEVICE; - break; - case CDSP1_DOMAIN_ID: - name = CDSP1RPC_DEVICE; - break; - case GDSP0_DOMAIN_ID: - name = GDSP0RPC_DEVICE; - break; - case GDSP1_DOMAIN_ID: - name = GDSP1RPC_DEVICE; - break; - default: - name = DEFAULT_DEVICE; - break; - } - return name; +static const char * +get_domain_name(int domain_id) +{ + const char *name; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); + + switch(domain) { + case ADSP_DOMAIN_ID: + name = ADSPRPC_DEVICE; + break; + case SDSP_DOMAIN_ID: + name = SDSPRPC_DEVICE; + break; + case MDSP_DOMAIN_ID: + name = MDSPRPC_DEVICE; + break; + case CDSP_DOMAIN_ID: + name = CDSPRPC_DEVICE; + break; + case CDSP1_DOMAIN_ID: + name = CDSP1RPC_DEVICE; + break; + case GDSP0_DOMAIN_ID: + name = GDSP0RPC_DEVICE; + break; + case GDSP1_DOMAIN_ID: + name = GDSP1RPC_DEVICE; + break; + default: + name = DEFAULT_DEVICE; + break; + } + return name; } -int open_device_node(int domain_id) { - int dev = -1, nErr = 0; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - int sess_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain_id); - - switch (domain) { - case ADSP_DOMAIN_ID: - case SDSP_DOMAIN_ID: - case MDSP_DOMAIN_ID: - dev = open(get_secure_domain_name(domain), O_NONBLOCK); - if ((dev < 0) && (errno == ENOENT)) { - FARF(RUNTIME_RPC_HIGH, - "Device node %s open failed for domain %d (errno %s)," - "falling back to node %s \n", - get_secure_domain_name(domain), domain, strerror(errno), - get_domain_name(domain)); - dev = open(get_domain_name(domain), O_NONBLOCK); - if ((dev < 0) && (errno == ENOENT)) { - FARF(RUNTIME_RPC_HIGH, - "Device node %s open failed for domain %d (errno %s)," - "falling back to node %s \n", - get_domain_name(domain), domain, strerror(errno), DEFAULT_DEVICE); - dev = open(DEFAULT_DEVICE, O_NONBLOCK); - } - } else if ((dev < 0) && (errno == EACCES)) { - // Open the default device node if unable to open the - // secure device node due to permissions - FARF(RUNTIME_RPC_HIGH, - "Device node %s open failed for domain %d (errno %s)," - "falling back to node %s \n", - get_secure_domain_name(domain), domain, strerror(errno), - DEFAULT_DEVICE); - dev = open(DEFAULT_DEVICE, O_NONBLOCK); - } - break; - case CDSP_DOMAIN_ID: - case CDSP1_DOMAIN_ID: - case GDSP0_DOMAIN_ID: - case GDSP1_DOMAIN_ID: - dev = open(get_secure_domain_name(domain), O_NONBLOCK); - if ((dev < 0) && ((errno == ENOENT) || (errno == EACCES))) { - FARF(RUNTIME_RPC_HIGH, - "Device node %s open failed for domain %d (errno %s)," - "falling back to node %s \n", - get_secure_domain_name(domain), domain, strerror(errno), - get_domain_name(domain)); - dev = open(get_domain_name(domain), O_NONBLOCK); - if ((dev < 0) && ((errno == ENOENT) || (errno == EACCES))) { - // Open the default device node if actual device node - // is not present - FARF(RUNTIME_RPC_HIGH, - "Device node %s open failed for domain %d (errno %s)," - "falling back to node %s \n", - get_domain_name(domain), domain, strerror(errno), DEFAULT_DEVICE); - dev = open(DEFAULT_DEVICE, O_NONBLOCK); - } - } - break; - default: - break; - } - if (dev < 0) - FARF(ERROR, - "Error 0x%x: %s failed for domain ID %d, sess ID %d secure dev : %s, " - "dev : %s. (errno %d, %s) (Either the remote processor is down, or " - "application does not have permission to access the remote " - "processor\n", - nErr, __func__, domain_id, sess_id, get_secure_domain_name(domain), - get_domain_name(domain), errno, strerror(errno)); - return dev; +int +open_device_node(int domain_id) +{ + int dev = -1, nErr = 0; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); + int sess_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain_id); + + switch(domain) { + case ADSP_DOMAIN_ID: + case SDSP_DOMAIN_ID: + case MDSP_DOMAIN_ID: + dev = open(get_secure_domain_name(domain), O_NONBLOCK); + if((dev < 0) && (errno == ENOENT)) { + FARF(RUNTIME_RPC_HIGH, + "Device node %s open failed for domain %d (errno " + "%s)," + "falling back to node %s \n", + get_secure_domain_name(domain), domain, + strerror(errno), get_domain_name(domain)); + dev = open(get_domain_name(domain), O_NONBLOCK); + if((dev < 0) && (errno == ENOENT)) { + FARF(RUNTIME_RPC_HIGH, + "Device node %s open failed for domain " + "%d (errno %s)," + "falling back to node %s \n", + get_domain_name(domain), domain, + strerror(errno), DEFAULT_DEVICE); + dev = open(DEFAULT_DEVICE, O_NONBLOCK); + } + } else if((dev < 0) && (errno == EACCES)) { + // Open the default device node if unable to open the + // secure device node due to permissions + FARF(RUNTIME_RPC_HIGH, + "Device node %s open failed for domain %d (errno " + "%s)," + "falling back to node %s \n", + get_secure_domain_name(domain), domain, + strerror(errno), DEFAULT_DEVICE); + dev = open(DEFAULT_DEVICE, O_NONBLOCK); + } + break; + case CDSP_DOMAIN_ID: + case CDSP1_DOMAIN_ID: + case GDSP0_DOMAIN_ID: + case GDSP1_DOMAIN_ID: + dev = open(get_secure_domain_name(domain), O_NONBLOCK); + if((dev < 0) && ((errno == ENOENT) || (errno == EACCES))) { + FARF(RUNTIME_RPC_HIGH, + "Device node %s open failed for domain %d (errno " + "%s)," + "falling back to node %s \n", + get_secure_domain_name(domain), domain, + strerror(errno), get_domain_name(domain)); + dev = open(get_domain_name(domain), O_NONBLOCK); + if((dev < 0) + && ((errno == ENOENT) || (errno == EACCES))) { + // Open the default device node if actual + // device node is not present + FARF(RUNTIME_RPC_HIGH, + "Device node %s open failed for domain " + "%d (errno %s)," + "falling back to node %s \n", + get_domain_name(domain), domain, + strerror(errno), DEFAULT_DEVICE); + dev = open(DEFAULT_DEVICE, O_NONBLOCK); + } + } + break; + default: + break; + } + if(dev < 0) + FARF(ERROR, + "Error 0x%x: %s failed for domain ID %d, sess ID %d " + "secure dev : %s, " + "dev : %s. (errno %d, %s) (Either the remote processor " + "is down, or " + "application does not have permission to access the " + "remote " + "processor\n", + nErr, __func__, domain_id, sess_id, + get_secure_domain_name(domain), get_domain_name(domain), + errno, strerror(errno)); + return dev; } -static int close_device_node(int domain_id, int dev) { - int nErr = 0; - nErr = close(dev); - FARF(ALWAYS, "%s: closed dev %d on domain %d", __func__, dev, domain_id); - return nErr; +static int +close_device_node(int domain_id, int dev) +{ + int nErr = 0; + nErr = close(dev); + FARF(ALWAYS, "%s: closed dev %d on domain %d", __func__, dev, + domain_id); + return nErr; } -static int get_process_attrs(int domain) { - int attrs = 0; - - attrs = fastrpc_get_property_int(FASTRPC_PROCESS_ATTRS, 0); - attrs |= fastrpc_get_property_int(FASTRPC_PROCESS_ATTRS_PERSISTENT, 0); - fastrpc_trace = fastrpc_get_property_int(FASTRPC_DEBUG_TRACE, 0); - attrs |= hlist[domain].qos.adaptive_qos ? FASTRPC_MODE_ADAPTIVE_QOS : 0; - attrs |= hlist[domain].unsigned_module ? FASTRPC_MODE_UNSIGNED_MODULE : 0; - attrs |= (hlist[domain].pd_dump | fastrpc_config_is_pddump_enabled()) - ? FASTRPC_MODE_ENABLE_PDDUMP - : 0; - attrs |= fastrpc_get_property_int(FASTRPC_DEBUG_PDDUMP, 0) - ? FASTRPC_MODE_DEBUG_PDDUMP - : 0; - attrs |= (fastrpc_config_is_perfkernel_enabled() | - fastrpc_get_property_int(FASTRPC_PERF_KERNEL, 0)) - ? FASTRPC_MODE_PERF_KERNEL - : 0; - attrs |= (fastrpc_config_is_perfdsp_enabled() | - fastrpc_get_property_int(FASTRPC_PERF_ADSP, 0)) - ? FASTRPC_MODE_PERF_DSP - : 0; - attrs |= fastrpc_config_is_log_iregion_enabled() - ? FASTRPC_MODE_ENABLE_IREGION_LOG - : 0; - attrs |= fastrpc_config_is_qtf_tracing_enabled() - ? FASTRPC_MODE_ENABLE_QTF_TRACING - : 0; - attrs |= (fastrpc_config_get_caller_level() << 13) & - FASTRPC_MODE_CALLER_LEVEL_MASK; - attrs |= fastrpc_config_is_uaf_enabled() ? FASTRPC_MODE_ENABLE_UAF : 0; - attrs |= fastrpc_config_is_debug_logging_enabled() - ? FASTRPC_MODE_ENABLE_DEBUG_LOGGING - : 0; +static int +get_process_attrs(int domain) +{ + int attrs = 0; + + attrs = fastrpc_get_property_int(FASTRPC_PROCESS_ATTRS, 0); + attrs |= fastrpc_get_property_int(FASTRPC_PROCESS_ATTRS_PERSISTENT, 0); + fastrpc_trace = fastrpc_get_property_int(FASTRPC_DEBUG_TRACE, 0); + attrs + |= hlist[domain].qos.adaptive_qos ? FASTRPC_MODE_ADAPTIVE_QOS : 0; + attrs |= hlist[domain].unsigned_module ? FASTRPC_MODE_UNSIGNED_MODULE + : 0; + attrs |= (hlist[domain].pd_dump | fastrpc_config_is_pddump_enabled()) + ? FASTRPC_MODE_ENABLE_PDDUMP + : 0; + attrs |= fastrpc_get_property_int(FASTRPC_DEBUG_PDDUMP, 0) + ? FASTRPC_MODE_DEBUG_PDDUMP + : 0; + attrs |= (fastrpc_config_is_perfkernel_enabled() + | fastrpc_get_property_int(FASTRPC_PERF_KERNEL, 0)) + ? FASTRPC_MODE_PERF_KERNEL + : 0; + attrs |= (fastrpc_config_is_perfdsp_enabled() + | fastrpc_get_property_int(FASTRPC_PERF_ADSP, 0)) + ? FASTRPC_MODE_PERF_DSP + : 0; + attrs |= fastrpc_config_is_log_iregion_enabled() + ? FASTRPC_MODE_ENABLE_IREGION_LOG + : 0; + attrs |= fastrpc_config_is_qtf_tracing_enabled() + ? FASTRPC_MODE_ENABLE_QTF_TRACING + : 0; + attrs |= (fastrpc_config_get_caller_level() << 13) + & FASTRPC_MODE_CALLER_LEVEL_MASK; + attrs |= fastrpc_config_is_uaf_enabled() ? FASTRPC_MODE_ENABLE_UAF : 0; + attrs |= fastrpc_config_is_debug_logging_enabled() + ? FASTRPC_MODE_ENABLE_DEBUG_LOGGING + : 0; #ifdef SYSTEM_RPC_LIBRARY - attrs |= FASTRPC_MODE_SYSTEM_PROCESS; + attrs |= FASTRPC_MODE_SYSTEM_PROCESS; #endif - attrs |= fastrpc_config_is_sysmon_reserved_bit_enabled() - ? FASTRPC_MODE_SYSMON_RESERVED_BIT - : 0; - attrs |= fastrpc_config_is_logpacket_enabled() ? FASTRPC_MODE_LOG_PACKET : 0; - attrs |= (fastrpc_config_get_leak_detect() << 19) & - FASTRPC_MODE_ENABLE_LEAK_DETECT; - attrs |= (fastrpc_config_get_caller_stack_num() << 21) & - FASTRPC_MODE_CALLER_STACK_NUM; - return attrs; + attrs |= fastrpc_config_is_sysmon_reserved_bit_enabled() + ? FASTRPC_MODE_SYSMON_RESERVED_BIT + : 0; + attrs |= fastrpc_config_is_logpacket_enabled() + ? FASTRPC_MODE_LOG_PACKET + : 0; + attrs |= (fastrpc_config_get_leak_detect() << 19) + & FASTRPC_MODE_ENABLE_LEAK_DETECT; + attrs |= (fastrpc_config_get_caller_stack_num() << 21) + & FASTRPC_MODE_CALLER_STACK_NUM; + return attrs; } -static void get_process_testsig(apps_std_FILE *fp, uint64_t *ptrlen) { - int nErr = 0; - uint64_t len = 0; - char testsig[PROPERTY_VALUE_MAX]; - - if (fp == NULL || ptrlen == NULL) - return; - - if (fastrpc_get_property_string(FASTRPC_DEBUG_TESTSIG, testsig, NULL)) { - FARF(RUNTIME_RPC_HIGH, "testsig file loading is %s", testsig); - nErr = apps_std_fopen_with_env(ADSP_LIBRARY_PATH, ";", testsig, "r", fp); - if (nErr == AEE_SUCCESS && *fp != -1) - nErr = apps_std_flen(*fp, &len); - } - if (nErr) - len = 0; - *ptrlen = len; - return; +static void +get_process_testsig(apps_std_FILE *fp, uint64_t *ptrlen) +{ + int nErr = 0; + uint64_t len = 0; + char testsig[PROPERTY_VALUE_MAX]; + + if(fp == NULL || ptrlen == NULL) + return; + + if(fastrpc_get_property_string(FASTRPC_DEBUG_TESTSIG, testsig, NULL)) { + FARF(RUNTIME_RPC_HIGH, "testsig file loading is %s", testsig); + nErr = apps_std_fopen_with_env(ADSP_LIBRARY_PATH, ";", testsig, + "r", fp); + if(nErr == AEE_SUCCESS && *fp != -1) + nErr = apps_std_flen(*fp, &len); + } + if(nErr) + len = 0; + *ptrlen = len; + return; } -static int open_shell(int domain_id, apps_std_FILE *fh, int unsigned_shell) { - char *absName = NULL; - char *shell_absName = NULL; - char *domain_str = NULL; - uint16_t shell_absNameLen = 0, absNameLen = 0; - ; - int nErr = AEE_SUCCESS; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - const char *shell_name = SIGNED_SHELL; - - if (1 == unsigned_shell) { - shell_name = UNSIGNED_SHELL; - } - - if (domain == MDSP_DOMAIN_ID) { - return nErr; - } - VERIFYC(NULL != (domain_str = (char *)malloc(sizeof(domain))), AEE_ENOMEMORY); - snprintf(domain_str, sizeof(domain), "%d", domain); - - shell_absNameLen = strlen(shell_name) + strlen(domain_str) + 1; - - VERIFYC(NULL != - (shell_absName = (char *)malloc(sizeof(char) * shell_absNameLen)), - AEE_ENOMEMORY); - strlcpy(shell_absName, shell_name, shell_absNameLen); - - strlcat(shell_absName, domain_str, shell_absNameLen); - - absNameLen = strlen(DSP_MOUNT_LOCATION) + shell_absNameLen + 1; - VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - strlcpy(absName, DSP_MOUNT_LOCATION, absNameLen); - strlcat(absName, shell_absName, absNameLen); - - nErr = apps_std_fopen(absName, "r", fh); - if (nErr) { - absNameLen = strlen(DSP_DOM_LOCATION) + shell_absNameLen + 1; - VERIFYC(NULL != - (absName = (char *)realloc(absName, sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - strlcpy(absName, DSP_MOUNT_LOCATION, absNameLen); - strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, shell_absName, absNameLen); - nErr = apps_std_fopen(absName, "r", fh); - } - if (nErr) { - absNameLen = strlen(VENDOR_DSP_LOCATION) + shell_absNameLen + 1; - VERIFYC(NULL != - (absName = (char *)realloc(absName, sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - strlcpy(absName, VENDOR_DSP_LOCATION, absNameLen); - strlcat(absName, shell_absName, absNameLen); - - nErr = apps_std_fopen(absName, "r", fh); - if (nErr) { - absNameLen = strlen(VENDOR_DOM_LOCATION) + shell_absNameLen + 1; - VERIFYC(NULL != (absName = - (char *)realloc(absName, sizeof(char) * absNameLen)), - AEE_ENOMEMORY); - strlcpy(absName, VENDOR_DSP_LOCATION, absNameLen); - strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); - strlcat(absName, "/", absNameLen); - strlcat(absName, shell_absName, absNameLen); - - nErr = apps_std_fopen(absName, "r", fh); - } - } - if (!nErr) - FARF(RUNTIME_RPC_HIGH, "Successfully opened %s, domain %d", absName, domain); +static int +open_shell(int domain_id, apps_std_FILE *fh, int unsigned_shell) +{ + char *absName = NULL; + char *shell_absName = NULL; + char *domain_str = NULL; + uint16_t shell_absNameLen = 0, absNameLen = 0; + ; + int nErr = AEE_SUCCESS; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); + const char *shell_name = SIGNED_SHELL; + + if(1 == unsigned_shell) { + shell_name = UNSIGNED_SHELL; + } + + if(domain == MDSP_DOMAIN_ID) { + return nErr; + } + VERIFYC(NULL != (domain_str = (char *)malloc(sizeof(domain))), + AEE_ENOMEMORY); + snprintf(domain_str, sizeof(domain), "%d", domain); + + shell_absNameLen = strlen(shell_name) + strlen(domain_str) + 1; + + VERIFYC(NULL + != (shell_absName + = (char *)malloc(sizeof(char) * shell_absNameLen)), + AEE_ENOMEMORY); + strlcpy(shell_absName, shell_name, shell_absNameLen); + + strlcat(shell_absName, domain_str, shell_absNameLen); + + absNameLen = strlen(DSP_MOUNT_LOCATION) + shell_absNameLen + 1; + VERIFYC(NULL != (absName = (char *)malloc(sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + strlcpy(absName, DSP_MOUNT_LOCATION, absNameLen); + strlcat(absName, shell_absName, absNameLen); + + nErr = apps_std_fopen(absName, "r", fh); + if(nErr) { + absNameLen = strlen(DSP_DOM_LOCATION) + shell_absNameLen + 1; + VERIFYC(NULL + != (absName = (char *)realloc( + absName, sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + strlcpy(absName, DSP_MOUNT_LOCATION, absNameLen); + strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, shell_absName, absNameLen); + nErr = apps_std_fopen(absName, "r", fh); + } + if(nErr) { + absNameLen + = strlen(VENDOR_DSP_LOCATION) + shell_absNameLen + 1; + VERIFYC(NULL + != (absName = (char *)realloc( + absName, sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + strlcpy(absName, VENDOR_DSP_LOCATION, absNameLen); + strlcat(absName, shell_absName, absNameLen); + + nErr = apps_std_fopen(absName, "r", fh); + if(nErr) { + absNameLen = strlen(VENDOR_DOM_LOCATION) + + shell_absNameLen + 1; + VERIFYC( + NULL + != (absName = (char *)realloc( + absName, sizeof(char) * absNameLen)), + AEE_ENOMEMORY); + strlcpy(absName, VENDOR_DSP_LOCATION, absNameLen); + strlcat(absName, SUBSYSTEM_NAME[domain], absNameLen); + strlcat(absName, "/", absNameLen); + strlcat(absName, shell_absName, absNameLen); + + nErr = apps_std_fopen(absName, "r", fh); + } + } + if(!nErr) + FARF(RUNTIME_RPC_HIGH, "Successfully opened %s, domain %d", + absName, domain); bail: - if (domain_str) { - free(domain_str); - domain_str = NULL; - } - if (shell_absName) { - free(shell_absName); - shell_absName = NULL; - } - if (absName) { - free(absName); - absName = NULL; - } - if (nErr != AEE_SUCCESS) { - if (domain == SDSP_DOMAIN_ID && fh != NULL) { - nErr = AEE_SUCCESS; - *fh = -1; - } else { - FARF(ERROR, - "Error 0x%x: %s failed for domain %d search paths used are %s, %s, " - "%s (errno %s)\n", - nErr, __func__, domain, DSP_MOUNT_LOCATION, VENDOR_DSP_LOCATION, - VENDOR_DOM_LOCATION, strerror(errno)); - } - } - return nErr; + if(domain_str) { + free(domain_str); + domain_str = NULL; + } + if(shell_absName) { + free(shell_absName); + shell_absName = NULL; + } + if(absName) { + free(absName); + absName = NULL; + } + if(nErr != AEE_SUCCESS) { + if(domain == SDSP_DOMAIN_ID && fh != NULL) { + nErr = AEE_SUCCESS; + *fh = -1; + } else { + FARF(ERROR, + "Error 0x%x: %s failed for domain %d search " + "paths used are %s, %s, " + "%s (errno %s)\n", + nErr, __func__, domain, DSP_MOUNT_LOCATION, + VENDOR_DSP_LOCATION, VENDOR_DOM_LOCATION, + strerror(errno)); + } + } + return nErr; } /* @@ -3542,619 +4102,733 @@ static int open_shell(int domain_id, apps_std_FILE *fh, int unsigned_shell) { * * Return : 0 on success */ -static int fastrpc_enable_kernel_optimizations(int domain) { - int nErr = AEE_SUCCESS, dev = hlist[domain].dev, - dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); - const uint32_t max_concurrency = 25; - - if (((dom != CDSP_DOMAIN_ID) && (dom != CDSP1_DOMAIN_ID) && - (dom != GDSP0_DOMAIN_ID) && (dom != GDSP1_DOMAIN_ID)) || (hlist[domain].dsppd != USERPD)) - goto bail; - errno = 0; - - nErr = ioctl_optimization(dev, max_concurrency); - // TODO:Bharath - if ((nErr == -1 || nErr == (DSP_AEE_EOFFSET + AEE_ERPC)) && - (errno == ENOTTY || errno == EINVAL || errno == EBADRQC)) { - /* - * Kernel optimizations not supported. Ignore IOCTL failure - * TODO: kernel cleanup to return ENOTTY for all unsupported IOCTLs - */ - nErr = 0; - } +static int +fastrpc_enable_kernel_optimizations(int domain) +{ + int nErr = AEE_SUCCESS, dev = hlist[domain].dev, + dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); + const uint32_t max_concurrency = 25; + + if(((dom != CDSP_DOMAIN_ID) && (dom != CDSP1_DOMAIN_ID) + && (dom != GDSP0_DOMAIN_ID) && (dom != GDSP1_DOMAIN_ID)) + || (hlist[domain].dsppd != USERPD)) + goto bail; + errno = 0; + + nErr = ioctl_optimization(dev, max_concurrency); + // TODO:Bharath + if((nErr == -1 || nErr == (DSP_AEE_EOFFSET + AEE_ERPC)) + && (errno == ENOTTY || errno == EINVAL || errno == EBADRQC)) { + /* + * Kernel optimizations not supported. Ignore IOCTL failure + * TODO: kernel cleanup to return ENOTTY for all unsupported + * IOCTLs + */ + nErr = 0; + } bail: - if (nErr) { - FARF(RUNTIME_RPC_ERROR, "Error 0x%x: %s failed for domain %d (%s)\n", nErr, __func__, - domain, strerror(errno)); - } - /* - * Since this is a performance optimization, print error but ignore - * failure until the feature is stable enough. - */ - return 0; + if(nErr) { + FARF(RUNTIME_RPC_ERROR, + "Error 0x%x: %s failed for domain %d (%s)\n", nErr, + __func__, domain, strerror(errno)); + } + /* + * Since this is a performance optimization, print error but ignore + * failure until the feature is stable enough. + */ + return 0; } -void print_process_attrs(int domain) { - bool dbgMode = false, crc = false, signedMd = false, unsignedMd = false, - qos = false, configPDdump = false; - bool debugPDdump = false, KernelPerf = false, DSPperf = false, - iregion = false, qtf = false, uaf = false; - int one_mb = 1024 * 1024; - int pd_initmem_size = 0; - bool logpkt = false; - - if (IS_DEBUG_MODE_ENABLED(hlist[domain].procattrs)) - dbgMode = true; - if (IS_CRC_CHECK_ENABLED(hlist[domain].procattrs)) - crc = true; - if (hlist[domain].unsigned_module) { - unsignedMd = true; - pd_initmem_size = 5 * one_mb; - } else { - signedMd = true; - pd_initmem_size = hlist[domain].pd_initmem_size; - } - if (hlist[domain].qos.adaptive_qos) - qos = true; - if (hlist[domain].pd_dump | fastrpc_config_is_pddump_enabled()) - configPDdump = true; - if (fastrpc_get_property_int(FASTRPC_DEBUG_PDDUMP, 0)) - debugPDdump = true; - if (hlist[domain].procattrs & FASTRPC_MODE_PERF_KERNEL) - KernelPerf = true; - if (hlist[domain].procattrs & FASTRPC_MODE_PERF_DSP) - DSPperf = true; - if (fastrpc_config_is_log_iregion_enabled()) - iregion = true; - if (fastrpc_config_is_qtf_tracing_enabled()) - qtf = true; - if (fastrpc_config_is_uaf_enabled()) - uaf = true; - if (fastrpc_config_is_logpacket_enabled()) - logpkt = true; - FARF(ALWAYS, - "Info: Created user PD on domain %d, dbg_trace 0x%x, enabled attr=> RPC " - "timeout:%d, Dbg Mode:%s, CRC:%s, Unsigned:%s, Signed:%s, Adapt QOS:%s, " - "PD dump: (Config:%s, Dbg:%s), Perf: (Kernel:%s, DSP:%s), Iregion:%s, " - "QTF:%s, UAF:%s userPD initmem len:0x%x, Log pkt: %s", - domain, fastrpc_trace, fastrpc_config_get_rpctimeout(), - (dbgMode ? "Y" : "N"), (crc ? "Y" : "N"), (unsignedMd ? "Y" : "N"), - (signedMd ? "Y" : "N"), (qos ? "Y" : "N"), (configPDdump ? "Y" : "N"), - (debugPDdump ? "Y" : "N"), (KernelPerf ? "Y" : "N"), - (DSPperf ? "Y" : "N"), (iregion ? "Y" : "N"), (qtf ? "Y" : "N"), - (uaf ? "Y" : "N"), pd_initmem_size, (logpkt ? "Y" : "N")); - return; +void +print_process_attrs(int domain) +{ + bool dbgMode = false, crc = false, signedMd = false, + unsignedMd = false, qos = false, configPDdump = false; + bool debugPDdump = false, KernelPerf = false, DSPperf = false, + iregion = false, qtf = false, uaf = false; + int one_mb = 1024 * 1024; + int pd_initmem_size = 0; + bool logpkt = false; + + if(IS_DEBUG_MODE_ENABLED(hlist[domain].procattrs)) + dbgMode = true; + if(IS_CRC_CHECK_ENABLED(hlist[domain].procattrs)) + crc = true; + if(hlist[domain].unsigned_module) { + unsignedMd = true; + pd_initmem_size = 5 * one_mb; + } else { + signedMd = true; + pd_initmem_size = hlist[domain].pd_initmem_size; + } + if(hlist[domain].qos.adaptive_qos) + qos = true; + if(hlist[domain].pd_dump | fastrpc_config_is_pddump_enabled()) + configPDdump = true; + if(fastrpc_get_property_int(FASTRPC_DEBUG_PDDUMP, 0)) + debugPDdump = true; + if(hlist[domain].procattrs & FASTRPC_MODE_PERF_KERNEL) + KernelPerf = true; + if(hlist[domain].procattrs & FASTRPC_MODE_PERF_DSP) + DSPperf = true; + if(fastrpc_config_is_log_iregion_enabled()) + iregion = true; + if(fastrpc_config_is_qtf_tracing_enabled()) + qtf = true; + if(fastrpc_config_is_uaf_enabled()) + uaf = true; + if(fastrpc_config_is_logpacket_enabled()) + logpkt = true; + FARF(ALWAYS, + "Info: Created user PD on domain %d, dbg_trace 0x%x, enabled " + "attr=> RPC " + "timeout:%d, Dbg Mode:%s, CRC:%s, Unsigned:%s, Signed:%s, Adapt " + "QOS:%s, " + "PD dump: (Config:%s, Dbg:%s), Perf: (Kernel:%s, DSP:%s), " + "Iregion:%s, " + "QTF:%s, UAF:%s userPD initmem len:0x%x, Log pkt: %s", + domain, fastrpc_trace, fastrpc_config_get_rpctimeout(), + (dbgMode ? "Y" : "N"), (crc ? "Y" : "N"), + (unsignedMd ? "Y" : "N"), (signedMd ? "Y" : "N"), + (qos ? "Y" : "N"), (configPDdump ? "Y" : "N"), + (debugPDdump ? "Y" : "N"), (KernelPerf ? "Y" : "N"), + (DSPperf ? "Y" : "N"), (iregion ? "Y" : "N"), (qtf ? "Y" : "N"), + (uaf ? "Y" : "N"), pd_initmem_size, (logpkt ? "Y" : "N")); + return; } -static int remote_init(int domain) { - int nErr = AEE_SUCCESS, ioErr = 0; - int dev = -1; - struct fastrpc_proc_sess_info sess_info = {0}; - apps_std_FILE fh = -1; - int pd_type = 0, errno_save = 0; - uint32_t info = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); - int shared_buf_support = 0; - char *file = NULL; - int flags = 0, filelen = 0, memlen = 0, filefd = -1; - - FARF(RUNTIME_RPC_HIGH, "starting %s for domain %d", __func__, domain); - /* - * is_proc_sharedbuf_supported_dsp call should be made before - * mutex lock (hlist[domain].mut), Since remote_get_info is also locked - * by the same mutex - */ - shared_buf_support = is_proc_sharedbuf_supported_dsp(domain); - pthread_setspecific(tlsKey, (void *)&hlist[domain]); - pd_type = hlist[domain].dsppd; - VERIFYC(pd_type > DEFAULT_UNUSED && pd_type < MAX_PD_TYPE, AEE_EBADITEM); - if (hlist[domain].dev == -1) { - dev = open_device_node(domain); - VERIFYC(dev >= 0, AEE_ECONNREFUSED); - // Set session relation info using FASTRPC_INVOKE2_SESS_INFO - sess_info.domain_id = info; - sess_info.pd_type = pd_type; - sess_info.session_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); - - nErr = ioctl_session_info(dev, &sess_info); - if (nErr == AEE_SUCCESS) { - info = sess_info.domain_id; - // Skip setting session related info in multiple ioctl calls, if - // FASTRPC_CONTROL_SESS_INFO is supported - goto set_sess_info_supported; - } else { - // Fallback to previous approach, if FASTRPC_CONTROL_SESS_INFO is not - // supported - FARF(RUNTIME_RPC_HIGH, - "%s: FASTRPC_CONTROL_SESS_INFO not supported with error %d", - __func__, nErr); - } - - if (pd_type == SENSORS_STATICPD || pd_type == GUEST_OS_SHARED) { - struct fastrpc_ctrl_smmu smmu = {0}; - smmu.sharedcb = 1; - if (ioctl_control(dev, DSPRPC_SMMU_SUPPORT, &smmu)) { - FARF(RUNTIME_RPC_HIGH, "%s: DSPRPC_SMMU_SUPPORT not supported", - __func__); - } - } - nErr = ioctl_getinfo(dev, &info); - set_sess_info_supported: - hlist[domain].info = -1; - if (nErr == AEE_SUCCESS) { - hlist[domain].info = info; - } else if (errno == EACCES) { - FARF(ERROR, - "Error %d: %s: app does not have access to fastrpc device of domain " - "%d (%s)", - nErr, __func__, domain, strerror(errno)); - goto bail; - } else if (errno == ECONNREFUSED || (errno == ENODEV)) { - nErr = AEE_ECONNREFUSED; - FARF(ERROR, "Error %d: %s: fastRPC device driver is disabled (%s)", nErr, - __func__, strerror(errno)); - goto bail; - } else if (nErr) { - FARF(ERROR, "Error 0x%x: %s: failed to setup fastrpc session in kernel", - nErr, __func__); - goto bail; - } - - // Set session id - if (IS_EXTENDED_DOMAIN_ID(domain)) - VERIFY(AEE_SUCCESS == (nErr = ioctl_setmode(dev, FASTRPC_SESSION_ID1))); - - FARF(RUNTIME_RPC_HIGH, "%s: device %d opened with info 0x%x (attach %d)", - __func__, dev, hlist[domain].info, pd_type); - // keep the memory we used to allocate - if (pd_type == ROOT_PD || pd_type == GUEST_OS_SHARED || - pd_type == SECURE_STATICPD) { - FARF(RUNTIME_RPC_HIGH, - "%s: attaching to guest OS/Secure PD (attach %d) for domain %d", - __func__, pd_type, domain); - if (pd_type == SECURE_STATICPD) { - file = calloc(1, (int)(strlen(hlist[domain].dsppdname) + 1)); - VERIFYC(file, AEE_ENOMEMORY); - strlcpy((char *)file, hlist[domain].dsppdname, - strlen(hlist[domain].dsppdname) + 1); - filelen = strlen(hlist[domain].dsppdname) + 1; - } - flags = FASTRPC_INIT_ATTACH; - ioErr = ioctl_init(dev, flags, 0, (unsigned char *)file, filelen, -1, 0, 0, 0, 0); - if (file) { - free(file); - file = NULL; - } - VERIFYC((!ioErr || errno == ENOTTY || errno == ENXIO || errno == EINVAL), - AEE_ERPC); - } else if (pd_type == AUDIO_STATICPD || pd_type == OIS_STATICPD) { - FARF(RUNTIME_RPC_HIGH, "%s: creating static user PD for domain %d", - __func__, domain); - file = - rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, - (int)(strlen(hlist[domain].dsppdname) + 1)); - VERIFYC(file, AEE_ENORPCMEMORY); - strlcpy((char *)file, hlist[domain].dsppdname, - strlen(hlist[domain].dsppdname) + 1); - filelen = strlen(hlist[domain].dsppdname) + 1; - flags = FASTRPC_INIT_CREATE_STATIC; - // 3MB of remote heap for dynamic loading is available only for Audio PD. - if (pd_type == AUDIO_STATICPD) { - memlen = 3 * 1024 * 1024; - } - ioErr = - ioctl_init(dev, flags, 0, (unsigned char *)file, filelen, -1, 0, memlen, 0, 0); - if (ioErr) { - nErr = convert_kernel_to_user_error(ioErr, errno); - goto bail; - } - } else if (pd_type == SENSORS_STATICPD) { - FARF(RUNTIME_RPC_HIGH, "%s: attaching to sensors PD for domain %d", - __func__, domain); - flags = FASTRPC_INIT_ATTACH_SENSORS; - ioErr = ioctl_init(dev, flags, 0, (unsigned char *)0, 0, -1, 0, 0, 0, 0); - VERIFYC((!ioErr || errno == ENOTTY || errno == ENXIO || errno == EINVAL), - AEE_ERPC); - } else if (pd_type == USERPD) { - uint64_t len = 0; - int readlen = 0, eof; - apps_std_FILE fsig = -1; - uint64_t siglen = 0; +static int +remote_init(int domain) +{ + int nErr = AEE_SUCCESS, ioErr = 0; + int dev = -1; + struct fastrpc_proc_sess_info sess_info = { 0 }; + apps_std_FILE fh = -1; + int pd_type = 0, errno_save = 0; + uint32_t info = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); + int shared_buf_support = 0; + char *file = NULL; + int flags = 0, filelen = 0, memlen = 0, filefd = -1; + + FARF(RUNTIME_RPC_HIGH, "starting %s for domain %d", __func__, domain); + /* + * is_proc_sharedbuf_supported_dsp call should be made before + * mutex lock (hlist[domain].mut), Since remote_get_info is also locked + * by the same mutex + */ + shared_buf_support = is_proc_sharedbuf_supported_dsp(domain); + pthread_setspecific(tlsKey, (void *)&hlist[domain]); + pd_type = hlist[domain].dsppd; + VERIFYC(pd_type > DEFAULT_UNUSED && pd_type < MAX_PD_TYPE, + AEE_EBADITEM); + if(hlist[domain].dev == -1) { + dev = open_device_node(domain); + VERIFYC(dev >= 0, AEE_ECONNREFUSED); + // Set session relation info using FASTRPC_INVOKE2_SESS_INFO + sess_info.domain_id = info; + sess_info.pd_type = pd_type; + sess_info.session_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); + + nErr = ioctl_session_info(dev, &sess_info); + if(nErr == AEE_SUCCESS) { + info = sess_info.domain_id; + // Skip setting session related info in multiple ioctl + // calls, if FASTRPC_CONTROL_SESS_INFO is supported + goto set_sess_info_supported; + } else { + // Fallback to previous approach, if + // FASTRPC_CONTROL_SESS_INFO is not supported + FARF(RUNTIME_RPC_HIGH, + "%s: FASTRPC_CONTROL_SESS_INFO not supported " + "with error %d", + __func__, nErr); + } + + if(pd_type == SENSORS_STATICPD || pd_type == GUEST_OS_SHARED) { + struct fastrpc_ctrl_smmu smmu = { 0 }; + smmu.sharedcb = 1; + if(ioctl_control(dev, DSPRPC_SMMU_SUPPORT, &smmu)) { + FARF(RUNTIME_RPC_HIGH, + "%s: DSPRPC_SMMU_SUPPORT not supported", + __func__); + } + } + nErr = ioctl_getinfo(dev, &info); + set_sess_info_supported: + hlist[domain].info = -1; + if(nErr == AEE_SUCCESS) { + hlist[domain].info = info; + } else if(errno == EACCES) { + FARF(ERROR, + "Error %d: %s: app does not have access to " + "fastrpc device of domain " + "%d (%s)", + nErr, __func__, domain, strerror(errno)); + goto bail; + } else if(errno == ECONNREFUSED || (errno == ENODEV)) { + nErr = AEE_ECONNREFUSED; + FARF(ERROR, + "Error %d: %s: fastRPC device driver is disabled " + "(%s)", + nErr, __func__, strerror(errno)); + goto bail; + } else if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: failed to setup fastrpc session " + "in kernel", + nErr, __func__); + goto bail; + } + + // Set session id + if(IS_EXTENDED_DOMAIN_ID(domain)) + VERIFY(AEE_SUCCESS + == (nErr + = ioctl_setmode(dev, FASTRPC_SESSION_ID1))); + + FARF(RUNTIME_RPC_HIGH, + "%s: device %d opened with info 0x%x (attach %d)", + __func__, dev, hlist[domain].info, pd_type); + // keep the memory we used to allocate + if(pd_type == ROOT_PD || pd_type == GUEST_OS_SHARED + || pd_type == SECURE_STATICPD) { + FARF(RUNTIME_RPC_HIGH, + "%s: attaching to guest OS/Secure PD (attach %d) " + "for domain %d", + __func__, pd_type, domain); + if(pd_type == SECURE_STATICPD) { + file = calloc( + 1, (int)(strlen(hlist[domain].dsppdname) + + 1)); + VERIFYC(file, AEE_ENOMEMORY); + strlcpy((char *)file, hlist[domain].dsppdname, + strlen(hlist[domain].dsppdname) + 1); + filelen = strlen(hlist[domain].dsppdname) + 1; + } + flags = FASTRPC_INIT_ATTACH; + ioErr + = ioctl_init(dev, flags, 0, (unsigned char *)file, + filelen, -1, 0, 0, 0, 0); + if(file) { + free(file); + file = NULL; + } + VERIFYC((!ioErr || errno == ENOTTY || errno == ENXIO + || errno == EINVAL), + AEE_ERPC); + } else if(pd_type == AUDIO_STATICPD + || pd_type == OIS_STATICPD) { + FARF(RUNTIME_RPC_HIGH, + "%s: creating static user PD for domain %d", + __func__, domain); + file = rpcmem_alloc_internal( + 0, RPCMEM_HEAP_DEFAULT, + (int)(strlen(hlist[domain].dsppdname) + 1)); + VERIFYC(file, AEE_ENORPCMEMORY); + strlcpy((char *)file, hlist[domain].dsppdname, + strlen(hlist[domain].dsppdname) + 1); + filelen = strlen(hlist[domain].dsppdname) + 1; + flags = FASTRPC_INIT_CREATE_STATIC; + // 3MB of remote heap for dynamic loading is available + // only for Audio PD. + if(pd_type == AUDIO_STATICPD) { + memlen = 3 * 1024 * 1024; + } + ioErr + = ioctl_init(dev, flags, 0, (unsigned char *)file, + filelen, -1, 0, memlen, 0, 0); + if(ioErr) { + nErr = convert_kernel_to_user_error(ioErr, + errno); + goto bail; + } + } else if(pd_type == SENSORS_STATICPD) { + FARF(RUNTIME_RPC_HIGH, + "%s: attaching to sensors PD for domain %d", + __func__, domain); + flags = FASTRPC_INIT_ATTACH_SENSORS; + ioErr = ioctl_init(dev, flags, 0, (unsigned char *)0, + 0, -1, 0, 0, 0, 0); + VERIFYC((!ioErr || errno == ENOTTY || errno == ENXIO + || errno == EINVAL), + AEE_ERPC); + } else if(pd_type == USERPD) { + uint64_t len = 0; + int readlen = 0, eof; + apps_std_FILE fsig = -1; + uint64_t siglen = 0; #ifndef VIRTUAL_FASTRPC #if !defined(SYSTEM_RPC_LIBRARY) - open_shell(domain, &fh, hlist[domain].unsigned_module); + open_shell(domain, &fh, hlist[domain].unsigned_module); #endif #endif - hlist[domain].procattrs = get_process_attrs(domain); - if (IS_DEBUG_MODE_ENABLED(hlist[domain].procattrs)) - get_process_testsig(&fsig, &siglen); - - flags = FASTRPC_INIT_CREATE; - if (fh != -1) { - VERIFY(AEE_SUCCESS == (nErr = apps_std_flen(fh, &len))); - filelen = len + siglen; - VERIFYC(filelen && filelen < INT_MAX, AEE_EFILE); - file = rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, (size_t)filelen); - VERIFYC(file, AEE_ENORPCMEMORY); - VERIFY(AEE_SUCCESS == - (nErr = apps_std_fread(fh, (unsigned char *)file, len, &readlen, &eof))); - VERIFYC((int)len == readlen, AEE_EFILE); - filefd = rpcmem_to_fd_internal((void *)file); - filelen = (int)len; - VERIFYC(filefd != -1, AEE_ERPC); - } else { - siglen = 0; - fsig = -1; - } - - if (!(FASTRPC_MODE_UNSIGNED_MODULE & hlist[domain].procattrs)) { - memlen = hlist[domain].pd_initmem_size; - } else { - if (hlist[domain].pd_initmem_size != DEFAULT_PD_INITMEM_SIZE) - FARF(ERROR, "Setting user PD initial memory length is not supported " - "for unsigned PD, using default size\n"); - } - errno = 0; - - if (shared_buf_support) { - fastrpc_process_pack_params(dev, domain); - } - if (hlist[domain].procattrs) { - if (siglen && fsig != -1) { - VERIFY(AEE_SUCCESS == - (nErr = apps_std_fread(fsig, (unsigned char *)(file + len), siglen, - &readlen, &eof))); - VERIFYC(siglen == (uint64_t)readlen, AEE_EFILE); - filelen = len + siglen; - } - } - ioErr = ioctl_init(dev, flags, hlist[domain].procattrs, (unsigned char *)file, - filelen, filefd, NULL, memlen, -1, siglen); - if (ioErr) { - nErr = ioErr; - if (errno == ECONNREFUSED) { - nErr = AEE_ECONNREFUSED; - FARF(ERROR, - "Error 0x%x: %s: untrusted app trying to offload to signed " - "remote process (errno %d, %s). Try offloading to unsignedPD " - "using remote_session_control", - nErr, __func__, errno, strerror(errno)); - } - goto bail; - } - print_process_attrs(domain); - } else { - FARF(ERROR, "Error: %s called for unknown mode %d", __func__, pd_type); - } - hlist[domain].dev = dev; - dev = -1; - hlist[domain].disable_exit_logs = 0; - } + hlist[domain].procattrs = get_process_attrs(domain); + if(IS_DEBUG_MODE_ENABLED(hlist[domain].procattrs)) + get_process_testsig(&fsig, &siglen); + + flags = FASTRPC_INIT_CREATE; + if(fh != -1) { + VERIFY(AEE_SUCCESS + == (nErr = apps_std_flen(fh, &len))); + filelen = len + siglen; + VERIFYC(filelen && filelen < INT_MAX, + AEE_EFILE); + file = rpcmem_alloc_internal( + 0, RPCMEM_HEAP_DEFAULT, (size_t)filelen); + VERIFYC(file, AEE_ENORPCMEMORY); + VERIFY(AEE_SUCCESS + == (nErr = apps_std_fread( + fh, (unsigned char *)file, len, + &readlen, &eof))); + VERIFYC((int)len == readlen, AEE_EFILE); + filefd = rpcmem_to_fd_internal((void *)file); + filelen = (int)len; + VERIFYC(filefd != -1, AEE_ERPC); + } else { + siglen = 0; + fsig = -1; + } + + if(!(FASTRPC_MODE_UNSIGNED_MODULE + & hlist[domain].procattrs)) { + memlen = hlist[domain].pd_initmem_size; + } else { + if(hlist[domain].pd_initmem_size + != DEFAULT_PD_INITMEM_SIZE) + FARF(ERROR, + "Setting user PD initial memory " + "length is not supported " + "for unsigned PD, using default " + "size\n"); + } + errno = 0; + + if(shared_buf_support) { + fastrpc_process_pack_params(dev, domain); + } + if(hlist[domain].procattrs) { + if(siglen && fsig != -1) { + VERIFY( + AEE_SUCCESS + == (nErr = apps_std_fread( + fsig, + (unsigned char *)(file + + len), + siglen, &readlen, &eof))); + VERIFYC(siglen == (uint64_t)readlen, + AEE_EFILE); + filelen = len + siglen; + } + } + ioErr = ioctl_init(dev, flags, hlist[domain].procattrs, + (unsigned char *)file, filelen, + filefd, NULL, memlen, -1, siglen); + if(ioErr) { + nErr = ioErr; + if(errno == ECONNREFUSED) { + nErr = AEE_ECONNREFUSED; + FARF(ERROR, + "Error 0x%x: %s: untrusted app " + "trying to offload to signed " + "remote process (errno %d, %s). " + "Try offloading to unsignedPD " + "using remote_session_control", + nErr, __func__, errno, + strerror(errno)); + } + goto bail; + } + print_process_attrs(domain); + } else { + FARF(ERROR, "Error: %s called for unknown mode %d", + __func__, pd_type); + } + hlist[domain].dev = dev; + dev = -1; + hlist[domain].disable_exit_logs = 0; + } bail: - // errno is being set to 0 in apps_std_fclose and we need original errno to - // return proper error to user call - errno_save = errno; - if (file) { - rpcmem_free_internal(file); - file = NULL; - } - if (dev >= 0) { - close_device_node(domain, dev); - } - if (fh != -1) { - apps_std_fclose(fh); - } - if (nErr != AEE_SUCCESS) { - errno = errno_save; - if ((nErr == -1) && (errno == ECONNRESET)) { - nErr = AEE_ECONNRESET; - } - FARF(ERROR, "Error 0x%x: %s failed for domain %d, errno %s, ioErr %d\n", - nErr, __func__, domain, strerror(errno), ioErr); - } - FARF(RUNTIME_RPC_HIGH, "Done with %s, err: 0x%x, dev: %d", __func__, nErr, - hlist[domain].dev); - return nErr; + // errno is being set to 0 in apps_std_fclose and we need original + // errno to return proper error to user call + errno_save = errno; + if(file) { + rpcmem_free_internal(file); + file = NULL; + } + if(dev >= 0) { + close_device_node(domain, dev); + } + if(fh != -1) { + apps_std_fclose(fh); + } + if(nErr != AEE_SUCCESS) { + errno = errno_save; + if((nErr == -1) && (errno == ECONNRESET)) { + nErr = AEE_ECONNRESET; + } + FARF(ERROR, + "Error 0x%x: %s failed for domain %d, errno %s, ioErr " + "%d\n", + nErr, __func__, domain, strerror(errno), ioErr); + } + FARF(RUNTIME_RPC_HIGH, "Done with %s, err: 0x%x, dev: %d", __func__, + nErr, hlist[domain].dev); + return nErr; } -__attribute__((destructor)) static void close_dev(void) { - int i; - - FARF(RUNTIME_RPC_HIGH, "%s: unloading library %s", __func__, - fastrpc_library[DEFAULT_DOMAIN_ID]); - FOR_EACH_EFFECTIVE_DOMAIN_ID(i) { - domain_deinit(i); - } - deinit_fastrpc_dsp_lib_refcnt(); - pl_deinit(); - PL_DEINIT(fastrpc_apps_user); +__attribute__((destructor)) static void +close_dev(void) +{ + int i; + + FARF(RUNTIME_RPC_HIGH, "%s: unloading library %s", __func__, + fastrpc_library[DEFAULT_DOMAIN_ID]); + FOR_EACH_EFFECTIVE_DOMAIN_ID(i) { domain_deinit(i); } + deinit_fastrpc_dsp_lib_refcnt(); + pl_deinit(); + PL_DEINIT(fastrpc_apps_user); } -remote_handle64 get_adsp_current_process1_handle(int domain) { - remote_handle64 local; - int nErr = AEE_SUCCESS; - - if (hlist[domain].cphandle) { - return hlist[domain].cphandle; - } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_update_module_list( - DOMAIN_LIST_PREPEND, domain, - _const_adsp_current_process1_handle, &local, NULL))); - hlist[domain].cphandle = local; - return hlist[domain].cphandle; +remote_handle64 +get_adsp_current_process1_handle(int domain) +{ + remote_handle64 local; + int nErr = AEE_SUCCESS; + + if(hlist[domain].cphandle) { + return hlist[domain].cphandle; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + DOMAIN_LIST_PREPEND, domain, + _const_adsp_current_process1_handle, &local, NULL))); + hlist[domain].cphandle = local; + return hlist[domain].cphandle; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: adsp current process handle failed. domain %d (errno " - "%s)\n", - nErr, domain, strerror(errno)); - } - return INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: adsp current process handle failed. domain " + "%d (errno " + "%s)\n", + nErr, domain, strerror(errno)); + } + return INVALID_HANDLE; } -remote_handle64 get_adspmsgd_adsp1_handle(int domain) { - remote_handle64 local; - int nErr = AEE_SUCCESS; - - if (hlist[domain].msghandle) { - return hlist[domain].msghandle; - } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_update_module_list( - DOMAIN_LIST_PREPEND, domain, - _const_adspmsgd_adsp1_handle, &local, NULL))); - hlist[domain].msghandle = local; - return hlist[domain].msghandle; +remote_handle64 +get_adspmsgd_adsp1_handle(int domain) +{ + remote_handle64 local; + int nErr = AEE_SUCCESS; + + if(hlist[domain].msghandle) { + return hlist[domain].msghandle; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + DOMAIN_LIST_PREPEND, domain, + _const_adspmsgd_adsp1_handle, &local, NULL))); + hlist[domain].msghandle = local; + return hlist[domain].msghandle; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: get adsp msgd handle failed. domain %d (errno %s)\n", - nErr, domain, strerror(errno)); - } - return INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: get adsp msgd handle failed. domain %d " + "(errno %s)\n", + nErr, domain, strerror(errno)); + } + return INVALID_HANDLE; } -remote_handle64 get_adsp_listener1_handle(int domain) { - remote_handle64 local; - int nErr = AEE_SUCCESS; - - if (hlist[domain].listenerhandle) { - return hlist[domain].listenerhandle; - } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_update_module_list( - DOMAIN_LIST_PREPEND, domain, - _const_adsp_listener1_handle, &local, NULL))); - hlist[domain].listenerhandle = local; - return hlist[domain].listenerhandle; +remote_handle64 +get_adsp_listener1_handle(int domain) +{ + remote_handle64 local; + int nErr = AEE_SUCCESS; + + if(hlist[domain].listenerhandle) { + return hlist[domain].listenerhandle; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + DOMAIN_LIST_PREPEND, domain, + _const_adsp_listener1_handle, &local, NULL))); + hlist[domain].listenerhandle = local; + return hlist[domain].listenerhandle; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno %s)\n", nErr, - __func__, domain, strerror(errno)); - } - return INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d (errno %s)\n", + nErr, __func__, domain, strerror(errno)); + } + return INVALID_HANDLE; } -remote_handle64 get_remotectl1_handle(int domain) { - remote_handle64 local; - int nErr = AEE_SUCCESS; - - // If remotectlhandle is 0 allocate handle, else return handle even though - // INVALID_HANDLE handle - if (hlist[domain].remotectlhandle) { - return hlist[domain].remotectlhandle; - } - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_update_module_list(DOMAIN_LIST_PREPEND, domain, - _const_remotectl1_handle, &local, NULL))); - hlist[domain].remotectlhandle = local; - return hlist[domain].remotectlhandle; +remote_handle64 +get_remotectl1_handle(int domain) +{ + remote_handle64 local; + int nErr = AEE_SUCCESS; + + // If remotectlhandle is 0 allocate handle, else return handle even + // though INVALID_HANDLE handle + if(hlist[domain].remotectlhandle) { + return hlist[domain].remotectlhandle; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + DOMAIN_LIST_PREPEND, domain, _const_remotectl1_handle, + &local, NULL))); + hlist[domain].remotectlhandle = local; + return hlist[domain].remotectlhandle; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: remotectl1 handle failed. domain %d (errno %s)\n", - nErr, domain, strerror(errno)); - } - return INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: remotectl1 handle failed. domain %d (errno " + "%s)\n", + nErr, domain, strerror(errno)); + } + return INVALID_HANDLE; } -remote_handle64 get_adsp_perf1_handle(int domain) { - remote_handle64 local; - int nErr = AEE_SUCCESS; - - if (hlist[domain].adspperfhandle) { - return hlist[domain].adspperfhandle; - } - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_update_module_list(DOMAIN_LIST_PREPEND, domain, - _const_adsp_perf1_handle, &local, NULL))); - hlist[domain].adspperfhandle = local; - return hlist[domain].adspperfhandle; +remote_handle64 +get_adsp_perf1_handle(int domain) +{ + remote_handle64 local; + int nErr = AEE_SUCCESS; + + if(hlist[domain].adspperfhandle) { + return hlist[domain].adspperfhandle; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + DOMAIN_LIST_PREPEND, domain, _const_adsp_perf1_handle, + &local, NULL))); + hlist[domain].adspperfhandle = local; + return hlist[domain].adspperfhandle; bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: adsp_perf1 handle failed. domain %d (errno %s)\n", - nErr, domain, strerror(errno)); - } - return INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: adsp_perf1 handle failed. domain %d (errno " + "%s)\n", + nErr, domain, strerror(errno)); + } + return INVALID_HANDLE; } -static int domain_init(int domain, int *dev) { - int nErr = AEE_SUCCESS, dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); - remote_handle64 panic_handle = 0; - struct err_codes *err_codes_to_send = NULL; - - pthread_mutex_lock(&hlist[domain].mut); - if (hlist[domain].state != FASTRPC_DOMAIN_STATE_CLEAN) { - *dev = hlist[domain].dev; - pthread_mutex_unlock(&hlist[domain].mut); - return AEE_SUCCESS; - } - - QList_Ctor(&hlist[domain].ql); - QList_Ctor(&hlist[domain].nql); - QList_Ctor(&hlist[domain].rql); - hlist[domain].is_session_reserved = true; - VERIFY(AEE_SUCCESS == (nErr = remote_init(domain))); - if (fastrpc_wake_lock_enable[domain]) { - VERIFY(AEE_SUCCESS == - (nErr = update_kernel_wakelock_status( - domain, hlist[domain].dev, fastrpc_wake_lock_enable[domain]))); - } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_mem_open(domain))); - VERIFY(AEE_SUCCESS == (nErr = apps_mem_init(domain))); - - if (dom == CDSP_DOMAIN_ID || dom == CDSP1_DOMAIN_ID || dom == GDSP0_DOMAIN_ID || dom == GDSP1_DOMAIN_ID) { - panic_handle = get_adsp_current_process1_handle(domain); - if (panic_handle != INVALID_HANDLE) { - int ret = -1; - /* If error codes are available in debug config, send panic error codes to - * dsp to crash. */ - err_codes_to_send = fastrpc_config_get_errcodes(); - if (err_codes_to_send) { - ret = adsp_current_process1_panic_err_codes( - panic_handle, err_codes_to_send->err_code, - err_codes_to_send->num_err_codes); - if (AEE_SUCCESS == ret) { - FARF(ALWAYS, "%s : panic error codes sent successfully\n", __func__); - } else { - FARF(ERROR, "Error 0x%x: %s : panic error codes send failed\n", ret, - __func__); - } - } - } else { - FARF(ALWAYS, "%s : current process handle is not valid\n", __func__); - } - } - VERIFY(AEE_SUCCESS == (nErr = fastrpc_enable_kernel_optimizations(domain))); - initFileWatcher(domain); // Ignore errors - trace_marker_init(domain); - - // If client notifications are registered, initialize notification thread and - // enable notifications on domains - if (fastrpc_notif_flag) { - int ret = 0; - ret = enable_process_state_notif_on_dsp(domain); - if (ret == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED)) { - VERIFY_WPRINTF("Warning: %s: DSP does not support notifications", - __func__); - } - VERIFYC(ret == AEE_SUCCESS || - ret == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED), - ret); - } +static int +domain_init(int domain, int *dev) +{ + int nErr = AEE_SUCCESS, dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); + remote_handle64 panic_handle = 0; + struct err_codes *err_codes_to_send = NULL; + + pthread_mutex_lock(&hlist[domain].mut); + if(hlist[domain].state != FASTRPC_DOMAIN_STATE_CLEAN) { + *dev = hlist[domain].dev; + pthread_mutex_unlock(&hlist[domain].mut); + return AEE_SUCCESS; + } + + QList_Ctor(&hlist[domain].ql); + QList_Ctor(&hlist[domain].nql); + QList_Ctor(&hlist[domain].rql); + hlist[domain].is_session_reserved = true; + VERIFY(AEE_SUCCESS == (nErr = remote_init(domain))); + if(fastrpc_wake_lock_enable[domain]) { + VERIFY(AEE_SUCCESS + == (nErr = update_kernel_wakelock_status( + domain, hlist[domain].dev, + fastrpc_wake_lock_enable[domain]))); + } + VERIFY(AEE_SUCCESS == (nErr = fastrpc_mem_open(domain))); + VERIFY(AEE_SUCCESS == (nErr = apps_mem_init(domain))); + + if(dom == CDSP_DOMAIN_ID || dom == CDSP1_DOMAIN_ID + || dom == GDSP0_DOMAIN_ID || dom == GDSP1_DOMAIN_ID) { + panic_handle = get_adsp_current_process1_handle(domain); + if(panic_handle != INVALID_HANDLE) { + int ret = -1; + /* If error codes are available in debug config, send + * panic error codes to dsp to crash. */ + err_codes_to_send = fastrpc_config_get_errcodes(); + if(err_codes_to_send) { + ret = adsp_current_process1_panic_err_codes( + panic_handle, err_codes_to_send->err_code, + err_codes_to_send->num_err_codes); + if(AEE_SUCCESS == ret) { + FARF(ALWAYS, + "%s : panic error codes sent " + "successfully\n", + __func__); + } else { + FARF(ERROR, + "Error 0x%x: %s : panic error " + "codes send failed\n", + ret, __func__); + } + } + } else { + FARF(ALWAYS, + "%s : current process handle is not valid\n", + __func__); + } + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_enable_kernel_optimizations(domain))); + initFileWatcher(domain); // Ignore errors + trace_marker_init(domain); + + // If client notifications are registered, initialize notification + // thread and enable notifications on domains + if(fastrpc_notif_flag) { + int ret = 0; + ret = enable_process_state_notif_on_dsp(domain); + if(ret == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED)) { + VERIFY_WPRINTF( + "Warning: %s: DSP does not support notifications", + __func__); + } + VERIFYC( + ret == AEE_SUCCESS + || ret == (int)(DSP_AEE_EOFFSET + AEE_EUNSUPPORTED), + ret); + } #ifdef PD_EXCEPTION_LOGGING - if ((dom != SDSP_DOMAIN_ID) && hlist[domain].dsppd == ROOT_PD) { - remote_handle64 handle = 0; - handle = get_adspmsgd_adsp1_handle(domain); - if (handle != INVALID_HANDLE) { - adspmsgd_init(handle, 0x10); // enable PD exception logging - } - } + if((dom != SDSP_DOMAIN_ID) && hlist[domain].dsppd == ROOT_PD) { + remote_handle64 handle = 0; + handle = get_adspmsgd_adsp1_handle(domain); + if(handle != INVALID_HANDLE) { + adspmsgd_init(handle, + 0x10); // enable PD exception logging + } + } #endif - fastrpc_perf_init(hlist[domain].dev, domain); - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_latency_init(hlist[domain].dev, &hlist[domain].qos))); - get_dsp_dma_reverse_rpc_map_capability(domain); - hlist[domain].state = FASTRPC_DOMAIN_STATE_INIT; - hlist[domain].ref = 0; - pthread_mutex_unlock(&hlist[domain].mut); - VERIFY(AEE_SUCCESS == (nErr = listener_android_domain_init( - domain, hlist[domain].th_params.update_requested, - &hlist[domain].th_params.r_sem))); + fastrpc_perf_init(hlist[domain].dev, domain); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_latency_init(hlist[domain].dev, + &hlist[domain].qos))); + get_dsp_dma_reverse_rpc_map_capability(domain); + hlist[domain].state = FASTRPC_DOMAIN_STATE_INIT; + hlist[domain].ref = 0; + pthread_mutex_unlock(&hlist[domain].mut); + VERIFY(AEE_SUCCESS + == (nErr = listener_android_domain_init( + domain, hlist[domain].th_params.update_requested, + &hlist[domain].th_params.r_sem))); bail: - if (nErr != AEE_SUCCESS) { - domain_deinit(domain); - if (hlist) { - FARF(ERROR, "Error 0x%x: %s (%d) failed for domain %d (errno %s)\n", nErr, - __func__, hlist[domain].dev, domain, strerror(errno)); - } - *dev = -1; - return nErr; - } - if (hlist) { - FARF(RUNTIME_RPC_LOW, "Done %s with dev %d, err %d", __func__, - hlist[domain].dev, nErr); - *dev = hlist[domain].dev; - return nErr; - } else { - *dev = -1; - FARF(ERROR, - "Error 0x%x: Unable to get dev as hlist is NULL for domain %d\n", nErr, - __func__, domain); - return nErr; - } + if(nErr != AEE_SUCCESS) { + domain_deinit(domain); + if(hlist) { + FARF(ERROR, + "Error 0x%x: %s (%d) failed for domain %d (errno " + "%s)\n", + nErr, __func__, hlist[domain].dev, domain, + strerror(errno)); + } + *dev = -1; + return nErr; + } + if(hlist) { + FARF(RUNTIME_RPC_LOW, "Done %s with dev %d, err %d", __func__, + hlist[domain].dev, nErr); + *dev = hlist[domain].dev; + return nErr; + } else { + *dev = -1; + FARF(ERROR, + "Error 0x%x: Unable to get dev as hlist is NULL for " + "domain %d\n", + nErr, __func__, domain); + return nErr; + } } -static void fastrpc_apps_user_deinit(void) { - int i; - - FARF(RUNTIME_RPC_HIGH, "%s called\n", __func__); - if (tlsKey != INVALID_KEY) { - pthread_key_delete(tlsKey); - tlsKey = INVALID_KEY; - } - fastrpc_clear_handle_list(NON_DOMAIN_HANDLE_LIST_ID, DEFAULT_DOMAIN_ID); - if (hlist) { - FOR_EACH_EFFECTIVE_DOMAIN_ID(i) { - fastrpc_clear_handle_list(MULTI_DOMAIN_HANDLE_LIST_ID, i); - fastrpc_clear_handle_list(REVERSE_HANDLE_LIST_ID, i); - sem_destroy(&hlist[i].th_params.r_sem); - pthread_mutex_destroy(&hlist[i].mut); - pthread_mutex_destroy(&hlist[i].lmut); - pthread_mutex_destroy(&hlist[i].init); - pthread_mutex_destroy(&hlist[i].async_init_deinit_mut); - } - listener_android_deinit(); - free(hlist); - hlist = NULL; - } - fastrpc_context_table_deinit(); - deinit_process_signals(); - fastrpc_notif_deinit(); - apps_mem_table_deinit(); - fastrpc_wake_lock_deinit(); - fastrpc_log_deinit(); - fastrpc_mem_deinit(); - PL_DEINIT(apps_std); - PL_DEINIT(rpcmem); - PL_DEINIT(gpls); - - FARF(ALWAYS, "%s done\n", __func__); - return; +static void +fastrpc_apps_user_deinit(void) +{ + int i; + + FARF(RUNTIME_RPC_HIGH, "%s called\n", __func__); + if(tlsKey != INVALID_KEY) { + pthread_key_delete(tlsKey); + tlsKey = INVALID_KEY; + } + fastrpc_clear_handle_list(NON_DOMAIN_HANDLE_LIST_ID, + DEFAULT_DOMAIN_ID); + if(hlist) { + FOR_EACH_EFFECTIVE_DOMAIN_ID(i) + { + fastrpc_clear_handle_list(MULTI_DOMAIN_HANDLE_LIST_ID, + i); + fastrpc_clear_handle_list(REVERSE_HANDLE_LIST_ID, i); + sem_destroy(&hlist[i].th_params.r_sem); + pthread_mutex_destroy(&hlist[i].mut); + pthread_mutex_destroy(&hlist[i].lmut); + pthread_mutex_destroy(&hlist[i].init); + pthread_mutex_destroy(&hlist[i].async_init_deinit_mut); + } + listener_android_deinit(); + free(hlist); + hlist = NULL; + } + fastrpc_context_table_deinit(); + deinit_process_signals(); + fastrpc_notif_deinit(); + apps_mem_table_deinit(); + fastrpc_wake_lock_deinit(); + fastrpc_log_deinit(); + fastrpc_mem_deinit(); + PL_DEINIT(apps_std); + PL_DEINIT(rpcmem); + PL_DEINIT(gpls); + + FARF(ALWAYS, "%s done\n", __func__); + return; } -static void exit_thread(void *value) { - remote_handle64 handle = 0; - int domain; - int nErr = AEE_SUCCESS; - struct handle_list *list = NULL; - - if (!hlist) { - FARF(CRITICAL, "%s: Invalid hlist", __func__); - return; - } - list = (struct handle_list *)value; - if (list) { - domain = (int)(list - &hlist[0]); - } - - FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) { - if (hlist[domain].dev != -1) { - if ((handle = get_adsp_current_process1_handle(domain)) != - INVALID_HANDLE) { - nErr = adsp_current_process1_thread_exit(handle); - if (nErr) { - FARF(RUNTIME_RPC_HIGH, "%s: nErr:0x%x, dom:%d, h:0x%llx", __func__, nErr, - domain, handle); - } - } else if (domain == DEFAULT_DOMAIN_ID) { - nErr = adsp_current_process_thread_exit(); - if (nErr) { - FARF(RUNTIME_RPC_HIGH, "%s: nErr:0x%x, dom:%d", __func__, nErr, domain); - } - } - } - } - // Set tlsKey to NULL, so that exit_thread won't be called recursively - pthread_setspecific(tlsKey, (void *)NULL); +static void +exit_thread(void *value) +{ + remote_handle64 handle = 0; + int domain; + int nErr = AEE_SUCCESS; + struct handle_list *list = NULL; + + if(!hlist) { + FARF(CRITICAL, "%s: Invalid hlist", __func__); + return; + } + list = (struct handle_list *)value; + if(list) { + domain = (int)(list - &hlist[0]); + } + + FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) + { + if(hlist[domain].dev != -1) { + if((handle = get_adsp_current_process1_handle(domain)) + != INVALID_HANDLE) { + nErr = adsp_current_process1_thread_exit( + handle); + if(nErr) { + FARF(RUNTIME_RPC_HIGH, + "%s: nErr:0x%x, dom:%d, h:0x%llx", + __func__, nErr, domain, handle); + } + } else if(domain == DEFAULT_DOMAIN_ID) { + nErr = adsp_current_process_thread_exit(); + if(nErr) { + FARF(RUNTIME_RPC_HIGH, + "%s: nErr:0x%x, dom:%d", __func__, + nErr, domain); + } + } + } + } + // Set tlsKey to NULL, so that exit_thread won't be called recursively + pthread_setspecific(tlsKey, (void *)NULL); } /* @@ -4162,90 +4836,106 @@ static void exit_thread(void *value) { * Initializes the data structures */ -static int fastrpc_apps_user_init(void) { - int nErr = AEE_SUCCESS, i; - pthread_mutexattr_t attr; - - pthread_mutexattr_init(&attr); - pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); - - VERIFY(AEE_SUCCESS == (nErr = PL_INIT(gpls))); - VERIFY(AEE_SUCCESS == (nErr = PL_INIT(rpcmem))); - fastrpc_mem_init(); - fastrpc_context_table_init(); - fastrpc_log_init(); - fastrpc_config_init(); - pthread_mutex_init(&update_notif_list_mut, 0); - VERIFYC(NULL != (hlist = calloc(NUM_DOMAINS_EXTEND, sizeof(*hlist))), - AEE_ENOMEMORY); - FOR_EACH_EFFECTIVE_DOMAIN_ID(i) { - hlist[i].dev = -1; - hlist[i].th_params.thread_priority = DEFAULT_UTHREAD_PRIORITY; - hlist[i].jobid = 1; - hlist[i].info = -1; - hlist[i].th_params.stack_size = DEFAULT_UTHREAD_STACK_SIZE; - sem_init(&hlist[i].th_params.r_sem, 0, - 0); // Initialize semaphore count to 0 - hlist[i].dsppd = attach_guestos(i); - hlist[i].trace_marker_fd = -1; - hlist[i].state = FASTRPC_DOMAIN_STATE_CLEAN; - hlist[i].pd_initmem_size = DEFAULT_PD_INITMEM_SIZE; - QList_Ctor(&hlist[i].ql); - QList_Ctor(&hlist[i].nql); - QList_Ctor(&hlist[i].rql); - memset(hlist[i].dsppdname, 0, MAX_DSPPD_NAMELEN); - memset(hlist[i].sessionname, 0, MAX_DSPPD_NAMELEN); - pthread_mutex_init(&hlist[i].mut, &attr); - pthread_mutex_init(&hlist[i].lmut, 0); - pthread_mutex_init(&hlist[i].init, 0); - pthread_mutex_init(&hlist[i].async_init_deinit_mut, 0); - } - listener_android_init(); - VERIFY(AEE_SUCCESS == (nErr = pthread_key_create(&tlsKey, exit_thread))); - VERIFY(AEE_SUCCESS == (nErr = PL_INIT(apps_std))); - GenCrc32Tab(POLY32, crc_table); - fastrpc_notif_init(); - apps_mem_table_init(); +static int +fastrpc_apps_user_init(void) +{ + int nErr = AEE_SUCCESS, i; + pthread_mutexattr_t attr; + + pthread_mutexattr_init(&attr); + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE); + + VERIFY(AEE_SUCCESS == (nErr = PL_INIT(gpls))); + VERIFY(AEE_SUCCESS == (nErr = PL_INIT(rpcmem))); + fastrpc_mem_init(); + fastrpc_context_table_init(); + fastrpc_log_init(); + fastrpc_config_init(); + pthread_mutex_init(&update_notif_list_mut, 0); + VERIFYC(NULL != (hlist = calloc(NUM_DOMAINS_EXTEND, sizeof(*hlist))), + AEE_ENOMEMORY); + FOR_EACH_EFFECTIVE_DOMAIN_ID(i) + { + hlist[i].dev = -1; + hlist[i].th_params.thread_priority = DEFAULT_UTHREAD_PRIORITY; + hlist[i].jobid = 1; + hlist[i].info = -1; + hlist[i].th_params.stack_size = DEFAULT_UTHREAD_STACK_SIZE; + sem_init(&hlist[i].th_params.r_sem, 0, + 0); // Initialize semaphore count to 0 + hlist[i].dsppd = attach_guestos(i); + hlist[i].trace_marker_fd = -1; + hlist[i].state = FASTRPC_DOMAIN_STATE_CLEAN; + hlist[i].pd_initmem_size = DEFAULT_PD_INITMEM_SIZE; + QList_Ctor(&hlist[i].ql); + QList_Ctor(&hlist[i].nql); + QList_Ctor(&hlist[i].rql); + memset(hlist[i].dsppdname, 0, MAX_DSPPD_NAMELEN); + memset(hlist[i].sessionname, 0, MAX_DSPPD_NAMELEN); + pthread_mutex_init(&hlist[i].mut, &attr); + pthread_mutex_init(&hlist[i].lmut, 0); + pthread_mutex_init(&hlist[i].init, 0); + pthread_mutex_init(&hlist[i].async_init_deinit_mut, 0); + } + listener_android_init(); + VERIFY(AEE_SUCCESS + == (nErr = pthread_key_create(&tlsKey, exit_thread))); + VERIFY(AEE_SUCCESS == (nErr = PL_INIT(apps_std))); + GenCrc32Tab(POLY32, crc_table); + fastrpc_notif_init(); + apps_mem_table_init(); bail: - /* - print address of static variable - to know duplicate instance of libcdsprpc.so - */ - if (nErr) { - FARF(ERROR, - "Error 0x%x: %s failed. default domain:%x and &fastrpc_trace:%p \n", - nErr, __func__, DEFAULT_DOMAIN_ID, &fastrpc_trace); - fastrpc_apps_user_deinit(); - } else { - FARF(ALWAYS, "%s done. default domain:%x and &fastrpc_trace:%p\n", __func__, - DEFAULT_DOMAIN_ID, &fastrpc_trace); - } - return nErr; + /* + print address of static variable + to know duplicate instance of libcdsprpc.so + */ + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed. default domain:%x and " + "&fastrpc_trace:%p \n", + nErr, __func__, DEFAULT_DOMAIN_ID, &fastrpc_trace); + fastrpc_apps_user_deinit(); + } else { + FARF(ALWAYS, + "%s done. default domain:%x and &fastrpc_trace:%p\n", + __func__, DEFAULT_DOMAIN_ID, &fastrpc_trace); + } + return nErr; } PL_DEFINE(fastrpc_apps_user, fastrpc_apps_user_init, fastrpc_apps_user_deinit); -static void frpc_init(void) { PL_INIT(fastrpc_apps_user); } +static void +frpc_init(void) +{ + PL_INIT(fastrpc_apps_user); +} -int fastrpc_init_once(void) { - static pthread_once_t frpc = PTHREAD_ONCE_INIT; - int nErr = AEE_SUCCESS; - VERIFY(AEE_SUCCESS == (nErr = pthread_once(&frpc, (void *)frpc_init))); +int +fastrpc_init_once(void) +{ + static pthread_once_t frpc = PTHREAD_ONCE_INIT; + int nErr = AEE_SUCCESS; + VERIFY(AEE_SUCCESS == (nErr = pthread_once(&frpc, (void *)frpc_init))); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error %x: fastrpc init once failed\n", nErr); - } - return nErr == AEE_SUCCESS ? _pl_fastrpc_apps_user()->nErr : nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error %x: fastrpc init once failed\n", nErr); + } + return nErr == AEE_SUCCESS ? _pl_fastrpc_apps_user()->nErr : nErr; } -static int rpcmem_init_me(void) { - rpcmem_init_internal(); - return AEE_SUCCESS; +static int +rpcmem_init_me(void) +{ + rpcmem_init_internal(); + return AEE_SUCCESS; } -static void rpcmem_deinit_me(void) { - rpcmem_deinit_internal(); - return; +static void +rpcmem_deinit_me(void) +{ + rpcmem_deinit_internal(); + return; } /* @@ -4255,90 +4945,108 @@ static void rpcmem_deinit_me(void) { * Return : void. */ -static void check_multilib_util(void) { - int nErr = 0, ret = -1, ii = 0; - const char *env_name = fastrpc_dsp_lib_refcnt[DEFAULT_DOMAIN_ID]; - - /* Set env variable of default domain id to 1. */ - ret = setenv(env_name, "1", 1); - if (ret != 0 && errno == ENOMEM) { - nErr = ERRNO; - FARF(ERROR, "Error 0x%x: setenv failed for %s (domain %u), errno is %s\n", - nErr, env_name, DEFAULT_DOMAIN_ID, strerror(ERRNO)); - /* - * If failed to set env variable then free the memory allocated to - * env variables and exit the application. - */ - deinit_fastrpc_dsp_lib_refcnt(); - exit(EXIT_FAILURE); - } else { - total_dsp_lib_refcnt = 1; - } - - /* Get the values of all env variables and increment the refcount accordingly. - */ - FOR_EACH_DOMAIN_ID(ii) { - char *env_val = NULL; - env_name = fastrpc_dsp_lib_refcnt[ii]; - - /* Skip the check to get default domain env variable value as we already set - * its value. */ - if (ii == DEFAULT_DOMAIN_ID) - continue; - - env_val = getenv(env_name); - if (NULL != env_val) { - /* - * Add env value to total reference count to check - * the total number of dsp library instances loaded. - */ - total_dsp_lib_refcnt += atoi(env_val); - - /* If the total reference count exceeds one then show warning, application - * will abort on first handle open. */ - if (total_dsp_lib_refcnt > MAX_LIB_INSTANCE_ALLOWED) { - FARF(ERROR, - "Warning: %s %d instances of libxdsprpc (already loaded %s). Only " - "%d allowed\n", - fastrpc_library[DEFAULT_DOMAIN_ID], total_dsp_lib_refcnt, - fastrpc_library[ii], MAX_LIB_INSTANCE_ALLOWED); - } - } - } +static void +check_multilib_util(void) +{ + int nErr = 0, ret = -1, ii = 0; + const char *env_name = fastrpc_dsp_lib_refcnt[DEFAULT_DOMAIN_ID]; + + /* Set env variable of default domain id to 1. */ + ret = setenv(env_name, "1", 1); + if(ret != 0 && errno == ENOMEM) { + nErr = ERRNO; + FARF(ERROR, + "Error 0x%x: setenv failed for %s (domain %u), errno is " + "%s\n", + nErr, env_name, DEFAULT_DOMAIN_ID, strerror(ERRNO)); + /* + * If failed to set env variable then free the memory allocated + * to env variables and exit the application. + */ + deinit_fastrpc_dsp_lib_refcnt(); + exit(EXIT_FAILURE); + } else { + total_dsp_lib_refcnt = 1; + } + + /* Get the values of all env variables and increment the refcount + * accordingly. + */ + FOR_EACH_DOMAIN_ID(ii) + { + char *env_val = NULL; + env_name = fastrpc_dsp_lib_refcnt[ii]; + + /* Skip the check to get default domain env variable value as + * we already set its value. */ + if(ii == DEFAULT_DOMAIN_ID) + continue; + + env_val = getenv(env_name); + if(NULL != env_val) { + /* + * Add env value to total reference count to check + * the total number of dsp library instances loaded. + */ + total_dsp_lib_refcnt += atoi(env_val); + + /* If the total reference count exceeds one then show + * warning, application will abort on first handle + * open. */ + if(total_dsp_lib_refcnt > MAX_LIB_INSTANCE_ALLOWED) { + FARF(ERROR, + "Warning: %s %d instances of libxdsprpc " + "(already loaded %s). Only " + "%d allowed\n", + fastrpc_library[DEFAULT_DOMAIN_ID], + total_dsp_lib_refcnt, fastrpc_library[ii], + MAX_LIB_INSTANCE_ALLOWED); + } + } + } } __CONSTRUCTOR_ATTRIBUTE__ -static void multidsplib_env_init(void) { - const char *local_fastrpc_lib_refcnt[NUM_DOMAINS] = { - "FASTRPC_ADSP_REFCNT", "FASTRPC_MDSP_REFCNT", "FASTRPC_SDSP_REFCNT", - "FASTRPC_CDSP_REFCNT", "FASTRPC_CDSP1_REFCNT", "FASTRPC_GDSP0_REFCNT", "FASTRPC_GDSP1_REFCNT"}; - char buf[64] = {0}; - size_t env_name_len = 0; - char *env_name = NULL; - int ii = 0; - - pid_t pid = getpid(); - - /* Initialize all global array with env variable names along with process id. - */ - FOR_EACH_DOMAIN_ID(ii) { - snprintf(buf, sizeof(buf), "%s_%d", local_fastrpc_lib_refcnt[ii], pid); - env_name_len = (sizeof(char) * strlen(buf)) + 1; - env_name = malloc(env_name_len); - if (env_name) { - strlcpy(env_name, buf, env_name_len); - fastrpc_dsp_lib_refcnt[ii] = env_name; - } else { - FARF(ERROR, - "Error %d: %s: env variable allocation for %zu bytes failed, domain " - "%d\n", - ENOMEM, __func__, env_name_len, ii); - deinit_fastrpc_dsp_lib_refcnt(); - exit(EXIT_FAILURE); - } - } - check_multilib_util(); - FARF(ALWAYS, "%s: %s loaded", __func__, fastrpc_library[DEFAULT_DOMAIN_ID]); +static void +multidsplib_env_init(void) +{ + const char *local_fastrpc_lib_refcnt[NUM_DOMAINS] + = { "FASTRPC_ADSP_REFCNT", "FASTRPC_MDSP_REFCNT", + "FASTRPC_SDSP_REFCNT", "FASTRPC_CDSP_REFCNT", + "FASTRPC_CDSP1_REFCNT", "FASTRPC_GDSP0_REFCNT", + "FASTRPC_GDSP1_REFCNT" }; + char buf[64] = { 0 }; + size_t env_name_len = 0; + char *env_name = NULL; + int ii = 0; + + pid_t pid = getpid(); + + /* Initialize all global array with env variable names along with + * process id. + */ + FOR_EACH_DOMAIN_ID(ii) + { + snprintf(buf, sizeof(buf), "%s_%d", + local_fastrpc_lib_refcnt[ii], pid); + env_name_len = (sizeof(char) * strlen(buf)) + 1; + env_name = malloc(env_name_len); + if(env_name) { + strlcpy(env_name, buf, env_name_len); + fastrpc_dsp_lib_refcnt[ii] = env_name; + } else { + FARF(ERROR, + "Error %d: %s: env variable allocation for %zu " + "bytes failed, domain " + "%d\n", + ENOMEM, __func__, env_name_len, ii); + deinit_fastrpc_dsp_lib_refcnt(); + exit(EXIT_FAILURE); + } + } + check_multilib_util(); + FARF(ALWAYS, "%s: %s loaded", __func__, + fastrpc_library[DEFAULT_DOMAIN_ID]); } PL_DEFINE(rpcmem, rpcmem_init_me, rpcmem_deinit_me); diff --git a/src/fastrpc_async.c b/src/fastrpc_async.c index c3b69e50..09cc49a4 100644 --- a/src/fastrpc_async.c +++ b/src/fastrpc_async.c @@ -24,31 +24,31 @@ #include "AEEStdErr.h" #include "AEEstd.h" #include "HAP_farf.h" -#include "fastrpc_perf.h" -#include "fastrpc_common.h" #include "fastrpc_async.h" +#include "fastrpc_common.h" +#include "fastrpc_perf.h" #include "platform_libs.h" #include "verify.h" #define GET_DOMAIN_FROM_JOBID(jobid) (jobid & FASTRPC_ASYNC_DOMAIN_MASK) -#define GET_HASH_FROM_JOBID(jobid) \ - ((jobid & FASTRPC_ASYNC_HASH_MASK) >> FASTRPC_ASYNC_JOB_POS) +#define GET_HASH_FROM_JOBID(jobid) \ + ((jobid & FASTRPC_ASYNC_HASH_MASK) >> FASTRPC_ASYNC_JOB_POS) #define EVENT_COMPLETE 0xff struct fastrpc_async { - QList ql[FASTRPC_ASYNC_QUEUE_LIST_LEN]; - pthread_mutex_t mut; - pthread_t thread; - int init_done; - int deinit_started; + QList ql[FASTRPC_ASYNC_QUEUE_LIST_LEN]; + pthread_mutex_t mut; + pthread_t thread; + int init_done; + int deinit_started; }; struct fastrpc_async_job_node { - QNode qn; - fastrpc_async_descriptor_t async_desc; - bool isjobdone; - struct pollfd pfd; - int result; + QNode qn; + fastrpc_async_descriptor_t async_desc; + bool isjobdone; + struct pollfd pfd; + int result; }; pthread_mutex_t async_mut = PTHREAD_MUTEX_INITIALIZER; @@ -58,348 +58,409 @@ extern void set_thread_context(int domain); static int get_remote_async_response(int domain, fastrpc_async_jobid *jobid, int *result); -int fastrpc_search_async_job(fastrpc_async_jobid jobid, - struct fastrpc_async_job_node **async_node) { - int nErr = AEE_SUCCESS; - int domain, hash; - struct fastrpc_async *me = NULL; - QNode *pn, *pnn; - bool jobfound = false; - struct fastrpc_async_job_node *lasync_node; - - domain = GET_DOMAIN_FROM_JOBID(jobid); - hash = GET_HASH_FROM_JOBID(jobid); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - me = &lasyncinfo[domain]; - VERIFYC(me->init_done == 1, AEE_EBADPARM); - pthread_mutex_lock(&me->mut); - QLIST_NEXTSAFE_FOR_ALL(&me->ql[hash], pn, pnn) { - lasync_node = STD_RECOVER_REC(struct fastrpc_async_job_node, qn, pn); - if (lasync_node->async_desc.jobid == jobid) { - jobfound = true; - break; - } - } - pthread_mutex_unlock(&me->mut); - VERIFYC(jobfound, AEE_EBADPARM); - *async_node = lasync_node; +int +fastrpc_search_async_job(fastrpc_async_jobid jobid, + struct fastrpc_async_job_node **async_node) +{ + int nErr = AEE_SUCCESS; + int domain, hash; + struct fastrpc_async *me = NULL; + QNode *pn, *pnn; + bool jobfound = false; + struct fastrpc_async_job_node *lasync_node; + + domain = GET_DOMAIN_FROM_JOBID(jobid); + hash = GET_HASH_FROM_JOBID(jobid); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + me = &lasyncinfo[domain]; + VERIFYC(me->init_done == 1, AEE_EBADPARM); + pthread_mutex_lock(&me->mut); + QLIST_NEXTSAFE_FOR_ALL(&me->ql[hash], pn, pnn) + { + lasync_node + = STD_RECOVER_REC(struct fastrpc_async_job_node, qn, pn); + if(lasync_node->async_desc.jobid == jobid) { + jobfound = true; + break; + } + } + pthread_mutex_unlock(&me->mut); + VERIFYC(jobfound, AEE_EBADPARM); + *async_node = lasync_node; bail: - return nErr; + return nErr; } -int fastrpc_async_get_status(fastrpc_async_jobid jobid, int timeout_us, - int *result) { - int nErr = AEE_SUCCESS; - int domain; - struct fastrpc_async *me = NULL; - struct fastrpc_async_job_node *lasync_node = NULL; - eventfd_t event = 0; - - VERIFYC(result != NULL, AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_search_async_job(jobid, &lasync_node))); - domain = GET_DOMAIN_FROM_JOBID(jobid); - me = &lasyncinfo[domain]; - pthread_mutex_lock(&me->mut); - if (lasync_node->isjobdone) { // If job is done, return result - *result = lasync_node->result; - goto unlock_bail; - } else if (timeout_us == 0) { // If timeout 0, then return PENDING - nErr = AEE_EBUSY; - goto unlock_bail; - } - // If valid timeout(+ve/-ve), create poll event and wait on poll - if (-1 == (lasync_node->pfd.fd = eventfd(0, 0))) { - nErr = AEE_EFAILED; - FARF(ERROR, - "Error 0x%x: %s failed to create poll event for jobid 0x%" PRIx64 - " (%s)\n", - nErr, __func__, jobid, strerror(errno)); - goto unlock_bail; - } - lasync_node->pfd.events = POLLIN; - lasync_node->pfd.revents = 0; - pthread_mutex_unlock(&me->mut); - while (1) { - VERIFYC(0 < poll(&lasync_node->pfd, 1, timeout_us), AEE_EFAILED); - VERIFYC(0 == eventfd_read(lasync_node->pfd.fd, &event), AEE_EFAILED); - if (event) { - break; - } - } - VERIFYC(lasync_node->isjobdone, AEE_EBUSY); - *result = lasync_node->result; - goto bail; +int +fastrpc_async_get_status(fastrpc_async_jobid jobid, int timeout_us, + int *result) +{ + int nErr = AEE_SUCCESS; + int domain; + struct fastrpc_async *me = NULL; + struct fastrpc_async_job_node *lasync_node = NULL; + eventfd_t event = 0; + + VERIFYC(result != NULL, AEE_EBADPARM); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_search_async_job(jobid, &lasync_node))); + domain = GET_DOMAIN_FROM_JOBID(jobid); + me = &lasyncinfo[domain]; + pthread_mutex_lock(&me->mut); + if(lasync_node->isjobdone) { // If job is done, return result + *result = lasync_node->result; + goto unlock_bail; + } else if(timeout_us == 0) { // If timeout 0, then return PENDING + nErr = AEE_EBUSY; + goto unlock_bail; + } + // If valid timeout(+ve/-ve), create poll event and wait on poll + if(-1 == (lasync_node->pfd.fd = eventfd(0, 0))) { + nErr = AEE_EFAILED; + FARF(ERROR, + "Error 0x%x: %s failed to create poll event for jobid " + "0x%" PRIx64 " (%s)\n", + nErr, __func__, jobid, strerror(errno)); + goto unlock_bail; + } + lasync_node->pfd.events = POLLIN; + lasync_node->pfd.revents = 0; + pthread_mutex_unlock(&me->mut); + while(1) { + VERIFYC(0 < poll(&lasync_node->pfd, 1, timeout_us), + AEE_EFAILED); + VERIFYC(0 == eventfd_read(lasync_node->pfd.fd, &event), + AEE_EFAILED); + if(event) { + break; + } + } + VERIFYC(lasync_node->isjobdone, AEE_EBUSY); + *result = lasync_node->result; + goto bail; unlock_bail: - pthread_mutex_unlock(&me->mut); + pthread_mutex_unlock(&me->mut); bail: - if (nErr) { - FARF(ERROR, "Error 0x%x: %s failed for jobid 0x%" PRIx64 " (%s)\n", nErr, - __func__, jobid, strerror(errno)); - } - return nErr; + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed for jobid 0x%" PRIx64 " (%s)\n", + nErr, __func__, jobid, strerror(errno)); + } + return nErr; } -int fastrpc_remove_async_job(fastrpc_async_jobid jobid, - bool dsp_invoke_done) { - int nErr = AEE_SUCCESS; - struct fastrpc_async *me = NULL; - struct fastrpc_async_job_node *lasync_node = NULL; - int domain = -1; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_search_async_job(jobid, &lasync_node))); - domain = GET_DOMAIN_FROM_JOBID(jobid); - me = &lasyncinfo[domain]; - pthread_mutex_lock(&me->mut); - if (dsp_invoke_done && !lasync_node->isjobdone) { - pthread_mutex_unlock(&me->mut); - nErr = AEE_EBUSY; - goto bail; - } - QNode_DequeueZ(&lasync_node->qn); - pthread_mutex_unlock(&me->mut); - if (lasync_node->async_desc.type == FASTRPC_ASYNC_POLL && - lasync_node->pfd.fd != -1) { - close(lasync_node->pfd.fd); - lasync_node->pfd.fd = -1; - } - free(lasync_node); - lasync_node = NULL; +int +fastrpc_remove_async_job(fastrpc_async_jobid jobid, bool dsp_invoke_done) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_async *me = NULL; + struct fastrpc_async_job_node *lasync_node = NULL; + int domain = -1; + + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_search_async_job(jobid, &lasync_node))); + domain = GET_DOMAIN_FROM_JOBID(jobid); + me = &lasyncinfo[domain]; + pthread_mutex_lock(&me->mut); + if(dsp_invoke_done && !lasync_node->isjobdone) { + pthread_mutex_unlock(&me->mut); + nErr = AEE_EBUSY; + goto bail; + } + QNode_DequeueZ(&lasync_node->qn); + pthread_mutex_unlock(&me->mut); + if(lasync_node->async_desc.type == FASTRPC_ASYNC_POLL + && lasync_node->pfd.fd != -1) { + close(lasync_node->pfd.fd); + lasync_node->pfd.fd = -1; + } + free(lasync_node); + lasync_node = NULL; bail: - if (nErr) { - FARF(ERROR, - "Error 0x%x: %s failed for domain %d and jobid 0x%" PRIx64 " (%s)\n", - nErr, __func__, domain, jobid, strerror(errno)); - } - return nErr; + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed for domain %d and jobid 0x%" PRIx64 + " (%s)\n", + nErr, __func__, domain, jobid, strerror(errno)); + } + return nErr; } -int fastrpc_release_async_job(fastrpc_async_jobid jobid) { - return fastrpc_remove_async_job(jobid, true); +int +fastrpc_release_async_job(fastrpc_async_jobid jobid) +{ + return fastrpc_remove_async_job(jobid, true); } -int fastrpc_save_async_job(int domain, struct fastrpc_async_job *async_job, - fastrpc_async_descriptor_t *desc) { - int nErr = AEE_SUCCESS; - struct fastrpc_async *me = &lasyncinfo[domain]; - struct fastrpc_async_job_node *lasync_job = 0; - int hash = -1; - - VERIFYC(me->init_done == 1, AEE_EINVALIDJOB); - VERIFYC(NULL != (lasync_job = calloc(1, sizeof(*lasync_job))), AEE_ENOMEMORY); - QNode_CtorZ(&lasync_job->qn); - lasync_job->async_desc.jobid = async_job->jobid; - lasync_job->async_desc.type = desc->type; - lasync_job->async_desc.cb.fn = desc->cb.fn; - lasync_job->async_desc.cb.context = desc->cb.context; - lasync_job->isjobdone = false; - lasync_job->result = -1; - lasync_job->pfd.fd = -1; - hash = GET_HASH_FROM_JOBID(lasync_job->async_desc.jobid); - pthread_mutex_lock(&me->mut); - QList_AppendNode(&me->ql[hash], &lasync_job->qn); - pthread_mutex_unlock(&me->mut); - FARF(RUNTIME_RPC_HIGH, "adsprpc: %s : Saving job with jobid 0x%" PRIx64 "", - __func__, lasync_job->async_desc.jobid); +int +fastrpc_save_async_job(int domain, struct fastrpc_async_job *async_job, + fastrpc_async_descriptor_t *desc) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_async *me = &lasyncinfo[domain]; + struct fastrpc_async_job_node *lasync_job = 0; + int hash = -1; + + VERIFYC(me->init_done == 1, AEE_EINVALIDJOB); + VERIFYC(NULL != (lasync_job = calloc(1, sizeof(*lasync_job))), + AEE_ENOMEMORY); + QNode_CtorZ(&lasync_job->qn); + lasync_job->async_desc.jobid = async_job->jobid; + lasync_job->async_desc.type = desc->type; + lasync_job->async_desc.cb.fn = desc->cb.fn; + lasync_job->async_desc.cb.context = desc->cb.context; + lasync_job->isjobdone = false; + lasync_job->result = -1; + lasync_job->pfd.fd = -1; + hash = GET_HASH_FROM_JOBID(lasync_job->async_desc.jobid); + pthread_mutex_lock(&me->mut); + QList_AppendNode(&me->ql[hash], &lasync_job->qn); + pthread_mutex_unlock(&me->mut); + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s : Saving job with jobid 0x%" PRIx64 "", __func__, + lasync_job->async_desc.jobid); bail: - if (nErr) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d (%s)\n", nErr, __func__, - domain, strerror(errno)); - } - return nErr; + if(nErr) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d (%s)\n", nErr, + __func__, domain, strerror(errno)); + } + return nErr; } -void fastrpc_async_respond_all_pending_jobs(int domain) { - int i = 0; - struct fastrpc_async *me = &lasyncinfo[domain]; - struct fastrpc_async_job_node *lasync_node = NULL; - QNode *pn; - - for (i = 0; i < FASTRPC_ASYNC_QUEUE_LIST_LEN; i++) { - pthread_mutex_lock(&me->mut); - while (!QList_IsEmpty(&me->ql[i])) { - pn = QList_GetFirst(&me->ql[i]); - lasync_node = STD_RECOVER_REC(struct fastrpc_async_job_node, qn, pn); - if (!lasync_node) { - continue; - } - QNode_DequeueZ(&lasync_node->qn); - lasync_node->result = -ECONNRESET; - pthread_mutex_unlock(&me->mut); - if (lasync_node->async_desc.type == FASTRPC_ASYNC_CALLBACK) { - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s callback jobid 0x%" PRIx64 " and result 0x%x", - __func__, lasync_node->async_desc.jobid, lasync_node->result); - lasync_node->async_desc.cb.fn(lasync_node->async_desc.jobid, - lasync_node->async_desc.cb.context, - lasync_node->result); - } else if (lasync_node->async_desc.type == FASTRPC_ASYNC_POLL) { - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s poll jobid 0x%" PRIx64 " and result 0x%x", __func__, - lasync_node->async_desc.jobid, lasync_node->result); - if (lasync_node->pfd.fd != -1) { - eventfd_write(lasync_node->pfd.fd, (eventfd_t)EVENT_COMPLETE); - } - } - free(lasync_node); - lasync_node = NULL; - pthread_mutex_lock(&me->mut); - } - pthread_mutex_unlock(&me->mut); - } +void +fastrpc_async_respond_all_pending_jobs(int domain) +{ + int i = 0; + struct fastrpc_async *me = &lasyncinfo[domain]; + struct fastrpc_async_job_node *lasync_node = NULL; + QNode *pn; + + for(i = 0; i < FASTRPC_ASYNC_QUEUE_LIST_LEN; i++) { + pthread_mutex_lock(&me->mut); + while(!QList_IsEmpty(&me->ql[i])) { + pn = QList_GetFirst(&me->ql[i]); + lasync_node = STD_RECOVER_REC( + struct fastrpc_async_job_node, qn, pn); + if(!lasync_node) { + continue; + } + QNode_DequeueZ(&lasync_node->qn); + lasync_node->result = -ECONNRESET; + pthread_mutex_unlock(&me->mut); + if(lasync_node->async_desc.type + == FASTRPC_ASYNC_CALLBACK) { + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s callback jobid 0x%" PRIx64 + " and result 0x%x", + __func__, lasync_node->async_desc.jobid, + lasync_node->result); + lasync_node->async_desc.cb.fn( + lasync_node->async_desc.jobid, + lasync_node->async_desc.cb.context, + lasync_node->result); + } else if(lasync_node->async_desc.type + == FASTRPC_ASYNC_POLL) { + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s poll jobid 0x%" PRIx64 + " and result 0x%x", + __func__, lasync_node->async_desc.jobid, + lasync_node->result); + if(lasync_node->pfd.fd != -1) { + eventfd_write( + lasync_node->pfd.fd, + (eventfd_t)EVENT_COMPLETE); + } + } + free(lasync_node); + lasync_node = NULL; + pthread_mutex_lock(&me->mut); + } + pthread_mutex_unlock(&me->mut); + } } -static void *async_fastrpc_thread(void *arg) { - int nErr = AEE_SUCCESS; - struct fastrpc_async *me = (struct fastrpc_async *)arg; - int domain = (int)(me - &lasyncinfo[0]); - struct fastrpc_async_job_node *lasync_node = NULL; - int result = -1; - fastrpc_async_jobid jobid = -1; - QNode *pn, *pnn; - - int hash = -1; - bool isjobfound = false; - - /// TODO: Do we really need this line? - set_thread_context(domain); - do { - nErr = get_remote_async_response(domain, &jobid, &result); - VERIFY(nErr == AEE_SUCCESS); - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s received async response for jobid 0x%" PRIx64 - " and result 0x%x", - __func__, jobid, result); - isjobfound = false; - hash = GET_HASH_FROM_JOBID(jobid); - pthread_mutex_lock(&me->mut); - QLIST_NEXTSAFE_FOR_ALL(&me->ql[hash], pn, pnn) { - lasync_node = STD_RECOVER_REC(struct fastrpc_async_job_node, qn, pn); - if (lasync_node->async_desc.jobid == jobid) { - lasync_node->isjobdone = true; - lasync_node->result = result; - isjobfound = true; - switch (lasync_node->async_desc.type) { - case FASTRPC_ASYNC_NO_SYNC: - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s nosync jobid 0x%" PRIx64 " and result 0x%x", - __func__, lasync_node->async_desc.jobid, result); - QNode_DequeueZ(&lasync_node->qn); - pthread_mutex_unlock(&me->mut); - free(lasync_node); - lasync_node = NULL; - break; - case FASTRPC_ASYNC_POLL: - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s poll jobid 0x%" PRIx64 " and result 0x%x", __func__, - lasync_node->async_desc.jobid, result); - if (lasync_node->pfd.fd != -1) { - eventfd_write(lasync_node->pfd.fd, (eventfd_t)EVENT_COMPLETE); - } - pthread_mutex_unlock(&me->mut); - break; - case FASTRPC_ASYNC_CALLBACK: - pthread_mutex_unlock(&me->mut); - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s callback jobid 0x%" PRIx64 " and result 0x%x", - __func__, lasync_node->async_desc.jobid, result); - lasync_node->async_desc.cb.fn(lasync_node->async_desc.jobid, - lasync_node->async_desc.cb.context, - result); - break; - default: - pthread_mutex_unlock(&me->mut); - FARF(RUNTIME_RPC_HIGH, - "adsprpc: %s Invalid job type for jobid 0x%" PRIx64 "", __func__, - lasync_node->async_desc.jobid); - break; - } - break; - } - } - if (!isjobfound) - pthread_mutex_unlock(&me->mut); - } while (1); +static void * +async_fastrpc_thread(void *arg) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_async *me = (struct fastrpc_async *)arg; + int domain = (int)(me - &lasyncinfo[0]); + struct fastrpc_async_job_node *lasync_node = NULL; + int result = -1; + fastrpc_async_jobid jobid = -1; + QNode *pn, *pnn; + + int hash = -1; + bool isjobfound = false; + + /// TODO: Do we really need this line? + set_thread_context(domain); + do { + nErr = get_remote_async_response(domain, &jobid, &result); + VERIFY(nErr == AEE_SUCCESS); + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s received async response for jobid 0x%" PRIx64 + " and result 0x%x", + __func__, jobid, result); + isjobfound = false; + hash = GET_HASH_FROM_JOBID(jobid); + pthread_mutex_lock(&me->mut); + QLIST_NEXTSAFE_FOR_ALL(&me->ql[hash], pn, pnn) + { + lasync_node = STD_RECOVER_REC( + struct fastrpc_async_job_node, qn, pn); + if(lasync_node->async_desc.jobid == jobid) { + lasync_node->isjobdone = true; + lasync_node->result = result; + isjobfound = true; + switch(lasync_node->async_desc.type) { + case FASTRPC_ASYNC_NO_SYNC: + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s nosync jobid " + "0x%" PRIx64 " and result 0x%x", + __func__, + lasync_node->async_desc.jobid, + result); + QNode_DequeueZ(&lasync_node->qn); + pthread_mutex_unlock(&me->mut); + free(lasync_node); + lasync_node = NULL; + break; + case FASTRPC_ASYNC_POLL: + FARF( + RUNTIME_RPC_HIGH, + "adsprpc: %s poll jobid 0x%" PRIx64 + " and result 0x%x", + __func__, + lasync_node->async_desc.jobid, + result); + if(lasync_node->pfd.fd != -1) { + eventfd_write( + lasync_node->pfd.fd, + (eventfd_t)EVENT_COMPLETE); + } + pthread_mutex_unlock(&me->mut); + break; + case FASTRPC_ASYNC_CALLBACK: + pthread_mutex_unlock(&me->mut); + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s callback jobid " + "0x%" PRIx64 " and result 0x%x", + __func__, + lasync_node->async_desc.jobid, + result); + lasync_node->async_desc.cb.fn( + lasync_node->async_desc.jobid, + lasync_node->async_desc.cb.context, + result); + break; + default: + pthread_mutex_unlock(&me->mut); + FARF(RUNTIME_RPC_HIGH, + "adsprpc: %s Invalid job type " + "for jobid 0x%" PRIx64 "", + __func__, + lasync_node->async_desc.jobid); + break; + } + break; + } + } + if(!isjobfound) + pthread_mutex_unlock(&me->mut); + } while(1); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s AsyncFastRPC worker thread exited for " - "domain %d (errno %s), async_domain_deinit started %d", - nErr, __func__, domain, strerror(errno), me->deinit_started); - } - dlerror(); - return (void *)(uintptr_t)nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: %s AsyncFastRPC worker thread exited for " + "domain %d (errno %s), async_domain_deinit started %d", + nErr, __func__, domain, strerror(errno), + me->deinit_started); + } + dlerror(); + return (void *)(uintptr_t)nErr; } -void async_thread_exit_handler(int sig) { - FARF(ALWAYS, "Async FastRPC worker thread exiting with signal %d\n", sig); - pthread_exit(0); +void +async_thread_exit_handler(int sig) +{ + FARF(ALWAYS, "Async FastRPC worker thread exiting with signal %d\n", + sig); + pthread_exit(0); } -void fastrpc_async_domain_deinit(int domain) { - struct fastrpc_async *me = &lasyncinfo[domain]; - int err = 0; - - pthread_mutex_lock(&async_mut); - if (!me->init_done) { - goto fasync_deinit_done; - } - FARF(ALWAYS, "%s: Waiting for AsyncRPC worker thread to join for domain %d\n", - __func__, domain); - if (me->thread) { - me->deinit_started = 1; - err = fastrpc_exit_async_thread(domain); - if (err) { - pthread_kill(me->thread, SIGUSR1); - } - pthread_join(me->thread, 0); - me->thread = 0; - } - FARF(ALWAYS, "fastrpc async thread joined for domain %d", domain); - fastrpc_async_respond_all_pending_jobs(domain); - pthread_mutex_destroy(&me->mut); - me->init_done = 0; +void +fastrpc_async_domain_deinit(int domain) +{ + struct fastrpc_async *me = &lasyncinfo[domain]; + int err = 0; + + pthread_mutex_lock(&async_mut); + if(!me->init_done) { + goto fasync_deinit_done; + } + FARF(ALWAYS, + "%s: Waiting for AsyncRPC worker thread to join for domain %d\n", + __func__, domain); + if(me->thread) { + me->deinit_started = 1; + err = fastrpc_exit_async_thread(domain); + if(err) { + pthread_kill(me->thread, SIGUSR1); + } + pthread_join(me->thread, 0); + me->thread = 0; + } + FARF(ALWAYS, "fastrpc async thread joined for domain %d", domain); + fastrpc_async_respond_all_pending_jobs(domain); + pthread_mutex_destroy(&me->mut); + me->init_done = 0; fasync_deinit_done: - pthread_mutex_unlock(&async_mut); - return; + pthread_mutex_unlock(&async_mut); + return; } -int fastrpc_async_domain_init(int domain) { - struct fastrpc_async *me = &lasyncinfo[domain]; - int nErr = AEE_EUNKNOWN, i = 0; - struct sigaction siga; - uint32_t capability = 0; - - pthread_mutex_lock(&async_mut); - if (me->init_done) { - nErr = AEE_SUCCESS; - goto bail; - } - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_get_cap(domain, ASYNC_FASTRPC_SUPPORT, &capability))); - VERIFYC(capability == 1, AEE_EUNSUPPORTED); - me->thread = 0; - pthread_mutex_init(&me->mut, 0); - for (i = 0; i < FASTRPC_ASYNC_QUEUE_LIST_LEN; i++) { - QList_Ctor(&me->ql[i]); - } - VERIFY(AEE_SUCCESS == - (nErr = pthread_create(&me->thread, 0, async_fastrpc_thread, - (void *)me))); - memset(&siga, 0, sizeof(siga)); - siga.sa_flags = 0; - siga.sa_handler = async_thread_exit_handler; - VERIFY(AEE_SUCCESS == (nErr = sigaction(SIGUSR1, &siga, NULL))); - me->init_done = 1; - me->deinit_started = 0; - FARF(ALWAYS, "%s: AsyncRPC worker thread launched for domain %d\n", __func__, - domain); +int +fastrpc_async_domain_init(int domain) +{ + struct fastrpc_async *me = &lasyncinfo[domain]; + int nErr = AEE_EUNKNOWN, i = 0; + struct sigaction siga; + uint32_t capability = 0; + + pthread_mutex_lock(&async_mut); + if(me->init_done) { + nErr = AEE_SUCCESS; + goto bail; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_get_cap(domain, ASYNC_FASTRPC_SUPPORT, + &capability))); + VERIFYC(capability == 1, AEE_EUNSUPPORTED); + me->thread = 0; + pthread_mutex_init(&me->mut, 0); + for(i = 0; i < FASTRPC_ASYNC_QUEUE_LIST_LEN; i++) { + QList_Ctor(&me->ql[i]); + } + VERIFY(AEE_SUCCESS + == (nErr = pthread_create(&me->thread, 0, async_fastrpc_thread, + (void *)me))); + memset(&siga, 0, sizeof(siga)); + siga.sa_flags = 0; + siga.sa_handler = async_thread_exit_handler; + VERIFY(AEE_SUCCESS == (nErr = sigaction(SIGUSR1, &siga, NULL))); + me->init_done = 1; + me->deinit_started = 0; + FARF(ALWAYS, "%s: AsyncRPC worker thread launched for domain %d\n", + __func__, domain); bail: - pthread_mutex_unlock(&async_mut); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d (%s)\n", nErr, __func__, - domain, strerror(errno)); - fastrpc_async_domain_deinit(domain); - } - return nErr; + pthread_mutex_unlock(&async_mut); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d (%s)\n", + nErr, __func__, domain, strerror(errno)); + fastrpc_async_domain_deinit(domain); + } + return nErr; } /* @@ -410,80 +471,91 @@ int fastrpc_async_domain_init(int domain) { * job information returns 0 on success * */ -static int get_remote_async_response(int domain, fastrpc_async_jobid *jobid, - int *result) { - int nErr = AEE_SUCCESS, dev = -1; - uint64_t *perf_kernel = NULL, *perf_dsp = NULL; - fastrpc_async_jobid job = -1; - int res = -1; - remote_handle handle = -1; - uint32_t sc = 0; - - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); - if (is_kernel_perf_enabled()) { - perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); - } - if (is_dsp_perf_enabled(domain)) { - perf_dsp = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); - VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); - } - nErr = ioctl_invoke2_response(dev, &job, &handle, &sc, &res, perf_kernel, - perf_dsp); - if (perf_kernel) { - FARF(ALWAYS, - "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 " ns M:%" PRIu64 - " ns CP:%" PRIu64 " ns L:%" PRIu64 " ns G:%" PRIu64 " ns P:%" PRIu64 - " ns INV:%" PRIu64 " ns INVOKE:%" PRIu64 " ns\n", - handle, sc, perf_kernel[0], perf_kernel[1], perf_kernel[2], - perf_kernel[3], perf_kernel[4], perf_kernel[5], perf_kernel[6], - perf_kernel[7], perf_kernel[8]); - } - if (perf_dsp) { - FARF(ALWAYS, - "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 " us M:%" PRIu64 - " us G:%" PRIu64 " us INVOKE:%" PRIu64 " us P:%" PRIu64 - " us CACHE:%" PRIu64 " us UM:%" PRIu64 " us " - "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 - " us J_S_T:%" PRIu64 " us\n", - handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], perf_dsp[3], - perf_dsp[4], perf_dsp[5], perf_dsp[6], perf_dsp[7], perf_dsp[8], - perf_dsp[9], perf_dsp[10], perf_dsp[11]); - } - *jobid = job; - *result = res; +static int +get_remote_async_response(int domain, fastrpc_async_jobid *jobid, int *result) +{ + int nErr = AEE_SUCCESS, dev = -1; + uint64_t *perf_kernel = NULL, *perf_dsp = NULL; + fastrpc_async_jobid job = -1; + int res = -1; + remote_handle handle = -1; + uint32_t sc = 0; + + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + VERIFYM(-1 != dev, AEE_ERPC, "open dev failed\n"); + if(is_kernel_perf_enabled()) { + perf_kernel = (uint64_t *)calloc(PERF_KERNEL_KEY_MAX, + sizeof(uint64_t)); + VERIFYC(perf_kernel != NULL, AEE_ENOMEMORY); + } + if(is_dsp_perf_enabled(domain)) { + perf_dsp + = (uint64_t *)calloc(PERF_DSP_KEY_MAX, sizeof(uint64_t)); + VERIFYC(perf_dsp != NULL, AEE_ENOMEMORY); + } + nErr = ioctl_invoke2_response(dev, &job, &handle, &sc, &res, + perf_kernel, perf_dsp); + if(perf_kernel) { + FARF(ALWAYS, + "RPCPERF-K H:0x%x SC:0x%x C:%" PRIu64 " F:%" PRIu64 + " ns M:%" PRIu64 " ns CP:%" PRIu64 " ns L:%" PRIu64 + " ns G:%" PRIu64 " ns P:%" PRIu64 " ns INV:%" PRIu64 + " ns INVOKE:%" PRIu64 " ns\n", + handle, sc, perf_kernel[0], perf_kernel[1], + perf_kernel[2], perf_kernel[3], perf_kernel[4], + perf_kernel[5], perf_kernel[6], perf_kernel[7], + perf_kernel[8]); + } + if(perf_dsp) { + FARF(ALWAYS, + "RPCPERF-D H:0x%x SC:0x%x C:%" PRIu64 " M_H:%" PRIu64 + " us M:%" PRIu64 " us G:%" PRIu64 " us INVOKE:%" PRIu64 + " us P:%" PRIu64 " us CACHE:%" PRIu64 " us UM:%" PRIu64 + " us " + "UM_H:%" PRIu64 " us R:%" PRIu64 " us E_R:%" PRIu64 + " us J_S_T:%" PRIu64 " us\n", + handle, sc, perf_dsp[0], perf_dsp[1], perf_dsp[2], + perf_dsp[3], perf_dsp[4], perf_dsp[5], perf_dsp[6], + perf_dsp[7], perf_dsp[8], perf_dsp[9], perf_dsp[10], + perf_dsp[11]); + } + *jobid = job; + *result = res; bail: - if (perf_kernel) { - free(perf_kernel); - perf_kernel = NULL; - } - if (perf_dsp) { - free(perf_dsp); - perf_dsp = NULL; - } - if (nErr) { - FARF(ERROR, - "Error 0x%x: %s failed to get async response data for domain %d errno " - "%s", - nErr, __func__, domain, strerror(errno)); - } - return nErr; + if(perf_kernel) { + free(perf_kernel); + perf_kernel = NULL; + } + if(perf_dsp) { + free(perf_dsp); + perf_dsp = NULL; + } + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s failed to get async response data for " + "domain %d errno " + "%s", + nErr, __func__, domain, strerror(errno)); + } + return nErr; } // Make IOCTL call to exit async thread -int fastrpc_exit_async_thread(int domain) { - int nErr = AEE_SUCCESS, dev; +int +fastrpc_exit_async_thread(int domain) +{ + int nErr = AEE_SUCCESS, dev; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - nErr = ioctl_control(dev, DSPRPC_ASYNC_WAKE, NULL); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + nErr = ioctl_control(dev, DSPRPC_ASYNC_WAKE, NULL); bail: - if (nErr) - FARF(ERROR, - "Error 0x%x: %s failed for domain %d (errno: %s), ignore if ioctl not " - "supported, try pthread kill ", - nErr, __func__, domain, strerror(errno)); - return nErr; + if(nErr) + FARF(ERROR, + "Error 0x%x: %s failed for domain %d (errno: %s), ignore " + "if ioctl not " + "supported, try pthread kill ", + nErr, __func__, domain, strerror(errno)); + return nErr; } diff --git a/src/fastrpc_cap.c b/src/fastrpc_cap.c index 0ad169ed..508e3389 100644 --- a/src/fastrpc_cap.c +++ b/src/fastrpc_cap.c @@ -1,36 +1,46 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause +#include +#include #include #include #include -#include #include -#include #define FARF_ERROR 1 -#include "remote.h" #include "AEEStdErr.h" -#include "verify.h" #include "HAP_farf.h" #include "fastrpc_cap.h" #include "fastrpc_common.h" #include "fastrpc_internal.h" - +#include "remote.h" +#include "verify.h" #define BUF_SIZE 50 -const char * RPROC_SUBSYSTEM_NAME[] = {"adsp", "mss", "spss", "cdsp", "cdsp1", "gdsp0", "gdsp1", "reserved"}; +const char *RPROC_SUBSYSTEM_NAME[] + = { "adsp", "mss", "spss", "cdsp", "cdsp1", "gdsp0", "gdsp1", "reserved" }; -static inline uint32_t fastrpc_check_if_dsp_present_pil(uint32_t domain) { +static inline uint32_t +fastrpc_check_if_dsp_present_pil(uint32_t domain) +{ uint32_t domain_supported = 0; struct stat sb; // mark rest of the list as reserved to avoid out of bound access - const char *SUBSYSTEM_DEV_NAME[] = {"/dev/subsys_adsp", "", "/dev/subsys_slpi", "/dev/subsys_cdsp", "/dev/subsys_cdsp1", "/dev/subsys_gdsp0", "/dev/subsys_gdsp1", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved", "reserved"}; + const char *SUBSYSTEM_DEV_NAME[] + = { "/dev/subsys_adsp", "", + "/dev/subsys_slpi", "/dev/subsys_cdsp", + "/dev/subsys_cdsp1", "/dev/subsys_gdsp0", + "/dev/subsys_gdsp1", "reserved", + "reserved", "reserved", + "reserved", "reserved", + "reserved", "reserved", + "reserved", "reserved" }; // If device file is present, then target supports that DSP - if (!stat(SUBSYSTEM_DEV_NAME[domain], &sb)) { + if(!stat(SUBSYSTEM_DEV_NAME[domain], &sb)) { domain_supported = 1; } return domain_supported; @@ -39,36 +49,38 @@ static inline uint32_t fastrpc_check_if_dsp_present_pil(uint32_t domain) { /* * Function to check whether particular remote subsystem is present or not. * Return 0 if subsystem is not available otherwise 1. -*/ -static inline uint32_t fastrpc_check_if_dsp_present_rproc(uint32_t domain) { + */ +static inline uint32_t +fastrpc_check_if_dsp_present_rproc(uint32_t domain) +{ char *dir_base_path = "/sys/class/remoteproc/remoteproc"; const char *search_string = NULL; uint32_t domain_supported = 0; int dir_index = 0, nErr = AEE_SUCCESS; char *buffer = NULL; - if (domain < ADSP_DOMAIN_ID || domain > GDSP1_DOMAIN_ID) { + if(domain < ADSP_DOMAIN_ID || domain > GDSP1_DOMAIN_ID) { FARF(ERROR, "%s Invalid domain 0x%x ", __func__, domain); return 0; } VERIFYC(NULL != (buffer = malloc(BUF_SIZE)), AEE_ENOMEMORY); - search_string = RPROC_SUBSYSTEM_NAME[domain]; + search_string = RPROC_SUBSYSTEM_NAME[domain]; - while (1) { + while(1) { memset(buffer, 0, BUF_SIZE); snprintf(buffer, BUF_SIZE, "%s%d", dir_base_path, dir_index); strlcat(buffer, "/name", BUF_SIZE); int fd = open(buffer, O_RDONLY); - if (fd == -1) { + if(fd == -1) { break; } FILE *file = fdopen(fd, "r"); - if (file != NULL) { + if(file != NULL) { memset(buffer, 0, BUF_SIZE); - if (fgets(buffer, BUF_SIZE, file) != NULL) { + if(fgets(buffer, BUF_SIZE, file) != NULL) { buffer[BUF_SIZE - 1] = '\0'; - if (strstr(buffer, search_string) != NULL) { + if(strstr(buffer, search_string) != NULL) { domain_supported = 1; fclose(file); break; @@ -79,155 +91,183 @@ static inline uint32_t fastrpc_check_if_dsp_present_rproc(uint32_t domain) { close(fd); dir_index++; } -bail : - if (buffer){ +bail: + if(buffer) { free(buffer); } - if (nErr) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d\n", nErr, __func__, domain); + if(nErr) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d\n", nErr, + __func__, domain); } return domain_supported; } -int fastrpc_get_cap(uint32_t domain, uint32_t attributeID, uint32_t *capability) { - int nErr = AEE_SUCCESS, dev = -1, dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); - - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - VERIFYC(capability != NULL, AEE_EBADPARM); - VERIFYC(attributeID < FASTRPC_MAX_ATTRIBUTES, AEE_EBADPARM); //Check if the attribute ID is less than max attributes accepted by userspace - - *capability = 0; - - if (attributeID == DOMAIN_SUPPORT) { - *capability = fastrpc_check_if_dsp_present_pil(dom); - if (*capability == 0) { - *capability = fastrpc_check_if_dsp_present_rproc(dom); - } - if (*capability == 0) { - FARF(ALWAYS, "Warning! %s domain %d is not present\n", __func__, dom); - } - goto bail; - } - if(attributeID == ASYNC_FASTRPC_SUPPORT) { - if(!is_async_fastrpc_supported() ) { - *capability = 0; - goto bail; - } - } - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_open(dom, &dev))); - errno = 0; - nErr = ioctl_getdspinfo(dev, dom, attributeID, capability); - if(nErr) { - goto bail; - } - if (attributeID == STATUS_NOTIFICATION_SUPPORT) { - *capability = (*capability == STATUS_NOTIF_V2) ? 1 : 0; - } +int +fastrpc_get_cap(uint32_t domain, uint32_t attributeID, uint32_t *capability) +{ + int nErr = AEE_SUCCESS, dev = -1, + dom = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); + + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC(capability != NULL, AEE_EBADPARM); + VERIFYC(attributeID < FASTRPC_MAX_ATTRIBUTES, + AEE_EBADPARM); // Check if the attribute ID is less than max + // attributes accepted by userspace + + *capability = 0; + + if(attributeID == DOMAIN_SUPPORT) { + *capability = fastrpc_check_if_dsp_present_pil(dom); + if(*capability == 0) { + *capability = fastrpc_check_if_dsp_present_rproc(dom); + } + if(*capability == 0) { + FARF(ALWAYS, "Warning! %s domain %d is not present\n", + __func__, dom); + } + goto bail; + } + if(attributeID == ASYNC_FASTRPC_SUPPORT) { + if(!is_async_fastrpc_supported()) { + *capability = 0; + goto bail; + } + } + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_open(dom, &dev))); + errno = 0; + nErr = ioctl_getdspinfo(dev, dom, attributeID, capability); + if(nErr) { + goto bail; + } + if(attributeID == STATUS_NOTIFICATION_SUPPORT) { + *capability = (*capability == STATUS_NOTIF_V2) ? 1 : 0; + } bail: - if(dev != -1) - fastrpc_session_close(dom, dev); - if (nErr) { - FARF(ERROR, "Warning 0x%x: %s failed to get attribute %u for domain %u (errno %s)", nErr, __func__, attributeID, domain, strerror(errno)); - } - return nErr; + if(dev != -1) + fastrpc_session_close(dom, dev); + if(nErr) { + FARF(ERROR, + "Warning 0x%x: %s failed to get attribute %u for domain " + "%u (errno %s)", + nErr, __func__, attributeID, domain, strerror(errno)); + } + return nErr; } -uint32_t get_dsp_dma_reverse_rpc_map_capability(int domain) { +uint32_t +get_dsp_dma_reverse_rpc_map_capability(int domain) +{ int nErr = 0; - uint32_t capability = 0; + uint32_t capability = 0; - nErr= fastrpc_get_cap(domain, MAP_DMA_HANDLE_REVERSERPC, &capability); - if (nErr == 0) { + nErr = fastrpc_get_cap(domain, MAP_DMA_HANDLE_REVERSERPC, &capability); + if(nErr == 0) { return capability; } - return 0; + return 0; } -static int check_status_notif_version2_capability(int domain) +static int +check_status_notif_version2_capability(int domain) { int nErr = 0; - struct remote_dsp_capability cap = {0}; + struct remote_dsp_capability cap = { 0 }; cap.domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain); cap.attribute_ID = STATUS_NOTIFICATION_SUPPORT; - nErr= fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == 0) { + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); + if(nErr == 0) { return cap.capability; } else { - FARF(RUNTIME_RPC_HIGH, "%s: Capability not found. nErr: 0x%x", __func__, nErr); + FARF(RUNTIME_RPC_HIGH, "%s: Capability not found. nErr: 0x%x", + __func__, nErr); } - return 0; + return 0; } -int is_status_notif_version2_supported(int domain) +int +is_status_notif_version2_supported(int domain) { - static int status_notif_version2_capability = -1; + static int status_notif_version2_capability = -1; if(status_notif_version2_capability == -1) { - status_notif_version2_capability = check_status_notif_version2_capability(domain); + status_notif_version2_capability + = check_status_notif_version2_capability(domain); } return status_notif_version2_capability; } -static int check_userspace_allocation_capability(void) +static int +check_userspace_allocation_capability(void) { int nErr = 0; - struct remote_dsp_capability cap = {0}; - + struct remote_dsp_capability cap = { 0 }; + cap.domain = DEFAULT_DOMAIN_ID; cap.attribute_ID = USERSPACE_ALLOCATION_SUPPORT; - nErr= fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == 0) { + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); + if(nErr == 0) { return cap.capability; } else { - FARF(RUNTIME_RPC_HIGH, "%s: Capability not found. nErr: 0x%x", __func__, nErr); + FARF(RUNTIME_RPC_HIGH, "%s: Capability not found. nErr: 0x%x", + __func__, nErr); } - return 0; + return 0; } -int is_userspace_allocation_supported(void) +int +is_userspace_allocation_supported(void) { - static int userspace_allocation_capability = -1; + static int userspace_allocation_capability = -1; if(userspace_allocation_capability == -1) { - userspace_allocation_capability = check_userspace_allocation_capability(); + userspace_allocation_capability + = check_userspace_allocation_capability(); } return userspace_allocation_capability; } -int is_proc_sharedbuf_supported_dsp(int domain) +int +is_proc_sharedbuf_supported_dsp(int domain) { int nErr = AEE_SUCCESS; static int proc_sharedbuf_capability = -1; - struct remote_dsp_capability cap = {domain, PROC_SHARED_BUFFER_SUPPORT, 0}; + struct remote_dsp_capability cap + = { domain, PROC_SHARED_BUFFER_SUPPORT, 0 }; - if (proc_sharedbuf_capability == -1) { - nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == AEE_SUCCESS) { + if(proc_sharedbuf_capability == -1) { + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, + &cap.capability); + if(nErr == AEE_SUCCESS) { proc_sharedbuf_capability = cap.capability; } else { - FARF(RUNTIME_RPC_HIGH, "Error 0x%x: %s: capability not found", nErr, __func__); + FARF(RUNTIME_RPC_HIGH, + "Error 0x%x: %s: capability not found", nErr, + __func__); proc_sharedbuf_capability = 0; } } return proc_sharedbuf_capability; } -int check_error_code_change_present() { +int +check_error_code_change_present() +{ int nErr = 0; - struct remote_dsp_capability cap = {0}; - static int driver_error_code_capability = -1; + struct remote_dsp_capability cap = { 0 }; + static int driver_error_code_capability = -1; cap.domain = DEFAULT_DOMAIN_ID; cap.attribute_ID = DRIVER_ERROR_CODE_CHANGE; - if(driver_error_code_capability == -1) { - nErr= fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == 0) { - driver_error_code_capability = cap.capability; - } - } - return driver_error_code_capability; + if(driver_error_code_capability == -1) { + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, + &cap.capability); + if(nErr == 0) { + driver_error_code_capability = cap.capability; + } + } + return driver_error_code_capability; } diff --git a/src/fastrpc_config.c b/src/fastrpc_config.c index 7073aa84..aea81138 100644 --- a/src/fastrpc_config.c +++ b/src/fastrpc_config.c @@ -22,9 +22,9 @@ #include "AEEstd.h" #include "HAP_farf.h" #include "apps_std.h" +#include "apps_std_internal.h" #include "fastrpc_common.h" #include "fastrpc_config.h" -#include "apps_std_internal.h" #include "verify.h" #define CONFIG_PDDUMP "pddump" @@ -45,400 +45,526 @@ #define CONFIG_LOGPACKET "logPackets" #define CONFIG_LEAK_DETECT "leak_detect" #define CONFIG_CALL_STACK_NUM "num_call_stack" -#define CONFIG_SETDMABUFNAME "setdmabufname" +#define CONFIG_SETDMABUFNAME "setdmabufname" struct fastrpc_config_param { - bool pddump; - int rpc_timeout; - bool perfkernel; - bool perfdsp; - _cstring1_t *paths; - char *farf_log_filename; - char *farf_log_filename_userspace; - bool log_iregion; - bool qtf_tracing; - int caller_level; - bool uaf_enabled; - bool debug_logging; - struct err_codes err_codes_to_crash; - bool sysmonreservedbit; - bool logPackets; - int leak_detect; - int num_call_stack; - bool setdmabufname; + bool pddump; + int rpc_timeout; + bool perfkernel; + bool perfdsp; + _cstring1_t *paths; + char *farf_log_filename; + char *farf_log_filename_userspace; + bool log_iregion; + bool qtf_tracing; + int caller_level; + bool uaf_enabled; + bool debug_logging; + struct err_codes err_codes_to_crash; + bool sysmonreservedbit; + bool logPackets; + int leak_detect; + int num_call_stack; + bool setdmabufname; }; static struct fastrpc_config_param frpc_config; // Function to read and parse config file -int fastrpc_read_config_file_from_path(const char *base, const char *file) { - int nErr = 0; - apps_std_FILE fp = -1; - uint64_t len; - unsigned char *buf = NULL; - int eof; - char *path = NULL, *param = NULL, *saveptr = NULL; - bool fileExists = false; - char *delim = "=", *delim2 = ","; - uint64_t logFileNameLen = 0; - frpc_config.err_codes_to_crash.num_err_codes = 0; +int +fastrpc_read_config_file_from_path(const char *base, const char *file) +{ + int nErr = 0; + apps_std_FILE fp = -1; + uint64_t len; + unsigned char *buf = NULL; + int eof; + char *path = NULL, *param = NULL, *saveptr = NULL; + bool fileExists = false; + char *delim = "=", *delim2 = ","; + uint64_t logFileNameLen = 0; + frpc_config.err_codes_to_crash.num_err_codes = 0; - len = snprintf(0, 0, "%s/%s", base, file) + 1; - VERIFYC(NULL != (path = calloc(1, sizeof(char) * len)), AEE_ENOMEMORY); - snprintf(path, (int)len, "%s/%s", base, file); - VERIFY(AEE_SUCCESS == (nErr = apps_std_fileExists(path, &fileExists))); - if (fileExists == false) { - nErr = AEE_ENOSUCHFILE; - goto bail; - } + len = snprintf(0, 0, "%s/%s", base, file) + 1; + VERIFYC(NULL != (path = calloc(1, sizeof(char) * len)), AEE_ENOMEMORY); + snprintf(path, (int)len, "%s/%s", base, file); + VERIFY(AEE_SUCCESS == (nErr = apps_std_fileExists(path, &fileExists))); + if(fileExists == false) { + nErr = AEE_ENOSUCHFILE; + goto bail; + } - VERIFY(AEE_SUCCESS == (nErr = apps_std_fopen(path, "r", &fp))); - VERIFY(AEE_SUCCESS == (nErr = apps_std_flen(fp, &len))); - // Allocate buffer for reading each line - VERIFYC(NULL != (buf = calloc(1, sizeof(unsigned char) * (len + 1))), - AEE_ENOMEMORY); // extra 1 unsigned char for null character + VERIFY(AEE_SUCCESS == (nErr = apps_std_fopen(path, "r", &fp))); + VERIFY(AEE_SUCCESS == (nErr = apps_std_flen(fp, &len))); + // Allocate buffer for reading each line + VERIFYC(NULL != (buf = calloc(1, sizeof(unsigned char) * (len + 1))), + AEE_ENOMEMORY); // extra 1 unsigned char for null character - do { - // Read each line at a time - VERIFY(AEE_SUCCESS == (nErr = apps_std_fgets(fp, buf, len, &eof))); - if (eof) { - break; - } - param = strtok_r((char *)buf, delim, &saveptr); - if (param == NULL) { - continue; - } + do { + // Read each line at a time + VERIFY(AEE_SUCCESS + == (nErr = apps_std_fgets(fp, buf, len, &eof))); + if(eof) { + break; + } + param = strtok_r((char *)buf, delim, &saveptr); + if(param == NULL) { + continue; + } - if (strncmp(param, CONFIG_ERR_CODES, strlen(CONFIG_ERR_CODES)) == - 0) { - int ii = 0, num_err_codes = 0; - unsigned int err_code = 0; + if(strncmp(param, CONFIG_ERR_CODES, strlen(CONFIG_ERR_CODES)) + == 0) { + int ii = 0, num_err_codes = 0; + unsigned int err_code = 0; - FARF(ALWAYS, "%s: panic error codes applicable only to cdsp domain\n", - __func__); - do { - param = strtok_r(NULL, delim2, &saveptr); - if (param != NULL) { - err_code = strtol(param, NULL, 16); - if (err_code >= MIN_DSP_ERR_RNG && err_code <= MAX_DSP_ERR_RNG) { - frpc_config.err_codes_to_crash.err_code[ii] = err_code; - FARF(ALWAYS, "%s : panic error codes : 0x%x\n", __func__, - frpc_config.err_codes_to_crash.err_code[ii]); - ii++; - if (ii >= MAX_PANIC_ERR_CODES) { - FARF(ERROR, "%s : Max panic error codes limit reached\n", - __func__, MAX_PANIC_ERR_CODES); - break; - } - } else { - FARF(ALWAYS, - "%s : panic error code read from debugcnfig : 0x%x is not in " - "dsp error codes range\n", - __func__, err_code); - } - } - } while (param != NULL); - num_err_codes = ii; - frpc_config.err_codes_to_crash.num_err_codes = num_err_codes; - } else if (strncmp(param, CONFIG_PDDUMP, strlen(CONFIG_PDDUMP)) == - 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.pddump = true; - FARF(ALWAYS, "fastrpc config enabling PD dump\n"); - } - } else if (strncmp(param, CONFIG_RPCTIMEOUT, - strlen(CONFIG_RPCTIMEOUT)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - frpc_config.rpc_timeout = atoi(param); - FARF(ALWAYS, "fastrpc config set rpc timeout with %d\n", - frpc_config.rpc_timeout); - } - } else if (strncmp(param, CONFIG_PERF_KERNEL, - strlen(CONFIG_PERF_KERNEL)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.perfkernel = true; - FARF(ALWAYS, "fastrpc config enabling profiling on kernel\n"); - } - } else if (strncmp(param, CONFIG_PERF_DSP, - strlen(CONFIG_PERF_DSP)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.perfdsp = true; - FARF(ALWAYS, "fastrpc config enabling profiling on dsp\n"); - } - } else if (strncmp(param, CONFIG_COLLECT_RUNTIME_FARF, - strlen(CONFIG_COLLECT_RUNTIME_FARF)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - logFileNameLen = strlen(param) + 1; - VERIFYC(NULL != (frpc_config.farf_log_filename = - (char *)malloc(sizeof(char) * logFileNameLen)), - AEE_ENOMEMORY); - strlcpy(frpc_config.farf_log_filename, param, logFileNameLen); - FARF(ALWAYS, - "fastrpc config enabling farf logs collection into file %s", - frpc_config.farf_log_filename); - } - } else if (strncmp(param, CONFIG_COLLECT_RUNTIME_FARF_USERSPACE, - strlen(CONFIG_COLLECT_RUNTIME_FARF_USERSPACE)) == - 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - logFileNameLen = strlen(param) + 1; - VERIFYC(NULL != (frpc_config.farf_log_filename_userspace = - (char *)malloc(sizeof(char) * logFileNameLen)), - AEE_ENOMEMORY); - strlcpy(frpc_config.farf_log_filename_userspace, param, - logFileNameLen); - FARF(ALWAYS, - "fastrpc config enabling userspace farf logs collection into file " - "%s", - frpc_config.farf_log_filename_userspace); - } - } else if (strncmp(param, CONFIG_LOG_IREGION, - strlen(CONFIG_LOG_IREGION)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - frpc_config.log_iregion = true; - FARF(ALWAYS, "fastrpc config enabling iregion logging\n"); - } - } else if (strncmp(param, CONFIG_QTF_TRACING, - strlen(CONFIG_QTF_TRACING)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.qtf_tracing = true; - FARF(ALWAYS, "fastrpc config enabling QTF tracing\n"); - } - } else if (strncmp(param, CONFIG_CALLER_LEVEL, - strlen(CONFIG_CALLER_LEVEL)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.caller_level = atoi(param); - FARF(ALWAYS, "fastrpc config setting heap caller level with %d\n", - frpc_config.caller_level); - } - } else if (strncmp(param, CONFIG_ENABLE_UAF, - strlen(CONFIG_ENABLE_UAF)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.uaf_enabled = true; - FARF(ALWAYS, "fastrpc config enabling uaf on heap\n"); - } - } else if (strncmp(param, CONFIG_DEBUG_LOGGING, - strlen(CONFIG_DEBUG_LOGGING)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - frpc_config.debug_logging = true; - FARF(ALWAYS, "fastrpc config enabling debug logging\n"); - } - } else if (strncmp(param, CONFIG_DEBUG_SYSMON_LOGGING, - strlen(CONFIG_DEBUG_SYSMON_LOGGING)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - frpc_config.sysmonreservedbit = true; - FARF(ALWAYS, "fastrpc config enabling sysmon logging \n"); - } - } else if (strncmp(param, CONFIG_LOGPACKET, - strlen(CONFIG_LOGPACKET)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL) { - frpc_config.logPackets = true; - FARF(ALWAYS, "fastrpc config enabling Log packets\n"); - } - } else if (strncmp(param, CONFIG_LEAK_DETECT, - strlen(CONFIG_LEAK_DETECT)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.leak_detect = atoi(param); - FARF(ALWAYS, "fastrpc config enabling leak detect with %d\n", - frpc_config.leak_detect); - } - } else if (strncmp(param, CONFIG_CALL_STACK_NUM, - strlen(CONFIG_CALL_STACK_NUM)) == 0) { - param = strtok_r(NULL, delim, &saveptr); - if (param != NULL && atoi(param)) { - frpc_config.num_call_stack = atoi(param); - FARF(ALWAYS, "fastrpc config setting call stack num with %d\n", - frpc_config.num_call_stack); - } - } else if (strncmp(param, CONFIG_SETDMABUFNAME, - strlen(CONFIG_SETDMABUFNAME)) == 0) { - param = strtok_r (NULL, delim, &saveptr); - if (param != NULL && atoi(param)) + FARF(ALWAYS, + "%s: panic error codes applicable only to cdsp " + "domain\n", + __func__); + do { + param = strtok_r(NULL, delim2, &saveptr); + if(param != NULL) { + err_code = strtol(param, NULL, 16); + if(err_code >= MIN_DSP_ERR_RNG + && err_code <= MAX_DSP_ERR_RNG) { + frpc_config.err_codes_to_crash + .err_code[ii] + = err_code; + FARF(ALWAYS, + "%s : panic error codes " + ": 0x%x\n", + __func__, + frpc_config + .err_codes_to_crash + .err_code[ii]); + ii++; + if(ii >= MAX_PANIC_ERR_CODES) { + FARF( + ERROR, + "%s : Max panic " + "error codes " + "limit reached\n", + __func__, + MAX_PANIC_ERR_CODES); + break; + } + } else { + FARF(ALWAYS, + "%s : panic error code " + "read from debugcnfig : " + "0x%x is not in " + "dsp error codes range\n", + __func__, err_code); + } + } + } while(param != NULL); + num_err_codes = ii; + frpc_config.err_codes_to_crash.num_err_codes + = num_err_codes; + } else if(strncmp(param, CONFIG_PDDUMP, strlen(CONFIG_PDDUMP)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.pddump = true; + FARF(ALWAYS, + "fastrpc config enabling PD dump\n"); + } + } else if(strncmp(param, CONFIG_RPCTIMEOUT, + strlen(CONFIG_RPCTIMEOUT)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + frpc_config.rpc_timeout = atoi(param); + FARF( + ALWAYS, + "fastrpc config set rpc timeout with %d\n", + frpc_config.rpc_timeout); + } + } else if(strncmp(param, CONFIG_PERF_KERNEL, + strlen(CONFIG_PERF_KERNEL)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.perfkernel = true; + FARF(ALWAYS, "fastrpc config enabling " + "profiling on kernel\n"); + } + } else if(strncmp(param, CONFIG_PERF_DSP, + strlen(CONFIG_PERF_DSP)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.perfdsp = true; + FARF(ALWAYS, "fastrpc config enabling " + "profiling on dsp\n"); + } + } else if(strncmp(param, CONFIG_COLLECT_RUNTIME_FARF, + strlen(CONFIG_COLLECT_RUNTIME_FARF)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + logFileNameLen = strlen(param) + 1; + VERIFYC(NULL + != (frpc_config.farf_log_filename + = (char *)malloc( + sizeof(char) + * logFileNameLen)), + AEE_ENOMEMORY); + strlcpy(frpc_config.farf_log_filename, param, + logFileNameLen); + FARF(ALWAYS, + "fastrpc config enabling farf logs " + "collection into file %s", + frpc_config.farf_log_filename); + } + } else if(strncmp( + param, CONFIG_COLLECT_RUNTIME_FARF_USERSPACE, + strlen(CONFIG_COLLECT_RUNTIME_FARF_USERSPACE)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + logFileNameLen = strlen(param) + 1; + VERIFYC( + NULL + != (frpc_config + .farf_log_filename_userspace + = (char *)malloc( + sizeof(char) + * logFileNameLen)), + AEE_ENOMEMORY); + strlcpy( + frpc_config.farf_log_filename_userspace, + param, logFileNameLen); + FARF(ALWAYS, + "fastrpc config enabling userspace farf " + "logs collection into file " + "%s", + frpc_config.farf_log_filename_userspace); + } + } else if(strncmp(param, CONFIG_LOG_IREGION, + strlen(CONFIG_LOG_IREGION)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + frpc_config.log_iregion = true; + FARF(ALWAYS, "fastrpc config enabling iregion " + "logging\n"); + } + } else if(strncmp(param, CONFIG_QTF_TRACING, + strlen(CONFIG_QTF_TRACING)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.qtf_tracing = true; + FARF(ALWAYS, + "fastrpc config enabling QTF tracing\n"); + } + } else if(strncmp(param, CONFIG_CALLER_LEVEL, + strlen(CONFIG_CALLER_LEVEL)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.caller_level = atoi(param); + FARF(ALWAYS, + "fastrpc config setting heap caller " + "level with %d\n", + frpc_config.caller_level); + } + } else if(strncmp(param, CONFIG_ENABLE_UAF, + strlen(CONFIG_ENABLE_UAF)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.uaf_enabled = true; + FARF(ALWAYS, + "fastrpc config enabling uaf on heap\n"); + } + } else if(strncmp(param, CONFIG_DEBUG_LOGGING, + strlen(CONFIG_DEBUG_LOGGING)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + frpc_config.debug_logging = true; + FARF( + ALWAYS, + "fastrpc config enabling debug logging\n"); + } + } else if(strncmp(param, CONFIG_DEBUG_SYSMON_LOGGING, + strlen(CONFIG_DEBUG_SYSMON_LOGGING)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + frpc_config.sysmonreservedbit = true; + FARF(ALWAYS, "fastrpc config enabling sysmon " + "logging \n"); + } + } else if(strncmp(param, CONFIG_LOGPACKET, + strlen(CONFIG_LOGPACKET)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL) { + frpc_config.logPackets = true; + FARF(ALWAYS, + "fastrpc config enabling Log packets\n"); + } + } else if(strncmp(param, CONFIG_LEAK_DETECT, + strlen(CONFIG_LEAK_DETECT)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.leak_detect = atoi(param); + FARF(ALWAYS, + "fastrpc config enabling leak detect " + "with %d\n", + frpc_config.leak_detect); + } + } else if(strncmp(param, CONFIG_CALL_STACK_NUM, + strlen(CONFIG_CALL_STACK_NUM)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) { + frpc_config.num_call_stack = atoi(param); + FARF(ALWAYS, + "fastrpc config setting call stack num " + "with %d\n", + frpc_config.num_call_stack); + } + } else if(strncmp(param, CONFIG_SETDMABUFNAME, + strlen(CONFIG_SETDMABUFNAME)) + == 0) { + param = strtok_r(NULL, delim, &saveptr); + if(param != NULL && atoi(param)) frpc_config.setdmabufname = true; - } - param = NULL; - } while (!eof); + } + param = NULL; + } while(!eof); bail: - if (buf != NULL) { - free(buf); - buf = NULL; - } - if (fp != -1) { - apps_std_fclose(fp); - } - if (path != NULL) { - free(path); - path = NULL; - } - if (nErr != AEE_SUCCESS && nErr != AEE_ENOSUCHFILE) { - FARF(ALWAYS, "Error 0x%x: failed for %s/%s with errno(%s)\n", nErr, base, - file, strerror(errno)); - } - return nErr; + if(buf != NULL) { + free(buf); + buf = NULL; + } + if(fp != -1) { + apps_std_fclose(fp); + } + if(path != NULL) { + free(path); + path = NULL; + } + if(nErr != AEE_SUCCESS && nErr != AEE_ENOSUCHFILE) { + FARF(ALWAYS, "Error 0x%x: failed for %s/%s with errno(%s)\n", + nErr, base, file, strerror(errno)); + } + return nErr; } // Function to get panic error codes. -struct err_codes *fastrpc_config_get_errcodes(void) { - if (frpc_config.err_codes_to_crash.num_err_codes != 0) - return (&(frpc_config.err_codes_to_crash)); - return NULL; +struct err_codes * +fastrpc_config_get_errcodes(void) +{ + if(frpc_config.err_codes_to_crash.num_err_codes != 0) + return (&(frpc_config.err_codes_to_crash)); + return NULL; } // Function to get rpc timeout. -int fastrpc_config_get_rpctimeout(void) { return frpc_config.rpc_timeout; } +int +fastrpc_config_get_rpctimeout(void) +{ + return frpc_config.rpc_timeout; +} // Function to get if PD dump feature is enabled. -bool fastrpc_config_is_pddump_enabled(void) { return frpc_config.pddump; } +bool +fastrpc_config_is_pddump_enabled(void) +{ + return frpc_config.pddump; +} // Functions to get if profiling mode is enabled. -bool fastrpc_config_is_perfkernel_enabled(void) { - return frpc_config.perfkernel; +bool +fastrpc_config_is_perfkernel_enabled(void) +{ + return frpc_config.perfkernel; +} +bool +fastrpc_config_is_perfdsp_enabled(void) +{ + return frpc_config.perfdsp; } -bool fastrpc_config_is_perfdsp_enabled(void) { return frpc_config.perfdsp; } // Function to get the file name to collect runtime farf logs. -char *fastrpc_config_get_runtime_farf_file(void) { - return frpc_config.farf_log_filename; +char * +fastrpc_config_get_runtime_farf_file(void) +{ + return frpc_config.farf_log_filename; } // Function to get the file name to collect userspace runtime farf logs. -char *fastrpc_config_get_userspace_runtime_farf_file(void) { - return frpc_config.farf_log_filename_userspace; +char * +fastrpc_config_get_userspace_runtime_farf_file(void) +{ + return frpc_config.farf_log_filename_userspace; } // Function to get if iregion logging feature is enabled. -bool fastrpc_config_is_log_iregion_enabled(void) { - return frpc_config.log_iregion; +bool +fastrpc_config_is_log_iregion_enabled(void) +{ + return frpc_config.log_iregion; } // Function to get if debug logging feature is enabled. -bool fastrpc_config_is_debug_logging_enabled(void) { - return frpc_config.debug_logging; +bool +fastrpc_config_is_debug_logging_enabled(void) +{ + return frpc_config.debug_logging; } // Function to get if debug logging feature is enabled for sysmon reserved bit. -bool fastrpc_config_is_sysmon_reserved_bit_enabled(void) { - return frpc_config.sysmonreservedbit; +bool +fastrpc_config_is_sysmon_reserved_bit_enabled(void) +{ + return frpc_config.sysmonreservedbit; } // Function to get if QTF tracing is enabled. -bool fastrpc_config_is_qtf_tracing_enabled(void) { - return frpc_config.qtf_tracing; +bool +fastrpc_config_is_qtf_tracing_enabled(void) +{ + return frpc_config.qtf_tracing; } // Function to get heap caller level. -int fastrpc_config_get_caller_level(void) { return frpc_config.caller_level; } +int +fastrpc_config_get_caller_level(void) +{ + return frpc_config.caller_level; +} // Function to get if uaf should be enabled in heap -bool fastrpc_config_is_uaf_enabled(void) { return frpc_config.uaf_enabled; } +bool +fastrpc_config_is_uaf_enabled(void) +{ + return frpc_config.uaf_enabled; +} // Function to get if Log packet is enabled. -bool fastrpc_config_is_logpacket_enabled(void) { - return frpc_config.logPackets; +bool +fastrpc_config_is_logpacket_enabled(void) +{ + return frpc_config.logPackets; } // Function to get if leak detect is enabled -int fastrpc_config_get_leak_detect(void) { return frpc_config.leak_detect; } +int +fastrpc_config_get_leak_detect(void) +{ + return frpc_config.leak_detect; +} // Function to return the call stack num -int fastrpc_config_get_caller_stack_num(void) { - return frpc_config.num_call_stack; +int +fastrpc_config_get_caller_stack_num(void) +{ + return frpc_config.num_call_stack; } -bool fastrpc_config_is_setdmabufname_enabled(void) { +bool +fastrpc_config_is_setdmabufname_enabled(void) +{ return frpc_config.setdmabufname; } // Fastrpc config init function -int fastrpc_config_init() { - int nErr = AEE_SUCCESS, i = 0; - const char *file_extension = ".debugconfig"; - char *name = NULL; - char *data_paths = NULL; - char *config_file = NULL; - _cstring1_t *paths = NULL; - uint32_t len = 0; - uint16_t maxPathLen = 0; - uint32_t numPaths = 0; - int file_found = 0; +int +fastrpc_config_init() +{ + int nErr = AEE_SUCCESS, i = 0; + const char *file_extension = ".debugconfig"; + char *name = NULL; + char *data_paths = NULL; + char *config_file = NULL; + _cstring1_t *paths = NULL; + uint32_t len = 0; + uint16_t maxPathLen = 0; + uint32_t numPaths = 0; + int file_found = 0; - VERIFYC(NULL != (name = std_basename(__progname)), AEE_EINVALIDPROCNAME); - len = strlen(name) + strlen(file_extension) + 1; - VERIFYC(NULL != (config_file = calloc(1, sizeof(char) * len)), AEE_ENOMEMORY); - // Prepare config filename - snprintf(config_file, len, "%s%s", name, file_extension); - FARF(RUNTIME_RPC_HIGH, "Reading configuration file: %s\n", config_file); + VERIFYC(NULL != (name = std_basename(__progname)), + AEE_EINVALIDPROCNAME); + len = strlen(name) + strlen(file_extension) + 1; + VERIFYC(NULL != (config_file = calloc(1, sizeof(char) * len)), + AEE_ENOMEMORY); + // Prepare config filename + snprintf(config_file, len, "%s%s", name, file_extension); + FARF(RUNTIME_RPC_HIGH, "Reading configuration file: %s\n", + config_file); - // Get the required size for PATH - apps_std_get_search_paths_with_env(ADSP_LIBRARY_PATH, ";", NULL, 0, &numPaths, - &maxPathLen); - maxPathLen += +1; + // Get the required size for PATH + apps_std_get_search_paths_with_env(ADSP_LIBRARY_PATH, ";", NULL, 0, + &numPaths, &maxPathLen); + maxPathLen += +1; - // Allocate memory for the PATH's - VERIFYC(NULL != (paths = calloc(1, sizeof(_cstring1_t) * numPaths)), - AEE_ENOMEMORY); - for (i = 0; i < (int)numPaths; ++i) { - VERIFYC(NULL != (paths[i].data = calloc(1, sizeof(char) * maxPathLen)), - AEE_ENOMEMORY); - paths[i].dataLen = maxPathLen; - } + // Allocate memory for the PATH's + VERIFYC(NULL != (paths = calloc(1, sizeof(_cstring1_t) * numPaths)), + AEE_ENOMEMORY); + for(i = 0; i < (int)numPaths; ++i) { + VERIFYC(NULL + != (paths[i].data + = calloc(1, sizeof(char) * maxPathLen)), + AEE_ENOMEMORY); + paths[i].dataLen = maxPathLen; + } - // Allocate single buffer for all the PATHs - VERIFYC(NULL != - (data_paths = calloc(1, sizeof(char) * maxPathLen * numPaths)), - AEE_ENOMEMORY); + // Allocate single buffer for all the PATHs + VERIFYC(NULL + != (data_paths + = calloc(1, sizeof(char) * maxPathLen * numPaths)), + AEE_ENOMEMORY); - // Get the paths - VERIFY(AEE_SUCCESS == - (nErr = apps_std_get_search_paths_with_env( - ADSP_LIBRARY_PATH, ";", paths, numPaths, &len, &maxPathLen))); - maxPathLen += 1; - for (i = 0; i < (int)numPaths; ++i) { - strlcat(data_paths, paths[i].data, - sizeof(char) * maxPathLen * numPaths); - strlcat(data_paths, ", ", sizeof(char) * maxPathLen * numPaths); - if (0 == fastrpc_read_config_file_from_path(paths[i].data, config_file)) { - file_found = 1; - FARF(ALWAYS, "Read fastrpc config file %s found at %s\n", config_file, - paths[i].data); - break; - } - } - if (!file_found) { - FARF(RUNTIME_RPC_HIGH, "%s: Couldn't find file %s, errno (%s) at %s\n", __func__, - config_file, strerror(errno), data_paths); - } + // Get the paths + VERIFY(AEE_SUCCESS + == (nErr = apps_std_get_search_paths_with_env( + ADSP_LIBRARY_PATH, ";", paths, numPaths, &len, + &maxPathLen))); + maxPathLen += 1; + for(i = 0; i < (int)numPaths; ++i) { + strlcat(data_paths, paths[i].data, + sizeof(char) * maxPathLen * numPaths); + strlcat(data_paths, ", ", + sizeof(char) * maxPathLen * numPaths); + if(0 + == fastrpc_read_config_file_from_path(paths[i].data, + config_file)) { + file_found = 1; + FARF(ALWAYS, + "Read fastrpc config file %s found at %s\n", + config_file, paths[i].data); + break; + } + } + if(!file_found) { + FARF(RUNTIME_RPC_HIGH, + "%s: Couldn't find file %s, errno (%s) at %s\n", __func__, + config_file, strerror(errno), data_paths); + } bail: - if (nErr) { - FARF(ERROR, "%s: failed for process %s", __func__, name); - } - if (paths) { - for (i = 0; i < (int)numPaths; ++i) { - if (paths[i].data) { - free(paths[i].data); - paths[i].data = NULL; - } - } - free(paths); - paths = NULL; - } - if (config_file) { - free(config_file); - config_file = NULL; - } - if (data_paths) { - free(data_paths); - } - return nErr; + if(nErr) { + FARF(ERROR, "%s: failed for process %s", __func__, name); + } + if(paths) { + for(i = 0; i < (int)numPaths; ++i) { + if(paths[i].data) { + free(paths[i].data); + paths[i].data = NULL; + } + } + free(paths); + paths = NULL; + } + if(config_file) { + free(config_file); + config_file = NULL; + } + if(data_paths) { + free(data_paths); + } + return nErr; } diff --git a/src/fastrpc_context.c b/src/fastrpc_context.c index 4e32a042..75528273 100644 --- a/src/fastrpc_context.c +++ b/src/fastrpc_context.c @@ -6,39 +6,45 @@ #endif #ifndef VERIFY_PRINT_WARN #define VERIFY_PRINT_WARN -#endif //VERIFY_PRINT_WARN +#endif // VERIFY_PRINT_WARN #define FARF_ERROR 1 #define FARF_HIGH 0 #define FARF_MEDIUM 0 -#include -#include -#include -#include -#include "verify.h" #include "fastrpc_context.h" -#include "fastrpc_internal.h" #include "fastrpc_apps_user.h" +#include "fastrpc_internal.h" +#include "verify.h" +#include +#include +#include +#include /* Global context table */ static fastrpc_context_table gctx; /* Add context entry to global context table */ -static inline void fastrpc_context_add_to_table(fastrpc_context *ctx) { +static inline void +fastrpc_context_add_to_table(fastrpc_context *ctx) +{ pthread_mutex_lock(&gctx.mut); HASH_ADD(hh, gctx.table, ctxid, sizeof(ctx->ctxid), ctx); pthread_mutex_unlock(&gctx.mut); } /* Remove context entry from global context table */ -static inline void fastrpc_context_remove_from_table(fastrpc_context *ctx) { +static inline void +fastrpc_context_remove_from_table(fastrpc_context *ctx) +{ pthread_mutex_lock(&gctx.mut); HASH_DELETE(hh, gctx.table, ctx); pthread_mutex_unlock(&gctx.mut); } /* Validate that context is present in global hash-table */ -static inline fastrpc_context *fastrpc_context_validate(uint64_t ctxid) { +static inline fastrpc_context * +fastrpc_context_validate(uint64_t ctxid) +{ fastrpc_context *ctx = NULL; // Search in hash-table @@ -54,60 +60,65 @@ static inline fastrpc_context *fastrpc_context_validate(uint64_t ctxid) { * * Effective domain ids passed by user are validated on the following * basis: - * Context can either be created on multiple sessions on one domain - * or multiple domains, but not both. - * For example, context cannot be created on 2 sessions on CDSP + - * 1 session on ADSP. + * Context can either be created on multiple sessions on one + *domain or multiple domains, but not both. For example, context cannot be + *created on 2 sessions on CDSP + 1 session on ADSP. * * returns 0 on success */ -static int fastrpc_context_init_domains(fastrpc_context_create *create, - fastrpc_context *ctx) { +static int +fastrpc_context_init_domains(fastrpc_context_create *create, + fastrpc_context *ctx) +{ int nErr = AEE_SUCCESS, i = 0, j = 0; - unsigned int effec_domain_id = 0, num_domain_ids = create->num_domain_ids; + unsigned int effec_domain_id = 0, + num_domain_ids = create->num_domain_ids; unsigned int *domain_ids = ctx->domains; bool multisess = true, multidom = true; - for (i = 0; i < num_domain_ids; i++) { + for(i = 0; i < num_domain_ids; i++) { effec_domain_id = create->effec_domain_ids[i]; VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(effec_domain_id), - AEE_EBADDOMAIN); + AEE_EBADDOMAIN); ctx->effec_domain_ids[i] = effec_domain_id; - domain_ids[i] = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(effec_domain_id); + domain_ids[i] + = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(effec_domain_id); /* - * If client is trying to create context on multiple sessions on - * same domain, validate that all domain ids are the same. + * If client is trying to create context on multiple sessions + * on same domain, validate that all domain ids are the same. */ - if (domain_ids[i] != domain_ids[0]) + if(domain_ids[i] != domain_ids[0]) multisess = false; } - if (multisess) + if(multisess) goto bail; /* * If client is trying to create context on multiple domains, validate * that every domain id in the list is unique. */ - for (i = 0; i < num_domain_ids; i++) { - for (j = i + 1; j < num_domain_ids; j++) { - if (domain_ids[j] == domain_ids[i]) { + for(i = 0; i < num_domain_ids; i++) { + for(j = i + 1; j < num_domain_ids; j++) { + if(domain_ids[j] == domain_ids[i]) { multidom = false; break; } } } - if (multidom) + if(multidom) goto bail; /* Context on multiple sessions on multiple domains is not allowed */ nErr = AEE_EBADPARM; - FARF(ALWAYS, "Error 0x%x: %s: context cannot be both multi-session & multi-domain", - nErr, __func__); + FARF(ALWAYS, + "Error 0x%x: %s: context cannot be both multi-session & " + "multi-domain", + nErr, __func__); return nErr; bail: - if (nErr) + if(nErr) FARF(ALWAYS, "Error 0x%x: %s failed", nErr, __func__); return nErr; @@ -120,18 +131,20 @@ static int fastrpc_context_init_domains(fastrpc_context_create *create, * * Returns 0 on success */ -static int fastrpc_context_deinit(fastrpc_context *ctx) { +static int +fastrpc_context_deinit(fastrpc_context *ctx) +{ unsigned int domain = 0; - if (!ctx) + if(!ctx) return AEE_EBADCONTEXT; pthread_mutex_lock(&ctx->mut); - for (unsigned int i = 0; i < ctx->num_domain_ids; i++) { + for(unsigned int i = 0; i < ctx->num_domain_ids; i++) { domain = ctx->effec_domain_ids[i]; // If no session was opened on domain, continue - if (!ctx->devs[i]) + if(!ctx->devs[i]) continue; fastrpc_session_close(domain, INVALID_DEVICE); @@ -153,48 +166,61 @@ static int fastrpc_context_deinit(fastrpc_context *ctx) { * Allocate context struct and initialize it * * @param[in] num_domain_ids : Number of effective domain ids on which - * context is being created. + * context is + *being created. * * Returns valid context struct on success, NULL on failure */ -static fastrpc_context *fastrpc_context_init(unsigned int num_domain_ids) { +static fastrpc_context * +fastrpc_context_init(unsigned int num_domain_ids) +{ fastrpc_context *ctx = NULL; int nErr = AEE_SUCCESS; // Allocate memory for context struct and its members - VERIFYC(NULL != (ctx = (fastrpc_context *)calloc(1, - sizeof(fastrpc_context))), AEE_ENOMEMORY); + VERIFYC(NULL + != (ctx = (fastrpc_context *)calloc( + 1, sizeof(fastrpc_context))), + AEE_ENOMEMORY); pthread_mutex_init(&ctx->mut, 0); - VERIFYC(NULL != (ctx->effec_domain_ids = (unsigned int *)calloc( - num_domain_ids, sizeof(*ctx->effec_domain_ids))), AEE_ENOMEMORY); - VERIFYC(NULL != (ctx->domains = (unsigned int *)calloc(num_domain_ids, - sizeof(*ctx->domains))), AEE_ENOMEMORY); - VERIFYC(NULL != (ctx->devs = (int *)calloc(num_domain_ids, - sizeof(*ctx->devs))), AEE_ENOMEMORY); + VERIFYC(NULL + != (ctx->effec_domain_ids = (unsigned int *)calloc( + num_domain_ids, sizeof(*ctx->effec_domain_ids))), + AEE_ENOMEMORY); + VERIFYC(NULL + != (ctx->domains = (unsigned int *)calloc( + num_domain_ids, sizeof(*ctx->domains))), + AEE_ENOMEMORY); + VERIFYC(NULL + != (ctx->devs + = (int *)calloc(num_domain_ids, sizeof(*ctx->devs))), + AEE_ENOMEMORY); ctx->num_domain_ids = num_domain_ids; bail: - if (nErr) { + if(nErr) { FARF(ALWAYS, "Error 0x%x: %s failed for num domain ids %u\n", - nErr, __func__, num_domain_ids); + nErr, __func__, num_domain_ids); fastrpc_context_deinit(ctx); ctx = NULL; } return ctx; } -int fastrpc_destroy_context(uint64_t ctxid) { +int +fastrpc_destroy_context(uint64_t ctxid) +{ int nErr = AEE_SUCCESS, dev = -1; fastrpc_context *ctx = NULL; VERIFYC(gctx.init, AEE_ENOTINITIALIZED); - FARF(ALWAYS, "%s called for context 0x%"PRIx64"", __func__, ctxid); + FARF(ALWAYS, "%s called for context 0x%" PRIx64 "", __func__, ctxid); VERIFYC(NULL != (ctx = fastrpc_context_validate(ctxid)), - AEE_EBADCONTEXT); + AEE_EBADCONTEXT); fastrpc_context_remove_from_table(ctx); /* @@ -203,21 +229,24 @@ int fastrpc_destroy_context(uint64_t ctxid) { * Use the first domain's device fd. */ VERIFYC(-1 != (dev = get_device_fd(ctx->effec_domain_ids[0])), - AEE_EINVALIDDEVICE); - VERIFY(AEE_SUCCESS == (nErr = ioctl_mdctx_manage(dev, - FASTRPC_MDCTX_REMOVE, NULL, NULL, 0, &ctx->ctxid))); + AEE_EINVALIDDEVICE); + VERIFY(AEE_SUCCESS + == (nErr = ioctl_mdctx_manage(dev, FASTRPC_MDCTX_REMOVE, NULL, + NULL, 0, &ctx->ctxid))); VERIFY(AEE_SUCCESS == (nErr = fastrpc_context_deinit(ctx))); - FARF(ALWAYS, "%s done for context 0x%"PRIx64"", __func__, ctxid); + FARF(ALWAYS, "%s done for context 0x%" PRIx64 "", __func__, ctxid); bail: - if (nErr) { - FARF(ALWAYS, "Error 0x%x: %s failed for ctx 0x%"PRIx64"", - nErr, __func__, ctxid); + if(nErr) { + FARF(ALWAYS, "Error 0x%x: %s failed for ctx 0x%" PRIx64 "", + nErr, __func__, ctxid); } return nErr; } -int fastrpc_create_context(fastrpc_context_create *create) { +int +fastrpc_create_context(fastrpc_context_create *create) +{ int nErr = AEE_SUCCESS, dev = -1; unsigned int num_domain_ids = 0, effec_domain_id = 0, i = 0; fastrpc_context *ctx = NULL; @@ -229,20 +258,22 @@ int fastrpc_create_context(fastrpc_context_create *create) { // Basic sanity checks on client inputs VERIFYC(create->effec_domain_ids && !create->flags, AEE_EBADPARM); VERIFYC(num_domain_ids && num_domain_ids < NUM_DOMAINS_EXTEND, - AEE_EBADPARM); + AEE_EBADPARM); VERIFYC(NULL != (ctx = fastrpc_context_init(num_domain_ids)), - AEE_EBADCONTEXT); - VERIFYC(AEE_SUCCESS == (nErr = fastrpc_context_init_domains(create, - ctx)), AEE_EBADPARM); + AEE_EBADCONTEXT); + VERIFYC(AEE_SUCCESS + == (nErr = fastrpc_context_init_domains(create, ctx)), + AEE_EBADPARM); // Create session on each domain id - for (i = 0; i < num_domain_ids; i++) { + for(i = 0; i < num_domain_ids; i++) { effec_domain_id = ctx->effec_domain_ids[i]; // Create session on domain if not already created - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_open(effec_domain_id, - &ctx->devs[i]))); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_session_open(effec_domain_id, + &ctx->devs[i]))); } /* @@ -251,49 +282,54 @@ int fastrpc_create_context(fastrpc_context_create *create) { * Use the first domain's device fd. */ VERIFYC(-1 != (dev = get_device_fd(ctx->effec_domain_ids[0])), - AEE_EINVALIDDEVICE); - VERIFY(AEE_SUCCESS == (nErr = ioctl_mdctx_manage(dev, - FASTRPC_MDCTX_SETUP, ctx, ctx->domains, - num_domain_ids, &ctx->ctxid))); + AEE_EINVALIDDEVICE); + VERIFY(AEE_SUCCESS + == (nErr = ioctl_mdctx_manage(dev, FASTRPC_MDCTX_SETUP, ctx, + ctx->domains, num_domain_ids, + &ctx->ctxid))); fastrpc_context_add_to_table(ctx); // Return context to user create->ctx = ctx->ctxid; - FARF(ALWAYS, "%s done with context 0x%"PRIx64" on %u domain ids", - __func__, ctx->ctxid, num_domain_ids); + FARF(ALWAYS, "%s done with context 0x%" PRIx64 " on %u domain ids", + __func__, ctx->ctxid, num_domain_ids); bail: - if (nErr) { - FARF(ALWAYS, "Error 0x%x: %s failed for %u domain ids\n", - nErr, __func__, num_domain_ids); + if(nErr) { + FARF(ALWAYS, "Error 0x%x: %s failed for %u domain ids\n", nErr, + __func__, num_domain_ids); fastrpc_context_deinit(ctx); } return nErr; } -int fastrpc_context_get_domains(uint64_t ctxid, - unsigned int **effec_domain_ids, unsigned int *num_domain_ids) { +int +fastrpc_context_get_domains(uint64_t ctxid, unsigned int **effec_domain_ids, + unsigned int *num_domain_ids) +{ int nErr = AEE_SUCCESS; fastrpc_context *ctx = NULL; VERIFYC(NULL != (ctx = fastrpc_context_validate(ctxid)), - AEE_EBADCONTEXT); + AEE_EBADCONTEXT); VERIFYC(effec_domain_ids && num_domain_ids, AEE_EMEMPTR); *effec_domain_ids = ctx->effec_domain_ids; *num_domain_ids = ctx->num_domain_ids; bail: - if (nErr) + if(nErr) FARF(ALWAYS, "Error 0x%x: %s failed\n", nErr, __func__); return nErr; } -int fastrpc_context_table_init(void) { +int +fastrpc_context_table_init(void) +{ int nErr = AEE_SUCCESS; pthread_mutex_init(&gctx.mut, 0); gctx.init = true; - if (nErr) + if(nErr) FARF(ERROR, "Error 0x%x: %s failed\n", nErr, __func__); else FARF(RUNTIME_RPC_HIGH, "%s done", __func__); @@ -301,7 +337,9 @@ int fastrpc_context_table_init(void) { return nErr; } -int fastrpc_context_table_deinit(void) { +int +fastrpc_context_table_deinit(void) +{ int nErr = AEE_SUCCESS; fastrpc_context *table = gctx.table, *ctx = NULL, *tmp = NULL; pthread_mutex_t *mut = &gctx.mut; @@ -311,7 +349,8 @@ int fastrpc_context_table_deinit(void) { /* Delete all contexts */ pthread_mutex_lock(mut); - HASH_ITER(hh, table, ctx, tmp) { + HASH_ITER(hh, table, ctx, tmp) + { HASH_DELETE(hh, table, ctx); fastrpc_context_deinit(ctx); } @@ -319,10 +358,10 @@ int fastrpc_context_table_deinit(void) { pthread_mutex_destroy(mut); bail: - if (nErr) + if(nErr) FARF(ERROR, "Error 0x%x: %s failed\n", nErr, __func__); else FARF(RUNTIME_RPC_HIGH, "%s done", __func__); return nErr; -} \ No newline at end of file +} diff --git a/src/fastrpc_ioctl.c b/src/fastrpc_ioctl.c index e0329e13..4d4aacb4 100644 --- a/src/fastrpc_ioctl.c +++ b/src/fastrpc_ioctl.c @@ -12,248 +12,298 @@ #include /* check async support */ -int is_async_fastrpc_supported(void) { - /* async not supported by upstream driver */ - return 0; +int +is_async_fastrpc_supported(void) +{ + /* async not supported by upstream driver */ + return 0; } /* Returns the name of the domain based on the following ADSP/SLPI/MDSP/CDSP - Return Secure node */ -const char *get_secure_domain_name(int domain_id) { - const char *name; - int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); - - switch (domain) { - case ADSP_DOMAIN_ID: - name = ADSPRPC_SECURE_DEVICE; - break; - case SDSP_DOMAIN_ID: - name = SDSPRPC_SECURE_DEVICE; - break; - case MDSP_DOMAIN_ID: - name = MDSPRPC_SECURE_DEVICE; - break; - case CDSP_DOMAIN_ID: - name = CDSPRPC_SECURE_DEVICE; - break; - case CDSP1_DOMAIN_ID: - name = CDSP1RPC_SECURE_DEVICE; - break; - case GDSP0_DOMAIN_ID: - name = GDSP0RPC_SECURE_DEVICE; - break; - case GDSP1_DOMAIN_ID: - name = GDSP1RPC_SECURE_DEVICE; - break; - default: - name = DEFAULT_DEVICE; - break; - } - return name; +const char * +get_secure_domain_name(int domain_id) +{ + const char *name; + int domain = GET_DOMAIN_FROM_EFFEC_DOMAIN_ID(domain_id); + + switch(domain) { + case ADSP_DOMAIN_ID: + name = ADSPRPC_SECURE_DEVICE; + break; + case SDSP_DOMAIN_ID: + name = SDSPRPC_SECURE_DEVICE; + break; + case MDSP_DOMAIN_ID: + name = MDSPRPC_SECURE_DEVICE; + break; + case CDSP_DOMAIN_ID: + name = CDSPRPC_SECURE_DEVICE; + break; + case CDSP1_DOMAIN_ID: + name = CDSP1RPC_SECURE_DEVICE; + break; + case GDSP0_DOMAIN_ID: + name = GDSP0RPC_SECURE_DEVICE; + break; + case GDSP1_DOMAIN_ID: + name = GDSP1RPC_SECURE_DEVICE; + break; + default: + name = DEFAULT_DEVICE; + break; + } + return name; } -int ioctl_init(int dev, uint32_t flags, int attr, unsigned char *shell, int shelllen, - int shellfd, char *mem, int memlen, int memfd, int tessiglen) { - int ioErr = 0; - struct fastrpc_ioctl_init_create init = {0}; - struct fastrpc_ioctl_init_create_static init_static = {0}; - - switch (flags) { - case FASTRPC_INIT_ATTACH: - ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_ATTACH, NULL); - break; - case FASTRPC_INIT_ATTACH_SENSORS: - ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_ATTACH_SNS, NULL); - break; - case FASTRPC_INIT_CREATE_STATIC: - init_static.namelen = shelllen; - init_static.memlen = memlen; - init_static.name = (uint64_t)shell; - ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_CREATE_STATIC, - (unsigned long)&init_static); - break; - case FASTRPC_INIT_CREATE: - init.file = (uint64_t)shell; - init.filelen = shelllen; - init.filefd = shellfd; - init.attrs = attr; - init.siglen = tessiglen; - ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_CREATE, (unsigned long)&init); - break; - default: - FARF(ERROR, "ERROR: %s Invalid init flags passed %d", __func__, flags); - ioErr = AEE_EBADPARM; - break; - } - - return ioErr; +int +ioctl_init(int dev, uint32_t flags, int attr, unsigned char *shell, + int shelllen, int shellfd, char *mem, int memlen, int memfd, + int tessiglen) +{ + int ioErr = 0; + struct fastrpc_ioctl_init_create init = { 0 }; + struct fastrpc_ioctl_init_create_static init_static = { 0 }; + + switch(flags) { + case FASTRPC_INIT_ATTACH: + ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_ATTACH, NULL); + break; + case FASTRPC_INIT_ATTACH_SENSORS: + ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_ATTACH_SNS, NULL); + break; + case FASTRPC_INIT_CREATE_STATIC: + init_static.namelen = shelllen; + init_static.memlen = memlen; + init_static.name = (uint64_t)shell; + ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_CREATE_STATIC, + (unsigned long)&init_static); + break; + case FASTRPC_INIT_CREATE: + init.file = (uint64_t)shell; + init.filelen = shelllen; + init.filefd = shellfd; + init.attrs = attr; + init.siglen = tessiglen; + ioErr = ioctl(dev, FASTRPC_IOCTL_INIT_CREATE, + (unsigned long)&init); + break; + default: + FARF(ERROR, "ERROR: %s Invalid init flags passed %d", __func__, + flags); + ioErr = AEE_EBADPARM; + break; + } + + return ioErr; } -int ioctl_invoke(int dev, int req, remote_handle handle, uint32_t sc, void *pra, - int *fds, unsigned int *attrs, void *job, unsigned int *crc, - uint64_t *perf_kernel, uint64_t *perf_dsp) { - int ioErr = AEE_SUCCESS; - struct fastrpc_ioctl_invoke invoke = {0}; - - invoke.handle = handle; - invoke.sc = sc; - invoke.args = (uint64_t)pra; - if (req >= INVOKE && req <= INVOKE_FD) - ioErr = ioctl(dev, FASTRPC_IOCTL_INVOKE, (unsigned long)&invoke); - else - return AEE_EUNSUPPORTED; - - return ioErr; +int +ioctl_invoke(int dev, int req, remote_handle handle, uint32_t sc, void *pra, + int *fds, unsigned int *attrs, void *job, unsigned int *crc, + uint64_t *perf_kernel, uint64_t *perf_dsp) +{ + int ioErr = AEE_SUCCESS; + struct fastrpc_ioctl_invoke invoke = { 0 }; + + invoke.handle = handle; + invoke.sc = sc; + invoke.args = (uint64_t)pra; + if(req >= INVOKE && req <= INVOKE_FD) + ioErr + = ioctl(dev, FASTRPC_IOCTL_INVOKE, (unsigned long)&invoke); + else + return AEE_EUNSUPPORTED; + + return ioErr; } -int ioctl_invoke2_response(int dev, fastrpc_async_jobid *jobid, - remote_handle *handle, uint32_t *sc, int *result, - uint64_t *perf_kernel, uint64_t *perf_dsp) { - return AEE_EUNSUPPORTED; +int +ioctl_invoke2_response(int dev, fastrpc_async_jobid *jobid, + remote_handle *handle, uint32_t *sc, int *result, + uint64_t *perf_kernel, uint64_t *perf_dsp) +{ + return AEE_EUNSUPPORTED; } -int ioctl_invoke2_notif(int dev, int *domain, int *session, int *status) { - return AEE_EUNSUPPORTED; +int +ioctl_invoke2_notif(int dev, int *domain, int *session, int *status) +{ + return AEE_EUNSUPPORTED; } -int ioctl_mmap(int dev, int req, uint32_t flags, int attr, int fd, int offset, - size_t len, uintptr_t vaddrin, uint64_t *vaddrout) { - int ioErr = AEE_SUCCESS; - - switch (req) { - case MEM_MAP: { - struct fastrpc_ioctl_mem_map map = {0}; - map.version = 0; - map.fd = fd; - map.offset = offset; - map.flags = flags; - map.vaddrin = (uint64_t)vaddrin; - map.length = len; - map.attrs = attr; - ioErr = ioctl(dev, FASTRPC_IOCTL_MEM_MAP, (unsigned long)&map); - *vaddrout = (uint64_t)map.vaddrout; - } break; - case MMAP: - case MMAP_64: { - struct fastrpc_ioctl_req_mmap map = {0}; - map.fd = fd; - map.flags = flags; - map.vaddrin = (uint64_t)vaddrin; - map.size = len; - ioErr = ioctl(dev, FASTRPC_IOCTL_MMAP, (unsigned long)&map); - *vaddrout = (uint64_t)map.vaddrout; - } break; - default: - FARF(ERROR, "ERROR: %s Invalid request passed %d", __func__, req); - ioErr = AEE_EBADPARM; - break; - } - return ioErr; +int +ioctl_mmap(int dev, int req, uint32_t flags, int attr, int fd, int offset, + size_t len, uintptr_t vaddrin, uint64_t *vaddrout) +{ + int ioErr = AEE_SUCCESS; + + switch(req) { + case MEM_MAP: { + struct fastrpc_ioctl_mem_map map = { 0 }; + map.version = 0; + map.fd = fd; + map.offset = offset; + map.flags = flags; + map.vaddrin = (uint64_t)vaddrin; + map.length = len; + map.attrs = attr; + ioErr = ioctl(dev, FASTRPC_IOCTL_MEM_MAP, (unsigned long)&map); + *vaddrout = (uint64_t)map.vaddrout; + } break; + case MMAP: + case MMAP_64: { + struct fastrpc_ioctl_req_mmap map = { 0 }; + map.fd = fd; + map.flags = flags; + map.vaddrin = (uint64_t)vaddrin; + map.size = len; + ioErr = ioctl(dev, FASTRPC_IOCTL_MMAP, (unsigned long)&map); + *vaddrout = (uint64_t)map.vaddrout; + } break; + default: + FARF(ERROR, "ERROR: %s Invalid request passed %d", __func__, + req); + ioErr = AEE_EBADPARM; + break; + } + return ioErr; } -int ioctl_munmap(int dev, int req, int attr, void *buf, int fd, int len, - uint64_t vaddr) { - int ioErr = AEE_SUCCESS; - - switch (req) { - case MEM_UNMAP: - case MUNMAP_FD: { - struct fastrpc_ioctl_mem_unmap unmap = {0}; - unmap.version = 0; - unmap.fd = fd; - unmap.vaddr = vaddr; - unmap.length = len; - ioErr = ioctl(dev, FASTRPC_IOCTL_MEM_UNMAP, (unsigned long)&unmap); - } break; - case MUNMAP: - case MUNMAP_64: { - struct fastrpc_ioctl_req_munmap unmap = {0}; - unmap.vaddrout = vaddr; - unmap.size = (ssize_t)len; - ioErr = ioctl(dev, FASTRPC_IOCTL_MUNMAP, (unsigned long)&unmap); - } break; - default: - FARF(ERROR, "ERROR: %s Invalid request passed %d", __func__, req); - break; - } - - return ioErr; +int +ioctl_munmap(int dev, int req, int attr, void *buf, int fd, int len, + uint64_t vaddr) +{ + int ioErr = AEE_SUCCESS; + + switch(req) { + case MEM_UNMAP: + case MUNMAP_FD: { + struct fastrpc_ioctl_mem_unmap unmap = { 0 }; + unmap.version = 0; + unmap.fd = fd; + unmap.vaddr = vaddr; + unmap.length = len; + ioErr = ioctl(dev, FASTRPC_IOCTL_MEM_UNMAP, + (unsigned long)&unmap); + } break; + case MUNMAP: + case MUNMAP_64: { + struct fastrpc_ioctl_req_munmap unmap = { 0 }; + unmap.vaddrout = vaddr; + unmap.size = (ssize_t)len; + ioErr + = ioctl(dev, FASTRPC_IOCTL_MUNMAP, (unsigned long)&unmap); + } break; + default: + FARF(ERROR, "ERROR: %s Invalid request passed %d", __func__, + req); + break; + } + + return ioErr; } -int ioctl_getinfo(int dev, uint32_t *info) { - *info = 1; - return AEE_SUCCESS; +int +ioctl_getinfo(int dev, uint32_t *info) +{ + *info = 1; + return AEE_SUCCESS; } -int ioctl_getdspinfo(int dev, int domain, uint32_t attr, uint32_t *capability) { - int ioErr = AEE_SUCCESS; - static struct fastrpc_ioctl_capability cap = {0}; - - if (attr >= PERF_V2_DRIVER_SUPPORT && attr < FASTRPC_MAX_ATTRIBUTES) { - *capability = 0; - return 0; - } - - cap.domain = domain; - cap.attribute_id = attr; - cap.capability = 0; - ioErr = ioctl(dev, FASTRPC_IOCTL_GET_DSP_INFO, &cap); - *capability = cap.capability; - return ioErr; +int +ioctl_getdspinfo(int dev, int domain, uint32_t attr, uint32_t *capability) +{ + int ioErr = AEE_SUCCESS; + static struct fastrpc_ioctl_capability cap = { 0 }; + + if(attr >= PERF_V2_DRIVER_SUPPORT && attr < FASTRPC_MAX_ATTRIBUTES) { + *capability = 0; + return 0; + } + + cap.domain = domain; + cap.attribute_id = attr; + cap.capability = 0; + ioErr = ioctl(dev, FASTRPC_IOCTL_GET_DSP_INFO, &cap); + *capability = cap.capability; + return ioErr; } -int ioctl_setmode(int dev, int mode) { - if (mode == FASTRPC_SESSION_ID1) - return AEE_SUCCESS; +int +ioctl_setmode(int dev, int mode) +{ + if(mode == FASTRPC_SESSION_ID1) + return AEE_SUCCESS; - return AEE_EUNSUPPORTED; + return AEE_EUNSUPPORTED; } -int ioctl_control(int dev, int req, void *c) { - return AEE_EUNSUPPORTED; +int +ioctl_control(int dev, int req, void *c) +{ + return AEE_EUNSUPPORTED; } -int ioctl_getperf(int dev, int key, void *data, int *datalen) { - return AEE_EUNSUPPORTED; +int +ioctl_getperf(int dev, int key, void *data, int *datalen) +{ + return AEE_EUNSUPPORTED; } -int ioctl_signal_create(int dev, uint32_t signal, uint32_t flags) { - return AEE_EUNSUPPORTED; +int +ioctl_signal_create(int dev, uint32_t signal, uint32_t flags) +{ + return AEE_EUNSUPPORTED; } -int ioctl_signal_destroy(int dev, uint32_t signal) { - return AEE_EUNSUPPORTED; +int +ioctl_signal_destroy(int dev, uint32_t signal) +{ + return AEE_EUNSUPPORTED; } -int ioctl_signal_signal(int dev, uint32_t signal) { - return AEE_EUNSUPPORTED; +int +ioctl_signal_signal(int dev, uint32_t signal) +{ + return AEE_EUNSUPPORTED; } -int ioctl_signal_wait(int dev, uint32_t signal, uint32_t timeout_usec) { - return AEE_EUNSUPPORTED; +int +ioctl_signal_wait(int dev, uint32_t signal, uint32_t timeout_usec) +{ + return AEE_EUNSUPPORTED; } -int ioctl_signal_cancel_wait(int dev, uint32_t signal) { - return AEE_EUNSUPPORTED; +int +ioctl_signal_cancel_wait(int dev, uint32_t signal) +{ + return AEE_EUNSUPPORTED; } -int ioctl_sharedbuf(int dev, - struct fastrpc_proc_sharedbuf_info *sharedbuf_info) { - return AEE_EUNSUPPORTED; +int +ioctl_sharedbuf(int dev, struct fastrpc_proc_sharedbuf_info *sharedbuf_info) +{ + return AEE_EUNSUPPORTED; } -int ioctl_session_info(int dev, struct fastrpc_proc_sess_info *sess_info) { - return AEE_EUNSUPPORTED; +int +ioctl_session_info(int dev, struct fastrpc_proc_sess_info *sess_info) +{ + return AEE_EUNSUPPORTED; } -int ioctl_optimization(int dev, uint32_t max_concurrency) { - return AEE_EUNSUPPORTED; +int +ioctl_optimization(int dev, uint32_t max_concurrency) +{ + return AEE_EUNSUPPORTED; } -int ioctl_mdctx_manage(int dev, int req, void *user_ctx, - unsigned int *domain_ids, unsigned int num_domain_ids, uint64_t *ctx) +int +ioctl_mdctx_manage(int dev, int req, void *user_ctx, unsigned int *domain_ids, + unsigned int num_domain_ids, uint64_t *ctx) { // TODO: Implement this for opensource return AEE_EUNSUPPORTED; -} \ No newline at end of file +} diff --git a/src/fastrpc_latency.c b/src/fastrpc_latency.c index 46fdab8f..1583e0fc 100644 --- a/src/fastrpc_latency.c +++ b/src/fastrpc_latency.c @@ -23,179 +23,200 @@ #include "fastrpc_latency.h" #include "verify.h" -int fastrpc_latency_invoke_incr(struct fastrpc_latency *qp) { - if (qp == NULL || qp->state == FASTRPC_LATENCY_STOP) - goto bail; - qp->invoke++; - if (qp->vote == FASTRPC_LATENCY_VOTE_OFF) { - pthread_mutex_lock(&qp->wmut); - pthread_cond_signal(&qp->cond); - pthread_mutex_unlock(&qp->wmut); - } +int +fastrpc_latency_invoke_incr(struct fastrpc_latency *qp) +{ + if(qp == NULL || qp->state == FASTRPC_LATENCY_STOP) + goto bail; + qp->invoke++; + if(qp->vote == FASTRPC_LATENCY_VOTE_OFF) { + pthread_mutex_lock(&qp->wmut); + pthread_cond_signal(&qp->cond); + pthread_mutex_unlock(&qp->wmut); + } bail: - return 0; + return 0; } -int fastrpc_latency_init(int dev, struct fastrpc_latency *qos) { - int nErr = 0; +int +fastrpc_latency_init(int dev, struct fastrpc_latency *qos) +{ + int nErr = 0; - VERIFYC(qos && dev != -1, AEE_ERPC); + VERIFYC(qos && dev != -1, AEE_ERPC); - qos->dev = dev; - qos->state = FASTRPC_LATENCY_STOP; - qos->thread = 0; - qos->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; - pthread_mutex_init(&qos->mut, 0); - pthread_mutex_init(&qos->wmut, 0); - pthread_cond_init(&qos->cond, NULL); + qos->dev = dev; + qos->state = FASTRPC_LATENCY_STOP; + qos->thread = 0; + qos->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; + pthread_mutex_init(&qos->mut, 0); + pthread_mutex_init(&qos->wmut, 0); + pthread_cond_init(&qos->cond, NULL); bail: - return nErr; + return nErr; } -int fastrpc_latency_deinit(struct fastrpc_latency *qos) { - int nErr = 0; - - VERIFYC(qos, AEE_ERPC); - if (qos->state == FASTRPC_LATENCY_START) { - pthread_mutex_lock(&qos->wmut); - qos->exit = FASTRPC_LATENCY_EXIT; - pthread_cond_signal(&qos->cond); - pthread_mutex_unlock(&qos->wmut); - if (qos->thread) { - pthread_join(qos->thread, 0); - qos->thread = 0; - FARF(ALWAYS, "latency thread joined"); - } - pthread_mutex_destroy(&qos->mut); - pthread_mutex_destroy(&qos->wmut); - } +int +fastrpc_latency_deinit(struct fastrpc_latency *qos) +{ + int nErr = 0; + + VERIFYC(qos, AEE_ERPC); + if(qos->state == FASTRPC_LATENCY_START) { + pthread_mutex_lock(&qos->wmut); + qos->exit = FASTRPC_LATENCY_EXIT; + pthread_cond_signal(&qos->cond); + pthread_mutex_unlock(&qos->wmut); + if(qos->thread) { + pthread_join(qos->thread, 0); + qos->thread = 0; + FARF(ALWAYS, "latency thread joined"); + } + pthread_mutex_destroy(&qos->mut); + pthread_mutex_destroy(&qos->wmut); + } bail: - return nErr; + return nErr; } /* FastRPC QoS handler votes for pm_qos latency based on * RPC activity in a window of time. */ -static void *fastrpc_latency_thread_handler(void *arg) { - int nErr = 0; - long ns = 0; - struct timespec tw; - struct timeval tp; - int invoke = 0; - struct fastrpc_ioctl_control qos = {0}; - struct fastrpc_ctrl_latency lp = {0}; - struct fastrpc_latency *qp = (struct fastrpc_latency *)arg; - - if (qp == NULL) { - nErr = AEE_ERPC; - FARF(ERROR, "Error 0x%x: %s failed \n", nErr, __func__); - return NULL; - } - VERIFYC(qp->dev != -1, AEE_ERPC); - - FARF(ALWAYS, "%s started for QoS with activity window %d ms", __func__, - FASTRPC_LATENCY_WAIT_TIME_USEC / MS_TO_US); - - // Look for RPC activity in 100 ms window - qp->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; - qp->invoke++; - while (1) { - nErr = gettimeofday(&tp, NULL); - /* valid values for "tv_nsec" are [0, 999999999] */ - ns = ((tp.tv_usec + qp->wait_time) * US_TO_NS); - tw.tv_sec = tp.tv_sec + (ns / SEC_TO_NS); - tw.tv_nsec = (ns % SEC_TO_NS); - - pthread_mutex_lock(&qp->wmut); - if (qp->wait_time) - pthread_cond_timedwait(&qp->cond, &qp->wmut, &tw); - else - pthread_cond_wait(&qp->cond, &qp->wmut); - pthread_mutex_unlock(&qp->wmut); - - if (qp->exit == FASTRPC_LATENCY_EXIT) { - qp->exit = 0; - break; - } - - pthread_mutex_lock(&qp->mut); - invoke = qp->invoke; - qp->invoke = 0; - pthread_mutex_unlock(&qp->mut); - - if (invoke) { - // found RPC activity in window. vote for pm_qos. - qp->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; - if (qp->vote == FASTRPC_LATENCY_VOTE_OFF) { - lp.enable = FASTRPC_LATENCY_VOTE_ON; - lp.latency = qp->latency; - nErr = ioctl_control(qp->dev, DSPRPC_CONTROL_LATENCY, &lp); - if (nErr == AEE_SUCCESS) { - qp->vote = FASTRPC_LATENCY_VOTE_ON; - } else if (nErr == AEE_EUNSUPPORTED) { - goto bail; - } else { - FARF(ERROR, - "Error %d: %s: PM QoS ON request failed with errno %d (%s)", - nErr, __func__, errno, strerror(errno)); - } - } - } else { - // No RPC activity detected in a window. Remove pm_qos vote. - qp->wait_time = 0; - if (qp->vote == FASTRPC_LATENCY_VOTE_ON) { - lp.enable = FASTRPC_LATENCY_VOTE_OFF; - lp.latency = 0; - nErr = ioctl_control(qp->dev, DSPRPC_CONTROL_LATENCY, &lp); - if (nErr == AEE_SUCCESS) { - qp->vote = FASTRPC_LATENCY_VOTE_OFF; - } else if (nErr == AEE_EUNSUPPORTED) { - goto bail; - } else { - FARF(ERROR, - "Error %d: %s: PM QoS OFF request failed with errno %d (%s)", - nErr, __func__, errno, strerror(errno)); - } - } - } - } - FARF(ALWAYS, "FastRPC latency thread for QoS exited"); +static void * +fastrpc_latency_thread_handler(void *arg) +{ + int nErr = 0; + long ns = 0; + struct timespec tw; + struct timeval tp; + int invoke = 0; + struct fastrpc_ioctl_control qos = { 0 }; + struct fastrpc_ctrl_latency lp = { 0 }; + struct fastrpc_latency *qp = (struct fastrpc_latency *)arg; + + if(qp == NULL) { + nErr = AEE_ERPC; + FARF(ERROR, "Error 0x%x: %s failed \n", nErr, __func__); + return NULL; + } + VERIFYC(qp->dev != -1, AEE_ERPC); + + FARF(ALWAYS, "%s started for QoS with activity window %d ms", __func__, + FASTRPC_LATENCY_WAIT_TIME_USEC / MS_TO_US); + + // Look for RPC activity in 100 ms window + qp->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; + qp->invoke++; + while(1) { + nErr = gettimeofday(&tp, NULL); + /* valid values for "tv_nsec" are [0, 999999999] */ + ns = ((tp.tv_usec + qp->wait_time) * US_TO_NS); + tw.tv_sec = tp.tv_sec + (ns / SEC_TO_NS); + tw.tv_nsec = (ns % SEC_TO_NS); + + pthread_mutex_lock(&qp->wmut); + if(qp->wait_time) + pthread_cond_timedwait(&qp->cond, &qp->wmut, &tw); + else + pthread_cond_wait(&qp->cond, &qp->wmut); + pthread_mutex_unlock(&qp->wmut); + + if(qp->exit == FASTRPC_LATENCY_EXIT) { + qp->exit = 0; + break; + } + + pthread_mutex_lock(&qp->mut); + invoke = qp->invoke; + qp->invoke = 0; + pthread_mutex_unlock(&qp->mut); + + if(invoke) { + // found RPC activity in window. vote for pm_qos. + qp->wait_time = FASTRPC_LATENCY_WAIT_TIME_USEC; + if(qp->vote == FASTRPC_LATENCY_VOTE_OFF) { + lp.enable = FASTRPC_LATENCY_VOTE_ON; + lp.latency = qp->latency; + nErr = ioctl_control( + qp->dev, DSPRPC_CONTROL_LATENCY, &lp); + if(nErr == AEE_SUCCESS) { + qp->vote = FASTRPC_LATENCY_VOTE_ON; + } else if(nErr == AEE_EUNSUPPORTED) { + goto bail; + } else { + FARF(ERROR, + "Error %d: %s: PM QoS ON request " + "failed with errno %d (%s)", + nErr, __func__, errno, + strerror(errno)); + } + } + } else { + // No RPC activity detected in a window. Remove pm_qos + // vote. + qp->wait_time = 0; + if(qp->vote == FASTRPC_LATENCY_VOTE_ON) { + lp.enable = FASTRPC_LATENCY_VOTE_OFF; + lp.latency = 0; + nErr = ioctl_control( + qp->dev, DSPRPC_CONTROL_LATENCY, &lp); + if(nErr == AEE_SUCCESS) { + qp->vote = FASTRPC_LATENCY_VOTE_OFF; + } else if(nErr == AEE_EUNSUPPORTED) { + goto bail; + } else { + FARF( + ERROR, + "Error %d: %s: PM QoS OFF request " + "failed with errno %d (%s)", + nErr, __func__, errno, + strerror(errno)); + } + } + } + } + FARF(ALWAYS, "FastRPC latency thread for QoS exited"); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, - "Error 0x%x: %s failed for wait time %d latency control enable %d " - "latency %d\n", - nErr, __func__, qp->wait_time, qos.lp.enable, qos.lp.latency); - } - return NULL; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for wait time %d latency control " + "enable %d " + "latency %d\n", + nErr, __func__, qp->wait_time, qos.lp.enable, + qos.lp.latency); + } + return NULL; } -int fastrpc_set_pm_qos(struct fastrpc_latency *qos, uint32_t enable, - uint32_t latency) { - int nErr = AEE_SUCCESS; - int state = 0; - - VERIFYC(qos != NULL, AEE_EBADPARM); - if (qos->exit == FASTRPC_LATENCY_EXIT) - goto bail; - pthread_mutex_lock(&qos->mut); - state = qos->state; - qos->latency = latency; - pthread_mutex_unlock(&qos->mut); - - if (!enable && state == FASTRPC_LATENCY_START) { - qos->exit = FASTRPC_LATENCY_EXIT; - pthread_mutex_lock(&qos->wmut); - pthread_cond_signal(&qos->cond); - pthread_mutex_unlock(&qos->wmut); - } - - if (enable && state == FASTRPC_LATENCY_STOP) { - qos->state = FASTRPC_LATENCY_START; - VERIFY(AEE_SUCCESS == (nErr = pthread_create(&qos->thread, 0, - fastrpc_latency_thread_handler, - (void *)qos))); - } +int +fastrpc_set_pm_qos(struct fastrpc_latency *qos, uint32_t enable, + uint32_t latency) +{ + int nErr = AEE_SUCCESS; + int state = 0; + + VERIFYC(qos != NULL, AEE_EBADPARM); + if(qos->exit == FASTRPC_LATENCY_EXIT) + goto bail; + pthread_mutex_lock(&qos->mut); + state = qos->state; + qos->latency = latency; + pthread_mutex_unlock(&qos->mut); + + if(!enable && state == FASTRPC_LATENCY_START) { + qos->exit = FASTRPC_LATENCY_EXIT; + pthread_mutex_lock(&qos->wmut); + pthread_cond_signal(&qos->cond); + pthread_mutex_unlock(&qos->wmut); + } + + if(enable && state == FASTRPC_LATENCY_STOP) { + qos->state = FASTRPC_LATENCY_START; + VERIFY(AEE_SUCCESS + == (nErr = pthread_create( + &qos->thread, 0, fastrpc_latency_thread_handler, + (void *)qos))); + } bail: - return nErr; + return nErr; } diff --git a/src/fastrpc_log.c b/src/fastrpc_log.c index de773f4d..ec32405c 100644 --- a/src/fastrpc_log.c +++ b/src/fastrpc_log.c @@ -2,19 +2,19 @@ // SPDX-License-Identifier: BSD-3-Clause #define _GNU_SOURCE +#include #include #include #include #include #include #include -#include #include #include "AEEStdErr.h" -#include "fastrpc_config.h" #include "HAP_farf_internal.h" #include "fastrpc_common.h" +#include "fastrpc_config.h" #include "fastrpc_trace.h" #include "rpcmem_internal.h" #include "verify.h" @@ -29,321 +29,356 @@ /* trace to update start of persist buffer. */ #define DEBUF_BUF_TRACE "frpc_dbgbuf:" -#define IS_PERSIST_BUF_DATA(len, level) \ - ((len > 0) && (len < MAX_FARF_LEN) && (level == HAP_LEVEL_RPC_CRITICAL || \ - level == HAP_LEVEL_CRITICAL)) +#define IS_PERSIST_BUF_DATA(len, level) \ + ((len > 0) && (len < MAX_FARF_LEN) \ + && (level == HAP_LEVEL_RPC_CRITICAL || level == HAP_LEVEL_CRITICAL)) typedef struct persist_buffer { - /* Debug logs to be printed on dsp side */ - char *buf; + /* Debug logs to be printed on dsp side */ + char *buf; - /* Buffer index */ - unsigned int size; + /* Buffer index */ + unsigned int size; - /* Lock to protect global logger buffer */ - pthread_mutex_t mut; + /* Lock to protect global logger buffer */ + pthread_mutex_t mut; } persist_buffer; static persist_buffer persist_buf; static uint32_t fastrpc_logmask; -static FILE *log_userspace_file_fd; // file descriptor to save userspace runtime - // farf logs +static FILE *log_userspace_file_fd; // file descriptor to save userspace + // runtime farf logs -void set_runtime_logmask(uint32_t mask) { fastrpc_logmask = mask; } +void +set_runtime_logmask(uint32_t mask) +{ + fastrpc_logmask = mask; +} #if defined(__LE_TVM__) || defined(__ANDROID__) #include extern const char *__progname; -static inline int hap_2_android_log_level(int hap_level) { - switch (hap_level) { - case HAP_LEVEL_LOW: - case HAP_LEVEL_RPC_LOW: - case HAP_LEVEL_CRITICAL: - case HAP_LEVEL_RPC_CRITICAL: - return ANDROID_LOG_DEBUG; - case HAP_LEVEL_MEDIUM: - case HAP_LEVEL_HIGH: - case HAP_LEVEL_RPC_MEDIUM: - case HAP_LEVEL_RPC_HIGH: - return ANDROID_LOG_INFO; - case HAP_LEVEL_ERROR: - case HAP_LEVEL_RPC_ERROR: - return ANDROID_LOG_ERROR; - case HAP_LEVEL_FATAL: - case HAP_LEVEL_RPC_FATAL: - return ANDROID_LOG_FATAL; - } - return ANDROID_LOG_UNKNOWN; +static inline int +hap_2_android_log_level(int hap_level) +{ + switch(hap_level) { + case HAP_LEVEL_LOW: + case HAP_LEVEL_RPC_LOW: + case HAP_LEVEL_CRITICAL: + case HAP_LEVEL_RPC_CRITICAL: + return ANDROID_LOG_DEBUG; + case HAP_LEVEL_MEDIUM: + case HAP_LEVEL_HIGH: + case HAP_LEVEL_RPC_MEDIUM: + case HAP_LEVEL_RPC_HIGH: + return ANDROID_LOG_INFO; + case HAP_LEVEL_ERROR: + case HAP_LEVEL_RPC_ERROR: + return ANDROID_LOG_ERROR; + case HAP_LEVEL_FATAL: + case HAP_LEVEL_RPC_FATAL: + return ANDROID_LOG_FATAL; + } + return ANDROID_LOG_UNKNOWN; } #elif defined(USE_SYSLOG) #include -int hap_2_syslog_level(int log_type) { - switch (log_type) { - case HAP_LEVEL_LOW: - case HAP_LEVEL_RPC_LOW: - case HAP_LEVEL_RPC_CRITICAL: - case HAP_LEVEL_CRITICAL: - return LOG_DEBUG; - case HAP_LEVEL_MEDIUM: - case HAP_LEVEL_HIGH: - case HAP_LEVEL_RPC_MEDIUM: - case HAP_LEVEL_RPC_HIGH: - return LOG_INFO; - case HAP_LEVEL_ERROR: - case HAP_LEVEL_RPC_ERROR: - return LOG_ERR; - case HAP_LEVEL_FATAL: - case HAP_LEVEL_RPC_FATAL: - return LOG_CRIT; - } - return 0; +int +hap_2_syslog_level(int log_type) +{ + switch(log_type) { + case HAP_LEVEL_LOW: + case HAP_LEVEL_RPC_LOW: + case HAP_LEVEL_RPC_CRITICAL: + case HAP_LEVEL_CRITICAL: + return LOG_DEBUG; + case HAP_LEVEL_MEDIUM: + case HAP_LEVEL_HIGH: + case HAP_LEVEL_RPC_MEDIUM: + case HAP_LEVEL_RPC_HIGH: + return LOG_INFO; + case HAP_LEVEL_ERROR: + case HAP_LEVEL_RPC_ERROR: + return LOG_ERR; + case HAP_LEVEL_FATAL: + case HAP_LEVEL_RPC_FATAL: + return LOG_CRIT; + } + return 0; } #endif -static unsigned long long GetTime(void) { - struct timeval tv; - struct timezone tz; +static unsigned long long +GetTime(void) +{ + struct timeval tv; + struct timezone tz; - gettimeofday(&tv, &tz); + gettimeofday(&tv, &tz); - /* Integer overflow check. */ - if (tv.tv_sec > (ULLONG_MAX - tv.tv_usec) / 1000000ULL) { - return 0; - } - return tv.tv_sec * 1000000ULL + tv.tv_usec; + /* Integer overflow check. */ + if(tv.tv_sec > (ULLONG_MAX - tv.tv_usec) / 1000000ULL) { + return 0; + } + return tv.tv_sec * 1000000ULL + tv.tv_usec; } /* Function to append CRITICAL debug logs to persist_buf */ -static void print_dbgbuf_data(char *data, int size) { - int len = 0; - - pthread_mutex_lock(&persist_buf.mut); - if (persist_buf.buf) { - if (((persist_buf.size + PREPEND_DBGBUF_FARF_SIZE + size) > - DEBUG_BUF_SIZE)) { - persist_buf.size = strlen(DEBUF_BUF_TRACE) + 1; - } - len = snprintf(persist_buf.buf + persist_buf.size, - DEBUG_BUF_SIZE - persist_buf.size, "%llu:%d:%d:dom:%d: %s\n", - GetTime(), getpid(), gettid(), get_current_domain(), data); - persist_buf.size += (len + 1); - } - pthread_mutex_unlock(&persist_buf.mut); +static void +print_dbgbuf_data(char *data, int size) +{ + int len = 0; + + pthread_mutex_lock(&persist_buf.mut); + if(persist_buf.buf) { + if(((persist_buf.size + PREPEND_DBGBUF_FARF_SIZE + size) + > DEBUG_BUF_SIZE)) { + persist_buf.size = strlen(DEBUF_BUF_TRACE) + 1; + } + len = snprintf(persist_buf.buf + persist_buf.size, + DEBUG_BUF_SIZE - persist_buf.size, + "%llu:%d:%d:dom:%d: %s\n", GetTime(), getpid(), + gettid(), get_current_domain(), data); + persist_buf.size += (len + 1); + } + pthread_mutex_unlock(&persist_buf.mut); } -void HAP_debug_v2(int level, const char *file, int line, const char *format, - ...) { - char *buf = NULL; - int len = 0; - va_list argp; - - buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN); - if (buf == NULL) { - return; - } - va_start(argp, format); - len = vsnprintf(buf, MAX_FARF_LEN, format, argp); - va_end(argp); - /* If level is set to HAP_LEVEL_DEBUG append the farf message to persist - * buffer. */ - if (persist_buf.buf && IS_PERSIST_BUF_DATA(len, level)) { - print_dbgbuf_data(buf, len); - } - HAP_debug(buf, level, file, line); - if (buf) { - free(buf); - buf = NULL; - } +void +HAP_debug_v2(int level, const char *file, int line, const char *format, ...) +{ + char *buf = NULL; + int len = 0; + va_list argp; + + buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN); + if(buf == NULL) { + return; + } + va_start(argp, format); + len = vsnprintf(buf, MAX_FARF_LEN, format, argp); + va_end(argp); + /* If level is set to HAP_LEVEL_DEBUG append the farf message to + * persist buffer. */ + if(persist_buf.buf && IS_PERSIST_BUF_DATA(len, level)) { + print_dbgbuf_data(buf, len); + } + HAP_debug(buf, level, file, line); + if(buf) { + free(buf); + buf = NULL; + } } -void HAP_debug_runtime(int level, const char *file, int line, - const char *format, ...) { - int len = 0; - va_list argp; - char *buf = NULL, *log = NULL; - - /* - * Adding logs to persist buffer when level is set to - * RUNTIME_RPC_CRITICAL and fastrpc_log mask is disabled. - */ - if (((1 << level) & (fastrpc_logmask)) || - ((level == HAP_LEVEL_RPC_CRITICAL) && persist_buf.buf) || - log_userspace_file_fd != NULL) { - buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN); - if (buf == NULL) { - return; - } - va_start(argp, format); - len = vsnprintf(buf, MAX_FARF_LEN, format, argp); - va_end(argp); - log = (char *)malloc(sizeof(char) * MAX_FARF_LEN); - if (log == NULL) { - return; - } - snprintf(log, MAX_FARF_LEN, "%d:%d:%s:%s:%d: %s", getpid(), gettid(), - __progname, file, line, buf); - } - - print_dbgbuf_data(log, len); - if (((1 << level) & (fastrpc_logmask))) { - if (log_userspace_file_fd != NULL) { - fputs(log, log_userspace_file_fd); - fputs("\n", log_userspace_file_fd); - } - HAP_debug(buf, level, file, line); - } - if (buf) { - free(buf); - } - if (log) { - free(log); - } +void +HAP_debug_runtime(int level, const char *file, int line, const char *format, + ...) +{ + int len = 0; + va_list argp; + char *buf = NULL, *log = NULL; + + /* + * Adding logs to persist buffer when level is set to + * RUNTIME_RPC_CRITICAL and fastrpc_log mask is disabled. + */ + if(((1 << level) & (fastrpc_logmask)) + || ((level == HAP_LEVEL_RPC_CRITICAL) && persist_buf.buf) + || log_userspace_file_fd != NULL) { + buf = (char *)malloc(sizeof(char) * MAX_FARF_LEN); + if(buf == NULL) { + return; + } + va_start(argp, format); + len = vsnprintf(buf, MAX_FARF_LEN, format, argp); + va_end(argp); + log = (char *)malloc(sizeof(char) * MAX_FARF_LEN); + if(log == NULL) { + return; + } + snprintf(log, MAX_FARF_LEN, "%d:%d:%s:%s:%d: %s", getpid(), + gettid(), __progname, file, line, buf); + } + + print_dbgbuf_data(log, len); + if(((1 << level) & (fastrpc_logmask))) { + if(log_userspace_file_fd != NULL) { + fputs(log, log_userspace_file_fd); + fputs("\n", log_userspace_file_fd); + } + HAP_debug(buf, level, file, line); + } + if(buf) { + free(buf); + } + if(log) { + free(log); + } } #ifdef __LE_TVM__ -static char android_log_level_to_char(int level) { - char log_level; - - switch (level) { - case ANDROID_LOG_DEBUG: - case ANDROID_LOG_DEFAULT: - log_level = 'D'; - break; - case ANDROID_LOG_INFO: - log_level = 'I'; - break; - case ANDROID_LOG_WARN: - log_level = 'W'; - break; - case ANDROID_LOG_ERROR: - log_level = 'E'; - break; - case ANDROID_LOG_FATAL: - log_level = 'F'; - break; - default: - log_level = 'D'; - } - - return log_level; +static char +android_log_level_to_char(int level) +{ + char log_level; + + switch(level) { + case ANDROID_LOG_DEBUG: + case ANDROID_LOG_DEFAULT: + log_level = 'D'; + break; + case ANDROID_LOG_INFO: + log_level = 'I'; + break; + case ANDROID_LOG_WARN: + log_level = 'W'; + break; + case ANDROID_LOG_ERROR: + log_level = 'E'; + break; + case ANDROID_LOG_FATAL: + log_level = 'F'; + break; + default: + log_level = 'D'; + } + + return log_level; } -static char *get_filename(const char *str, const char delim) { - char *iter = NULL, *token = str; +static char * +get_filename(const char *str, const char delim) +{ + char *iter = NULL, *token = str; - for (iter = str; *iter != '\0'; iter++) { - if (*iter == delim) - token = iter + 1; - } - return token; + for(iter = str; *iter != '\0'; iter++) { + if(*iter == delim) + token = iter + 1; + } + return token; } -int get_newlines(const char *str) { - char *iter = NULL; - int newlines = 0; - - for (iter = str; *iter != '\0'; iter++) { - if (*iter == '\n') - newlines++; - } - return newlines; +int +get_newlines(const char *str) +{ + char *iter = NULL; + int newlines = 0; + + for(iter = str; *iter != '\0'; iter++) { + if(*iter == '\n') + newlines++; + } + return newlines; } #endif -void HAP_debug(const char *msg, int level, const char *filename, int line) { +void +HAP_debug(const char *msg, int level, const char *filename, int line) +{ #ifdef __ANDROID__ - __android_log_print(hap_2_android_log_level(level), __progname, "%s:%d: %s", - filename, line, msg); + __android_log_print(hap_2_android_log_level(level), __progname, + "%s:%d: %s", filename, line, msg); #elif defined(USE_SYSLOG) - syslog(hap_2_syslog_level(level), "%s:%d: %s", filename, line, msg); + syslog(hap_2_syslog_level(level), "%s:%d: %s", filename, line, msg); #elif defined(__LE_TVM__) - const char delim = '/'; - char *short_filename = NULL; - int newlines = 0; - - short_filename = get_filename(filename, delim); - newlines = get_newlines(msg); - level = hap_2_android_log_level(level); - if (newlines) - printf("ADSPRPC: %d %d %c %s: %s:%d: %s", getpid(), gettid(), - android_log_level_to_char(level), __progname, short_filename, line, - msg); - else - printf("ADSPRPC: %d %d %c %s: %s:%d: %s\n", getpid(), gettid(), - android_log_level_to_char(level), __progname, short_filename, line, - msg); - fflush(stdout); + const char delim = '/'; + char *short_filename = NULL; + int newlines = 0; + + short_filename = get_filename(filename, delim); + newlines = get_newlines(msg); + level = hap_2_android_log_level(level); + if(newlines) + printf("ADSPRPC: %d %d %c %s: %s:%d: %s", getpid(), gettid(), + android_log_level_to_char(level), __progname, + short_filename, line, msg); + else + printf("ADSPRPC: %d %d %c %s: %s:%d: %s\n", getpid(), gettid(), + android_log_level_to_char(level), __progname, + short_filename, line, msg); + fflush(stdout); #endif } -void fastrpc_log_init() { - bool debug_build_type = false; - int nErr = AEE_SUCCESS, fd = -1; - char build_type[PROPERTY_VALUE_MAX]; - char *logfilename; - - pthread_mutex_init(&persist_buf.mut, 0); - pthread_mutex_lock(&persist_buf.mut); - /* - * Get build type by reading the target properties, - * if buuid type is eng or userdebug allocate 1 MB persist buf. - */ - if (fastrpc_get_property_string(FASTRPC_BUILD_TYPE, build_type, NULL)) { +void +fastrpc_log_init() +{ + bool debug_build_type = false; + int nErr = AEE_SUCCESS, fd = -1; + char build_type[PROPERTY_VALUE_MAX]; + char *logfilename; + + pthread_mutex_init(&persist_buf.mut, 0); + pthread_mutex_lock(&persist_buf.mut); + /* + * Get build type by reading the target properties, + * if buuid type is eng or userdebug allocate 1 MB persist buf. + */ + if(fastrpc_get_property_string(FASTRPC_BUILD_TYPE, build_type, NULL)) { #if !defined(LE_ENABLE) - if (!strncmp(build_type, "eng", PROPERTY_VALUE_MAX) || - !strncmp(build_type, "userdebug", PROPERTY_VALUE_MAX)) - debug_build_type = true; + if(!strncmp(build_type, "eng", PROPERTY_VALUE_MAX) + || !strncmp(build_type, "userdebug", PROPERTY_VALUE_MAX)) + debug_build_type = true; #else - if (atoi(build_type)) - debug_build_type = true; + if(atoi(build_type)) + debug_build_type = true; #endif - } - if (persist_buf.buf == NULL && debug_build_type) { - /* Create a debug buffer to append DEBUG FARF level message. */ - persist_buf.buf = (char *)rpcmem_alloc_internal( - RPCMEM_HEAP_ID_SYSTEM, RPCMEM_DEFAULT_FLAGS | RPCMEM_TRY_MAP_STATIC, - DEBUG_BUF_SIZE * sizeof(char)); - if (persist_buf.buf) { - fd = rpcmem_to_fd(persist_buf.buf); - FARF(RUNTIME_RPC_HIGH, "%s: persist_buf.buf created %d size %d", __func__, - fd, DEBUG_BUF_SIZE); - /* Appending header to persist buffer, to identify the start address - * through script. */ - strlcpy(persist_buf.buf, DEBUF_BUF_TRACE, DEBUG_BUF_SIZE); - persist_buf.size = strlen(DEBUF_BUF_TRACE) + 1; - } else { - nErr = AEE_ENORPCMEMORY; - FARF(ERROR, "Error 0x%x: %s allocation failed for persist_buf of size %d", - nErr, __func__, DEBUG_BUF_SIZE); - } - } - pthread_mutex_unlock(&persist_buf.mut); - logfilename = fastrpc_config_get_userspace_runtime_farf_file(); - if (logfilename) { - log_userspace_file_fd = fopen(logfilename, "w"); - if (log_userspace_file_fd == NULL) { - VERIFY_EPRINTF("Error 0x%x: %s failed to collect userspace runtime farf " - "logs into file %s with errno %s\n", - nErr, __func__, logfilename, strerror(errno)); - } else { - FARF(RUNTIME_RPC_HIGH, "%s done\n", __func__); - } - } + } + if(persist_buf.buf == NULL && debug_build_type) { + /* Create a debug buffer to append DEBUG FARF level message. */ + persist_buf.buf = (char *)rpcmem_alloc_internal( + RPCMEM_HEAP_ID_SYSTEM, + RPCMEM_DEFAULT_FLAGS | RPCMEM_TRY_MAP_STATIC, + DEBUG_BUF_SIZE * sizeof(char)); + if(persist_buf.buf) { + fd = rpcmem_to_fd(persist_buf.buf); + FARF(RUNTIME_RPC_HIGH, + "%s: persist_buf.buf created %d size %d", + __func__, fd, DEBUG_BUF_SIZE); + /* Appending header to persist buffer, to identify the + * start address through script. */ + strlcpy(persist_buf.buf, DEBUF_BUF_TRACE, + DEBUG_BUF_SIZE); + persist_buf.size = strlen(DEBUF_BUF_TRACE) + 1; + } else { + nErr = AEE_ENORPCMEMORY; + FARF(ERROR, + "Error 0x%x: %s allocation failed for " + "persist_buf of size %d", + nErr, __func__, DEBUG_BUF_SIZE); + } + } + pthread_mutex_unlock(&persist_buf.mut); + logfilename = fastrpc_config_get_userspace_runtime_farf_file(); + if(logfilename) { + log_userspace_file_fd = fopen(logfilename, "w"); + if(log_userspace_file_fd == NULL) { + VERIFY_EPRINTF("Error 0x%x: %s failed to collect " + "userspace runtime farf " + "logs into file %s with errno %s\n", + nErr, __func__, logfilename, + strerror(errno)); + } else { + FARF(RUNTIME_RPC_HIGH, "%s done\n", __func__); + } + } } -void fastrpc_log_deinit() { - - pthread_mutex_lock(&persist_buf.mut); - if (persist_buf.buf) { - rpcmem_free(persist_buf.buf); - persist_buf.buf = NULL; - } - pthread_mutex_unlock(&persist_buf.mut); - if (log_userspace_file_fd) { - fclose(log_userspace_file_fd); - log_userspace_file_fd = NULL; - } - pthread_mutex_destroy(&persist_buf.mut); +void +fastrpc_log_deinit() +{ + + pthread_mutex_lock(&persist_buf.mut); + if(persist_buf.buf) { + rpcmem_free(persist_buf.buf); + persist_buf.buf = NULL; + } + pthread_mutex_unlock(&persist_buf.mut); + if(log_userspace_file_fd) { + fclose(log_userspace_file_fd); + log_userspace_file_fd = NULL; + } + pthread_mutex_destroy(&persist_buf.mut); } diff --git a/src/fastrpc_mem.c b/src/fastrpc_mem.c index 8f62fc25..dfe80420 100644 --- a/src/fastrpc_mem.c +++ b/src/fastrpc_mem.c @@ -1,13 +1,12 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause - -//#ifndef VERIFY_PRINT_ERROR -//#define VERIFY_PRINT_ERROR -//#endif // VERIFY_PRINT_ERROR -//#ifndef VERIFY_PRINT_INFO -//#define VERIFY_PRINT_INFO -//#endif // VERIFY_PRINT_INFO +// #ifndef VERIFY_PRINT_ERROR +// #define VERIFY_PRINT_ERROR +// #endif // VERIFY_PRINT_ERROR +// #ifndef VERIFY_PRINT_INFO +// #define VERIFY_PRINT_INFO +// #endif // VERIFY_PRINT_INFO #ifndef VERIFY_PRINT_WARN #define VERIFY_PRINT_WARN @@ -20,13 +19,13 @@ #include #include #include +#include #include #include #include #include #include #include -#include #define FARF_ERROR 1 @@ -42,9 +41,9 @@ #include "verify.h" #ifdef LE_ENABLE -#define PROPERTY_VALUE_MAX \ - 92 // as this macro is defined in cutils for Android platforms, defined - // explicitly for LE platform +#define PROPERTY_VALUE_MAX \ + 92 // as this macro is defined in cutils for Android platforms, defined + // explicitly for LE platform #elif (defined _ANDROID) || (defined ANDROID) // TODO: Bharath #include "cutils/properties.h" #define PROPERTY_VALUE_MAX 92 @@ -73,26 +72,26 @@ #define FASTRPC_MAP_FLAGS_MASK (0xFFFF) struct mem_to_fd { - QNode qn; - void *buf; - size_t size; - int fd; - int nova; - int attr; - int refcount; - bool mapped[NUM_DOMAINS_EXTEND]; //! Buffer persistent mapping status + QNode qn; + void *buf; + size_t size; + int fd; + int nova; + int attr; + int refcount; + bool mapped[NUM_DOMAINS_EXTEND]; //! Buffer persistent mapping status }; struct mem_to_fd_list { - QList ql; - pthread_mutex_t mut; + QList ql; + pthread_mutex_t mut; }; struct dma_handle_info { - int fd; - int len; - int used; - uint32_t attr; + int fd; + int len; + int used; + uint32_t attr; }; /** @@ -100,14 +99,14 @@ struct dma_handle_info { * Access to the list is protected with mutex. */ struct static_map { - QNode qn; - struct fastrpc_mem_map map; - int refs; + QNode qn; + struct fastrpc_mem_map map; + int refs; }; struct static_map_list { - QList ql; - pthread_mutex_t mut; + QList ql; + pthread_mutex_t mut; }; static struct static_map_list smaplst[NUM_DOMAINS_EXTEND]; @@ -119,691 +118,791 @@ static int fastrpc_unmap_fd(void *buf, size_t size, int fd, int attr); static __inline void try_map_buffer(struct mem_to_fd *tofd); static __inline int try_unmap_buffer(struct mem_to_fd *tofd); -int fastrpc_mem_init(void) { - int ii; - - pthread_mutex_init(&fdlist.mut, 0); - QList_Ctor(&fdlist.ql); - memset(dhandles, 0, sizeof(dhandles)); - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - QList_Ctor(&smaplst[ii].ql); - pthread_mutex_init(&smaplst[ii].mut, 0); - } - return 0; +int +fastrpc_mem_init(void) +{ + int ii; + + pthread_mutex_init(&fdlist.mut, 0); + QList_Ctor(&fdlist.ql); + memset(dhandles, 0, sizeof(dhandles)); + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + QList_Ctor(&smaplst[ii].ql); + pthread_mutex_init(&smaplst[ii].mut, 0); + } + return 0; } -int fastrpc_mem_deinit(void) { - int ii; - - pthread_mutex_destroy(&fdlist.mut); - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - pthread_mutex_destroy(&smaplst[ii].mut); - } - return 0; +int +fastrpc_mem_deinit(void) +{ + int ii; + + pthread_mutex_destroy(&fdlist.mut); + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + pthread_mutex_destroy(&smaplst[ii].mut); + } + return 0; } -static void *remote_register_fd_attr(int fd, size_t size, int attr) { - int nErr = AEE_SUCCESS; - void *po = NULL; - void *buf = (void *)-1; - struct mem_to_fd *tofd = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - VERIFYC(fd >= 0, AEE_EBADPARM); - - VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), AEE_ENOMEMORY); - QNode_CtorZ(&tofd->qn); - VERIFYM((void *)-1 != (buf = mmap(0, size, PROT_NONE, - MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)), - AEE_ERPC, "Error %x: mmap failed for fd %x, size %x\n", nErr, fd, - size); - tofd->buf = buf; - tofd->size = size; - tofd->fd = fd; - tofd->nova = 1; - tofd->attr = attr; - - pthread_mutex_lock(&fdlist.mut); - QList_AppendNode(&fdlist.ql, &tofd->qn); - pthread_mutex_unlock(&fdlist.mut); - - tofd = 0; - po = buf; - buf = (void *)-1; +static void * +remote_register_fd_attr(int fd, size_t size, int attr) +{ + int nErr = AEE_SUCCESS; + void *po = NULL; + void *buf = (void *)-1; + struct mem_to_fd *tofd = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFYC(fd >= 0, AEE_EBADPARM); + + VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), AEE_ENOMEMORY); + QNode_CtorZ(&tofd->qn); + VERIFYM((void *)-1 + != (buf = mmap(0, size, PROT_NONE, + MAP_ANONYMOUS | MAP_PRIVATE, -1, 0)), + AEE_ERPC, "Error %x: mmap failed for fd %x, size %x\n", nErr, + fd, size); + tofd->buf = buf; + tofd->size = size; + tofd->fd = fd; + tofd->nova = 1; + tofd->attr = attr; + + pthread_mutex_lock(&fdlist.mut); + QList_AppendNode(&fdlist.ql, &tofd->qn); + pthread_mutex_unlock(&fdlist.mut); + + tofd = 0; + po = buf; + buf = (void *)-1; bail: - if (buf != (void *)-1) - munmap(buf, size); - if (tofd) { - free(tofd); - tofd = NULL; - } - if (nErr != AEE_SUCCESS) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: remote register fd fails for fd %d, size %zu\n", - nErr, fd, size); - } - } - return po; + if(buf != (void *)-1) + munmap(buf, size); + if(tofd) { + free(tofd); + tofd = NULL; + } + if(nErr != AEE_SUCCESS) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: remote register fd fails for fd %d, " + "size %zu\n", + nErr, fd, size); + } + } + return po; } -void *remote_register_fd(int fd, int size) { - if (size < 0) { - FARF(ERROR, "Error: %s failed for invalid size %d", __func__, size); - return NULL; - } - return remote_register_fd_attr(fd, size, 0); +void * +remote_register_fd(int fd, int size) +{ + if(size < 0) { + FARF(ERROR, "Error: %s failed for invalid size %d", __func__, + size); + return NULL; + } + return remote_register_fd_attr(fd, size, 0); } -void *remote_register_fd2(int fd, size_t size) { - return remote_register_fd_attr(fd, size, 0); +void * +remote_register_fd2(int fd, size_t size) +{ + return remote_register_fd_attr(fd, size, 0); } -static int remote_register_buf_common(void *buf, size_t size, int fd, - int attr) { - int nErr = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - VERIFYC(NULL != buf, AEE_EBADPARM); - VERIFYC(size != 0, AEE_EBADPARM); - - if (fd != -1) { - struct mem_to_fd *tofd; - int fdfound = 0; - QNode *pn, *pnn; - - pthread_mutex_lock(&fdlist.mut); - QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) { - tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); - if (tofd->buf == buf && tofd->size == size && tofd->fd == fd) { - fdfound = 1; - if (attr) - tofd->attr = attr; - tofd->refcount++; - break; - } - } - pthread_mutex_unlock(&fdlist.mut); - if (!fdfound) { - VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), AEE_ENOMEMORY); - QNode_CtorZ(&tofd->qn); - tofd->buf = buf; - tofd->size = size; - tofd->fd = fd; - if (attr) - tofd->attr = attr; - tofd->refcount++; - if (tofd->attr & FASTRPC_ATTR_TRY_MAP_STATIC) { - try_map_buffer(tofd); - } - pthread_mutex_lock(&fdlist.mut); - QList_AppendNode(&fdlist.ql, &tofd->qn); - pthread_mutex_unlock(&fdlist.mut); - } - } else { - QNode *pn, *pnn; - struct mem_to_fd *freefd = NULL; - pthread_mutex_lock(&fdlist.mut); - struct mem_to_fd *addr_match_fd = NULL; - QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) { - struct mem_to_fd *tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); - if (tofd->buf == buf) { - if (tofd->size == size) { - tofd->refcount--; - if (tofd->refcount <= 0) { - QNode_DequeueZ(&tofd->qn); - freefd = tofd; - tofd = NULL; - } - break; - } else { - addr_match_fd = tofd; - } - } - } - pthread_mutex_unlock(&fdlist.mut); - if (freefd) { - if (freefd->attr & FASTRPC_ATTR_KEEP_MAP) { - fastrpc_unmap_fd(freefd->buf, freefd->size, freefd->fd, freefd->attr); - } - if (freefd->attr & FASTRPC_ATTR_TRY_MAP_STATIC) { - try_unmap_buffer(freefd); - } - if (freefd->nova) { - munmap(freefd->buf, freefd->size); - } - free(freefd); - freefd = NULL; - } else if (addr_match_fd) { - /** - * When buf deregister size mismatch with register size, deregister buf - * fails leaving stale fd in fdlist. Bad fd can be attached to other - * shared buffers in next invoke calls. - */ - FARF(ERROR, - "FATAL: Size mismatch between deregister buf (%p) size (%zu) and " - "registered buf size (%zu) fd %d, bad fd can be attached to other " - "shared buffers. Use same buffer size as registered buffer", - buf, size, addr_match_fd->size, addr_match_fd->fd); - raise(SIGABRT); - } - } +static int +remote_register_buf_common(void *buf, size_t size, int fd, int attr) +{ + int nErr = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + VERIFYC(NULL != buf, AEE_EBADPARM); + VERIFYC(size != 0, AEE_EBADPARM); + + if(fd != -1) { + struct mem_to_fd *tofd; + int fdfound = 0; + QNode *pn, *pnn; + + pthread_mutex_lock(&fdlist.mut); + QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) + { + tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); + if(tofd->buf == buf && tofd->size == size + && tofd->fd == fd) { + fdfound = 1; + if(attr) + tofd->attr = attr; + tofd->refcount++; + break; + } + } + pthread_mutex_unlock(&fdlist.mut); + if(!fdfound) { + VERIFYC(NULL != (tofd = calloc(1, sizeof(*tofd))), + AEE_ENOMEMORY); + QNode_CtorZ(&tofd->qn); + tofd->buf = buf; + tofd->size = size; + tofd->fd = fd; + if(attr) + tofd->attr = attr; + tofd->refcount++; + if(tofd->attr & FASTRPC_ATTR_TRY_MAP_STATIC) { + try_map_buffer(tofd); + } + pthread_mutex_lock(&fdlist.mut); + QList_AppendNode(&fdlist.ql, &tofd->qn); + pthread_mutex_unlock(&fdlist.mut); + } + } else { + QNode *pn, *pnn; + struct mem_to_fd *freefd = NULL; + pthread_mutex_lock(&fdlist.mut); + struct mem_to_fd *addr_match_fd = NULL; + QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) + { + struct mem_to_fd *tofd + = STD_RECOVER_REC(struct mem_to_fd, qn, pn); + if(tofd->buf == buf) { + if(tofd->size == size) { + tofd->refcount--; + if(tofd->refcount <= 0) { + QNode_DequeueZ(&tofd->qn); + freefd = tofd; + tofd = NULL; + } + break; + } else { + addr_match_fd = tofd; + } + } + } + pthread_mutex_unlock(&fdlist.mut); + if(freefd) { + if(freefd->attr & FASTRPC_ATTR_KEEP_MAP) { + fastrpc_unmap_fd(freefd->buf, freefd->size, + freefd->fd, freefd->attr); + } + if(freefd->attr & FASTRPC_ATTR_TRY_MAP_STATIC) { + try_unmap_buffer(freefd); + } + if(freefd->nova) { + munmap(freefd->buf, freefd->size); + } + free(freefd); + freefd = NULL; + } else if(addr_match_fd) { + /** + * When buf deregister size mismatch with register + * size, deregister buf fails leaving stale fd in + * fdlist. Bad fd can be attached to other shared + * buffers in next invoke calls. + */ + FARF(ERROR, + "FATAL: Size mismatch between deregister buf " + "(%p) size (%zu) and " + "registered buf size (%zu) fd %d, bad fd can be " + "attached to other " + "shared buffers. Use same buffer size as " + "registered buffer", + buf, size, addr_match_fd->size, + addr_match_fd->fd); + raise(SIGABRT); + } + } bail: - if (nErr != AEE_SUCCESS) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: remote_register_buf failed buf %p, size %zu, fd 0x%x", - nErr, buf, size, fd); - } - } - return nErr; + if(nErr != AEE_SUCCESS) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: remote_register_buf failed buf %p, " + "size %zu, fd 0x%x", + nErr, buf, size, fd); + } + } + return nErr; } -void remote_register_buf(void *buf, int size, int fd) { - remote_register_buf_common(buf, (size_t)size, fd, 0); +void +remote_register_buf(void *buf, int size, int fd) +{ + remote_register_buf_common(buf, (size_t)size, fd, 0); } -void remote_register_buf_attr(void *buf, int size, int fd, int attr) { - remote_register_buf_common(buf, (size_t)size, fd, attr); +void +remote_register_buf_attr(void *buf, int size, int fd, int attr) +{ + remote_register_buf_common(buf, (size_t)size, fd, attr); } -void remote_register_buf_attr2(void *buf, size_t size, int fd, int attr) { - remote_register_buf_common(buf, size, fd, attr); +void +remote_register_buf_attr2(void *buf, size_t size, int fd, int attr) +{ + remote_register_buf_common(buf, size, fd, attr); } -int remote_register_dma_handle_attr(int fd, uint32_t len, uint32_t attr) { - int nErr = AEE_SUCCESS, i; - int fd_found = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - if (attr && attr != FASTRPC_ATTR_NOMAP) { - FARF(ERROR, "Error: %s failed, unsupported attribute 0x%x", __func__, attr); - return AEE_EBADPARM; - } - VERIFYC(fd >= 0, AEE_EBADPARM); - VERIFYC(len >= 0, AEE_EBADPARM); - - pthread_mutex_lock(&fdlist.mut); - for (i = 0; i < dma_handle_count; i++) { - if (dhandles[i].used && dhandles[i].fd == fd) { - /* If fd already present in handle list, then just update attribute only - * if its zero */ - if (!dhandles[i].attr) { - dhandles[i].attr = attr; - } - fd_found = 1; - dhandles[i].used++; - break; - } - } - pthread_mutex_unlock(&fdlist.mut); - - if (fd_found) { - return AEE_SUCCESS; - } - - pthread_mutex_lock(&fdlist.mut); - for (i = 0; i < dma_handle_count; i++) { - if (!dhandles[i].used) { - dhandles[i].fd = fd; - dhandles[i].len = len; - dhandles[i].used = 1; - dhandles[i].attr = attr; - break; - } - } - if (i == dma_handle_count) { - if (dma_handle_count >= MAX_DMA_HANDLES) { - FARF(ERROR, "Error: %s: DMA handle list is already full (count %d)", - __func__, dma_handle_count); - nErr = AEE_EINVHANDLE; - } else { - dhandles[dma_handle_count].fd = fd; - dhandles[dma_handle_count].len = len; - dhandles[dma_handle_count].used = 1; - dhandles[dma_handle_count].attr = attr; - dma_handle_count++; - } - } - pthread_mutex_unlock(&fdlist.mut); +int +remote_register_dma_handle_attr(int fd, uint32_t len, uint32_t attr) +{ + int nErr = AEE_SUCCESS, i; + int fd_found = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + if(attr && attr != FASTRPC_ATTR_NOMAP) { + FARF(ERROR, "Error: %s failed, unsupported attribute 0x%x", + __func__, attr); + return AEE_EBADPARM; + } + VERIFYC(fd >= 0, AEE_EBADPARM); + VERIFYC(len >= 0, AEE_EBADPARM); + + pthread_mutex_lock(&fdlist.mut); + for(i = 0; i < dma_handle_count; i++) { + if(dhandles[i].used && dhandles[i].fd == fd) { + /* If fd already present in handle list, then just + * update attribute only if its zero */ + if(!dhandles[i].attr) { + dhandles[i].attr = attr; + } + fd_found = 1; + dhandles[i].used++; + break; + } + } + pthread_mutex_unlock(&fdlist.mut); + + if(fd_found) { + return AEE_SUCCESS; + } + + pthread_mutex_lock(&fdlist.mut); + for(i = 0; i < dma_handle_count; i++) { + if(!dhandles[i].used) { + dhandles[i].fd = fd; + dhandles[i].len = len; + dhandles[i].used = 1; + dhandles[i].attr = attr; + break; + } + } + if(i == dma_handle_count) { + if(dma_handle_count >= MAX_DMA_HANDLES) { + FARF(ERROR, + "Error: %s: DMA handle list is already full " + "(count %d)", + __func__, dma_handle_count); + nErr = AEE_EINVHANDLE; + } else { + dhandles[dma_handle_count].fd = fd; + dhandles[dma_handle_count].len = len; + dhandles[dma_handle_count].used = 1; + dhandles[dma_handle_count].attr = attr; + dma_handle_count++; + } + } + pthread_mutex_unlock(&fdlist.mut); bail: - if (nErr) { - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, "Error 0x%x: %s failed for fd 0x%x, len %d, attr 0x%x", nErr, - __func__, fd, len, attr); - } - } - return nErr; + if(nErr) { + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed for fd 0x%x, len %d, attr " + "0x%x", + nErr, __func__, fd, len, attr); + } + } + return nErr; } -int remote_register_dma_handle(int fd, uint32_t len) { - return remote_register_dma_handle_attr(fd, len, 0); +int +remote_register_dma_handle(int fd, uint32_t len) +{ + return remote_register_dma_handle_attr(fd, len, 0); } -void unregister_dma_handle(int fd, uint32_t *len, uint32_t *attr) { - int i, last_used = 0; - - *len = 0; - *attr = 0; - - pthread_mutex_lock(&fdlist.mut); - for (i = 0; i < dma_handle_count; i++) { - if (dhandles[i].used) { - if (dhandles[i].fd == fd) { - dhandles[i].used--; - *len = dhandles[i].len; - *attr = dhandles[i].attr; - if (i == (dma_handle_count - 1) && !dhandles[i].used) { - dma_handle_count = last_used + 1; - } - break; - } else { - last_used = i; - } - } - } - pthread_mutex_unlock(&fdlist.mut); +void +unregister_dma_handle(int fd, uint32_t *len, uint32_t *attr) +{ + int i, last_used = 0; + + *len = 0; + *attr = 0; + + pthread_mutex_lock(&fdlist.mut); + for(i = 0; i < dma_handle_count; i++) { + if(dhandles[i].used) { + if(dhandles[i].fd == fd) { + dhandles[i].used--; + *len = dhandles[i].len; + *attr = dhandles[i].attr; + if(i == (dma_handle_count - 1) + && !dhandles[i].used) { + dma_handle_count = last_used + 1; + } + break; + } else { + last_used = i; + } + } + } + pthread_mutex_unlock(&fdlist.mut); } -int fdlist_fd_from_buf(void *buf, int bufLen, int *nova, void **base, int *attr, - int *ofd) { - QNode *pn; - int fd = -1; - pthread_mutex_lock(&fdlist.mut); - QLIST_FOR_ALL(&fdlist.ql, pn) { - if (fd != -1) { - break; - } else { - struct mem_to_fd *tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); - if (STD_BETWEEN(buf, tofd->buf, (unsigned long)tofd->buf + tofd->size)) { - if (STD_BETWEEN((unsigned long)buf + bufLen - 1, tofd->buf, - (unsigned long)tofd->buf + tofd->size)) { - fd = tofd->fd; - *nova = tofd->nova; - *base = tofd->buf; - *attr = tofd->attr; - } else { - pthread_mutex_unlock(&fdlist.mut); - FARF(ERROR, - "Error 0x%x: Mismatch in buffer address(%p) or size(%x) to the " - "registered FD(0x%x), address(%p) and size(%zu)\n", - AEE_EBADPARM, buf, bufLen, tofd->fd, tofd->buf, tofd->size); - return AEE_EBADPARM; - } - } - } - } - *ofd = fd; - pthread_mutex_unlock(&fdlist.mut); - return 0; +int +fdlist_fd_from_buf(void *buf, int bufLen, int *nova, void **base, int *attr, + int *ofd) +{ + QNode *pn; + int fd = -1; + pthread_mutex_lock(&fdlist.mut); + QLIST_FOR_ALL(&fdlist.ql, pn) + { + if(fd != -1) { + break; + } else { + struct mem_to_fd *tofd + = STD_RECOVER_REC(struct mem_to_fd, qn, pn); + if(STD_BETWEEN(buf, tofd->buf, + (unsigned long)tofd->buf + + tofd->size)) { + if(STD_BETWEEN((unsigned long)buf + bufLen - 1, + tofd->buf, + (unsigned long)tofd->buf + + tofd->size)) { + fd = tofd->fd; + *nova = tofd->nova; + *base = tofd->buf; + *attr = tofd->attr; + } else { + pthread_mutex_unlock(&fdlist.mut); + FARF(ERROR, + "Error 0x%x: Mismatch in buffer " + "address(%p) or size(%x) to the " + "registered FD(0x%x), " + "address(%p) and size(%zu)\n", + AEE_EBADPARM, buf, bufLen, + tofd->fd, tofd->buf, tofd->size); + return AEE_EBADPARM; + } + } + } + } + *ofd = fd; + pthread_mutex_unlock(&fdlist.mut); + return 0; } -int fastrpc_mmap(int domain, int fd, void *vaddr, int offset, size_t length, - enum fastrpc_map_flags flags) { - struct fastrpc_map map = {0}; - int nErr = 0, dev = -1, iocErr = 0, attrs = 0, ref = 0; - uint64_t vaddrout = 0; - struct static_map *mNode = NULL, *tNode = NULL; - QNode *pn, *pnn; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FARF(RUNTIME_RPC_HIGH, - "%s: domain %d fd %d addr %p length 0x%zx flags 0x%x offset 0x%x", - __func__, domain, fd, vaddr, length, flags, offset); - - /** - * Mask is applied on "flags" parameter to extract map control flags - * and SMMU mapping control attributes. Currently no attributes are - * suppported. It allows future extension of the fastrpc_mmap API - * for SMMU mapping control attributes. - */ - attrs = flags & (~FASTRPC_MAP_FLAGS_MASK); - flags = flags & FASTRPC_MAP_FLAGS_MASK; - VERIFYC(fd >= 0 && offset == 0 && attrs == 0, AEE_EBADPARM); - VERIFYC(flags >= 0 && flags < FASTRPC_MAP_MAX && - flags != FASTRPC_MAP_RESERVED, - AEE_EBADPARM); - - // Get domain and open session if not already open - if (domain == -1) { - domain = get_current_domain(); - } - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - VERIFYC(-1 != dev, AEE_ERPC); - - /* Search for mapping in current session static map list */ - pthread_mutex_lock(&smaplst[domain].mut); - QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) { - tNode = STD_RECOVER_REC(struct static_map, qn, pn); - if (tNode->map.fd == fd) { - break; - } - } - pthread_mutex_unlock(&smaplst[domain].mut); - - // Raise error if map found already - if (tNode) { - VERIFYM(tNode->map.fd != fd, AEE_EALREADY, "Error: Map already present."); - } - - // map not found, allocate memory for adding to static map list. - VERIFYC(NULL != (mNode = calloc(1, sizeof(*mNode))), AEE_ENOMEMORY); - - // Map buffer to DSP process and return limited errors to user - map.version = 0; - map.m.fd = fd; - map.m.offset = offset; - map.m.flags = flags; - map.m.vaddrin = (uintptr_t)vaddr; - map.m.length = (size_t)length; - map.m.attrs = attrs; - map.m.vaddrout = 0; - mNode->map = map.m; - iocErr = ioctl_mmap(dev, MEM_MAP, flags, attrs, fd, offset, length, - (uint64_t)vaddr, &vaddrout); - if (!iocErr) { - mNode->map.vaddrout = vaddrout; - mNode->refs = 1; - pthread_mutex_lock(&smaplst[domain].mut); - QList_AppendNode(&smaplst[domain].ql, &mNode->qn); - pthread_mutex_unlock(&smaplst[domain].mut); - mNode = NULL; - } else if (errno == ENOTTY || - iocErr == (int)(DSP_AEE_EOFFSET | AEE_EUNSUPPORTED)) { - nErr = AEE_EUNSUPPORTED; - goto bail; - } else { - nErr = AEE_EFAILED; - goto bail; - } +int +fastrpc_mmap(int domain, int fd, void *vaddr, int offset, size_t length, + enum fastrpc_map_flags flags) +{ + struct fastrpc_map map = { 0 }; + int nErr = 0, dev = -1, iocErr = 0, attrs = 0, ref = 0; + uint64_t vaddrout = 0; + struct static_map *mNode = NULL, *tNode = NULL; + QNode *pn, *pnn; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, + "%s: domain %d fd %d addr %p length 0x%zx flags 0x%x offset 0x%x", + __func__, domain, fd, vaddr, length, flags, offset); + + /** + * Mask is applied on "flags" parameter to extract map control flags + * and SMMU mapping control attributes. Currently no attributes are + * suppported. It allows future extension of the fastrpc_mmap API + * for SMMU mapping control attributes. + */ + attrs = flags & (~FASTRPC_MAP_FLAGS_MASK); + flags = flags & FASTRPC_MAP_FLAGS_MASK; + VERIFYC(fd >= 0 && offset == 0 && attrs == 0, AEE_EBADPARM); + VERIFYC(flags >= 0 && flags < FASTRPC_MAP_MAX + && flags != FASTRPC_MAP_RESERVED, + AEE_EBADPARM); + + // Get domain and open session if not already open + if(domain == -1) { + domain = get_current_domain(); + } + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + VERIFYC(-1 != dev, AEE_ERPC); + + /* Search for mapping in current session static map list */ + pthread_mutex_lock(&smaplst[domain].mut); + QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) + { + tNode = STD_RECOVER_REC(struct static_map, qn, pn); + if(tNode->map.fd == fd) { + break; + } + } + pthread_mutex_unlock(&smaplst[domain].mut); + + // Raise error if map found already + if(tNode) { + VERIFYM(tNode->map.fd != fd, AEE_EALREADY, + "Error: Map already present."); + } + + // map not found, allocate memory for adding to static map list. + VERIFYC(NULL != (mNode = calloc(1, sizeof(*mNode))), AEE_ENOMEMORY); + + // Map buffer to DSP process and return limited errors to user + map.version = 0; + map.m.fd = fd; + map.m.offset = offset; + map.m.flags = flags; + map.m.vaddrin = (uintptr_t)vaddr; + map.m.length = (size_t)length; + map.m.attrs = attrs; + map.m.vaddrout = 0; + mNode->map = map.m; + iocErr = ioctl_mmap(dev, MEM_MAP, flags, attrs, fd, offset, length, + (uint64_t)vaddr, &vaddrout); + if(!iocErr) { + mNode->map.vaddrout = vaddrout; + mNode->refs = 1; + pthread_mutex_lock(&smaplst[domain].mut); + QList_AppendNode(&smaplst[domain].ql, &mNode->qn); + pthread_mutex_unlock(&smaplst[domain].mut); + mNode = NULL; + } else if(errno == ENOTTY + || iocErr == (int)(DSP_AEE_EOFFSET | AEE_EUNSUPPORTED)) { + nErr = AEE_EUNSUPPORTED; + goto bail; + } else { + nErr = AEE_EFAILED; + goto bail; + } bail: - FASTRPC_PUT_REF(domain); - if (nErr) { - if (iocErr == 0) { - errno = 0; - } - FARF(ERROR, - "Error 0x%x: %s failed to map buffer fd %d, addr %p, length 0x%zx, " - "domain %d, flags 0x%x, ioctl ret 0x%x, errno %s", - nErr, __func__, fd, vaddr, length, domain, flags, iocErr, - strerror(errno)); - } - if (mNode) { - free(mNode); - mNode = NULL; - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr) { + if(iocErr == 0) { + errno = 0; + } + FARF(ERROR, + "Error 0x%x: %s failed to map buffer fd %d, addr %p, " + "length 0x%zx, " + "domain %d, flags 0x%x, ioctl ret 0x%x, errno %s", + nErr, __func__, fd, vaddr, length, domain, flags, iocErr, + strerror(errno)); + } + if(mNode) { + free(mNode); + mNode = NULL; + } + return nErr; } -int fastrpc_munmap(int domain, int fd, void *vaddr, size_t length) { - int nErr = 0, dev = -1, iocErr = 0, locked = 0, ref = 0; - struct static_map *mNode = NULL; - QNode *pn, *pnn; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FARF(RUNTIME_RPC_HIGH, "%s: domain %d fd %d vaddr %p length 0x%zx", __func__, - domain, fd, vaddr, length); - if (domain == -1) { - domain = get_current_domain(); - } - VERIFYC(fd >= 0 && IS_VALID_EFFECTIVE_DOMAIN_ID(domain), - AEE_EBADPARM); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - /** - * Search for mapping in current static map list using only file descriptor. - * Virtual address and length can be used for precise find with additional - * flags in future. - */ - pthread_mutex_lock(&smaplst[domain].mut); - locked = 1; - QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) { - mNode = STD_RECOVER_REC(struct static_map, qn, pn); - if (mNode->map.fd == fd) { - FARF(RUNTIME_RPC_HIGH, "%s: unmap found for fd %d domain %d", __func__, - fd, domain); - break; - } - } - VERIFYC(mNode && mNode->map.fd == fd, AEE_ENOSUCHMAP); - if (mNode->refs > 1) { - FARF(ERROR, "%s: Attempt to unmap FD %d with %d outstanding references", - __func__, fd, mNode->refs - 1); - nErr = AEE_EBADPARM; - goto bail; - } - mNode->refs = 0; - locked = 0; - pthread_mutex_unlock(&smaplst[domain].mut); - - iocErr = ioctl_munmap(dev, MEM_UNMAP, 0, 0, fd, mNode->map.length, - mNode->map.vaddrout); - pthread_mutex_lock(&smaplst[domain].mut); - locked = 1; - if (iocErr == 0) { - QNode_DequeueZ(&mNode->qn); - free(mNode); - mNode = NULL; - } else if (errno == ENOTTY || errno == EINVAL) { - nErr = AEE_EUNSUPPORTED; - } else { - mNode->refs = 1; - nErr = AEE_EFAILED; - } +int +fastrpc_munmap(int domain, int fd, void *vaddr, size_t length) +{ + int nErr = 0, dev = -1, iocErr = 0, locked = 0, ref = 0; + struct static_map *mNode = NULL; + QNode *pn, *pnn; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, "%s: domain %d fd %d vaddr %p length 0x%zx", + __func__, domain, fd, vaddr, length); + if(domain == -1) { + domain = get_current_domain(); + } + VERIFYC(fd >= 0 && IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + /** + * Search for mapping in current static map list using only file + * descriptor. Virtual address and length can be used for precise find + * with additional flags in future. + */ + pthread_mutex_lock(&smaplst[domain].mut); + locked = 1; + QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) + { + mNode = STD_RECOVER_REC(struct static_map, qn, pn); + if(mNode->map.fd == fd) { + FARF(RUNTIME_RPC_HIGH, + "%s: unmap found for fd %d domain %d", __func__, + fd, domain); + break; + } + } + VERIFYC(mNode && mNode->map.fd == fd, AEE_ENOSUCHMAP); + if(mNode->refs > 1) { + FARF(ERROR, + "%s: Attempt to unmap FD %d with %d outstanding " + "references", + __func__, fd, mNode->refs - 1); + nErr = AEE_EBADPARM; + goto bail; + } + mNode->refs = 0; + locked = 0; + pthread_mutex_unlock(&smaplst[domain].mut); + + iocErr = ioctl_munmap(dev, MEM_UNMAP, 0, 0, fd, mNode->map.length, + mNode->map.vaddrout); + pthread_mutex_lock(&smaplst[domain].mut); + locked = 1; + if(iocErr == 0) { + QNode_DequeueZ(&mNode->qn); + free(mNode); + mNode = NULL; + } else if(errno == ENOTTY || errno == EINVAL) { + nErr = AEE_EUNSUPPORTED; + } else { + mNode->refs = 1; + nErr = AEE_EFAILED; + } bail: - if (locked == 1) { - locked = 0; - pthread_mutex_unlock(&smaplst[domain].mut); - } - FASTRPC_PUT_REF(domain); - if (nErr) { - if (iocErr == 0) { - errno = 0; - } - FARF(ERROR, - "Error 0x%x: %s failed fd %d, vaddr %p, length 0x%zx, domain %d, " - "ioctl ret 0x%x, errno %s", - nErr, __func__, fd, vaddr, length, domain, iocErr, strerror(errno)); - } - return nErr; + if(locked == 1) { + locked = 0; + pthread_mutex_unlock(&smaplst[domain].mut); + } + FASTRPC_PUT_REF(domain); + if(nErr) { + if(iocErr == 0) { + errno = 0; + } + FARF(ERROR, + "Error 0x%x: %s failed fd %d, vaddr %p, length 0x%zx, " + "domain %d, " + "ioctl ret 0x%x, errno %s", + nErr, __func__, fd, vaddr, length, domain, iocErr, + strerror(errno)); + } + return nErr; } -int remote_mem_map(int domain, int fd, int flags, uint64_t vaddr, size_t size, - uint64_t *raddr) { - int nErr = 0; - int dev = -1, ref = 0; - uint64_t vaddrout = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - FARF(RUNTIME_RPC_HIGH, - "%s: domain %d fd %d addr 0x%llx size 0x%zx flags 0x%x", __func__, - domain, fd, vaddr, size, flags); - - VERIFYC(fd >= 0, AEE_EBADPARM); - VERIFYC(size >= 0, AEE_EBADPARM); - VERIFYC(flags >= 0 && flags < REMOTE_MAP_MAX_FLAG && raddr != NULL, - AEE_EBADPARM); - if (domain == -1) { - domain = get_current_domain(); - } - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - - nErr = ioctl_mmap(dev, MMAP_64, flags, 0, fd, 0, size, vaddr, &vaddrout); - *raddr = vaddrout; +int +remote_mem_map(int domain, int fd, int flags, uint64_t vaddr, size_t size, + uint64_t *raddr) +{ + int nErr = 0; + int dev = -1, ref = 0; + uint64_t vaddrout = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + FARF(RUNTIME_RPC_HIGH, + "%s: domain %d fd %d addr 0x%llx size 0x%zx flags 0x%x", __func__, + domain, fd, vaddr, size, flags); + + VERIFYC(fd >= 0, AEE_EBADPARM); + VERIFYC(size >= 0, AEE_EBADPARM); + VERIFYC(flags >= 0 && flags < REMOTE_MAP_MAX_FLAG && raddr != NULL, + AEE_EBADPARM); + if(domain == -1) { + domain = get_current_domain(); + } + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + + nErr = ioctl_mmap(dev, MMAP_64, flags, 0, fd, 0, size, vaddr, + &vaddrout); + *raddr = vaddrout; bail: - FASTRPC_PUT_REF(domain); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: %s failed to map buffer fd %d addr 0x%llx size 0x%zx " - "domain %d flags %d errno %s", - nErr, __func__, fd, vaddr, size, domain, flags, strerror(errno)); - } - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed to map buffer fd %d addr " + "0x%llx size 0x%zx " + "domain %d flags %d errno %s", + nErr, __func__, fd, vaddr, size, domain, flags, + strerror(errno)); + } + } + return nErr; } -int remote_mem_unmap(int domain, uint64_t raddr, size_t size) { - int nErr = 0, dev = -1, ref = 0; +int +remote_mem_unmap(int domain, uint64_t raddr, size_t size) +{ + int nErr = 0, dev = -1, ref = 0; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - VERIFYC(size >= 0, AEE_EBADPARM); - VERIFYC(raddr != 0, AEE_EBADPARM); - FARF(RUNTIME_RPC_HIGH, "%s: domain %d addr 0x%llx size 0x%zx", __func__, - domain, raddr, size); - if (domain == -1) { - domain = get_current_domain(); - } - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + VERIFYC(size >= 0, AEE_EBADPARM); + VERIFYC(raddr != 0, AEE_EBADPARM); + FARF(RUNTIME_RPC_HIGH, "%s: domain %d addr 0x%llx size 0x%zx", + __func__, domain, raddr, size); + if(domain == -1) { + domain = get_current_domain(); + } + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - nErr = ioctl_munmap(dev, MUNMAP_64, 0, 0, -1, size, raddr); + nErr = ioctl_munmap(dev, MUNMAP_64, 0, 0, -1, size, raddr); bail: - FASTRPC_PUT_REF(domain); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - if (0 == check_rpc_error(nErr)) { - FARF(ERROR, - "Error 0x%x: %s failed to unmap buffer addr 0x%llx size 0x%zx " - "domain %d errno %s", - nErr, __func__, raddr, size, domain, strerror(errno)); - } - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + if(0 == check_rpc_error(nErr)) { + FARF(ERROR, + "Error 0x%x: %s failed to unmap buffer addr " + "0x%llx size 0x%zx " + "domain %d errno %s", + nErr, __func__, raddr, size, domain, + strerror(errno)); + } + } + return nErr; } -int remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, - int64_t size, uint64_t *vaddrout) { - int dev, domain = DEFAULT_DOMAIN_ID, nErr = AEE_SUCCESS, ref = 0; - uint64_t vaout = 0; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - domain = get_current_domain(); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADDOMAIN); - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - VERIFYM(-1 != dev, AEE_ERPC, "Invalid device\n"); - nErr = ioctl_mmap(dev, MMAP_64, flags, 0, fd, 0, size, vaddrin, &vaout); - *vaddrout = vaout; +int +remote_mmap64_internal(int fd, uint32_t flags, uint64_t vaddrin, int64_t size, + uint64_t *vaddrout) +{ + int dev, domain = DEFAULT_DOMAIN_ID, nErr = AEE_SUCCESS, ref = 0; + uint64_t vaout = 0; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + domain = get_current_domain(); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADDOMAIN); + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + VERIFYM(-1 != dev, AEE_ERPC, "Invalid device\n"); + nErr + = ioctl_mmap(dev, MMAP_64, flags, 0, fd, 0, size, vaddrin, &vaout); + *vaddrout = vaout; bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - nErr = convert_kernel_to_user_error(nErr, errno); - FARF(ERROR, - "Error 0x%x: %s failed for fd 0x%x of size %lld (flags 0x%x, vaddrin " - "0x%llx) errno %s\n", - nErr, __func__, fd, size, flags, vaddrin, strerror(errno)); - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + nErr = convert_kernel_to_user_error(nErr, errno); + FARF(ERROR, + "Error 0x%x: %s failed for fd 0x%x of size %lld (flags " + "0x%x, vaddrin " + "0x%llx) errno %s\n", + nErr, __func__, fd, size, flags, vaddrin, + strerror(errno)); + } + return nErr; } -int remote_mmap64(int fd, uint32_t flags, uint64_t vaddrin, int64_t size, - uint64_t *vaddrout) { - int nErr = AEE_SUCCESS, log = 1; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - - if (flags != 0) { - nErr = AEE_EBADPARM; - goto bail; - } - VERIFYC(size >= 0, AEE_EBADPARM); - VERIFYC(fd >= 0, AEE_EBADPARM); - VERIFYC(NULL != vaddrout, AEE_EBADPARM); - nErr = remote_mmap64_internal(fd, flags, vaddrin, size, vaddrout); - if (nErr == AEE_EBADDOMAIN) - nErr = AEE_ERPC; // override error code for user - log = 0; // so that we wont print error message twice +int +remote_mmap64(int fd, uint32_t flags, uint64_t vaddrin, int64_t size, + uint64_t *vaddrout) +{ + int nErr = AEE_SUCCESS, log = 1; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + + if(flags != 0) { + nErr = AEE_EBADPARM; + goto bail; + } + VERIFYC(size >= 0, AEE_EBADPARM); + VERIFYC(fd >= 0, AEE_EBADPARM); + VERIFYC(NULL != vaddrout, AEE_EBADPARM); + nErr = remote_mmap64_internal(fd, flags, vaddrin, size, vaddrout); + if(nErr == AEE_EBADDOMAIN) + nErr = AEE_ERPC; // override error code for user + log = 0; // so that we wont print error message twice bail: - if ((nErr != AEE_SUCCESS) && (log == 1)) { - FARF(ERROR, - "Error 0x%x: %s failed for fd 0x%x of size %lld (flags 0x%x, vaddrin " - "0x%llx)\n", - nErr, __func__, fd, size, flags, vaddrin); - } - return nErr; + if((nErr != AEE_SUCCESS) && (log == 1)) { + FARF(ERROR, + "Error 0x%x: %s failed for fd 0x%x of size %lld (flags " + "0x%x, vaddrin " + "0x%llx)\n", + nErr, __func__, fd, size, flags, vaddrin); + } + return nErr; } -int remote_mmap(int fd, uint32_t flags, uint32_t vaddrin, int size, - uint32_t *vaddrout) { - uint64_t vaddrout_64 = 0; - int nErr = 0; - - VERIFYC(NULL != vaddrout, AEE_EBADPARM); - nErr = - remote_mmap64(fd, flags, (uintptr_t)vaddrin, (int64_t)size, &vaddrout_64); - *vaddrout = (uint32_t)vaddrout_64; +int +remote_mmap(int fd, uint32_t flags, uint32_t vaddrin, int size, + uint32_t *vaddrout) +{ + uint64_t vaddrout_64 = 0; + int nErr = 0; + + VERIFYC(NULL != vaddrout, AEE_EBADPARM); + nErr = remote_mmap64(fd, flags, (uintptr_t)vaddrin, (int64_t)size, + &vaddrout_64); + *vaddrout = (uint32_t)vaddrout_64; bail: - return nErr; + return nErr; } -int remote_munmap64(uint64_t vaddrout, int64_t size) { - int dev, domain = DEFAULT_DOMAIN_ID, nErr = AEE_SUCCESS, ref = 0; +int +remote_munmap64(uint64_t vaddrout, int64_t size) +{ + int dev, domain = DEFAULT_DOMAIN_ID, nErr = AEE_SUCCESS, ref = 0; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_init_once())); - domain = get_current_domain(); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_ERPC); + domain = get_current_domain(); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_ERPC); - /* Don't open session in unmap. Return success if device already closed */ - FASTRPC_GET_REF(domain); - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - nErr = ioctl_munmap(dev, MUNMAP_64, 0, 0, -1, size, vaddrout); + /* Don't open session in unmap. Return success if device already closed + */ + FASTRPC_GET_REF(domain); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + nErr = ioctl_munmap(dev, MUNMAP_64, 0, 0, -1, size, vaddrout); bail: - FASTRPC_PUT_REF(domain); - if (nErr != AEE_SUCCESS) { - nErr = convert_kernel_to_user_error(nErr, errno); - FARF(ERROR, - "Error 0x%x: %s failed for size %lld (vaddrout 0x%llx) errno %s\n", - nErr, __func__, size, vaddrout, strerror(errno)); - } - return nErr; + FASTRPC_PUT_REF(domain); + if(nErr != AEE_SUCCESS) { + nErr = convert_kernel_to_user_error(nErr, errno); + FARF(ERROR, + "Error 0x%x: %s failed for size %lld (vaddrout 0x%llx) " + "errno %s\n", + nErr, __func__, size, vaddrout, strerror(errno)); + } + return nErr; } -int remote_munmap(uint32_t vaddrout, int size) { - return remote_munmap64((uintptr_t)vaddrout, (int64_t)size); +int +remote_munmap(uint32_t vaddrout, int size) +{ + return remote_munmap64((uintptr_t)vaddrout, (int64_t)size); } -static int fastrpc_unmap_fd(void *buf, size_t size, int fd, int attr) { - int nErr = 0; - int ii, dev = -1; - - FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) { - nErr = fastrpc_session_get(ii); - if(!nErr) - continue; - nErr = fastrpc_session_dev(ii, &dev); - if(!nErr) { - fastrpc_session_put(ii); - continue; - } - nErr = ioctl_munmap(dev, MUNMAP_FD, attr, buf, fd, size, 0); - if (nErr) - FARF(RUNTIME_RPC_LOW, - "unmap_fd: device found %d for domain %d returned %d", dev, ii, - nErr); - fastrpc_session_put(ii); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for size %zu fd %d errno %s\n", nErr, - __func__, size, fd, strerror(errno)); - } - return nErr; +static int +fastrpc_unmap_fd(void *buf, size_t size, int fd, int attr) +{ + int nErr = 0; + int ii, dev = -1; + + FOR_EACH_EFFECTIVE_DOMAIN_ID(ii) + { + nErr = fastrpc_session_get(ii); + if(!nErr) + continue; + nErr = fastrpc_session_dev(ii, &dev); + if(!nErr) { + fastrpc_session_put(ii); + continue; + } + nErr = ioctl_munmap(dev, MUNMAP_FD, attr, buf, fd, size, 0); + if(nErr) + FARF(RUNTIME_RPC_LOW, + "unmap_fd: device found %d for domain %d " + "returned %d", + dev, ii, nErr); + fastrpc_session_put(ii); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for size %zu fd %d errno %s\n", + nErr, __func__, size, fd, strerror(errno)); + } + return nErr; } /** @@ -814,28 +913,33 @@ static int fastrpc_unmap_fd(void *buf, size_t size, int fd, int attr) { * * Returns : None */ -static __inline void try_map_buffer(struct mem_to_fd *tofd) { - int nErr = 0, domain = 0, errcnt = 0; - - FARF(RUNTIME_RPC_HIGH, "%s: fd %d", __func__, tofd->fd); - - /** - * Tries to create static mapping on remote process of all open sessions. - * Ignore errors in case of failure - */ - FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) { - nErr = fastrpc_mmap(domain, tofd->fd, tofd->buf, 0, tofd->size, - FASTRPC_MAP_STATIC); - if (!nErr) { - tofd->mapped[domain] = true; - } else { - errcnt++; - } - } - if (errcnt) { - FARF(ERROR, "Error 0x%x: %s failed for fd %d buf %p size 0x%zx errcnt %d", - nErr, __func__, tofd->fd, tofd->buf, tofd->size, errcnt); - } +static __inline void +try_map_buffer(struct mem_to_fd *tofd) +{ + int nErr = 0, domain = 0, errcnt = 0; + + FARF(RUNTIME_RPC_HIGH, "%s: fd %d", __func__, tofd->fd); + + /** + * Tries to create static mapping on remote process of all open + * sessions. Ignore errors in case of failure + */ + FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) + { + nErr = fastrpc_mmap(domain, tofd->fd, tofd->buf, 0, tofd->size, + FASTRPC_MAP_STATIC); + if(!nErr) { + tofd->mapped[domain] = true; + } else { + errcnt++; + } + } + if(errcnt) { + FARF(ERROR, + "Error 0x%x: %s failed for fd %d buf %p size 0x%zx " + "errcnt %d", + nErr, __func__, tofd->fd, tofd->buf, tofd->size, errcnt); + } } /** @@ -846,160 +950,179 @@ static __inline void try_map_buffer(struct mem_to_fd *tofd) { * * Returns : None */ -static __inline int try_unmap_buffer(struct mem_to_fd *tofd) { - int nErr = 0, domain = 0, errcnt = 0; - - FARF(RUNTIME_RPC_HIGH, "%s: fd %d", __func__, tofd->fd); - - /* Remove static mapping of a buffer for all domains */ - FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) { - if (tofd->mapped[domain] == false) { - continue; - } - nErr = fastrpc_munmap(domain, tofd->fd, tofd->buf, tofd->size); - if (!nErr) { - tofd->mapped[domain] = false; - } else { - errcnt++; - //@TODO: Better way to handle error? probably prevent same FD getting - //re-used with FastRPC library. - } - } - if (errcnt) { - FARF(ERROR, "Error 0x%x: %s failed for fd %d buf %p size 0x%zx errcnt %d", - nErr, __func__, tofd->fd, tofd->buf, tofd->size, errcnt); - } - return errcnt; +static __inline int +try_unmap_buffer(struct mem_to_fd *tofd) +{ + int nErr = 0, domain = 0, errcnt = 0; + + FARF(RUNTIME_RPC_HIGH, "%s: fd %d", __func__, tofd->fd); + + /* Remove static mapping of a buffer for all domains */ + FOR_EACH_EFFECTIVE_DOMAIN_ID(domain) + { + if(tofd->mapped[domain] == false) { + continue; + } + nErr = fastrpc_munmap(domain, tofd->fd, tofd->buf, tofd->size); + if(!nErr) { + tofd->mapped[domain] = false; + } else { + errcnt++; + //@TODO: Better way to handle error? probably prevent + // same FD getting re-used with FastRPC library. + } + } + if(errcnt) { + FARF(ERROR, + "Error 0x%x: %s failed for fd %d buf %p size 0x%zx " + "errcnt %d", + nErr, __func__, tofd->fd, tofd->buf, tofd->size, errcnt); + } + return errcnt; } -int fastrpc_mem_open(int domain) { - int nErr = 0; - QNode *pn, *pnn; - struct mem_to_fd *tofd = NULL; - - /** - * Initialize fastrpc session specific informaiton of the fastrpc_mem module - */ - FARF(RUNTIME_RPC_HIGH, "%s for domain %d", __func__, domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - - /* Map buffers with TRY_MAP_STATIC attribute that were allocated - * and registered before a session was opened on a given domain. - */ - pthread_mutex_lock(&fdlist.mut); - QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) { - tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); - if (tofd->attr & FASTRPC_ATTR_TRY_MAP_STATIC && - tofd->mapped[domain] == false) { - nErr = fastrpc_mmap(domain, tofd->fd, tofd->buf, 0, tofd->size, - FASTRPC_MAP_STATIC); - if (!nErr) { - tofd->mapped[domain] = true; - } - } - } - nErr = 0; // Try mapping is optional. Ignore error - pthread_mutex_unlock(&fdlist.mut); +int +fastrpc_mem_open(int domain) +{ + int nErr = 0; + QNode *pn, *pnn; + struct mem_to_fd *tofd = NULL; + + /** + * Initialize fastrpc session specific informaiton of the fastrpc_mem + * module + */ + FARF(RUNTIME_RPC_HIGH, "%s for domain %d", __func__, domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + + /* Map buffers with TRY_MAP_STATIC attribute that were allocated + * and registered before a session was opened on a given domain. + */ + pthread_mutex_lock(&fdlist.mut); + QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) + { + tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); + if(tofd->attr & FASTRPC_ATTR_TRY_MAP_STATIC + && tofd->mapped[domain] == false) { + nErr = fastrpc_mmap(domain, tofd->fd, tofd->buf, 0, + tofd->size, FASTRPC_MAP_STATIC); + if(!nErr) { + tofd->mapped[domain] = true; + } + } + } + nErr = 0; // Try mapping is optional. Ignore error + pthread_mutex_unlock(&fdlist.mut); bail: - if (nErr) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, __func__, domain); - } - return nErr; + if(nErr) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, + __func__, domain); + } + return nErr; } -int fastrpc_mem_close(int domain) { - int nErr = 0; - struct static_map *mNode; - struct mem_to_fd *tofd = NULL; - QNode *pn, *pnn; - - FARF(RUNTIME_RPC_HIGH, "%s for domain %d", __func__, domain); - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - - /** - * Destroy fastrpc session specific information of the fastrpc_mem module. - * Remove all static mappings of a session - */ - pthread_mutex_lock(&smaplst[domain].mut); - do { - mNode = NULL; - QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) { - mNode = STD_RECOVER_REC(struct static_map, qn, pn); - QNode_DequeueZ(&mNode->qn); - free(mNode); - mNode = NULL; - } - } while (mNode); - pthread_mutex_unlock(&smaplst[domain].mut); - - // Remove mapping status of static buffers - pthread_mutex_lock(&fdlist.mut); - QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) { - tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); - /* This function is called only when remote session is being closed. - * So no need to do "fastrpc_munmap" here. - */ - if (tofd->mapped[domain]) { - tofd->mapped[domain] = false; - } - } - pthread_mutex_unlock(&fdlist.mut); +int +fastrpc_mem_close(int domain) +{ + int nErr = 0; + struct static_map *mNode; + struct mem_to_fd *tofd = NULL; + QNode *pn, *pnn; + + FARF(RUNTIME_RPC_HIGH, "%s for domain %d", __func__, domain); + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + + /** + * Destroy fastrpc session specific information of the fastrpc_mem + * module. Remove all static mappings of a session + */ + pthread_mutex_lock(&smaplst[domain].mut); + do { + mNode = NULL; + QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) + { + mNode = STD_RECOVER_REC(struct static_map, qn, pn); + QNode_DequeueZ(&mNode->qn); + free(mNode); + mNode = NULL; + } + } while(mNode); + pthread_mutex_unlock(&smaplst[domain].mut); + + // Remove mapping status of static buffers + pthread_mutex_lock(&fdlist.mut); + QLIST_NEXTSAFE_FOR_ALL(&fdlist.ql, pn, pnn) + { + tofd = STD_RECOVER_REC(struct mem_to_fd, qn, pn); + /* This function is called only when remote session is being + * closed. So no need to do "fastrpc_munmap" here. + */ + if(tofd->mapped[domain]) { + tofd->mapped[domain] = false; + } + } + pthread_mutex_unlock(&fdlist.mut); bail: - return nErr; + return nErr; } -int fastrpc_buffer_ref(int domain, int fd, int ref, void **va, size_t *size) { - - int nErr = 0; - struct static_map *map = NULL; - QNode *pn, *pnn; - - if (!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { - FARF(ERROR, "%s: invalid domain %d", __func__, domain); - return AEE_EBADPARM; - } - pthread_mutex_lock(&smaplst[domain].mut); - - // Find buffer in the domain's static mapping list - QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) { - struct static_map *m = STD_RECOVER_REC(struct static_map, qn, pn); - if (m->map.fd == fd) { - map = m; - break; - } - } - VERIFYC(map != NULL, AEE_ENOSUCHMAP); - VERIFYC(map->refs > 0, AEE_ERPC); - - // Populate output - if (va) { - *va = (void *)map->map.vaddrin; - } - if (size) { - *size = map->map.length; - } - - // Handle refcount - if (ref == 1) { - map->refs++; - } else if (ref == -1) { - if (map->refs == 1) { - FARF(ERROR, - "%s: Attempting to remove last reference to buffer %d on domain %d", - __func__, fd, domain); - nErr = AEE_EBADPARM; - goto bail; - } - map->refs--; - } else { - VERIFYC(ref == 0, AEE_ERPC); - } +int +fastrpc_buffer_ref(int domain, int fd, int ref, void **va, size_t *size) +{ + + int nErr = 0; + struct static_map *map = NULL; + QNode *pn, *pnn; + + if(!IS_VALID_EFFECTIVE_DOMAIN_ID(domain)) { + FARF(ERROR, "%s: invalid domain %d", __func__, domain); + return AEE_EBADPARM; + } + pthread_mutex_lock(&smaplst[domain].mut); + + // Find buffer in the domain's static mapping list + QLIST_NEXTSAFE_FOR_ALL(&smaplst[domain].ql, pn, pnn) + { + struct static_map *m + = STD_RECOVER_REC(struct static_map, qn, pn); + if(m->map.fd == fd) { + map = m; + break; + } + } + VERIFYC(map != NULL, AEE_ENOSUCHMAP); + VERIFYC(map->refs > 0, AEE_ERPC); + + // Populate output + if(va) { + *va = (void *)map->map.vaddrin; + } + if(size) { + *size = map->map.length; + } + + // Handle refcount + if(ref == 1) { + map->refs++; + } else if(ref == -1) { + if(map->refs == 1) { + FARF(ERROR, + "%s: Attempting to remove last reference to " + "buffer %d on domain %d", + __func__, fd, domain); + nErr = AEE_EBADPARM; + goto bail; + } + map->refs--; + } else { + VERIFYC(ref == 0, AEE_ERPC); + } bail: - pthread_mutex_unlock(&smaplst[domain].mut); - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed (domain %d, fd %d, ref %d)", nErr, - __func__, domain, fd, ref); - } - return nErr; + pthread_mutex_unlock(&smaplst[domain].mut); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed (domain %d, fd %d, ref %d)", + nErr, __func__, domain, fd, ref); + } + return nErr; } diff --git a/src/fastrpc_notif.c b/src/fastrpc_notif.c index be4bde6a..5244b7a8 100644 --- a/src/fastrpc_notif.c +++ b/src/fastrpc_notif.c @@ -25,25 +25,25 @@ #include "AEEstd.h" #include "HAP_farf.h" #include "fastrpc_common.h" +#include "fastrpc_hash_table.h" #include "fastrpc_notif.h" #include "platform_libs.h" #include "verify.h" -#include "fastrpc_hash_table.h" typedef struct { - pthread_t thread; - int init_done; - int deinit_started; - ADD_DOMAIN_HASH(); + pthread_t thread; + int init_done; + int deinit_started; + ADD_DOMAIN_HASH(); } notif_config; // Fastrpc client notification request node to be queued to struct fastrpc_notif { - QNode qn; - remote_rpc_notif_register_t notif; + QNode qn; + remote_rpc_notif_register_t notif; }; -struct other_handle_list { // For non-domain and reverse handle list +struct other_handle_list { // For non-domain and reverse handle list QList ql; }; @@ -56,202 +56,239 @@ void fastrpc_cleanup_notif_list(); DECLARE_HASH_TABLE(fastrpc_notif, notif_config); -static void *notif_fastrpc_thread(void *arg) { - notif_config *me = (notif_config *)arg; - int nErr = AEE_SUCCESS, domain = me->domain; - - do { - nErr = get_remote_notif_response(domain); - if (nErr) - goto bail; - } while (1); +static void * +notif_fastrpc_thread(void *arg) +{ + notif_config *me = (notif_config *)arg; + int nErr = AEE_SUCCESS, domain = me->domain; + + do { + nErr = get_remote_notif_response(domain); + if(nErr) + goto bail; + } while(1); bail: - dlerror(); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s FastRPC notification worker thread exited " - "for domain %d (errno %s), notif_domain_deinit started %d", - nErr, __func__, domain, strerror(errno), me->deinit_started); - } - return (void *)(uintptr_t)nErr; + dlerror(); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: %s FastRPC notification worker thread exited " + "for domain %d (errno %s), notif_domain_deinit started %d", + nErr, __func__, domain, strerror(errno), + me->deinit_started); + } + return (void *)(uintptr_t)nErr; } /* This function gets called in the thread context when thread has been * interrupted with SIGUSR1 */ -void notif_thread_exit_handler(int sig) { - FARF(ALWAYS, "Notification FastRPC worker thread exiting with signal %d\n", - sig); - pthread_exit(0); +void +notif_thread_exit_handler(int sig) +{ + FARF(ALWAYS, + "Notification FastRPC worker thread exiting with signal %d\n", + sig); + pthread_exit(0); } -void fastrpc_notif_init() { - HASH_TABLE_INIT(notif_config); - QList_Ctor(¬if_list.ql); - pthread_mutex_init(&update_notif_list_mut, 0); +void +fastrpc_notif_init() +{ + HASH_TABLE_INIT(notif_config); + QList_Ctor(¬if_list.ql); + pthread_mutex_init(&update_notif_list_mut, 0); } -void fastrpc_notif_deinit() { - HASH_TABLE_CLEANUP(notif_config); - fastrpc_cleanup_notif_list(); - pthread_mutex_destroy(&update_notif_list_mut); +void +fastrpc_notif_deinit() +{ + HASH_TABLE_CLEANUP(notif_config); + fastrpc_cleanup_notif_list(); + pthread_mutex_destroy(&update_notif_list_mut); } -void fastrpc_notif_domain_deinit(int domain) { - notif_config *me = NULL; - int err = 0; - - GET_HASH_NODE(notif_config, domain, me); - if (!me) { - FARF(RUNTIME_RPC_HIGH, "Warning: %s: unable to find hash-node for domain %d", - __func__, domain); - return; - } - if (me->thread) { - FARF(ALWAYS, "%s: Waiting for FastRPC notification worker thread to join", - __func__); - me->deinit_started = 1; - err = fastrpc_exit_notif_thread(domain); - if (err) { - pthread_kill(me->thread, SIGUSR1); - } - pthread_join(me->thread, 0); - me->thread = 0; - FARF(ALWAYS, "%s: Fastrpc notification worker thread joined", __func__); - } - me->init_done = 0; - return; +void +fastrpc_notif_domain_deinit(int domain) +{ + notif_config *me = NULL; + int err = 0; + + GET_HASH_NODE(notif_config, domain, me); + if(!me) { + FARF(RUNTIME_RPC_HIGH, + "Warning: %s: unable to find hash-node for domain %d", + __func__, domain); + return; + } + if(me->thread) { + FARF(ALWAYS, + "%s: Waiting for FastRPC notification worker thread to " + "join", + __func__); + me->deinit_started = 1; + err = fastrpc_exit_notif_thread(domain); + if(err) { + pthread_kill(me->thread, SIGUSR1); + } + pthread_join(me->thread, 0); + me->thread = 0; + FARF(ALWAYS, "%s: Fastrpc notification worker thread joined", + __func__); + } + me->init_done = 0; + return; } -int fastrpc_notif_domain_init(int domain) { - notif_config *me = NULL; - int nErr = AEE_SUCCESS; - struct sigaction siga; - - GET_HASH_NODE(notif_config, domain, me); - if (!me) { - ALLOC_AND_ADD_NEW_NODE_TO_TABLE(notif_config, domain, me); - } - if (me->init_done) { - goto bail; - } - me->thread = 0; - VERIFY(AEE_SUCCESS == - (nErr = pthread_create(&me->thread, 0, notif_fastrpc_thread, - (void *)me))); - // Register signal handler to interrupt thread, while thread is waiting in - // kernel - memset(&siga, 0, sizeof(siga)); - siga.sa_flags = 0; - siga.sa_handler = notif_thread_exit_handler; - VERIFY(AEE_SUCCESS == (nErr = sigaction(SIGUSR1, &siga, NULL))); - me->init_done = 1; - me->deinit_started = 0; - FARF(ALWAYS, "%s: FastRPC notification worker thread launched\n", __func__); +int +fastrpc_notif_domain_init(int domain) +{ + notif_config *me = NULL; + int nErr = AEE_SUCCESS; + struct sigaction siga; + + GET_HASH_NODE(notif_config, domain, me); + if(!me) { + ALLOC_AND_ADD_NEW_NODE_TO_TABLE(notif_config, domain, me); + } + if(me->init_done) { + goto bail; + } + me->thread = 0; + VERIFY(AEE_SUCCESS + == (nErr = pthread_create(&me->thread, 0, notif_fastrpc_thread, + (void *)me))); + // Register signal handler to interrupt thread, while thread is waiting + // in kernel + memset(&siga, 0, sizeof(siga)); + siga.sa_flags = 0; + siga.sa_handler = notif_thread_exit_handler; + VERIFY(AEE_SUCCESS == (nErr = sigaction(SIGUSR1, &siga, NULL))); + me->init_done = 1; + me->deinit_started = 0; + FARF(ALWAYS, "%s: FastRPC notification worker thread launched\n", + __func__); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s failed (errno %s)\n", nErr, __func__, - strerror(errno)); - fastrpc_notif_domain_deinit(domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s failed (errno %s)\n", nErr, + __func__, strerror(errno)); + fastrpc_notif_domain_deinit(domain); + } + return nErr; } -int fastrpc_notif_register(int domain, - struct remote_rpc_notif_register *notif) { - int nErr = AEE_SUCCESS; - struct fastrpc_notif *lnotif = NULL; +int +fastrpc_notif_register(int domain, struct remote_rpc_notif_register *notif) +{ + int nErr = AEE_SUCCESS; + struct fastrpc_notif *lnotif = NULL; - // Initialize fastrpc structures, if in case this is the first call to library - VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); + // Initialize fastrpc structures, if in case this is the first call to + // library + VERIFYC(IS_VALID_EFFECTIVE_DOMAIN_ID(domain), AEE_EBADPARM); - // Allocate client notification request node - VERIFYC(NULL != (lnotif = calloc(1, sizeof(struct fastrpc_notif))), - AEE_ENOMEMORY); - QNode_CtorZ(&lnotif->qn); - memcpy(&lnotif->notif, notif, sizeof(remote_rpc_notif_register_t)); + // Allocate client notification request node + VERIFYC(NULL != (lnotif = calloc(1, sizeof(struct fastrpc_notif))), + AEE_ENOMEMORY); + QNode_CtorZ(&lnotif->qn); + memcpy(&lnotif->notif, notif, sizeof(remote_rpc_notif_register_t)); - // Add client node to notification list - pthread_mutex_lock(&update_notif_list_mut); - QList_AppendNode(¬if_list.ql, &lnotif->qn); - pthread_mutex_unlock(&update_notif_list_mut); + // Add client node to notification list + pthread_mutex_lock(&update_notif_list_mut); + QList_AppendNode(¬if_list.ql, &lnotif->qn); + pthread_mutex_unlock(&update_notif_list_mut); bail: - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, __func__, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for domain %d", nErr, + __func__, domain); + } + return nErr; } /* Internal function to notify clients, if there is any notification request */ -static int fastrpc_notify_status(int domain, int session, int status) { - QNode *pn, *pnn; - struct fastrpc_notif *lnotif = NULL; - int nErr = AEE_SUCCESS; - - pthread_mutex_lock(&update_notif_list_mut); - if (!QList_IsEmpty(¬if_list.ql)) { - QLIST_NEXTSAFE_FOR_ALL(¬if_list.ql, pn, pnn) { - lnotif = STD_RECOVER_REC(struct fastrpc_notif, qn, pn); - if (lnotif && (lnotif->notif.domain == domain)) { - lnotif->notif.notifier_fn(lnotif->notif.context, domain, session, - status); - } - } - } - pthread_mutex_unlock(&update_notif_list_mut); - return nErr; +static int +fastrpc_notify_status(int domain, int session, int status) +{ + QNode *pn, *pnn; + struct fastrpc_notif *lnotif = NULL; + int nErr = AEE_SUCCESS; + + pthread_mutex_lock(&update_notif_list_mut); + if(!QList_IsEmpty(¬if_list.ql)) { + QLIST_NEXTSAFE_FOR_ALL(¬if_list.ql, pn, pnn) + { + lnotif = STD_RECOVER_REC(struct fastrpc_notif, qn, pn); + if(lnotif && (lnotif->notif.domain == domain)) { + lnotif->notif.notifier_fn( + lnotif->notif.context, domain, session, + status); + } + } + } + pthread_mutex_unlock(&update_notif_list_mut); + return nErr; } -void fastrpc_cleanup_notif_list() { - QNode *pn = NULL, *pnn = NULL; - struct fastrpc_notif *lnotif = NULL; - - pthread_mutex_lock(&update_notif_list_mut); - if (!QList_IsEmpty(¬if_list.ql)) { - QLIST_NEXTSAFE_FOR_ALL(¬if_list.ql, pn, pnn) { - lnotif = STD_RECOVER_REC(struct fastrpc_notif, qn, pn); - if (lnotif) { - free(lnotif); - lnotif = NULL; - } - } - } - pthread_mutex_unlock(&update_notif_list_mut); +void +fastrpc_cleanup_notif_list() +{ + QNode *pn = NULL, *pnn = NULL; + struct fastrpc_notif *lnotif = NULL; + + pthread_mutex_lock(&update_notif_list_mut); + if(!QList_IsEmpty(¬if_list.ql)) { + QLIST_NEXTSAFE_FOR_ALL(¬if_list.ql, pn, pnn) + { + lnotif = STD_RECOVER_REC(struct fastrpc_notif, qn, pn); + if(lnotif) { + free(lnotif); + lnotif = NULL; + } + } + } + pthread_mutex_unlock(&update_notif_list_mut); } /* Function to wait in kernel for an update in remote process status */ -int get_remote_notif_response(int domain) { - int nErr = AEE_SUCCESS, dev; - int dom = -1, session = -1, status = -1; - - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - nErr = ioctl_invoke2_notif(dev, &dom, &session, &status); - if (nErr) { - nErr = convert_kernel_to_user_error(nErr, errno); - goto bail; - } - FARF(ALWAYS, "%s: received status notification %u for domain %d, session %d", - __func__, status, dom, session); - fastrpc_notify_status(dom, session, status); +int +get_remote_notif_response(int domain) +{ + int nErr = AEE_SUCCESS, dev; + int dom = -1, session = -1, status = -1; + + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + nErr = ioctl_invoke2_notif(dev, &dom, &session, &status); + if(nErr) { + nErr = convert_kernel_to_user_error(nErr, errno); + goto bail; + } + FARF(ALWAYS, + "%s: received status notification %u for domain %d, session %d", + __func__, status, dom, session); + fastrpc_notify_status(dom, session, status); bail: - if (nErr && (errno != EBADF) && (nErr != AEE_EEXPIRED)) { - FARF(ERROR, - "Error 0x%x: %s failed to get notification response data errno %s", - nErr, __func__, strerror(errno)); - } - return nErr; + if(nErr && (errno != EBADF) && (nErr != AEE_EEXPIRED)) { + FARF(ERROR, + "Error 0x%x: %s failed to get notification response data " + "errno %s", + nErr, __func__, strerror(errno)); + } + return nErr; } // Make IOCTL call to exit notif thread -int fastrpc_exit_notif_thread(int domain) { - int nErr = AEE_SUCCESS, dev; +int +fastrpc_exit_notif_thread(int domain) +{ + int nErr = AEE_SUCCESS, dev; - VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); - nErr = ioctl_control(dev, DSPRPC_NOTIF_WAKE, NULL); + VERIFY(AEE_SUCCESS == (nErr = fastrpc_session_dev(domain, &dev))); + nErr = ioctl_control(dev, DSPRPC_NOTIF_WAKE, NULL); bail: - if (nErr) - FARF(ERROR, - "Error 0x%x: %s failed for domain %d (errno: %s), ignore if ioctl not " - "supported, try pthread kill ", - nErr, __func__, domain, strerror(errno)); - return nErr; + if(nErr) + FARF(ERROR, + "Error 0x%x: %s failed for domain %d (errno: %s), ignore " + "if ioctl not " + "supported, try pthread kill ", + nErr, __func__, domain, strerror(errno)); + return nErr; } diff --git a/src/fastrpc_perf.c b/src/fastrpc_perf.c index fef90202..7c840a2d 100644 --- a/src/fastrpc_perf.c +++ b/src/fastrpc_perf.c @@ -12,28 +12,27 @@ #define FARF_ERROR 1 #include +#include #include #include #include #include #include -#include #include "AEEStdErr.h" #include "AEEstd.h" #include "HAP_farf.h" #include "adsp_perf.h" #include "adsp_perf1.h" +#include "fastrpc_cap.h" #include "fastrpc_common.h" #include "fastrpc_internal.h" -#include "fastrpc_trace.h" -#include "fastrpc_cap.h" #include "fastrpc_perf.h" +#include "fastrpc_trace.h" #include "remote.h" #include "rpcmem_internal.h" #include "verify.h" - #define PERF_MODE 2 #define PERF_OFF 0 #define PERF_KERNEL_MASK (0x1) @@ -44,19 +43,18 @@ #define PERF_NS_TO_US(n) ((n) / 1000) -#define IS_KEY_ENABLED(name) \ - (!strncmp((name), "perf_invoke_count", 17) || \ - !strncmp((name), "perf_mod_invoke", 15) || \ - !strncmp((name), "perf_rsp", 8) || \ - !strncmp((name), "perf_hdr_sync_flush", 19) || \ - !strncmp((name), "perf_sync_flush", 15) || \ - !strncmp((name), "perf_hdr_sync_inv", 17) || \ - !strncmp((name), "perf_clean_cache", 16) || \ - !strncmp((name), "perf_sync_inv", 13)) +#define IS_KEY_ENABLED(name) \ + (!strncmp((name), "perf_invoke_count", 17) \ + || !strncmp((name), "perf_mod_invoke", 15) \ + || !strncmp((name), "perf_rsp", 8) \ + || !strncmp((name), "perf_hdr_sync_flush", 19) \ + || !strncmp((name), "perf_sync_flush", 15) \ + || !strncmp((name), "perf_hdr_sync_inv", 17) \ + || !strncmp((name), "perf_clean_cache", 16) \ + || !strncmp((name), "perf_sync_inv", 13)) #define PERF_CAPABILITY_CHECK (1 << 1) - extern bool fastrpc_config_is_perfkernel_enabled(void); extern bool fastrpc_config_is_perfdsp_enabled(void); @@ -64,69 +62,92 @@ int perf_v2_kernel = 0; int perf_v2_dsp = 0; struct perf_keys { - int64_t data[PERF_MAX_NUM_KEYS]; - int numKeys; - int maxLen; - int enable; - char *keys; + int64_t data[PERF_MAX_NUM_KEYS]; + int numKeys; + int maxLen; + int enable; + char *keys; }; struct fastrpc_perf { - int count; - int freq; - int perf_on; - int process_trace_enabled; - struct perf_keys kernel; - struct perf_keys dsp; - remote_handle64 adsp_perf_handle; + int count; + int freq; + int perf_on; + int process_trace_enabled; + struct perf_keys kernel; + struct perf_keys dsp; + remote_handle64 adsp_perf_handle; }; -struct fastrpc_perf gperf = {0}; - -void check_perf_v2_enabled(int domain) { - int nErr = 0; - fastrpc_capability cap = {0}; - cap.domain = domain; - cap.attribute_ID = PERF_V2_DRIVER_SUPPORT; - - nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == 0) { - perf_v2_kernel = (cap.capability == PERF_CAPABILITY_CHECK) ? 1 : 0; - } - cap.attribute_ID = PERF_V2_DSP_SUPPORT; - nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); - if (nErr == 0) { - perf_v2_dsp = (cap.capability == PERF_CAPABILITY_CHECK) ? 1 : 0; - } +struct fastrpc_perf gperf = { 0 }; + +void +check_perf_v2_enabled(int domain) +{ + int nErr = 0; + fastrpc_capability cap = { 0 }; + cap.domain = domain; + cap.attribute_ID = PERF_V2_DRIVER_SUPPORT; + + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); + if(nErr == 0) { + perf_v2_kernel + = (cap.capability == PERF_CAPABILITY_CHECK) ? 1 : 0; + } + cap.attribute_ID = PERF_V2_DSP_SUPPORT; + nErr = fastrpc_get_cap(cap.domain, cap.attribute_ID, &cap.capability); + if(nErr == 0) { + perf_v2_dsp + = (cap.capability == PERF_CAPABILITY_CHECK) ? 1 : 0; + } +} + +bool +is_kernel_perf_enabled() +{ + return perf_v2_kernel; +} +bool +is_dsp_perf_enabled(int domain) +{ + return perf_v2_dsp; +} +bool +is_perf_v2_enabled() +{ + return (perf_v2_kernel == 1 && perf_v2_dsp == 1); +} + +inline int +is_systrace_enabled() +{ + return gperf.process_trace_enabled; } -bool is_kernel_perf_enabled() { return perf_v2_kernel; } -bool is_dsp_perf_enabled(int domain) { return perf_v2_dsp; } -bool is_perf_v2_enabled() { return (perf_v2_kernel == 1 && perf_v2_dsp == 1); } - -inline int is_systrace_enabled() { return gperf.process_trace_enabled; } - -static int perf_kernel_getkeys(int dev) { - int nErr = 0, numkeys = 0; - struct fastrpc_perf *p = &gperf; - char *token; - char *saveptr; - - VERIFYC(p->kernel.keys, AEE_ERPC); - VERIFY(0 == (nErr = ioctl_getperf(dev, 1, p->kernel.keys, &numkeys))); - FARF(RUNTIME_RPC_HIGH, "adsprpc:apps:keys: numkeys %d keys: %s", numkeys, - p->kernel.keys); - p->kernel.numKeys = numkeys; - token = strtok_r(p->kernel.keys, ":", &saveptr); - while (token) { - FARF(RUNTIME_RPC_LOW, "key: %s", token); - token = strtok_r(NULL, ":", &saveptr); - } +static int +perf_kernel_getkeys(int dev) +{ + int nErr = 0, numkeys = 0; + struct fastrpc_perf *p = &gperf; + char *token; + char *saveptr; + + VERIFYC(p->kernel.keys, AEE_ERPC); + VERIFY(0 == (nErr = ioctl_getperf(dev, 1, p->kernel.keys, &numkeys))); + FARF(RUNTIME_RPC_HIGH, "adsprpc:apps:keys: numkeys %d keys: %s", + numkeys, p->kernel.keys); + p->kernel.numKeys = numkeys; + token = strtok_r(p->kernel.keys, ":", &saveptr); + while(token) { + FARF(RUNTIME_RPC_LOW, "key: %s", token); + token = strtok_r(NULL, ":", &saveptr); + } bail: - if (nErr) { - VERIFY_WPRINTF("Warning: %s: Failed to get kernel keys, nErr 0x%x\n", - __func__, nErr); - } - return nErr; + if(nErr) { + VERIFY_WPRINTF( + "Warning: %s: Failed to get kernel keys, nErr 0x%x\n", + __func__, nErr); + } + return nErr; } /* C: PERF_COUNT @@ -140,203 +161,238 @@ INV: PERF_INVARGS INVOKE: PERF_INVOKE */ -static void get_perf_kernel(int dev, remote_handle handle, uint32_t sc) { - int nErr = 0, numkeys = 0; - struct fastrpc_perf *p = &gperf; - char *token; - - VERIFYC(dev != -1, AEE_ERPC); - - VERIFY(0 == (nErr = ioctl_getperf(dev, 0, p->kernel.data, &numkeys))); - token = p->kernel.keys; - - VERIFYC(token, AEE_ERPC); - switch (numkeys) { - case PERF_KERNEL_NUM_KEYS: - FARF(ALWAYS, - "RPCPERF-K H:0x%x SC:0x%x C:%" PRId64 " F:%" PRId64 " ns M:%" PRId64 - " ns CP:%" PRId64 " ns L:%" PRId64 " ns G:%" PRId64 " ns P:%" PRId64 - " ns INV:%" PRId64 " ns INVOKE:%" PRId64 " ns\n", - handle, sc, p->kernel.data[0], p->kernel.data[1], p->kernel.data[2], - p->kernel.data[3], p->kernel.data[4], p->kernel.data[5], - p->kernel.data[6], p->kernel.data[7], p->kernel.data[8]); - break; - default: - FARF(ALWAYS, "RPCPERF-K H:0x%x SC:0x%x \n", handle, sc); - break; - } +static void +get_perf_kernel(int dev, remote_handle handle, uint32_t sc) +{ + int nErr = 0, numkeys = 0; + struct fastrpc_perf *p = &gperf; + char *token; + + VERIFYC(dev != -1, AEE_ERPC); + + VERIFY(0 == (nErr = ioctl_getperf(dev, 0, p->kernel.data, &numkeys))); + token = p->kernel.keys; + + VERIFYC(token, AEE_ERPC); + switch(numkeys) { + case PERF_KERNEL_NUM_KEYS: + FARF(ALWAYS, + "RPCPERF-K H:0x%x SC:0x%x C:%" PRId64 " F:%" PRId64 + " ns M:%" PRId64 " ns CP:%" PRId64 " ns L:%" PRId64 + " ns G:%" PRId64 " ns P:%" PRId64 " ns INV:%" PRId64 + " ns INVOKE:%" PRId64 " ns\n", + handle, sc, p->kernel.data[0], p->kernel.data[1], + p->kernel.data[2], p->kernel.data[3], p->kernel.data[4], + p->kernel.data[5], p->kernel.data[6], p->kernel.data[7], + p->kernel.data[8]); + break; + default: + FARF(ALWAYS, "RPCPERF-K H:0x%x SC:0x%x \n", handle, sc); + break; + } bail: - if (nErr) - VERIFY_WPRINTF( - "Warning: %s: Failed to get perf data from kernel, nErr 0x%x\n", - __func__, nErr); - return; + if(nErr) + VERIFY_WPRINTF("Warning: %s: Failed to get perf data from " + "kernel, nErr 0x%x\n", + __func__, nErr); + return; } -static void get_perf_adsp(remote_handle handle, uint32_t sc) { - int nErr = 0; - struct perf_keys *pdsp = &gperf.dsp; - int ii; - char *token; - - char *keystr = pdsp->keys; - if (gperf.adsp_perf_handle != INVALID_HANDLE) { - VERIFY(0 == (nErr = adsp_perf1_get_usecs(gperf.adsp_perf_handle, pdsp->data, - PERF_MAX_NUM_KEYS))); - } else { - VERIFY(0 == (nErr = adsp_perf_get_usecs(pdsp->data, PERF_MAX_NUM_KEYS))); - } - VERIFYC(pdsp->maxLen < PERF_KEY_STR_MAX, AEE_ERPC); - VERIFYC(pdsp->numKeys < PERF_MAX_NUM_KEYS, AEE_ERPC); - FARF(ALWAYS, "\nFastRPC dsp perf for handle 0x%x sc 0x%x\n", handle, sc); - for (ii = 0; ii < pdsp->numKeys; ii++) { - token = keystr; - keystr += strlen(token) + 1; - VERIFYC(token, AEE_ERPC); - if (!pdsp->data[ii]) - continue; - if (!strncmp(token, "perf_invoke_count", 17)) { - FARF(ALWAYS, "fastrpc.dsp.%-20s : %" PRId64 " \n", token, pdsp->data[ii]); - } else { - FARF(ALWAYS, "fastrpc.dsp.%-20s : %" PRId64 " us\n", token, - pdsp->data[ii]); - } - } +static void +get_perf_adsp(remote_handle handle, uint32_t sc) +{ + int nErr = 0; + struct perf_keys *pdsp = &gperf.dsp; + int ii; + char *token; + + char *keystr = pdsp->keys; + if(gperf.adsp_perf_handle != INVALID_HANDLE) { + VERIFY(0 + == (nErr = adsp_perf1_get_usecs(gperf.adsp_perf_handle, + pdsp->data, + PERF_MAX_NUM_KEYS))); + } else { + VERIFY(0 + == (nErr = adsp_perf_get_usecs(pdsp->data, + PERF_MAX_NUM_KEYS))); + } + VERIFYC(pdsp->maxLen < PERF_KEY_STR_MAX, AEE_ERPC); + VERIFYC(pdsp->numKeys < PERF_MAX_NUM_KEYS, AEE_ERPC); + FARF(ALWAYS, "\nFastRPC dsp perf for handle 0x%x sc 0x%x\n", handle, + sc); + for(ii = 0; ii < pdsp->numKeys; ii++) { + token = keystr; + keystr += strlen(token) + 1; + VERIFYC(token, AEE_ERPC); + if(!pdsp->data[ii]) + continue; + if(!strncmp(token, "perf_invoke_count", 17)) { + FARF(ALWAYS, "fastrpc.dsp.%-20s : %" PRId64 " \n", + token, pdsp->data[ii]); + } else { + FARF(ALWAYS, "fastrpc.dsp.%-20s : %" PRId64 " us\n", + token, pdsp->data[ii]); + } + } bail: - if (nErr) - VERIFY_WPRINTF("Warning: %s: Failed to get perf data from dsp, nErr 0x%x\n", - __func__, nErr); - return; + if(nErr) + VERIFY_WPRINTF("Warning: %s: Failed to get perf data from " + "dsp, nErr 0x%x\n", + __func__, nErr); + return; } -void fastrpc_perf_update(int dev, remote_handle handle, uint32_t sc) { - struct fastrpc_perf *p = &gperf; +void +fastrpc_perf_update(int dev, remote_handle handle, uint32_t sc) +{ + struct fastrpc_perf *p = &gperf; - if (!(p->perf_on && !IS_STATIC_HANDLE(handle) && p->freq > 0)) - return; + if(!(p->perf_on && !IS_STATIC_HANDLE(handle) && p->freq > 0)) + return; - p->count++; - if (p->count % p->freq != 0) - return; + p->count++; + if(p->count % p->freq != 0) + return; - if (p->kernel.enable && !perf_v2_kernel) - get_perf_kernel(dev, handle, sc); + if(p->kernel.enable && !perf_v2_kernel) + get_perf_kernel(dev, handle, sc); - if (p->dsp.enable && !perf_v2_dsp) - get_perf_adsp(handle, sc); + if(p->dsp.enable && !perf_v2_dsp) + get_perf_adsp(handle, sc); - return; + return; } -static int perf_dsp_enable(int domain) { - int nErr = 0; - int numKeys = 0, maxLen = 0; - char *keys = NULL; - int ii; - - keys = - (char *)rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, PERF_KEY_STR_MAX); - VERIFYC(gperf.dsp.keys = keys, AEE_ERPC); - memset(keys, 0, PERF_KEY_STR_MAX); - - VERIFY(0 == (nErr = adsp_perf_get_keys(keys, PERF_KEY_STR_MAX, &maxLen, - &numKeys))); - if ((gperf.adsp_perf_handle = get_adsp_perf1_handle(domain)) != - INVALID_HANDLE) { - nErr = adsp_perf1_get_keys(gperf.adsp_perf_handle, keys, PERF_KEY_STR_MAX, - &maxLen, &numKeys); - if (nErr) { - FARF(ALWAYS, - "Warning 0x%x: %s: adsp_perf1 domains not supported for domain %d\n", - nErr, __func__, domain); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, _const_adsp_perf1_handle, NULL, NULL); - gperf.adsp_perf_handle = INVALID_HANDLE; - VERIFY(0 == (nErr = adsp_perf_get_keys(keys, PERF_KEY_STR_MAX, &maxLen, - &numKeys))); - } - } - VERIFYC(maxLen < PERF_KEY_STR_MAX && maxLen >= 0, AEE_ERPC); - VERIFYC(numKeys < PERF_MAX_NUM_KEYS && numKeys >= 0, AEE_ERPC); - gperf.dsp.maxLen = maxLen; - gperf.dsp.numKeys = numKeys; - for (ii = 0; ii < numKeys; ii++) { - char *name = keys; - keys += strlen(name) + 1; - if (IS_KEY_ENABLED(name)) { - if (gperf.adsp_perf_handle != INVALID_HANDLE) { - VERIFY(0 == (nErr = adsp_perf1_enable(gperf.adsp_perf_handle, ii))); - } else { - VERIFY(0 == (nErr = adsp_perf_enable(ii))); - } - } - } - FARF(RUNTIME_RPC_HIGH, "keys enable done maxLen %d numKeys %d", maxLen, - numKeys); +static int +perf_dsp_enable(int domain) +{ + int nErr = 0; + int numKeys = 0, maxLen = 0; + char *keys = NULL; + int ii; + + keys = (char *)rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, + PERF_KEY_STR_MAX); + VERIFYC(gperf.dsp.keys = keys, AEE_ERPC); + memset(keys, 0, PERF_KEY_STR_MAX); + + VERIFY(0 + == (nErr = adsp_perf_get_keys(keys, PERF_KEY_STR_MAX, &maxLen, + &numKeys))); + if((gperf.adsp_perf_handle = get_adsp_perf1_handle(domain)) + != INVALID_HANDLE) { + nErr + = adsp_perf1_get_keys(gperf.adsp_perf_handle, keys, + PERF_KEY_STR_MAX, &maxLen, &numKeys); + if(nErr) { + FARF(ALWAYS, + "Warning 0x%x: %s: adsp_perf1 domains not " + "supported for domain %d\n", + nErr, __func__, domain); + fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, + _const_adsp_perf1_handle, + NULL, NULL); + gperf.adsp_perf_handle = INVALID_HANDLE; + VERIFY(0 + == (nErr + = adsp_perf_get_keys(keys, PERF_KEY_STR_MAX, + &maxLen, &numKeys))); + } + } + VERIFYC(maxLen < PERF_KEY_STR_MAX && maxLen >= 0, AEE_ERPC); + VERIFYC(numKeys < PERF_MAX_NUM_KEYS && numKeys >= 0, AEE_ERPC); + gperf.dsp.maxLen = maxLen; + gperf.dsp.numKeys = numKeys; + for(ii = 0; ii < numKeys; ii++) { + char *name = keys; + keys += strlen(name) + 1; + if(IS_KEY_ENABLED(name)) { + if(gperf.adsp_perf_handle != INVALID_HANDLE) { + VERIFY(0 + == (nErr = adsp_perf1_enable( + gperf.adsp_perf_handle, ii))); + } else { + VERIFY(0 == (nErr = adsp_perf_enable(ii))); + } + } + } + FARF(RUNTIME_RPC_HIGH, "keys enable done maxLen %d numKeys %d", maxLen, + numKeys); bail: - if (nErr) { - VERIFY_WPRINTF("Warning: %s: Failed to enable perf on dsp, nErr 0x%x\n", - __func__, nErr); - } - return nErr; + if(nErr) { + VERIFY_WPRINTF( + "Warning: %s: Failed to enable perf on dsp, nErr 0x%x\n", + __func__, nErr); + } + return nErr; } -int fastrpc_perf_init(int dev, int domain) { - int nErr = 0; - struct fastrpc_perf *p = &gperf; - struct perf_keys *pk = &gperf.kernel; - struct perf_keys *pd = &gperf.dsp; - - pk->enable = fastrpc_get_property_int(FASTRPC_PERF_KERNEL, 0) || - fastrpc_config_is_perfkernel_enabled(); - pd->enable = fastrpc_get_property_int(FASTRPC_PERF_ADSP, 0) || - fastrpc_config_is_perfdsp_enabled(); - - p->perf_on = (pk->enable || pd->enable) ? PERF_MODE : PERF_OFF; - p->freq = fastrpc_get_property_int(FASTRPC_PERF_FREQ, 1000); - VERIFYC(p->freq > 0, AEE_ERPC); - p->process_trace_enabled = - fastrpc_get_property_int(FASTRPC_ENABLE_SYSTRACE, 0); - if (p->perf_on) { - check_perf_v2_enabled(domain); - } - p->count = 0; - if (pk->enable) { - VERIFY(0 == (nErr = ioctl_setmode(dev, PERF_MODE))); - if (!perf_v2_kernel) { - VERIFYC(NULL != - (pk->keys = (char *)calloc(sizeof(char), PERF_KEY_STR_MAX)), - AEE_ENOMEMORY); - VERIFY(0 == (nErr = perf_kernel_getkeys(dev))); - } - } - - if (pd->enable && (!perf_v2_dsp)) - perf_dsp_enable(domain); +int +fastrpc_perf_init(int dev, int domain) +{ + int nErr = 0; + struct fastrpc_perf *p = &gperf; + struct perf_keys *pk = &gperf.kernel; + struct perf_keys *pd = &gperf.dsp; + + pk->enable = fastrpc_get_property_int(FASTRPC_PERF_KERNEL, 0) + || fastrpc_config_is_perfkernel_enabled(); + pd->enable = fastrpc_get_property_int(FASTRPC_PERF_ADSP, 0) + || fastrpc_config_is_perfdsp_enabled(); + + p->perf_on = (pk->enable || pd->enable) ? PERF_MODE : PERF_OFF; + p->freq = fastrpc_get_property_int(FASTRPC_PERF_FREQ, 1000); + VERIFYC(p->freq > 0, AEE_ERPC); + p->process_trace_enabled + = fastrpc_get_property_int(FASTRPC_ENABLE_SYSTRACE, 0); + if(p->perf_on) { + check_perf_v2_enabled(domain); + } + p->count = 0; + if(pk->enable) { + VERIFY(0 == (nErr = ioctl_setmode(dev, PERF_MODE))); + if(!perf_v2_kernel) { + VERIFYC(NULL + != (pk->keys = (char *)calloc( + sizeof(char), PERF_KEY_STR_MAX)), + AEE_ENOMEMORY); + VERIFY(0 == (nErr = perf_kernel_getkeys(dev))); + } + } + + if(pd->enable && (!perf_v2_dsp)) + perf_dsp_enable(domain); bail: - if (nErr) { - FARF(ERROR, - "fastrpc perf init failed, nErr 0x%x (kernel %d, dsp %d) with " - "frequency %d", - nErr, pk->enable, pd->enable, p->freq); - p->perf_on = 0; - } else { - FARF(ALWAYS, - "%s: enabled systrace 0x%x and RPC traces (kernel %d, dsp %d) with " - "frequency %d", - __func__, p->process_trace_enabled, pk->enable, pd->enable, p->freq); - } - return nErr; + if(nErr) { + FARF(ERROR, + "fastrpc perf init failed, nErr 0x%x (kernel %d, dsp %d) " + "with " + "frequency %d", + nErr, pk->enable, pd->enable, p->freq); + p->perf_on = 0; + } else { + FARF(ALWAYS, + "%s: enabled systrace 0x%x and RPC traces (kernel %d, " + "dsp %d) with " + "frequency %d", + __func__, p->process_trace_enabled, pk->enable, + pd->enable, p->freq); + } + return nErr; } -void fastrpc_perf_deinit(void) { - struct fastrpc_perf *p = &gperf; - if (p->kernel.keys) { - free(p->kernel.keys); - p->kernel.keys = NULL; - } - if (p->dsp.keys) { - rpcmem_free_internal(p->dsp.keys); - p->dsp.keys = NULL; - } - return; +void +fastrpc_perf_deinit(void) +{ + struct fastrpc_perf *p = &gperf; + if(p->kernel.keys) { + free(p->kernel.keys); + p->kernel.keys = NULL; + } + if(p->dsp.keys) { + rpcmem_free_internal(p->dsp.keys); + p->dsp.keys = NULL; + } + return; } diff --git a/src/fastrpc_pm.c b/src/fastrpc_pm.c index a718a293..01d968bf 100644 --- a/src/fastrpc_pm.c +++ b/src/fastrpc_pm.c @@ -12,207 +12,245 @@ #include #include #include -#include #include #include +#include #include #include #include -#include "AEEstd.h" #include "AEEStdErr.h" +#include "AEEstd.h" #include "HAP_farf.h" #include "verify.h" - #define WAKE_LOCK_FILE "/sys/power/wake_lock" #define WAKE_UNLOCK_FILE "/sys/power/wake_unlock" #define WAKELOCK_NAME_LEN 50 struct wake_lock { - char wake_lock_name[WAKELOCK_NAME_LEN]; - int lock; - int unlock; - pthread_mutex_t wmut; - unsigned int count; - bool init_done; - bool deinit_started; + char wake_lock_name[WAKELOCK_NAME_LEN]; + int lock; + int unlock; + pthread_mutex_t wmut; + unsigned int count; + bool init_done; + bool deinit_started; }; static struct wake_lock wakelock; static atomic_bool wakelock_wmut_int = false; -int fastrpc_wake_lock() { - int nErr = AEE_SUCCESS, ret = 0; - - if (!wakelock.init_done) { - nErr = AEE_ERPC; - FARF(ERROR, "Error 0x%x : %s failed for wakelock is not initialized\n", - nErr, __func__); - return nErr; - } - - pthread_mutex_lock(&wakelock.wmut); - if (wakelock.deinit_started) { - nErr = AEE_ERPC; - FARF(ERROR, "Warning 0x%x : %s failed for wakelock as deinit started\n", - nErr, __func__); - goto bail; - } - if (!wakelock.count && wakelock.lock > 0) - VERIFYC(0 < (ret = write(wakelock.lock, wakelock.wake_lock_name, - strlen(wakelock.wake_lock_name))), - AEE_ERPC); - wakelock.count++; +int +fastrpc_wake_lock() +{ + int nErr = AEE_SUCCESS, ret = 0; + + if(!wakelock.init_done) { + nErr = AEE_ERPC; + FARF( + ERROR, + "Error 0x%x : %s failed for wakelock is not initialized\n", + nErr, __func__); + return nErr; + } + + pthread_mutex_lock(&wakelock.wmut); + if(wakelock.deinit_started) { + nErr = AEE_ERPC; + FARF(ERROR, + "Warning 0x%x : %s failed for wakelock as deinit " + "started\n", + nErr, __func__); + goto bail; + } + if(!wakelock.count && wakelock.lock > 0) + VERIFYC( + 0 < (ret = write(wakelock.lock, wakelock.wake_lock_name, + strlen(wakelock.wake_lock_name))), + AEE_ERPC); + wakelock.count++; bail: - pthread_mutex_unlock(&wakelock.wmut); - if (nErr) { - FARF(ERROR, "Error 0x%x (%d): %s failed for %s, fd %d (errno %s)\n", nErr, - ret, __func__, WAKE_LOCK_FILE, wakelock.lock, strerror(errno)); - } - return nErr; + pthread_mutex_unlock(&wakelock.wmut); + if(nErr) { + FARF(ERROR, + "Error 0x%x (%d): %s failed for %s, fd %d (errno %s)\n", + nErr, ret, __func__, WAKE_LOCK_FILE, wakelock.lock, + strerror(errno)); + } + return nErr; } -int fastrpc_wake_unlock() { - int nErr = AEE_SUCCESS, ret = 0; - - if (!wakelock.init_done) { - nErr = AEE_ERPC; - FARF(ERROR, "Error 0x%x : %s failed for wakelock is not initialized\n", - nErr, __func__); - return nErr; - } - - pthread_mutex_lock(&wakelock.wmut); - if (!wakelock.count) - goto bail; - wakelock.count--; - if (!wakelock.count && wakelock.unlock > 0) - VERIFYC(0 < (ret = write(wakelock.unlock, wakelock.wake_lock_name, - strlen(wakelock.wake_lock_name))), - AEE_ERPC); +int +fastrpc_wake_unlock() +{ + int nErr = AEE_SUCCESS, ret = 0; + + if(!wakelock.init_done) { + nErr = AEE_ERPC; + FARF( + ERROR, + "Error 0x%x : %s failed for wakelock is not initialized\n", + nErr, __func__); + return nErr; + } + + pthread_mutex_lock(&wakelock.wmut); + if(!wakelock.count) + goto bail; + wakelock.count--; + if(!wakelock.count && wakelock.unlock > 0) + VERIFYC( + 0 < (ret = write(wakelock.unlock, wakelock.wake_lock_name, + strlen(wakelock.wake_lock_name))), + AEE_ERPC); bail: - if (nErr) { - wakelock.count++; - FARF(ERROR, "Error 0x%x (%d): %s failed for %s, fd %d (errno %s)\n", nErr, - ret, __func__, WAKE_UNLOCK_FILE, wakelock.unlock, strerror(errno)); - } - pthread_mutex_unlock(&wakelock.wmut); - return nErr; + if(nErr) { + wakelock.count++; + FARF(ERROR, + "Error 0x%x (%d): %s failed for %s, fd %d (errno %s)\n", + nErr, ret, __func__, WAKE_UNLOCK_FILE, wakelock.unlock, + strerror(errno)); + } + pthread_mutex_unlock(&wakelock.wmut); + return nErr; } -static void fastrpc_wake_lock_release() { - int nErr = AEE_SUCCESS; +static void +fastrpc_wake_lock_release() +{ + int nErr = AEE_SUCCESS; - while (wakelock.count) { - VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_unlock())); - } + while(wakelock.count) { + VERIFY(AEE_SUCCESS == (nErr = fastrpc_wake_unlock())); + } bail: - return; + return; } -int fastrpc_wake_lock_init() { - int nErr = AEE_SUCCESS, ret = 0; - const unsigned int TMPSTR_LEN = WAKELOCK_NAME_LEN / 2; - char pid_str[TMPSTR_LEN], prog_name_str[TMPSTR_LEN]; - bool expected = false; +int +fastrpc_wake_lock_init() +{ + int nErr = AEE_SUCCESS, ret = 0; + const unsigned int TMPSTR_LEN = WAKELOCK_NAME_LEN / 2; + char pid_str[TMPSTR_LEN], prog_name_str[TMPSTR_LEN]; + bool expected = false; - if (wakelock.init_done) - return nErr; + if(wakelock.init_done) + return nErr; - wakelock.deinit_started = 0; + wakelock.deinit_started = 0; - if (atomic_compare_exchange_strong(&wakelock_wmut_int, &expected, true)) - VERIFY(AEE_SUCCESS == (nErr = pthread_mutex_init(&wakelock.wmut, 0))); + if(atomic_compare_exchange_strong(&wakelock_wmut_int, &expected, true)) + VERIFY(AEE_SUCCESS + == (nErr = pthread_mutex_init(&wakelock.wmut, 0))); - pthread_mutex_lock(&wakelock.wmut); + pthread_mutex_lock(&wakelock.wmut); - VERIFYC(0 < (ret = snprintf(pid_str, TMPSTR_LEN, ":%d", getpid())), AEE_ERPC); - if (0 >= (ret = snprintf(prog_name_str, TMPSTR_LEN, "%s", __progname))) { - nErr = AEE_ERPC; - goto bail; - } + VERIFYC(0 < (ret = snprintf(pid_str, TMPSTR_LEN, ":%d", getpid())), + AEE_ERPC); + if(0 + >= (ret = snprintf(prog_name_str, TMPSTR_LEN, "%s", __progname))) { + nErr = AEE_ERPC; + goto bail; + } - strlcpy(wakelock.wake_lock_name, prog_name_str, WAKELOCK_NAME_LEN); - strlcat(wakelock.wake_lock_name, pid_str, WAKELOCK_NAME_LEN); + strlcpy(wakelock.wake_lock_name, prog_name_str, WAKELOCK_NAME_LEN); + strlcat(wakelock.wake_lock_name, pid_str, WAKELOCK_NAME_LEN); - VERIFYC(0 < (wakelock.lock = open(WAKE_LOCK_FILE, O_RDWR | O_CLOEXEC)), - AEE_ERPC); - VERIFYC(0 < (wakelock.unlock = open(WAKE_UNLOCK_FILE, O_RDWR | O_CLOEXEC)), - AEE_ERPC); + VERIFYC(0 < (wakelock.lock = open(WAKE_LOCK_FILE, O_RDWR | O_CLOEXEC)), + AEE_ERPC); + VERIFYC( + 0 < (wakelock.unlock = open(WAKE_UNLOCK_FILE, O_RDWR | O_CLOEXEC)), + AEE_ERPC); bail: - if (nErr) { - FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, ret, __func__, - strerror(errno)); - if ((nErr == AEE_ERPC) && (errno == ENOENT)) { - nErr = AEE_EUNSUPPORTEDAPI; - } - if (wakelock.lock > 0) { - ret = close(wakelock.lock); - if (ret) { - FARF(ERROR, "Error %d: %s: failed to close %s with fd %d (errno %s)", - ret, __func__, WAKE_LOCK_FILE, wakelock.lock, strerror(errno)); - } else { - wakelock.lock = 0; - } - } - if (wakelock.unlock > 0) { - ret = close(wakelock.unlock); - if (ret) { - FARF(ERROR, "Error %d: %s: failed to close %s with fd %d (errno %s)", - ret, __func__, WAKE_UNLOCK_FILE, wakelock.unlock, strerror(errno)); - } else { - wakelock.unlock = 0; - } - } - pthread_mutex_unlock(&wakelock.wmut); - pthread_mutex_destroy(&wakelock.wmut); - } else { - wakelock.init_done = true; - pthread_mutex_unlock(&wakelock.wmut); - FARF(ALWAYS, "%s done for %s", __func__, wakelock.wake_lock_name); - } - return nErr; + if(nErr) { + FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, + ret, __func__, strerror(errno)); + if((nErr == AEE_ERPC) && (errno == ENOENT)) { + nErr = AEE_EUNSUPPORTEDAPI; + } + if(wakelock.lock > 0) { + ret = close(wakelock.lock); + if(ret) { + FARF(ERROR, + "Error %d: %s: failed to close %s with " + "fd %d (errno %s)", + ret, __func__, WAKE_LOCK_FILE, + wakelock.lock, strerror(errno)); + } else { + wakelock.lock = 0; + } + } + if(wakelock.unlock > 0) { + ret = close(wakelock.unlock); + if(ret) { + FARF(ERROR, + "Error %d: %s: failed to close %s with " + "fd %d (errno %s)", + ret, __func__, WAKE_UNLOCK_FILE, + wakelock.unlock, strerror(errno)); + } else { + wakelock.unlock = 0; + } + } + pthread_mutex_unlock(&wakelock.wmut); + pthread_mutex_destroy(&wakelock.wmut); + } else { + wakelock.init_done = true; + pthread_mutex_unlock(&wakelock.wmut); + FARF(ALWAYS, "%s done for %s", __func__, + wakelock.wake_lock_name); + } + return nErr; } -int fastrpc_wake_lock_deinit() { - int nErr = AEE_SUCCESS; - - if (!wakelock.init_done) - return nErr; - - pthread_mutex_lock(&wakelock.wmut); - wakelock.deinit_started = 1; - pthread_mutex_unlock(&wakelock.wmut); - fastrpc_wake_lock_release(); - pthread_mutex_lock(&wakelock.wmut); - if (wakelock.lock > 0) { - nErr = close(wakelock.lock); - if (nErr) { - FARF(ERROR, "Error %d: %s: failed to close %s with fd %d (errno %s)", - nErr, __func__, WAKE_LOCK_FILE, wakelock.lock, strerror(errno)); - } else { - wakelock.lock = 0; - } - } - if (wakelock.unlock > 0) { - nErr = close(wakelock.unlock); - if (nErr) { - FARF(ERROR, "Error %d: %s: failed to close %s with fd %d (errno %s)", - nErr, __func__, WAKE_UNLOCK_FILE, wakelock.unlock, strerror(errno)); - } else { - wakelock.unlock = 0; - } - } - wakelock.init_done = false; - pthread_mutex_unlock(&wakelock.wmut); - - if (nErr) - FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, nErr, __func__, - strerror(errno)); - else - FARF(ALWAYS, "%s done", __func__); - return nErr; +int +fastrpc_wake_lock_deinit() +{ + int nErr = AEE_SUCCESS; + + if(!wakelock.init_done) + return nErr; + + pthread_mutex_lock(&wakelock.wmut); + wakelock.deinit_started = 1; + pthread_mutex_unlock(&wakelock.wmut); + fastrpc_wake_lock_release(); + pthread_mutex_lock(&wakelock.wmut); + if(wakelock.lock > 0) { + nErr = close(wakelock.lock); + if(nErr) { + FARF(ERROR, + "Error %d: %s: failed to close %s with fd %d " + "(errno %s)", + nErr, __func__, WAKE_LOCK_FILE, wakelock.lock, + strerror(errno)); + } else { + wakelock.lock = 0; + } + } + if(wakelock.unlock > 0) { + nErr = close(wakelock.unlock); + if(nErr) { + FARF(ERROR, + "Error %d: %s: failed to close %s with fd %d " + "(errno %s)", + nErr, __func__, WAKE_UNLOCK_FILE, wakelock.unlock, + strerror(errno)); + } else { + wakelock.unlock = 0; + } + } + wakelock.init_done = false; + pthread_mutex_unlock(&wakelock.wmut); + + if(nErr) + FARF(ERROR, "Error 0x%x (%d): %s failed (errno %s)\n", nErr, + nErr, __func__, strerror(errno)); + else + FARF(ALWAYS, "%s done", __func__); + return nErr; } diff --git a/src/fastrpc_procbuf.c b/src/fastrpc_procbuf.c index e6628946..41fa5597 100644 --- a/src/fastrpc_procbuf.c +++ b/src/fastrpc_procbuf.c @@ -1,119 +1,151 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause -#include #include -#include +#include #include +#include -#include "AEEstd.h" #include "AEEStdErr.h" -#include "verify.h" -#include "fastrpc_procbuf.h" +#include "AEEstd.h" +#include "HAP_farf_internal.h" #include "apps_std_internal.h" +#include "fastrpc_common.h" #include "fastrpc_config.h" #include "fastrpc_internal.h" //TODO: Bharath -#include "rpcmem_internal.h" -#include "fastrpc_common.h" -#include "HAP_farf_internal.h" +#include "fastrpc_procbuf.h" #include "fastrpc_process_attributes.h" +#include "rpcmem_internal.h" +#include "verify.h" /* size of buffer used to share the inital config params to dsp */ -#define PROC_SHAREDBUF_SIZE (4*1024) +#define PROC_SHAREDBUF_SIZE (4 * 1024) #define WORD_SIZE 4 extern struct handle_list *hlist; -int proc_sharedbuf_init(int dev, int domain) { - int proc_sharedbuf_size = PROC_SHAREDBUF_SIZE, sharedbuf_kernel_support = 1; +int +proc_sharedbuf_init(int dev, int domain) +{ + int proc_sharedbuf_size = PROC_SHAREDBUF_SIZE, + sharedbuf_kernel_support = 1; int nErr = AEE_SUCCESS, ioErr = 0; void *proc_sharedbuf = NULL; struct fastrpc_proc_sharedbuf_info sharedbuf_info; errno = 0; - VERIFYC(NULL != (proc_sharedbuf = rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, (size_t)proc_sharedbuf_size)), AEE_ENORPCMEMORY); + VERIFYC(NULL + != (proc_sharedbuf + = rpcmem_alloc_internal(0, RPCMEM_HEAP_DEFAULT, + (size_t)proc_sharedbuf_size)), + AEE_ENORPCMEMORY); hlist[domain].proc_sharedbuf = proc_sharedbuf; - VERIFYC(-1 != (sharedbuf_info.buf_fd = rpcmem_to_fd_internal(proc_sharedbuf)), AEE_ERPC); + VERIFYC(-1 + != (sharedbuf_info.buf_fd + = rpcmem_to_fd_internal(proc_sharedbuf)), + AEE_ERPC); sharedbuf_info.buf_size = proc_sharedbuf_size; ioErr = ioctl_sharedbuf(dev, &sharedbuf_info); - if (ioErr) { - if (errno == ENOTTY) { + if(ioErr) { + if(errno == ENOTTY) { sharedbuf_kernel_support = 0; - FARF(ERROR, "Error 0x%x: %s: sharedbuff capability not supported by kernel (errno %d, %s).", - nErr, __func__, errno, strerror(errno)); + FARF(ERROR, + "Error 0x%x: %s: sharedbuff capability not " + "supported by kernel (errno %d, %s).", + nErr, __func__, errno, strerror(errno)); } else { nErr = convert_kernel_to_user_error(nErr, errno); } } bail: - if (proc_sharedbuf && (nErr || !sharedbuf_kernel_support)) { + if(proc_sharedbuf && (nErr || !sharedbuf_kernel_support)) { rpcmem_free_internal(proc_sharedbuf); proc_sharedbuf = NULL; hlist[domain].proc_sharedbuf = NULL; } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for domain %d, errno %s, ioErr %d\n", - nErr, __func__, domain, strerror(errno), ioErr); + if(nErr != AEE_SUCCESS) { + FARF(ERROR, + "Error 0x%x: %s failed for domain %d, errno %s, ioErr " + "%d\n", + nErr, __func__, domain, strerror(errno), ioErr); } return nErr; } /* - * Function to pack the shared buffer with list of shared objects in custom DSP_LIBRARY_PATH. - * @lib_names : List of the shared objects present in the custom DSP_SEARCH_PATH set by user. + * Function to pack the shared buffer with list of shared objects in custom + * DSP_LIBRARY_PATH. + * @lib_names : List of the shared objects present in the custom + * DSP_SEARCH_PATH set by user. * @buffer_size : Number of characters to be packed. * Updated lib_names at the end (example) : lib1.so;lib2.so;lib3.so; */ -static int get_non_preload_lib_names (char** lib_names, size_t* buffer_size, int domain) +static int +get_non_preload_lib_names(char **lib_names, size_t *buffer_size, int domain) { - int nErr = AEE_SUCCESS, env_list_len = 0, concat_len = 0; - char* data_paths = NULL; - char *saveptr = NULL; + int nErr = AEE_SUCCESS, env_list_len = 0, concat_len = 0; + char *data_paths = NULL; + char *saveptr = NULL; size_t dsp_search_path_len = strlen(DSP_LIBRARY_PATH) + 1; VERIFYC(*lib_names != NULL, AEE_ENOMEMORY); - VERIFYC(NULL != (data_paths = calloc(1, sizeof(char) * dsp_search_path_len)), AEE_ENOMEMORY); - VERIFYC(AEE_SUCCESS == apps_std_getenv(DSP_LIBRARY_PATH, data_paths, dsp_search_path_len, &env_list_len), AEE_EGETENV); + VERIFYC(NULL + != (data_paths + = calloc(1, sizeof(char) * dsp_search_path_len)), + AEE_ENOMEMORY); + VERIFYC(AEE_SUCCESS + == apps_std_getenv(DSP_LIBRARY_PATH, data_paths, + dsp_search_path_len, &env_list_len), + AEE_EGETENV); - char* path = strtok_r(data_paths, ";", &saveptr); - while (path != NULL) - { + char *path = strtok_r(data_paths, ";", &saveptr); + while(path != NULL) { struct dirent *entry; DIR *dir = opendir(path); VERIFYC(NULL != dir, AEE_EBADPARM); - while ((entry = readdir(dir)) != NULL) { - if ( entry -> d_type == DT_REG) { - char* file = entry->d_name; - if (strstr(file, FILE_EXT) != NULL) { - if (concat_len + strlen(file) > MAX_NON_PRELOAD_LIBS_LEN) { - FARF(ALWAYS,"ERROR: Failed to pack library names in custom DSP_LIBRARY_PATH as required buffer size exceeds Max limit (%d).", MAX_NON_PRELOAD_LIBS_LEN); + while((entry = readdir(dir)) != NULL) { + if(entry->d_type == DT_REG) { + char *file = entry->d_name; + if(strstr(file, FILE_EXT) != NULL) { + if(concat_len + strlen(file) + > MAX_NON_PRELOAD_LIBS_LEN) { + FARF(ALWAYS, + "ERROR: Failed to pack " + "library names in custom " + "DSP_LIBRARY_PATH as " + "required buffer size " + "exceeds Max limit (%d).", + MAX_NON_PRELOAD_LIBS_LEN); nErr = AEE_EBUFFERTOOSMALL; closedir(dir); goto bail; } - strlcat(*lib_names, file, MAX_NON_PRELOAD_LIBS_LEN); - concat_len = strlcat(*lib_names, ";", MAX_NON_PRELOAD_LIBS_LEN); + strlcat(*lib_names, file, + MAX_NON_PRELOAD_LIBS_LEN); + concat_len = strlcat( + *lib_names, ";", + MAX_NON_PRELOAD_LIBS_LEN); } } } - if (dir != NULL) { + if(dir != NULL) { closedir(dir); } - path = strtok_r(NULL,";", &saveptr); + path = strtok_r(NULL, ";", &saveptr); } *buffer_size = strlen(*lib_names) + 1; bail: - if (data_paths) { + if(data_paths) { free(data_paths); data_paths = NULL; } - if (nErr && (nErr != AEE_EGETENV)) { - FARF(ERROR, "Error 0x%x: %s Failed for domain %d (%s)\n", - nErr, __func__, domain, strerror(errno)); + if(nErr && (nErr != AEE_EGETENV)) { + FARF(ERROR, "Error 0x%x: %s Failed for domain %d (%s)\n", nErr, + __func__, domain, strerror(errno)); } return nErr; } @@ -147,34 +179,43 @@ static int get_non_preload_lib_names (char** lib_names, size_t* buffer_size, int * returns 0 on success */ -static int pack_proc_shared_buf_params(int domain, uint32_t param_id, - void *param_addr, uint32_t param_size) +static int +pack_proc_shared_buf_params(int domain, uint32_t param_id, void *param_addr, + uint32_t param_size) { - uint32_t *buf_start_addr = (uint32_t*)hlist[domain].proc_sharedbuf; + uint32_t *buf_start_addr = (uint32_t *)hlist[domain].proc_sharedbuf; uint32_t align_param_size = param_size; /* Params pack address */ - uint32_t *buf_write_addr = (uint32_t*)hlist[domain].proc_sharedbuf_cur_addr, - *buf_last_addr = buf_start_addr + PROC_SHAREDBUF_SIZE; + uint32_t *buf_write_addr + = (uint32_t *)hlist[domain].proc_sharedbuf_cur_addr, + *buf_last_addr = buf_start_addr + PROC_SHAREDBUF_SIZE; - if (param_addr == NULL || param_size <= 0 || param_id < 0 || - param_id >= PROC_ATTR_BUF_MAX_ID) { - FARF(ERROR, "Error: %s: invalid param %u or size %u or addr 0x%x", - __func__, param_id, param_size, param_addr); + if(param_addr == NULL || param_size <= 0 || param_id < 0 + || param_id >= PROC_ATTR_BUF_MAX_ID) { + FARF(ERROR, + "Error: %s: invalid param %u or size %u or addr 0x%x", + __func__, param_id, param_size, param_addr); return AEE_EBADPARM; } - if (buf_write_addr == NULL) { + if(buf_write_addr == NULL) { /* - * Total no of param ids (4 bytes) are packed at shared buffer initial address, - * so add 4 bytes to start pack process params + * Total no of param ids (4 bytes) are packed at shared buffer + * initial address, so add 4 bytes to start pack process params */ - buf_write_addr = (uint32_t*)((char*)buf_start_addr + WORD_SIZE); + buf_write_addr + = (uint32_t *)((char *)buf_start_addr + WORD_SIZE); } - /* Align the params size in multiple of 4 bytes (word) for easy unpacking at DSP */ + /* Align the params size in multiple of 4 bytes (word) for easy + * unpacking at DSP */ align_param_size = ALIGN_B(param_size, WORD_SIZE); - if (buf_last_addr < (uint32_t*)((char*)buf_write_addr + align_param_size + sizeof(param_id))) { - FARF(ERROR, "Error: %s: proc shared buffer exhausted to pack param_id:%u params", - __func__, param_id); + if(buf_last_addr + < (uint32_t *)((char *)buf_write_addr + align_param_size + + sizeof(param_id))) { + FARF(ERROR, + "Error: %s: proc shared buffer exhausted to pack " + "param_id:%u params", + __func__, param_id); return AEE_ERPC; } /* Write param_id */ @@ -184,11 +225,14 @@ static int pack_proc_shared_buf_params(int domain, uint32_t param_id, *buf_write_addr = (*buf_write_addr) << PROC_ATTR_BUF_ID_POS; /* Write param size in last 24 bits */ - *buf_write_addr = (*buf_write_addr) + (PROC_ATTR_BUF_ID_SIZE_MASK & align_param_size); + *buf_write_addr = (*buf_write_addr) + + (PROC_ATTR_BUF_ID_SIZE_MASK & align_param_size); buf_write_addr++; - memcpy(buf_write_addr, param_addr, STD_MIN(buf_last_addr - buf_write_addr, param_size)); - buf_write_addr = (uint32_t*)((char*)buf_write_addr + align_param_size); + memcpy(buf_write_addr, param_addr, + STD_MIN(buf_last_addr - buf_write_addr, param_size)); + buf_write_addr + = (uint32_t *)((char *)buf_write_addr + align_param_size); hlist[domain].proc_sharedbuf_cur_addr = buf_write_addr; /* Increase the number of ids in start address */ @@ -202,69 +246,93 @@ static int pack_proc_shared_buf_params(int domain, uint32_t param_id, * @ domain: domain to retrieve the process shared buffer address * returns none */ -void fastrpc_process_pack_params(int dev, int domain) { - int nErr = AEE_SUCCESS, sess_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); - struct err_codes* err_codes_to_send = NULL; +void +fastrpc_process_pack_params(int dev, int domain) +{ + int nErr = AEE_SUCCESS, + sess_id = GET_SESSION_ID_FROM_DOMAIN_ID(domain); + struct err_codes *err_codes_to_send = NULL; size_t buffer_size = 0; char *lib_names = NULL; pid_t pid = getpid(); - if (AEE_SUCCESS != proc_sharedbuf_init(dev, domain)) { + if(AEE_SUCCESS != proc_sharedbuf_init(dev, domain)) { return; } - if (!hlist[domain].proc_sharedbuf) { + if(!hlist[domain].proc_sharedbuf) { return; } - nErr = pack_proc_shared_buf_params(domain, HLOS_PID_ID, - &pid, sizeof(pid)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack process id in shared buffer", - nErr, __func__); + nErr = pack_proc_shared_buf_params(domain, HLOS_PID_ID, &pid, + sizeof(pid)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack process id in shared " + "buffer", + nErr, __func__); } nErr = pack_proc_shared_buf_params(domain, THREAD_PARAM_ID, - &hlist[domain].th_params, sizeof(hlist[domain].th_params)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack thread parameters in shared buffer", - nErr, __func__); + &hlist[domain].th_params, + sizeof(hlist[domain].th_params)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack thread parameters in " + "shared buffer", + nErr, __func__); } nErr = pack_proc_shared_buf_params(domain, PROC_ATTR_ID, - &hlist[domain].procattrs, sizeof(hlist[domain].procattrs)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack process config parameters in shared buffer", - nErr, __func__); + &hlist[domain].procattrs, + sizeof(hlist[domain].procattrs)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack process config " + "parameters in shared buffer", + nErr, __func__); } err_codes_to_send = fastrpc_config_get_errcodes(); - if (err_codes_to_send) { + if(err_codes_to_send) { nErr = pack_proc_shared_buf_params(domain, PANIC_ERR_CODES_ID, - err_codes_to_send, sizeof(*err_codes_to_send)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack panic error codes in shared buffer", - nErr, __func__); + err_codes_to_send, + sizeof(*err_codes_to_send)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack panic error " + "codes in shared buffer", + nErr, __func__); } } nErr = pack_proc_shared_buf_params(domain, HLOS_PROC_EFFEC_DOM_ID, - &domain, sizeof(domain)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack effective domain id %d in shared buffer", - nErr, __func__, domain); + &domain, sizeof(domain)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack effective domain id %d " + "in shared buffer", + nErr, __func__, domain); } lib_names = (char *)malloc(sizeof(char) * MAX_NON_PRELOAD_LIBS_LEN); - if (lib_names) { - if (AEE_SUCCESS == get_non_preload_lib_names(&lib_names, &buffer_size, domain)) { - nErr = pack_proc_shared_buf_params(domain, CUSTOM_DSP_SEARCH_PATH_LIBS_ID, lib_names, buffer_size); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack the directory list in shared buffer", - nErr, __func__); + if(lib_names) { + if(AEE_SUCCESS + == get_non_preload_lib_names(&lib_names, &buffer_size, + domain)) { + nErr = pack_proc_shared_buf_params( + domain, CUSTOM_DSP_SEARCH_PATH_LIBS_ID, lib_names, + buffer_size); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack the " + "directory list in shared buffer", + nErr, __func__); } } } - nErr = pack_proc_shared_buf_params(domain, HLOS_PROC_SESS_ID, - &sess_id, sizeof(sess_id)); - if (nErr) { - FARF(ERROR, "Error 0x%x: %s: Failed to pack session id %d in shared buffer", - nErr, __func__, sess_id); + nErr = pack_proc_shared_buf_params(domain, HLOS_PROC_SESS_ID, &sess_id, + sizeof(sess_id)); + if(nErr) { + FARF(ERROR, + "Error 0x%x: %s: Failed to pack session id %d in shared " + "buffer", + nErr, __func__, sess_id); } - if (lib_names){ + if(lib_names) { free(lib_names); lib_names = NULL; } diff --git a/src/gpls.c b/src/gpls.c index 0d69ef59..73208d06 100644 --- a/src/gpls.c +++ b/src/gpls.c @@ -10,43 +10,63 @@ static struct pls_table gpls; const char pls_version[] = VERSION_STRING; -int gpls_init(void) { - pls_ctor(&gpls, 1); - return 0; +int +gpls_init(void) +{ + pls_ctor(&gpls, 1); + return 0; } -void gpls_deinit(void) { pls_thread_deinit(&gpls); } +void +gpls_deinit(void) +{ + pls_thread_deinit(&gpls); +} -int HAP_pls_add(uintptr_t type, uintptr_t key, int size, - int (*ctor)(void *ctx, void *data), void *ctx, - void (*dtor)(void *), void **ppo) { - return pls_add(&gpls, type, key, size, ctor, ctx, dtor, ppo); +int +HAP_pls_add(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo) +{ + return pls_add(&gpls, type, key, size, ctor, ctx, dtor, ppo); } -int HAP_pls_add_lookup(uintptr_t type, uintptr_t key, int size, - int (*ctor)(void *ctx, void *data), void *ctx, - void (*dtor)(void *), void **ppo) { - return pls_add_lookup_singleton(&gpls, type, key, size, ctor, ctx, dtor, ppo); +int +HAP_pls_add_lookup(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo) +{ + return pls_add_lookup_singleton(&gpls, type, key, size, ctor, ctx, + dtor, ppo); } -int HAP_pls_lookup(uintptr_t type, uintptr_t key, void **ppo) { - return pls_lookup(&gpls, type, key, ppo); +int +HAP_pls_lookup(uintptr_t type, uintptr_t key, void **ppo) +{ + return pls_lookup(&gpls, type, key, ppo); } -int adsp_pls_add(uintptr_t type, uintptr_t key, int size, - int (*ctor)(void *ctx, void *data), void *ctx, - void (*dtor)(void *), void **ppo) { - return pls_add(&gpls, type, key, size, ctor, ctx, dtor, ppo); +int +adsp_pls_add(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo) +{ + return pls_add(&gpls, type, key, size, ctor, ctx, dtor, ppo); } -int adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, - int (*ctor)(void *ctx, void *data), void *ctx, - void (*dtor)(void *), void **ppo) { - return pls_add_lookup_singleton(&gpls, type, key, size, ctor, ctx, dtor, ppo); +int +adsp_pls_add_lookup(uintptr_t type, uintptr_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *), void **ppo) +{ + return pls_add_lookup_singleton(&gpls, type, key, size, ctor, ctx, + dtor, ppo); } -int adsp_pls_lookup(uintptr_t type, uintptr_t key, void **ppo) { - return pls_lookup(&gpls, type, key, ppo); +int +adsp_pls_lookup(uintptr_t type, uintptr_t key, void **ppo) +{ + return pls_lookup(&gpls, type, key, ppo); } PL_DEFINE(gpls, gpls_init, gpls_deinit) diff --git a/src/listener_android.c b/src/listener_android.c index 712945ce..f77d2f4f 100644 --- a/src/listener_android.c +++ b/src/listener_android.c @@ -21,27 +21,27 @@ #include "AEEStdErr.h" #include "AEEstd.h" #include "HAP_farf.h" -#include "rpcmem_internal.h" #include "adsp_listener.h" #include "adsp_listener1.h" #include "fastrpc_common.h" +#include "fastrpc_hash_table.h" #include "fastrpc_internal.h" #include "listener_buf.h" #include "mod_table.h" #include "platform_libs.h" #include "rpcmem.h" +#include "rpcmem_internal.h" #include "shared.h" #include "verify.h" -#include "fastrpc_hash_table.h" typedef struct { - pthread_t thread; - int eventfd; - int update_requested; - int params_updated; - sem_t *r_sem; - remote_handle64 adsp_listener1_handle; - ADD_DOMAIN_HASH(); + pthread_t thread; + int eventfd; + int update_requested; + int params_updated; + sem_t *r_sem; + remote_handle64 adsp_listener1_handle; + ADD_DOMAIN_HASH(); } listener_config; DECLARE_HASH_TABLE(listener, listener_config); @@ -49,280 +49,315 @@ DECLARE_HASH_TABLE(listener, listener_config); extern void set_thread_context(int domain); __QAIC_IMPL_EXPORT int -__QAIC_IMPL(apps_remotectl_open)(const char *name, uint32_t *handle, char *dlStr, - int dlerrorLen, - int *dlErr) __QAIC_IMPL_ATTRIBUTE { - int domain = get_current_domain(); - int nErr = AEE_SUCCESS; - remote_handle64 local; - VERIFY(AEE_SUCCESS == - (nErr = mod_table_open(name, handle, dlStr, dlerrorLen, dlErr))); - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_update_module_list( - REVERSE_HANDLE_LIST_PREPEND, domain, (remote_handle)*handle, &local, NULL))); +__QAIC_IMPL(apps_remotectl_open)(const char *name, uint32_t *handle, + char *dlStr, int dlerrorLen, + int *dlErr) __QAIC_IMPL_ATTRIBUTE +{ + int domain = get_current_domain(); + int nErr = AEE_SUCCESS; + remote_handle64 local; + VERIFY(AEE_SUCCESS + == (nErr + = mod_table_open(name, handle, dlStr, dlerrorLen, dlErr))); + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + REVERSE_HANDLE_LIST_PREPEND, domain, + (remote_handle)*handle, &local, NULL))); bail: - return nErr; + return nErr; } __QAIC_IMPL_EXPORT int __QAIC_IMPL(apps_remotectl_close)(uint32_t handle, char *errStr, int errStrLen, - int *dlErr) __QAIC_IMPL_ATTRIBUTE { - int domain = get_current_domain(); - int nErr = AEE_SUCCESS; - - if (AEE_SUCCESS != - (nErr = mod_table_close(handle, errStr, errStrLen, dlErr))) { - if(!is_process_exiting(domain)) { - FARF(ERROR, - "Error 0x%x: %s: mod_table_close failed for handle:0x%x (dlErr %s)", - nErr, __func__, handle, (char *)dlErr); - } - goto bail; - } - VERIFY(AEE_SUCCESS == - (nErr = fastrpc_update_module_list( - REVERSE_HANDLE_LIST_DEQUEUE, domain, (remote_handle)handle, NULL, NULL))); + int *dlErr) __QAIC_IMPL_ATTRIBUTE +{ + int domain = get_current_domain(); + int nErr = AEE_SUCCESS; + + if(AEE_SUCCESS + != (nErr = mod_table_close(handle, errStr, errStrLen, dlErr))) { + if(!is_process_exiting(domain)) { + FARF(ERROR, + "Error 0x%x: %s: mod_table_close failed for " + "handle:0x%x (dlErr %s)", + nErr, __func__, handle, (char *)dlErr); + } + goto bail; + } + VERIFY(AEE_SUCCESS + == (nErr = fastrpc_update_module_list( + REVERSE_HANDLE_LIST_DEQUEUE, domain, + (remote_handle)handle, NULL, NULL))); bail: - return nErr; + return nErr; } -#define RPC_FREEIF(buf) \ - do { \ - if (buf) { \ - rpcmem_free_internal(buf); \ - buf = 0; \ - } \ - } while (0) - -static __inline void *rpcmem_realloc(int heapid, uint32_t flags, void *buf, - int oldsize, size_t size) { - void *bufnew = rpcmem_alloc_internal(heapid, flags, size); - if (buf && bufnew) { - memmove(bufnew, buf, STD_MIN(oldsize, size)); - rpcmem_free_internal(buf); - buf = NULL; - } - return bufnew; +#define RPC_FREEIF(buf) \ + do { \ + if(buf) { \ + rpcmem_free_internal(buf); \ + buf = 0; \ + } \ + } while(0) + +static __inline void * +rpcmem_realloc(int heapid, uint32_t flags, void *buf, int oldsize, size_t size) +{ + void *bufnew = rpcmem_alloc_internal(heapid, flags, size); + if(buf && bufnew) { + memmove(bufnew, buf, STD_MIN(oldsize, size)); + rpcmem_free_internal(buf); + buf = NULL; + } + return bufnew; } #define MIN_BUF_SIZE 0x1000 #define ALIGNB(sz) ((sz) == 0 ? MIN_BUF_SIZE : _SBUF_ALIGN((sz), MIN_BUF_SIZE)) -static void listener(listener_config *me) { - int nErr = AEE_SUCCESS, i = 0, domain = me->domain, ref = 0; - adsp_listener1_invoke_ctx ctx = 0; - uint8_t *outBufs = 0; - int outBufsLen = 0, outBufsCapacity = 0; - uint8_t *inBufs = 0; - int inBufsLen = 0, inBufsLenReq = 0; - int result = -1, bufs_len = 0; - adsp_listener1_remote_handle handle = -1; - uint32_t sc = 0; - const char *eheap = getenv("ADSP_LISTENER_HEAP_ID"); - int heapid = eheap == 0 ? -1 : atoi(eheap); - const char *eflags = getenv("ADSP_LISTENER_HEAP_FLAGS"); - uint32_t flags = eflags == 0 ? 0 : (uint32_t)atoi(eflags); - const char *emin = getenv("ADSP_LISTENER_MEM_CACHE_SIZE"); - int cache_size = emin == 0 ? 0 : atoi(emin); - remote_arg args[512]; - struct sbuf buf; - eventfd_t event = 0xff; - - FARF(ALWAYS, "%s thread starting\n", __func__); - memset(args, 0, sizeof(args)); - if (eheap || eflags || emin) { - FARF(RUNTIME_RPC_HIGH, - "listener using ion heap: %d flags: %x cache: %lld\n", (int)heapid, - (int)flags, cache_size); - } - - do { - invoke: - sc = 0xffffffff; - if (result != 0) { - outBufsLen = 0; - } - FARF(RUNTIME_RPC_HIGH, - "%s responding 0x%x for ctx 0x%x, handle 0x%x, sc 0x%x", __func__, - result, ctx, handle, sc); - FASTRPC_PUT_REF(domain); - if (me->adsp_listener1_handle != INVALID_HANDLE) { - nErr = __QAIC_HEADER(adsp_listener1_next2)( - me->adsp_listener1_handle, ctx, result, outBufs, outBufsLen, &ctx, - &handle, &sc, inBufs, inBufsLen, &inBufsLenReq); - } else { - nErr = __QAIC_HEADER(adsp_listener_next2)( - ctx, result, outBufs, outBufsLen, &ctx, &handle, &sc, inBufs, - inBufsLen, &inBufsLenReq); - } - if (nErr) { - if (nErr == AEE_EINTERRUPTED) { - /* UserPD in CPZ migration. Keep retrying until migration is complete. - * Also reset the context, as previous context is invalid after CPZ - * migration - */ - ctx = 0; - result = -1; - goto invoke; - } else if (nErr == (DSP_AEE_EOFFSET + AEE_EBADSTATE)) { - /* UserPD in irrecoverable bad state. Exit listener */ - goto bail; - } - /* For any other error, retry once and exit if error seen again */ - if (me->adsp_listener1_handle != INVALID_HANDLE) { - nErr = __QAIC_HEADER(adsp_listener1_next2)( - me->adsp_listener1_handle, ctx, nErr, 0, 0, &ctx, &handle, &sc, - inBufs, inBufsLen, &inBufsLenReq); - } else { - nErr = __QAIC_HEADER(adsp_listener_next2)(ctx, nErr, 0, 0, &ctx, - &handle, &sc, inBufs, - inBufsLen, &inBufsLenReq); - } - if (nErr) { - FARF(RUNTIME_HIGH, - "Error 0x%x: %s response with result 0x%x for ctx 0x%x, handle " - "0x%x, sc 0x%x failed\n", - nErr, __func__, result, ctx, handle, sc); - goto bail; - } - } - FASTRPC_GET_REF(domain); - if (__builtin_smul_overflow(inBufsLenReq, 2, &bufs_len)) { - FARF(ERROR, - "Error: %s: overflow occurred while multiplying input buffer size: " - "%d * 2 = %d for handle 0x%x, sc 0x%x", - __func__, inBufsLenReq, bufs_len, handle, sc); - result = AEE_EBADSIZE; - goto invoke; - } - if (ALIGNB(bufs_len) < inBufsLen && inBufsLen > cache_size) { - void *buf; - int size = ALIGNB(bufs_len); - if (NULL == - (buf = rpcmem_realloc(heapid, flags, inBufs, inBufsLen, size))) { - result = AEE_ENORPCMEMORY; - FARF(RUNTIME_RPC_HIGH, "rpcmem_realloc shrink failed"); - goto invoke; - } - inBufs = buf; - inBufsLen = size; - } - if (inBufsLenReq > inBufsLen) { - void *buf; - int req; - int oldLen = inBufsLen; - int size = _SBUF_ALIGN(inBufsLenReq, MIN_BUF_SIZE); - if (AEE_SUCCESS == - (buf = rpcmem_realloc(heapid, flags, inBufs, inBufsLen, size))) { - result = AEE_ENORPCMEMORY; - FARF(ERROR, "rpcmem_realloc failed"); - goto invoke; - } - inBufs = buf; - inBufsLen = size; - if (me->adsp_listener1_handle != INVALID_HANDLE) { - result = __QAIC_HEADER(adsp_listener1_get_in_bufs2)( - me->adsp_listener1_handle, ctx, oldLen, inBufs + oldLen, - inBufsLen - oldLen, &req); - } else { - result = __QAIC_HEADER(adsp_listener_get_in_bufs2)( - ctx, oldLen, inBufs + oldLen, inBufsLen - oldLen, &req); - } - if (AEE_SUCCESS != result) { - FARF(RUNTIME_RPC_HIGH, "adsp_listener_invoke_get_in_bufs2 failed %x", - result); - goto invoke; - } - if (req > inBufsLen) { - result = AEE_EBADPARM; - FARF(RUNTIME_RPC_HIGH, - "adsp_listener_invoke_get_in_bufs2 failed, size is invalid req %d " - "inBufsLen %d result %d", - req, inBufsLen, result); - goto invoke; - } - } - if (REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc) > 0) { - result = AEE_EBADPARM; - goto invoke; - } - - sbuf_init(&buf, 0, inBufs, inBufsLen); - unpack_in_bufs(&buf, args, REMOTE_SCALARS_INBUFS(sc)); - unpack_out_lens(&buf, args + REMOTE_SCALARS_INBUFS(sc), - REMOTE_SCALARS_OUTBUFS(sc)); - - sbuf_init(&buf, 0, 0, 0); - pack_out_bufs(&buf, args + REMOTE_SCALARS_INBUFS(sc), - REMOTE_SCALARS_OUTBUFS(sc)); - outBufsLen = sbuf_needed(&buf); - - if (__builtin_smul_overflow(outBufsLen, 2, &bufs_len)) { - FARF(ERROR, - "%s: Overflow occured while multiplying output buffer size: %d * 2 " - "= %d", - __func__, outBufsLen, bufs_len); - result = AEE_EBADSIZE; - goto invoke; - } - if (ALIGNB(bufs_len) < outBufsCapacity && outBufsCapacity > cache_size) { - void *buf; - int size = ALIGNB(bufs_len); - if (NULL == (buf = rpcmem_realloc(heapid, flags, outBufs, outBufsCapacity, - size))) { - result = AEE_ENORPCMEMORY; - FARF(RUNTIME_RPC_HIGH, "listener rpcmem_realloc shrink failed"); - goto invoke; - } - outBufs = buf; - outBufsCapacity = size; - } - if (outBufsLen > outBufsCapacity) { - void *buf; - int size = ALIGNB(outBufsLen); - if (NULL == (buf = rpcmem_realloc(heapid, flags, outBufs, outBufsCapacity, - size))) { - result = AEE_ENORPCMEMORY; - FARF(ERROR, "listener rpcmem_realloc failed"); - goto invoke; - } - outBufs = buf; - outBufsLen = size; - outBufsCapacity = size; - } - sbuf_init(&buf, 0, outBufs, outBufsLen); - pack_out_bufs(&buf, args + REMOTE_SCALARS_INBUFS(sc), - REMOTE_SCALARS_OUTBUFS(sc)); - result = mod_table_invoke(handle, sc, args); - if (result && is_process_exiting(domain)) - result = AEE_EBADSTATE; // override result as process is exiting - } while (1); +static void +listener(listener_config *me) +{ + int nErr = AEE_SUCCESS, i = 0, domain = me->domain, ref = 0; + adsp_listener1_invoke_ctx ctx = 0; + uint8_t *outBufs = 0; + int outBufsLen = 0, outBufsCapacity = 0; + uint8_t *inBufs = 0; + int inBufsLen = 0, inBufsLenReq = 0; + int result = -1, bufs_len = 0; + adsp_listener1_remote_handle handle = -1; + uint32_t sc = 0; + const char *eheap = getenv("ADSP_LISTENER_HEAP_ID"); + int heapid = eheap == 0 ? -1 : atoi(eheap); + const char *eflags = getenv("ADSP_LISTENER_HEAP_FLAGS"); + uint32_t flags = eflags == 0 ? 0 : (uint32_t)atoi(eflags); + const char *emin = getenv("ADSP_LISTENER_MEM_CACHE_SIZE"); + int cache_size = emin == 0 ? 0 : atoi(emin); + remote_arg args[512]; + struct sbuf buf; + eventfd_t event = 0xff; + + FARF(ALWAYS, "%s thread starting\n", __func__); + memset(args, 0, sizeof(args)); + if(eheap || eflags || emin) { + FARF(RUNTIME_RPC_HIGH, + "listener using ion heap: %d flags: %x cache: %lld\n", + (int)heapid, (int)flags, cache_size); + } + + do { + invoke: + sc = 0xffffffff; + if(result != 0) { + outBufsLen = 0; + } + FARF(RUNTIME_RPC_HIGH, + "%s responding 0x%x for ctx 0x%x, handle 0x%x, sc 0x%x", + __func__, result, ctx, handle, sc); + FASTRPC_PUT_REF(domain); + if(me->adsp_listener1_handle != INVALID_HANDLE) { + nErr = __QAIC_HEADER(adsp_listener1_next2)( + me->adsp_listener1_handle, ctx, result, outBufs, + outBufsLen, &ctx, &handle, &sc, inBufs, inBufsLen, + &inBufsLenReq); + } else { + nErr = __QAIC_HEADER(adsp_listener_next2)( + ctx, result, outBufs, outBufsLen, &ctx, &handle, + &sc, inBufs, inBufsLen, &inBufsLenReq); + } + if(nErr) { + if(nErr == AEE_EINTERRUPTED) { + /* UserPD in CPZ migration. Keep retrying until + * migration is complete. Also reset the + * context, as previous context is invalid + * after CPZ migration + */ + ctx = 0; + result = -1; + goto invoke; + } else if(nErr == (DSP_AEE_EOFFSET + AEE_EBADSTATE)) { + /* UserPD in irrecoverable bad state. Exit + * listener */ + goto bail; + } + /* For any other error, retry once and exit if error + * seen again */ + if(me->adsp_listener1_handle != INVALID_HANDLE) { + nErr = __QAIC_HEADER(adsp_listener1_next2)( + me->adsp_listener1_handle, ctx, nErr, 0, 0, + &ctx, &handle, &sc, inBufs, inBufsLen, + &inBufsLenReq); + } else { + nErr = __QAIC_HEADER(adsp_listener_next2)( + ctx, nErr, 0, 0, &ctx, &handle, &sc, + inBufs, inBufsLen, &inBufsLenReq); + } + if(nErr) { + FARF(RUNTIME_HIGH, + "Error 0x%x: %s response with result " + "0x%x for ctx 0x%x, handle " + "0x%x, sc 0x%x failed\n", + nErr, __func__, result, ctx, handle, sc); + goto bail; + } + } + FASTRPC_GET_REF(domain); + if(__builtin_smul_overflow(inBufsLenReq, 2, &bufs_len)) { + FARF(ERROR, + "Error: %s: overflow occurred while multiplying " + "input buffer size: " + "%d * 2 = %d for handle 0x%x, sc 0x%x", + __func__, inBufsLenReq, bufs_len, handle, sc); + result = AEE_EBADSIZE; + goto invoke; + } + if(ALIGNB(bufs_len) < inBufsLen && inBufsLen > cache_size) { + void *buf; + int size = ALIGNB(bufs_len); + if(NULL + == (buf = rpcmem_realloc(heapid, flags, inBufs, + inBufsLen, size))) { + result = AEE_ENORPCMEMORY; + FARF(RUNTIME_RPC_HIGH, + "rpcmem_realloc shrink failed"); + goto invoke; + } + inBufs = buf; + inBufsLen = size; + } + if(inBufsLenReq > inBufsLen) { + void *buf; + int req; + int oldLen = inBufsLen; + int size = _SBUF_ALIGN(inBufsLenReq, MIN_BUF_SIZE); + if(AEE_SUCCESS + == (buf = rpcmem_realloc(heapid, flags, inBufs, + inBufsLen, size))) { + result = AEE_ENORPCMEMORY; + FARF(ERROR, "rpcmem_realloc failed"); + goto invoke; + } + inBufs = buf; + inBufsLen = size; + if(me->adsp_listener1_handle != INVALID_HANDLE) { + result = __QAIC_HEADER( + adsp_listener1_get_in_bufs2)( + me->adsp_listener1_handle, ctx, oldLen, + inBufs + oldLen, inBufsLen - oldLen, &req); + } else { + result = __QAIC_HEADER( + adsp_listener_get_in_bufs2)( + ctx, oldLen, inBufs + oldLen, + inBufsLen - oldLen, &req); + } + if(AEE_SUCCESS != result) { + FARF(RUNTIME_RPC_HIGH, + "adsp_listener_invoke_get_in_bufs2 " + "failed %x", + result); + goto invoke; + } + if(req > inBufsLen) { + result = AEE_EBADPARM; + FARF(RUNTIME_RPC_HIGH, + "adsp_listener_invoke_get_in_bufs2 " + "failed, size is invalid req %d " + "inBufsLen %d result %d", + req, inBufsLen, result); + goto invoke; + } + } + if(REMOTE_SCALARS_INHANDLES(sc) + REMOTE_SCALARS_OUTHANDLES(sc) + > 0) { + result = AEE_EBADPARM; + goto invoke; + } + + sbuf_init(&buf, 0, inBufs, inBufsLen); + unpack_in_bufs(&buf, args, REMOTE_SCALARS_INBUFS(sc)); + unpack_out_lens(&buf, args + REMOTE_SCALARS_INBUFS(sc), + REMOTE_SCALARS_OUTBUFS(sc)); + + sbuf_init(&buf, 0, 0, 0); + pack_out_bufs(&buf, args + REMOTE_SCALARS_INBUFS(sc), + REMOTE_SCALARS_OUTBUFS(sc)); + outBufsLen = sbuf_needed(&buf); + + if(__builtin_smul_overflow(outBufsLen, 2, &bufs_len)) { + FARF(ERROR, + "%s: Overflow occured while multiplying output " + "buffer size: %d * 2 " + "= %d", + __func__, outBufsLen, bufs_len); + result = AEE_EBADSIZE; + goto invoke; + } + if(ALIGNB(bufs_len) < outBufsCapacity + && outBufsCapacity > cache_size) { + void *buf; + int size = ALIGNB(bufs_len); + if(NULL + == (buf = rpcmem_realloc(heapid, flags, outBufs, + outBufsCapacity, size))) { + result = AEE_ENORPCMEMORY; + FARF(RUNTIME_RPC_HIGH, + "listener rpcmem_realloc shrink failed"); + goto invoke; + } + outBufs = buf; + outBufsCapacity = size; + } + if(outBufsLen > outBufsCapacity) { + void *buf; + int size = ALIGNB(outBufsLen); + if(NULL + == (buf = rpcmem_realloc(heapid, flags, outBufs, + outBufsCapacity, size))) { + result = AEE_ENORPCMEMORY; + FARF(ERROR, "listener rpcmem_realloc failed"); + goto invoke; + } + outBufs = buf; + outBufsLen = size; + outBufsCapacity = size; + } + sbuf_init(&buf, 0, outBufs, outBufsLen); + pack_out_bufs(&buf, args + REMOTE_SCALARS_INBUFS(sc), + REMOTE_SCALARS_OUTBUFS(sc)); + result = mod_table_invoke(handle, sc, args); + if(result && is_process_exiting(domain)) + result = AEE_EBADSTATE; // override result as process + // is exiting + } while(1); bail: - me->adsp_listener1_handle = INVALID_HANDLE; - RPC_FREEIF(outBufs); - RPC_FREEIF(inBufs); - if (nErr != AEE_SUCCESS) { - if(!is_process_exiting(domain)) { - FARF(ERROR, - "Error 0x%x: %s response with result 0x%x for ctx 0x%x, handle 0x%x, " - "sc 0x%x failed : listener thread exited (errno %s)", - nErr, __func__, result, ctx, handle, sc, strerror(errno)); - } - } - for (i = 0; i < RETRY_WRITE; i++) { - if (AEE_SUCCESS == (nErr = eventfd_write(me->eventfd, event))) { - break; - } - // Sleep for 1 sec before retry writing - sleep(1); - } - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF( - "Error 0x%x : Writing to listener event_fd %d failed (errno %s)", nErr, - me->eventfd, strerror(errno)); - } - FARF(ALWAYS, "%s thread exiting\n", __func__); - dlerror(); + me->adsp_listener1_handle = INVALID_HANDLE; + RPC_FREEIF(outBufs); + RPC_FREEIF(inBufs); + if(nErr != AEE_SUCCESS) { + if(!is_process_exiting(domain)) { + FARF(ERROR, + "Error 0x%x: %s response with result 0x%x for " + "ctx 0x%x, handle 0x%x, " + "sc 0x%x failed : listener thread exited (errno " + "%s)", + nErr, __func__, result, ctx, handle, sc, + strerror(errno)); + } + } + for(i = 0; i < RETRY_WRITE; i++) { + if(AEE_SUCCESS == (nErr = eventfd_write(me->eventfd, event))) { + break; + } + // Sleep for 1 sec before retry writing + sleep(1); + } + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x : Writing to listener event_fd %d " + "failed (errno %s)", + nErr, me->eventfd, strerror(errno)); + } + FARF(ALWAYS, "%s thread exiting\n", __func__); + dlerror(); } extern int apps_remotectl_skel_invoke(uint32_t _sc, remote_arg *_pra); @@ -334,161 +369,191 @@ extern int fastrpc_set_remote_uthread_params(int domain); PL_DEP(mod_table); PL_DEP(apps_std); -static void *listener_start_thread(void *arg) { - int nErr = AEE_SUCCESS; - listener_config *me = (listener_config *)arg; - int domain = me->domain; - remote_handle64 adsp_listener1_handle = INVALID_HANDLE; - - /* - * Need to set TLS key of listener thread to right domain. - * Otherwise, the init2() call will go to default domain. - */ - set_thread_context(domain); - if ((adsp_listener1_handle = get_adsp_listener1_handle(domain)) != INVALID_HANDLE) { - nErr = __QAIC_HEADER(adsp_listener1_init2)(adsp_listener1_handle); - if ((nErr == DSP_AEE_EOFFSET + AEE_ERPC) || - nErr == DSP_AEE_EOFFSET + AEE_ENOSUCHMOD) { - FARF(ERROR, "Error 0x%x: %s domains support not available in listener", - nErr, __func__); - fastrpc_update_module_list(DOMAIN_LIST_DEQUEUE, domain, _const_adsp_listener1_handle, NULL, NULL); - adsp_listener1_handle = INVALID_HANDLE; - VERIFY(AEE_SUCCESS == (nErr = __QAIC_HEADER(adsp_listener_init2)())); - } else if (nErr == AEE_SUCCESS) { - me->adsp_listener1_handle = adsp_listener1_handle; - } - } else { - VERIFY(AEE_SUCCESS == (nErr = __QAIC_HEADER(adsp_listener_init2)())); - } - - if (me->update_requested) { - /* Update parameters on DSP and signal main thread to proceed */ - me->params_updated = fastrpc_set_remote_uthread_params(domain); - sem_post(me->r_sem); - VERIFY(AEE_SUCCESS == (nErr = me->params_updated)); - } - listener(me); +static void * +listener_start_thread(void *arg) +{ + int nErr = AEE_SUCCESS; + listener_config *me = (listener_config *)arg; + int domain = me->domain; + remote_handle64 adsp_listener1_handle = INVALID_HANDLE; + + /* + * Need to set TLS key of listener thread to right domain. + * Otherwise, the init2() call will go to default domain. + */ + set_thread_context(domain); + if((adsp_listener1_handle = get_adsp_listener1_handle(domain)) + != INVALID_HANDLE) { + nErr = __QAIC_HEADER(adsp_listener1_init2)( + adsp_listener1_handle); + if((nErr == DSP_AEE_EOFFSET + AEE_ERPC) + || nErr == DSP_AEE_EOFFSET + AEE_ENOSUCHMOD) { + FARF(ERROR, + "Error 0x%x: %s domains support not available in " + "listener", + nErr, __func__); + fastrpc_update_module_list( + DOMAIN_LIST_DEQUEUE, domain, + _const_adsp_listener1_handle, NULL, NULL); + adsp_listener1_handle = INVALID_HANDLE; + VERIFY( + AEE_SUCCESS + == (nErr = __QAIC_HEADER(adsp_listener_init2)())); + } else if(nErr == AEE_SUCCESS) { + me->adsp_listener1_handle = adsp_listener1_handle; + } + } else { + VERIFY(AEE_SUCCESS + == (nErr = __QAIC_HEADER(adsp_listener_init2)())); + } + + if(me->update_requested) { + /* Update parameters on DSP and signal main thread to proceed + */ + me->params_updated = fastrpc_set_remote_uthread_params(domain); + sem_post(me->r_sem); + VERIFY(AEE_SUCCESS == (nErr = me->params_updated)); + } + listener(me); bail: - me->adsp_listener1_handle = INVALID_HANDLE; - if (nErr != AEE_SUCCESS) { - sem_post(me->r_sem); - VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d\n", nErr, __func__, - domain); - } - return (void *)(uintptr_t)nErr; + me->adsp_listener1_handle = INVALID_HANDLE; + if(nErr != AEE_SUCCESS) { + sem_post(me->r_sem); + VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d\n", nErr, + __func__, domain); + } + return (void *)(uintptr_t)nErr; } -void listener_android_deinit(void) { - HASH_TABLE_CLEANUP(listener_config); - PL_DEINIT(mod_table); - PL_DEINIT(apps_std); +void +listener_android_deinit(void) +{ + HASH_TABLE_CLEANUP(listener_config); + PL_DEINIT(mod_table); + PL_DEINIT(apps_std); } -int listener_android_init(void) { - int nErr = 0; - - HASH_TABLE_INIT(listener_config); - - VERIFY(AEE_SUCCESS == (nErr = PL_INIT(mod_table))); - VERIFY(AEE_SUCCESS == (nErr = PL_INIT(apps_std))); - VERIFY(AEE_SUCCESS == (nErr = mod_table_register_const_handle( - 0, "apps_remotectl", apps_remotectl_skel_invoke))); - VERIFY(AEE_SUCCESS == - (nErr = mod_table_register_static("apps_std", apps_std_skel_invoke))); - VERIFY(AEE_SUCCESS == - (nErr = mod_table_register_static("apps_mem", apps_mem_skel_invoke))); - VERIFY(AEE_SUCCESS == (nErr = mod_table_register_static( - "adspmsgd_apps", adspmsgd_apps_skel_invoke))); +int +listener_android_init(void) +{ + int nErr = 0; + + HASH_TABLE_INIT(listener_config); + + VERIFY(AEE_SUCCESS == (nErr = PL_INIT(mod_table))); + VERIFY(AEE_SUCCESS == (nErr = PL_INIT(apps_std))); + VERIFY(AEE_SUCCESS + == (nErr = mod_table_register_const_handle( + 0, "apps_remotectl", apps_remotectl_skel_invoke))); + VERIFY(AEE_SUCCESS + == (nErr = mod_table_register_static("apps_std", + apps_std_skel_invoke))); + VERIFY(AEE_SUCCESS + == (nErr = mod_table_register_static("apps_mem", + apps_mem_skel_invoke))); + VERIFY(AEE_SUCCESS + == (nErr = mod_table_register_static( + "adspmsgd_apps", adspmsgd_apps_skel_invoke))); bail: - if (nErr != AEE_SUCCESS) { - listener_android_deinit(); - VERIFY_EPRINTF("Error %x: fastrpc listener initialization error", nErr); - } - return nErr; + if(nErr != AEE_SUCCESS) { + listener_android_deinit(); + VERIFY_EPRINTF( + "Error %x: fastrpc listener initialization error", nErr); + } + return nErr; } -void listener_android_domain_deinit(int domain) { - listener_config *me = NULL; - - GET_HASH_NODE(listener_config, domain, me); - if (!me) - return; - - FARF(RUNTIME_RPC_HIGH, "fastrpc listener joining to exit"); - if (me->thread) { - pthread_join(me->thread, 0); - me->thread = 0; - } - FARF(RUNTIME_RPC_HIGH, "fastrpc listener joined"); - me->adsp_listener1_handle = INVALID_HANDLE; - if (me->eventfd != -1) { - close(me->eventfd); - FARF(RUNTIME_RPC_HIGH, "Closed Listener event_fd %d for domain %d\n", - me->eventfd, domain); - me->eventfd = -1; - } +void +listener_android_domain_deinit(int domain) +{ + listener_config *me = NULL; + + GET_HASH_NODE(listener_config, domain, me); + if(!me) + return; + + FARF(RUNTIME_RPC_HIGH, "fastrpc listener joining to exit"); + if(me->thread) { + pthread_join(me->thread, 0); + me->thread = 0; + } + FARF(RUNTIME_RPC_HIGH, "fastrpc listener joined"); + me->adsp_listener1_handle = INVALID_HANDLE; + if(me->eventfd != -1) { + close(me->eventfd); + FARF(RUNTIME_RPC_HIGH, + "Closed Listener event_fd %d for domain %d\n", + me->eventfd, domain); + me->eventfd = -1; + } } -int listener_android_domain_init(int domain, int update_requested, - sem_t *r_sem) { - listener_config *me = NULL; - int nErr = AEE_SUCCESS; - - GET_HASH_NODE(listener_config, domain, me); - if (!me) { - ALLOC_AND_ADD_NEW_NODE_TO_TABLE(listener_config, domain, me); - } - me->eventfd = -1; - VERIFYC(-1 != (me->eventfd = eventfd(0, 0)), AEE_EBADPARM); - FARF(RUNTIME_RPC_HIGH, "Opened Listener event_fd %d for domain %d\n", - me->eventfd, domain); - me->update_requested = update_requested; - me->r_sem = r_sem; - me->adsp_listener1_handle = INVALID_HANDLE; - me->domain = domain; - VERIFY(AEE_SUCCESS == - (nErr = pthread_create(&me->thread, 0, listener_start_thread, - (void *)me))); - - if (me->update_requested) { - /* - * Semaphore initialized to 0. If main thread reaches wait first, - * then it will wait for listener to increment semaphore to 1. - * If listener posted semaphore first, then this wait will decrement - * semaphore to 0 and proceed. - */ - sem_wait(me->r_sem); - VERIFY(AEE_SUCCESS == (nErr = me->params_updated)); - } +int +listener_android_domain_init(int domain, int update_requested, sem_t *r_sem) +{ + listener_config *me = NULL; + int nErr = AEE_SUCCESS; + + GET_HASH_NODE(listener_config, domain, me); + if(!me) { + ALLOC_AND_ADD_NEW_NODE_TO_TABLE(listener_config, domain, me); + } + me->eventfd = -1; + VERIFYC(-1 != (me->eventfd = eventfd(0, 0)), AEE_EBADPARM); + FARF(RUNTIME_RPC_HIGH, "Opened Listener event_fd %d for domain %d\n", + me->eventfd, domain); + me->update_requested = update_requested; + me->r_sem = r_sem; + me->adsp_listener1_handle = INVALID_HANDLE; + me->domain = domain; + VERIFY(AEE_SUCCESS + == (nErr = pthread_create(&me->thread, 0, listener_start_thread, + (void *)me))); + + if(me->update_requested) { + /* + * Semaphore initialized to 0. If main thread reaches wait + * first, then it will wait for listener to increment semaphore + * to 1. If listener posted semaphore first, then this wait + * will decrement semaphore to 0 and proceed. + */ + sem_wait(me->r_sem); + VERIFY(AEE_SUCCESS == (nErr = me->params_updated)); + } bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d\n", nErr, __func__, - domain); - listener_android_domain_deinit(domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s failed for domain %d\n", nErr, + __func__, domain); + listener_android_domain_deinit(domain); + } + return nErr; } -int close_reverse_handle(remote_handle64 h, char *dlerr, int dlerrorLen, - int *dlErr) { - return apps_remotectl_close((uint32_t)h, dlerr, dlerrorLen, dlErr); +int +close_reverse_handle(remote_handle64 h, char *dlerr, int dlerrorLen, + int *dlErr) +{ + return apps_remotectl_close((uint32_t)h, dlerr, dlerrorLen, dlErr); } -int listener_android_geteventfd(int domain, int *fd) { - listener_config *me = NULL; - int nErr = 0; +int +listener_android_geteventfd(int domain, int *fd) +{ + listener_config *me = NULL; + int nErr = 0; - GET_HASH_NODE(listener_config, domain, me); - VERIFYC(me, AEE_ERESOURCENOTFOUND); - VERIFYC(-1 != me->eventfd, AEE_EBADPARM); - *fd = me->eventfd; + GET_HASH_NODE(listener_config, domain, me); + VERIFYC(me, AEE_ERESOURCENOTFOUND); + VERIFYC(-1 != me->eventfd, AEE_EBADPARM); + *fd = me->eventfd; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: listener android getevent file descriptor failed " - "for domain %d\n", - nErr, domain); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: listener android getevent file " + "descriptor failed " + "for domain %d\n", + nErr, domain); + } + return nErr; } PL_DEFINE(listener_android, listener_android_init, listener_android_deinit) diff --git a/src/log_config.c b/src/log_config.c index 0c3ee428..60db7bd5 100644 --- a/src/log_config.c +++ b/src/log_config.c @@ -48,8 +48,9 @@ #define DEFAULT_ADSPMSGD_MEMORY_SIZE 8192 #define INVALID_HANDLE (remote_handle64)(-1) #define ERRNO (errno == 0 ? -1 : errno) -#define ADSPMSGD_FILTER \ - 0x1f001f // Filter passed to adspmsgd init API to push DSP messages to logcat +#define ADSPMSGD_FILTER \ + 0x1f001f // Filter passed to adspmsgd init API to push DSP messages to + // logcat #define MAX_FARF_FILE_SIZE (511) @@ -63,20 +64,20 @@ #define ENV_PATH_LEN 256 struct log_config_watcher_params { - int fd; - int event_fd; // Duplicate fd to quit the poll - _cstring1_t *paths; - int *wd; - uint32_t numPaths; - pthread_attr_t attr; - pthread_t thread; - unsigned char stopThread; - int asidToWatch; - char *fileToWatch; - char *asidFileToWatch; - char *pidFileToWatch; - bool adspmsgdEnabled; - bool file_watcher_init_flag; + int fd; + int event_fd; // Duplicate fd to quit the poll + _cstring1_t *paths; + int *wd; + uint32_t numPaths; + pthread_attr_t attr; + pthread_t thread; + unsigned char stopThread; + int asidToWatch; + char *fileToWatch; + char *asidFileToWatch; + char *pidFileToWatch; + bool adspmsgdEnabled; + bool file_watcher_init_flag; }; static struct log_config_watcher_params log_config_watcher[NUM_DOMAINS_EXTEND]; @@ -85,647 +86,804 @@ void set_runtime_logmask(uint32_t); const char *get_domain_str(int domain); -static int parseLogConfig(int dom, unsigned int mask, char *filenames) { - _cstring1_t *filesToLog = NULL; - int filesToLogLen = 0; - char *tempFiles = NULL; - int nErr = AEE_SUCCESS; - char *saveptr = NULL; - char *path = NULL; - char delim[] = {','}; - int maxPathLen = 0; - int i = 0; - remote_handle64 handle; - - VERIFYC(filenames != NULL, AEE_ERPC); - - VERIFYC(NULL != - (tempFiles = malloc(sizeof(char) * (strlen(filenames) + 1))), - AEE_ENOMEMORY); - strlcpy(tempFiles, filenames, strlen(filenames) + 1); - - // Get the number of folders and max size needed - path = strtok_r(tempFiles, delim, &saveptr); - while (path != NULL) { - maxPathLen = STD_MAX(maxPathLen, (int)strlen(path)) + 1; - filesToLogLen++; - path = strtok_r(NULL, delim, &saveptr); - } - - VERIFY_IPRINTF("%s: #files: %d max_len: %d\n", - log_config_watcher[dom].fileToWatch, filesToLogLen, - maxPathLen); - - // Allocate memory - VERIFYC(NULL != (filesToLog = malloc(sizeof(_cstring1_t) * filesToLogLen)), - AEE_ENOMEMORY); - for (i = 0; i < filesToLogLen; ++i) { - VERIFYC(NULL != (filesToLog[i].data = malloc(sizeof(char) * maxPathLen)), - AEE_ENOMEMORY); - filesToLog[i].dataLen = maxPathLen; - } - - // Get the number of folders and max size needed - strlcpy(tempFiles, filenames, strlen(filenames) + 1); - i = 0; - path = strtok_r(tempFiles, delim, &saveptr); - while (path != NULL) { - VERIFYC((filesToLog != NULL) && (filesToLog[i].data != NULL) && - filesToLog[i].dataLen >= (int)strlen(path), - AEE_ERPC); - strlcpy(filesToLog[i].data, path, filesToLog[i].dataLen); - VERIFY_IPRINTF("%s: %s\n", log_config_watcher[dom].fileToWatch, - filesToLog[i].data); - path = strtok_r(NULL, delim, &saveptr); - i++; - } - - handle = get_adsp_current_process1_handle(dom); - if (handle != INVALID_HANDLE) { - if (AEE_SUCCESS != (nErr = adsp_current_process1_set_logging_params2( - handle, mask, filesToLog, filesToLogLen))) { - VERIFY(AEE_SUCCESS == (nErr = adsp_current_process1_set_logging_params( - handle, mask, filesToLog, filesToLogLen))); - } - } else { - if (AEE_SUCCESS != (nErr = adsp_current_process_set_logging_params2( - mask, filesToLog, filesToLogLen))) { - VERIFY(AEE_SUCCESS == (nErr = adsp_current_process_set_logging_params( - mask, filesToLog, filesToLogLen))); - } - } +static int +parseLogConfig(int dom, unsigned int mask, char *filenames) +{ + _cstring1_t *filesToLog = NULL; + int filesToLogLen = 0; + char *tempFiles = NULL; + int nErr = AEE_SUCCESS; + char *saveptr = NULL; + char *path = NULL; + char delim[] = { ',' }; + int maxPathLen = 0; + int i = 0; + remote_handle64 handle; + + VERIFYC(filenames != NULL, AEE_ERPC); + + VERIFYC(NULL + != (tempFiles + = malloc(sizeof(char) * (strlen(filenames) + 1))), + AEE_ENOMEMORY); + strlcpy(tempFiles, filenames, strlen(filenames) + 1); + + // Get the number of folders and max size needed + path = strtok_r(tempFiles, delim, &saveptr); + while(path != NULL) { + maxPathLen = STD_MAX(maxPathLen, (int)strlen(path)) + 1; + filesToLogLen++; + path = strtok_r(NULL, delim, &saveptr); + } + + VERIFY_IPRINTF("%s: #files: %d max_len: %d\n", + log_config_watcher[dom].fileToWatch, filesToLogLen, + maxPathLen); + + // Allocate memory + VERIFYC( + NULL != (filesToLog = malloc(sizeof(_cstring1_t) * filesToLogLen)), + AEE_ENOMEMORY); + for(i = 0; i < filesToLogLen; ++i) { + VERIFYC(NULL + != (filesToLog[i].data + = malloc(sizeof(char) * maxPathLen)), + AEE_ENOMEMORY); + filesToLog[i].dataLen = maxPathLen; + } + + // Get the number of folders and max size needed + strlcpy(tempFiles, filenames, strlen(filenames) + 1); + i = 0; + path = strtok_r(tempFiles, delim, &saveptr); + while(path != NULL) { + VERIFYC((filesToLog != NULL) && (filesToLog[i].data != NULL) + && filesToLog[i].dataLen >= (int)strlen(path), + AEE_ERPC); + strlcpy(filesToLog[i].data, path, filesToLog[i].dataLen); + VERIFY_IPRINTF("%s: %s\n", log_config_watcher[dom].fileToWatch, + filesToLog[i].data); + path = strtok_r(NULL, delim, &saveptr); + i++; + } + + handle = get_adsp_current_process1_handle(dom); + if(handle != INVALID_HANDLE) { + if(AEE_SUCCESS + != (nErr = adsp_current_process1_set_logging_params2( + handle, mask, filesToLog, filesToLogLen))) { + VERIFY( + AEE_SUCCESS + == (nErr + = adsp_current_process1_set_logging_params( + handle, mask, filesToLog, filesToLogLen))); + } + } else { + if(AEE_SUCCESS + != (nErr = adsp_current_process_set_logging_params2( + mask, filesToLog, filesToLogLen))) { + VERIFY( + AEE_SUCCESS + == (nErr = adsp_current_process_set_logging_params( + mask, filesToLog, filesToLogLen))); + } + } bail: - if (filesToLog) { - for (i = 0; i < filesToLogLen; ++i) { - if (filesToLog[i].data != NULL) { - free(filesToLog[i].data); - filesToLog[i].data = NULL; - } - } - free(filesToLog); - filesToLog = NULL; - } - - if (tempFiles) { - free(tempFiles); - tempFiles = NULL; - } - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: parse log config failed. domain %d, mask %x, " - "filename %s\n", - nErr, dom, mask, filenames); - } - return nErr; + if(filesToLog) { + for(i = 0; i < filesToLogLen; ++i) { + if(filesToLog[i].data != NULL) { + free(filesToLog[i].data); + filesToLog[i].data = NULL; + } + } + free(filesToLog); + filesToLog = NULL; + } + + if(tempFiles) { + free(tempFiles); + tempFiles = NULL; + } + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: parse log config failed. domain %d, mask %x, " + "filename %s\n", + nErr, dom, mask, filenames); + } + return nErr; } // Read log config given the filename -static int readLogConfigFromPath(int dom, const char *base, const char *file) { - int nErr = 0; - apps_std_FILE fp = -1; - uint64_t len; - unsigned char *buf = NULL; - int readlen = 0, eof; - unsigned int mask = 0; - char *path = NULL; - char *filenames = NULL; - bool fileExists = false; - int buf_addr = 0; - remote_handle64 handle; - uint64_t farf_logmask = 0; - - len = snprintf(0, 0, "%s/%s", base, file) + 1; - VERIFYC(NULL != (path = malloc(sizeof(char) * len)), AEE_ENOMEMORY); - snprintf(path, (int)len, "%s/%s", base, file); - VERIFY(AEE_SUCCESS == (nErr = apps_std_fileExists(path, &fileExists))); - if (fileExists == false) { - FARF(RUNTIME_RPC_HIGH, "%s: Couldn't find file: %s\n", - log_config_watcher[dom].fileToWatch, path); - nErr = AEE_ENOSUCHFILE; - goto bail; - } - if (log_config_watcher[dom].adspmsgdEnabled == false) { - handle = get_adspmsgd_adsp1_handle(dom); - if (handle != INVALID_HANDLE) { - if ((nErr = adspmsgd_init(handle, ADSPMSGD_FILTER)) == - (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET)) - adspmsgd_adsp1_init2(handle); - } else if ((nErr = adspmsgd_adsp_init2()) == - (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET)) { - nErr = adspmsgd_adsp_init(0, RPCMEM_HEAP_DEFAULT, 0, - DEFAULT_ADSPMSGD_MEMORY_SIZE, &buf_addr); - } - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("adspmsgd not supported. nErr=%x\n", nErr); - } else { - log_config_watcher[dom].adspmsgdEnabled = true; - } - VERIFY_EPRINTF("Found %s. adspmsgd enabled \n", - log_config_watcher[dom].fileToWatch); - } - - VERIFY(AEE_SUCCESS == (nErr = apps_std_fopen(path, "r", &fp))); - VERIFY(AEE_SUCCESS == (nErr = apps_std_flen(fp, &len))); - - VERIFYM(len <= MAX_FARF_FILE_SIZE, AEE_ERPC, - "len greater than %d for path %s (%s)\n", nErr, MAX_FARF_FILE_SIZE, - path, strerror(ERRNO)); - VERIFYC(NULL != (buf = calloc(1, sizeof(unsigned char) * (len + 1))), - AEE_ENOMEMORY); // extra 1 unsigned char for null character - VERIFYC(NULL != (filenames = malloc(sizeof(unsigned char) * len)), AEE_ENOMEMORY); - VERIFY(AEE_SUCCESS == (nErr = apps_std_fread(fp, buf, len, &readlen, &eof))); - VERIFYC((int)len == readlen, AEE_ERPC); - - FARF(RUNTIME_RPC_HIGH, "%s: Config file %s contents: %s\n", - log_config_watcher[dom].fileToWatch, path, buf); - - // Parse farf file to get logmasks. - len = sscanf((const char *)buf, "0x%lx %511s", &farf_logmask, filenames); - - if (farf_logmask == LLONG_MAX || farf_logmask == (uint64_t)LLONG_MIN || - farf_logmask == 0) { - VERIFY_EPRINTF("Error : Invalid FARF logmask!"); - } - /* - * Parsing logmask to get userspace and kernel space masks. - * Example: For farf_logmask = 0x001f001f001f001f, this enables all Runtime - * levels - * - * i.e.: 0x 001f001f 001f001f - * |__________| |__________| - * Userspace DSP space - */ - mask = farf_logmask & 0xffffffff; - set_runtime_logmask(farf_logmask >> 32); - switch (len) { - case 1: - FARF(RUNTIME_RPC_HIGH, "%s: Setting log mask:0x%x", - log_config_watcher[dom].fileToWatch, mask); - handle = get_adsp_current_process1_handle(dom); - if (handle != INVALID_HANDLE) { - if (AEE_SUCCESS != (nErr = adsp_current_process1_set_logging_params2( - handle, mask, NULL, 0))) { - VERIFY(AEE_SUCCESS == (nErr = adsp_current_process1_set_logging_params( - handle, mask, NULL, 0))); - } - } else { - if (AEE_SUCCESS != - (nErr = adsp_current_process_set_logging_params2(mask, NULL, 0))) { - VERIFY(AEE_SUCCESS == - (nErr = adsp_current_process_set_logging_params(mask, NULL, 0))); - } - } - break; - case 2: - VERIFY(AEE_SUCCESS == (nErr = parseLogConfig(dom, mask, filenames))); - FARF(RUNTIME_RPC_HIGH, "%s: Setting log mask:0x%x, filename:%s", - log_config_watcher[dom].fileToWatch, mask, filenames); - break; - default: - VERIFY_EPRINTF("Error : %s: No valid data found in config file %s", - log_config_watcher[dom].fileToWatch, path); - nErr = AEE_EUNSUPPORTED; - goto bail; - } +static int +readLogConfigFromPath(int dom, const char *base, const char *file) +{ + int nErr = 0; + apps_std_FILE fp = -1; + uint64_t len; + unsigned char *buf = NULL; + int readlen = 0, eof; + unsigned int mask = 0; + char *path = NULL; + char *filenames = NULL; + bool fileExists = false; + int buf_addr = 0; + remote_handle64 handle; + uint64_t farf_logmask = 0; + + len = snprintf(0, 0, "%s/%s", base, file) + 1; + VERIFYC(NULL != (path = malloc(sizeof(char) * len)), AEE_ENOMEMORY); + snprintf(path, (int)len, "%s/%s", base, file); + VERIFY(AEE_SUCCESS == (nErr = apps_std_fileExists(path, &fileExists))); + if(fileExists == false) { + FARF(RUNTIME_RPC_HIGH, "%s: Couldn't find file: %s\n", + log_config_watcher[dom].fileToWatch, path); + nErr = AEE_ENOSUCHFILE; + goto bail; + } + if(log_config_watcher[dom].adspmsgdEnabled == false) { + handle = get_adspmsgd_adsp1_handle(dom); + if(handle != INVALID_HANDLE) { + if((nErr = adspmsgd_init(handle, ADSPMSGD_FILTER)) + == (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET)) + adspmsgd_adsp1_init2(handle); + } else if((nErr = adspmsgd_adsp_init2()) + == (int)(AEE_EUNSUPPORTED + DSP_AEE_EOFFSET)) { + nErr = adspmsgd_adsp_init(0, RPCMEM_HEAP_DEFAULT, 0, + DEFAULT_ADSPMSGD_MEMORY_SIZE, + &buf_addr); + } + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("adspmsgd not supported. nErr=%x\n", + nErr); + } else { + log_config_watcher[dom].adspmsgdEnabled = true; + } + VERIFY_EPRINTF("Found %s. adspmsgd enabled \n", + log_config_watcher[dom].fileToWatch); + } + + VERIFY(AEE_SUCCESS == (nErr = apps_std_fopen(path, "r", &fp))); + VERIFY(AEE_SUCCESS == (nErr = apps_std_flen(fp, &len))); + + VERIFYM(len <= MAX_FARF_FILE_SIZE, AEE_ERPC, + "len greater than %d for path %s (%s)\n", nErr, + MAX_FARF_FILE_SIZE, path, strerror(ERRNO)); + VERIFYC(NULL != (buf = calloc(1, sizeof(unsigned char) * (len + 1))), + AEE_ENOMEMORY); // extra 1 unsigned char for null character + VERIFYC(NULL != (filenames = malloc(sizeof(unsigned char) * len)), + AEE_ENOMEMORY); + VERIFY(AEE_SUCCESS + == (nErr = apps_std_fread(fp, buf, len, &readlen, &eof))); + VERIFYC((int)len == readlen, AEE_ERPC); + + FARF(RUNTIME_RPC_HIGH, "%s: Config file %s contents: %s\n", + log_config_watcher[dom].fileToWatch, path, buf); + + // Parse farf file to get logmasks. + len = sscanf((const char *)buf, "0x%lx %511s", &farf_logmask, + filenames); + + if(farf_logmask == LLONG_MAX || farf_logmask == (uint64_t)LLONG_MIN + || farf_logmask == 0) { + VERIFY_EPRINTF("Error : Invalid FARF logmask!"); + } + /* + * Parsing logmask to get userspace and kernel space masks. + * Example: For farf_logmask = 0x001f001f001f001f, this enables all + * Runtime levels + * + * i.e.: 0x 001f001f 001f001f + * |__________| |__________| + * Userspace DSP space + */ + mask = farf_logmask & 0xffffffff; + set_runtime_logmask(farf_logmask >> 32); + switch(len) { + case 1: + FARF(RUNTIME_RPC_HIGH, "%s: Setting log mask:0x%x", + log_config_watcher[dom].fileToWatch, mask); + handle = get_adsp_current_process1_handle(dom); + if(handle != INVALID_HANDLE) { + if(AEE_SUCCESS + != (nErr + = adsp_current_process1_set_logging_params2( + handle, mask, NULL, 0))) { + VERIFY( + AEE_SUCCESS + == (nErr + = adsp_current_process1_set_logging_params( + handle, mask, NULL, 0))); + } + } else { + if(AEE_SUCCESS + != (nErr = adsp_current_process_set_logging_params2( + mask, NULL, 0))) { + VERIFY( + AEE_SUCCESS + == (nErr + = adsp_current_process_set_logging_params( + mask, NULL, 0))); + } + } + break; + case 2: + VERIFY(AEE_SUCCESS + == (nErr = parseLogConfig(dom, mask, filenames))); + FARF(RUNTIME_RPC_HIGH, + "%s: Setting log mask:0x%x, filename:%s", + log_config_watcher[dom].fileToWatch, mask, filenames); + break; + default: + VERIFY_EPRINTF( + "Error : %s: No valid data found in config file %s", + log_config_watcher[dom].fileToWatch, path); + nErr = AEE_EUNSUPPORTED; + goto bail; + } bail: - if (buf != NULL) { - free(buf); - buf = NULL; - } - - if (filenames != NULL) { - free(filenames); - filenames = NULL; - } - - if (fp != -1) { - apps_std_fclose(fp); - } - - if (path != NULL) { - free(path); - path = NULL; - } - - if (nErr != AEE_SUCCESS && nErr != AEE_ENOSUCHFILE) { - VERIFY_EPRINTF("Error 0x%x: fopen failed for %s/%s. (%s)\n", nErr, base, - file, strerror(ERRNO)); - } - return nErr; + if(buf != NULL) { + free(buf); + buf = NULL; + } + + if(filenames != NULL) { + free(filenames); + filenames = NULL; + } + + if(fp != -1) { + apps_std_fclose(fp); + } + + if(path != NULL) { + free(path); + path = NULL; + } + + if(nErr != AEE_SUCCESS && nErr != AEE_ENOSUCHFILE) { + VERIFY_EPRINTF("Error 0x%x: fopen failed for %s/%s. (%s)\n", + nErr, base, file, strerror(ERRNO)); + } + return nErr; } // Read log config given the watch descriptor -static int readLogConfigFromEvent(int dom, struct inotify_event *event) { - int i = 0; - - // Ensure we are looking at the right file - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - if (log_config_watcher[dom].wd[i] == event->wd) { - if (strcmp(log_config_watcher[dom].fileToWatch, event->name) == 0) { - return readLogConfigFromPath(dom, log_config_watcher[dom].paths[i].data, - log_config_watcher[dom].fileToWatch); - } else if (strcmp(log_config_watcher[dom].asidFileToWatch, - event->name) == 0) { - return readLogConfigFromPath(dom, log_config_watcher[dom].paths[i].data, - log_config_watcher[dom].asidFileToWatch); - } else if (strcmp(log_config_watcher[dom].pidFileToWatch, - event->name) == 0) { - return readLogConfigFromPath(dom, log_config_watcher[dom].paths[i].data, - log_config_watcher[dom].pidFileToWatch); - } - } - } - VERIFY_IPRINTF("%s: Watch descriptor %d not valid for current process", - log_config_watcher[dom].fileToWatch, event->wd); - return AEE_SUCCESS; +static int +readLogConfigFromEvent(int dom, struct inotify_event *event) +{ + int i = 0; + + // Ensure we are looking at the right file + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + if(log_config_watcher[dom].wd[i] == event->wd) { + if(strcmp(log_config_watcher[dom].fileToWatch, + event->name) + == 0) { + return readLogConfigFromPath( + dom, log_config_watcher[dom].paths[i].data, + log_config_watcher[dom].fileToWatch); + } else if(strcmp( + log_config_watcher[dom].asidFileToWatch, + event->name) + == 0) { + return readLogConfigFromPath( + dom, log_config_watcher[dom].paths[i].data, + log_config_watcher[dom].asidFileToWatch); + } else if(strcmp( + log_config_watcher[dom].pidFileToWatch, + event->name) + == 0) { + return readLogConfigFromPath( + dom, log_config_watcher[dom].paths[i].data, + log_config_watcher[dom].pidFileToWatch); + } + } + } + VERIFY_IPRINTF("%s: Watch descriptor %d not valid for current process", + log_config_watcher[dom].fileToWatch, event->wd); + return AEE_SUCCESS; } // Read log config given the watch descriptor -static int resetLogConfigFromEvent(int dom, struct inotify_event *event) { - int i = 0; - remote_handle64 handle; - - // Ensure we are looking at the right file - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - if (log_config_watcher[dom].wd[i] == event->wd) { - if ((strcmp(log_config_watcher[dom].fileToWatch, event->name) == 0) || - (strcmp(log_config_watcher[dom].asidFileToWatch, event->name) == - 0) || - (strcmp(log_config_watcher[dom].pidFileToWatch, event->name) == - 0)) { - if (log_config_watcher[dom].adspmsgdEnabled == true) { - adspmsgd_stop(dom); - log_config_watcher[dom].adspmsgdEnabled = false; - handle = get_adspmsgd_adsp1_handle(dom); - if (handle != INVALID_HANDLE) { - adspmsgd_adsp1_deinit(handle); - } else { - adspmsgd_adsp_deinit(); - } - } - handle = get_adsp_current_process1_handle(dom); - if (handle != INVALID_HANDLE) { - return adsp_current_process1_set_logging_params(handle, 0, NULL, 0); - } else { - return adsp_current_process_set_logging_params(0, NULL, 0); - } - } - } - } - VERIFY_IPRINTF("%s: Watch descriptor %d not valid for current process", - log_config_watcher[dom].fileToWatch, event->wd); - return AEE_SUCCESS; +static int +resetLogConfigFromEvent(int dom, struct inotify_event *event) +{ + int i = 0; + remote_handle64 handle; + + // Ensure we are looking at the right file + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + if(log_config_watcher[dom].wd[i] == event->wd) { + if((strcmp(log_config_watcher[dom].fileToWatch, + event->name) + == 0) + || (strcmp(log_config_watcher[dom].asidFileToWatch, + event->name) + == 0) + || (strcmp(log_config_watcher[dom].pidFileToWatch, + event->name) + == 0)) { + if(log_config_watcher[dom].adspmsgdEnabled + == true) { + adspmsgd_stop(dom); + log_config_watcher[dom].adspmsgdEnabled + = false; + handle + = get_adspmsgd_adsp1_handle(dom); + if(handle != INVALID_HANDLE) { + adspmsgd_adsp1_deinit(handle); + } else { + adspmsgd_adsp_deinit(); + } + } + handle = get_adsp_current_process1_handle(dom); + if(handle != INVALID_HANDLE) { + return adsp_current_process1_set_logging_params( + handle, 0, NULL, 0); + } else { + return adsp_current_process_set_logging_params( + 0, NULL, 0); + } + } + } + } + VERIFY_IPRINTF("%s: Watch descriptor %d not valid for current process", + log_config_watcher[dom].fileToWatch, event->wd); + return AEE_SUCCESS; } -static void *file_watcher_thread(void *arg) { - int dom = (int)(uintptr_t)arg; - int ret = 0, current_errno = 0, env_list_len = 0; - int length = 0; - int nErr = AEE_SUCCESS; - int i = 0; - char buffer[EVENT_BUF_LEN]; - struct pollfd pfd[] = {{log_config_watcher[dom].fd, POLLIN, 0}, - {log_config_watcher[dom].event_fd, POLLIN, 0}}; - const char *fileExtension = ".farf"; - int len = 0; - remote_handle64 handle; - int file_found = 0; - char *data_paths = NULL; - - FARF(ALWAYS, "%s starting for domain %d\n", __func__, dom); - // Check for the presence of the .farf file at bootup - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - if (0 == readLogConfigFromPath(dom, log_config_watcher[dom].paths[i].data, - log_config_watcher[dom].fileToWatch)) { - file_found = 1; - VERIFY_IPRINTF("%s: Log config File %s found.\n", - log_config_watcher[dom].fileToWatch, - log_config_watcher[dom].paths[i].data); - break; - } - } - if (!file_found) { - // Allocate single buffer for all the paths. - data_paths = calloc(1, sizeof(char) * ENV_PATH_LEN); - if (data_paths) { - current_errno = errno; - // Get DSP_LIBRARY_PATH env variable path set by the user. - ret = apps_std_getenv(DSP_LIBRARY_PATH, data_paths, ENV_PATH_LEN, - &env_list_len); - errno = current_errno; - // User has not set the env variable. Get default search paths. - if (ret != 0) - memmove(data_paths, DSP_SEARCH_PATH, strlen(DSP_SEARCH_PATH)); - VERIFY_WPRINTF("%s: Couldn't find file %s, errno (%s) at %s\n", __func__, - log_config_watcher[dom].fileToWatch, strerror(errno), - data_paths); - } else { - VERIFY_WPRINTF( - "%s: Calloc failed for %d bytes. Couldn't find file %s, errno (%s)\n", - __func__, ENV_PATH_LEN, log_config_watcher[dom].fileToWatch, - strerror(errno)); - } - } - - while (log_config_watcher[dom].stopThread == 0) { - // Block forever - ret = poll(pfd, 2, -1); - if (ret < 0) { - VERIFY_EPRINTF("Error : %s: Error polling for file change. Runtime FARF " - "will not work for this process. errno=%x !", - log_config_watcher[dom].fileToWatch, errno); - break; - } else if (pfd[1].revents & POLLIN) { // Check for exit - VERIFY_WPRINTF("Warning: %s received exit for domain %d, file %s\n", - __func__, dom, log_config_watcher[dom].fileToWatch); - break; - } else { - length = read(log_config_watcher[dom].fd, buffer, EVENT_BUF_LEN); - i = 0; - while (i < length) { - struct inotify_event *event = (struct inotify_event *)&buffer[i]; - if (event->len) { - // Get the asiD for the current process - // Do it once only - if (log_config_watcher[dom].asidToWatch == -1) { - handle = get_adsp_current_process1_handle(dom); - if (handle != INVALID_HANDLE) { - VERIFY( - AEE_SUCCESS == - (nErr = adsp_current_process1_getASID( - handle, - (unsigned int *)&log_config_watcher[dom].asidToWatch))); - } else { - VERIFY( - AEE_SUCCESS == - (nErr = adsp_current_process_getASID( - (unsigned int *)&log_config_watcher[dom].asidToWatch))); - } - len = strlen(fileExtension) + strlen(__TOSTR__(INT_MAX)); - VERIFYC(NULL != (log_config_watcher[dom].asidFileToWatch = - malloc(sizeof(char) * len)), - AEE_ENOMEMORY); - snprintf(log_config_watcher[dom].asidFileToWatch, len, "%d%s", - log_config_watcher[dom].asidToWatch, fileExtension); - VERIFY_IPRINTF("%s: Watching ASID file %s\n", - log_config_watcher[dom].fileToWatch, - log_config_watcher[dom].asidFileToWatch); - } - - VERIFY_IPRINTF("%s: %s %d.\n", log_config_watcher[dom].fileToWatch, - event->name, event->mask); - if ((event->mask & IN_CREATE) || (event->mask & IN_MODIFY)) { - VERIFY_IPRINTF("%s: File %s created.\n", - log_config_watcher[dom].fileToWatch, event->name); - if (0 != readLogConfigFromEvent(dom, event)) { - VERIFY_EPRINTF("Error : %s: Error reading config file %s", - log_config_watcher[dom].fileToWatch, - log_config_watcher[dom].paths[i].data); - } - } else if (event->mask & IN_DELETE) { - VERIFY_IPRINTF("%s: File %s deleted.\n", - log_config_watcher[dom].fileToWatch, event->name); - if (0 != resetLogConfigFromEvent(dom, event)) { - VERIFY_EPRINTF( - "Error : %s: Error resetting FARF runtime log config", - log_config_watcher[dom].fileToWatch); - } - } - } - - i += EVENT_SIZE + event->len; - } - } - } +static void * +file_watcher_thread(void *arg) +{ + int dom = (int)(uintptr_t)arg; + int ret = 0, current_errno = 0, env_list_len = 0; + int length = 0; + int nErr = AEE_SUCCESS; + int i = 0; + char buffer[EVENT_BUF_LEN]; + struct pollfd pfd[] + = { { log_config_watcher[dom].fd, POLLIN, 0 }, + { log_config_watcher[dom].event_fd, POLLIN, 0 } }; + const char *fileExtension = ".farf"; + int len = 0; + remote_handle64 handle; + int file_found = 0; + char *data_paths = NULL; + + FARF(ALWAYS, "%s starting for domain %d\n", __func__, dom); + // Check for the presence of the .farf file at bootup + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + if(0 + == readLogConfigFromPath( + dom, log_config_watcher[dom].paths[i].data, + log_config_watcher[dom].fileToWatch)) { + file_found = 1; + VERIFY_IPRINTF("%s: Log config File %s found.\n", + log_config_watcher[dom].fileToWatch, + log_config_watcher[dom].paths[i].data); + break; + } + } + if(!file_found) { + // Allocate single buffer for all the paths. + data_paths = calloc(1, sizeof(char) * ENV_PATH_LEN); + if(data_paths) { + current_errno = errno; + // Get DSP_LIBRARY_PATH env variable path set by the + // user. + ret = apps_std_getenv(DSP_LIBRARY_PATH, data_paths, + ENV_PATH_LEN, &env_list_len); + errno = current_errno; + // User has not set the env variable. Get default + // search paths. + if(ret != 0) + memmove(data_paths, DSP_SEARCH_PATH, + strlen(DSP_SEARCH_PATH)); + VERIFY_WPRINTF( + "%s: Couldn't find file %s, errno (%s) at %s\n", + __func__, log_config_watcher[dom].fileToWatch, + strerror(errno), data_paths); + } else { + VERIFY_WPRINTF("%s: Calloc failed for %d bytes. " + "Couldn't find file %s, errno (%s)\n", + __func__, ENV_PATH_LEN, + log_config_watcher[dom].fileToWatch, + strerror(errno)); + } + } + + while(log_config_watcher[dom].stopThread == 0) { + // Block forever + ret = poll(pfd, 2, -1); + if(ret < 0) { + VERIFY_EPRINTF( + "Error : %s: Error polling for file change. " + "Runtime FARF " + "will not work for this process. errno=%x !", + log_config_watcher[dom].fileToWatch, errno); + break; + } else if(pfd[1].revents & POLLIN) { // Check for exit + VERIFY_WPRINTF("Warning: %s received exit for domain " + "%d, file %s\n", + __func__, dom, + log_config_watcher[dom].fileToWatch); + break; + } else { + length = read(log_config_watcher[dom].fd, buffer, + EVENT_BUF_LEN); + i = 0; + while(i < length) { + struct inotify_event *event + = (struct inotify_event *)&buffer[i]; + if(event->len) { + // Get the asiD for the current process + // Do it once only + if(log_config_watcher[dom].asidToWatch + == -1) { + handle + = get_adsp_current_process1_handle( + dom); + if(handle != INVALID_HANDLE) { + VERIFY( + AEE_SUCCESS + == (nErr + = adsp_current_process1_getASID( + handle, + (unsigned int + *)&log_config_watcher + [dom] + .asidToWatch))); + } else { + VERIFY( + AEE_SUCCESS + == (nErr + = adsp_current_process_getASID( + (unsigned int + *)&log_config_watcher + [dom] + .asidToWatch))); + } + len = strlen(fileExtension) + + strlen( + __TOSTR__(INT_MAX)); + VERIFYC( + NULL + != (log_config_watcher + [dom] + .asidFileToWatch + = malloc( + sizeof(char) + * len)), + AEE_ENOMEMORY); + snprintf( + log_config_watcher[dom] + .asidFileToWatch, + len, "%d%s", + log_config_watcher[dom] + .asidToWatch, + fileExtension); + VERIFY_IPRINTF( + "%s: Watching ASID file " + "%s\n", + log_config_watcher[dom] + .fileToWatch, + log_config_watcher[dom] + .asidFileToWatch); + } + + VERIFY_IPRINTF("%s: %s %d.\n", + log_config_watcher[dom] + .fileToWatch, + event->name, + event->mask); + if((event->mask & IN_CREATE) + || (event->mask & IN_MODIFY)) { + VERIFY_IPRINTF( + "%s: File %s created.\n", + log_config_watcher[dom] + .fileToWatch, + event->name); + if(0 + != readLogConfigFromEvent( + dom, event)) { + VERIFY_EPRINTF( + "Error : %s: " + "Error reading " + "config file %s", + log_config_watcher + [dom] + .fileToWatch, + log_config_watcher + [dom] + .paths[i] + .data); + } + } else if(event->mask & IN_DELETE) { + VERIFY_IPRINTF( + "%s: File %s deleted.\n", + log_config_watcher[dom] + .fileToWatch, + event->name); + if(0 + != resetLogConfigFromEvent( + dom, event)) { + VERIFY_EPRINTF( + "Error : %s: " + "Error resetting " + "FARF runtime log " + "config", + log_config_watcher + [dom] + .fileToWatch); + } + } + } + + i += EVENT_SIZE + event->len; + } + } + } bail: - if (data_paths) { - free(data_paths); - data_paths = NULL; - } - - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s exited. Runtime FARF will not work for this " - "process. filename %s (errno %s)\n", - nErr, __func__, log_config_watcher[dom].fileToWatch, - strerror(errno)); - } else { - FARF(ALWAYS, "%s exiting for domain %d\n", __func__, dom); - } - return NULL; + if(data_paths) { + free(data_paths); + data_paths = NULL; + } + + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s exited. Runtime FARF will not " + "work for this " + "process. filename %s (errno %s)\n", + nErr, __func__, + log_config_watcher[dom].fileToWatch, + strerror(errno)); + } else { + FARF(ALWAYS, "%s exiting for domain %d\n", __func__, dom); + } + return NULL; } -void deinitFileWatcher(int dom) { - int i = 0; - uint64_t stop = 10; - remote_handle64 handle; - ssize_t sz = 0; - - if (log_config_watcher[dom].file_watcher_init_flag) { - log_config_watcher[dom].stopThread = 1; - if (0 <= log_config_watcher[dom].event_fd) { - for (i = 0; i < RETRY_WRITE; i++) { - VERIFY_IPRINTF( - "Writing to file_watcher_thread event_fd %d for domain %d\n", - log_config_watcher[dom].event_fd, dom); - sz = write(log_config_watcher[dom].event_fd, &stop, sizeof(uint64_t)); - if ((sz < (ssize_t)sizeof(uint64_t)) || (sz == -1 && errno == EAGAIN)) { - VERIFY_WPRINTF("Warning: Written %zd bytes on event_fd %d for domain " - "%d (errno = %s): Retrying ...\n", - sz, log_config_watcher[dom].event_fd, dom, - strerror(errno)); - continue; - } else { - break; - } - } - } - if (sz != sizeof(uint64_t) && 0 <= log_config_watcher[dom].event_fd) { - VERIFY_EPRINTF("Error: Written %zd bytes on event_fd %d for domain %d: " - "Cannot set exit flag to watcher thread (errno = %s)\n", - sz, log_config_watcher[dom].event_fd, dom, - strerror(errno)); - // When deinitFileWatcher fail to write dupfd, file watcher thread hangs - // on poll. Abort in this case. - raise(SIGABRT); - } - } - if (log_config_watcher[dom].thread) { - pthread_join(log_config_watcher[dom].thread, NULL); - log_config_watcher[dom].thread = 0; - } - if (log_config_watcher[dom].fileToWatch) { - free(log_config_watcher[dom].fileToWatch); - log_config_watcher[dom].fileToWatch = 0; - } - if (log_config_watcher[dom].asidFileToWatch) { - free(log_config_watcher[dom].asidFileToWatch); - log_config_watcher[dom].asidFileToWatch = 0; - } - if (log_config_watcher[dom].pidFileToWatch) { - free(log_config_watcher[dom].pidFileToWatch); - log_config_watcher[dom].pidFileToWatch = 0; - } - if (log_config_watcher[dom].wd) { - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - // On success, inotify_add_watch() returns a nonnegative integer watch - // descriptor - if (log_config_watcher[dom].wd[i] >= 0) { - inotify_rm_watch(log_config_watcher[dom].fd, - log_config_watcher[dom].wd[i]); - } - } - free(log_config_watcher[dom].wd); - log_config_watcher[dom].wd = NULL; - } - if (log_config_watcher[dom].paths) { - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - if (log_config_watcher[dom].paths[i].data) { - free(log_config_watcher[dom].paths[i].data); - log_config_watcher[dom].paths[i].data = NULL; - } - } - free(log_config_watcher[dom].paths); - log_config_watcher[dom].paths = NULL; - } - if (log_config_watcher[dom].fd != 0) { - close(log_config_watcher[dom].fd); - VERIFY_IPRINTF("Closed file watcher fd %d for domain %d\n", - log_config_watcher[dom].fd, dom); - log_config_watcher[dom].fd = 0; - } - if (log_config_watcher[dom].adspmsgdEnabled == true) { - adspmsgd_stop(dom); - handle = get_adspmsgd_adsp1_handle(dom); - if (handle != INVALID_HANDLE) { - adspmsgd_adsp1_deinit(handle); - } else { - adspmsgd_adsp_deinit(); - } - log_config_watcher[dom].adspmsgdEnabled = false; - } - if (log_config_watcher[dom].file_watcher_init_flag && - (log_config_watcher[dom].event_fd != -1)) { - close(log_config_watcher[dom].event_fd); - VERIFY_IPRINTF("Closed file watcher eventfd %d for domain %d\n", - log_config_watcher[dom].event_fd, dom); - log_config_watcher[dom].event_fd = -1; - } - log_config_watcher[dom].file_watcher_init_flag = false; - log_config_watcher[dom].numPaths = 0; +void +deinitFileWatcher(int dom) +{ + int i = 0; + uint64_t stop = 10; + remote_handle64 handle; + ssize_t sz = 0; + + if(log_config_watcher[dom].file_watcher_init_flag) { + log_config_watcher[dom].stopThread = 1; + if(0 <= log_config_watcher[dom].event_fd) { + for(i = 0; i < RETRY_WRITE; i++) { + VERIFY_IPRINTF( + "Writing to file_watcher_thread event_fd " + "%d for domain %d\n", + log_config_watcher[dom].event_fd, dom); + sz = write(log_config_watcher[dom].event_fd, + &stop, sizeof(uint64_t)); + if((sz < (ssize_t)sizeof(uint64_t)) + || (sz == -1 && errno == EAGAIN)) { + VERIFY_WPRINTF( + "Warning: Written %zd bytes on " + "event_fd %d for domain " + "%d (errno = %s): Retrying ...\n", + sz, + log_config_watcher[dom].event_fd, + dom, strerror(errno)); + continue; + } else { + break; + } + } + } + if(sz != sizeof(uint64_t) + && 0 <= log_config_watcher[dom].event_fd) { + VERIFY_EPRINTF("Error: Written %zd bytes on event_fd " + "%d for domain %d: " + "Cannot set exit flag to watcher " + "thread (errno = %s)\n", + sz, log_config_watcher[dom].event_fd, + dom, strerror(errno)); + // When deinitFileWatcher fail to write dupfd, file + // watcher thread hangs on poll. Abort in this case. + raise(SIGABRT); + } + } + if(log_config_watcher[dom].thread) { + pthread_join(log_config_watcher[dom].thread, NULL); + log_config_watcher[dom].thread = 0; + } + if(log_config_watcher[dom].fileToWatch) { + free(log_config_watcher[dom].fileToWatch); + log_config_watcher[dom].fileToWatch = 0; + } + if(log_config_watcher[dom].asidFileToWatch) { + free(log_config_watcher[dom].asidFileToWatch); + log_config_watcher[dom].asidFileToWatch = 0; + } + if(log_config_watcher[dom].pidFileToWatch) { + free(log_config_watcher[dom].pidFileToWatch); + log_config_watcher[dom].pidFileToWatch = 0; + } + if(log_config_watcher[dom].wd) { + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + // On success, inotify_add_watch() returns a + // nonnegative integer watch descriptor + if(log_config_watcher[dom].wd[i] >= 0) { + inotify_rm_watch( + log_config_watcher[dom].fd, + log_config_watcher[dom].wd[i]); + } + } + free(log_config_watcher[dom].wd); + log_config_watcher[dom].wd = NULL; + } + if(log_config_watcher[dom].paths) { + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + if(log_config_watcher[dom].paths[i].data) { + free(log_config_watcher[dom].paths[i].data); + log_config_watcher[dom].paths[i].data = NULL; + } + } + free(log_config_watcher[dom].paths); + log_config_watcher[dom].paths = NULL; + } + if(log_config_watcher[dom].fd != 0) { + close(log_config_watcher[dom].fd); + VERIFY_IPRINTF("Closed file watcher fd %d for domain %d\n", + log_config_watcher[dom].fd, dom); + log_config_watcher[dom].fd = 0; + } + if(log_config_watcher[dom].adspmsgdEnabled == true) { + adspmsgd_stop(dom); + handle = get_adspmsgd_adsp1_handle(dom); + if(handle != INVALID_HANDLE) { + adspmsgd_adsp1_deinit(handle); + } else { + adspmsgd_adsp_deinit(); + } + log_config_watcher[dom].adspmsgdEnabled = false; + } + if(log_config_watcher[dom].file_watcher_init_flag + && (log_config_watcher[dom].event_fd != -1)) { + close(log_config_watcher[dom].event_fd); + VERIFY_IPRINTF( + "Closed file watcher eventfd %d for domain %d\n", + log_config_watcher[dom].event_fd, dom); + log_config_watcher[dom].event_fd = -1; + } + log_config_watcher[dom].file_watcher_init_flag = false; + log_config_watcher[dom].numPaths = 0; } -int initFileWatcher(int dom) { - int nErr = AEE_SUCCESS; - const char *fileExtension = ".farf"; - uint32_t len = 0; - uint16_t maxPathLen = 0; - int i = 0; - char *name = NULL; - - memset(&log_config_watcher[dom], 0, sizeof(struct log_config_watcher_params)); - log_config_watcher[dom].asidToWatch = 0; - log_config_watcher[dom].event_fd = -1; - - VERIFYC(NULL != (name = std_basename(__progname)), AEE_EBADPARM); - - len = strlen(name) + strlen(fileExtension) + 1; - VERIFYC(NULL != (log_config_watcher[dom].fileToWatch = - malloc(sizeof(char) * len)), - AEE_ENOMEMORY); - snprintf(log_config_watcher[dom].fileToWatch, len, "%s%s", name, - fileExtension); - - len = strlen(fileExtension) + strlen(__TOSTR__(INT_MAX)); - VERIFYC(NULL != (log_config_watcher[dom].pidFileToWatch = - malloc(sizeof(char) * len)), - AEE_ENOMEMORY); - snprintf(log_config_watcher[dom].pidFileToWatch, len, "%d%s", getpid(), - fileExtension); - - VERIFY_IPRINTF("%s: Watching PID file: %s\n", - log_config_watcher[dom].fileToWatch, - log_config_watcher[dom].pidFileToWatch); - - log_config_watcher[dom].fd = inotify_init(); - if (log_config_watcher[dom].fd < 0) { - nErr = AEE_ERPC; - VERIFY_EPRINTF("Error 0x%x: inotify_init failed, invalid fd errno = %s\n", - nErr, strerror(errno)); - goto bail; - } - - // Duplicate the fd, so we can use it to quit polling - log_config_watcher[dom].event_fd = eventfd(0, 0); - if (log_config_watcher[dom].event_fd < 0) { - nErr = AEE_ERPC; - VERIFY_EPRINTF("Error 0x%x: eventfd in dup failed, invalid fd errno %s\n", - nErr, strerror(errno)); - goto bail; - } - log_config_watcher[dom].file_watcher_init_flag = true; - VERIFY_IPRINTF("Opened file watcher fd %d eventfd %d for domain %d\n", - log_config_watcher[dom].fd, log_config_watcher[dom].event_fd, - dom); - - // Get the required size - apps_std_get_search_paths_with_env(ADSP_LIBRARY_PATH, ";", NULL, 0, - &log_config_watcher[dom].numPaths, - &maxPathLen); - - maxPathLen += +1; - - // Allocate memory - VERIFYC(NULL != (log_config_watcher[dom].paths = malloc( - sizeof(_cstring1_t) * log_config_watcher[dom].numPaths)), - AEE_ENOMEMORY); - VERIFYC(NULL != (log_config_watcher[dom].wd = - malloc(sizeof(int) * log_config_watcher[dom].numPaths)), - AEE_ENOMEMORY); - - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - VERIFYC(NULL != (log_config_watcher[dom].paths[i].data = - malloc(sizeof(char) * maxPathLen)), - AEE_ENOMEMORY); - log_config_watcher[dom].paths[i].dataLen = maxPathLen; - } - - // Get the paths - VERIFY(AEE_SUCCESS == - (nErr = apps_std_get_search_paths_with_env( - ADSP_LIBRARY_PATH, ";", log_config_watcher[dom].paths, - log_config_watcher[dom].numPaths, &len, &maxPathLen))); - - maxPathLen += 1; - - VERIFY_IPRINTF("%s: Watching folders:\n", - log_config_watcher[dom].fileToWatch); - for (i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { - // Watch for creation, deletion and modification of files in path - VERIFY_IPRINTF("log file watcher: %s: %s\n", - log_config_watcher[dom].fileToWatch, - log_config_watcher[dom].paths[i].data); - if ((log_config_watcher[dom].wd[i] = inotify_add_watch( - log_config_watcher[dom].fd, log_config_watcher[dom].paths[i].data, - IN_CREATE | IN_DELETE)) < 0) { - VERIFY_EPRINTF( - "Error : Unable to add watcher for folder %s : errno is %s\n", - log_config_watcher[dom].paths[i].data, strerror(ERRNO)); - } - } - - // Create a thread to watch for file changes - log_config_watcher[dom].asidToWatch = -1; - log_config_watcher[dom].stopThread = 0; - pthread_create(&log_config_watcher[dom].thread, NULL, file_watcher_thread, - (void *)(uintptr_t)dom); +int +initFileWatcher(int dom) +{ + int nErr = AEE_SUCCESS; + const char *fileExtension = ".farf"; + uint32_t len = 0; + uint16_t maxPathLen = 0; + int i = 0; + char *name = NULL; + + memset(&log_config_watcher[dom], 0, + sizeof(struct log_config_watcher_params)); + log_config_watcher[dom].asidToWatch = 0; + log_config_watcher[dom].event_fd = -1; + + VERIFYC(NULL != (name = std_basename(__progname)), AEE_EBADPARM); + + len = strlen(name) + strlen(fileExtension) + 1; + VERIFYC(NULL + != (log_config_watcher[dom].fileToWatch + = malloc(sizeof(char) * len)), + AEE_ENOMEMORY); + snprintf(log_config_watcher[dom].fileToWatch, len, "%s%s", name, + fileExtension); + + len = strlen(fileExtension) + strlen(__TOSTR__(INT_MAX)); + VERIFYC(NULL + != (log_config_watcher[dom].pidFileToWatch + = malloc(sizeof(char) * len)), + AEE_ENOMEMORY); + snprintf(log_config_watcher[dom].pidFileToWatch, len, "%d%s", getpid(), + fileExtension); + + VERIFY_IPRINTF("%s: Watching PID file: %s\n", + log_config_watcher[dom].fileToWatch, + log_config_watcher[dom].pidFileToWatch); + + log_config_watcher[dom].fd = inotify_init(); + if(log_config_watcher[dom].fd < 0) { + nErr = AEE_ERPC; + VERIFY_EPRINTF( + "Error 0x%x: inotify_init failed, invalid fd errno = %s\n", + nErr, strerror(errno)); + goto bail; + } + + // Duplicate the fd, so we can use it to quit polling + log_config_watcher[dom].event_fd = eventfd(0, 0); + if(log_config_watcher[dom].event_fd < 0) { + nErr = AEE_ERPC; + VERIFY_EPRINTF( + "Error 0x%x: eventfd in dup failed, invalid fd errno %s\n", + nErr, strerror(errno)); + goto bail; + } + log_config_watcher[dom].file_watcher_init_flag = true; + VERIFY_IPRINTF("Opened file watcher fd %d eventfd %d for domain %d\n", + log_config_watcher[dom].fd, + log_config_watcher[dom].event_fd, dom); + + // Get the required size + apps_std_get_search_paths_with_env(ADSP_LIBRARY_PATH, ";", NULL, 0, + &log_config_watcher[dom].numPaths, + &maxPathLen); + + maxPathLen += +1; + + // Allocate memory + VERIFYC(NULL + != (log_config_watcher[dom].paths + = malloc(sizeof(_cstring1_t) + * log_config_watcher[dom].numPaths)), + AEE_ENOMEMORY); + VERIFYC(NULL + != (log_config_watcher[dom].wd = malloc( + sizeof(int) * log_config_watcher[dom].numPaths)), + AEE_ENOMEMORY); + + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + VERIFYC(NULL + != (log_config_watcher[dom].paths[i].data + = malloc(sizeof(char) * maxPathLen)), + AEE_ENOMEMORY); + log_config_watcher[dom].paths[i].dataLen = maxPathLen; + } + + // Get the paths + VERIFY(AEE_SUCCESS + == (nErr = apps_std_get_search_paths_with_env( + ADSP_LIBRARY_PATH, ";", log_config_watcher[dom].paths, + log_config_watcher[dom].numPaths, &len, &maxPathLen))); + + maxPathLen += 1; + + VERIFY_IPRINTF("%s: Watching folders:\n", + log_config_watcher[dom].fileToWatch); + for(i = 0; i < (int)log_config_watcher[dom].numPaths; ++i) { + // Watch for creation, deletion and modification of files in + // path + VERIFY_IPRINTF("log file watcher: %s: %s\n", + log_config_watcher[dom].fileToWatch, + log_config_watcher[dom].paths[i].data); + if((log_config_watcher[dom].wd[i] + = inotify_add_watch(log_config_watcher[dom].fd, + log_config_watcher[dom].paths[i].data, + IN_CREATE | IN_DELETE)) + < 0) { + VERIFY_EPRINTF("Error : Unable to add watcher for " + "folder %s : errno is %s\n", + log_config_watcher[dom].paths[i].data, + strerror(ERRNO)); + } + } + + // Create a thread to watch for file changes + log_config_watcher[dom].asidToWatch = -1; + log_config_watcher[dom].stopThread = 0; + pthread_create(&log_config_watcher[dom].thread, NULL, + file_watcher_thread, (void *)(uintptr_t)dom); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: Failed to register with inotify file %s. " - "Runtime FARF will not work for the process %s! errno %d", - nErr, log_config_watcher[dom].fileToWatch, name, errno); - deinitFileWatcher(dom); - } - - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error 0x%x: Failed to register with inotify file %s. " + "Runtime FARF will not work for the process %s! errno %d", + nErr, log_config_watcher[dom].fileToWatch, name, errno); + deinitFileWatcher(dom); + } + + return nErr; } diff --git a/src/mod_table.c b/src/mod_table.c index d19fa908..829d281a 100644 --- a/src/mod_table.c +++ b/src/mod_table.c @@ -42,30 +42,39 @@ RW_MUTEX_T rev_handle_table_lock; #define RTLD_NOW 0 -static __inline HMODULE DLOPEN(LPCSTR name, int mode) { - UNREFERENCED_PARAMETER(mode); - return LoadLibraryExA(name, 0, 0); +static __inline HMODULE +DLOPEN(LPCSTR name, int mode) +{ + UNREFERENCED_PARAMETER(mode); + return LoadLibraryExA(name, 0, 0); } -static __inline FARPROC DLSYM(LPVOID handle, LPCSTR name) { - return GetProcAddress((HMODULE)handle, name); +static __inline FARPROC +DLSYM(LPVOID handle, LPCSTR name) +{ + return GetProcAddress((HMODULE)handle, name); } -static __inline int DLCLOSE(LPVOID handle) { - int nErr = AEE_SUCCESS; +static __inline int +DLCLOSE(LPVOID handle) +{ + int nErr = AEE_SUCCESS; - VERIFYC(0 < FreeLibrary((HMODULE)handle), AEE_EBADPARM); + VERIFYC(0 < FreeLibrary((HMODULE)handle), AEE_EBADPARM); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: dlclose failed for %x\n", nErr, handle); - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: dlclose failed for %x\n", nErr, + handle); + } + return nErr; } -static __inline const char *DLERROR(VOID) { - static const char errMsg[] = "dl Error"; - return errMsg; +static __inline const char * +DLERROR(VOID) +{ + static const char errMsg[] = "dl Error"; + return errMsg; } #else #include @@ -92,830 +101,935 @@ extern int errno; * are not going to be returned by malloc (0, or odd). */ struct static_mod_table { - RW_MUTEX_T mut; - struct static_mod *staticModOverrides; - struct static_mod *staticMods; - struct const_mod *constMods; - bool bInit; + RW_MUTEX_T mut; + struct static_mod *staticModOverrides; + struct static_mod *staticMods; + struct const_mod *constMods; + bool bInit; }; struct open_mod_table { - RW_MUTEX_T mut; - struct open_mod *openMods; - struct static_mod_table *smt; + RW_MUTEX_T mut; + struct open_mod *openMods; + struct static_mod_table *smt; }; typedef int (*invoke_fn)(uint32_t, remote_arg *); typedef int (*handle_invoke_fn)(remote_handle64, uint32_t, remote_arg *); struct static_mod { - invoke_fn invoke; - handle_invoke_fn handle_invoke; - UT_hash_handle hh; - char uri[1]; + invoke_fn invoke; + handle_invoke_fn handle_invoke; + UT_hash_handle hh; + char uri[1]; }; struct const_mod { - invoke_fn invoke; - handle_invoke_fn handle_invoke; - uint32_t key; - remote_handle64 h64; - UT_hash_handle hh; - char uri[1]; + invoke_fn invoke; + handle_invoke_fn handle_invoke; + uint32_t key; + remote_handle64 h64; + UT_hash_handle hh; + char uri[1]; }; struct parsed_uri { - const char *file; - const char *sym; - const char *ver; - int filelen; - int symlen; - int verlen; + const char *file; + const char *sym; + const char *ver; + int filelen; + int symlen; + int verlen; }; struct open_mod { - void *dlhandle; - invoke_fn invoke; - handle_invoke_fn handle_invoke; - uint64_t key; - UT_hash_handle hh; - remote_handle64 h64; - struct parsed_uri vals; - int refs; - char uri[1]; + void *dlhandle; + invoke_fn invoke; + handle_invoke_fn handle_invoke; + uint64_t key; + UT_hash_handle hh; + remote_handle64 h64; + struct parsed_uri vals; + int refs; + char uri[1]; }; -static int static_mod_table_ctor(struct static_mod_table *me) { - if (me->bInit == 0) { - RW_MUTEX_CTOR(me->mut); - RW_MUTEX_CTOR(rev_handle_table_lock); - me->staticMods = 0; - me->staticModOverrides = 0; - me->bInit = 1; - } - return 0; +static int +static_mod_table_ctor(struct static_mod_table *me) +{ + if(me->bInit == 0) { + RW_MUTEX_CTOR(me->mut); + RW_MUTEX_CTOR(rev_handle_table_lock); + me->staticMods = 0; + me->staticModOverrides = 0; + me->bInit = 1; + } + return 0; } -static void static_mod_table_dtor_imp(struct static_mod_table *me) { - struct static_mod *sm, *stmp; - struct const_mod *dm, *ftmp; - if (me->bInit != 0) { - if (me->staticMods || me->constMods || me->staticModOverrides) { - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_ITER(hh, me->staticMods, sm, stmp) { - if (me->staticMods) { - HASH_DEL(me->staticMods, sm); - } - free(sm); - sm = NULL; - } - HASH_ITER(hh, me->staticModOverrides, sm, stmp) { - if (me->staticModOverrides) { - HASH_DEL(me->staticModOverrides, sm); - } - free(sm); - sm = NULL; - } - HASH_ITER(hh, me->constMods, dm, ftmp) { - if (me->constMods) { - HASH_DEL(me->constMods, dm); - } - free(dm); - dm = NULL; - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - } - RW_MUTEX_DTOR(me->mut); - RW_MUTEX_DTOR(rev_handle_table_lock); - me->staticMods = 0; - me->staticModOverrides = 0; - me->bInit = 0; - } +static void +static_mod_table_dtor_imp(struct static_mod_table *me) +{ + struct static_mod *sm, *stmp; + struct const_mod *dm, *ftmp; + if(me->bInit != 0) { + if(me->staticMods || me->constMods || me->staticModOverrides) { + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_ITER(hh, me->staticMods, sm, stmp) + { + if(me->staticMods) { + HASH_DEL(me->staticMods, sm); + } + free(sm); + sm = NULL; + } + HASH_ITER(hh, me->staticModOverrides, sm, stmp) + { + if(me->staticModOverrides) { + HASH_DEL(me->staticModOverrides, sm); + } + free(sm); + sm = NULL; + } + HASH_ITER(hh, me->constMods, dm, ftmp) + { + if(me->constMods) { + HASH_DEL(me->constMods, dm); + } + free(dm); + dm = NULL; + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + } + RW_MUTEX_DTOR(me->mut); + RW_MUTEX_DTOR(rev_handle_table_lock); + me->staticMods = 0; + me->staticModOverrides = 0; + me->bInit = 0; + } } -static int open_mod_table_ctor_imp(void *ctx, void *data) { - struct open_mod_table *me = (struct open_mod_table *)data; - RW_MUTEX_CTOR(me->mut); - me->openMods = 0; - me->smt = (struct static_mod_table *)ctx; - return 0; +static int +open_mod_table_ctor_imp(void *ctx, void *data) +{ + struct open_mod_table *me = (struct open_mod_table *)data; + RW_MUTEX_CTOR(me->mut); + me->openMods = 0; + me->smt = (struct static_mod_table *)ctx; + return 0; } static int open_mod_handle_close(struct open_mod *mod, remote_handle64 h); -static void open_mod_table_dtor_imp(void *data) { - struct open_mod_table *me = (struct open_mod_table *)data; - struct open_mod *dm, *ftmp; - if (me->openMods) { - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_ITER(hh, me->openMods, dm, ftmp) { - if (me->openMods) { - HASH_DEL(me->openMods, dm); - } - if (dm->h64) { - (void)open_mod_handle_close(dm, dm->h64); - } - if (dm->dlhandle) { - DLCLOSE(dm->dlhandle); - } - FARF(RUNTIME_RPC_HIGH, "%s: closed reverse module %s with handle 0x%x", __func__, - dm->uri, (uint32_t)dm->key); - dm->key = 0; - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - } - RW_MUTEX_DTOR(me->mut); - me->openMods = 0; +static void +open_mod_table_dtor_imp(void *data) +{ + struct open_mod_table *me = (struct open_mod_table *)data; + struct open_mod *dm, *ftmp; + if(me->openMods) { + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_ITER(hh, me->openMods, dm, ftmp) + { + if(me->openMods) { + HASH_DEL(me->openMods, dm); + } + if(dm->h64) { + (void)open_mod_handle_close(dm, dm->h64); + } + if(dm->dlhandle) { + DLCLOSE(dm->dlhandle); + } + FARF(RUNTIME_RPC_HIGH, + "%s: closed reverse module %s with handle 0x%x", + __func__, dm->uri, (uint32_t)dm->key); + dm->key = 0; + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + } + RW_MUTEX_DTOR(me->mut); + me->openMods = 0; } static int open_mod_table_open_from_static(struct open_mod_table *me, struct static_mod **tbl, const char *uri, remote_handle *handle); -static int open_mod_table_open_static_override(struct open_mod_table *me, - const char *uri, - remote_handle *handle) { - FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_static_override"); - return open_mod_table_open_from_static(me, &me->smt->staticModOverrides, uri, - handle); +static int +open_mod_table_open_static_override(struct open_mod_table *me, const char *uri, + remote_handle *handle) +{ + FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_static_override"); + return open_mod_table_open_from_static( + me, &me->smt->staticModOverrides, uri, handle); } -static int open_mod_table_open_static(struct open_mod_table *me, - const char *uri, remote_handle *handle) { - FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_static"); - return open_mod_table_open_from_static(me, &me->smt->staticMods, uri, handle); +static int +open_mod_table_open_static(struct open_mod_table *me, const char *uri, + remote_handle *handle) +{ + FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_static"); + return open_mod_table_open_from_static(me, &me->smt->staticMods, uri, + handle); } -static int static_mod_add(struct static_mod_table *me, struct static_mod **tbl, - const char *uri, - int (*invoke)(uint32_t sc, remote_arg *pra), - int (*handle_invoke)(remote_handle64, uint32_t sc, - remote_arg *pra)) { - int nErr = AEE_SUCCESS; - struct static_mod *sm = 0; - int len = strlen(uri) + 1; - VERIFYC(NULL != (sm = ((struct static_mod *)calloc( - 1, sizeof(struct static_mod) + len))), - AEE_ENOMEMORY); - strlcpy(sm->uri, uri, len); - sm->invoke = invoke; - sm->handle_invoke = handle_invoke; - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_ADD_STR(*tbl, uri, sm); - RW_MUTEX_UNLOCK_WRITE(me->mut); +static int +static_mod_add(struct static_mod_table *me, struct static_mod **tbl, + const char *uri, int (*invoke)(uint32_t sc, remote_arg *pra), + int (*handle_invoke)(remote_handle64, uint32_t sc, + remote_arg *pra)) +{ + int nErr = AEE_SUCCESS; + struct static_mod *sm = 0; + int len = strlen(uri) + 1; + VERIFYC(NULL + != (sm = ((struct static_mod *)calloc( + 1, sizeof(struct static_mod) + len))), + AEE_ENOMEMORY); + strlcpy(sm->uri, uri, len); + sm->invoke = invoke; + sm->handle_invoke = handle_invoke; + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_ADD_STR(*tbl, uri, sm); + RW_MUTEX_UNLOCK_WRITE(me->mut); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: static module addition failed\n", nErr); - if (sm) { - free(sm); - sm = NULL; - } - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: static module addition failed\n", + nErr); + if(sm) { + free(sm); + sm = NULL; + } + } + return nErr; } -static int static_mod_table_register_static_override( - struct static_mod_table *me, const char *uri, - int (*pfn)(uint32_t sc, remote_arg *pra)) { - return static_mod_add(me, &me->staticModOverrides, uri, pfn, 0); +static int +static_mod_table_register_static_override(struct static_mod_table *me, + const char *uri, + int (*pfn)(uint32_t sc, + remote_arg *pra)) +{ + return static_mod_add(me, &me->staticModOverrides, uri, pfn, 0); } -static int static_mod_table_register_static_override1( +static int +static_mod_table_register_static_override1( struct static_mod_table *me, const char *uri, - int (*pfn)(remote_handle64, uint32_t sc, remote_arg *pra)) { - return static_mod_add(me, &me->staticModOverrides, uri, 0, pfn); + int (*pfn)(remote_handle64, uint32_t sc, remote_arg *pra)) +{ + return static_mod_add(me, &me->staticModOverrides, uri, 0, pfn); } static int static_mod_table_register_static(struct static_mod_table *me, const char *uri, - int (*pfn)(uint32_t sc, remote_arg *pra)) { - return static_mod_add(me, &me->staticMods, uri, pfn, 0); + int (*pfn)(uint32_t sc, remote_arg *pra)) +{ + return static_mod_add(me, &me->staticMods, uri, pfn, 0); } -static int static_mod_table_register_static1( - struct static_mod_table *me, const char *uri, - int (*pfn)(remote_handle64, uint32_t sc, remote_arg *pra)) { - return static_mod_add(me, &me->staticMods, uri, 0, pfn); +static int +static_mod_table_register_static1(struct static_mod_table *me, const char *uri, + int (*pfn)(remote_handle64, uint32_t sc, + remote_arg *pra)) +{ + return static_mod_add(me, &me->staticMods, uri, 0, pfn); } -static int static_mod_table_register_const_handle( +static int +static_mod_table_register_const_handle( struct static_mod_table *me, remote_handle local, remote_handle64 remote, const char *uri, int (*invoke)(uint32_t sc, remote_arg *pra), - int (*handle_invoke)(remote_handle64, uint32_t sc, remote_arg *pra)) { - int nErr = AEE_SUCCESS; - int len = strlen(uri) + 1; - struct const_mod *dm = 0, *dmOld; - VERIFYC(NULL != (dm = ((struct const_mod *)calloc(1, sizeof(struct open_mod) + - len))), - AEE_ENOMEMORY); - dm->key = local; - dm->invoke = invoke; - dm->handle_invoke = handle_invoke; - dm->h64 = remote; - strlcpy(dm->uri, uri, len); - - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_FIND_INT(me->constMods, &local, dmOld); - if (dmOld == 0) { - HASH_ADD_INT(me->constMods, key, dm); - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - nErr = dmOld != 0 ? -1 : nErr; + int (*handle_invoke)(remote_handle64, uint32_t sc, remote_arg *pra)) +{ + int nErr = AEE_SUCCESS; + int len = strlen(uri) + 1; + struct const_mod *dm = 0, *dmOld; + VERIFYC(NULL + != (dm = ((struct const_mod *)calloc( + 1, sizeof(struct open_mod) + len))), + AEE_ENOMEMORY); + dm->key = local; + dm->invoke = invoke; + dm->handle_invoke = handle_invoke; + dm->h64 = remote; + strlcpy(dm->uri, uri, len); + + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_FIND_INT(me->constMods, &local, dmOld); + if(dmOld == 0) { + HASH_ADD_INT(me->constMods, key, dm); + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + nErr = dmOld != 0 ? -1 : nErr; bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: failed to register const handle in modtable\n", - nErr); - if (dm) { - free(dm); - dm = NULL; - } - } - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error %x: failed to register const handle in modtable\n", + nErr); + if(dm) { + free(dm); + dm = NULL; + } + } + return nErr; } -static int open_mod_handle_open(struct open_mod *mod, const char *name, - remote_handle64 *ph) { - int nErr = AEE_SUCCESS; - remote_arg args[3] = {0}; - int32_t len = strlen(name) + 1; - args[0].buf.pv = &len; - args[0].buf.nLen = sizeof(len); - args[1].buf.pv = (void *)name; - args[1].buf.nLen = len; - nErr = mod->handle_invoke(0, REMOTE_SCALARS_MAKEX(0, 0, 2, 0, 0, 1), args); - if (!nErr) { - *ph = args[2].h64; - } - FARF(RUNTIME_RPC_HIGH, "allocated %x", *ph); - return nErr; +static int +open_mod_handle_open(struct open_mod *mod, const char *name, + remote_handle64 *ph) +{ + int nErr = AEE_SUCCESS; + remote_arg args[3] = { 0 }; + int32_t len = strlen(name) + 1; + args[0].buf.pv = &len; + args[0].buf.nLen = sizeof(len); + args[1].buf.pv = (void *)name; + args[1].buf.nLen = len; + nErr = mod->handle_invoke(0, REMOTE_SCALARS_MAKEX(0, 0, 2, 0, 0, 1), + args); + if(!nErr) { + *ph = args[2].h64; + } + FARF(RUNTIME_RPC_HIGH, "allocated %x", *ph); + return nErr; +} + +static int +open_mod_handle_close(struct open_mod *mod, remote_handle64 h) +{ + int nErr; + remote_arg args[1] = { 0 }; + args[0].h64 = h; + FARF(RUNTIME_RPC_HIGH, "releasing %x", h); + nErr = mod->handle_invoke(0, REMOTE_SCALARS_MAKEX(0, 1, 0, 0, 1, 0), + args); + return nErr; } -static int open_mod_handle_close(struct open_mod *mod, remote_handle64 h) { - int nErr; - remote_arg args[1] = {0}; - args[0].h64 = h; - FARF(RUNTIME_RPC_HIGH, "releasing %x", h); - nErr = mod->handle_invoke(0, REMOTE_SCALARS_MAKEX(0, 1, 0, 0, 1, 0), args); - return nErr; +static int +notqmark(struct sbuf *buf) +{ + return sbuf_notchar(buf, '?'); +} +static int +notandoreq(struct sbuf *buf) +{ + return sbuf_notchars(buf, "&="); +} +static int +notand(struct sbuf *buf) +{ + return sbuf_notchar(buf, '&'); } -static int notqmark(struct sbuf *buf) { return sbuf_notchar(buf, '?'); } -static int notandoreq(struct sbuf *buf) { return sbuf_notchars(buf, "&="); } -static int notand(struct sbuf *buf) { return sbuf_notchar(buf, '&'); } - -static int parse_uri(const char *uri, int urilen, struct parsed_uri *out) { - // "file:///librhtest_skel.so?rhtest_skel_handle_invoke&_modver=1.0" - int nErr = 0; - char *name, *value; - int nameLen, valueLen; - struct sbuf buf; - FARF(RUNTIME_RPC_HIGH, "parse_uri %s %d", uri, urilen); - memset(out, 0, sizeof(*out)); - // initialize - sbuf_parser_init(&buf, uri, urilen); - - // parse until question mark - VERIFYC(sbuf_string(&buf, "file://"), AEE_EBADPARM); - - // ignore the starting / - (void)sbuf_string(&buf, "/"); - - out->file = sbuf_cur(&buf); - VERIFY(sbuf_many1(&buf, notqmark)); - out->filelen = sbuf_cur(&buf) - out->file; - FARF(RUNTIME_RPC_HIGH, "file:%.*s %d", out->filelen, out->file, out->filelen); - VERIFY(sbuf_char(&buf, '?')); - out->sym = sbuf_cur(&buf); - VERIFY(sbuf_many1(&buf, notand)); - out->symlen = sbuf_cur(&buf) - out->sym; - assert(out->sym + out->symlen <= uri + urilen); - FARF(RUNTIME_RPC_HIGH, "sym:%.*s %d", out->symlen, out->sym, out->symlen); - - if (!sbuf_end(&buf) && sbuf_char(&buf, '&')) { - // parse each query - while (!sbuf_end(&buf)) { - // record where the name starts - name = sbuf_cur(&buf); - - // name is valid until '=' or '&' - VERIFY(sbuf_many1(&buf, notandoreq)); - nameLen = sbuf_cur(&buf) - name; - - value = 0; - valueLen = 0; - // if the next char is a '=' then we also get a value - if (sbuf_char(&buf, '=')) { - value = sbuf_cur(&buf); - - // value is until the next query that starts with '&' - VERIFY(sbuf_many1(&buf, notand)); - valueLen = sbuf_cur(&buf) - value; - } - // expect '&' or end - sbuf_char(&buf, '&'); - if (!strncmp(name, "_modver", nameLen)) { - out->ver = value; - out->verlen = valueLen; - } - } - } +static int +parse_uri(const char *uri, int urilen, struct parsed_uri *out) +{ + // "file:///librhtest_skel.so?rhtest_skel_handle_invoke&_modver=1.0" + int nErr = 0; + char *name, *value; + int nameLen, valueLen; + struct sbuf buf; + FARF(RUNTIME_RPC_HIGH, "parse_uri %s %d", uri, urilen); + memset(out, 0, sizeof(*out)); + // initialize + sbuf_parser_init(&buf, uri, urilen); + + // parse until question mark + VERIFYC(sbuf_string(&buf, "file://"), AEE_EBADPARM); + + // ignore the starting / + (void)sbuf_string(&buf, "/"); + + out->file = sbuf_cur(&buf); + VERIFY(sbuf_many1(&buf, notqmark)); + out->filelen = sbuf_cur(&buf) - out->file; + FARF(RUNTIME_RPC_HIGH, "file:%.*s %d", out->filelen, out->file, + out->filelen); + VERIFY(sbuf_char(&buf, '?')); + out->sym = sbuf_cur(&buf); + VERIFY(sbuf_many1(&buf, notand)); + out->symlen = sbuf_cur(&buf) - out->sym; + assert(out->sym + out->symlen <= uri + urilen); + FARF(RUNTIME_RPC_HIGH, "sym:%.*s %d", out->symlen, out->sym, + out->symlen); + + if(!sbuf_end(&buf) && sbuf_char(&buf, '&')) { + // parse each query + while(!sbuf_end(&buf)) { + // record where the name starts + name = sbuf_cur(&buf); + + // name is valid until '=' or '&' + VERIFY(sbuf_many1(&buf, notandoreq)); + nameLen = sbuf_cur(&buf) - name; + + value = 0; + valueLen = 0; + // if the next char is a '=' then we also get a value + if(sbuf_char(&buf, '=')) { + value = sbuf_cur(&buf); + + // value is until the next query that starts + // with '&' + VERIFY(sbuf_many1(&buf, notand)); + valueLen = sbuf_cur(&buf) - value; + } + // expect '&' or end + sbuf_char(&buf, '&'); + if(!strncmp(name, "_modver", nameLen)) { + out->ver = value; + out->verlen = valueLen; + } + } + } bail: - if (out->filelen) { - FARF(RUNTIME_RPC_HIGH, "parse_uri file: %.*s", out->filelen, out->file); - } - if (out->symlen) { - FARF(RUNTIME_RPC_HIGH, "parse_uri sym: %.*s", out->symlen, out->sym); - } - if (out->verlen) { - FARF(RUNTIME_RPC_HIGH, "parse_uri version: %.*s", out->verlen, out->ver); - } - FARF(RUNTIME_RPC_HIGH, "parse_uri done: %s %d err:%x", uri, urilen, nErr); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: parseuri failed for uri %s, urilen %d\n", nErr, - uri, urilen); - } - return nErr; + if(out->filelen) { + FARF(RUNTIME_RPC_HIGH, "parse_uri file: %.*s", out->filelen, + out->file); + } + if(out->symlen) { + FARF(RUNTIME_RPC_HIGH, "parse_uri sym: %.*s", out->symlen, + out->sym); + } + if(out->verlen) { + FARF(RUNTIME_RPC_HIGH, "parse_uri version: %.*s", out->verlen, + out->ver); + } + FARF(RUNTIME_RPC_HIGH, "parse_uri done: %s %d err:%x", uri, urilen, + nErr); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF( + "Error %x: parseuri failed for uri %s, urilen %d\n", nErr, + uri, urilen); + } + return nErr; } /* - * Iterate through the list of reverse handles and search for the next available - * handle. 'key' is only set when handle have been taken and is set to 0 when - * handle is free. Returns 0 if it found a free handle, otherwise return -1 if - * it fails. + * Iterate through the list of reverse handles and search for the next + * available handle. 'key' is only set when handle have been taken and is set + * to 0 when handle is free. Returns 0 if it found a free handle, otherwise + * return -1 if it fails. */ -static inline int next_available_rev_handle(uint32_t *handle_idx) { - int nErr = AEE_EUNKNOWN; - struct open_mod *dm = 0; - unsigned int ii; - - for (ii = 0; ii < MAX_REV_HANDLES; ++ii) { - dm = (struct open_mod *)&(rev_handle_table[ii][0]); - if (dm->key == 0) { - *handle_idx = ii; - nErr = 0; - break; - } - } - if (nErr) - FARF(ERROR, - "Error 0x%x: %s: max number of reverse RPC handles (%u) open already", - nErr, __func__, MAX_REV_HANDLES); - return nErr; +static inline int +next_available_rev_handle(uint32_t *handle_idx) +{ + int nErr = AEE_EUNKNOWN; + struct open_mod *dm = 0; + unsigned int ii; + + for(ii = 0; ii < MAX_REV_HANDLES; ++ii) { + dm = (struct open_mod *)&(rev_handle_table[ii][0]); + if(dm->key == 0) { + *handle_idx = ii; + nErr = 0; + break; + } + } + if(nErr) + FARF(ERROR, + "Error 0x%x: %s: max number of reverse RPC handles (%u) " + "open already", + nErr, __func__, MAX_REV_HANDLES); + return nErr; } -uint32_t is_reverse_handle_opened(struct open_mod_table *me, - remote_handle *handle, const char *uri) { - int ii = 0; - uint32_t keyfound = 0; - struct open_mod *dmOld; - RW_MUTEX_LOCK_WRITE(me->mut); - for (ii = 0; ii < MAX_REV_HANDLES; ++ii) { - dmOld = (struct open_mod *)&(rev_handle_table[ii][0]); - if (dmOld->key != 0) { - if (!strncmp(dmOld->uri, uri, MAX(strlen(dmOld->uri), strlen(uri)))) { - keyfound = 1; - break; - } - } - } - if (keyfound) { - *handle = dmOld->key; - dmOld->refs++; - FARF( - ALWAYS, - "%s: reverse module %s already found with handle 0x%x (idx %u) refs %d", - __func__, uri, *handle, ii, dmOld->refs); - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - return keyfound; +uint32_t +is_reverse_handle_opened(struct open_mod_table *me, remote_handle *handle, + const char *uri) +{ + int ii = 0; + uint32_t keyfound = 0; + struct open_mod *dmOld; + RW_MUTEX_LOCK_WRITE(me->mut); + for(ii = 0; ii < MAX_REV_HANDLES; ++ii) { + dmOld = (struct open_mod *)&(rev_handle_table[ii][0]); + if(dmOld->key != 0) { + if(!strncmp(dmOld->uri, uri, + MAX(strlen(dmOld->uri), strlen(uri)))) { + keyfound = 1; + break; + } + } + } + if(keyfound) { + *handle = dmOld->key; + dmOld->refs++; + FARF(ALWAYS, + "%s: reverse module %s already found with handle 0x%x " + "(idx %u) refs %d", + __func__, uri, *handle, ii, dmOld->refs); + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + return keyfound; } -static int open_mod_table_open_dynamic(struct open_mod_table *me, - const char *uri, remote_handle *handle, - char *dlStr, int dlerrorLen, - int *pdlErr) { - int nErr = AEE_SUCCESS, dlErr = 0; - struct open_mod *dm = 0, *dmOld; - int len = strlen(uri); - int tmplen = len * 2 + - sizeof("file:///lib_skel.so?_skel_handle_invoke&_modver=1.0") + - 1; - char *tmp = 0; - uint32_t handle_idx = 0, keyfound = 0; - int lock = 0; - - FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_dynamic uri %s", uri); - VERIFYC(NULL != (tmp = calloc(1, tmplen)), AEE_ENOMEMORY); - VERIFYC((REV_HANDLE_SIZE >= sizeof(struct open_mod) + len + 1), - AEE_ENOMEMORY); - RW_MUTEX_LOCK_WRITE(rev_handle_table_lock); - lock = 1; - keyfound = is_reverse_handle_opened(me, handle, uri); - if (keyfound) { - goto bail; - } - - VERIFYC(0 == (nErr = next_available_rev_handle(&handle_idx)), AEE_EINVHANDLE); - VERIFYC(handle_idx < MAX_REV_HANDLES, AEE_EINVHANDLE); - dm = (struct open_mod *)&(rev_handle_table[handle_idx][0]); - memset(dm, 0, REV_HANDLE_SIZE); - memmove(dm->uri, uri, len + 1); - FARF(RUNTIME_RPC_HIGH, "calling parse_uri"); - (void)parse_uri(dm->uri, len, &dm->vals); - FARF(RUNTIME_RPC_HIGH, "done calling parse_uri"); - FARF(RUNTIME_RPC_HIGH, "vals %d %d %d", dm->vals.filelen, dm->vals.symlen, - dm->vals.verlen); - if (dm->vals.filelen) { - int rv = snprintf(tmp, tmplen, "%.*s", dm->vals.filelen, dm->vals.file); - VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); - } else { - int rv; - rv = snprintf(tmp, tmplen, "lib%s_skel.so", uri); - VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); - } - - FARF(RUNTIME_RPC_HIGH, "calling dlopen for %s", tmp); - errno = 0; - dm->dlhandle = DLOPEN(tmp, RTLD_NOW); - - // Only check for system library if original library was not found - if ((dlErr = dm->dlhandle == 0 ? AEE_EINVHANDLE : 0) && errno == ENOENT) { - int str_len, ii, rv; - - FARF(RUNTIME_RPC_HIGH, "Couldn't find %s", tmp); - str_len = strlen(tmp); - VERIFYC(str_len <= tmplen, AEE_EBADPARM); - for (ii = str_len - 1; ii >= 0; ii--) { - - // Find index of last character before the extension ".so" starts - if (tmp[ii] == '.') { - tmp[ii] = '\0'; - break; - } - } - rv = snprintf(tmp, tmplen, "%s_system.so", tmp); - VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); - FARF(RUNTIME_RPC_HIGH, "calling dlopen for %s", tmp); - dm->dlhandle = DLOPEN(tmp, RTLD_NOW); - dlErr = dm->dlhandle == 0 ? AEE_EINVHANDLE : 0; - if (dlErr == 0) - FARF(ALWAYS, "system library %s successfully loaded", tmp); - } - FARF(RUNTIME_RPC_HIGH, "got DL handle %p for %s", dm->dlhandle, tmp); - VERIFY(!(nErr = dlErr)); - - if (dm->vals.symlen) { - int rv = snprintf(tmp, tmplen, "%.*s", dm->vals.symlen, dm->vals.sym); - VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); - } else { - int rv = snprintf(tmp, tmplen, "%s_skel_invoke", uri); - VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); - } - - FARF(RUNTIME_RPC_HIGH, "calling dlsym for %s", tmp); - if (dm->vals.verlen && - 0 == strncmp(dm->vals.ver, "1.0", dm->vals.verlen)) { - dm->handle_invoke = (handle_invoke_fn)DLSYM(dm->dlhandle, tmp); - } else { - dm->invoke = (invoke_fn)DLSYM(dm->dlhandle, tmp); - } - FARF(RUNTIME_RPC_HIGH, "dlsym returned %p %p", dm->invoke, dm->handle_invoke); - VERIFYC(!(dlErr = dm->invoke || dm->handle_invoke ? 0 : AEE_ENOSUCHSYMBOL), - AEE_ENOSUCHSYMBOL); - - dm->key = (uint32_t)(uintptr_t)dm; - dm->refs = 1; - if (dm->handle_invoke) { - VERIFY(AEE_SUCCESS == (nErr = open_mod_handle_open(dm, uri, &dm->h64))); - } - - RW_MUTEX_LOCK_WRITE(me->mut); - if (!keyfound) { - do { - HASH_FIND_INT(me->openMods, &dm->key, dmOld); - if (dmOld) { - dm->key++; - } - } while (dmOld); - RW_MUTEX_LOCK_WRITE(me->smt->mut); - HASH_FIND_INT(me->smt->constMods, &dm->key, dmOld); - RW_MUTEX_UNLOCK_WRITE(me->smt->mut); - if (dmOld == 0) { - HASH_ADD_INT(me->openMods, key, dm); - } - nErr = dmOld != 0 ? -1 : nErr; - if (nErr == 0) { - *handle = dm->key; - } - } - RW_MUTEX_UNLOCK_WRITE(me->mut); +static int +open_mod_table_open_dynamic(struct open_mod_table *me, const char *uri, + remote_handle *handle, char *dlStr, int dlerrorLen, + int *pdlErr) +{ + int nErr = AEE_SUCCESS, dlErr = 0; + struct open_mod *dm = 0, *dmOld; + int len = strlen(uri); + int tmplen + = len * 2 + + sizeof("file:///lib_skel.so?_skel_handle_invoke&_modver=1.0") + + 1; + char *tmp = 0; + uint32_t handle_idx = 0, keyfound = 0; + int lock = 0; + + FARF(RUNTIME_RPC_HIGH, "open_mod_table_open_dynamic uri %s", uri); + VERIFYC(NULL != (tmp = calloc(1, tmplen)), AEE_ENOMEMORY); + VERIFYC((REV_HANDLE_SIZE >= sizeof(struct open_mod) + len + 1), + AEE_ENOMEMORY); + RW_MUTEX_LOCK_WRITE(rev_handle_table_lock); + lock = 1; + keyfound = is_reverse_handle_opened(me, handle, uri); + if(keyfound) { + goto bail; + } + + VERIFYC(0 == (nErr = next_available_rev_handle(&handle_idx)), + AEE_EINVHANDLE); + VERIFYC(handle_idx < MAX_REV_HANDLES, AEE_EINVHANDLE); + dm = (struct open_mod *)&(rev_handle_table[handle_idx][0]); + memset(dm, 0, REV_HANDLE_SIZE); + memmove(dm->uri, uri, len + 1); + FARF(RUNTIME_RPC_HIGH, "calling parse_uri"); + (void)parse_uri(dm->uri, len, &dm->vals); + FARF(RUNTIME_RPC_HIGH, "done calling parse_uri"); + FARF(RUNTIME_RPC_HIGH, "vals %d %d %d", dm->vals.filelen, + dm->vals.symlen, dm->vals.verlen); + if(dm->vals.filelen) { + int rv = snprintf(tmp, tmplen, "%.*s", dm->vals.filelen, + dm->vals.file); + VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); + } else { + int rv; + rv = snprintf(tmp, tmplen, "lib%s_skel.so", uri); + VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); + } + + FARF(RUNTIME_RPC_HIGH, "calling dlopen for %s", tmp); + errno = 0; + dm->dlhandle = DLOPEN(tmp, RTLD_NOW); + + // Only check for system library if original library was not found + if((dlErr = dm->dlhandle == 0 ? AEE_EINVHANDLE : 0) + && errno == ENOENT) { + int str_len, ii, rv; + + FARF(RUNTIME_RPC_HIGH, "Couldn't find %s", tmp); + str_len = strlen(tmp); + VERIFYC(str_len <= tmplen, AEE_EBADPARM); + for(ii = str_len - 1; ii >= 0; ii--) { + + // Find index of last character before the extension + // ".so" starts + if(tmp[ii] == '.') { + tmp[ii] = '\0'; + break; + } + } + rv = snprintf(tmp, tmplen, "%s_system.so", tmp); + VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); + FARF(RUNTIME_RPC_HIGH, "calling dlopen for %s", tmp); + dm->dlhandle = DLOPEN(tmp, RTLD_NOW); + dlErr = dm->dlhandle == 0 ? AEE_EINVHANDLE : 0; + if(dlErr == 0) + FARF(ALWAYS, "system library %s successfully loaded", + tmp); + } + FARF(RUNTIME_RPC_HIGH, "got DL handle %p for %s", dm->dlhandle, tmp); + VERIFY(!(nErr = dlErr)); + + if(dm->vals.symlen) { + int rv = snprintf(tmp, tmplen, "%.*s", dm->vals.symlen, + dm->vals.sym); + VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); + } else { + int rv = snprintf(tmp, tmplen, "%s_skel_invoke", uri); + VERIFYC((rv > 0) && (tmplen >= rv), AEE_EBADPARM); + } + + FARF(RUNTIME_RPC_HIGH, "calling dlsym for %s", tmp); + if(dm->vals.verlen + && 0 == strncmp(dm->vals.ver, "1.0", dm->vals.verlen)) { + dm->handle_invoke = (handle_invoke_fn)DLSYM(dm->dlhandle, tmp); + } else { + dm->invoke = (invoke_fn)DLSYM(dm->dlhandle, tmp); + } + FARF(RUNTIME_RPC_HIGH, "dlsym returned %p %p", dm->invoke, + dm->handle_invoke); + VERIFYC( + !(dlErr = dm->invoke || dm->handle_invoke ? 0 : AEE_ENOSUCHSYMBOL), + AEE_ENOSUCHSYMBOL); + + dm->key = (uint32_t)(uintptr_t)dm; + dm->refs = 1; + if(dm->handle_invoke) { + VERIFY(AEE_SUCCESS + == (nErr = open_mod_handle_open(dm, uri, &dm->h64))); + } + + RW_MUTEX_LOCK_WRITE(me->mut); + if(!keyfound) { + do { + HASH_FIND_INT(me->openMods, &dm->key, dmOld); + if(dmOld) { + dm->key++; + } + } while(dmOld); + RW_MUTEX_LOCK_WRITE(me->smt->mut); + HASH_FIND_INT(me->smt->constMods, &dm->key, dmOld); + RW_MUTEX_UNLOCK_WRITE(me->smt->mut); + if(dmOld == 0) { + HASH_ADD_INT(me->openMods, key, dm); + } + nErr = dmOld != 0 ? -1 : nErr; + if(nErr == 0) { + *handle = dm->key; + } + } + RW_MUTEX_UNLOCK_WRITE(me->mut); bail: - if (lock) { - lock = 0; - RW_MUTEX_UNLOCK_WRITE(rev_handle_table_lock); - } - if (nErr == AEE_SUCCESS) { - FARF(ALWAYS, - "%s: dynamic reverse module %s opened with handle 0x%x (idx %u)", - __func__, uri, *handle, handle_idx); - } else { - if (dlErr) { - const char *dlerr = DLERROR(); - if (dlerr != 0) { - strlcpy(dlStr, dlerr, dlerrorLen); - } - FARF(RUNTIME_RPC_HIGH, "dlerror:0x%x:%s", dlErr, dlerr == 0 ? "" : dlerr); - nErr = 0; - } - if (pdlErr) { - *pdlErr = dlErr; - } - if (dm && dm->h64) { - (void)open_mod_handle_close(dm, dm->h64); - } - if (dm && dm->dlhandle) { - DLCLOSE(dm->dlhandle); - } - if (dm) { - dm->key = 0; - dm = NULL; - } - VERIFY_EPRINTF("Error 0x%x: %s failed for %s, dlerr 0x%x", nErr, __func__, - uri, dlErr); - } - - FARF(RUNTIME_RPC_HIGH, - "done open_mod_table_open_dynamic for %s rv %x handle: %p %x", uri, nErr, - *handle, dlErr); - if (tmp) { - free(tmp); - tmp = NULL; - } - return nErr; + if(lock) { + lock = 0; + RW_MUTEX_UNLOCK_WRITE(rev_handle_table_lock); + } + if(nErr == AEE_SUCCESS) { + FARF(ALWAYS, + "%s: dynamic reverse module %s opened with handle 0x%x " + "(idx %u)", + __func__, uri, *handle, handle_idx); + } else { + if(dlErr) { + const char *dlerr = DLERROR(); + if(dlerr != 0) { + strlcpy(dlStr, dlerr, dlerrorLen); + } + FARF(RUNTIME_RPC_HIGH, "dlerror:0x%x:%s", dlErr, + dlerr == 0 ? "" : dlerr); + nErr = 0; + } + if(pdlErr) { + *pdlErr = dlErr; + } + if(dm && dm->h64) { + (void)open_mod_handle_close(dm, dm->h64); + } + if(dm && dm->dlhandle) { + DLCLOSE(dm->dlhandle); + } + if(dm) { + dm->key = 0; + dm = NULL; + } + VERIFY_EPRINTF("Error 0x%x: %s failed for %s, dlerr 0x%x", + nErr, __func__, uri, dlErr); + } + + FARF(RUNTIME_RPC_HIGH, + "done open_mod_table_open_dynamic for %s rv %x handle: %p %x", + uri, nErr, *handle, dlErr); + if(tmp) { + free(tmp); + tmp = NULL; + } + return nErr; } -static int open_mod_table_open_from_static(struct open_mod_table *me, - struct static_mod **tbl, - const char *uri, - remote_handle *handle) { - int nErr = AEE_SUCCESS; - struct static_mod *sm = 0; - struct open_mod *dm = 0; - int len = strlen(uri); - int sz = len * 2 + - sizeof("file:///lib_skel.so?_skel_handle_invoke&_modver=1.0") + 1; - uint32_t handle_idx = 0, keyfound = 0; - int lock = 0; - - VERIFYC((REV_HANDLE_SIZE >= sizeof(struct open_mod) + sz), AEE_ENOMEMORY); - - RW_MUTEX_LOCK_WRITE(rev_handle_table_lock); - lock = 1; - keyfound = is_reverse_handle_opened(me, handle, uri); - if (keyfound) { - goto bail; - } - VERIFYC(0 == (nErr = next_available_rev_handle(&handle_idx)), AEE_EINVHANDLE); - VERIFYC(handle_idx < MAX_REV_HANDLES, AEE_EINVHANDLE); - dm = (struct open_mod *)&(rev_handle_table[handle_idx][0]); - memset(dm, 0, REV_HANDLE_SIZE); - RW_MUTEX_LOCK_READ(me->mut); - HASH_FIND_STR(*tbl, uri, sm); - RW_MUTEX_UNLOCK_READ(me->mut); - memmove(dm->uri, uri, len); - if (sm == 0) { - VERIFY(AEE_SUCCESS == (nErr = parse_uri(uri, len, &dm->vals))); - FARF(RUNTIME_RPC_HIGH, "file %.*s %d", dm->vals.filelen, dm->vals.file, - dm->vals.filelen); - FARF(RUNTIME_RPC_HIGH, "sym %.*s %d", dm->vals.symlen, dm->vals.sym, - dm->vals.symlen); - FARF(RUNTIME_RPC_HIGH, "version %.*s %d", dm->vals.verlen, dm->vals.ver, - dm->vals.verlen); - if (dm->vals.verlen) { - int rv = snprintf(dm->uri, sz, "file:///%.*s?%.*s&_modver=%.*s", - dm->vals.filelen, dm->vals.file, dm->vals.symlen, - dm->vals.sym, dm->vals.verlen, dm->vals.ver); - VERIFYC((rv > 0) && (sz >= rv), AEE_EBADPARM); - } else { - int rv = snprintf(dm->uri, sz, "file://%.*s?%.*s", dm->vals.filelen, - dm->vals.file, dm->vals.symlen, dm->vals.sym); - VERIFYC((rv > 0) && (sz >= rv), AEE_EBADPARM); - } - FARF(RUNTIME_RPC_HIGH, "dm->uri:%s", dm->uri); - - RW_MUTEX_LOCK_READ(me->mut); - HASH_FIND_STR(*tbl, dm->uri, sm); - RW_MUTEX_UNLOCK_READ(me->mut); - } - VERIFYM(0 != sm, AEE_ENOSUCHMOD, "Error %x: static mod is not initialized\n", - nErr); - assert(sm->handle_invoke || sm->invoke); - dm->handle_invoke = sm->handle_invoke; - dm->invoke = sm->invoke; - dm->key = (uint32_t)(uintptr_t)dm; - dm->refs = 1; - if (dm->handle_invoke) { - VERIFY(AEE_SUCCESS == (nErr = open_mod_handle_open(dm, uri, &dm->h64))); - } - - RW_MUTEX_LOCK_WRITE(me->mut); - if (!keyfound) { - HASH_ADD_INT(me->openMods, key, dm); - *handle = dm->key; - } - RW_MUTEX_UNLOCK_WRITE(me->mut); +static int +open_mod_table_open_from_static(struct open_mod_table *me, + struct static_mod **tbl, const char *uri, + remote_handle *handle) +{ + int nErr = AEE_SUCCESS; + struct static_mod *sm = 0; + struct open_mod *dm = 0; + int len = strlen(uri); + int sz + = len * 2 + + sizeof("file:///lib_skel.so?_skel_handle_invoke&_modver=1.0") + + 1; + uint32_t handle_idx = 0, keyfound = 0; + int lock = 0; + + VERIFYC((REV_HANDLE_SIZE >= sizeof(struct open_mod) + sz), + AEE_ENOMEMORY); + + RW_MUTEX_LOCK_WRITE(rev_handle_table_lock); + lock = 1; + keyfound = is_reverse_handle_opened(me, handle, uri); + if(keyfound) { + goto bail; + } + VERIFYC(0 == (nErr = next_available_rev_handle(&handle_idx)), + AEE_EINVHANDLE); + VERIFYC(handle_idx < MAX_REV_HANDLES, AEE_EINVHANDLE); + dm = (struct open_mod *)&(rev_handle_table[handle_idx][0]); + memset(dm, 0, REV_HANDLE_SIZE); + RW_MUTEX_LOCK_READ(me->mut); + HASH_FIND_STR(*tbl, uri, sm); + RW_MUTEX_UNLOCK_READ(me->mut); + memmove(dm->uri, uri, len); + if(sm == 0) { + VERIFY(AEE_SUCCESS == (nErr = parse_uri(uri, len, &dm->vals))); + FARF(RUNTIME_RPC_HIGH, "file %.*s %d", dm->vals.filelen, + dm->vals.file, dm->vals.filelen); + FARF(RUNTIME_RPC_HIGH, "sym %.*s %d", dm->vals.symlen, + dm->vals.sym, dm->vals.symlen); + FARF(RUNTIME_RPC_HIGH, "version %.*s %d", dm->vals.verlen, + dm->vals.ver, dm->vals.verlen); + if(dm->vals.verlen) { + int rv = snprintf( + dm->uri, sz, "file:///%.*s?%.*s&_modver=%.*s", + dm->vals.filelen, dm->vals.file, dm->vals.symlen, + dm->vals.sym, dm->vals.verlen, dm->vals.ver); + VERIFYC((rv > 0) && (sz >= rv), AEE_EBADPARM); + } else { + int rv = snprintf(dm->uri, sz, "file://%.*s?%.*s", + dm->vals.filelen, dm->vals.file, + dm->vals.symlen, dm->vals.sym); + VERIFYC((rv > 0) && (sz >= rv), AEE_EBADPARM); + } + FARF(RUNTIME_RPC_HIGH, "dm->uri:%s", dm->uri); + + RW_MUTEX_LOCK_READ(me->mut); + HASH_FIND_STR(*tbl, dm->uri, sm); + RW_MUTEX_UNLOCK_READ(me->mut); + } + VERIFYM(0 != sm, AEE_ENOSUCHMOD, + "Error %x: static mod is not initialized\n", nErr); + assert(sm->handle_invoke || sm->invoke); + dm->handle_invoke = sm->handle_invoke; + dm->invoke = sm->invoke; + dm->key = (uint32_t)(uintptr_t)dm; + dm->refs = 1; + if(dm->handle_invoke) { + VERIFY(AEE_SUCCESS + == (nErr = open_mod_handle_open(dm, uri, &dm->h64))); + } + + RW_MUTEX_LOCK_WRITE(me->mut); + if(!keyfound) { + HASH_ADD_INT(me->openMods, key, dm); + *handle = dm->key; + } + RW_MUTEX_UNLOCK_WRITE(me->mut); bail: - if (lock) { - lock = 0; - RW_MUTEX_UNLOCK_WRITE(rev_handle_table_lock); - } - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error 0x%x: %s failed for %s", nErr, __func__, uri); - } else { - FARF(RUNTIME_RPC_HIGH, "%s: reverse module %s opened with handle 0x%x (idx %u)", - __func__, uri, *handle, handle_idx); - } - if (nErr && dm) { - if (dm->h64) { - (void)open_mod_handle_close(dm, dm->h64); - } - dm->key = 0; - dm = NULL; - } - return nErr; + if(lock) { + lock = 0; + RW_MUTEX_UNLOCK_WRITE(rev_handle_table_lock); + } + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error 0x%x: %s failed for %s", nErr, __func__, + uri); + } else { + FARF(RUNTIME_RPC_HIGH, + "%s: reverse module %s opened with handle 0x%x (idx %u)", + __func__, uri, *handle, handle_idx); + } + if(nErr && dm) { + if(dm->h64) { + (void)open_mod_handle_close(dm, dm->h64); + } + dm->key = 0; + dm = NULL; + } + return nErr; } -static int open_mod_table_open(struct open_mod_table *me, const char *uri, - remote_handle *handle, char *dlerr, - int dlerrorLen, int *pdlErr) { - int nErr = AEE_SUCCESS, dlErr = 0; - if (pdlErr) { - *pdlErr = 0; - } - if (0 != open_mod_table_open_static_override(me, uri, handle)) { - VERIFY(AEE_SUCCESS == (nErr = open_mod_table_open_dynamic( - me, uri, handle, dlerr, dlerrorLen, &dlErr))); - if (dlErr != 0) { - FARF(RUNTIME_RPC_HIGH, "dynammic open failed, trying static"); - if (0 != open_mod_table_open_static(me, uri, handle)) { - if (pdlErr) { - *pdlErr = dlErr; - } - } - } - } +static int +open_mod_table_open(struct open_mod_table *me, const char *uri, + remote_handle *handle, char *dlerr, int dlerrorLen, + int *pdlErr) +{ + int nErr = AEE_SUCCESS, dlErr = 0; + if(pdlErr) { + *pdlErr = 0; + } + if(0 != open_mod_table_open_static_override(me, uri, handle)) { + VERIFY(AEE_SUCCESS + == (nErr = open_mod_table_open_dynamic( + me, uri, handle, dlerr, dlerrorLen, &dlErr))); + if(dlErr != 0) { + FARF(RUNTIME_RPC_HIGH, + "dynammic open failed, trying static"); + if(0 != open_mod_table_open_static(me, uri, handle)) { + if(pdlErr) { + *pdlErr = dlErr; + } + } + } + } bail: - FARF(RUNTIME_RPC_HIGH, "done open for %s rv %d handle: %p", uri, nErr, - *handle); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: open modtable failed\n", nErr); - } - return nErr; + FARF(RUNTIME_RPC_HIGH, "done open for %s rv %d handle: %p", uri, nErr, + *handle); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: open modtable failed\n", nErr); + } + return nErr; } -static void open_mod_close(struct open_mod_table *me, struct open_mod *dm) { - RW_MUTEX_LOCK_WRITE(me->mut); - FARF(RUNTIME_RPC_HIGH, "%s: uri:%s, refs:%d", __func__, dm->uri, dm->refs); - dm->refs--; - if (dm->refs == 0) { - HASH_DEL(me->openMods, dm); - } else { - FARF(RUNTIME_RPC_HIGH, "%s : module %s has pending invokes ref count %d", - __func__, dm->uri, dm->refs); - dm = 0; - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - if (dm) { - if (dm->h64) { - (void)open_mod_handle_close(dm, dm->h64); - } - if (dm->dlhandle) { - DLCLOSE(dm->dlhandle); - } - FARF(ALWAYS, "%s: closed reverse module %s with handle 0x%x", __func__, - dm->uri, (uint32_t)dm->key); - dm->key = 0; - dm = NULL; - } +static void +open_mod_close(struct open_mod_table *me, struct open_mod *dm) +{ + RW_MUTEX_LOCK_WRITE(me->mut); + FARF(RUNTIME_RPC_HIGH, "%s: uri:%s, refs:%d", __func__, dm->uri, + dm->refs); + dm->refs--; + if(dm->refs == 0) { + HASH_DEL(me->openMods, dm); + } else { + FARF(RUNTIME_RPC_HIGH, + "%s : module %s has pending invokes ref count %d", + __func__, dm->uri, dm->refs); + dm = 0; + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + if(dm) { + if(dm->h64) { + (void)open_mod_handle_close(dm, dm->h64); + } + if(dm->dlhandle) { + DLCLOSE(dm->dlhandle); + } + FARF(ALWAYS, "%s: closed reverse module %s with handle 0x%x", + __func__, dm->uri, (uint32_t)dm->key); + dm->key = 0; + dm = NULL; + } } -static int open_mod_table_close(struct open_mod_table *me, - remote_handle64 handle, char *errStr, - int errStrLen, int *pdlErr) { - int nErr = AEE_SUCCESS; - struct open_mod *dm, *del = 0; - int dlErr = 0, locked = 0; - // First ensure that the handle is valid - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_FIND_INT(me->openMods, &handle, dm); - locked = 1; - VERIFYC(dm, AEE_ENOSUCHMOD); - if (dm) { - dm->refs--; - if (dm->refs == 0) { - del = dm; - FARF(RUNTIME_RPC_HIGH, "deleting %s %p %d", del->uri, del, dm->refs); - HASH_DEL(me->openMods, dm); - del->key = 0; - } else { - FARF(RUNTIME_RPC_HIGH, "%s: pending ref: dm->refs %d, for uri: %s", - __func__, dm->refs, dm->uri); - dm = 0; - } - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - locked = 0; - if (del) { - if (del->h64) { - (void)open_mod_handle_close(dm, dm->h64); - } - if (del->dlhandle) { - dlErr = DLCLOSE(del->dlhandle); - } - FARF(ALWAYS, "%s: closed reverse module %s with handle 0x%x", __func__, - del->uri, (uint32_t)handle); - del = NULL; - } +static int +open_mod_table_close(struct open_mod_table *me, remote_handle64 handle, + char *errStr, int errStrLen, int *pdlErr) +{ + int nErr = AEE_SUCCESS; + struct open_mod *dm, *del = 0; + int dlErr = 0, locked = 0; + // First ensure that the handle is valid + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_FIND_INT(me->openMods, &handle, dm); + locked = 1; + VERIFYC(dm, AEE_ENOSUCHMOD); + if(dm) { + dm->refs--; + if(dm->refs == 0) { + del = dm; + FARF(RUNTIME_RPC_HIGH, "deleting %s %p %d", del->uri, + del, dm->refs); + HASH_DEL(me->openMods, dm); + del->key = 0; + } else { + FARF(RUNTIME_RPC_HIGH, + "%s: pending ref: dm->refs %d, for uri: %s", + __func__, dm->refs, dm->uri); + dm = 0; + } + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + locked = 0; + if(del) { + if(del->h64) { + (void)open_mod_handle_close(dm, dm->h64); + } + if(del->dlhandle) { + dlErr = DLCLOSE(del->dlhandle); + } + FARF(ALWAYS, "%s: closed reverse module %s with handle 0x%x", + __func__, del->uri, (uint32_t)handle); + del = NULL; + } bail: - if (locked) { - locked = 0; - RW_MUTEX_UNLOCK_WRITE(me->mut); - } - if (dlErr) { - const char *error = DLERROR(); - nErr = dlErr; - if (error != 0) { - strlcpy(errStr, error, errStrLen); - } - VERIFY_EPRINTF("Error %x: open modtable close failed. dlerr %s\n", nErr, - error); - } - if (pdlErr) { - *pdlErr = dlErr; - } - return nErr; + if(locked) { + locked = 0; + RW_MUTEX_UNLOCK_WRITE(me->mut); + } + if(dlErr) { + const char *error = DLERROR(); + nErr = dlErr; + if(error != 0) { + strlcpy(errStr, error, errStrLen); + } + VERIFY_EPRINTF( + "Error %x: open modtable close failed. dlerr %s\n", nErr, + error); + } + if(pdlErr) { + *pdlErr = dlErr; + } + return nErr; } -static struct open_mod *open_mod_table_get_open(struct open_mod_table *me, - remote_handle handle) { - struct open_mod *om = 0; - RW_MUTEX_LOCK_WRITE(me->mut); - HASH_FIND_INT(me->openMods, &handle, om); - if (0 != om) { - om->refs++; - FARF(RUNTIME_RPC_HIGH, "%s: module %s, increament refs %d", __func__, - om->uri, om->refs); - } - RW_MUTEX_UNLOCK_WRITE(me->mut); - return om; +static struct open_mod * +open_mod_table_get_open(struct open_mod_table *me, remote_handle handle) +{ + struct open_mod *om = 0; + RW_MUTEX_LOCK_WRITE(me->mut); + HASH_FIND_INT(me->openMods, &handle, om); + if(0 != om) { + om->refs++; + FARF(RUNTIME_RPC_HIGH, "%s: module %s, increament refs %d", + __func__, om->uri, om->refs); + } + RW_MUTEX_UNLOCK_WRITE(me->mut); + return om; } -static struct const_mod *open_mod_table_get_const(struct open_mod_table *me, - remote_handle handle) { - struct const_mod *cm = 0; - RW_MUTEX_LOCK_READ(me->smt->mut); - HASH_FIND_INT(me->smt->constMods, &handle, cm); - RW_MUTEX_UNLOCK_READ(me->smt->mut); - return cm; +static struct const_mod * +open_mod_table_get_const(struct open_mod_table *me, remote_handle handle) +{ + struct const_mod *cm = 0; + RW_MUTEX_LOCK_READ(me->smt->mut); + HASH_FIND_INT(me->smt->constMods, &handle, cm); + RW_MUTEX_UNLOCK_READ(me->smt->mut); + return cm; } -static int open_mod_table_handle_invoke(struct open_mod_table *me, - remote_handle handle, uint32_t sc, - remote_arg *pra) { - int nErr = AEE_SUCCESS; - struct open_mod *om = 0; - struct const_mod *cm = 0; - remote_handle64 h = 0; - invoke_fn invoke = 0; - handle_invoke_fn handle_invoke = 0; - cm = open_mod_table_get_const(me, handle); - - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", __func__, - handle, sc); - if (cm) { - invoke = cm->invoke; - handle_invoke = cm->handle_invoke; - h = cm->h64; - } else { - VERIFYC(0 != (om = open_mod_table_get_open(me, handle)), AEE_ENOSUCHMOD); - invoke = om->invoke; - handle_invoke = om->handle_invoke; - h = om->h64; - } - if (invoke) { - VERIFY(AEE_SUCCESS == (nErr = invoke(sc, pra))); - } else { - VERIFY(AEE_SUCCESS == (nErr = handle_invoke(h, sc, pra))); - } +static int +open_mod_table_handle_invoke(struct open_mod_table *me, remote_handle handle, + uint32_t sc, remote_arg *pra) +{ + int nErr = AEE_SUCCESS; + struct open_mod *om = 0; + struct const_mod *cm = 0; + remote_handle64 h = 0; + invoke_fn invoke = 0; + handle_invoke_fn handle_invoke = 0; + cm = open_mod_table_get_const(me, handle); + + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x , scalar 0x%x", + __func__, handle, sc); + if(cm) { + invoke = cm->invoke; + handle_invoke = cm->handle_invoke; + h = cm->h64; + } else { + VERIFYC(0 != (om = open_mod_table_get_open(me, handle)), + AEE_ENOSUCHMOD); + invoke = om->invoke; + handle_invoke = om->handle_invoke; + h = om->h64; + } + if(invoke) { + VERIFY(AEE_SUCCESS == (nErr = invoke(sc, pra))); + } else { + VERIFY(AEE_SUCCESS == (nErr = handle_invoke(h, sc, pra))); + } bail: - if (om) { - open_mod_close(me, om); - } - if (nErr != AEE_SUCCESS) { - FARF(ERROR, "Error 0x%x: %s failed for handle:0x%x, sc:0x%x", nErr, - __func__, handle, sc); - } - FASTRPC_ATRACE_END(); - return nErr; + if(om) { + open_mod_close(me, om); + } + if(nErr != AEE_SUCCESS) { + FARF(ERROR, "Error 0x%x: %s failed for handle:0x%x, sc:0x%x", + nErr, __func__, handle, sc); + } + FASTRPC_ATRACE_END(); + return nErr; } struct mod_table { - struct static_mod_table smt; - struct open_mod_table omt; + struct static_mod_table smt; + struct open_mod_table omt; }; // mod_table object @@ -937,23 +1051,27 @@ static struct static_mod_table static_mod_table_obj; * } * */ -int mod_table_register_static_override(const char *name, - int (*pfn)(uint32_t sc, remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_static_override(&static_mod_table_obj, - name, pfn); - } - return AEE_EUNKNOWN; +int +mod_table_register_static_override(const char *name, + int (*pfn)(uint32_t sc, remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_static_override( + &static_mod_table_obj, name, pfn); + } + return AEE_EUNKNOWN; } -int mod_table_register_static_override1(const char *name, - int (*pfn)(remote_handle64, uint32_t sc, - remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_static_override1(&static_mod_table_obj, - name, pfn); - } - return AEE_EUNKNOWN; +int +mod_table_register_static_override1(const char *name, + int (*pfn)(remote_handle64, uint32_t sc, + remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_static_override1( + &static_mod_table_obj, name, pfn); + } + return AEE_EUNKNOWN; } /** @@ -969,21 +1087,27 @@ int mod_table_register_static_override1(const char *name, * } * */ -int mod_table_register_static(const char *name, - int (*pfn)(uint32_t sc, remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_static(&static_mod_table_obj, name, pfn); - } - return AEE_EUNKNOWN; +int +mod_table_register_static(const char *name, + int (*pfn)(uint32_t sc, remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_static(&static_mod_table_obj, + name, pfn); + } + return AEE_EUNKNOWN; } -int mod_table_register_static1(const char *name, - int (*pfn)(remote_handle64, uint32_t sc, - remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_static1(&static_mod_table_obj, name, pfn); - } - return AEE_EUNKNOWN; +int +mod_table_register_static1(const char *name, + int (*pfn)(remote_handle64, uint32_t sc, + remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_static1(&static_mod_table_obj, + name, pfn); + } + return AEE_EUNKNOWN; } /** @@ -995,30 +1119,33 @@ int mod_table_register_static1(const char *name, * dlerrorLen, Length of error String (if an error occurs) * pdlErr, Error identifier */ -int mod_table_open(const char *uri, remote_handle *handle, char *dlerr, - int dlerrorLen, int *pdlErr) { - int nErr = AEE_SUCCESS; - struct open_mod_table *pomt = 0; - - VERIFYC(NULL != uri, AEE_EBADPARM); - FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, uri); - FARF(RUNTIME_RPC_HIGH, "mod_table_open for %s", uri); - VERIFY(AEE_SUCCESS == - (nErr = HAP_pls_add_lookup((uintptr_t)open_mod_table_ctor_imp, 0, - sizeof(*pomt), open_mod_table_ctor_imp, - (void *)&static_mod_table_obj, - open_mod_table_dtor_imp, (void **)&pomt))); - VERIFY(AEE_SUCCESS == (nErr = open_mod_table_open(pomt, uri, handle, dlerr, - dlerrorLen, pdlErr))); +int +mod_table_open(const char *uri, remote_handle *handle, char *dlerr, + int dlerrorLen, int *pdlErr) +{ + int nErr = AEE_SUCCESS; + struct open_mod_table *pomt = 0; + + VERIFYC(NULL != uri, AEE_EBADPARM); + FASTRPC_ATRACE_BEGIN_L("%s for %s", __func__, uri); + FARF(RUNTIME_RPC_HIGH, "mod_table_open for %s", uri); + VERIFY(AEE_SUCCESS + == (nErr = HAP_pls_add_lookup( + (uintptr_t)open_mod_table_ctor_imp, 0, sizeof(*pomt), + open_mod_table_ctor_imp, (void *)&static_mod_table_obj, + open_mod_table_dtor_imp, (void **)&pomt))); + VERIFY(AEE_SUCCESS + == (nErr = open_mod_table_open(pomt, uri, handle, dlerr, + dlerrorLen, pdlErr))); bail: - FARF(RUNTIME_RPC_HIGH, "mod_table_open for %s nErr: %x", uri, nErr); - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: modtable open failed\n", nErr); - } - if (uri) { - FASTRPC_ATRACE_END(); - } - return nErr; + FARF(RUNTIME_RPC_HIGH, "mod_table_open for %s nErr: %x", uri, nErr); + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: modtable open failed\n", nErr); + } + if(uri) { + FASTRPC_ATRACE_END(); + } + return nErr; } /** * invoke a handle in the mod table @@ -1027,18 +1154,21 @@ int mod_table_open(const char *uri, remote_handle *handle, char *dlerr, * sc, scalars, see remote.h for documentation. * pra, args, see remote.h for documentation. */ -int mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg *pra) { - int nErr = AEE_SUCCESS; - struct open_mod_table *pomt = 0; - VERIFY(AEE_SUCCESS == - (nErr = HAP_pls_add_lookup((uintptr_t)open_mod_table_ctor_imp, 0, - sizeof(*pomt), open_mod_table_ctor_imp, - (void *)&static_mod_table_obj, - open_mod_table_dtor_imp, (void **)&pomt))); - VERIFY(AEE_SUCCESS == - (nErr = open_mod_table_handle_invoke(pomt, handle, sc, pra))); +int +mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg *pra) +{ + int nErr = AEE_SUCCESS; + struct open_mod_table *pomt = 0; + VERIFY(AEE_SUCCESS + == (nErr = HAP_pls_add_lookup( + (uintptr_t)open_mod_table_ctor_imp, 0, sizeof(*pomt), + open_mod_table_ctor_imp, (void *)&static_mod_table_obj, + open_mod_table_dtor_imp, (void **)&pomt))); + VERIFY( + AEE_SUCCESS + == (nErr = open_mod_table_handle_invoke(pomt, handle, sc, pra))); bail: - return nErr; + return nErr; } /** @@ -1049,54 +1179,65 @@ int mod_table_invoke(remote_handle handle, uint32_t sc, remote_arg *pra) { * errStrLen, Length of error String (if an error occurs) * pdlErr, Error identifier */ -int mod_table_close(remote_handle handle, char *errStr, int errStrLen, - int *pdlErr) { - int nErr = AEE_SUCCESS; - struct open_mod_table *pomt = 0; - - FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x", __func__, (int)handle); - VERIFY(AEE_SUCCESS == - (nErr = HAP_pls_lookup((uintptr_t)open_mod_table_ctor_imp, 0, - (void **)&pomt))); - VERIFY(AEE_SUCCESS == (nErr = open_mod_table_close(pomt, handle, errStr, - errStrLen, pdlErr))); +int +mod_table_close(remote_handle handle, char *errStr, int errStrLen, int *pdlErr) +{ + int nErr = AEE_SUCCESS; + struct open_mod_table *pomt = 0; + + FASTRPC_ATRACE_BEGIN_L("%s called with handle 0x%x", __func__, + (int)handle); + VERIFY(AEE_SUCCESS + == (nErr = HAP_pls_lookup((uintptr_t)open_mod_table_ctor_imp, 0, + (void **)&pomt))); + VERIFY(AEE_SUCCESS + == (nErr = open_mod_table_close(pomt, handle, errStr, errStrLen, + pdlErr))); bail: - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: modtable close failed\n", nErr); - } - FASTRPC_ATRACE_END(); - return nErr; + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: modtable close failed\n", nErr); + } + FASTRPC_ATRACE_END(); + return nErr; } /** * internal use only */ -int mod_table_register_const_handle(remote_handle remote, const char *uri, - int (*pfn)(uint32_t sc, remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_const_handle(&static_mod_table_obj, remote, - 0, uri, pfn, 0); - } - return AEE_EUNKNOWN; +int +mod_table_register_const_handle(remote_handle remote, const char *uri, + int (*pfn)(uint32_t sc, remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_const_handle( + &static_mod_table_obj, remote, 0, uri, pfn, 0); + } + return AEE_EUNKNOWN; } -int mod_table_register_const_handle1(remote_handle remote, - remote_handle64 local, const char *uri, - int (*pfn)(remote_handle64, uint32_t sc, - remote_arg *pra)) { - if (0 == static_mod_table_ctor(&static_mod_table_obj)) { - return static_mod_table_register_const_handle(&static_mod_table_obj, remote, - local, uri, 0, pfn); - } - return AEE_EUNKNOWN; +int +mod_table_register_const_handle1(remote_handle remote, remote_handle64 local, + const char *uri, + int (*pfn)(remote_handle64, uint32_t sc, + remote_arg *pra)) +{ + if(0 == static_mod_table_ctor(&static_mod_table_obj)) { + return static_mod_table_register_const_handle( + &static_mod_table_obj, remote, local, uri, 0, pfn); + } + return AEE_EUNKNOWN; } // Constructor and destructor -static int mod_table_ctor(void) { - return static_mod_table_ctor(&static_mod_table_obj); +static int +mod_table_ctor(void) +{ + return static_mod_table_ctor(&static_mod_table_obj); } -static void mod_table_dtor(void) { - static_mod_table_dtor_imp(&static_mod_table_obj); - return; +static void +mod_table_dtor(void) +{ + static_mod_table_dtor_imp(&static_mod_table_obj); + return; } PL_DEFINE(mod_table, mod_table_ctor, mod_table_dtor); diff --git a/src/pl_list.c b/src/pl_list.c index 97a404a8..b251edf6 100644 --- a/src/pl_list.c +++ b/src/pl_list.c @@ -6,5 +6,5 @@ PL_DEP(gpls) PL_DEP(listener_android) -struct platform_lib *(*pl_list[])(void) = {PL_ENTRY(gpls), - PL_ENTRY(listener_android), 0}; +struct platform_lib *(*pl_list[])(void) + = { PL_ENTRY(gpls), PL_ENTRY(listener_android), 0 }; diff --git a/src/platform_libs.c b/src/platform_libs.c index 481a18f2..45edd9d5 100644 --- a/src/platform_libs.c +++ b/src/platform_libs.c @@ -12,64 +12,78 @@ extern struct platform_lib *(*pl_list[])(void); -int pl_lib_init(struct platform_lib *(*plf)(void)) { - int nErr = AEE_SUCCESS; - struct platform_lib *pl = plf(); - if (!atomic_fetch_add(&pl->uRefs, 1)) { - if (pl->init) { - FARF(RUNTIME_RPC_HIGH, "calling init for %s", pl->name); - nErr = pl->init(); - FARF(RUNTIME_RPC_HIGH, "init for %s returned %x", pl->name, nErr); - } - pl->nErr = nErr; - } - if (pl->nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: %s init failed", nErr, pl->name); - } - return pl->nErr; +int +pl_lib_init(struct platform_lib *(*plf)(void)) +{ + int nErr = AEE_SUCCESS; + struct platform_lib *pl = plf(); + if(!atomic_fetch_add(&pl->uRefs, 1)) { + if(pl->init) { + FARF(RUNTIME_RPC_HIGH, "calling init for %s", + pl->name); + nErr = pl->init(); + FARF(RUNTIME_RPC_HIGH, "init for %s returned %x", + pl->name, nErr); + } + pl->nErr = nErr; + } + if(pl->nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: %s init failed", nErr, pl->name); + } + return pl->nErr; } -void pl_lib_deinit(struct platform_lib *(*plf)(void)) { - struct platform_lib *pl = plf(); - if (1 == atomic_fetch_sub(&pl->uRefs, 1)) { - if (pl->deinit && pl->nErr == 0) { - pl->deinit(); - } - } - return; +void +pl_lib_deinit(struct platform_lib *(*plf)(void)) +{ + struct platform_lib *pl = plf(); + if(1 == atomic_fetch_sub(&pl->uRefs, 1)) { + if(pl->deinit && pl->nErr == 0) { + pl->deinit(); + } + } + return; } -static int pl_init_lst(struct platform_lib *(*lst[])(void)) { - int nErr = AEE_SUCCESS; - int ii; - for (ii = 0; lst[ii] != 0; ++ii) { - nErr = pl_lib_init(lst[ii]); - if (nErr != 0) { - break; - } - } - if (nErr != AEE_SUCCESS) { - VERIFY_EPRINTF("Error %x: plinit failed\n", nErr); - } - return nErr; +static int +pl_init_lst(struct platform_lib *(*lst[])(void)) +{ + int nErr = AEE_SUCCESS; + int ii; + for(ii = 0; lst[ii] != 0; ++ii) { + nErr = pl_lib_init(lst[ii]); + if(nErr != 0) { + break; + } + } + if(nErr != AEE_SUCCESS) { + VERIFY_EPRINTF("Error %x: plinit failed\n", nErr); + } + return nErr; } -int pl_init(void) { - int nErr = pl_init_lst(pl_list); - return nErr; +int +pl_init(void) +{ + int nErr = pl_init_lst(pl_list); + return nErr; } -static void pl_deinit_lst(struct platform_lib *(*lst[])(void)) { - int size, ii; - for (size = 0; lst[size] != 0; ++size) { - ; - } - for (ii = size - 1; ii >= 0; --ii) { - pl_lib_deinit(lst[ii]); - } - return; +static void +pl_deinit_lst(struct platform_lib *(*lst[])(void)) +{ + int size, ii; + for(size = 0; lst[size] != 0; ++size) { + ; + } + for(ii = size - 1; ii >= 0; --ii) { + pl_lib_deinit(lst[ii]); + } + return; } -void pl_deinit(void) { - pl_deinit_lst(pl_list); - return; +void +pl_deinit(void) +{ + pl_deinit_lst(pl_list); + return; } diff --git a/src/remotectl1_stub.c b/src/remotectl1_stub.c index 5528cc1e..be788d91 100644 --- a/src/remotectl1_stub.c +++ b/src/remotectl1_stub.c @@ -12,81 +12,88 @@ #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -94,175 +101,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _REMOTECTL1_SLIM_H #define _REMOTECTL1_SLIM_H @@ -276,131 +280,263 @@ struct Interface { #endif static const Type types[2]; -static const Type types[2] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}}; -static const Parameter parameters[8] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),3,0},{SLIM_IFPTR32(0x4,0x8),{{(const uintptr_t)0xdeadc0de,(const uintptr_t)0}}, 0,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0}}; -static const Parameter* const parameterArrays[14] = {(&(parameters[0])),(&(parameters[3])),(&(parameters[4])),(&(parameters[3])),(&(parameters[5])),(&(parameters[4])),(&(parameters[3])),(&(parameters[5])),(&(parameters[7])),(&(parameters[6])),(&(parameters[6])),(&(parameters[0])),(&(parameters[1])),(&(parameters[2]))}; -static const Method methods[6] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x1),0x4,0x0,2,2,(&(parameterArrays[11])),0x4,0x1},{REMOTE_SCALARS_MAKEX(0,0,0x0,0x0,0x1,0x0),0x0,0x0,1,1,(&(parameterArrays[13])),0x1,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x8,0x8,6,4,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[4])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[9])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x8,0x0,3,2,(&(parameterArrays[7])),0x4,0x0}}; -static const Method* const methodArrays[6] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3]),&(methods[4]),&(methods[5])}; -static const char strings[103] = "set_param\0grow_heap\0phyAddr\0dlerror\0params\0close1\0handle\0reqID\0nSize\0open1\0close\0nErr\0name\0open\0uri\0h\0"; -static const uint16_t methodStrings[20] = {69,86,50,28,81,43,50,28,81,0,57,36,10,20,63,91,96,100,75,100}; -static const uint16_t methodStringsArrays[6] = {15,18,0,5,12,9}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(remotectl1_slim) = {6,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Type types[2] + = { { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 } }; +static const Parameter parameters[8] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { SLIM_IFPTR32(0x4, 0x8), + { { (const uintptr_t)0xdeadc0de, (const uintptr_t)0 } }, + 0, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 } }; +static const Parameter *const parameterArrays[14] + = { (&(parameters[0])), (&(parameters[3])), (&(parameters[4])), + (&(parameters[3])), (&(parameters[5])), (&(parameters[4])), + (&(parameters[3])), (&(parameters[5])), (&(parameters[7])), + (&(parameters[6])), (&(parameters[6])), (&(parameters[0])), + (&(parameters[1])), (&(parameters[2])) }; +static const Method methods[6] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x1), 0x4, 0x0, 2, 2, + (&(parameterArrays[11])), 0x4, 0x1 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x0, 0x0, 0x1, 0x0), 0x0, 0x0, 1, 1, + (&(parameterArrays[13])), 0x1, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x8, 0x8, 6, 4, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x8, 0x4, 5, 3, + (&(parameterArrays[4])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[9])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x8, 0x0, 3, 2, + (&(parameterArrays[7])), 0x4, 0x0 } }; +static const Method *const methodArrays[6] + = { &(methods[0]), &(methods[1]), &(methods[2]), + &(methods[3]), &(methods[4]), &(methods[5]) }; +static const char strings[103] + = "set_param\0grow_" + "heap\0phyAddr\0dlerror\0params\0close1\0handle\0reqID\0nSize\0open1\0cl" + "ose\0nErr\0name\0open\0uri\0h\0"; +static const uint16_t methodStrings[20] + = { 69, 86, 50, 28, 81, 43, 50, 28, 81, 0, + 57, 36, 10, 20, 63, 91, 96, 100, 75, 100 }; +static const uint16_t methodStringsArrays[6] = { 15, 18, 0, 5, 12, 9 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(remotectl1_slim) + = { 6, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_REMOTECTL1_SLIM_H - #ifdef __cplusplus extern "C" { #endif -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_open)(const char* uri, remote_handle64* h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_open)(uri, h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_open)(const char *uri, + remote_handle64 *h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_open)(uri, h); } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE { - return __QAIC_REMOTE(remote_handle64_close)(h); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_close)(remote_handle64 h) __QAIC_STUB_ATTRIBUTE +{ + return __QAIC_REMOTE(remote_handle64_close)(h); } -static __inline int _stub_method(remote_handle64 _handle, uint32_t _mid, char* _in0[1], uint32_t _rout1[1], char* _rout2[1], uint32_t _rout2Len[1], uint32_t _rout3[1]) { - uint32_t _in0Len[1] = {0}; - int _numIn[1] = {0}; - remote_arg _pra[4] = {0}; - uint32_t _primIn[2]= {0}; - uint32_t _primROut[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 1; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _COPY(_primIn, 4, _rout2Len, 0, 4); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout2[0]; - _praROut[0].buf.nLen = (1 * _rout2Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); - _COPY(_rout1, 0, _primROut, 0, 4); - _COPY(_rout3, 0, _primROut, 4, 4); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method(remote_handle64 _handle, uint32_t _mid, char *_in0[1], + uint32_t _rout1[1], char *_rout2[1], uint32_t _rout2Len[1], + uint32_t _rout3[1]) +{ + uint32_t _in0Len[1] = { 0 }; + int _numIn[1] = { 0 }; + remote_arg _pra[4] = { 0 }; + uint32_t _primIn[2] = { 0 }; + uint32_t _primROut[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 1; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _COPY(_primIn, 4, _rout2Len, 0, 4); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout2[0]; + _praROut[0].buf.nLen = (1 * _rout2Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); + _COPY(_rout1, 0, _primROut, 0, 4); + _COPY(_rout3, 0, _primROut, 4, 4); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_open1)(remote_handle64 _handle, const char* name, int* handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - return _stub_method(_handle, _mid, (char**)&name, (uint32_t*)handle, (char**)&dlerror, (uint32_t*)&dlerrorLen, (uint32_t*)nErr); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_open1)(remote_handle64 _handle, const char *name, + int *handle, char *dlerror, int dlerrorLen, + int *nErr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + return _stub_method(_handle, _mid, (char **)&name, (uint32_t *)handle, + (char **)&dlerror, (uint32_t *)&dlerrorLen, + (uint32_t *)nErr); } -static __inline int _stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], char* _rout1[1], uint32_t _rout1Len[1], uint32_t _rout2[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[2]= {0}; - uint32_t _primROut[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _rout1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout1[0]; - _praROut[0].buf.nLen = (1 * _rout1Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout2, 0, _primROut, 0, 4); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_1(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + char *_rout1[1], uint32_t _rout1Len[1], uint32_t _rout2[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[2] = { 0 }; + uint32_t _primROut[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _rout1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout1[0]; + _praROut[0].buf.nLen = (1 * _rout1Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout2, 0, _primROut, 0, 4); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_close1)(remote_handle64 _handle, int handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - return _stub_method_1(_handle, _mid, (uint32_t*)&handle, (char**)&dlerror, (uint32_t*)&dlerrorLen, (uint32_t*)nErr); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_close1)(remote_handle64 _handle, int handle, + char *dlerror, int dlerrorLen, + int *nErr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + return _stub_method_1(_handle, _mid, (uint32_t *)&handle, + (char **)&dlerror, (uint32_t *)&dlerrorLen, + (uint32_t *)nErr); } -static __inline int _stub_method_2(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[2]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_2(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[2] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_grow_heap)(remote_handle64 _handle, uint32_t phyAddr, uint32_t nSize) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 4; - return _stub_method_2(_handle, _mid, (uint32_t*)&phyAddr, (uint32_t*)&nSize); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_grow_heap)(remote_handle64 _handle, uint32_t phyAddr, + uint32_t nSize) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 4; + return _stub_method_2(_handle, _mid, (uint32_t *)&phyAddr, + (uint32_t *)&nSize); } -static __inline int _stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], char* _in1[1], uint32_t _in1Len[1]) { - remote_arg _pra[2] = {0}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in1[0]; - _praIn[0].buf.nLen = (4 * _in1Len[0]); - _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); - _CATCH_FARF(_nErr) { - _QAIC_FARF(RUNTIME_ERROR, "ERROR 0x%x: handle=0x%"PRIx64", scalar=0x%x, method ID=%d: %s failed\n", _nErr , _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _mid, __func__); - } - return _nErr; +static __inline int +_stub_method_3(remote_handle64 _handle, uint32_t _mid, uint32_t _in0[1], + char *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in1[0]; + _praIn[0].buf.nLen = (4 * _in1Len[0]); + _TRY_FARF(_nErr, __QAIC_REMOTE(remote_handle64_invoke)( + _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); + _CATCH_FARF(_nErr) + { + _QAIC_FARF(RUNTIME_ERROR, + "ERROR 0x%x: handle=0x%" PRIx64 + ", scalar=0x%x, method ID=%d: %s failed\n", + _nErr, _handle, + REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _mid, + __func__); + } + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl1_set_param)(remote_handle64 _handle, int reqID, const uint32_t* params, int paramsLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 5; - return _stub_method_3(_handle, _mid, (uint32_t*)&reqID, (char**)¶ms, (uint32_t*)¶msLen); +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl1_set_param)(remote_handle64 _handle, int reqID, + const uint32_t *params, + int paramsLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 5; + return _stub_method_3(_handle, _mid, (uint32_t *)&reqID, + (char **)¶ms, (uint32_t *)¶msLen); } #ifdef __cplusplus } diff --git a/src/remotectl_stub.c b/src/remotectl_stub.c index 19a19df9..fbefc74d 100644 --- a/src/remotectl_stub.c +++ b/src/remotectl_stub.c @@ -25,7 +25,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_UNUSED #else -#define _ATTRIBUTE_UNUSED __attribute__ ((unused)) +#define _ATTRIBUTE_UNUSED __attribute__((unused)) #endif #endif // _ATTRIBUTE_UNUSED @@ -35,7 +35,7 @@ #ifdef _WIN32 #define _ATTRIBUTE_VISIBILITY #else -#define _ATTRIBUTE_VISIBILITY __attribute__ ((visibility("default"))) +#define _ATTRIBUTE_VISIBILITY __attribute__((visibility("default"))) #endif #endif // _ATTRIBUTE_VISIBILITY @@ -93,159 +93,173 @@ #endif // __QAIC_SKEL_ATTRIBUTE #ifdef __QAIC_DEBUG__ - #ifndef __QAIC_DBG_PRINTF__ - #include - #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0) - #endif +#ifndef __QAIC_DBG_PRINTF__ +#include +#define __QAIC_DBG_PRINTF__(ee) \ + do { \ + printf ee; \ + } while(0) +#endif #else - #define __QAIC_DBG_PRINTF__( ee ) (void)0 +#define __QAIC_DBG_PRINTF__(ee) (void)0 #endif +#define _OFFSET(src, sof) ((void *)(((char *)(src)) + (sof))) -#define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof))) +#define _COPY(dst, dof, src, sof, sz) \ + do { \ + struct __copy { \ + char ar[sz]; \ + }; \ + *(struct __copy *)_OFFSET(dst, dof) \ + = *(struct __copy *)_OFFSET(src, sof); \ + } while(0) -#define _COPY(dst, dof, src, sof, sz) \ - do {\ - struct __copy { \ - char ar[sz]; \ - };\ - *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\ - } while (0) - -#define _COPYIF(dst, dof, src, sof, sz) \ - do {\ - if(_OFFSET(dst, dof) != _OFFSET(src, sof)) {\ - _COPY(dst, dof, src, sof, sz); \ - } \ - } while (0) +#define _COPYIF(dst, dof, src, sof, sz) \ + do { \ + if(_OFFSET(dst, dof) != _OFFSET(src, sof)) { \ + _COPY(dst, dof, src, sof, sz); \ + } \ + } while(0) _ATTRIBUTE_UNUSED -static __inline void _qaic_memmove(void* dst, void* src, int size) { - int i = 0; - for(i = 0; i < size; ++i) { - ((char*)dst)[i] = ((char*)src)[i]; - } +static __inline void +_qaic_memmove(void *dst, void *src, int size) +{ + int i = 0; + for(i = 0; i < size; ++i) { + ((char *)dst)[i] = ((char *)src)[i]; + } } -#define _MEMMOVEIF(dst, src, sz) \ - do {\ - if(dst != src) {\ - _qaic_memmove(dst, src, sz);\ - } \ - } while (0) - +#define _MEMMOVEIF(dst, src, sz) \ + do { \ + if(dst != src) { \ + _qaic_memmove(dst, src, sz); \ + } \ + } while(0) -#define _ASSIGN(dst, src, sof) \ - do {\ - dst = OFFSET(src, sof); \ - } while (0) +#define _ASSIGN(dst, src, sof) \ + do { \ + dst = OFFSET(src, sof); \ + } while(0) #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str)) #include "AEEStdErr.h" -#define _TRY(ee, func) \ - do { \ - if (AEE_SUCCESS != ((ee) = func)) {\ - __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", __LINE__, (int)(ee),#func));\ - goto ee##bail;\ - } \ - } while (0) +#define _TRY(ee, func) \ + do { \ + if(AEE_SUCCESS != ((ee) = func)) { \ + __QAIC_DBG_PRINTF__((__FILE__ ":%d:error:%d:%s\n", \ + __LINE__, (int)(ee), #func)); \ + goto ee##bail; \ + } \ + } while(0) -#define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS) +#define _CATCH(exception) exception##bail : if(exception != AEE_SUCCESS) #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS) #ifdef __QAIC_DEBUG__ -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, __FILE_LINE__, size, alignment, \ + (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #else -#define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void**)&pv));\ - _ASSERT(nErr,pv || !(size)) +#define _ALLOCATE(nErr, pal, size, alignment, pv) \ + _TRY(nErr, _allocator_alloc(pal, 0, size, alignment, (void **)&pv)); \ + _ASSERT(nErr, pv || !(size)) #endif - #endif // _QAIC_ENV_H #include #ifndef _ALLOCATOR_H #define _ALLOCATOR_H -#include #include +#include typedef struct _heap _heap; struct _heap { - _heap* pPrev; - const char* loc; - uint64_t buf; + _heap *pPrev; + const char *loc; + uint64_t buf; }; typedef struct _allocator { - _heap* pheap; - uint8_t* stack; - uint8_t* stackEnd; - int nSize; + _heap *pheap; + uint8_t *stack; + uint8_t *stackEnd; + int nSize; } _allocator; _ATTRIBUTE_UNUSED -static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) { - _heap* pn = 0; - pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); - if(pn != 0) { - pn->pPrev = *ppa; - pn->loc = loc; - *ppa = pn; - *ppbuf = (void*)&(pn->buf); - return 0; - } else { - return -1; - } +static __inline int +_heap_alloc(_heap **ppa, const char *loc, int size, void **ppbuf) +{ + _heap *pn = 0; + pn = malloc((size_t)size + sizeof(_heap) - sizeof(uint64_t)); + if(pn != 0) { + pn->pPrev = *ppa; + pn->loc = loc; + *ppa = pn; + *ppbuf = (void *)&(pn->buf); + return 0; + } else { + return -1; + } } -#define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1)) +#define _ALIGN_SIZE(x, y) (((x) + (y - 1)) & ~(y - 1)) _ATTRIBUTE_UNUSED -static __inline int _allocator_alloc(_allocator* me, - const char* loc, - int size, - unsigned int al, - void** ppbuf) { - if(size < 0) { - return -1; - } else if (size == 0) { - *ppbuf = 0; - return 0; - } - if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) < (uintptr_t)me->stack + (size_t)me->nSize) { - *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); - me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size; - return 0; - } else { - return _heap_alloc(&me->pheap, loc, size, ppbuf); - } +static __inline int +_allocator_alloc(_allocator *me, const char *loc, int size, unsigned int al, + void **ppbuf) +{ + if(size < 0) { + return -1; + } else if(size == 0) { + *ppbuf = 0; + return 0; + } + if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + (size_t)size) + < (uintptr_t)me->stack + (size_t)me->nSize) { + *ppbuf = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al); + me->stackEnd + = (uint8_t *)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + + size; + return 0; + } else { + return _heap_alloc(&me->pheap, loc, size, ppbuf); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_deinit(_allocator* me) { - _heap* pa = me->pheap; - while(pa != 0) { - _heap* pn = pa; - const char* loc = pn->loc; - (void)loc; - pa = pn->pPrev; - free(pn); - } +static __inline void +_allocator_deinit(_allocator *me) +{ + _heap *pa = me->pheap; + while(pa != 0) { + _heap *pn = pa; + const char *loc = pn->loc; + (void)loc; + pa = pn->pPrev; + free(pn); + } } _ATTRIBUTE_UNUSED -static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSize) { - me->stack = stack; - me->stackEnd = stack + stackSize; - me->nSize = stackSize; - me->pheap = 0; +static __inline void +_allocator_init(_allocator *me, uint8_t *stack, int stackSize) +{ + me->stack = stack; + me->stackEnd = stack + stackSize; + me->nSize = stackSize; + me->pheap = 0; } - #endif // _ALLOCATOR_H #ifndef SLIM_H @@ -253,175 +267,172 @@ static __inline void _allocator_init(_allocator* me, uint8_t* stack, int stackSi #include -//a C data structure for the idl types that can be used to implement -//static and dynamic language bindings fairly efficiently. +// a C data structure for the idl types that can be used to implement +// static and dynamic language bindings fairly efficiently. // -//the goal is to have a minimal ROM and RAM footprint and without -//doing too many allocations. A good way to package these things seemed -//like the module boundary, so all the idls within one module can share -//all the type references. - - -#define PARAMETER_IN 0x0 -#define PARAMETER_OUT 0x1 -#define PARAMETER_INOUT 0x2 -#define PARAMETER_ROUT 0x3 -#define PARAMETER_INROUT 0x4 - -//the types that we get from idl -#define TYPE_OBJECT 0x0 -#define TYPE_INTERFACE 0x1 -#define TYPE_PRIMITIVE 0x2 -#define TYPE_ENUM 0x3 -#define TYPE_STRING 0x4 -#define TYPE_WSTRING 0x5 -#define TYPE_STRUCTURE 0x6 -#define TYPE_UNION 0x7 -#define TYPE_ARRAY 0x8 -#define TYPE_SEQUENCE 0x9 - -//these require the pack/unpack to recurse -//so it's a hint to those languages that can optimize in cases where -//recursion isn't necessary. -#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) -#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) -#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) -#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) - +// the goal is to have a minimal ROM and RAM footprint and without +// doing too many allocations. A good way to package these things seemed +// like the module boundary, so all the idls within one module can share +// all the type references. + +#define PARAMETER_IN 0x0 +#define PARAMETER_OUT 0x1 +#define PARAMETER_INOUT 0x2 +#define PARAMETER_ROUT 0x3 +#define PARAMETER_INROUT 0x4 + +// the types that we get from idl +#define TYPE_OBJECT 0x0 +#define TYPE_INTERFACE 0x1 +#define TYPE_PRIMITIVE 0x2 +#define TYPE_ENUM 0x3 +#define TYPE_STRING 0x4 +#define TYPE_WSTRING 0x5 +#define TYPE_STRUCTURE 0x6 +#define TYPE_UNION 0x7 +#define TYPE_ARRAY 0x8 +#define TYPE_SEQUENCE 0x9 + +// these require the pack/unpack to recurse +// so it's a hint to those languages that can optimize in cases where +// recursion isn't necessary. +#define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE) +#define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION) +#define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY) +#define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE) typedef struct Type Type; -#define INHERIT_TYPE\ - int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\ - union {\ - struct {\ - const uintptr_t p1;\ - const uintptr_t p2;\ - } _cast;\ - struct {\ - uint32_t iid;\ - uint32_t bNotNil;\ - } object;\ - struct {\ - const Type *arrayType;\ - int32_t nItems;\ - } array;\ - struct {\ - const Type *seqType;\ - int32_t nMaxLen;\ - } seqSimple; \ - struct {\ - uint32_t bFloating;\ - uint32_t bSigned;\ - } prim; \ - const SequenceType* seqComplex;\ - const UnionType *unionType;\ - const StructType *structType;\ - int32_t stringMaxLen;\ - uint8_t bInterfaceNotNil;\ - } param;\ - uint8_t type;\ - uint8_t nativeAlignment\ +#define INHERIT_TYPE \ + int32_t nativeSize; /*in the simple case its the same as wire size \ + and alignment*/ \ + union { \ + struct { \ + const uintptr_t p1; \ + const uintptr_t p2; \ + } _cast; \ + struct { \ + uint32_t iid; \ + uint32_t bNotNil; \ + } object; \ + struct { \ + const Type *arrayType; \ + int32_t nItems; \ + } array; \ + struct { \ + const Type *seqType; \ + int32_t nMaxLen; \ + } seqSimple; \ + struct { \ + uint32_t bFloating; \ + uint32_t bSigned; \ + } prim; \ + const SequenceType *seqComplex; \ + const UnionType *unionType; \ + const StructType *structType; \ + int32_t stringMaxLen; \ + uint8_t bInterfaceNotNil; \ + } param; \ + uint8_t type; \ + uint8_t nativeAlignment typedef struct UnionType UnionType; typedef struct StructType StructType; typedef struct SequenceType SequenceType; struct Type { - INHERIT_TYPE; + INHERIT_TYPE; }; struct SequenceType { - const Type * seqType; - uint32_t nMaxLen; - uint32_t inSize; - uint32_t routSizePrimIn; - uint32_t routSizePrimROut; + const Type *seqType; + uint32_t nMaxLen; + uint32_t inSize; + uint32_t routSizePrimIn; + uint32_t routSizePrimROut; }; -//unsigned char offset from the start of the case values for -//this unions case value array. it MUST be aligned -//at the alignment requrements for the descriptor +// unsigned char offset from the start of the case values for +// this unions case value array. it MUST be aligned +// at the alignment requrements for the descriptor // -//if negative it means that the unions cases are -//simple enumerators, so the value read from the descriptor -//can be used directly to find the correct case +// if negative it means that the unions cases are +// simple enumerators, so the value read from the descriptor +// can be used directly to find the correct case typedef union CaseValuePtr CaseValuePtr; union CaseValuePtr { - const uint8_t* value8s; - const uint16_t* value16s; - const uint32_t* value32s; - const uint64_t* value64s; + const uint8_t *value8s; + const uint16_t *value16s; + const uint32_t *value32s; + const uint64_t *value64s; }; -//these are only used in complex cases -//so I pulled them out of the type definition as references to make -//the type smaller +// these are only used in complex cases +// so I pulled them out of the type definition as references to make +// the type smaller struct UnionType { - const Type *descriptor; - uint32_t nCases; - const CaseValuePtr caseValues; - const Type * const *cases; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; - uint8_t inCaseAlignment; - uint8_t routCaseAlignmentPrimIn; - uint8_t routCaseAlignmentPrimROut; - uint8_t nativeCaseAlignment; - uint8_t bDefaultCase; + const Type *descriptor; + uint32_t nCases; + const CaseValuePtr caseValues; + const Type *const *cases; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; + uint8_t inCaseAlignment; + uint8_t routCaseAlignmentPrimIn; + uint8_t routCaseAlignmentPrimROut; + uint8_t nativeCaseAlignment; + uint8_t bDefaultCase; }; struct StructType { - uint32_t nMembers; - const Type * const *members; - int32_t inSize; - int32_t routSizePrimIn; - int32_t routSizePrimROut; - uint8_t inAlignment; - uint8_t routAlignmentPrimIn; - uint8_t routAlignmentPrimROut; + uint32_t nMembers; + const Type *const *members; + int32_t inSize; + int32_t routSizePrimIn; + int32_t routSizePrimROut; + uint8_t inAlignment; + uint8_t routAlignmentPrimIn; + uint8_t routAlignmentPrimROut; }; typedef struct Parameter Parameter; struct Parameter { - INHERIT_TYPE; - uint8_t mode; - uint8_t bNotNil; + INHERIT_TYPE; + uint8_t mode; + uint8_t bNotNil; }; -#define SLIM_IFPTR32(is32,is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) +#define SLIM_IFPTR32(is32, is64) (sizeof(uintptr_t) == 4 ? (is32) : (is64)) #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff) typedef struct Method Method; struct Method { - uint32_t uScalars; //no method index - int32_t primInSize; - int32_t primROutSize; - int maxArgs; - int numParams; - const Parameter * const *params; - uint8_t primInAlignment; - uint8_t primROutAlignment; + uint32_t uScalars; // no method index + int32_t primInSize; + int32_t primROutSize; + int maxArgs; + int numParams; + const Parameter *const *params; + uint8_t primInAlignment; + uint8_t primROutAlignment; }; typedef struct Interface Interface; struct Interface { - int nMethods; - const Method * const *methodArray; - int nIIds; - const uint32_t *iids; - const uint16_t* methodStringArray; - const uint16_t* methodStrings; - const char* strings; + int nMethods; + const Method *const *methodArray; + int nIIds; + const uint32_t *iids; + const uint16_t *methodStringArray; + const uint16_t *methodStrings; + const char *strings; }; - -#endif //SLIM_H - +#endif // SLIM_H #ifndef _REMOTECTL_SLIM_H #define _REMOTECTL_SLIM_H @@ -435,66 +446,129 @@ struct Interface { #endif static const Type types[2]; -static const Type types[2] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x1},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4}}; -static const Parameter parameters[6] = {{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)0x0,0}}, 4,SLIM_IFPTR32(0x4,0x8),0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0},{SLIM_IFPTR32(0x8,0x10),{{(const uintptr_t)&(types[1]),(const uintptr_t)0x0}}, 9,SLIM_IFPTR32(0x4,0x8),0,0}}; -static const Parameter* const parameterArrays[11] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[2])),(&(parameters[1])),(&(parameters[3])),(&(parameters[2])),(&(parameters[1])),(&(parameters[3])),(&(parameters[5])),(&(parameters[4])),(&(parameters[4]))}; -static const Method methods[4] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x8,0x8,6,4,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[4])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x0,0x0,0x0),0x8,0x0,2,2,(&(parameterArrays[9])),0x4,0x0},{REMOTE_SCALARS_MAKEX(0,0,0x2,0x0,0x0,0x0),0x8,0x0,3,2,(&(parameterArrays[7])),0x4,0x0}}; -static const Method* const methodArrays[4] = {&(methods[0]),&(methods[1]),&(methods[2]),&(methods[3])}; -static const char strings[84] = "set_param\0grow_heap\0phyAddr\0dlerror\0params\0handle\0reqID\0nSize\0close\0nErr\0name\0open\0"; -static const uint16_t methodStrings[15] = {78,73,43,28,68,62,43,28,68,0,50,36,10,20,56}; -static const uint16_t methodStringsArrays[4] = {0,5,12,9}; -__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(remotectl_slim) = {4,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings}; +static const Type types[2] + = { { 0x1, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x1 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4 } }; +static const Parameter parameters[6] + = { { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)0x0, 0 } }, + 4, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 3, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[0]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 3, + 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { 0x4, { { (const uintptr_t)0, (const uintptr_t)1 } }, 2, 0x4, 0, 0 }, + { SLIM_IFPTR32(0x8, 0x10), + { { (const uintptr_t)&(types[1]), (const uintptr_t)0x0 } }, + 9, + SLIM_IFPTR32(0x4, 0x8), + 0, + 0 } }; +static const Parameter *const parameterArrays[11] + = { (&(parameters[0])), (&(parameters[1])), (&(parameters[2])), + (&(parameters[1])), (&(parameters[3])), (&(parameters[2])), + (&(parameters[1])), (&(parameters[3])), (&(parameters[5])), + (&(parameters[4])), (&(parameters[4])) }; +static const Method methods[4] + = { { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x2, 0x0, 0x0), 0x8, 0x8, 6, 4, + (&(parameterArrays[0])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x2, 0x0, 0x0), 0x8, 0x4, 5, 3, + (&(parameterArrays[4])), 0x4, 0x4 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x1, 0x0, 0x0, 0x0), 0x8, 0x0, 2, 2, + (&(parameterArrays[9])), 0x4, 0x0 }, + { REMOTE_SCALARS_MAKEX(0, 0, 0x2, 0x0, 0x0, 0x0), 0x8, 0x0, 3, 2, + (&(parameterArrays[7])), 0x4, 0x0 } }; +static const Method *const methodArrays[4] + = { &(methods[0]), &(methods[1]), &(methods[2]), &(methods[3]) }; +static const char strings[84] = "set_param\0grow_" + "heap\0phyAddr\0dlerror\0params\0handle\0reqID" + "\0nSize\0close\0nErr\0name\0open\0"; +static const uint16_t methodStrings[15] + = { 78, 73, 43, 28, 68, 62, 43, 28, 68, 0, 50, 36, 10, 20, 56 }; +static const uint16_t methodStringsArrays[4] = { 0, 5, 12, 9 }; +__QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(remotectl_slim) + = { 4, &(methodArrays[0]), 0, + 0, &(methodStringsArrays[0]), methodStrings, + strings }; #endif //_REMOTECTL_SLIM_H #ifdef __cplusplus extern "C" { #endif #ifndef _const_remotectl_handle -#define _const_remotectl_handle ((remote_handle)-1) +#define _const_remotectl_handle ((remote_handle) - 1) #endif //_const_remotectl_handle -static void _remotectl_pls_dtor(void* data) { - remote_handle* ph = (remote_handle*)data; - if(_const_remotectl_handle != *ph) { - (void)__QAIC_REMOTE(remote_handle_close)(*ph); - *ph = _const_remotectl_handle; - } +static void +_remotectl_pls_dtor(void *data) +{ + remote_handle *ph = (remote_handle *)data; + if(_const_remotectl_handle != *ph) { + (void)__QAIC_REMOTE(remote_handle_close)(*ph); + *ph = _const_remotectl_handle; + } } -static int _remotectl_pls_ctor(void* ctx, void* data) { - remote_handle* ph = (remote_handle*)data; - *ph = _const_remotectl_handle; - if(*ph == (remote_handle)-1) { - return __QAIC_REMOTE(remote_handle_open)((const char*)ctx, ph); - } - return 0; +static int +_remotectl_pls_ctor(void *ctx, void *data) +{ + remote_handle *ph = (remote_handle *)data; + *ph = _const_remotectl_handle; + if(*ph == (remote_handle)-1) { + return __QAIC_REMOTE(remote_handle_open)((const char *)ctx, + ph); + } + return 0; } #if (defined __qdsp6__) || (defined __hexagon__) -#pragma weak adsp_pls_add_lookup -extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); -#pragma weak HAP_pls_add_lookup -extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, int (*ctor)(void* ctx, void* data), void* ctx, void (*dtor)(void* ctx), void** ppo); - -__QAIC_STUB_EXPORT remote_handle _remotectl_handle(void) { - remote_handle* ph = 0; - if(adsp_pls_add_lookup) { - if(0 == adsp_pls_add_lookup((uint32_t)_remotectl_handle, 0, sizeof(*ph), _remotectl_pls_ctor, "remotectl", _remotectl_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } else if(HAP_pls_add_lookup) { - if(0 == HAP_pls_add_lookup((uint32_t)_remotectl_handle, 0, sizeof(*ph), _remotectl_pls_ctor, "remotectl", _remotectl_pls_dtor, (void**)&ph)) { - return *ph; - } - return (remote_handle)-1; - } - return(remote_handle)-1; +#pragma weak adsp_pls_add_lookup +extern int adsp_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); +#pragma weak HAP_pls_add_lookup +extern int HAP_pls_add_lookup(uint32_t type, uint32_t key, int size, + int (*ctor)(void *ctx, void *data), void *ctx, + void (*dtor)(void *ctx), void **ppo); + +__QAIC_STUB_EXPORT remote_handle +_remotectl_handle(void) +{ + remote_handle *ph = 0; + if(adsp_pls_add_lookup) { + if(0 + == adsp_pls_add_lookup((uint32_t)_remotectl_handle, 0, + sizeof(*ph), _remotectl_pls_ctor, + "remotectl", _remotectl_pls_dtor, + (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } else if(HAP_pls_add_lookup) { + if(0 + == HAP_pls_add_lookup((uint32_t)_remotectl_handle, 0, + sizeof(*ph), _remotectl_pls_ctor, + "remotectl", _remotectl_pls_dtor, + (void **)&ph)) { + return *ph; + } + return (remote_handle)-1; + } + return (remote_handle)-1; } #else //__qdsp6__ || __hexagon__ -uint32_t _remotectl_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare); +uint32_t _remotectl_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, + uint32_t uCompare); #ifdef _WIN32 #ifdef _USRDLL @@ -502,31 +576,43 @@ uint32_t _remotectl_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32 #else #include "ntddk.h" #endif //_USRDLL -uint32_t _remotectl_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return (uint32_t)InterlockedCompareExchange((volatile LONG*)puDest, (LONG)uExchange, (LONG)uCompare); +uint32_t +_remotectl_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return (uint32_t)InterlockedCompareExchange( + (volatile LONG *)puDest, (LONG)uExchange, (LONG)uCompare); } #elif __GNUC__ -uint32_t _remotectl_atomic_CompareAndExchange(uint32_t * volatile puDest, uint32_t uExchange, uint32_t uCompare) { - return __sync_val_compare_and_swap(puDest, uCompare, uExchange); +uint32_t +_remotectl_atomic_CompareAndExchange(uint32_t *volatile puDest, + uint32_t uExchange, uint32_t uCompare) +{ + return __sync_val_compare_and_swap(puDest, uCompare, uExchange); } #endif //_WIN32 - -__QAIC_STUB_EXPORT remote_handle _remotectl_handle(void) { - static remote_handle handle = _const_remotectl_handle; - if((remote_handle)-1 != handle) { - return handle; - } else { - remote_handle tmp; - int nErr = _remotectl_pls_ctor("remotectl", (void*)&tmp); - if(nErr) { - return (remote_handle)-1; - } - if(((remote_handle)-1 != handle) || ((remote_handle)-1 != (remote_handle)_remotectl_atomic_CompareAndExchange((uint32_t*)&handle, (uint32_t)tmp, (uint32_t)-1))) { - _remotectl_pls_dtor(&tmp); - } - return handle; - } +__QAIC_STUB_EXPORT remote_handle +_remotectl_handle(void) +{ + static remote_handle handle = _const_remotectl_handle; + if((remote_handle)-1 != handle) { + return handle; + } else { + remote_handle tmp; + int nErr = _remotectl_pls_ctor("remotectl", (void *)&tmp); + if(nErr) { + return (remote_handle)-1; + } + if(((remote_handle)-1 != handle) + || ((remote_handle)-1 + != (remote_handle)_remotectl_atomic_CompareAndExchange( + (uint32_t *)&handle, (uint32_t)tmp, + (uint32_t)-1))) { + _remotectl_pls_dtor(&tmp); + } + return handle; + } } #endif //__qdsp6__ @@ -535,138 +621,165 @@ __QAIC_STUB_EXPORT remote_handle _remotectl_handle(void) { } #endif - #ifdef __cplusplus extern "C" { #endif -static __inline int _stub_method(remote_handle _handle, uint32_t _mid, char* _in0[1], uint32_t _rout1[1], char* _rout2[1], uint32_t _rout2Len[1], uint32_t _rout3[1]) { - uint32_t _in0Len[1] = {0}; - int _numIn[1] = {0}; - remote_arg _pra[4] = {0}; - uint32_t _primIn[2]= {0}; - uint32_t _primROut[2]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 1; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); - _COPY(_primIn, 0, _in0Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in0[0]; - _praIn[0].buf.nLen = (1 * _in0Len[0]); - _COPY(_primIn, 4, _rout2Len, 0, 4); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout2[0]; - _praROut[0].buf.nLen = (1 * _rout2Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); - _COPY(_rout1, 0, _primROut, 0, 4); - _COPY(_rout3, 0, _primROut, 4, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method(remote_handle _handle, uint32_t _mid, char *_in0[1], + uint32_t _rout1[1], char *_rout2[1], uint32_t _rout2Len[1], + uint32_t _rout3[1]) +{ + uint32_t _in0Len[1] = { 0 }; + int _numIn[1] = { 0 }; + remote_arg _pra[4] = { 0 }; + uint32_t _primIn[2] = { 0 }; + uint32_t _primROut[2] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 1; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _in0Len[0] = (uint32_t)(1 + strlen(_in0[0])); + _COPY(_primIn, 0, _in0Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in0[0]; + _praIn[0].buf.nLen = (1 * _in0Len[0]); + _COPY(_primIn, 4, _rout2Len, 0, 4); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout2[0]; + _praROut[0].buf.nLen = (1 * _rout2Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 2, 0, 0), _pra)); + _COPY(_rout1, 0, _primROut, 0, 4); + _COPY(_rout3, 0, _primROut, 4, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl_open)(const char* name, int* handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 0; - remote_handle _handle = _remotectl_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method(_handle, _mid, (char**)&name, (uint32_t*)handle, (char**)&dlerror, (uint32_t*)&dlerrorLen, (uint32_t*)nErr); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl_open)(const char *name, int *handle, char *dlerror, + int dlerrorLen, int *nErr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 0; + remote_handle _handle = _remotectl_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method(_handle, _mid, (char **)&name, + (uint32_t *)handle, (char **)&dlerror, + (uint32_t *)&dlerrorLen, (uint32_t *)nErr); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_1(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], char* _rout1[1], uint32_t _rout1Len[1], uint32_t _rout2[1]) { - int _numIn[1] = {0}; - remote_arg _pra[3] = {0}; - uint32_t _primIn[2]= {0}; - uint32_t _primROut[1]= {0}; - remote_arg* _praIn = 0; - remote_arg* _praROut = 0; - int _nErr = 0; - _numIn[0] = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _pra[(_numIn[0] + 1)].buf.pv = (void*)_primROut; - _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _rout1Len, 0, 4); - _praIn = (_pra + 1); - _praROut = (_praIn + _numIn[0] + 1); - _praROut[0].buf.pv = _rout1[0]; - _praROut[0].buf.nLen = (1 * _rout1Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); - _COPY(_rout2, 0, _primROut, 0, 4); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_1(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + char *_rout1[1], uint32_t _rout1Len[1], uint32_t _rout2[1]) +{ + int _numIn[1] = { 0 }; + remote_arg _pra[3] = { 0 }; + uint32_t _primIn[2] = { 0 }; + uint32_t _primROut[1] = { 0 }; + remote_arg *_praIn = 0; + remote_arg *_praROut = 0; + int _nErr = 0; + _numIn[0] = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _pra[(_numIn[0] + 1)].buf.pv = (void *)_primROut; + _pra[(_numIn[0] + 1)].buf.nLen = sizeof(_primROut); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _rout1Len, 0, 4); + _praIn = (_pra + 1); + _praROut = (_praIn + _numIn[0] + 1); + _praROut[0].buf.pv = _rout1[0]; + _praROut[0].buf.nLen = (1 * _rout1Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 2, 0, 0), _pra)); + _COPY(_rout2, 0, _primROut, 0, 4); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl_close)(int handle, char* dlerror, int dlerrorLen, int* nErr) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 1; - remote_handle _handle = _remotectl_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_1(_handle, _mid, (uint32_t*)&handle, (char**)&dlerror, (uint32_t*)&dlerrorLen, (uint32_t*)nErr); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl_close)(int handle, char *dlerror, int dlerrorLen, + int *nErr) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 1; + remote_handle _handle = _remotectl_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_1( + _handle, _mid, (uint32_t *)&handle, (char **)&dlerror, + (uint32_t *)&dlerrorLen, (uint32_t *)nErr); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_2(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], uint32_t _in1[1]) { - remote_arg _pra[1] = {0}; - uint32_t _primIn[2]= {0}; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1, 0, 4); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_2(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + uint32_t _in1[1]) +{ + remote_arg _pra[1] = { 0 }; + uint32_t _primIn[2] = { 0 }; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1, 0, 4); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 1, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl_grow_heap)(uint32_t phyAddr, uint32_t nSize) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 2; - remote_handle _handle = _remotectl_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_2(_handle, _mid, (uint32_t*)&phyAddr, (uint32_t*)&nSize); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl_grow_heap)(uint32_t phyAddr, + uint32_t nSize) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 2; + remote_handle _handle = _remotectl_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_2(_handle, _mid, (uint32_t *)&phyAddr, + (uint32_t *)&nSize); + } else { + return AEE_EINVHANDLE; + } } -static __inline int _stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], char* _in1[1], uint32_t _in1Len[1]) { - remote_arg _pra[2] = {0}; - uint32_t _primIn[2]= {0}; - remote_arg* _praIn = 0; - int _nErr = 0; - _pra[0].buf.pv = (void*)_primIn; - _pra[0].buf.nLen = sizeof(_primIn); - _COPY(_primIn, 0, _in0, 0, 4); - _COPY(_primIn, 4, _in1Len, 0, 4); - _praIn = (_pra + 1); - _praIn[0].buf.pv = (void*) _in1[0]; - _praIn[0].buf.nLen = (4 * _in1Len[0]); - _TRY(_nErr, __QAIC_REMOTE(remote_handle_invoke)(_handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); - _CATCH(_nErr) {} - return _nErr; +static __inline int +_stub_method_3(remote_handle _handle, uint32_t _mid, uint32_t _in0[1], + char *_in1[1], uint32_t _in1Len[1]) +{ + remote_arg _pra[2] = { 0 }; + uint32_t _primIn[2] = { 0 }; + remote_arg *_praIn = 0; + int _nErr = 0; + _pra[0].buf.pv = (void *)_primIn; + _pra[0].buf.nLen = sizeof(_primIn); + _COPY(_primIn, 0, _in0, 0, 4); + _COPY(_primIn, 4, _in1Len, 0, 4); + _praIn = (_pra + 1); + _praIn[0].buf.pv = (void *)_in1[0]; + _praIn[0].buf.nLen = (4 * _in1Len[0]); + _TRY(_nErr, + __QAIC_REMOTE(remote_handle_invoke)( + _handle, REMOTE_SCALARS_MAKEX(0, _mid, 2, 0, 0, 0), _pra)); + _CATCH(_nErr) {} + return _nErr; } -__QAIC_STUB_EXPORT int __QAIC_STUB(remotectl_set_param)(int reqID, const uint32_t* params, int paramsLen) __QAIC_STUB_ATTRIBUTE { - uint32_t _mid = 3; - remote_handle _handle = _remotectl_handle(); - if (_handle != (remote_handle)-1) - { - return _stub_method_3(_handle, _mid, (uint32_t*)&reqID, (char**)¶ms, (uint32_t*)¶msLen); - } - else - { - return AEE_EINVHANDLE; - } +__QAIC_STUB_EXPORT int +__QAIC_STUB(remotectl_set_param)(int reqID, const uint32_t *params, + int paramsLen) __QAIC_STUB_ATTRIBUTE +{ + uint32_t _mid = 3; + remote_handle _handle = _remotectl_handle(); + if(_handle != (remote_handle)-1) { + return _stub_method_3(_handle, _mid, (uint32_t *)&reqID, + (char **)¶ms, + (uint32_t *)¶msLen); + } else { + return AEE_EINVHANDLE; + } } #ifdef __cplusplus } diff --git a/src/rpcmem_linux.c b/src/rpcmem_linux.c index a0814b97..3624f90e 100644 --- a/src/rpcmem_linux.c +++ b/src/rpcmem_linux.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -38,7 +39,6 @@ #include #include #include -#include #include #include "AEEQList.h" @@ -48,9 +48,9 @@ #include "apps_std.h" #include "fastrpc_common.h" #include "fastrpc_ioctl.h" +#include "fastrpc_mem.h" #include "rpcmem.h" #include "verify.h" -#include "fastrpc_mem.h" #define PAGE_SIZE 4096 @@ -59,193 +59,237 @@ #endif struct dma_heap_allocation_data { - __u64 len; - __u32 fd; - __u32 fd_flags; - __u64 heap_flags; + __u64 len; + __u32 fd; + __u32 fd_flags; + __u64 heap_flags; }; #define DMA_HEAP_IOC_MAGIC 'H' -#define DMA_HEAP_IOCTL_ALLOC \ - _IOWR(DMA_HEAP_IOC_MAGIC, 0x0, struct dma_heap_allocation_data) +#define DMA_HEAP_IOCTL_ALLOC \ + _IOWR(DMA_HEAP_IOC_MAGIC, 0x0, struct dma_heap_allocation_data) #define DMA_HEAP_NAME "/dev/dma_heap/system" static int dmafd = -1; static int rpcfd = -1; static QList rpclst; static pthread_mutex_t rpcmt; struct rpc_info { - QNode qn; - void *buf; - void *aligned_buf; - int size; - int fd; - int dma; + QNode qn; + void *buf; + void *aligned_buf; + int size; + int fd; + int dma; }; struct fastrpc_alloc_dma_buf { - int fd; /* fd */ - uint32_t flags; /* flags to map with */ - uint64_t size; /* size */ + int fd; /* fd */ + uint32_t flags; /* flags to map with */ + uint64_t size; /* size */ }; -void rpcmem_init() { - QList_Ctor(&rpclst); - pthread_mutex_init(&rpcmt, 0); - pthread_mutex_lock(&rpcmt); - - dmafd = open(DMA_HEAP_NAME, O_RDONLY | O_CLOEXEC); - if (dmafd < 0) { - FARF(ALWAYS, "Warning %d: Unable to open %s, falling back to fastrpc ioctl\n", errno, DMA_HEAP_NAME); - /* - * Application should link proper library as DEFAULT_DOMAIN_ID - * is used to open rpc device node and not the uri passed by - * user. - */ - rpcfd = open_device_node(DEFAULT_DOMAIN_ID); - if (rpcfd < 0) - FARF(ALWAYS, "Warning %d: Unable to open fastrpc dev node for domain: %d\n", errno, DEFAULT_DOMAIN_ID); - } - pthread_mutex_unlock(&rpcmt); +void +rpcmem_init() +{ + QList_Ctor(&rpclst); + pthread_mutex_init(&rpcmt, 0); + pthread_mutex_lock(&rpcmt); + + dmafd = open(DMA_HEAP_NAME, O_RDONLY | O_CLOEXEC); + if(dmafd < 0) { + FARF(ALWAYS, + "Warning %d: Unable to open %s, falling back to fastrpc " + "ioctl\n", + errno, DMA_HEAP_NAME); + /* + * Application should link proper library as DEFAULT_DOMAIN_ID + * is used to open rpc device node and not the uri passed by + * user. + */ + rpcfd = open_device_node(DEFAULT_DOMAIN_ID); + if(rpcfd < 0) + FARF(ALWAYS, + "Warning %d: Unable to open fastrpc dev node for " + "domain: %d\n", + errno, DEFAULT_DOMAIN_ID); + } + pthread_mutex_unlock(&rpcmt); } -void rpcmem_deinit() { - pthread_mutex_lock(&rpcmt); - if (dmafd != -1) - close(dmafd); - if (rpcfd != -1) - close(rpcfd); - pthread_mutex_unlock(&rpcmt); - pthread_mutex_destroy(&rpcmt); +void +rpcmem_deinit() +{ + pthread_mutex_lock(&rpcmt); + if(dmafd != -1) + close(dmafd); + if(rpcfd != -1) + close(rpcfd); + pthread_mutex_unlock(&rpcmt); + pthread_mutex_destroy(&rpcmt); } -int rpcmem_set_dmabuf_name(const char *name, int fd, int heapid, - void *buf, uint32_t rpcflags) { - // Dummy call where DMABUF is not used - return 0; +int +rpcmem_set_dmabuf_name(const char *name, int fd, int heapid, void *buf, + uint32_t rpcflags) +{ + // Dummy call where DMABUF is not used + return 0; } -int rpcmem_to_fd_internal(void *po) { - struct rpc_info *rinfo, *rfree = 0; - QNode *pn, *pnn; +int +rpcmem_to_fd_internal(void *po) +{ + struct rpc_info *rinfo, *rfree = 0; + QNode *pn, *pnn; + + pthread_mutex_lock(&rpcmt); + QLIST_NEXTSAFE_FOR_ALL(&rpclst, pn, pnn) + { + rinfo = STD_RECOVER_REC(struct rpc_info, qn, pn); + if(rinfo->aligned_buf == po) { + rfree = rinfo; + break; + } + } + pthread_mutex_unlock(&rpcmt); - pthread_mutex_lock(&rpcmt); - QLIST_NEXTSAFE_FOR_ALL(&rpclst, pn, pnn) { - rinfo = STD_RECOVER_REC(struct rpc_info, qn, pn); - if (rinfo->aligned_buf == po) { - rfree = rinfo; - break; - } - } - pthread_mutex_unlock(&rpcmt); + if(rfree) + return rfree->fd; - if (rfree) - return rfree->fd; + return -1; +} - return -1; +int +rpcmem_to_fd(void *po) +{ + return rpcmem_to_fd_internal(po); } -int rpcmem_to_fd(void *po) { return rpcmem_to_fd_internal(po); } - -void *rpcmem_alloc_internal(int heapid, uint32_t flags, size_t size) { - struct rpc_info *rinfo; - int nErr = 0, fd = -1; - struct dma_heap_allocation_data dmabuf = { - .len = size, - .fd_flags = O_RDWR | O_CLOEXEC, - }; - - if ((dmafd == -1 && rpcfd == -1) || size <= 0) { - FARF(ERROR, - "Error: Unable to allocate memory dmaheap fd %d, rpcfd %d, size " - "%zu, flags %u", - dmafd, rpcfd, size, flags); - return NULL; - } - - VERIFY(0 != (rinfo = calloc(1, sizeof(*rinfo)))); - - if (dmafd != -1) { - nErr = ioctl(dmafd, DMA_HEAP_IOCTL_ALLOC, &dmabuf); - if (nErr) { - FARF(ERROR, - "Error %d: Unable to allocate memory dmaheap fd %d, heapid %d, size " - "%zu, flags %u", - errno, dmafd, heapid, size, flags); - goto bail; - } - fd = dmabuf.fd; - } else { - struct fastrpc_ioctl_alloc_dma_buf buf; - - buf.size = size + PAGE_SIZE; - buf.fd = -1; - buf.flags = 0; - - nErr = ioctl(rpcfd, FASTRPC_IOCTL_ALLOC_DMA_BUFF, (unsigned long)&buf); - if (nErr) { - FARF(ERROR, - "Error %d: Unable to allocate memory fastrpc fd %d, heapid %d, size " - "%zu, flags %u", - errno, rpcfd, heapid, size, flags); - goto bail; - } - fd = buf.fd; - } - VERIFY(0 != (rinfo->buf = mmap(0, size, PROT_READ | PROT_WRITE, MAP_SHARED, - fd, 0))); - rinfo->fd = fd; - rinfo->aligned_buf = - (void *)(((uintptr_t)rinfo->buf /*+ PAGE_SIZE*/) & PAGE_MASK); - rinfo->aligned_buf = rinfo->buf; - rinfo->size = size; - pthread_mutex_lock(&rpcmt); - QList_AppendNode(&rpclst, &rinfo->qn); - pthread_mutex_unlock(&rpcmt); - FARF(RUNTIME_RPC_HIGH, "Allocted memory from DMA heap fd %d ptr %p orig ptr %p\n", - rinfo->fd, rinfo->aligned_buf, rinfo->buf); - remote_register_buf(rinfo->buf, rinfo->size, rinfo->fd); - return rinfo->aligned_buf; +void * +rpcmem_alloc_internal(int heapid, uint32_t flags, size_t size) +{ + struct rpc_info *rinfo; + int nErr = 0, fd = -1; + struct dma_heap_allocation_data dmabuf = { + .len = size, + .fd_flags = O_RDWR | O_CLOEXEC, + }; + + if((dmafd == -1 && rpcfd == -1) || size <= 0) { + FARF(ERROR, + "Error: Unable to allocate memory dmaheap fd %d, rpcfd " + "%d, size " + "%zu, flags %u", + dmafd, rpcfd, size, flags); + return NULL; + } + + VERIFY(0 != (rinfo = calloc(1, sizeof(*rinfo)))); + + if(dmafd != -1) { + nErr = ioctl(dmafd, DMA_HEAP_IOCTL_ALLOC, &dmabuf); + if(nErr) { + FARF(ERROR, + "Error %d: Unable to allocate memory dmaheap fd " + "%d, heapid %d, size " + "%zu, flags %u", + errno, dmafd, heapid, size, flags); + goto bail; + } + fd = dmabuf.fd; + } else { + struct fastrpc_ioctl_alloc_dma_buf buf; + + buf.size = size + PAGE_SIZE; + buf.fd = -1; + buf.flags = 0; + + nErr = ioctl(rpcfd, FASTRPC_IOCTL_ALLOC_DMA_BUFF, + (unsigned long)&buf); + if(nErr) { + FARF(ERROR, + "Error %d: Unable to allocate memory fastrpc fd " + "%d, heapid %d, size " + "%zu, flags %u", + errno, rpcfd, heapid, size, flags); + goto bail; + } + fd = buf.fd; + } + VERIFY(0 + != (rinfo->buf = mmap(0, size, PROT_READ | PROT_WRITE, + MAP_SHARED, fd, 0))); + rinfo->fd = fd; + rinfo->aligned_buf + = (void *)(((uintptr_t)rinfo->buf /*+ PAGE_SIZE*/) & PAGE_MASK); + rinfo->aligned_buf = rinfo->buf; + rinfo->size = size; + pthread_mutex_lock(&rpcmt); + QList_AppendNode(&rpclst, &rinfo->qn); + pthread_mutex_unlock(&rpcmt); + FARF(RUNTIME_RPC_HIGH, + "Allocted memory from DMA heap fd %d ptr %p orig ptr %p\n", + rinfo->fd, rinfo->aligned_buf, rinfo->buf); + remote_register_buf(rinfo->buf, rinfo->size, rinfo->fd); + return rinfo->aligned_buf; bail: - if (nErr) { - if (rinfo) { - if (rinfo->buf) { - free(rinfo->buf); - } - free(rinfo); - } - } - return NULL; + if(nErr) { + if(rinfo) { + if(rinfo->buf) { + free(rinfo->buf); + } + free(rinfo); + } + } + return NULL; } -void rpcmem_free_internal(void *po) { - struct rpc_info *rinfo, *rfree = 0; - QNode *pn, *pnn; - - pthread_mutex_lock(&rpcmt); - QLIST_NEXTSAFE_FOR_ALL(&rpclst, pn, pnn) { - rinfo = STD_RECOVER_REC(struct rpc_info, qn, pn); - if (rinfo->aligned_buf == po) { - rfree = rinfo; - QNode_Dequeue(&rinfo->qn); - break; - } - } - pthread_mutex_unlock(&rpcmt); - if (rfree) { - remote_register_buf(rfree->buf, rfree->size, -1); - munmap(rfree->buf, rfree->size); - close(rfree->fd); - free(rfree); - } - return; +void +rpcmem_free_internal(void *po) +{ + struct rpc_info *rinfo, *rfree = 0; + QNode *pn, *pnn; + + pthread_mutex_lock(&rpcmt); + QLIST_NEXTSAFE_FOR_ALL(&rpclst, pn, pnn) + { + rinfo = STD_RECOVER_REC(struct rpc_info, qn, pn); + if(rinfo->aligned_buf == po) { + rfree = rinfo; + QNode_Dequeue(&rinfo->qn); + break; + } + } + pthread_mutex_unlock(&rpcmt); + if(rfree) { + remote_register_buf(rfree->buf, rfree->size, -1); + munmap(rfree->buf, rfree->size); + close(rfree->fd); + free(rfree); + } + return; } -void rpcmem_free(void *po) { rpcmem_free_internal(po); } +void +rpcmem_free(void *po) +{ + rpcmem_free_internal(po); +} -void *rpcmem_alloc(int heapid, uint32_t flags, int size) { - return rpcmem_alloc_internal(heapid, flags, size); +void * +rpcmem_alloc(int heapid, uint32_t flags, int size) +{ + return rpcmem_alloc_internal(heapid, flags, size); } -void rpcmem_deinit_internal() { rpcmem_deinit(); } +void +rpcmem_deinit_internal() +{ + rpcmem_deinit(); +} -void rpcmem_init_internal() { rpcmem_init(); } +void +rpcmem_init_internal() +{ + rpcmem_init(); +} diff --git a/src/std_dtoa.c b/src/std_dtoa.c index d2dfb8a4..73bf76da 100644 --- a/src/std_dtoa.c +++ b/src/std_dtoa.c @@ -1,112 +1,109 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause +#include "std_dtoa.h" #include "AEEStdDef.h" -#include "AEEstd.h" #include "AEEStdErr.h" -#include "std_dtoa.h" +#include "AEEstd.h" #include "math.h" // // Useful Macros // -#define FAILED(b) ( (b) != AEE_SUCCESS ? true : false ) -#define CLEANUP_ON_ERROR(b,l) if( FAILED( b ) ) { goto l; } -#define FP_POW_10(n) fp_pow_10(n) - -static __inline -uint32_t std_dtoa_clz32( uint32_t ulVal ) +#define FAILED(b) ((b) != AEE_SUCCESS ? true : false) +#define CLEANUP_ON_ERROR(b, l) \ + if(FAILED(b)) { \ + goto l; \ + } +#define FP_POW_10(n) fp_pow_10(n) + +static __inline uint32_t +std_dtoa_clz32(uint32_t ulVal) // // This function returns the number of leading zeroes in a uint32_t. // This is a naive implementation that uses binary search. This could be // replaced by an optimized inline assembly code. // { - if( (int)ulVal <= 0 ) - { - return ( ulVal == 0 ) ? 32 : 0; - } - else - { - uint32_t uRet = 28; - uint32_t uTmp = 0; - uTmp = ( ulVal > 0xFFFF ) * 16; ulVal >>= uTmp, uRet -= uTmp; - uTmp = ( ulVal > 0xFF ) * 8; ulVal >>= uTmp, uRet -= uTmp; - uTmp = ( ulVal > 0xF ) * 4; ulVal >>= uTmp, uRet -= uTmp; - return uRet + ( ( 0x55AF >> ( ulVal * 2 ) ) & 3 ); - } + if((int)ulVal <= 0) { + return (ulVal == 0) ? 32 : 0; + } else { + uint32_t uRet = 28; + uint32_t uTmp = 0; + uTmp = (ulVal > 0xFFFF) * 16; + ulVal >>= uTmp, uRet -= uTmp; + uTmp = (ulVal > 0xFF) * 8; + ulVal >>= uTmp, uRet -= uTmp; + uTmp = (ulVal > 0xF) * 4; + ulVal >>= uTmp, uRet -= uTmp; + return uRet + ((0x55AF >> (ulVal * 2)) & 3); + } } -static __inline -uint32_t std_dtoa_clz64( uint64_t ulVal ) +static __inline uint32_t +std_dtoa_clz64(uint64_t ulVal) // // This function returns the number of leading zeroes in a uint64_t. // { - uint32_t ulCount = 0; - - if( !( ulVal >> 32 ) ) - { - ulCount += 32; - } - else - { - ulVal >>= 32; - } - - return ulCount + std_dtoa_clz32( (uint32_t)ulVal ); + uint32_t ulCount = 0; + + if(!(ulVal >> 32)) { + ulCount += 32; + } else { + ulVal >>= 32; + } + + return ulCount + std_dtoa_clz32((uint32_t)ulVal); } -double fp_pow_10( int nPow ) +double +fp_pow_10(int nPow) { - double dRet = 1.0; - int nI = 0; - bool bNegative = false; - double aTablePos[] = { 0, 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 1e64, 1e128, - 1e256 }; - double aTableNeg[] = { 0, 1e-1, 1e-2, 1e-4, 1e-8, 1e-16, 1e-32, 1e-64, 1e-128, - 1e-256 }; - double* pTable = aTablePos; - int nTableSize = STD_ARRAY_SIZE( aTablePos ); - - if( 0 == nPow ) - { - return 1.0; - } - - if( nPow < 0 ) - { - bNegative = true; - nPow = -nPow; - pTable = aTableNeg; - nTableSize = STD_ARRAY_SIZE( aTableNeg ); - } - - for( nI = 1; nPow && (nI < nTableSize); nI++ ) - { - if( nPow & 1 ) - { - dRet *= pTable[nI]; - } - - nPow >>= 1; - } - - if( nPow ) - { - // Overflow. Trying to compute a large power value. - union { - uint64_t ul; - double d; - } val; - val.ul = STD_DTOA_FP_POSITIVE_INF; - dRet = bNegative ? 0 : val.d; - } - - return dRet; + double dRet = 1.0; + int nI = 0; + bool bNegative = false; + double aTablePos[] + = { 0, 1e1, 1e2, 1e4, 1e8, 1e16, 1e32, 1e64, 1e128, 1e256 }; + double aTableNeg[] = { 0, 1e-1, 1e-2, 1e-4, 1e-8, + 1e-16, 1e-32, 1e-64, 1e-128, 1e-256 }; + double *pTable = aTablePos; + int nTableSize = STD_ARRAY_SIZE(aTablePos); + + if(0 == nPow) { + return 1.0; + } + + if(nPow < 0) { + bNegative = true; + nPow = -nPow; + pTable = aTableNeg; + nTableSize = STD_ARRAY_SIZE(aTableNeg); + } + + for(nI = 1; nPow && (nI < nTableSize); nI++) { + if(nPow & 1) { + dRet *= pTable[nI]; + } + + nPow >>= 1; + } + + if(nPow) { + // Overflow. Trying to compute a large power value. + union { + uint64_t ul; + double d; + } val; + val.ul = STD_DTOA_FP_POSITIVE_INF; + dRet = bNegative ? 0 : val.d; + } + + return dRet; } -double fp_round( double dNumber, int nPrecision ) +double +fp_round(double dNumber, int nPrecision) // // This functions rounds dNumber to the specified precision nPrecision. // For example: @@ -114,382 +111,352 @@ double fp_round( double dNumber, int nPrecision ) // fp_round(2.34553, 4) = 2.3455 // { - double dResult = dNumber; - double dRoundingFactor = FP_POW_10( -nPrecision ) * 0.5; - - if( dNumber < 0 ) - { - dResult = dNumber - dRoundingFactor; - } - else - { - dResult = dNumber + dRoundingFactor; - } - - return dResult; + double dResult = dNumber; + double dRoundingFactor = FP_POW_10(-nPrecision) * 0.5; + + if(dNumber < 0) { + dResult = dNumber - dRoundingFactor; + } else { + dResult = dNumber + dRoundingFactor; + } + + return dResult; } -int fp_log_10( double dNumber ) +int +fp_log_10(double dNumber) // // This function finds the integer part of the log_10( dNumber ). // The function assumes that dNumber != 0. // { - // Absorb the negative sign - if( dNumber < 0 ) - { - dNumber = -dNumber; - } + // Absorb the negative sign + if(dNumber < 0) { + dNumber = -dNumber; + } - return (int)( floor( log10( dNumber ) ) ); + return (int)(floor(log10(dNumber))); } -int fp_check_special_cases( double dNumber, FloatingPointType* pNumberType ) +int +fp_check_special_cases(double dNumber, FloatingPointType *pNumberType) // // This function evaluates the input floating-point number dNumber to check for // following special cases: NaN, +/-Infinity. // The evaluation is based on the IEEE Standard 754 for Floating Point Numbers // { - int nError = AEE_SUCCESS; - FloatingPointType NumberType = FP_TYPE_UNKOWN; - uint64_t ullValue = 0; - uint64_t ullSign = 0; - int64_t n64Exponent = 0; - uint64_t ullMantissa = 0; - - union { - uint64_t ul; - double d; - } val; - - val.d = dNumber; - ullValue = val.ul; - - // Extract the sign, exponent and mantissa - ullSign = FP_SIGN( ullValue ); - n64Exponent = FP_EXPONENT_BIASED( ullValue ); - ullMantissa = FP_MANTISSA_DENORM( ullValue ); - - // - // Rules for special cases are listed below: - // For Infinity, the following needs to be true: - // 1. Exponent should have all bits set to 1. - // 2. Mantissa should have all bits set to 0. - // - // For NaN, the following needs to be true: - // 1. Exponent should have all bits set to 1. - // 2. Mantissa should be non-zero. - // Note that we do not differentiate between QNaNs and SNaNs. - // - if( STD_DTOA_DP_INFINITY_EXPONENT_ID == n64Exponent ) - { - if( 0 == ullMantissa ) - { - // Inifinity. - if( ullSign ) - { - NumberType = FP_TYPE_NEGATIVE_INF; - } - else - { - NumberType = FP_TYPE_POSITIVE_INF; - } - } - else - { - // NaN - NumberType = FP_TYPE_NAN; - } - } - else - { - // A normal number - NumberType = FP_TYPE_GENERAL; - } - - // Set the output value - *pNumberType = NumberType; - - return nError; + int nError = AEE_SUCCESS; + FloatingPointType NumberType = FP_TYPE_UNKOWN; + uint64_t ullValue = 0; + uint64_t ullSign = 0; + int64_t n64Exponent = 0; + uint64_t ullMantissa = 0; + + union { + uint64_t ul; + double d; + } val; + + val.d = dNumber; + ullValue = val.ul; + + // Extract the sign, exponent and mantissa + ullSign = FP_SIGN(ullValue); + n64Exponent = FP_EXPONENT_BIASED(ullValue); + ullMantissa = FP_MANTISSA_DENORM(ullValue); + + // + // Rules for special cases are listed below: + // For Infinity, the following needs to be true: + // 1. Exponent should have all bits set to 1. + // 2. Mantissa should have all bits set to 0. + // + // For NaN, the following needs to be true: + // 1. Exponent should have all bits set to 1. + // 2. Mantissa should be non-zero. + // Note that we do not differentiate between QNaNs and SNaNs. + // + if(STD_DTOA_DP_INFINITY_EXPONENT_ID == n64Exponent) { + if(0 == ullMantissa) { + // Inifinity. + if(ullSign) { + NumberType = FP_TYPE_NEGATIVE_INF; + } else { + NumberType = FP_TYPE_POSITIVE_INF; + } + } else { + // NaN + NumberType = FP_TYPE_NAN; + } + } else { + // A normal number + NumberType = FP_TYPE_GENERAL; + } + + // Set the output value + *pNumberType = NumberType; + + return nError; } -int std_dtoa_decimal( double dNumber, int nPrecision, - char acIntegerPart[ STD_DTOA_FORMAT_INTEGER_SIZE ], - char acFractionPart[ STD_DTOA_FORMAT_FRACTION_SIZE ] ) +int +std_dtoa_decimal(double dNumber, int nPrecision, + char acIntegerPart[STD_DTOA_FORMAT_INTEGER_SIZE], + char acFractionPart[STD_DTOA_FORMAT_FRACTION_SIZE]) { - int nError = AEE_SUCCESS; - bool bNegativeNumber = false; - double dIntegerPart = 0.0; - double dFractionPart = 0.0; - double dTempIp = 0.0; - double dTempFp = 0.0; - int nMaxIntDigs = STD_DTOA_FORMAT_INTEGER_SIZE; - uint32_t ulI = 0; - int nIntStartPos = 0; - - // Optimization: Special case an input of 0 - if( 0.0 == dNumber ) - { - acIntegerPart[0] = '0'; - acIntegerPart[1] = '\0'; - - for( ulI = 0; (ulI < STD_DTOA_FORMAT_FRACTION_SIZE - 1) && (nPrecision > 0); - ulI++, nPrecision-- ) - { - acFractionPart[ulI] = '0'; - } - acFractionPart[ ulI ] = '\0'; - - goto bail; - } - - // Absorb the negative sign - if( dNumber < 0 ) - { - acIntegerPart[0] = '-'; - nIntStartPos = 1; - dNumber = -dNumber; - bNegativeNumber = true; - } - - // Split the input number into it's integer and fraction parts - dFractionPart = modf( dNumber, &dIntegerPart ); - - // First up, convert the integer part - if( 0.0 == dIntegerPart ) - { - acIntegerPart[ nIntStartPos ] = '0'; - } - else - { - double dRoundingConst = FP_POW_10( -STD_DTOA_PRECISION_ROUNDING_VALUE ); - int nIntDigs = 0; - int nI = 0; - - // Compute the number of digits in the integer part of the number - nIntDigs = fp_log_10( dIntegerPart ) + 1; - - // For negative numbers, a '-' sign has already been written. - if( true == bNegativeNumber ) - { - nIntDigs++; - } - - // Check for overflow - if( nIntDigs >= nMaxIntDigs ) - { - // Overflow! - // Note that currently, we return a simple AEE_EFAILED for all - // errors. - nError = AEE_EFAILED; - goto bail; - } - - // Null Terminate the string - acIntegerPart[ nIntDigs ] = '\0'; - - for( nI = nIntDigs - 1; nI >= nIntStartPos; nI-- ) - { - dIntegerPart = dIntegerPart / 10.0; - dTempFp = modf( dIntegerPart, &dTempIp ); - - // Round it to the a specific precision - dTempFp = dTempFp + dRoundingConst; - - // Convert the digit to a character - acIntegerPart[ nI ] = (int)( dTempFp * 10 ) + '0'; - if( !MY_ISDIGIT( acIntegerPart[ nI ] ) ) - { - // Overflow! - // Note that currently, we return a simple AEE_EFAILED for all - // errors. - nError = AEE_EFAILED; - goto bail; - } - dIntegerPart = dTempIp; - } - } - - // Just a double check for integrity sake. This should ideally never happen. - // Out of bounds scenario. That is, the integer part of the input number is - // too large. - if( dIntegerPart != 0.0 ) - { - // Note that currently, we return a simple AEE_EFAILED for all - // errors. - nError = AEE_EFAILED; - goto bail; - } - - // Now, convert the fraction part - for( ulI = 0; ( nPrecision > 0 ) && ( ulI < STD_DTOA_FORMAT_FRACTION_SIZE - 1 ); - nPrecision--, ulI++ ) - { - if( 0.0 == dFractionPart ) - { - acFractionPart[ ulI ] = '0'; - } - else - { - double dRoundingValue = FP_POW_10( -( nPrecision + - STD_DTOA_PRECISION_ROUNDING_VALUE ) ); - acFractionPart[ ulI ] = (int)( ( dFractionPart + dRoundingValue ) * 10.0 ) + '0'; - if( !MY_ISDIGIT( acFractionPart[ ulI ] ) ) - { - // Overflow! - // Note that currently, we return a simple AEE_EFAILED for all - // errors. - nError = AEE_EFAILED; - goto bail; - } - - dFractionPart = ( dFractionPart * 10.0 ) - - (int)( ( dFractionPart + FP_POW_10( -nPrecision - 6 ) ) * 10.0 ); - } - } - + int nError = AEE_SUCCESS; + bool bNegativeNumber = false; + double dIntegerPart = 0.0; + double dFractionPart = 0.0; + double dTempIp = 0.0; + double dTempFp = 0.0; + int nMaxIntDigs = STD_DTOA_FORMAT_INTEGER_SIZE; + uint32_t ulI = 0; + int nIntStartPos = 0; + + // Optimization: Special case an input of 0 + if(0.0 == dNumber) { + acIntegerPart[0] = '0'; + acIntegerPart[1] = '\0'; + + for(ulI = 0; (ulI < STD_DTOA_FORMAT_FRACTION_SIZE - 1) + && (nPrecision > 0); + ulI++, nPrecision--) { + acFractionPart[ulI] = '0'; + } + acFractionPart[ulI] = '\0'; + + goto bail; + } + + // Absorb the negative sign + if(dNumber < 0) { + acIntegerPart[0] = '-'; + nIntStartPos = 1; + dNumber = -dNumber; + bNegativeNumber = true; + } + + // Split the input number into it's integer and fraction parts + dFractionPart = modf(dNumber, &dIntegerPart); + + // First up, convert the integer part + if(0.0 == dIntegerPart) { + acIntegerPart[nIntStartPos] = '0'; + } else { + double dRoundingConst + = FP_POW_10(-STD_DTOA_PRECISION_ROUNDING_VALUE); + int nIntDigs = 0; + int nI = 0; + + // Compute the number of digits in the integer part of the + // number + nIntDigs = fp_log_10(dIntegerPart) + 1; + + // For negative numbers, a '-' sign has already been written. + if(true == bNegativeNumber) { + nIntDigs++; + } + + // Check for overflow + if(nIntDigs >= nMaxIntDigs) { + // Overflow! + // Note that currently, we return a simple AEE_EFAILED + // for all errors. + nError = AEE_EFAILED; + goto bail; + } + + // Null Terminate the string + acIntegerPart[nIntDigs] = '\0'; + + for(nI = nIntDigs - 1; nI >= nIntStartPos; nI--) { + dIntegerPart = dIntegerPart / 10.0; + dTempFp = modf(dIntegerPart, &dTempIp); + + // Round it to the a specific precision + dTempFp = dTempFp + dRoundingConst; + + // Convert the digit to a character + acIntegerPart[nI] = (int)(dTempFp * 10) + '0'; + if(!MY_ISDIGIT(acIntegerPart[nI])) { + // Overflow! + // Note that currently, we return a simple + // AEE_EFAILED for all errors. + nError = AEE_EFAILED; + goto bail; + } + dIntegerPart = dTempIp; + } + } + + // Just a double check for integrity sake. This should ideally never + // happen. Out of bounds scenario. That is, the integer part of the + // input number is too large. + if(dIntegerPart != 0.0) { + // Note that currently, we return a simple AEE_EFAILED for all + // errors. + nError = AEE_EFAILED; + goto bail; + } + + // Now, convert the fraction part + for(ulI = 0; + (nPrecision > 0) && (ulI < STD_DTOA_FORMAT_FRACTION_SIZE - 1); + nPrecision--, ulI++) { + if(0.0 == dFractionPart) { + acFractionPart[ulI] = '0'; + } else { + double dRoundingValue = FP_POW_10( + -(nPrecision + STD_DTOA_PRECISION_ROUNDING_VALUE)); + acFractionPart[ulI] + = (int)((dFractionPart + dRoundingValue) * 10.0) + + '0'; + if(!MY_ISDIGIT(acFractionPart[ulI])) { + // Overflow! + // Note that currently, we return a simple + // AEE_EFAILED for all errors. + nError = AEE_EFAILED; + goto bail; + } + + dFractionPart = (dFractionPart * 10.0) + - (int)((dFractionPart + + FP_POW_10(-nPrecision - 6)) + * 10.0); + } + } bail: - return nError; + return nError; } -int std_dtoa_hex( double dNumber, int nPrecision, char cFormat, - char acIntegerPart[ STD_DTOA_FORMAT_INTEGER_SIZE ], - char acFractionPart[ STD_DTOA_FORMAT_FRACTION_SIZE ], - int* pnExponent ) +int +std_dtoa_hex(double dNumber, int nPrecision, char cFormat, + char acIntegerPart[STD_DTOA_FORMAT_INTEGER_SIZE], + char acFractionPart[STD_DTOA_FORMAT_FRACTION_SIZE], + int *pnExponent) { - int nError = AEE_SUCCESS; - uint64_t ullMantissa = 0; - uint64_t ullSign = 0; - int64_t n64Exponent = 0; - static const char HexDigitsU[] = "0123456789ABCDEF"; - static const char HexDigitsL[] = "0123456789abcde"; - bool bFirstDigit = true; - int nI = 0; - int nF = 0; - union { - uint64_t ul; - double d; - } val; - - val.d = dNumber; - uint64_t ullValue = val.ul; - - int nManShift = 0; - const char *pcDigitArray = ( cFormat == 'A' ) ? HexDigitsU : HexDigitsL; - bool bPrecisionSpecified = true; - - // If no precision is specified, then set the precision to be fairly - // large. - if( nPrecision < 0 ) - { - nPrecision = STD_DTOA_FORMAT_FRACTION_SIZE; - bPrecisionSpecified = false; - } - else - { - bPrecisionSpecified = true; - } - - // Extract the sign, exponent and mantissa - ullSign = FP_SIGN( ullValue ); - n64Exponent = FP_EXPONENT( ullValue ); - ullMantissa = FP_MANTISSA( ullValue ); - - // Write out the sign - if( ullSign ) - { - acIntegerPart[ nI++ ] = '-'; - } - - // Optimization: Special case an input of 0 - if( 0.0 == dNumber ) - { - acIntegerPart[0] = '0'; - acIntegerPart[1] = '\0'; - - for( nF = 0; (nF < STD_DTOA_FORMAT_FRACTION_SIZE - 1) && (nPrecision > 0); - nF++, nPrecision-- ) - { - acFractionPart[nF] = '0'; - } - acFractionPart[nF] = '\0'; - - goto bail; - } - - // The mantissa is in lower 53 bits (52 bits + an implicit 1). - // If we are dealing with a denormalized number, then the implicit 1 - // is absent. The above macros would have then set that bit to 0. - // Shift the mantisaa on to the highest bits. - - if( 0 == ( n64Exponent + STD_DTOA_DP_EXPONENT_BIAS ) ) - { - // DENORMALIZED NUMBER. - // A denormalized number is of the form: - // 0.bbb...bbb x 2^Exponent - // Shift the mantissa to the higher bits while discarding the leading 0 - ullMantissa <<= 12; - - // Lets update the exponent so as to make sure that the first hex value - // in the mantissa is non-zero, i.e., at least one of the first 4 bits is - // non-zero. - nManShift = std_dtoa_clz64( ullMantissa ) - 3; - if( nManShift > 0 ) - { - ullMantissa <<= nManShift; - n64Exponent -= nManShift; - } - } - else - { - // NORMALIZED NUMBER. - // A normalized number has the following form: - // 1.bbb...bbb x 2^Exponent - // Shift the mantissa to the higher bits while retaining the leading 1 - ullMantissa <<= 11; - } - - // Now, lets get the decimal point out of the picture by shifting the - // exponent by 1. - n64Exponent++; - - // Read the mantissa four bits at a time to form the hex output - for( nI = 0, nF = 0, bFirstDigit = true; ullMantissa != 0; - ullMantissa <<= 4 ) - { - uint64_t ulHexVal = ullMantissa & 0xF000000000000000uLL; - ulHexVal >>= 60; - if( bFirstDigit ) - { - // Write to the integral part of the number - acIntegerPart[ nI++ ] = pcDigitArray[ulHexVal]; - bFirstDigit = false; - } - else if( nF < nPrecision ) - { - // Write to the fractional part of the number - acFractionPart[ nF++ ] = pcDigitArray[ulHexVal]; - } - } - - // Pad the fraction with trailing zeroes upto the specified precision - for( ; bPrecisionSpecified && (nF < nPrecision); nF++ ) - { - acFractionPart[ nF ] = '0'; - } - - // Now the output is of the form; - // h.hhh x 2^Exponent - // where h is a non-zero hexadecimal number. - // But we were dealing with a binary fraction 0.bbb...bbb x 2^Exponent. - // Therefore, we need to subtract 4 from the exponent (since the shift - // was to the base 16 and the exponent is to the base 2). - n64Exponent -= 4; - *pnExponent = (int)n64Exponent; + int nError = AEE_SUCCESS; + uint64_t ullMantissa = 0; + uint64_t ullSign = 0; + int64_t n64Exponent = 0; + static const char HexDigitsU[] = "0123456789ABCDEF"; + static const char HexDigitsL[] = "0123456789abcde"; + bool bFirstDigit = true; + int nI = 0; + int nF = 0; + union { + uint64_t ul; + double d; + } val; + + val.d = dNumber; + uint64_t ullValue = val.ul; + + int nManShift = 0; + const char *pcDigitArray = (cFormat == 'A') ? HexDigitsU : HexDigitsL; + bool bPrecisionSpecified = true; + + // If no precision is specified, then set the precision to be fairly + // large. + if(nPrecision < 0) { + nPrecision = STD_DTOA_FORMAT_FRACTION_SIZE; + bPrecisionSpecified = false; + } else { + bPrecisionSpecified = true; + } + + // Extract the sign, exponent and mantissa + ullSign = FP_SIGN(ullValue); + n64Exponent = FP_EXPONENT(ullValue); + ullMantissa = FP_MANTISSA(ullValue); + + // Write out the sign + if(ullSign) { + acIntegerPart[nI++] = '-'; + } + + // Optimization: Special case an input of 0 + if(0.0 == dNumber) { + acIntegerPart[0] = '0'; + acIntegerPart[1] = '\0'; + + for(nF = 0; (nF < STD_DTOA_FORMAT_FRACTION_SIZE - 1) + && (nPrecision > 0); + nF++, nPrecision--) { + acFractionPart[nF] = '0'; + } + acFractionPart[nF] = '\0'; + + goto bail; + } + + // The mantissa is in lower 53 bits (52 bits + an implicit 1). + // If we are dealing with a denormalized number, then the implicit 1 + // is absent. The above macros would have then set that bit to 0. + // Shift the mantisaa on to the highest bits. + + if(0 == (n64Exponent + STD_DTOA_DP_EXPONENT_BIAS)) { + // DENORMALIZED NUMBER. + // A denormalized number is of the form: + // 0.bbb...bbb x 2^Exponent + // Shift the mantissa to the higher bits while discarding the + // leading 0 + ullMantissa <<= 12; + + // Lets update the exponent so as to make sure that the first + // hex value in the mantissa is non-zero, i.e., at least one of + // the first 4 bits is non-zero. + nManShift = std_dtoa_clz64(ullMantissa) - 3; + if(nManShift > 0) { + ullMantissa <<= nManShift; + n64Exponent -= nManShift; + } + } else { + // NORMALIZED NUMBER. + // A normalized number has the following form: + // 1.bbb...bbb x 2^Exponent + // Shift the mantissa to the higher bits while retaining the + // leading 1 + ullMantissa <<= 11; + } + + // Now, lets get the decimal point out of the picture by shifting the + // exponent by 1. + n64Exponent++; + + // Read the mantissa four bits at a time to form the hex output + for(nI = 0, nF = 0, bFirstDigit = true; ullMantissa != 0; + ullMantissa <<= 4) { + uint64_t ulHexVal = ullMantissa & 0xF000000000000000uLL; + ulHexVal >>= 60; + if(bFirstDigit) { + // Write to the integral part of the number + acIntegerPart[nI++] = pcDigitArray[ulHexVal]; + bFirstDigit = false; + } else if(nF < nPrecision) { + // Write to the fractional part of the number + acFractionPart[nF++] = pcDigitArray[ulHexVal]; + } + } + + // Pad the fraction with trailing zeroes upto the specified precision + for(; bPrecisionSpecified && (nF < nPrecision); nF++) { + acFractionPart[nF] = '0'; + } + + // Now the output is of the form; + // h.hhh x 2^Exponent + // where h is a non-zero hexadecimal number. + // But we were dealing with a binary fraction 0.bbb...bbb x 2^Exponent. + // Therefore, we need to subtract 4 from the exponent (since the shift + // was to the base 16 and the exponent is to the base 2). + n64Exponent -= 4; + *pnExponent = (int)n64Exponent; bail: - return nError; + return nError; } diff --git a/src/std_path.c b/src/std_path.c index 2597daa2..81964d4f 100644 --- a/src/std_path.c +++ b/src/std_path.c @@ -12,132 +12,135 @@ FILE: std_path.c /* To get memrchr on GNU/Linux */ #define _GNU_SOURCE -#include "AEEstd.h" #include "AEEBufBound.h" +#include "AEEstd.h" #include /*=========================================================================== ===========================================================================*/ -int std_makepath(const char* cpszDir, const char* cpszFile, - char* pszOut, int nOutLen) +int +std_makepath(const char *cpszDir, const char *cpszFile, char *pszOut, + int nOutLen) { - BufBound bb; - - BufBound_Init(&bb, pszOut, nOutLen); + BufBound bb; - BufBound_Puts(&bb, cpszDir); + BufBound_Init(&bb, pszOut, nOutLen); - if (('\0' != cpszDir[0]) && /* non-empty dir */ - ('/' != cpszDir[strlen(cpszDir)-1])) { /* no slash at end of dir */ - BufBound_Putc(&bb, '/'); - } - if ('/' == cpszFile[0]) { - cpszFile++; - } + BufBound_Puts(&bb, cpszDir); - BufBound_Puts(&bb, cpszFile); + if(('\0' != cpszDir[0]) && /* non-empty dir */ + ('/' + != cpszDir[strlen(cpszDir) - 1])) { /* no slash at end of dir */ + BufBound_Putc(&bb, '/'); + } + if('/' == cpszFile[0]) { + cpszFile++; + } - BufBound_ForceNullTerm(&bb); + BufBound_Puts(&bb, cpszFile); - return BufBound_Wrote(&bb) - 1; + BufBound_ForceNullTerm(&bb); + return BufBound_Wrote(&bb) - 1; } /*=========================================================================== ===========================================================================*/ -char* std_splitpath(const char* cpszPath, const char* cpszDir) +char * +std_splitpath(const char *cpszPath, const char *cpszDir) { - const char* cpsz = cpszPath; + const char *cpsz = cpszPath; - while ( ! ('\0' == cpszDir[0] || - ('/' == cpszDir[0] && '\0' == cpszDir[1])) ){ + while(!('\0' == cpszDir[0] + || ('/' == cpszDir[0] && '\0' == cpszDir[1]))) { - if (*cpszDir != *cpsz) { - return 0; - } + if(*cpszDir != *cpsz) { + return 0; + } - ++cpsz; - ++cpszDir; - } + ++cpsz; + ++cpszDir; + } - /* Found the filename part of the path. - It should begin with a '/' unless there is no filename */ - if ('/' == *cpsz) { - cpsz++; - } - else if ('\0' != *cpsz) { - cpsz = 0; - } + /* Found the filename part of the path. + It should begin with a '/' unless there is no filename */ + if('/' == *cpsz) { + cpsz++; + } else if('\0' != *cpsz) { + cpsz = 0; + } - return (char*)cpsz; + return (char *)cpsz; } -char* std_cleanpath(char* pszPath) +char * +std_cleanpath(char *pszPath) { - char* pszStart = pszPath; - char* pc; - char* pcEnd = pszStart+strlen(pszStart); - - /* preserve leading slash */ - if ('/' == pszStart[0]) { - pszStart++; - } - - pc = pszStart; - - while ((char*)0 != (pc = strstr(pc, "/."))) { - char* pcDelFrom; - - if ('/' == pc[2] || '\0' == pc[2]) { - /* delete "/." */ - pcDelFrom = pc; - pc += 2; - } else if ('.' == pc[2] && ('/' == pc[3] || '\0' == pc[3])) { - /* delete "/element/.." */ - pcDelFrom = memrchr(pszStart, '/', pc - pszStart); - if (!pcDelFrom) - pcDelFrom = pszStart; - pc += 3; - } else { - pc += 2; - continue; - } - - memmove(pcDelFrom, pc, pcEnd-pcDelFrom); - - pc = pcDelFrom; - } - - /* eliminate leading "../" */ - while (pszStart == strstr(pszStart, "../")) { - memmove(pszStart, pszStart+2, pcEnd-pszStart); - } - - /* eliminate leading "./" */ - while (pszStart == strstr(pszStart, "./")) { - memmove(pszStart, pszStart+1, pcEnd-pszStart); - } - - if (!strncmp(pszStart,"..",2) || !strncmp(pszStart,".",1)) { - pszStart[0] = '\0'; - } - - /* whack double '/' */ - while ((char*)0 != (pc = strstr(pszPath, "//"))) { - memmove(pc, pc+1, pcEnd-pc); - } - - return pszPath; + char *pszStart = pszPath; + char *pc; + char *pcEnd = pszStart + strlen(pszStart); + + /* preserve leading slash */ + if('/' == pszStart[0]) { + pszStart++; + } + + pc = pszStart; + + while((char *)0 != (pc = strstr(pc, "/."))) { + char *pcDelFrom; + + if('/' == pc[2] || '\0' == pc[2]) { + /* delete "/." */ + pcDelFrom = pc; + pc += 2; + } else if('.' == pc[2] && ('/' == pc[3] || '\0' == pc[3])) { + /* delete "/element/.." */ + pcDelFrom = memrchr(pszStart, '/', pc - pszStart); + if(!pcDelFrom) + pcDelFrom = pszStart; + pc += 3; + } else { + pc += 2; + continue; + } + + memmove(pcDelFrom, pc, pcEnd - pcDelFrom); + + pc = pcDelFrom; + } + + /* eliminate leading "../" */ + while(pszStart == strstr(pszStart, "../")) { + memmove(pszStart, pszStart + 2, pcEnd - pszStart); + } + + /* eliminate leading "./" */ + while(pszStart == strstr(pszStart, "./")) { + memmove(pszStart, pszStart + 1, pcEnd - pszStart); + } + + if(!strncmp(pszStart, "..", 2) || !strncmp(pszStart, ".", 1)) { + pszStart[0] = '\0'; + } + + /* whack double '/' */ + while((char *)0 != (pc = strstr(pszPath, "//"))) { + memmove(pc, pc + 1, pcEnd - pc); + } + + return pszPath; } -char* std_basename(const char* cpszFile) +char * +std_basename(const char *cpszFile) { - const char* cpsz; + const char *cpsz; - if ((char*)0 != (cpsz = strrchr(cpszFile,'/'))) { - cpszFile = cpsz+1; - } + if((char *)0 != (cpsz = strrchr(cpszFile, '/'))) { + cpszFile = cpsz + 1; + } - return (char*)cpszFile; + return (char *)cpszFile; } diff --git a/test/fastrpc_test.c b/test/fastrpc_test.c index 89f57e23..75165f39 100644 --- a/test/fastrpc_test.c +++ b/test/fastrpc_test.c @@ -1,149 +1,170 @@ // Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. // SPDX-License-Identifier: BSD-3-Clause -#include +#include +#include +#include +#include // For PATH_MAX #include +#include #include -#include #include -#include -#include -#include -#include // For PATH_MAX +#include typedef int (*run_test_t)(int domain_id, bool is_unsignedpd_enabled); -static void print_usage() { - printf("Usage:\n" - " fastrpc_test [-d domain] [-U unsigned_PD] [-t target] [-a arch_version]\n\n" - "Options:\n" - "-d domain: Run on a specific domain.\n" - " 0: Run the example on ADSP\n" - " 1: Run the example on MDSP\n" - " 2: Run the example on SDSP\n" - " 3: Run the example on CDSP\n" - " Default Value: 3(CDSP) for targets having CDSP.\n" - "-U unsigned_PD: Run on signed or unsigned PD.\n" - " 0: Run on signed PD.\n" - " 1: Run on unsigned PD.\n" - " Default Value: 1\n" - "-t target: Specify the target platform (android or linux).\n" - " Default Value: linux\n" - "-a arch_version: Specify the architecture version (v68 or v75).\n" - " Default Value: v68\n" - ); +static void +print_usage() +{ + printf( + "Usage:\n" + " fastrpc_test [-d domain] [-U unsigned_PD] [-t target] [-a " + "arch_version]\n\n" + "Options:\n" + "-d domain: Run on a specific domain.\n" + " 0: Run the example on ADSP\n" + " 1: Run the example on MDSP\n" + " 2: Run the example on SDSP\n" + " 3: Run the example on CDSP\n" + " Default Value: 3(CDSP) for targets having CDSP.\n" + "-U unsigned_PD: Run on signed or unsigned PD.\n" + " 0: Run on signed PD.\n" + " 1: Run on unsigned PD.\n" + " Default Value: 1\n" + "-t target: Specify the target platform (android or linux).\n" + " Default Value: linux\n" + "-a arch_version: Specify the architecture version (v68 or v75).\n" + " Default Value: v68\n"); } -int main(int argc, char *argv[]) { - int domain_id = 3; // Default domain ID for CDSP - bool is_unsignedpd_enabled = true; // Default to unsigned PD - const char *target = "linux"; // Default target platform - const char *arch_version = "v68"; // Default architecture version - char ld_lib_path[PATH_MAX]; - char dsp_lib_path[PATH_MAX]; - char *current_ld_lib_path; - char *current_dsp_lib_path; - DIR *dir; - struct dirent *entry; - char full_lib_path[PATH_MAX]; - void *lib_handle = NULL; - run_test_t run_test = NULL; - int nErr = 0; - - int opt; - while ((opt = getopt(argc, argv, "d:U:t:a:")) != -1) { - switch (opt) { - case 'd': - domain_id = atoi(optarg); - break; - case 'U': - is_unsignedpd_enabled = atoi(optarg) != 0; - break; - case 't': - target = optarg; - if (strcmp(target, "linux") != 0 && strcmp(target, "android") != 0) { - printf("\nERROR: Invalid target platform (-t). Must be linux or android.\n"); - print_usage(); - return -1; - } - break; - case 'a': - arch_version = optarg; - if (strcmp(arch_version, "v68") != 0 && strcmp(arch_version, "v75") != 0) { - printf("\nERROR: Invalid architecture version (-a). Must be v68 or v75.\n"); - print_usage(); - return -1; - } - break; - default: - print_usage(); - return -1; - } - } - - current_ld_lib_path = getenv("LD_LIBRARY_PATH"); - if (current_ld_lib_path) { - snprintf(ld_lib_path, sizeof(ld_lib_path), "%s;%s", current_ld_lib_path, testlibdir); - } else { - snprintf(ld_lib_path, sizeof(ld_lib_path), "%s", testlibdir); - } - if (setenv("LD_LIBRARY_PATH", ld_lib_path, 1) != 0) { - fprintf(stderr, "Error setting LD_LIBRARY_PATH: %s\n", strerror(errno)); - return -1; - } - - current_dsp_lib_path = getenv("DSP_LIBRARY_PATH"); - if (current_dsp_lib_path) { - snprintf(dsp_lib_path, sizeof(dsp_lib_path), "%s;%s/%s", current_dsp_lib_path, testdspdir, arch_version); - } else { - snprintf(dsp_lib_path, sizeof(dsp_lib_path), "%s/%s", testdspdir, arch_version); - } - if (setenv("DSP_LIBRARY_PATH", dsp_lib_path, 1) != 0) { - fprintf(stderr, "Error setting DSP_LIBRARY_PATH: %s\n", strerror(errno)); - return -1; - } - - dir = opendir(testlibdir); - if (!dir) { - fprintf(stderr, "Error opening directory %s: %s\n", testlibdir, strerror(errno)); - return -1; - } - - while ((entry = readdir(dir)) != NULL) { - if (entry->d_type == DT_REG && strstr(entry->d_name, ".so")) { - snprintf(full_lib_path, sizeof(full_lib_path), "%s/%s", testlibdir, entry->d_name); - - lib_handle = dlopen(full_lib_path, RTLD_LAZY); - if (!lib_handle) { - fprintf(stderr, "Error loading %s: %s\n", full_lib_path, dlerror()); - continue; - } - - run_test = (run_test_t)dlsym(lib_handle, "run_test"); - if (!run_test) { - fprintf(stderr, "Symbol 'run_test' not found in %s\n", full_lib_path); - dlclose(lib_handle); - continue; - } - - nErr = run_test(domain_id, is_unsignedpd_enabled); - if (nErr != 0) { - printf("Test failed with error code 0x%x in %s\n", nErr, full_lib_path); - } else { - printf("Success in %s\n", full_lib_path); - } - - dlclose(lib_handle); - } - } - - closedir(dir); - - if (nErr != 0) { - printf("Test failed with error code 0x%x\n", nErr); - } else { - printf("All tests completed successfully\n"); - } - - return nErr; -} \ No newline at end of file +int +main(int argc, char *argv[]) +{ + int domain_id = 3; // Default domain ID for CDSP + bool is_unsignedpd_enabled = true; // Default to unsigned PD + const char *target = "linux"; // Default target platform + const char *arch_version = "v68"; // Default architecture version + char ld_lib_path[PATH_MAX]; + char dsp_lib_path[PATH_MAX]; + char *current_ld_lib_path; + char *current_dsp_lib_path; + DIR *dir; + struct dirent *entry; + char full_lib_path[PATH_MAX]; + void *lib_handle = NULL; + run_test_t run_test = NULL; + int nErr = 0; + + int opt; + while((opt = getopt(argc, argv, "d:U:t:a:")) != -1) { + switch(opt) { + case 'd': + domain_id = atoi(optarg); + break; + case 'U': + is_unsignedpd_enabled = atoi(optarg) != 0; + break; + case 't': + target = optarg; + if(strcmp(target, "linux") != 0 + && strcmp(target, "android") != 0) { + printf("\nERROR: Invalid target platform " + "(-t). Must be linux or android.\n"); + print_usage(); + return -1; + } + break; + case 'a': + arch_version = optarg; + if(strcmp(arch_version, "v68") != 0 + && strcmp(arch_version, "v75") != 0) { + printf("\nERROR: Invalid architecture version " + "(-a). Must be v68 or v75.\n"); + print_usage(); + return -1; + } + break; + default: + print_usage(); + return -1; + } + } + + current_ld_lib_path = getenv("LD_LIBRARY_PATH"); + if(current_ld_lib_path) { + snprintf(ld_lib_path, sizeof(ld_lib_path), "%s;%s", + current_ld_lib_path, testlibdir); + } else { + snprintf(ld_lib_path, sizeof(ld_lib_path), "%s", testlibdir); + } + if(setenv("LD_LIBRARY_PATH", ld_lib_path, 1) != 0) { + fprintf(stderr, "Error setting LD_LIBRARY_PATH: %s\n", + strerror(errno)); + return -1; + } + + current_dsp_lib_path = getenv("DSP_LIBRARY_PATH"); + if(current_dsp_lib_path) { + snprintf(dsp_lib_path, sizeof(dsp_lib_path), "%s;%s/%s", + current_dsp_lib_path, testdspdir, arch_version); + } else { + snprintf(dsp_lib_path, sizeof(dsp_lib_path), "%s/%s", + testdspdir, arch_version); + } + if(setenv("DSP_LIBRARY_PATH", dsp_lib_path, 1) != 0) { + fprintf(stderr, "Error setting DSP_LIBRARY_PATH: %s\n", + strerror(errno)); + return -1; + } + + dir = opendir(testlibdir); + if(!dir) { + fprintf(stderr, "Error opening directory %s: %s\n", testlibdir, + strerror(errno)); + return -1; + } + + while((entry = readdir(dir)) != NULL) { + if(entry->d_type == DT_REG && strstr(entry->d_name, ".so")) { + snprintf(full_lib_path, sizeof(full_lib_path), "%s/%s", + testlibdir, entry->d_name); + + lib_handle = dlopen(full_lib_path, RTLD_LAZY); + if(!lib_handle) { + fprintf(stderr, "Error loading %s: %s\n", + full_lib_path, dlerror()); + continue; + } + + run_test = (run_test_t)dlsym(lib_handle, "run_test"); + if(!run_test) { + fprintf(stderr, + "Symbol 'run_test' not found in %s\n", + full_lib_path); + dlclose(lib_handle); + continue; + } + + nErr = run_test(domain_id, is_unsignedpd_enabled); + if(nErr != 0) { + printf( + "Test failed with error code 0x%x in %s\n", + nErr, full_lib_path); + } else { + printf("Success in %s\n", full_lib_path); + } + + dlclose(lib_handle); + } + } + + closedir(dir); + + if(nErr != 0) { + printf("Test failed with error code 0x%x\n", nErr); + } else { + printf("All tests completed successfully\n"); + } + + return nErr; +}