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         *  Special Error_Block used when the caller does not want to check
   338         *  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         *  Special Error_Block that terminates the application in case of an error
   352         *
   353         *  This constant has the same effect as passing `NULL` in place of an
   354         *  `Error_Block`. If an error is raised when `Error_ABORT` is passed, the
   355         *  application terminates regardless of `{@link #policy Error_policy}`.
   356         */
   357        const Block ABORT;
   358    
   359        /*!
   360         *  ======== PolicyFxn ========
   361         *  Error policy function signature
   362         *
   363         *  @a(Parameters)
   364         *  A policy function is passed the following parameters:
   365         *  @p(dlist)
   366         *      - `eb`
   367         *        A pointer to an `{@link #Block Error_Block}` structure to be
   368         *        initialized using the subsequent arguments.  This pointer may 
   369         *        be `NULL`.
   370         *      - `modId`
   371         *        The module ID of the module calling
   372         *        `{@link #raise Error_raise()}`
   373         *      - `fileName`
   374         *        A string naming the source file which made the call to
   375         *        `{@link #raise Error_raise()}`
   376         *      - `lineNumber`
   377         *        An integer line number within the file named above where
   378         *        the call `{@link #raise Error_raise()}` occured
   379         *      - `errId`
   380         *        The `{@link #Id Error_Id}` of the error being raised
   381         *      - `arg1` and `arg2`
   382         *        Two `IArg` arguments associated with the error being raised
   383         *  @p
   384         */
   385        typedef Void (*PolicyFxn)(Block *, Types.ModuleId, CString, Int, Id,
   386                                  IArg, IArg);
   387    
   388        /*!
   389         *  ======== policyFxn ========
   390         *  Error handler function
   391         *
   392         *  This function is called to handle all raised errors but, unlike
   393         *  `{@link raiseHook}`, this function is responsible for completely
   394         *  handling the error (including calling `{@link #raiseHook raiseHook}`
   395         *  with an appropriately initialized `{@link #Block Error_Block}`, if
   396         *  `raiseHook` functionality is required).
   397         *
   398         *  The default value is a function which, in addition to calling
   399         *  `raiseHook` with an initialized `Error_Block` structure, logs the
   400         *  error using this module's logger.
   401         *
   402         *  Alternately, `{@link #policySpin}`, which simply loops
   403         *  indefinitely, can be used to minimize target footprint.  Note, this
   404         *  function does NOT call `raiseHook`, and also ignores
   405         *  `{@link Error#policy Error.policy}`.
   406         *
   407         *  The third implementation, `{@link #policyMin}` finds a middle ground
   408         *  between the two implementations above in terms of memory footprint and
   409         *  the available error information. Only the `{@link #Id Error_Id}` of the
   410         *  error being raised is available in the resulting `Error_Block`,
   411         *  `raiseHook` is not invoked, but `{@link Error#policy Error.policy}` is
   412         *  observed.
   413         */
   414        config PolicyFxn policyFxn = Error.policyDefault;
   415    
   416        /*!
   417         *  ======== E_generic ========
   418         *  Generic error
   419         *
   420         *  This error takes advantage of the $S specifier to allow for recursive
   421         *  formatting of the error message passed to error raise.
   422         *
   423         *  For example, the following is possible:
   424         *  @p(code)
   425         *  Error_raise(eb, Error_E_generic, "Error occurred, code: %d", code);
   426         *  @p
   427         *
   428         *  @see System#extendedFormats
   429         *  @see System#printf
   430         */
   431        config Id E_generic = {msg: "%$S"};
   432    
   433        /*!
   434         *  ======== E_memory ========
   435         *  Out of memory error
   436         *
   437         *  The first parameter must be the heap instance handle. The second
   438         *  parameter is the size of the object for which the allocation failed.
   439         */
   440        config Id E_memory = {msg: "out of memory: heap=0x%x, size=%u"}; 
   441    
   442        /*!
   443         *  ======== E_msgCode ========
   444         *  Generic error that displays a string and a numeric value
   445         */
   446        config Id E_msgCode = {msg: "%s 0x%x"}; 
   447    
   448        /*!
   449         *  ======== policy ========
   450         *  System-wide error handling policy
   451         *
   452         *  You can use this parameter to decide at the configuration time what
   453         *  happens when an error is raised. The program can either call
   454         *  `System_abort()` or return back to the caller. The implementations of
   455         *  `{@link Error#policyFxn Error.policyFxn}` should consider this
   456         *  parameter, but some implementations may not do so to save the memory
   457         *  footprint (`Error_policySpin`, for example).
   458         * 
   459         */
   460        config Policy policy = UNWIND;
   461    
   462        /*!
   463         *  ======== raiseHook ========
   464         *  The function to call whenever an error is raised
   465         *
   466         *  If set to a non-`null` value, the referenced function is always
   467         *  called when an error is raised, even if the `Error` policy is
   468         *  `{@link #Policy TERMINATE}`.  In rare cases, it is possible that a
   469         *  raised error does not trigger a call to `raiseHook`; see
   470         *  `{@link #maxDepth}`.
   471         *
   472         *  Regardless of the current policy in use, raising an error by
   473         *  calling `{@link #raise Error_raise}` will always invoke the
   474         *  error raise hook function assigned to the
   475         *  `{@link #raiseHook Error.raiseHook}` configuration parameter, if the
   476         *  default `{@link Error#policyFxn Error.policyFxn}` implementation is
   477         *  used.
   478         *
   479         *
   480         *  By default, this function is set to `{@link #print Error_print}`
   481         *  which causes the error to be formatted and output via
   482         *  `{@link xdc.runtime.System#aprintf System_printf}`.  Setting this
   483         *  configuration parameter to `null` indicates that no function hook
   484         *  should be called.
   485         *
   486         *  @see #maxDepth
   487         *  @see #HookFxn
   488         *  @see #print
   489         */
   490        config HookFxn raiseHook = Error.print;
   491    
   492        /*!
   493         *  ======== maxDepth ========
   494         *  Maximum number of concurrent calls to `{@link #raiseHook}`
   495         *
   496         *  To prevent errors that occur in the raiseHook function from
   497         *  causing an infinite recursion, the maximum number of concurrent
   498         *  calls to `{@link #raiseHook}` is limited by `Error_maxDepth`.  If
   499         *  the number of concurrent calls exceeds `Error_maxDepth`, the
   500         *  `raiseHook` function is not called.
   501         *
   502         *  In multi-threaded systems, errors raised by separate threads may
   503         *  be detected as recursive calls to `raiseHook`.  So, setting
   504         *  `Error.maxDepth` to a small value may - in rare instances - result in
   505         *  `errorHook` not being called for some raised errors.
   506         *
   507         *  If it is important that all raised errors trigger a call to the
   508         *  `raiseHook` function, set `Error.maxDepth` to an impossibly large
   509         *  number (0xffff) and either ensure that the raise hook never calls a
   510         *  function that can raise an error or add checks in `raiseHook` to
   511         *  protect against "double faults".
   512         */
   513        config UInt16 maxDepth = 16;
   514    
   515        /*!
   516         *  ======== check ========
   517         *  Return TRUE if an error was raised
   518         *
   519         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   520         *
   521         *  @a(returns)
   522         *  If `eb` is non-`NULL` and `{@link #policy Error.policy} == UNWIND` and
   523         *  an error was raised on `eb`, this function returns `TRUE`.  Otherwise,
   524         *  it returns `FALSE`.
   525         */
   526        Bool check(Block *eb);
   527    
   528        /*!
   529         *  ======== getData ========
   530         *  Get an error's argument list
   531         *
   532         *  @param(eb)      non-`NULL` pointer to an `Error_Block`
   533         *
   534         *  @a(returns)
   535         *  `getData` returns an array of type `{@link #Data}` with
   536         *  `{@link #NUMARGS}` elements containing the arguments provided
   537         *  at the time the error was raised.
   538         *
   539         *  @see #raise
   540         */
   541        Data *getData(Block *eb);
   542    
   543        /*!
   544         *  ======== getCode ========
   545         *  Get an error's code
   546         *
   547         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   548         *
   549         *  @a(returns)
   550         *  `getCode` returns the error code associated with this error block.
   551         *
   552         *  @see #raise
   553         *  @see #Desc
   554         */
   555        UInt16 getCode(Block *eb);
   556    
   557        /*!
   558         *  ======== getId ========
   559         *  Get an error's id
   560         *
   561         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   562         *
   563         *  @a(Warning)
   564         *  `Error_Id` values may vary among different configurations
   565         *  of an application.  For example, the addition of a new module to a
   566         *  program may result in a different absolute value for
   567         *  `{@link #E_generic}`.  If you need error numbers that remain
   568         *  invariant, use the user definable `{@link #Desc Desc.code}` field.
   569         *
   570         *  @see #raise
   571         *  @see #Desc
   572         */
   573        Id getId(Block *eb);
   574    
   575        /*!
   576         *  ======== getMsg ========
   577         *  Get an error's "printf" format string
   578         *
   579         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   580         *
   581         *  @see #raise
   582         *  @see #Desc
   583         */
   584        CString getMsg(Block *eb);
   585    
   586        /*!
   587         *  ======== getSite ========
   588         *  Get an error's call site info
   589         *
   590         *  @param(eb) non-`NULL` pointer to an `Error_Block`
   591         *
   592         *  @a(returns)
   593         *  `getSite` returns a pointer to an initialized
   594         *  `{@link Types#Site Types.Site}` structure.  However, in the
   595         *  event that the call site was compiled with `xdc_FILE` defined to
   596         *  be `NULL` (to minimize string space overhead) the `file`
   597         *  field may be set to `NULL`.
   598         *
   599         *  @see #raise
   600         *  @see #Desc
   601         */
   602        Types.Site *getSite(Block *eb);
   603    
   604        /*!
   605         *  ======== idToCode ========
   606         *  Extract the user's error code associated with an `Error_Id`
   607         *
   608         *  @param(id) `Error_Id` from which to extract the user defined
   609         *             code 
   610         *  @_nodoc
   611         */
   612        @Macro UInt16 idToCode(Id id);
   613    
   614        /*!
   615         *  ======== idToUid ========
   616         *  Extract the unique error id associated with an `Error_Id`
   617         *
   618         *  @param(id) `Error_Id` from which to extract the system unique
   619         *             id associated with the specified `Error_Id`
   620         *  @_nodoc
   621         */
   622        @Macro UInt16 idToUid(Id id);
   623    
   624        /*!
   625         *  ======== init ========
   626         *  Put an error block into its initial state
   627         *
   628         *  To ensure reliable error detection, clients must call `init` for
   629         *  an `Error_Block` prior to any use.
   630         *
   631         *  If the same Error Block is used multiple times, only the last error
   632         *  raised is retained.
   633         *
   634         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   635         *
   636         *      If `eb` is `NULL` this function simply returns.
   637         */
   638        Void init(Block *eb);
   639    
   640        /*!
   641         *  ======== print ========
   642         *  Print error using System.printf()
   643         *
   644         *  This function prints the error using `System_printf()`.  The output
   645         *  is on a single line terminated with a new line character and has the
   646         *  following form:
   647         *  @p(code)
   648         *      <site>: <file>, line <line_num>: <err_msg>
   649         *  @p
   650         *  where `<site>` is the module that raised the error, `<file>` and
   651         *  `<line_num>` are the file and line number of the containing the call
   652         *  site of the `Error_raise()`, and `<err_msg>` is the error message
   653         *  rendered with the arguments associated with the error.
   654         *
   655         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   656         *
   657         *      If `eb` is `Error_ABORT` or `Error_IGNORE`, this function simply
   658         *      returns with no output.
   659         *
   660         *  @a(Warning)
   661         *  This function is not protected by a gate and, as a result,
   662         *  if two threads call this method concurrently, the output of the two
   663         *  calls will be intermingled.  To prevent intermingled error output,
   664         *  you can either wrap all calls to this method with an appropriate
   665         *  `Gate_enter`/`Gate_leave` pair or simply ensure that only one
   666         *  thread in the system ever calls this method.
   667         */
   668        Void print(Block *eb);
   669    
   670        /*!
   671         *  ======== policyDefault ========
   672         *  Default implementation of the policyFxn
   673         *
   674         *  This function is the implementation which is plugged in by default to
   675         *  the `{@link #policyFxn}`. It processes the error and logs it before
   676         *  returning to the caller or aborting - depending on the error policy
   677         *  `{@link #policy}`.
   678         */
   679        Void policyDefault(Block *eb, Types.ModuleId mod, CString file, Int line,
   680            Id id, IArg arg1, IArg arg2);
   681    
   682        /*!
   683         *  ======== policyMin ========
   684         *  Implementation of the policyFxn with a smaller footprint
   685         *
   686         *  This function is a compromise between a debug-friendly
   687         *  `{@link #policyDefault}`, which offers more details about any raised
   688         *  errors, but requires a larger footprint, and `{@link #policySpin}`,
   689         *  which is small but does not display any debug information.
   690         *
   691         *  This function returns to the caller, unless `{@link #policy}` is set to
   692         *  `TERMINATE`, or the `Error_Block` passed to it is `NULL`. If it returns,
   693         *  the only information available in the returned `Error_Block` is the
   694         *  error ID.
   695         */
   696        Void policyMin(Block *eb, Types.ModuleId mod, CString file, Int line,
   697            Id id, IArg arg1, IArg arg2);
   698    
   699        /*!
   700         *  ======== policySpin ========
   701         *  Lightweight implementation of the policyFxn
   702         *
   703         *  This function is a lightweight alternative  which can be plugged in to
   704         *  the `{@link #policyFxn}`. It just loops infinitely.
   705         *
   706         *  @a(Warning)
   707         *  This function does not call `{@link #raiseHook}` and never returns to
   708         *  the caller.  As a result, ANY error raised by the application will cause
   709         *  it to indefinitly hang.
   710         */
   711        Void policySpin(Block *eb, Types.ModuleId mod, CString file, Int line,
   712            Id id, IArg arg1, IArg arg2);
   713    
   714        /*!
   715         *  ======== raise ========
   716         *  Raise an error
   717         *
   718         *  This function is used to raise an `Error` by writing call site,
   719         *  error ID, and error argument information into the `Error_Block`
   720         *  pointed to by `eb`.
   721         *
   722         *  If `Error_raise` is called more than once on an `Error_Block` object,
   723         *  the previous error information is overwritten; only the last error
   724         *  is retained in the `Error_Block` object.
   725         *
   726         *  In all cases, any configured `{@link #raiseHook Error.raiseHook}`
   727         *  function is called with a non-`NULL` pointer to a fully
   728         *  initialized `Error_Block` object.
   729         *
   730         *  @param(eb) pointer to an `Error_Block`, `Error_ABORT` or `Error_IGNORE`
   731         *
   732         *      If `eb` is `Error_ABORT` or
   733         *      `{@link #policy Error.policy} == TERMINATE`,
   734         *      this function does not return to the caller; after calling any
   735         *      configured `{@link #raiseHook}`, `System_abort` is called with the
   736         *      string `"xdc.runtime.Error.raise: terminating execution\n"`.
   737         *
   738         *  @param(id) the error to raise
   739         *
   740         *      This pointer identifies the class of error being raised; the error
   741         *      class indicates how to interpret any subsequent arguments passed to
   742         *      `{@link #raise}`.
   743         *
   744         *  @param(arg1) error's first argument
   745         *
   746         *      The argument interpreted by the first control character
   747         *      in the error message format string. It is ignored if not needed.
   748         *
   749         *  @param(arg2) error's second argument
   750         *
   751         *      The argument interpreted by the second control character
   752         *      in the error message format string. It is ignored if not needed.
   753         */
   754        @Macro Void raise(Block *eb, Id id, IArg arg1, IArg arg2);
   755    
   756        /*! @_nodoc */
   757        Void raiseX(Block *eb, Types.ModuleId mod, CString file, Int line,
   758            Id id, IArg arg1, IArg arg2);
   759    
   760        /*! @_nodoc EXPERIMENTAL */
   761        Void setX(Block *eb, Types.ModuleId mod, CString file, Int line,
   762            Id id, IArg arg1, IArg arg2);
   763    
   764    internal:
   765    
   766        struct Module_State {
   767            UInt16      count;
   768        };
   769    
   770    }
   771    /*
   772     *  @(#) xdc.runtime; 2, 1, 0,0; 2-8-2017 14:15:54; /db/ztree/library/trees/xdc/xdc-D05/src/packages/
   773     */
   774