16cd6a6acSopenharmony_ciCall / Macro Statements 26cd6a6acSopenharmony_ci======================= 36cd6a6acSopenharmony_ci 46cd6a6acSopenharmony_cicall 56cd6a6acSopenharmony_ci---- 66cd6a6acSopenharmony_ci 76cd6a6acSopenharmony_ciInstantiate a [macro](#macro) within the current namespace. There may be zero or more parameters passed to the macro (with zero parameters this is similar to the [`blockinherit`](cil_container_statements.md#blockinherit) ([`call`](cil_call_macro_statements.md#call)) / [`blockabstract`](cil_container_statements.md#blockabstract) ([`macro`](cil_call_macro_statements.md#macro)) statements). 86cd6a6acSopenharmony_ci 96cd6a6acSopenharmony_ciEach parameter passed contains an argument to be resolved by the [macro](#macro), these can be named or anonymous but must conform to the parameter types defined in the [`macro`](cil_call_macro_statements.md#macro) statement. 106cd6a6acSopenharmony_ci 116cd6a6acSopenharmony_ciMacro rules are resolved by searching in the following order: 126cd6a6acSopenharmony_ci 136cd6a6acSopenharmony_ci- The macro namespace (If found this means that the name was declared in the macro and is now declared in the namespace of one of the parents of the call.) 146cd6a6acSopenharmony_ci 156cd6a6acSopenharmony_ci- The call arguments 166cd6a6acSopenharmony_ci 176cd6a6acSopenharmony_ci- The parent namespaces of the macro being called (if any) with the exception of the global namespace. 186cd6a6acSopenharmony_ci 196cd6a6acSopenharmony_ci- The parent namespaces of the call (if any) with the exception of the global namespace. 206cd6a6acSopenharmony_ci 216cd6a6acSopenharmony_ci- The global namespace 226cd6a6acSopenharmony_ci 236cd6a6acSopenharmony_ci**Statement definition:** 246cd6a6acSopenharmony_ci 256cd6a6acSopenharmony_ci```secil 266cd6a6acSopenharmony_ci (call macro_id [(param ...)]) 276cd6a6acSopenharmony_ci``` 286cd6a6acSopenharmony_ci 296cd6a6acSopenharmony_ci**Where:** 306cd6a6acSopenharmony_ci 316cd6a6acSopenharmony_ci<table> 326cd6a6acSopenharmony_ci<colgroup> 336cd6a6acSopenharmony_ci<col width="25%" /> 346cd6a6acSopenharmony_ci<col width="75%" /> 356cd6a6acSopenharmony_ci</colgroup> 366cd6a6acSopenharmony_ci<tbody> 376cd6a6acSopenharmony_ci<tr class="odd"> 386cd6a6acSopenharmony_ci<td align="left"><p><code>call</code></p></td> 396cd6a6acSopenharmony_ci<td align="left"><p>The <code>call</code> keyword.</p></td> 406cd6a6acSopenharmony_ci</tr> 416cd6a6acSopenharmony_ci<tr class="even"> 426cd6a6acSopenharmony_ci<td align="left"><p><code>macro_id</code></p></td> 436cd6a6acSopenharmony_ci<td align="left"><p>The identifier of the <code>macro</code> to be instantiated.</p></td> 446cd6a6acSopenharmony_ci</tr> 456cd6a6acSopenharmony_ci<tr class="odd"> 466cd6a6acSopenharmony_ci<td align="left"><p><code>param</code></p></td> 476cd6a6acSopenharmony_ci<td align="left"><p>Zero or more parameters that are passed to the macro.</p></td> 486cd6a6acSopenharmony_ci</tr> 496cd6a6acSopenharmony_ci</tbody> 506cd6a6acSopenharmony_ci</table> 516cd6a6acSopenharmony_ci 526cd6a6acSopenharmony_ci**Example:** 536cd6a6acSopenharmony_ci 546cd6a6acSopenharmony_ciSee the [`macro`](cil_call_macro_statements.md#macro) statement for an example. 556cd6a6acSopenharmony_ci 566cd6a6acSopenharmony_cimacro 576cd6a6acSopenharmony_ci----- 586cd6a6acSopenharmony_ci 596cd6a6acSopenharmony_ciDeclare a macro in the current namespace with its associated parameters. The macro identifier is used by the [`call`](cil_call_macro_statements.md#call) statement to instantiate the macro and resolve any parameters. The call statement may be within the body of a macro. 606cd6a6acSopenharmony_ci 616cd6a6acSopenharmony_ci[`tunable`](cil_conditional_statements.md#tunable), [`in`](cil_container_statements.md#in), [`block`](cil_container_statements.md#block), [`blockinherit`](cil_container_statements.md#blockinherit), [`blockabstract`](cil_container_statements.md#blockabstract), and other [`macro`](cil_call_macro_statements.md#macro) statements are not allowed in [`macro`](cil_call_macro_statements.md#macro) blocks. 626cd6a6acSopenharmony_ci 636cd6a6acSopenharmony_ciDuplicate [`macro`](cil_call_macro_statements.md#macro) declarations in the same namespace will normally cause an error, but inheriting a macro into a namespace (with [`blockinherit`](cil_container_statements.md#blockinherit)) that already has a macro with the same name will only result in a warning message and not cause an error. This behavior allows inherited macros to be overridden with local ones. 646cd6a6acSopenharmony_ci 656cd6a6acSopenharmony_ci**Statement definition:** 666cd6a6acSopenharmony_ci 676cd6a6acSopenharmony_ci```secil 686cd6a6acSopenharmony_ci (macro macro_id ([(param_type param_id) ...]) 696cd6a6acSopenharmony_ci cil_statements 706cd6a6acSopenharmony_ci ... 716cd6a6acSopenharmony_ci ) 726cd6a6acSopenharmony_ci``` 736cd6a6acSopenharmony_ci 746cd6a6acSopenharmony_ci**Where:** 756cd6a6acSopenharmony_ci 766cd6a6acSopenharmony_ci<table> 776cd6a6acSopenharmony_ci<colgroup> 786cd6a6acSopenharmony_ci<col width="25%" /> 796cd6a6acSopenharmony_ci<col width="75%" /> 806cd6a6acSopenharmony_ci</colgroup> 816cd6a6acSopenharmony_ci<tbody> 826cd6a6acSopenharmony_ci<tr class="odd"> 836cd6a6acSopenharmony_ci<td align="left"><p><code>macro</code></p></td> 846cd6a6acSopenharmony_ci<td align="left"><p>The <code>macro</code> keyword.</p></td> 856cd6a6acSopenharmony_ci</tr> 866cd6a6acSopenharmony_ci<tr class="even"> 876cd6a6acSopenharmony_ci<td align="left"><p><code>macro_id</code></p></td> 886cd6a6acSopenharmony_ci<td align="left"><p>The <code>macro</code> identifier.</p></td> 896cd6a6acSopenharmony_ci</tr> 906cd6a6acSopenharmony_ci<tr class="odd"> 916cd6a6acSopenharmony_ci<td align="left"><p><code>param_type</code></p></td> 926cd6a6acSopenharmony_ci<td align="left"><p>Zero or more parameters that are passed to the macro. The <code>param_type</code> is a keyword used to determine the declaration type (e.g. <code>type</code>, <code>class</code>, <code>categoryset</code>).</p> 936cd6a6acSopenharmony_ci<p>The list of valid <code>param_type</code> entries are: <code>type</code>, <code>typealias</code>, <code>role</code>, <code>user</code>, <code>sensitivity</code>, <code>sensitivityalias</code>, <code>category</code>, <code>categoryalias</code>, <code>categoryset</code> (named or anonymous), <code>level</code> (named or anonymous), <code>levelrange</code> (named or anonymous), <code>class</code>, <code>classpermission</code> (named or anonymous), <code>ipaddr</code> (named or anonymous), <code>name</code> (a string), <code>classmap</code></p></td> 946cd6a6acSopenharmony_ci</tr> 956cd6a6acSopenharmony_ci<tr class="even"> 966cd6a6acSopenharmony_ci<td align="left"><p><code>param_id</code></p></td> 976cd6a6acSopenharmony_ci<td align="left"><p>The parameter identifier used to reference the entry within the macro body (e.g. <code>ARG1</code>).</p></td> 986cd6a6acSopenharmony_ci</tr> 996cd6a6acSopenharmony_ci<tr class="odd"> 1006cd6a6acSopenharmony_ci<td align="left"><p><code>cil_statement</code></p></td> 1016cd6a6acSopenharmony_ci<td align="left"><p>Zero or more valid CIL statements.</p></td> 1026cd6a6acSopenharmony_ci</tr> 1036cd6a6acSopenharmony_ci</tbody> 1046cd6a6acSopenharmony_ci</table> 1056cd6a6acSopenharmony_ci 1066cd6a6acSopenharmony_ci**Examples:** 1076cd6a6acSopenharmony_ci 1086cd6a6acSopenharmony_ciThis example will instantiate the `binder_call` macro in the calling namespace (`my_domain`) and replace `ARG1` with `appdomain` and `ARG2` with `binderservicedomain`: 1096cd6a6acSopenharmony_ci 1106cd6a6acSopenharmony_ci```secil 1116cd6a6acSopenharmony_ci (block my_domain 1126cd6a6acSopenharmony_ci (call binder_call (appdomain binderservicedomain)) 1136cd6a6acSopenharmony_ci ) 1146cd6a6acSopenharmony_ci 1156cd6a6acSopenharmony_ci (macro binder_call ((type ARG1) (type ARG2)) 1166cd6a6acSopenharmony_ci (allow ARG1 ARG2 (binder (call transfer))) 1176cd6a6acSopenharmony_ci (allow ARG2 ARG1 (binder (transfer))) 1186cd6a6acSopenharmony_ci (allow ARG1 ARG2 (fd (use))) 1196cd6a6acSopenharmony_ci ) 1206cd6a6acSopenharmony_ci``` 1216cd6a6acSopenharmony_ci 1226cd6a6acSopenharmony_ciThis example does not pass any parameters to the macro but adds a [`type`](cil_type_statements.md#type) identifier to the current namespace: 1236cd6a6acSopenharmony_ci 1246cd6a6acSopenharmony_ci```secil 1256cd6a6acSopenharmony_ci (block unconfined 1266cd6a6acSopenharmony_ci (call add_type) 1276cd6a6acSopenharmony_ci .... 1286cd6a6acSopenharmony_ci 1296cd6a6acSopenharmony_ci (macro add_type () 1306cd6a6acSopenharmony_ci (type exec) 1316cd6a6acSopenharmony_ci ) 1326cd6a6acSopenharmony_ci ) 1336cd6a6acSopenharmony_ci``` 1346cd6a6acSopenharmony_ci 1356cd6a6acSopenharmony_ciThis example passes an anonymous and named IP address to the macro: 1366cd6a6acSopenharmony_ci 1376cd6a6acSopenharmony_ci```secil 1386cd6a6acSopenharmony_ci (ipaddr netmask_1 255.255.255.0) 1396cd6a6acSopenharmony_ci (context netlabel_1 (system.user object_r unconfined.object low_low)) 1406cd6a6acSopenharmony_ci 1416cd6a6acSopenharmony_ci (call build_nodecon ((192.168.1.64) netmask_1)) 1426cd6a6acSopenharmony_ci 1436cd6a6acSopenharmony_ci (macro build_nodecon ((ipaddr ARG1) (ipaddr ARG2)) 1446cd6a6acSopenharmony_ci (nodecon ARG1 ARG2 netlabel_1) 1456cd6a6acSopenharmony_ci ) 1466cd6a6acSopenharmony_ci``` 147