Tss2_Sys_Initialize: Factor the initialization of data buffer pointers into a separate function (InitSysContextPtrs).

These pointers are only initialized once so it made a certain amount of
sense to just do this in the main context initialization function. But
when we start integrating unit tests for the marshalling functions it's
nice to have a function to call that short cuts all of the consistency
checks in Tss2_Sys_Initialize. With this simple function we can
initialize all of the pointers to the data regions where data is
marshalled and then just call the relevant marshalling functions without
having to do a pile of setup.

Signed-off-by: Philip Tricca <philip.b.tricca@intel.com>
diff --git a/sysapi/include/sysapi_util.h b/sysapi/include/sysapi_util.h
index 4fd799c..3ed15ac 100644
--- a/sysapi/include/sysapi_util.h
+++ b/sysapi/include/sysapi_util.h
@@ -160,6 +160,7 @@
 TPM_RC ConcatSizedByteBuffer( TPM2B_MAX_BUFFER *result, TPM2B *addBuffer );
 
 void InitSysContextFields( TSS2_SYS_CONTEXT *sysContext );
+void InitSysContextPtrs ( TSS2_SYS_CONTEXT *sysContext, size_t contextSize );
 
 TSS2_RC CompleteChecks( TSS2_SYS_CONTEXT *sysContext );
 
diff --git a/sysapi/sysapi/ContextManagement.c b/sysapi/sysapi/ContextManagement.c
index 64601d1..13d41c0 100644
--- a/sysapi/sysapi/ContextManagement.c
+++ b/sysapi/sysapi/ContextManagement.c
@@ -83,15 +83,9 @@
     {
         SYS_CONTEXT->tctiContext = (TSS2_TCTI_CONTEXT *)tctiContext;
 
+        InitSysContextPtrs( sysContext, contextSize );
         InitSysContextFields( sysContext );
 
-        // First block of memory used for sysContext.
-        // Remaining block used for in/out buffers.
-        SYS_CONTEXT->tpmInBuffPtr = (UINT8 *)( SYS_CONTEXT ) + sizeof( _TSS2_SYS_CONTEXT_BLOB );;
-        SYS_CONTEXT->tpmOutBuffPtr = SYS_CONTEXT->tpmInBuffPtr;
-        SYS_CONTEXT->maxCommandSize = SYS_CONTEXT->maxResponseSize =
-                contextSize - ( ( (UINT8 *)SYS_CONTEXT->tpmInBuffPtr ) - (UINT8 *)SYS_CONTEXT );
-
         SYS_CONTEXT->previousStage = CMD_STAGE_INITIALIZE;
     }
 
diff --git a/sysapi/sysapi_util/CommandUtil.c b/sysapi/sysapi_util/CommandUtil.c
index c9d2e8a..51a8abf 100644
--- a/sysapi/sysapi_util/CommandUtil.c
+++ b/sysapi/sysapi_util/CommandUtil.c
@@ -58,6 +58,32 @@
     SYS_CONTEXT->rpBufferUsedSize = 0;
     SYS_CONTEXT->rval = TSS2_RC_SUCCESS;
 }
+/**
+ * Initialize pointers to the various memory blocks / buffers in the opaque
+ * area of the TSS2_SYS_CONTEXT structure.
+ *
+ * tpmInBufferPtr: pointer to the memory area where we build command buffers
+ *   that we send to the TPM
+ * tpmOutBufferPtrs: pointer to the memory area where we store the TPMs
+ *   response
+ * maxComamndSize / maxResponseSize: the size of these memory areas.
+ *
+ * NOTE: It should only be necessary to invoke this function once for any
+ * given sys context.
+ */
+void InitSysContextPtrs(
+    TSS2_SYS_CONTEXT   *sysContext,
+    size_t              contextSize
+    )
+{
+    SYS_CONTEXT->tpmInBuffPtr =
+        (UINT8 *)SYS_CONTEXT + sizeof( _TSS2_SYS_CONTEXT_BLOB );
+    SYS_CONTEXT->tpmOutBuffPtr = SYS_CONTEXT->tpmInBuffPtr;
+    SYS_CONTEXT->maxCommandSize =
+        contextSize - ((UINT8 *)SYS_CONTEXT->tpmInBuffPtr - (UINT8 *)SYS_CONTEXT);
+    SYS_CONTEXT->maxResponseSize = SYS_CONTEXT->maxCommandSize;
+}
+
 
 UINT32 GetCommandSize( TSS2_SYS_CONTEXT *sysContext )
 {