TianoCore EDK2 master
Loading...
Searching...
No Matches
CrtWrapper.c
Go to the documentation of this file.
1
10#include <Base.h>
11#include <Library/BaseLib.h>
12#include <Library/DebugLib.h>
14#include <stdio.h>
15
17
18int
19my_snprintf (
20 char *str,
21 size_t size,
22 const char *format,
23 ...
24 )
25{
26 return 0;
27}
28
29//
30// Extra header to record the memory buffer size from malloc routine.
31//
32#define CRYPTMEM_HEAD_SIGNATURE SIGNATURE_32('c','m','h','d')
33typedef struct {
34 UINT32 Signature;
35 UINT32 Reserved;
36 UINTN Size;
38
39#define CRYPTMEM_OVERHEAD sizeof(CRYPTMEM_HEAD)
40
41//
42// -- Memory-Allocation Routines --
43//
44
45/* Allocates memory blocks */
46void *
47mbedtls_calloc (
48 size_t num,
49 size_t size
50 )
51{
52 CRYPTMEM_HEAD *PoolHdr;
53 UINTN NewSize;
54 VOID *Data;
55
56 //
57 // Adjust the size by the buffer header overhead
58 //
59 NewSize = (UINTN)(size * num) + CRYPTMEM_OVERHEAD;
60
61 Data = AllocateZeroPool (NewSize);
62 if (Data != NULL) {
63 PoolHdr = (CRYPTMEM_HEAD *)Data;
64 //
65 // Record the memory brief information
66 //
67 PoolHdr->Signature = CRYPTMEM_HEAD_SIGNATURE;
68 PoolHdr->Size = size;
69
70 return (VOID *)(PoolHdr + 1);
71 } else {
72 //
73 // The buffer allocation failed.
74 //
75 return NULL;
76 }
77}
78
79/* De-allocates or frees a memory block */
80void
81mbedtls_free (
82 void *ptr
83 )
84{
85 CRYPTMEM_HEAD *PoolHdr;
86
87 //
88 // In Standard C, free() handles a null pointer argument transparently. This
89 // is not true of FreePool() below, so protect it.
90 //
91 if (ptr != NULL) {
92 PoolHdr = (CRYPTMEM_HEAD *)ptr - 1;
93 ASSERT (PoolHdr->Signature == CRYPTMEM_HEAD_SIGNATURE);
94 FreePool (PoolHdr);
95 }
96}
UINT64 UINTN
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319