Skip to content

Commit 105f130

Browse files
krzydynterry2000s
authored andcommitted
[TEEC] implement union for 32/64 bit, IntPtr context, IntPtr Operation, IntPtr tmpmem, fix Whole type
Change-Id: Ia45d9df73bb0f52467ca417f402ff908ede4df01
1 parent 37960b6 commit 105f130

File tree

3 files changed

+282
-73
lines changed

3 files changed

+282
-73
lines changed

src/Tizen.Security.TEEC/Interop/Interop.Libteec.cs

+8-14
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ internal static partial class Libteec
3131
/// </summary>
3232
//TEEC_Result TEEC_InitializeContext(const char *name, TEEC_Context *context);
3333
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_InitializeContext", CallingConvention = CallingConvention.Cdecl)]
34-
static public extern int InitializeContext(string name, ref TEEC_Context context);
34+
static public extern int InitializeContext(string name, IntPtr context);
3535

3636
/// <summary>
3737
/// This function destroys an initialized TEE Context, closing the connection between the client application
@@ -43,7 +43,7 @@ internal static partial class Libteec
4343
/// </summary>
4444
//void TEEC_FinalizeContext(TEEC_Context *context);
4545
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_FinalizeContext", CallingConvention = CallingConvention.Cdecl)]
46-
static public extern void FinalizeContext(ref TEEC_Context context);
46+
static public extern void FinalizeContext(IntPtr context);
4747

4848
/// <summary>
4949
/// This function registers a block of existing client application memory as a block of shared memory within
@@ -54,7 +54,7 @@ internal static partial class Libteec
5454
/// </summary>
5555
//EEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem);
5656
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_RegisterSharedMemory", CallingConvention = CallingConvention.Cdecl)]
57-
static public extern int RegisterSharedMemory(ref TEEC_Context context, ref TEEC_SharedMemory sharedMem);
57+
static public extern int RegisterSharedMemory(IntPtr context, ref TEEC_SharedMemory sharedMem);
5858

5959
/// <summary>
6060
/// This function allocates a new block of memory as a block of shared memory within the scope of the
@@ -65,7 +65,7 @@ internal static partial class Libteec
6565
/// </summary>
6666
//TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, TEEC_SharedMemory *sharedMem);
6767
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_AllocateSharedMemory", CallingConvention = CallingConvention.Cdecl)]
68-
static public extern int AllocateSharedMemory(ref TEEC_Context context, ref TEEC_SharedMemory sharedMem);
68+
static public extern int AllocateSharedMemory(IntPtr context, ref TEEC_SharedMemory sharedMem);
6969

7070
/// <summary>
7171
/// This function deregisters or deallocates a previously initialized block of the shared memory.
@@ -91,10 +91,7 @@ internal static partial class Libteec
9191
/// </summary>
9292
//TEEC_Result TEEC_OpenSession(TEEC_Context *context, TEEC_Session *session, const TEEC_UUID *destination, uint connectionMethod, const void *connectionData, TEEC_Operation *operation, uint *returnOrigin);
9393
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_OpenSession", CallingConvention = CallingConvention.Cdecl)]
94-
static public extern int OpenSession(ref TEEC_Context context, ref TEEC_Session session, ref TEEC_UUID destination, uint connectionMethod, byte[] connectionData, ref TEEC_Operation operation, out uint returnOrigin);
95-
96-
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_OpenSession", CallingConvention = CallingConvention.Cdecl)]
97-
static public extern int OpenSession(ref TEEC_Context context, ref TEEC_Session session, ref TEEC_UUID destination, uint connectionMethod, byte[] connectionData, IntPtr operation, out uint returnOrigin);
94+
static public extern int OpenSession(IntPtr context, IntPtr session, ref TEEC_UUID destination, uint connectionMethod, byte[] connectionData, IntPtr operation, out uint returnOrigin);
9895

9996
/// <summary>
10097
/// This function closes a session which has been opened with a trusted application.
@@ -105,7 +102,7 @@ internal static partial class Libteec
105102
/// </summary>
106103
//void TEEC_CloseSession(TEEC_Session *session);
107104
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_CloseSession", CallingConvention = CallingConvention.Cdecl)]
108-
static public extern void CloseSession(ref TEEC_Session session);
105+
static public extern void CloseSession(IntPtr session);
109106

110107
/// <summary>
111108
/// This function invokes a command within the specified session.
@@ -116,10 +113,7 @@ internal static partial class Libteec
116113
/// </summary>
117114
//TEEC_Result TEEC_InvokeCommand(TEEC_Session *session, uint commandID, TEEC_Operation *operation, uint *returnOrigin);
118115
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_InvokeCommand", CallingConvention = CallingConvention.Cdecl)]
119-
static public extern int InvokeCommand(ref TEEC_Session session, uint commandID, ref TEEC_Operation operation, out uint returnOrigin);
120-
121-
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_InvokeCommand", CallingConvention = CallingConvention.Cdecl)]
122-
static public extern int InvokeCommand(ref TEEC_Session session, uint commandID, IntPtr operation, out uint returnOrigin);
116+
static public extern int InvokeCommand(IntPtr session, uint commandID, IntPtr operation, out uint returnOrigin);
123117

