diff options
author | 2023-10-10 14:33:42 +0000 | |
---|---|---|
committer | 2023-10-10 14:33:42 +0000 | |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c')
-rw-r--r-- | roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c b/roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c new file mode 100644 index 000000000..2b2b0d420 --- /dev/null +++ b/roms/edk2/MdeModulePkg/Universal/RegularExpressionDxe/OnigurumaUefiPort.c @@ -0,0 +1,98 @@ +/** @file
+
+ Module to rewrite stdlib references within Oniguruma
+
+ (C) Copyright 2014-2015 Hewlett Packard Enterprise Development LP<BR>
+ Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include "OnigurumaUefiPort.h"
+
+#define ONIGMEM_HEAD_SIGNATURE SIGNATURE_32('o','m','h','d')
+
+typedef struct {
+ UINT32 Signature;
+ UINTN Size;
+} ONIGMEM_HEAD;
+
+#define ONIGMEM_OVERHEAD sizeof(ONIGMEM_HEAD)
+
+int EFIAPI sprintf_s(char *str, size_t sizeOfBuffer, char const *fmt, ...)
+{
+ VA_LIST Marker;
+ int NumberOfPrinted;
+
+ VA_START (Marker, fmt);
+ NumberOfPrinted = (int)AsciiVSPrint (str, sizeOfBuffer, fmt, Marker);
+ VA_END (Marker);
+
+ return NumberOfPrinted;
+}
+
+int OnigStrCmp (const char* Str1, const char* Str2)
+{
+ return (int)AsciiStrCmp (Str1, Str2);
+}
+
+int strlen(const char* str)
+{
+ return strlen_s(str, MAX_STRING_SIZE);
+}
+
+void * malloc (size_t size)
+{
+ ONIGMEM_HEAD *PoolHdr;
+ UINTN NewSize;
+ VOID *Data;
+
+ NewSize = (UINTN)(size) + ONIGMEM_OVERHEAD;
+
+ Data = AllocatePool (NewSize);
+ if (Data != NULL) {
+ PoolHdr = (ONIGMEM_HEAD *)Data;
+ PoolHdr->Signature = ONIGMEM_HEAD_SIGNATURE;
+ PoolHdr->Size = size;
+
+ return (VOID *)(PoolHdr + 1);
+ }
+ return NULL;
+}
+
+void * realloc (void *ptr, size_t size)
+{
+ ONIGMEM_HEAD *OldPoolHdr;
+ ONIGMEM_HEAD *NewPoolHdr;
+ UINTN OldSize;
+ UINTN NewSize;
+ VOID *Data;
+
+ NewSize = (UINTN)size + ONIGMEM_OVERHEAD;
+ Data = AllocatePool (NewSize);
+ if (Data != NULL) {
+ NewPoolHdr = (ONIGMEM_HEAD *)Data;
+ NewPoolHdr->Signature = ONIGMEM_HEAD_SIGNATURE;
+ NewPoolHdr->Size = size;
+ if (ptr != NULL) {
+ OldPoolHdr = (ONIGMEM_HEAD *)ptr - 1;
+ ASSERT (OldPoolHdr->Signature == ONIGMEM_HEAD_SIGNATURE);
+ OldSize = OldPoolHdr->Size;
+
+ CopyMem ((VOID *)(NewPoolHdr + 1), ptr, MIN (OldSize, size));
+ FreePool ((VOID *)OldPoolHdr);
+ }
+ return (VOID *)(NewPoolHdr + 1);
+ }
+ return NULL;
+}
+
+void* memcpy (void *dest, const void *src, unsigned int count)
+{
+ return CopyMem (dest, src, (UINTN)count);
+}
+
+void* memset (void *dest, char ch, unsigned int count)
+{
+ return SetMem (dest, ch, count);
+}
+
|