1    /* 
     2     *  Copyright (c) 2008-2017 Texas Instruments Incorporated
     3     *  This program and the accompanying materials are made available under the
     4     *  terms of the Eclipse Public License v1.0 and Eclipse Distribution License
     5     *  v. 1.0 which accompanies this distribution. The Eclipse Public License is
     6     *  available at http://www.eclipse.org/legal/epl-v10.html and the Eclipse
     7     *  Distribution License is available at
     8     *  http://www.eclipse.org/org/documents/edl-v10.php.
     9     *
    10     *  Contributors:
    11     *      Texas Instruments - initial implementation
    12     * */
    13    /*
    14     *  ======== Error.xdc ========
    15     */
    16    
    17    /*!
    18     *  ======== Error ========
    19     *  Runtime error manager
    20     *
    21     *  The `Error` module provides mechanisms for raising, checking, and
    22     *  handling errors in a program. At the configuration time, you can use the
    23     *  parameters `{@link Error#policy Error.policy}`,
    24     *  `{@link Error#policyFxn Error.policyFxn}` and
    25     *  `{@link Error#raiseHook Error.raiseHook}` to specify what happens when an
    26     *  error takes place. You can control how much debugging information is
    27     *  available in that case, while also controlling the memory footprint that the
    28     *  `Error' module adds to the program.
    29     *
    30     *  Module producers use this module to define specific error types and
    31     *  reference these when raising an error. Each error type has a custom error
    32     *  message and can be parameterized with up to `{@link #NUMARGS}` arguments. A
    33     *  generic error type is provided for raising errors when not in a module.
    34     *
    35     *  Use the `{@link #check Error_check()}` function in your application or
    36     *  module to determine if an error has been raised in a function that takes an
    37     *  `{@link #Block Error_Block}` as an argument. It is important to understand
    38     *  that it is the caller's responsibility to check the error block after
    39     *  calling such a function. Otherwise, a raised error may go undetected, which
    40     *  could compromise the integrity of the system. For example:
    41     *
    42     *  @p(code)
    43     *  Task_create(..., &eb);
    44     *
    45     *  if (Error_check(&eb)) {
    46     *      ...an error has been raised...
    47     *  }
    48     *  @p
    49     *
    50     *  The function assigned to the parameter
    51     *  `{@link Error#policyFxn Error.policyFxn}` is the central part of the
    52     *  error handling mechanism in this module. Most of the users will either leave
    53     *  this parameter at its default value, or select one of the alternative
    54     *  implementations that are included with the `Error` module. However, this
    55     *  configuration parameter also allows users to completely take over the error
    56     *  handling by setting this parameter to their own implementation. In that
    57     *  case, we recommend that users first review the included implementations,
    58     *  and base their implementation on one of these function. The included
    59     *  implementations are `{@link #policyDefault}`, `{@link #policyMin}`, and
    60     *  `{@link #policySpin}`.
    61     *
    62     *  The `{@link #raiseHook Error.raiseHook}` configuration parameter allows
    63     *  a configured function to be invoked when an error is raised.
    64     *  This function is invoked from the default implementation of
    65     *  `{@link Error#policyFxn Error.policyFxn}`. Therefore, if a different
    66     *  implementation of `Error.policyFxn` is used, the function specified by
    67     *  `Error.raiseHook` may or may not be called.
    68     *  This function is passed a pointer to the error's error block and makes it
    69     *  easy to manage all errors from a common point. For example, you can
    70     *  trap any error (fatal or not) by simply setting a breakpoint in this
    71     *  function. You can use the following functions to extract information
    72     *  from an error block.
    73     *
    74     *  @p(blist)
    75     *  - `{@link #getData Error_getData()}`
    76     *  - `{@link #getCode Error_getCode()}`
    77     *  - `{@link #getId Error_getId()}`
    78     *  - `{@link #getMsg Error_getMsg()}`
    79     *  - `{@link #getSite Error_getSite()}`
    80     *  @p
    81     *
    82     *  The Error module provides facilities for handling errors, but the Log
    83     *  module also provides features for logging error events. These are separate
    84     *  concepts; however, to ensure that users do not have to both raise and log
    85     *  an error, the Error module will automatically log an error event when one
    86     *  is raised. The Error module logs the standard {@link Log#L_error} event,
    87     *  passing it the error message and arguments.
    88     *
    89     *  The error event is logged to the Error module's logger using the Error
    90     *  module's diags mask. Logging of errors is enabled by default in the diags
    91     *  mask, but the event will not be logged unless a logger is configured for
    92     *  the Error module as well.
    93     *
    94     *  To make the error event appear as though it is coming from the module which
    95     *  called Error_raise, the event is logged with the caller's module id and
    96     *  with the caller's call site information.
    97     *
    98     *  @a(Examples)
    99     *  Example 1: The following example shows how a module, named ModA,
   100     *  defines a custom error type and shows how this error is raised by
   101     *  the module. The module defines an `Id` of `E_notEven` in its module
   102     *  specification file (in this case, `ModA.xdc`). The error's message
   103     *  string takes only one argument. The module also defines a `mayFail()`
   104     *  function that takes an error block. In the module's C source file,
   105     *  the function checks for the error condition and raises the error if
   106     *  needed.
   107     *
   108     *  This is part of ModA's XDC specification file for the module:
   109     *
   110     *  @p(code)
   111     *  config xdc.runtime.Error.Id E_notEven = {
   112     *      msg: "expected an even number (%d)"
   113     *  };
   114     *
   115     *  Void mayFail(Int x, xdc.runtime.Error.Block *eb);
   116     *  @p
   117     *
   118     *  This is part of the C code for the module:
   119     *
   120     *  @p(code)
   121     *  Void ModA_mayFail(Int x, Error_Block *eb)
   122     *  {
   123     *      if ((x % 2) != 0) {
   124     *          Error_raise(eb, ModA_E_notEven, x, 0);
   125     *          ...add error handling code here...
   126     *          return;
   127     *      }
   128     *      ...
   129     *  }
   130     *  @p
   131     *
   132     *  @p(html)
   133     *  <hr />
   134     *  @p
   135     *
   136     *  Example 2: The following C code supplies an error block to a function
   137     *  that requires one and tests the error block to see if the function
   138     *  raised an error. Note that an error block must be initialized before
   139     *  it can be used and same error block may be passed to several functions.
   140     *
   141     *  @p(code)
   142     *  #include <xdc/runtime/Error.h>
   143     *  #include <ti/sysbios/knl/Task.h>
   144     *  Error_Block eb;
   145     *  Task_Handle tsk;
   146     *
   147     *  Error_init(&eb);
   148     *  tsk = Task_create(..., &eb);
   149     *
   150     *  if (Error_check(&eb)) {
   151     *      ...an error has been raised...
   152     *  }
   153     *  @p
   154     *
   155     *  @p(html)
   156     *  <hr />
   157     *  @p
   158     *
   159     *  Example 3: The following C code shows that you may pass a special constant
   160     *  `Error_ABORT` in place of an error block to a function requiring an error
   161     *  block. In this case, if the function raises an error, the program is aborted
   162     *  (via `{@link System#abort xdc_runtime_System_abort()}`), thus execution
   163     *  control will never return to the caller.
   164     *
   165     *  @p(code)
   166     *  #include <xdc/runtime/Error.h>
   167     *  #include <ti/sysbios/knl/Task.h>
   168     *
   169     *  tsk = Task_create(..., Error_ABORT);
   170     *  ...will never get here if an error was raised in Task_create...
   171     *  @p
   172     *
   173     *  @p(html)
   174     *  <hr />
   175     *  @p
   176     *
   177     *  Example 4: The following C code shows that you may pass a special constant
   178     *  `Error_IGNORE` in place of an error block to a function requiring an error
   179     *  block. The purpose of this constant is to avoid allocating an error block on
   180     *  stack in the use case where the caller is not checking the error block after
   181     *  the call returns.
   182     *  In this example, the caller only checks the returned value but not the error
   183     *  block. If the function raises an error, the program will return to the
   184     *  caller, assuming `Error_policy` is set to `{@link #Policy UNWIND}`.
   185     *
   186     *  @p(code)
   187     *  #include <xdc/runtime/Error.h>
   188     *  #include <ti/sysbios/knl/Task.h>
   189     *
   190     *  tsk = Task_create(..., Error_IGNORE);
   191     *  if (tsk != NULL) {
   192     *      ...
   193     *  }
   194     *  @p
   195     *
   196     *  @p(html)
   197     *  <hr />
   198     *  @p
   199     *
   200     *  Example 5: The following C code shows how to write a function that
   201     *  is not part of a module and that takes an error block and raises
   202     *  the generic error type provided by the Error module. Note, if the
   203     *  caller passes `Error_ABORT` for the error block or if the error policy is
   204     *  `{@link #Policy TERMINATE}`, then the call to
   205     *  `{@link #raise Error_raise()}` will call
   206     *  `{@link System#abort xdc_runtime_System_abort()}` and never return.
   207     *
   208     *  @p(code)
   209     *  #include <xdc/runtime/Error.h>
   210     *
   211     *  Void myFunc(..., Error_Block *eb)
   212     *  {
   213     *      ...
   214     *
   215     *      if (...error condition detected...) {
   216     *          String  myErrorMsg = "my custom error message";
   217     *          Error_raise(eb, Error_E_generic, myErrorMsg, 0);
   218     *          ...add error handling code here...
   219     *          return;
   220     *      }
   221     *  }
   222     *  @p
   223     */
   224    @DirectCall
   225    @Template("./Error.xdt")
   226    
   227    module Error {
   228    
   229        /*!
   230         *  ======== Policy ========
   231         *  Error handling policies
   232         *
   233         *  These constants are assigned to `{@link Error#policy Error.policy}` to
   234         *  control the flow of the program when an error is raised.
   235         *
   236         *  @field(TERMINATE) All raised errors are fatal. A call to
   237         *  `{@link #raise Error_raise}` will never return to the caller. The
   238         *  program calls `System_abort` instead.
   239         *
   240         *  @field(UNWIND) Errors are returned to the caller. A call to
   241         *  `{@link #raise Error_raise}` will return back to the caller.
   242         */
   243        enum Policy {
   244            TERMINATE,
   245            UNWIND
   246        };
   247    
   248        /*!
   249         *  ======== Desc ========
   250         *  Error descriptor
   251         *
   252         *  Each type of error is defined with an error descriptor. This
   253         *  structure groups common information about the errors of this type.
   254         *
   255         *  @field(msg) The error message using a `printf` style format string, 
   256         *              but limited to `{@link #NUMARGS}` arguments.
   257         *              This format string together with the two arguments passed
   258         *              to `Error_raise`` are used to create a human readable
   259         *              error message.
   260         *
   261         *  @field(code) A user assignable code, 0 by default. The user may
   262         *              optionally set this field during config to give the
   263         *              error a well-known numeric code. 
   264         */
   265        metaonly struct Desc {
   266            String msg;
   267            UInt16 code;
   268        };
   269    
   270        /*!
   271         *  ======== Id ========
   272         *  Error identifier
   273         *
   274         *  Each type of error raised is defined with a metaonly
   275         *  `{@link Error#Desc}`.  An `Error_Id` is a 32-bit target value that
   276         *  encodes the information in the `Desc`.  Target programs use
   277         *  `Error_Id` values to "raise" and check for specific errors.
   278         *
   279         *  @a(Warning) `{@link #Id}` values may vary among different
   280         *  configurations of an application.  For example, the addition of a
   281         *  new module to a program may result in a different absolute value for
   282         *  `{@link #E_generic}`.  If you need error numbers that remain
   283         *  invariant, use the user definable `{@link #Desc Desc.code}` field.
   284         */
   285        @Encoded typedef Desc Id;
   286    
   287        /*!
   288         *  ======== HookFxn ========
   289         *  Function called whenever an error is raised
   290         *
   291         *  The first parameter and only parameter passed to this function is a
   292         *  pointer to an `Error_Block`.  Even if the client passes a `NULL` error
   293         *  block pointer to `{@link #raise Error_raise}`, this parameter passed 
   294         *  to this "hook" function is always `non-NULL`.
   295         */
   296        typedef Void (*HookFxn)(Block *);
   297    
   298        /*!
   299         *  ======== NUMARGS ========
   300         *  Maximum number of arguments supported by an error
   301         */
   302        const Int NUMARGS = 2;
   303    
   304        /*!
   305         *  ======== Data ========
   306         *  Error args
   307         *
   308         *  The two arguments (arg1, arg2) passed to `{@link #raise}` are 
   309         *  stored in one of these arrays within the associated Error_Block.
   310         *  To access these arguments use `{@link #getData}` to obtain a 
   311         *  pointer to the Error_Block's Data array.
   312         *
   313         *  @see #getData
   314         */
   315        struct Data {
   316            IArg arg[NUMARGS];
   317        }
   318    
   319        /*!
   320         *  ======== Block ========
   321         *  Error block
   322         *
   323         *  An opaque structure used to store information about errors once raised.
   324         *  This structure must be initialized via `{@link #init Error_init()}`
   325         *  before being used for the first time.
   326         */
   327        @Opaque struct Block {
   328            UInt16      unused;     /* for backward compatibility (was code) */
   329            Data        data;       /* arguments passed to raise() */
   330            Id          id;         /* id passed to raise() */
   331            CString     msg;        /* msg associated with id */
   332            Types.Site  site;       /* info about Error_raise call site */
   333        };
   334    
   335        /*!
   336         *  ======== IGNORE ========
   337         *  A pointer to a special Error_Block used when the caller does not want to
   338         *  check Error_Block
   339         *
   340         *  This constant should be used when the caller does not plan to check
   341         *  `Error_Block` after the call returns, but wants the call to return even
   342         *  in the case when an error is raised. `{@link #policy Error_policy}` is
   343         *  still in effect and the application will still terminate when an error
   344         *  is raised if `Error_policy` is not set to
   345         *  `{@link #Policy Error_UNWIND}`.
   346         */
   347        const Block IGNORE;
   348    
   349        /*!
   350         *  ======== ABORT ========
   351         *  A special Error_Block pointer that terminates the application in case of
   352         *  an error
   353         *
   354         *  This constant has the same effect as passing `NULL` in place of an
   355         *  `Error_Block`. If an error is raised when `Error_ABORT` is passed, the
   356         *  application terminates regardless of `{@link #policy Error_policy}`.
   357         */
   358        const Block ABORT;
   359    
   360        /*!
   361         *  ======== PolicyFxn ========
   362         *  Error policy function signature
   363         *
   364         *  @a(Parameters)
   365         *  A policy function is passed the following parameters:
   366         *  @p(dlist)
   367         *      - `eb`
   368         *        A pointer to an `{@link #Block Error_Block}` structure to be
   369         *        initialized using the subsequent arguments.  This pointer may 
   370         *        be `NULL`.
   371         *      - `modId`
   372         *        The module ID of the module calling
   373         *        `{@link #raise Error_raise()}`
   374         *      - `fileName`
   375         *        A string naming the source file which made the call to
   376         *        `{@link #raise Error_raise()}`
   377         *      - `lineNumber`
   378         *        An integer line number within the file named above where
   379         *        the call `{@link #raise Error_raise()}` occured
   380         *      - `errId`
   381         *        The `{@link #Id Error_Id}` of the error being raised
   382         *      - `arg1` and `arg2`
   383         *        Two `IArg` arguments associated with the error being raised
   384         *  @p
   385         */
   386        typedef Void (*PolicyFxn)(Block *, Types.ModuleId, CString, Int, Id,
   387                                  IArg, IArg);
   388    
   389        /*!
   390         *  ======== policyFxn ========
   391         *  Error handler function
   392         *
   393         *  This function is called to handle all raised errors but, unlike
   394         *  `{@link raiseHook}`, this function is responsible for completely
   395         *  handling the error (including calling `{@link #raiseHook raiseHook}`
   396         *  with an appropriately initialized `{@link #Block Error_Block}`, if
   397         *  `raiseHook` functionality is required).
   398         *
   399         *  The default value is a function which, in addition to calling
   400         *  `raiseHook` with an initialized `Error_Block` structure, logs the
   401         *  error using this module's logger.
   402         *
   403         *  Alternately, `{@link #policySpin}`, which simply loops
   404         *  indefinitely, can be used to minimize target footprint.  Note, this
   405         *  function does NOT call `raiseHook`, and also ignores
   406         *  `{@link Error#policy Error.policy}`.
   407         *
   408         *  The third implementation, `{@link #policyMin}` finds a middle ground
   409         *  between the two implementations above in terms of memory footprint and
   410         *  the available error information. Only the `{@link #Id Error_Id}` of the
   411         *  error being raised is available in the resulting `Error_Block`,
   412         *  `raiseHook` is not invoked, but `{@link Error#policy Error.policy}` is
   413         *  observed.
   414         */
   415        config PolicyFxn policyFxn = Error.policyDefault;
   416    
   417        /*!
   418         *  ======== E_generic ========
   419         *  Generic error
   420         *
   421         *  This error takes advantage of the $S specifier to allow for recursive
   422         *  formatting of the error message passed to error raise.
   423         *
   424         *  For example, the following is possible:
   425         *  @p(code)
   426         *  Error_raise(eb, Error_E_generic, "Error occurred, code: %d", code);
   427         *  @p
   428         *
   429         *  @see System#extendedFormats
   430         *  @see System#printf
   431         */
   432        config Id E_generic = {msg: "%$S"};
   433    
   434        /*!
   435         *  ======== E_memory ========
   436         *  Out of memory error
   437         *
   438         *  The first parameter must be the heap instance handle. The second
   439         *  parameter is the size of the object for which the allocation failed.
   440         */
   441        config Id E_memory = {msg: "out of memory: heap=0x%x, size=%u"}; 
   442    
   443        /*!
   444         *  ======== E_msgCode ========
   445         *  Generic error that displays a string and a numeric value
   446         */
   447        config Id E_msgCode = {msg: "%s 0x%x"}; 
   448    
   449        /*!
   450         *  ======== policy ========
   451         *  System-wide error handling policy
   452         *
   453         *  You can use this parameter to decide at the configuration time what
   454         *  happens when an error is raised. The program can either call
   455         *  `System_abort()` or return back to the caller. The implementations of
   456         *  `{@link Error#policyFxn Error.policyFxn}` should consider this
   457         *  parameter, but some implementations may not do so to save the memory
   458         *  footprint (`Error_policySpin`, for example).
   459         * 
   460         */
   461        config Policy policy = UNWIND;
   462    
   463        /*!
   464         *  ======== raiseHook ========
   465         *  The function to call whenever an error is raised
   466         *
   467         *  If set to a non-`null` value, the referenced function is always
   468         *  called when an error is raised, even if the `Error` policy is
   469         *  `{@link #Policy TERMINATE}`.  In rare cases, it is possible that a
   470         *  raised error does not trigger a call to `raiseHook`; see
   471         *  `{@link #maxDepth}`.
   472         *
   473         *  Regardless of the current policy in use, raising an error by
   474         *  calling `{@link #raise Error_raise}` will always invoke the
   475         *  error raise hook function assigned to the
   476         *  `{@link #raiseHook Error.raiseHook}` configuration parameter, if the
   477         *  default `{@link Error#policyFxn Error.policyFxn}` implementation is
   478         *  used.
   479         *
   480         *
   481         *  By default, this function is set to `{@link #print Error_print}`
   482         *  which causes the error to be formatted and output via
   483         *  `{@link xdc.runtime.System#aprintf System_printf}`.  Setting this
   484         *  configuration parameter to `null` indicates that no function hook
   485         *  should be called.
   486         *
   487         *  @see #maxDepth
   488         *  @see #HookFxn
   489         *  @see #print
   490         */
   491        config HookFxn raiseHook = Error.print;
   492    
   493        /*!
   494         *  ======== maxDepth ========
   495         *  Maximum number of concurrent calls to `{@link #raiseHook}`
   496         *
   497         *  To prevent errors that occur in the raiseHook function from
   498         *  causing an infinite recursion, the maximum number of concurrent
   499         *  calls to `{@link #raiseHook}` is limited by `Error_maxDepth`.  If
   500         *  the number of concurrent calls exceeds `Error_maxDepth`, the
   501         *  `raiseHook` function is not called.
   502         *
   503         *  In multi-threaded systems, errors raised by separate threads may
   504         *  be detected as recursive calls to `raiseHook`.  So, setting
   505         *  `Error.maxDepth` to a small value may - in rare instances - result in
   506         *  `errorHook` not being called for some raised errors.
   507         *
   508         *  If it is important that all raised errors trigger a call to the
   509         *  `raiseHook` function, set `Error.maxDepth` to an impossibly large
   510         *  number (0xffff) and either ensure that the raise hook never calls a
   511         *  function that can raise an error or add checks in `raiseHook` to
   512         *  protect against "double faults".
   513         */
   514        config UInt16 maxDepth = 16;
   515    
   516        /*!
   517         *  ======== check ========
   518         *  Return TRUE if an error was raised
   519         *
   520         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   521         *
   522         *  @a(returns)
   523         *  If `eb` is non-`NULL` and `{@link #policy Error.policy} == UNWIND` and
   524         *  an error was raised on `eb`, this function returns `TRUE`.  Otherwise,
   525         *  it returns `FALSE`.
   526         */
   527        Bool check(Block *eb);
   528    
   529        /*!
   530         *  ======== getData ========
   531         *  Get an error's argument list
   532         *
   533         *  @param(eb)      non-`NULL` pointer to an `Error_Block`
   534         *
   535         *  @a(returns)
   536         *  `getData` returns an array of type `{@link #Data}` with
   537         *  `{@link #NUMARGS}` elements containing the arguments provided
   538         *  at the time the error was raised.
   539         *
   540         *  @see #raise
   541         */
   542        Data *getData(Block *eb);
   543    
   544        /*!
   545         *  ======== getCode ========
   546         *  Get an error's code
   547         *
   548         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   549         *
   550         *  @a(returns)
   551         *  `getCode` returns the error code associated with this error block.
   552         *
   553         *  @see #raise
   554         *  @see #Desc
   555         */
   556        UInt16 getCode(Block *eb);
   557    
   558        /*!
   559         *  ======== getId ========
   560         *  Get an error's id
   561         *
   562         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   563         *
   564         *  @a(Warning)
   565         *  `Error_Id` values may vary among different configurations
   566         *  of an application.  For example, the addition of a new module to a
   567         *  program may result in a different absolute value for
   568         *  `{@link #E_generic}`.  If you need error numbers that remain
   569         *  invariant, use the user definable `{@link #Desc Desc.code}` field.
   570         *
   571         *  @see #raise
   572         *  @see #Desc
   573         */
   574        Id getId(Block *eb);
   575    
   576        /*!
   577         *  ======== getMsg ========
   578         *  Get an error's "printf" format string
   579         *
   580         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   581         *
   582         *  @see #raise
   583         *  @see #Desc
   584         */
   585        CString getMsg(Block *eb);
   586    
   587        /*!
   588         *  ======== getSite ========
   589         *  Get an error's call site info
   590         *
   591         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   592         *
   593         *  @a(returns)
   594         *  `getSite` returns a pointer to an initialized
   595         *  `{@link Types#Site Types.Site}` structure.  However, in the
   596         *  event that the call site was compiled with `xdc_FILE` defined to
   597         *  be `NULL` (to minimize string space overhead) the `file`
   598         *  field may be set to `NULL`.
   599         *
   600         *  @see #raise
   601         *  @see #Desc
   602         */
   603        Types.Site *getSite(Block *eb);
   604    
   605        /*!
   606         *  ======== idToCode ========
   607         *  Extract the user's error code associated with an `Error_Id`
   608         *
   609         *  @param(id) `Error_Id` from which to extract the user defined
   610         *             code 
   611         *  @_nodoc
   612         */
   613        @Macro UInt16 idToCode(Id id);
   614    
   615        /*!
   616         *  ======== idToUid ========
   617         *  Extract the unique error id associated with an `Error_Id`
   618         *
   619         *  @param(id) `Error_Id` from which to extract the system unique
   620         *             id associated with the specified `Error_Id`
   621         *  @_nodoc
   622         */
   623        @Macro UInt16 idToUid(Id id);
   624    
   625        /*!
   626         *  ======== init ========
   627         *  Put an error block into its initial state
   628         *
   629         *  To ensure reliable error detection, clients must call `init` for
   630         *  an `Error_Block` prior to any use.
   631         *
   632         *  If the same Error Block is used multiple times, only the last error
   633         *  raised is retained.
   634         *
   635         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   636         *
   637         *      If `eb` is `NULL` this function simply returns.
   638         */
   639        Void init(Block *eb);
   640    
   641        /*!
   642         *  ======== print ========
   643         *  Print error using System.printf()
   644         *
   645         *  This function prints the error using `System_printf()`.  The output
   646         *  is on a single line terminated with a new line character and has the
   647         *  following form:
   648         *  @p(code)
   649         *      <site>: <file>, line <line_num>: <err_msg>
   650         *  @p
   651         *  where `<site>` is the module that raised the error, `<file>` and
   652         *  `<line_num>` are the file and line number of the containing the call
   653         *  site of the `Error_raise()`, and `<err_msg>` is the error message
   654         *  rendered with the arguments associated with the error.
   655         *
   656         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   657         *
   658         *      If `eb` is `Error_ABORT` or `Error_IGNORE`, this function simply
   659         *      returns with no output.
   660         *
   661         *  @a(Warning)
   662         *  This function is not protected by a gate and, as a result,
   663         *  if two threads call this method concurrently, the output of the two
   664         *  calls will be intermingled.  To prevent intermingled error output,
   665         *  you can either wrap all calls to this method with an appropriate
   666         *  `Gate_enter`/`Gate_leave` pair or simply ensure that only one
   667         *  thread in the system ever calls this method.
   668         */
   669        Void print(Block *eb);
   670    
   671        /*!
   672         *  ======== policyDefault ========
   673         *  Default implementation of the policyFxn
   674         *
   675         *  This function is the implementation which is plugged in by default to
   676         *  the `{@link #policyFxn}`. It processes the error and logs it before
   677         *  returning to the caller or aborting - depending on the error policy
   678         *  `{@link #policy}`.
   679         */
   680        Void policyDefault(Block *eb, Types.ModuleId mod, CString file, Int line,
   681            Id id, IArg arg1, IArg arg2);
   682    
   683        /*!
   684         *  ======== policyMin ========
   685         *  Implementation of the policyFxn with a smaller footprint
   686         *
   687         *  This function is a compromise between a debug-friendly
   688         *  `{@link #policyDefault}`, which offers more details about any raised
   689         *  errors, but requires a larger footprint, and `{@link #policySpin}`,
   690         *  which is small but does not display any debug information.
   691         *
   692         *  This function returns to the caller, unless `{@link #policy}` is set to
   693         *  `TERMINATE`, or the `Error_Block` passed to it is `NULL`. If it returns,
   694         *  the only information available in the returned `Error_Block` is the
   695         *  error ID.
   696         */
   697        Void policyMin(Block *eb, Types.ModuleId mod, CString file, Int line,
   698            Id id, IArg arg1, IArg arg2);
   699    
   700        /*!
   701         *  ======== policySpin ========
   702         *  Lightweight implementation of the policyFxn
   703         *
   704         *  This function is a lightweight alternative  which can be plugged in to
   705         *  the `{@link #policyFxn}`. It just loops infinitely.
   706         *
   707         *  @a(Warning)
   708         *  This function does not call `{@link #raiseHook}` and never returns to
   709         *  the caller.  As a result, ANY error raised by the application will cause
   710         *  it to indefinitly hang.
   711         */
   712        Void policySpin(Block *eb, Types.ModuleId mod, CString file, Int line,
   713            Id id, IArg arg1, IArg arg2);
   714    
   715        /*!
   716         *  ======== raise ========
   717         *  Raise an error
   718         *
   719         *  This function is used to raise an `Error` by writing call site,
   720         *  error ID, and error argument information into the `Error_Block`
   721         *  pointed to by `eb`.
   722         *
   723         *  If `Error_raise` is called more than once on an `Error_Block` object,
   724         *  the previous error information is overwritten; only the last error
   725         *  is retained in the `Error_Block` object.
   726         *
   727         *  In all cases, any configured `{@link #raiseHook Error.raiseHook}`
   728         *  function is called with a non-`NULL` pointer to a fully
   729         *  initialized `Error_Block` object.
   730         *
   731         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   732         *
   733         *      If `eb` is `Error_ABORT` or
   734         *      `{@link #policy Error.policy} == TERMINATE`,
   735         *      this function does not return to the caller; after calling any
   736         *      configured `{@link #raiseHook}`, `System_abort` is called with the
   737         *      string `"xdc.runtime.Error.raise: terminating execution\n"`.
   738         *
   739         *  @param(id) the error to raise
   740         *
   741         *      This pointer identifies the class of error being raised; the error
   742         *      class indicates how to interpret any subsequent arguments passed to
   743         *      `{@link #raise}`.
   744         *
   745         *  @param(arg1) error's first argument
   746         *
   747         *      The argument interpreted by the first control character
   748         *      in the error message format string. It is ignored if not needed.
   749         *
   750         *  @param(arg2) error's second argument
   751         *
   752         *      The argument interpreted by the second control character
   753         *      in the error message format string. It is ignored if not needed.
   754         */
   755        @Macro Void raise(Block *eb, Id id, IArg arg1, IArg arg2);
   756    
   757        /*! @_nodoc */
   758        Void raiseX(Block *eb, Types.ModuleId mod, CString file, Int line,
   759            Id id, IArg arg1, IArg arg2);
   760    
   761        /*! @_nodoc EXPERIMENTAL */
   762        Void setX(Block *eb, Types.ModuleId mod, CString file, Int line,
   763            Id id, IArg arg1, IArg arg2);
   764    
   765    internal:
   766    
   767        struct Module_State {
   768            UInt16      count;
   769        };
   770    
   771    }
   772    /*
   773     *  @(#) xdc.runtime; 2, 1, 0,0; 11-14-2018 15:26:35; /db/ztree/library/trees/xdc/xdc-F05/src/packages/
   774     */
   775