ReactOS  0.4.14-dev-376-gaedba84
flatbuf.c File Reference
#include "precomp.h"
Include dependency graph for flatbuf.c:

Go to the source code of this file.

Functions

VOID WINAPI FlatBuf_Init (IN PFLATBUFF FlatBuffer, IN PVOID Buffer, IN SIZE_T Size)
 
PVOID WINAPI FlatBuf_Arg_Reserve (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_CopyMemory (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID Buffer, IN SIZE_T Size, IN ULONG Align)
 
PVOID WINAPI FlatBuf_Arg_WriteString (IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN PVOID String, IN BOOLEAN IsUnicode)
 

Function Documentation

◆ FlatBuf_Arg_CopyMemory()

PVOID WINAPI FlatBuf_Arg_CopyMemory ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  Buffer,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 60 of file flatbuf.c.

65 {
67 
68  /* First reserve the memory */
69  Destination = FlatBuf_Arg_Reserve(Position, FreeSize, Size, Align);
70  if (Destination)
71  {
72  /* We have space, do the copy */
74  }
75 
76  /* Return the pointer to the data */
77  return Destination;
78 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
static COORD Position
Definition: mouse.c:34
PVOID WINAPI FlatBuf_Arg_Reserve(IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
Definition: flatbuf.c:32
Definition: bufpool.h:45
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359

◆ FlatBuf_Arg_Reserve()

PVOID WINAPI FlatBuf_Arg_Reserve ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN SIZE_T  Size,
IN ULONG  Align 
)

Definition at line 32 of file flatbuf.c.

36 {
37  ULONG_PTR NewPosition, OldPosition = *Position;
38  SIZE_T NewFreeSize = *FreeSize;
39 
40  /* Start by aligning our position */
41  if (Align) OldPosition += (Align - 1) & ~Align;
42 
43  /* Update it */
44  NewPosition = OldPosition + Size;
45 
46  /* Update Free Size */
47  NewFreeSize += (OldPosition - NewPosition);
48 
49  /* Save new values */
50  *Position = NewPosition;
51  *FreeSize = NewFreeSize;
52 
53  /* Check if we're out of space or not */
54  if (NewFreeSize > 0) return (PVOID)OldPosition;
55  return NULL;
56 }
static COORD Position
Definition: mouse.c:34
uint32_t ULONG_PTR
Definition: typedefs.h:63
smooth NULL
Definition: ftsmooth.c:416
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
ULONG_PTR SIZE_T
Definition: typedefs.h:78

Referenced by FlatBuf_Arg_CopyMemory(), FlatBuf_Arg_ReserveAlignPointer(), and FlatBuf_Arg_WriteString().

◆ FlatBuf_Arg_WriteString()

PVOID WINAPI FlatBuf_Arg_WriteString ( IN OUT PULONG_PTR  Position,
IN OUT PSIZE_T  FreeSize,
IN PVOID  String,
IN BOOLEAN  IsUnicode 
)

Definition at line 82 of file flatbuf.c.

86 {
88  SIZE_T StringLength;
89  ULONG Align;
90 
91  /* Calculate the string length */
92  if (IsUnicode)
93  {
94  /* Get the length in bytes and use WCHAR alignment */
95  StringLength = (wcslen((LPWSTR)String) + 1) * sizeof(WCHAR);
96  Align = sizeof(WCHAR);
97  }
98  else
99  {
100  /* Get the length in bytes and use CHAR alignment */
101  StringLength = strlen((LPSTR)String) + 1;
102  Align = sizeof(CHAR);
103  }
104 
105  /* Now reserve the memory */
106  Destination = FlatBuf_Arg_Reserve(Position, FreeSize, StringLength, Align);
107  if (Destination)
108  {
109  /* We have space, do the copy */
110  RtlCopyMemory(Destination, String, StringLength);
111  }
112 
113  /* Return the pointer to the data */
114  return Destination;
115 }
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static COORD Position
Definition: mouse.c:34
static WCHAR String[]
Definition: stringtable.c:55
char * LPSTR
Definition: xmlstorage.h:182
PVOID WINAPI FlatBuf_Arg_Reserve(IN OUT PULONG_PTR Position, IN OUT PSIZE_T FreeSize, IN SIZE_T Size, IN ULONG Align)
Definition: flatbuf.c:32
__wchar_t WCHAR
Definition: xmlstorage.h:180
_In_ PUNICODE_STRING _Inout_ PUNICODE_STRING Destination
Definition: rtlfuncs.h:2891
ULONG_PTR SIZE_T
Definition: typedefs.h:78
unsigned int ULONG
Definition: retypes.h:1
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define CHAR(Char)
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)

◆ FlatBuf_Init()

VOID WINAPI FlatBuf_Init ( IN PFLATBUFF  FlatBuffer,
IN PVOID  Buffer,
IN SIZE_T  Size 
)

Definition at line 17 of file flatbuf.c.

20 {
21  /* Set up the Flat Buffer start, current and ending position */
22  FlatBuffer->Buffer = Buffer;
23  FlatBuffer->BufferPos = (ULONG_PTR)Buffer;
24  FlatBuffer->BufferEnd = (PVOID)(FlatBuffer->BufferPos + Size);
25 
26  /* Setup the current size and the available size */
27  FlatBuffer->BufferSize = FlatBuffer->BufferFreeSize = Size;
28 }
Definition: bufpool.h:45
void * PVOID
Definition: retypes.h:9
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
#define ULONG_PTR
Definition: config.h:101
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34