124118
/// <summary>
125119
/// This function requests the cancelation of a pending open session operation or a command invocation
@@ -131,6 +125,6 @@ internal static partial class Libteec
131125
/// </summary>
132126
//void TEEC_RequestCancellation(TEEC_Operation *operation);
133127
[DllImport(Libraries.Libteec, EntryPoint = "TEEC_RequestCancellation", CallingConvention = CallingConvention.Cdecl)]
134-
static public extern void RequestCancellation(ref TEEC_Operation operation);
128+
static public extern void RequestCancellation(IntPtr operation);
135129
}
136130
}

src/Tizen.Security.TEEC/Interop/Interop.Types.cs

+54-17
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ internal struct TEEC_SharedMemory
6262
public IntPtr buffer;
6363
public UIntPtr size;
6464
public UInt32 flags;
65-
public IntPtr imp;
65+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 128)]
66+
public byte[] padding;
6667
}
6768

6869
[StructLayout(LayoutKind.Sequential,Pack=8)]
@@ -72,39 +73,75 @@ internal struct TEEC_Value
7273
public UInt32 b;
7374
}
7475

75-
[StructLayout(LayoutKind.Sequential, Pack=8)]
76-
internal struct TEEC_TempMemoryReference
76+
[StructLayout(LayoutKind.Sequential)]
77+
internal struct TEEC_TempMemoryReference32
7778
{
78-
public IntPtr buffer;
79-
public UIntPtr size;
79+
public Int32 buffer;
80+
public UInt32 size;
8081
}
8182

82-
[StructLayout(LayoutKind.Sequential, Pack=8)]
83-
internal struct TEEC_RegisteredMemoryReference
83+
[StructLayout(LayoutKind.Sequential)]
84+
internal struct TEEC_RegisteredMemoryReference32
8485
{
85-
public IntPtr parent;
86-
public UIntPtr size;
87-
public UIntPtr offset;
86+
public Int32 parent;
87+
public UInt32 size;
88+
public UInt32 offset;
89+
}
90+
91+
[StructLayout(LayoutKind.Explicit)]
92+
internal struct TEEC_Parameter32
93+
{
94+
[FieldOffset(0)]
95+
public TEEC_TempMemoryReference32 tmpref;
96+
[FieldOffset(0)]
97+
public TEEC_RegisteredMemoryReference32 memref;
98+
[FieldOffset(0)]
99+
public TEEC_Value value;
100+
}
101+
102+
[StructLayout(LayoutKind.Sequential)]
103+
internal struct TEEC_Operation32
104+
{
105+
public UInt32 started;
106+
public UInt32 paramTypes;
107+
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
108+
public TEEC_Parameter32[] paramlist;
109+
public IntPtr imp;
88110
}
89111

90-
[StructLayout(LayoutKind.Explicit, Pack=8)]
91-
internal struct TEEC_Parameter
112+
[StructLayout(LayoutKind.Sequential)]
113+
internal struct TEEC_TempMemoryReference64
114+
{
115+
public Int64 buffer;
116+
public UInt64 size;
117+
}
118+
119+
[StructLayout(LayoutKind.Sequential)]
120+
internal struct TEEC_RegisteredMemoryReference64
121+
{
122+
public Int64 parent;
123+
public UInt64 size;
124+
public UInt64 offset;
125+
}
126+
127+
[StructLayout(LayoutKind.Explicit)]
128+
internal struct TEEC_Parameter64
92129
{
93130
[FieldOffset(0)]
94-
public TEEC_TempMemoryReference tmpref;
131+
public TEEC_TempMemoryReference64 tmpref;
95132
[FieldOffset(0)]
96-
public TEEC_RegisteredMemoryReference memref;
133+
public TEEC_RegisteredMemoryReference64 memref;
97134
[FieldOffset(0)]
98135
public TEEC_Value value;
99136
}
100137

101-
[StructLayout(LayoutKind.Sequential, Pack=8)]
102-
internal struct TEEC_Operation
138+
[StructLayout(LayoutKind.Sequential)]
139+
internal struct TEEC_Operation64
103140
{
104141
public UInt32 started;
105142
public UInt32 paramTypes;
106143
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
107-
public TEEC_Parameter[] paramlist;
144+
public TEEC_Parameter64[] paramlist;
108145
public IntPtr imp;
109146
}
110147
}

0 commit comments

Comments
 (0)