Merge branch 'master' into threads
This commit is contained in:
@@ -807,7 +807,7 @@ Shell::ReadCommand(OUT PWCHAR Buffer,
|
|||||||
* @param Handler
|
* @param Handler
|
||||||
* Supplies a pointer to the function that implements the command.
|
* Supplies a pointer to the function that implements the command.
|
||||||
*
|
*
|
||||||
* @return This routine returns a status code.
|
* @return This routine returns a status code indicating the success or failure of the operation.
|
||||||
*
|
*
|
||||||
* @since XT 1.0
|
* @since XT 1.0
|
||||||
*/
|
*/
|
||||||
@@ -835,6 +835,13 @@ Shell::RegisterCommand(IN PCWSTR Command,
|
|||||||
return STATUS_EFI_INVALID_PARAMETER;
|
return STATUS_EFI_INVALID_PARAMETER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check if the existing command string is lexicographically greater than the new command */
|
||||||
|
if(RTL::WideString::CompareWideStringInsensitive(CommandEntry->Command, Command, 0) > 0)
|
||||||
|
{
|
||||||
|
/* Break the traversal loop */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
/* Advance to the next entry */
|
/* Advance to the next entry */
|
||||||
ListEntry = ListEntry->Flink;
|
ListEntry = ListEntry->Flink;
|
||||||
}
|
}
|
||||||
@@ -852,8 +859,17 @@ Shell::RegisterCommand(IN PCWSTR Command,
|
|||||||
CommandEntry->Description = (PWCHAR)Description;
|
CommandEntry->Description = (PWCHAR)Description;
|
||||||
CommandEntry->Handler = Handler;
|
CommandEntry->Handler = Handler;
|
||||||
|
|
||||||
/* Append the command to the global shell commands list */
|
/* Check if the traversal reached the end of the command list */
|
||||||
|
if(ListEntry == &ShellCommands)
|
||||||
|
{
|
||||||
|
/* Append the new command entry to the tail of the list */
|
||||||
RTL::LinkedList::InsertTailList(&ShellCommands, &CommandEntry->Flink);
|
RTL::LinkedList::InsertTailList(&ShellCommands, &CommandEntry->Flink);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Insert the new command entry before the current item */
|
||||||
|
RTL::LinkedList::InsertHeadList(ListEntry->Blink, &CommandEntry->Flink);
|
||||||
|
}
|
||||||
|
|
||||||
/* Return success */
|
/* Return success */
|
||||||
return STATUS_EFI_SUCCESS;
|
return STATUS_EFI_SUCCESS;
|
||||||
|
|||||||
@@ -56,16 +56,16 @@ RTL::Memory::CompareMemory(IN PCVOID LeftBuffer,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine copies a block of memory.
|
* Copies a block of memory from a source buffer to a destination buffer.
|
||||||
*
|
*
|
||||||
* @param Destination
|
* @param Destination
|
||||||
* Supplies a pointer to the buffer where data will be copied to.
|
* Supplies a pointer to the target buffer where the data will be copied.
|
||||||
*
|
*
|
||||||
* @param Source
|
* @param Source
|
||||||
* Supplies a pointer to the source buffer that will be copied.
|
* Supplies a pointer to the source buffer containing the data to copy.
|
||||||
*
|
*
|
||||||
* @param Length
|
* @param Length
|
||||||
* Specifies the number of bytes to copy.
|
* Specifies the number of bytes to transfer.
|
||||||
*
|
*
|
||||||
* @return This routine does not return any value.
|
* @return This routine does not return any value.
|
||||||
*
|
*
|
||||||
@@ -77,13 +77,121 @@ RTL::Memory::CopyMemory(OUT PVOID Destination,
|
|||||||
IN PCVOID Source,
|
IN PCVOID Source,
|
||||||
IN SIZE_T Length)
|
IN SIZE_T Length)
|
||||||
{
|
{
|
||||||
PCHAR DestinationBytes = (PCHAR)Destination;
|
ULONG_PTR BytesToAlign, DestinationPointer, Remainder, SourcePointer, WordCount;
|
||||||
PCCHAR SourceBytes = (PCHAR)Source;
|
PULONG_PTR DestinationWord, SourceWord;
|
||||||
|
PCHAR DestinationByte, SourceByte;
|
||||||
|
|
||||||
/* Forward buffer copy */
|
/* Check if the payload is empty or the buffers are identical */
|
||||||
while(Length--)
|
if(Length == 0 || Destination == Source)
|
||||||
{
|
{
|
||||||
*DestinationBytes++ = *SourceBytes++;
|
/* No operation is required */
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Cast the pointers to scalar values */
|
||||||
|
DestinationPointer = (ULONG_PTR)Destination;
|
||||||
|
SourcePointer = (ULONG_PTR)Source;
|
||||||
|
|
||||||
|
/* Check if the destination overlaps the source in a destructive manner */
|
||||||
|
if(SourcePointer < DestinationPointer && DestinationPointer < (SourcePointer + Length))
|
||||||
|
{
|
||||||
|
/* Initialize the pointers for a backward traversal */
|
||||||
|
DestinationByte = (PCHAR)(DestinationPointer + Length);
|
||||||
|
SourceByte = (PCHAR)(SourcePointer + Length);
|
||||||
|
|
||||||
|
/* Calculate the number of trailing bytes */
|
||||||
|
BytesToAlign = ((ULONG_PTR)DestinationByte) & (sizeof(ULONG_PTR) - 1);
|
||||||
|
if(BytesToAlign > Length)
|
||||||
|
{
|
||||||
|
/* Clamp the alignment requirement */
|
||||||
|
BytesToAlign = Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute the alignment byte count from the remaining payload */
|
||||||
|
Length -= BytesToAlign;
|
||||||
|
|
||||||
|
/* Sequentially copy the unaligned trailing bytes */
|
||||||
|
while(BytesToAlign--)
|
||||||
|
{
|
||||||
|
/* Transfer a single byte */
|
||||||
|
*(--DestinationByte) = *(--SourceByte);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute the number of full words and any leftover */
|
||||||
|
WordCount = Length / sizeof(ULONG_PTR);
|
||||||
|
Remainder = Length & (sizeof(ULONG_PTR) - 1);
|
||||||
|
|
||||||
|
/* Elevate the byte pointers to word pointers */
|
||||||
|
DestinationWord = (PULONG_PTR)DestinationByte;
|
||||||
|
SourceWord = (PULONG_PTR)SourceByte;
|
||||||
|
|
||||||
|
/* Bulk data transfer */
|
||||||
|
while(WordCount--)
|
||||||
|
{
|
||||||
|
/* Transfer a full word */
|
||||||
|
*(--DestinationWord) = *(--SourceWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Downgrade the pointers back to byte */
|
||||||
|
DestinationByte = (PCHAR)DestinationWord;
|
||||||
|
SourceByte = (PCHAR)SourceWord;
|
||||||
|
|
||||||
|
/* Sequentially transfer any remaining bytes */
|
||||||
|
while(Remainder--)
|
||||||
|
{
|
||||||
|
/* Transfer a single byte */
|
||||||
|
*(--DestinationByte) = *(--SourceByte);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Calculate the number of leading bytes */
|
||||||
|
BytesToAlign = (sizeof(ULONG_PTR) - (DestinationPointer & (sizeof(ULONG_PTR) - 1))) & (sizeof(ULONG_PTR) - 1);
|
||||||
|
if(BytesToAlign > Length)
|
||||||
|
{
|
||||||
|
/* Clamp the alignment requirement */
|
||||||
|
BytesToAlign = Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute the alignment byte count from the remaining payload */
|
||||||
|
Length -= BytesToAlign;
|
||||||
|
|
||||||
|
/* Initialize the pointers for a forward traversal */
|
||||||
|
DestinationByte = (PCHAR)DestinationPointer;
|
||||||
|
SourceByte = (PCHAR)SourcePointer;
|
||||||
|
|
||||||
|
/* Sequentially copy the unaligned leading bytes */
|
||||||
|
while(BytesToAlign--)
|
||||||
|
{
|
||||||
|
/* Transfer a single byte */
|
||||||
|
*DestinationByte++ = *SourceByte++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Compute the number of full words and any leftover */
|
||||||
|
WordCount = Length / sizeof(ULONG_PTR);
|
||||||
|
Remainder = Length & (sizeof(ULONG_PTR) - 1);
|
||||||
|
|
||||||
|
/* Elevate the byte pointers to word pointers */
|
||||||
|
DestinationWord = (PULONG_PTR)DestinationByte;
|
||||||
|
SourceWord = (PULONG_PTR)SourceByte;
|
||||||
|
|
||||||
|
/* Bulk data transfer */
|
||||||
|
while(WordCount--)
|
||||||
|
{
|
||||||
|
/* Transfer a full word */
|
||||||
|
*DestinationWord++ = *SourceWord++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Downgrade the pointers back to byte */
|
||||||
|
DestinationByte = (PCHAR)DestinationWord;
|
||||||
|
SourceByte = (PCHAR)SourceWord;
|
||||||
|
|
||||||
|
/* Sequentially transfer any remaining bytes */
|
||||||
|
while(Remainder--)
|
||||||
|
{
|
||||||
|
/* Transfer a single byte */
|
||||||
|
*DestinationByte++ = *SourceByte++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,31 +218,9 @@ RTL::Memory::MoveMemory(OUT PVOID Destination,
|
|||||||
IN PCVOID Source,
|
IN PCVOID Source,
|
||||||
IN SIZE_T Length)
|
IN SIZE_T Length)
|
||||||
{
|
{
|
||||||
PCHAR DestinationBytes = (PCHAR)Destination;
|
/* Copy the memory */
|
||||||
PCHAR SourceBytes = (PCHAR)Source;
|
|
||||||
|
|
||||||
/* Make sure there is anything to copy */
|
|
||||||
if((!SourceBytes) && (!DestinationBytes))
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if source and destination overlaps */
|
|
||||||
if((DestinationBytes > SourceBytes) && (SourceBytes + Length > DestinationBytes))
|
|
||||||
{
|
|
||||||
/* Backward buffer copy */
|
|
||||||
while(Length)
|
|
||||||
{
|
|
||||||
DestinationBytes[Length - 1] = SourceBytes[Length - 1];
|
|
||||||
Length--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* Forward buffer copy */
|
|
||||||
CopyMemory(Destination, Source, Length);
|
CopyMemory(Destination, Source, Length);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This routine compares the first bytes of the specified memory buffers.
|
* This routine compares the first bytes of the specified memory buffers.
|
||||||
|
|||||||
Reference in New Issue
Block a user