20/202 TEE Internal API Specification – Public Release v1.0
Copyright 2011 GlobalPlatform Inc. All Rights Reserved.
The technology provided or described herein is subject to updates, revisions, and extensions by GlobalPlatform. Use of this
information is governed by the GlobalPlatform license agreement and any use inconsistent with that agreement is strictly
prohibited.
2.2 Error Handling
2.2.1 Normal Errors
The TEE Internal API functions usually return an error code of type TEE_Result to indicate errors to the
caller. This is used to denote “normal” run-time errors that the TA code is expected to catch and handle, such
as out-of-memory conditions or short buffers.
2.2.2 Programmer Errors
There are a number of conditions in this specification that can only occur as a result of Programmer Error,
i.e., they are triggered by incorrect use of the API by a Trusted Application, such as wrong parameters,
wrong state, invalid pointers, etc., rather than by run-time errors such as out-of-memory conditions.
Some Programmer Errors are explicitly tagged as “Panic Reasons” and MUST be reliably detected by an
Implementation. These errors make it impossible to produce the result of the function and require that the
API panic the calling TA instance, which kills the instance. If such a Panic Reason occurs, it MUST NOT go
undetected and, e.g., produce incorrect results or corrupt TA data.
However, it is accepted that some Programmer Errors cannot be realistically detected at all times and that
precise behavior cannot be specified without putting too much of a burden on the implementation. In case of
such a Programmer Error, an Implementation is therefore not required to gracefully handle the error or even
to behave consistently, but the Implementation SHOULD still make a best effort to detect the error and panic
the calling TA. In any case, a Trusted Application MUST NOT be able to use a Programmer Error on purpose
to circumvent the security boundaries enforced by an Implementation.
In general, incorrect handles—i.e., handles not returned by the API, already closed, with the wrong owner,
type, or state—are definite Panic Reasons while incorrect pointers are imprecise Programmer Errors.
2.2.3 Panics
A Panic is an instance-wide uncatchable exception that kills a whole TA instance as a result of calling one of
the API functions. It happens when the Implementation can detect a Programmer Error and also when the
Trusted Application itself requests to panic by calling the function TEE_Panic.
When a Panic occurs, the Trusted Core Framework kills the panicking TA instance and does the following:
• It discards all client entry point calls queued on the TA instance and closes all sessions opened by
Clients.
• It closes all resources that the TA instance opened, including all handles and all memory, and
destroys the instance. Note that multiple instances can reference a common resource, for example an
object. If an instance sharing a resource is destroyed, the Framework does not destroy the shared
resource immediately, but will wait until no other instances reference the resource before reclaiming it.
After a Panic, no TA function of the instance is ever called again, not even TA_DestroyEntryPoint.
From the client’s point of view, when a Trusted Application panics, the client commands must return the error
TEE_ERROR_TARGET_DEAD with the origin TEE_ORIGIN_TEE until the session is closed. (For details about
return origins, see the function TEE_InvokeTACommand in section 4.9.3 or the function
TEEC_InvokeCommand in the TEE Client API Specification [1], §4.5.9.)
When a Panic occurs, an Implementation in a non-production environment, such as in a development or
pre-production state, is encouraged to issue precise diagnostic information to help the developer understand
the Programmer Error. Diagnostic information SHOULD NOT be exposed outside of a secure development
environment.