TianoCore EDK2 master
Loading...
Searching...
No Matches
OnigurumaUefiPort.c
Go to the documentation of this file.
1
11#include "OnigurumaUefiPort.h"
12
13#define ONIGMEM_HEAD_SIGNATURE SIGNATURE_32('o','m','h','d')
14
15typedef struct {
16 UINT32 Signature;
17 UINTN Size;
19
20#define ONIGMEM_OVERHEAD sizeof(ONIGMEM_HEAD)
21
22int EFIAPI
23sprintf_s (
24 char *str,
25 size_t sizeOfBuffer,
26 char const *fmt,
27 ...
28 )
29{
30 VA_LIST Marker;
31 int NumberOfPrinted;
32
33 VA_START (Marker, fmt);
34 NumberOfPrinted = (int)AsciiVSPrint (str, sizeOfBuffer, fmt, Marker);
35 VA_END (Marker);
36
37 return NumberOfPrinted;
38}
39
40int
41OnigStrCmp (
42 const char *Str1,
43 const char *Str2
44 )
45{
46 return (int)AsciiStrCmp (Str1, Str2);
47}
48
49int
50strlen (
51 const char *str
52 )
53{
54 return strlen_s (str, MAX_STRING_SIZE);
55}
56
57void *
58malloc (
59 size_t size
60 )
61{
62 ONIGMEM_HEAD *PoolHdr;
63 UINTN NewSize;
64 VOID *Data;
65
66 NewSize = (UINTN)(size) + ONIGMEM_OVERHEAD;
67
68 Data = AllocatePool (NewSize);
69 if (Data != NULL) {
70 PoolHdr = (ONIGMEM_HEAD *)Data;
71 PoolHdr->Signature = ONIGMEM_HEAD_SIGNATURE;
72 PoolHdr->Size = size;
73
74 return (VOID *)(PoolHdr + 1);
75 }
76
77 return NULL;
78}
79
80void *
81realloc (
82 void *ptr,
83 size_t size
84 )
85{
86 ONIGMEM_HEAD *OldPoolHdr;
87 ONIGMEM_HEAD *NewPoolHdr;
88 UINTN OldSize;
89 UINTN NewSize;
90 VOID *Data;
91
92 NewSize = (UINTN)size + ONIGMEM_OVERHEAD;
93 Data = AllocatePool (NewSize);
94 if (Data != NULL) {
95 NewPoolHdr = (ONIGMEM_HEAD *)Data;
96 NewPoolHdr->Signature = ONIGMEM_HEAD_SIGNATURE;
97 NewPoolHdr->Size = size;
98 if (ptr != NULL) {
99 OldPoolHdr = (ONIGMEM_HEAD *)ptr - 1;
100 ASSERT (OldPoolHdr->Signature == ONIGMEM_HEAD_SIGNATURE);
101 OldSize = OldPoolHdr->Size;
102
103 CopyMem ((VOID *)(NewPoolHdr + 1), ptr, MIN (OldSize, size));
104 FreePool ((VOID *)OldPoolHdr);
105 }
106
107 return (VOID *)(NewPoolHdr + 1);
108 }
109
110 return NULL;
111}
112
113#if !defined (MDE_CPU_ARM)
114void *
115memcpy (
116 void *dest,
117 const void *src,
118 unsigned int count
119 )
120{
121 return CopyMem (dest, src, (UINTN)count);
122}
123
124#endif
125
126void *
127memset (
128 void *dest,
129 int ch,
130 unsigned int count
131 )
132{
133 return SetMem (dest, (UINTN)count, (UINT8)ch);
134}
135
136void
137free (
138 void *ptr
139 )
140{
141 VOID *EvalOnce;
142 ONIGMEM_HEAD *PoolHdr;
143
144 EvalOnce = ptr;
145 if (EvalOnce == NULL) {
146 return;
147 }
148
149 PoolHdr = (ONIGMEM_HEAD *)EvalOnce - 1;
150 if (PoolHdr->Signature == ONIGMEM_HEAD_SIGNATURE) {
151 FreePool (PoolHdr);
152 } else {
153 FreePool (EvalOnce);
154 }
155}
UINT64 UINTN
INTN EFIAPI AsciiStrCmp(IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
Definition: String.c:716
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI AsciiVSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString, IN VA_LIST Marker)
Definition: PrintLib.c:702
#define NULL
Definition: Base.h:319
#define MIN(a, b)
Definition: Base.h:1007
#define VA_START(Marker, Parameter)
Definition: Base.h:661
CHAR8 * VA_LIST
Definition: Base.h:643
#define VA_END(Marker)
Definition: Base.h:691
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)