2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
18 using System.Collections.Generic;
19 using System.Runtime.InteropServices;
20 using System.Threading;
21 using System.Threading.Tasks;
23 namespace Tizen.Security.TEEC
26 /// This type denotes the Session Login Method used in OpenSession.
28 /// <since_tizen> 3 </since_tizen>
29 public class LoginMethod
31 /// <summary>No login data is provided.</summary>
32 public const uint Public = 0x00000000;
33 /// <summary>Login data about the user running the client application process is provided.</summary>
34 public const uint User = 0x00000001;
35 /// <summary>Login data about the group running the client application process is provided.</summary>
36 public const uint Group = 0x00000002;
37 /// <summary>Login data about the running client application itself is provided.</summary>
38 public const uint Application = 0x00000003;
42 /// This type denotes the Value parameter.
44 /// <since_tizen> 3 </since_tizen>
45 public enum TEFValueType : UInt32
47 /// <summary>The parameter is a ValueType tagged as the input.</summary>
49 /// <summary>The parameter is a ValueType tagged as the output.</summary>
51 /// <summary>The parameter is a ValueType tagged as both the input and the output.</summary>
56 /// This type denotes the TempMemoryReference parameter
57 /// describing a region of memory which needs to be temporarily registered for the duration of the operation.
59 /// <since_tizen> 3 </since_tizen>
60 public enum TEFTempMemoryType : UInt32
62 /// <summary>The parameter is a TempMemoryType and is tagged as the input.</summary>
64 /// <summary>Same as the input, but the Memory Reference is tagged as the output.</summary>
66 /// <summary>A Temporary Memory Reference tagged as both the input and the output.</summary>
71 /// This type denotes the SharedMemoryReference parameter.
73 /// <since_tizen> 3 </since_tizen>
74 public enum TEFRegisteredMemoryType : UInt32
76 /// <summary>The parameter is a registered memory reference that refers to the entirety of its parent shared memory block.</summary>
78 /// <summary>A registered memory reference structure that refers to a partial region of its parent shared mMemory block and is tagged as the input.</summary>
79 PartialInput = 0x0000000D,
80 /// <summary>A registered memory reference structure that refers to a partial region of its parent shared memory block and is tagged as the output.</summary>
81 PartialOutput = 0x0000000E,
82 /// <summary>A registered memory reference structure that refers to a partial region of its parent shared memory block and is tagged as both the input and the output.</summary>
83 PartialInOut = 0x0000000F,
87 /// This type denotes the SharedMemory access direction.
89 /// <since_tizen> 3 </since_tizen>
91 public enum SharedMemoryFlags : UInt32
93 /// <summary>A flag indicates the shared memory can be read.</summary>
95 /// <summary>A flag indicates the shared memory can be written.</summary>
97 /// <summary>A flag indicates the shared memory can be read and written.</summary>
98 InOut = Input | Output,
102 /// This type denotes a shared memory block which has been either registered
103 /// with the implementation or allocated by it.
105 /// <since_tizen> 3 </since_tizen>
106 public sealed class SharedMemory
108 internal Interop.TEEC_SharedMemory shm;
109 internal SharedMemory(Interop.TEEC_SharedMemory shm)
114 /// This property represents the shared memory size in bytes.
116 /// <since_tizen> 3 </since_tizen>
119 get { return shm.size; }
122 /// This property represents the start address of the shared memory block.
124 /// <since_tizen> 3 </since_tizen>
125 public IntPtr Address
127 get { return shm.buffer; }
131 /// This function makes a copy and is designed for convenient operations on small buffers.
132 /// For large buffers, the direct address should be used.
134 /// <since_tizen> 3 </since_tizen>
135 /// <param name="data">The source data buffer to copy data from.</param>
136 /// <param name="dstOffs">The starting offset in the destination shared memory.</param>
137 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
138 public void SetData(byte[] data, int dstOffs)
140 if ((shm.flags & (uint)SharedMemoryFlags.Output) == 0) throw new InvalidOperationException("No write access");
141 Marshal.Copy(data, 0, shm.buffer + dstOffs, data.Length);
144 /// This function makes a copy and is designed for convenient operations on small buffers.
145 /// For large buffers, the direct address should be used.
147 /// <since_tizen> 3 </since_tizen>
148 /// <param name="data">The destination data buffer to copy data into.</param>
149 /// <param name="srcOffs">The starting offset in the source shared memory.</param>
150 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
151 public void GetData(byte[] data, int srcOffs)
153 if ((shm.flags & (uint)SharedMemoryFlags.Input) == 0) throw new InvalidOperationException("No read access");
154 Marshal.Copy(shm.buffer + srcOffs, data, 0, data.Length);
159 /// This type defines the payload of either an open session operation or an invoke command operation. It is
160 /// also used for cancelation of operations, which may be desirable even if no payload is passed.
161 /// Parameters are used to exchange data between CA and TA.
163 /// <since_tizen> 3 </since_tizen>
164 public abstract class Parameter
166 internal Parameter(uint t)
170 internal uint NativeType { get; }
174 /// This type defines a template for the parameter types.
176 /// <since_tizen> 3 </since_tizen>
177 public abstract class BaseParameter<TEnum> : Parameter where TEnum : struct, IComparable, IFormattable, IConvertible // as close to Enum as possible
179 internal BaseParameter(TEnum t) : base((uint)(object)t)
185 /// This property represents the access type to this parameter.
187 /// <since_tizen> 3 </since_tizen>
188 public TEnum Type { get; }
192 /// This type defines a temporary memory reference.
194 /// <since_tizen> 3 </since_tizen>
195 public sealed class TempMemoryReference : BaseParameter<TEFTempMemoryType>
198 /// Constructs a parameter object which holds information about the temporary memory copied to or from TA.
200 /// <since_tizen> 3 </since_tizen>
201 /// <param name="buffer">The address of the allocated memory buffer.</param>
202 /// <param name="size">The size of the buffer.</param>
203 /// <param name="type">The kind of access allowed for TA <see cref="TEFTempMemoryType"/>.</param>
204 public TempMemoryReference(IntPtr buffer, uint size, TEFTempMemoryType type) :
207 this.Buffer = buffer;
211 /// This property represents the memory address of the buffer.
213 /// <since_tizen> 3 </since_tizen>
214 public IntPtr Buffer { get; }
216 /// This property represents the size of the buffer.
218 /// <since_tizen> 3 </since_tizen>
219 public uint Size { get; internal set; }
223 /// This type defines a memory reference that uses a pre-registered or pre-allocated shared memory block.
225 /// <since_tizen> 3 </since_tizen>
226 public sealed class RegisteredMemoryReference : BaseParameter<TEFRegisteredMemoryType>
229 /// Constructs a parameter object which holds information about the registered memory shared with TA.
231 /// <since_tizen> 3 </since_tizen>
232 /// <param name="parent">The shared memory - registered or allocated.</param>
233 /// <param name="size">The size of the buffer part.</param>
234 /// <param name="offset">The offset of the buffer in the shared memory.</param>
235 /// <param name="type">The kind of access allowed for TA <see cref="TEFRegisteredMemoryType"/>.</param>
236 public RegisteredMemoryReference(SharedMemory parent, uint size, uint offset, TEFRegisteredMemoryType type) :
239 this.Parent = parent;
241 this.Offset = offset;
244 /// This property represents the shared memory that is referred to.
246 /// <since_tizen> 3 </since_tizen>
247 public SharedMemory Parent { get; }
249 /// This property represents the size (in bytes) of the shared memory.
251 /// <since_tizen> 3 </since_tizen>
252 public uint Size { get; internal set; }
254 /// This property represents the offset (in bytes) from the start of the shared memory.
256 /// <since_tizen> 3 </since_tizen>
257 public uint Offset { get; }
261 /// This type defines a parameter that is not referencing the shared memory, but carries instead small raw data
262 /// passed by a value.
264 /// <since_tizen> 3 </since_tizen>
265 public sealed class Value : BaseParameter<TEFValueType>
268 /// Constructs a parameter object which holds information about integer values copied to or from TA.
270 /// <since_tizen> 3 </since_tizen>
271 /// <param name="a">User paramter A.</param>
272 /// <param name="b">User paramter B.</param>
273 /// <param name="type">The kind of access allowed for TA <see cref="TEFValueType"/>.</param>
274 public Value(uint a, uint b, TEFValueType type) :
281 /// This property represents an unsigned integer A.
283 /// <since_tizen> 3 </since_tizen>
284 public uint A { get; internal set; }
286 /// This property represents an unsigned integer B.
288 /// <since_tizen> 3 </since_tizen>
289 public uint B { get; internal set; }
294 /// This type denotes a TEE Session, the logical container linking a client application with a particular trusted application.
296 /// <since_tizen> 3 </since_tizen>
297 public sealed class Session
299 private Interop.TEEC_Context context;
300 private Interop.TEEC_Session session;
302 internal Session(Interop.TEEC_Context context) {
303 this.context = context;
304 this.session = new Interop.TEEC_Session();
308 /// Destructor of the class.
315 internal UInt32 InitParam(ref Interop.TEEC_Parameter dst, Parameter src)
317 switch (src.NativeType) {
318 case (int)TEFValueType.Input:
319 case (int)TEFValueType.Output:
320 case (int)TEFValueType.InOut:
321 dst.value.a = ((Value)src).A;
322 dst.value.b = ((Value)src).B;
325 case (int)TEFTempMemoryType.Input:
326 case (int)TEFTempMemoryType.Output:
327 case (int)TEFTempMemoryType.InOut:
328 dst.tmpref.buffer = ((TempMemoryReference)src).Buffer;
329 dst.tmpref.size = ((TempMemoryReference)src).Size;
332 case (int)TEFRegisteredMemoryType.Whole:
333 case (int)TEFRegisteredMemoryType.PartialInput:
334 case (int)TEFRegisteredMemoryType.PartialOutput:
335 case (int)TEFRegisteredMemoryType.PartialInOut:
336 dst.memref.parent = ((RegisteredMemoryReference)src).Parent.shm;
337 dst.memref.size = ((RegisteredMemoryReference)src).Size;
338 dst.memref.offset = ((RegisteredMemoryReference)src).Offset;
343 return src.NativeType;
346 internal void UpdateParam(Interop.TEEC_Parameter src, ref Parameter dst)
348 switch (dst.NativeType) {
349 case (int)TEFValueType.Input:
350 case (int)TEFValueType.Output:
351 case (int)TEFValueType.InOut:
352 ((Value)dst).A = src.value.a;
353 ((Value)dst).B = src.value.b;
356 case (int)TEFTempMemoryType.Input:
357 case (int)TEFTempMemoryType.Output:
358 case (int)TEFTempMemoryType.InOut:
359 ((TempMemoryReference)dst).Size = src.tmpref.size;
362 case (int)TEFRegisteredMemoryType.Whole:
363 case (int)TEFRegisteredMemoryType.PartialInput:
364 case (int)TEFRegisteredMemoryType.PartialOutput:
365 case (int)TEFRegisteredMemoryType.PartialInOut:
366 ((RegisteredMemoryReference)dst).Size = src.memref.size;
373 internal void Open(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist)
375 Interop.TEEC_UUID uuid = Interop.TEEC_UUID.ToTeecUuid(destination);
376 Interop.TEEC_Operation op = new Interop.TEEC_Operation();
380 for (int i=0; i < 4 && i < paramlist.Length; ++i) {
381 op.paramTypes |= InitParam(ref op.paramlist[i], paramlist[i]) << (4*i);
385 int ret = Interop.Libteec.OpenSession(ref context, ref session, ref uuid, loginMethod, connectionData, ref op, out ro);
386 //MAYBE map origin of return code to specyfic Exception
387 Interop.CheckNThrowException(ret, string.Format("OpenSession('{0}')", destination));
388 for (int i=0; i < 4 && i < paramlist.Length; ++i) {
389 UpdateParam(op.paramlist[i], ref paramlist[i]);
394 /// This function closes a session which has been opened with a trusted application.
395 /// All commands within the session must be completed before this function can be called.
397 /// <since_tizen> 3 </since_tizen>
398 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
399 /// <privlevel>partner</privlevel>
400 /// <feature>http://tizen.org/feature/security.tee</feature>
401 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
402 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
403 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
404 public void Close() {
405 Interop.Libteec.CloseSession(ref session);
410 /// This function invokes a command within the specified session.
411 /// The parameter commandID is an identifier that is used to indicate which of the exposed trusted
412 /// application functions should be invoked. The supported command identifier values are defined by the
413 /// trusted application's protocol.
414 /// There can be up to four parameter objects given in the <paramref name="paramlist"/> array.
416 /// <since_tizen> 3 </since_tizen>
417 /// <param name="commandID">The command.</param>
418 /// <param name="paramlist">The array of parameters.</param>
419 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
420 /// <privlevel>partner</privlevel>
421 /// <feature>http://tizen.org/feature/security.tee</feature>
422 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
423 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
424 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
425 /// <exception cref="ArgumentException">The argument <paramref name="paramlist"/> is wrong.</exception>
426 public void InvokeCommand(uint commandID, Parameter[] paramlist)
428 Interop.TEEC_Operation op = new Interop.TEEC_Operation();
431 for (int i=0; i < 4 && i < paramlist.Length; ++i) {
432 op.paramTypes |= InitParam(ref op.paramlist[i], paramlist[i]) << (4*i);
436 int ret = Interop.Libteec.InvokeCommand(ref session, commandID, ref op, out ro);
437 //MAYBE map origin of return code to specific Exception
438 Interop.CheckNThrowException(ret, string.Format("InvokeCommand({0})", commandID));
439 for (int i=0; i < 4 && i < paramlist.Length; ++i) {
440 UpdateParam(op.paramlist[i], ref paramlist[i]);
445 /// The asynchronous version of the InvokeCommand.
447 /// <since_tizen> 3 </since_tizen>
448 /// <param name="commandID">The command.</param>
449 /// <param name="paramlist">The array of parameters.</param>
450 /// <param name="token">The token for task manipulation.</param>
451 /// <returns>Returns a task executing an invoke command in the background.</returns>
452 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
453 /// <privlevel>partner</privlevel>
454 /// <feature>http://tizen.org/feature/security.tee</feature>
455 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
456 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
457 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
458 /// <exception cref="ArgumentException">One of the arguments is wrong.</exception>
459 public async Task InvokeCommandAsync(uint commandID, Parameter[] paramlist, CancellationToken token = default(CancellationToken))
461 await Task.Factory.StartNew(() => InvokeCommand(commandID, paramlist));
467 /// This type denotes a TEE Context, the main logical container linking a Client Application with a particular TEE.
469 /// <since_tizen> 3 </since_tizen>
470 public sealed class Context : IDisposable
472 private Interop.TEEC_Context context;
475 /// This function (constructor) initializes a new TEE Context, forming a connection between this client application and the
476 /// TEE identified by the string identifier name (empty or null name denotes a default TEE).
478 /// <since_tizen> 3 </since_tizen>
479 /// <param name="name">The TEE name.</param>
480 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
481 /// <privlevel>partner</privlevel>
482 /// <feature>http://tizen.org/feature/security.tee</feature>
483 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
484 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
485 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
486 public Context(string name)
488 context = new Interop.TEEC_Context();
489 if (name != null && name.Length == 0)
492 int ret = Interop.Libteec.InitializeContext(name, ref context);
493 Interop.CheckNThrowException(ret, string.Format("InititalizeContext('{0}')", name));
495 catch (global::System.DllNotFoundException e)
498 Interop.CheckNThrowException((int)Interop.LibteecError.NotImplemented, "Not found: " + e.Message);
504 /// Destructor of the class.
512 /// This function implements the IDisposable interface.
514 /// <since_tizen> 3 </since_tizen>
515 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
516 /// <privlevel>partner</privlevel>
517 /// <feature>http://tizen.org/feature/security.tee</feature>
518 public void Dispose() {
520 Interop.Libteec.FinalizeContext(ref context);
522 catch (global::System.DllNotFoundException) { }
526 /// This function opens a new session between the client application and the specified trusted application.
527 /// The target trusted application is identified by an UUID passed in the parameter destination.
528 /// There can be up to four parameter objects given in the <paramref name="paramlist"/> array.
530 /// <since_tizen> 3 </since_tizen>
531 /// <param name="destination">The UUID of the destination TA.</param>
532 /// <param name="loginMethod">The authentication algorithm <see cref="LoginMethod" />.</param>
533 /// <param name="connectionData">The data to be verified by a given login method.</param>
534 /// <param name="paramlist">The parameters to be passed to TA open-session-callback.</param>
535 /// <returns>Returns opened session.</returns>
536 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
537 /// <privlevel>partner</privlevel>
538 /// <feature>http://tizen.org/feature/security.tee</feature>
539 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
540 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
541 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
542 /// <exception cref="ArgumentException">One of the arguments is wrong.</exception>
543 public Session OpenSession(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist)
545 Session ses = new Session(context);
546 ses.Open(destination, loginMethod, connectionData, paramlist);
550 /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token).
552 /// <since_tizen> 3 </since_tizen>
553 /// <param name="destination">The UUID of the destination TA.</param>
554 /// <returns>Returns opened session.</returns>
555 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
556 /// <privlevel>partner</privlevel>
557 /// <feature>http://tizen.org/feature/security.tee</feature>
558 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
559 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
560 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
561 public Session OpenSession(Guid destination)
563 Session ses = new Session(context);
564 ses.Open(destination, LoginMethod.Public, null, null);
569 /// The asynchronous version of the OpenSession.
570 /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token).
572 /// <since_tizen> 3 </since_tizen>
573 /// <param name="destination">The UUID of the destination TA.</param>
574 /// <param name="loginMethod">The authentication algorithm <see cref="LoginMethod" />.</param>
575 /// <param name="connectionData">The data to be verified by a given login method.</param>
576 /// <param name="paramlist">The parameters to be passed to the TA open-session-callback.</param>
577 /// <param name="token">The token for the task manipulation.</param>
578 /// <returns>Returns a Task executing the session open in the background.</returns>
579 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
580 /// <privlevel>partner</privlevel>
581 /// <feature>http://tizen.org/feature/security.tee</feature>
582 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
583 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
584 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
585 /// <exception cref="ArgumentException">One of the arguments is wrong.</exception>
586 public async Task<Session> OpenSessionAsync(Guid destination, uint loginMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token = default(CancellationToken))
588 Task<Session> task = Task<Session>.Factory.StartNew(() =>
590 return OpenSession(destination, loginMethod, connectionData, paramlist);
595 /// The asynchronous version of the OpenSession.
596 /// @see OpenSession (Guid destination, uint connectionMethod, byte[] connectionData, Parameter[] paramlist, CancellationToken token).
598 /// <since_tizen> 3 </since_tizen>
599 /// <param name="destination">The UUID of the destination TA.</param>
600 /// <param name="token">The token for a task manipulation.</param>
601 /// <returns>Returns a task executing session open in the background.</returns>
602 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
603 /// <privlevel>partner</privlevel>
604 /// <feature>http://tizen.org/feature/security.tee</feature>
605 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
606 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
607 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
608 public async Task<Session> OpenSessionAsync(Guid destination, CancellationToken token = default(CancellationToken))
610 Task<Session> task = Task<Session>.Factory.StartNew(() =>
612 return OpenSession(destination);
618 /// This function registers a block of the existing client application memory as a block of shared memory within
619 /// the scope of the specified context, in accordance with the parameters.
620 /// The input <paramref name="memaddr"/> must point to the shared memory region to register.
622 /// <since_tizen> 3 </since_tizen>
623 /// <param name="memaddr">The address of the shared memory.</param>
624 /// <param name="size">The size of the shared memory.</param>
625 /// <param name="flags">The flags describing the access modes (Input and/or Output).</param>
626 /// <returns>Returns the SharedMemory handler.</returns>
627 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
628 /// <privlevel>partner</privlevel>
629 /// <feature>http://tizen.org/feature/security.tee</feature>
630 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
631 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
632 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
633 /// <exception cref="ArgumentException">The argument <paramref name="memaddr"/> is wrong.</exception>
634 public SharedMemory RegisterSharedMemory(IntPtr memaddr, UInt32 size, SharedMemoryFlags flags)
636 Interop.TEEC_SharedMemory shm = new Interop.TEEC_SharedMemory();
637 shm.buffer = memaddr;
639 shm.flags = (UInt32)flags;
640 int ret = Interop.Libteec.RegisterSharedMemory(ref context, ref shm);
641 Interop.CheckNThrowException(ret, "RegisterSharedMemory");
642 return new SharedMemory(shm);
646 /// This function allocates a new block of memory as a block of shared memory within the scope of the
647 /// specified context, in accordance with the parameters.
649 /// <since_tizen> 3 </since_tizen>
650 /// <param name="size">The size of shared memory.</param>
651 /// <param name="flags">The flags describing access modes (Input and/or Output).</param>
652 /// <returns>Returns the Shared Memory handler.</returns>
653 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
654 /// <privlevel>partner</privlevel>
655 /// <feature>http://tizen.org/feature/security.tee</feature>
656 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
657 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
658 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
659 public SharedMemory AllocateSharedMemory(UInt32 size, SharedMemoryFlags flags)
661 Interop.TEEC_SharedMemory shm = new Interop.TEEC_SharedMemory();
663 shm.flags = (UInt32)flags;
664 int ret = Interop.Libteec.AllocateSharedMemory(ref context, ref shm);
665 Interop.CheckNThrowException(ret, "AllocateSharedMemory");
666 return new SharedMemory(shm);
670 /// This function deregisters or deallocates a previously initialized block of the shared memory.
673 /// For a memory buffer allocated using AllocateSharedMemory, the implementation must free the
674 /// underlying memory and the client application must not access this region after this function has been
675 /// called. In this case, the implementation must clear the buffer and size fields of the shared memory
676 /// structure before returning.
677 /// For memory registered using RegisterSharedMemory, the implementation must deregister the
678 /// underlying memory from the TEE, but the memory region will stay available to the client application for
679 /// other purposes as the memory is owned by it.
681 /// <since_tizen> 3 </since_tizen>
682 /// <param name="shm">The shared memory object returned by RegisterSharedMemory or AllocateSharedMemory.</param>
683 /// <privilege>http://tizen.org/privilege/tee.client</privilege>
684 /// <privlevel>partner</privlevel>
685 /// <feature>http://tizen.org/feature/security.tee</feature>
686 /// <exception cref="UnauthorizedAccessException">Thrown when an application does not have the privilege to access this method.</exception>
687 /// <exception cref="NotSupportedException">The required feature is not supported.</exception>
688 /// <exception cref="InvalidOperationException">The operation is invalid.</exception>
689 /// <exception cref="ArgumentException">The argument is wrong.</exception>
690 public void ReleaseSharedMemory(SharedMemory shm)
692 Interop.Libteec.ReleaseSharedMemory(ref shm.shm);