• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stefanberger / libtpms / #2022

23 Sep 2025 01:11PM UTC coverage: 77.227% (+0.009%) from 77.218%
#2022

push

travis-ci

web-flow
Merge a45c293de into 4504f47c6

36116 of 46766 relevant lines covered (77.23%)

125180.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/src/tpm2/RunCommand.c
1
/********************************************************************************/
2
/*                                                                                */
3
/*                Platform specific entry and fail processing                           */
4
/*                             Written by Ken Goldman                                */
5
/*                       IBM Thomas J. Watson Research Center                        */
6
/*            $Id: RunCommand.c 1476 2019-06-10 19:32:03Z kgoldman $                */
7
/*                                                                                */
8
/*  Licenses and Notices                                                        */
9
/*                                                                                */
10
/*  1. Copyright Licenses:                                                        */
11
/*                                                                                */
12
/*  - Trusted Computing Group (TCG) grants to the user of the source code in        */
13
/*    this specification (the "Source Code") a worldwide, irrevocable,                 */
14
/*    nonexclusive, royalty free, copyright license to reproduce, create         */
15
/*    derivative works, distribute, display and perform the Source Code and        */
16
/*    derivative works thereof, and to grant others the rights granted herein.        */
17
/*                                                                                */
18
/*  - The TCG grants to the user of the other parts of the specification         */
19
/*    (other than the Source Code) the rights to reproduce, distribute,         */
20
/*    display, and perform the specification solely for the purpose of                 */
21
/*    developing products based on such documents.                                */
22
/*                                                                                */
23
/*  2. Source Code Distribution Conditions:                                        */
24
/*                                                                                */
25
/*  - Redistributions of Source Code must retain the above copyright licenses,         */
26
/*    this list of conditions and the following disclaimers.                        */
27
/*                                                                                */
28
/*  - Redistributions in binary form must reproduce the above copyright         */
29
/*    licenses, this list of conditions        and the following disclaimers in the         */
30
/*    documentation and/or other materials provided with the distribution.        */
31
/*                                                                                */
32
/*  3. Disclaimers:                                                                */
33
/*                                                                                */
34
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF        */
35
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH        */
36
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES)        */
37
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.                */
38
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for                 */
39
/*  information on specification licensing rights available through TCG         */
40
/*  membership agreements.                                                        */
41
/*                                                                                */
42
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED         */
43
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR         */
44
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR                 */
45
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY                 */
46
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.                */
47
/*                                                                                */
48
/*  - Without limitation, TCG and its members and licensors disclaim all         */
49
/*    liability, including liability for infringement of any proprietary         */
50
/*    rights, relating to use of information in this specification and to the        */
51
/*    implementation of this specification, and TCG disclaims all liability for        */
52
/*    cost of procurement of substitute goods or services, lost profits, loss         */
53
/*    of use, loss of data or any incidental, consequential, direct, indirect,         */
54
/*    or special damages, whether under contract, tort, warranty or otherwise,         */
55
/*    arising in any way out of use or reliance upon this specification or any         */
56
/*    information herein.                                                        */
57
/*                                                                                */
58
/*  (c) Copyright IBM Corp. and others, 2016 - 2019                                */
59
/*                                                                                */
60
/********************************************************************************/
61

62
//**Introduction
63
// This module provides the platform specific entry and fail processing. The
64
// _plat__RunCommand() function is used to call to ExecuteCommand() in the TPM code.
65
// This function does whatever processing is necessary to set up the platform
66
// in anticipation of the call to the TPM including settup for error processing.
67
//
68
// The _plat__Fail() function is called when there is a failure in the TPM. The TPM
69
// code will have set the flag to indicate that the TPM is in failure mode.
70
// This call will then recursively call ExecuteCommand in order to build the
71
// failure mode response. When ExecuteCommand() returns to _plat__Fail(), the
72
// platform will do some platform specific operation to return to the environment in
73
// which the TPM is executing. For a simulator, setjmp/longjmp is used. For an OS,
74
// a system exit to the OS would be appropriate.
75

76
//** Includes and locals
77
#include "Platform.h"
78
#include <assert.h>
79
#include <setjmp.h>
80
#include <stdio.h>
81

82
jmp_buf s_jumpBuffer;
83

84
// The following extern globals are copied here from Global.h to avoid including all of Tpm.h here.
85
// TODO: Improve the interface by which these values are shared.
86
extern BOOL g_inFailureMode;  // Indicates that the TPM is in failure mode
87
#if ALLOW_FORCE_FAILURE_MODE
88
extern BOOL g_forceFailureMode;  // flag to force failure mode during test
89
#endif
90
#if FAIL_TRACE
91
// The name of the function that triggered failure mode.
92
extern const char* s_failFunctionName;
93
#endif  // FAIL_TRACE
94
extern UINT32 s_failFunction;
95
extern UINT32 s_failLine;
96
extern UINT32 s_failCode;
97

98
//** Functions
99

100
//***_plat__RunCommand()
101
// This version of RunCommand will set up a jum_buf and call ExecuteCommand(). If
102
// the command executes without failing, it will return and RunCommand will return.
103
// If there is a failure in the command, then _plat__Fail() is called and it will
104
// longjump back to RunCommand which will call ExecuteCommand again. However, this
105
// time, the TPM will be in failure mode so ExecuteCommand will simply build
106
// a failure response and return.
107
LIB_EXPORT void _plat__RunCommand(
17,798✔
108
    uint32_t        requestSize,   // IN: command buffer size
109
    unsigned char*  request,       // IN: command buffer
110
    uint32_t*       responseSize,  // IN/OUT: response buffer size
111
    unsigned char** response       // IN/OUT: response buffer
112
)
113
{
114
    setjmp(s_jumpBuffer);
17,798✔
115
    ExecuteCommand(requestSize, request, responseSize, response);
17,798✔
116
}
17,798✔
117

118
//***_plat__Fail()
119
// This is the platform depended failure exit for the TPM.
120
LIB_EXPORT NORETURN void _plat__Fail(void)
×
121
{
122

123
#if ALLOW_FORCE_FAILURE_MODE
124
    // The simulator asserts during unexpected (i.e., un-forced) failure modes.
125
    if(!g_forceFailureMode)
126
    {
127
        fprintf(stderr, "Unexpected failure mode (code %d) in ", s_failCode);
128
#  if FAIL_TRACE
129
        fprintf(stderr, "function '%s' (line %d)\n", s_failFunctionName, s_failLine);
130
#  else   // FAIL_TRACE
131
        fprintf(stderr, "location code 0x%0x\n", s_locationCode);
132
#  endif  // FAIL_TRACE
133
        assert(FALSE);
134
    }
135

136
    // Clear the forced-failure mode flag for next time.
137
    g_forceFailureMode = FALSE;
138
#endif  // ALLOW_FORCE_FAILURE_MODE
139

140
    longjmp(&s_jumpBuffer[0], 1);
×
141
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc