diff --git a/MdePkg/Include/Library/UefiLib.h b/MdePkg/Include/Library/UefiLib.h
index fd3bdac53e..428235cbf2 100644
--- a/MdePkg/Include/Library/UefiLib.h
+++ b/MdePkg/Include/Library/UefiLib.h
@@ -415,6 +415,34 @@ EfiCreateEventLegacyBoot (
   OUT EFI_EVENT  *LegacyBootEvent
   );
 
+/**
+  Create an EFI event in the Legacy Boot Event Group and allows
+  the caller to specify a notification function.  
+  
+  This function abstracts the creation of the Legacy Boot Event.
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.
+  This library abstracts the caller from how this event is created to prevent
+  to code form having to change with the version of the specification supported.
+  If LegacyBootEvent is NULL, then ASSERT().
+
+  @param  NotifyTpl         The task priority level of the event.
+  @param  NotifyFunction    The notification function to call when the event is signaled.
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).
+
+  @retval EFI_SUCCESS       Event was created.
+  @retval Other             Event was not created.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiCreateEventLegacyBootEx (
+  IN  EFI_TPL           NotifyTpl,
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL
+  IN  VOID              *NotifyContext,  OPTIONAL
+  OUT EFI_EVENT         *LegacyBootEvent
+  );
+
 /**
   Create a Read to Boot Event.  
   
@@ -437,6 +465,34 @@ EfiCreateEventReadyToBoot (
   OUT EFI_EVENT  *ReadyToBootEvent
   );
 
+/**
+  Create an EFI event in the Ready To Boot Event Group and allows
+  the caller to specify a notification function.  
+  
+  This function abstracts the creation of the Ready to Boot Event.
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.
+  This library abstracts the caller from how this event is created to prevent
+  to code form having to change with the version of the specification supported.
+  If ReadyToBootEvent is NULL, then ASSERT().
+
+  @param  NotifyTpl         The task priority level of the event.
+  @param  NotifyFunction    The notification function to call when the event is signaled.
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).
+
+  @retval EFI_SUCCESS       Event was created.
+  @retval Other             Event was not created.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiCreateEventReadyToBootEx (
+  IN  EFI_TPL           NotifyTpl,
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL
+  IN  VOID              *NotifyContext,  OPTIONAL
+  OUT EFI_EVENT         *ReadyToBootEvent
+  );
+
 /**
   Initialize a Firmware Volume (FV) Media Device Path node.
   
diff --git a/MdePkg/Library/BaseLib/Math64.c b/MdePkg/Library/BaseLib/Math64.c
index 27d75232c5..57dcca387f 100644
--- a/MdePkg/Library/BaseLib/Math64.c
+++ b/MdePkg/Library/BaseLib/Math64.c
@@ -121,14 +121,14 @@ InternalMathDivU64x32 (
   return Dividend / Divisor;
 }
 
-UINT64
+UINT32
 EFIAPI
 InternalMathModU64x32 (
   IN      UINT64                    Dividend,
   IN      UINT32                    Divisor
   )
 {
-  return Dividend % Divisor;
+  return (UINT32)(Dividend % Divisor);
 }
 
 UINT64
diff --git a/MdePkg/Library/BasePciCf8Lib/PciLib.c b/MdePkg/Library/BasePciCf8Lib/PciLib.c
index fe27c850c1..108c95291c 100644
--- a/MdePkg/Library/BasePciCf8Lib/PciLib.c
+++ b/MdePkg/Library/BasePciCf8Lib/PciLib.c
@@ -1298,6 +1298,11 @@ PciCf8ReadBuffer (
 {
   UINTN                             EndAddress;
 
+  ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);
+  ASSERT (Buffer != NULL);
+
   EndAddress = StartAddress + Size;
 
   if (StartAddress < EndAddress && (StartAddress & 1)) {
@@ -1382,6 +1387,11 @@ PciCf8WriteBuffer (
 {
   UINTN                             EndAddress;
 
+  ASSERT_INVALID_PCI_ADDRESS (StartAddress, 0);
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);
+  ASSERT (Buffer != NULL);
+
   EndAddress = StartAddress + Size;
 
   if ((StartAddress < EndAddress) && ((StartAddress & 1)!= 0)) {
diff --git a/MdePkg/Library/BasePciExpressLib/PciLib.c b/MdePkg/Library/BasePciExpressLib/PciLib.c
index 3003613486..de33bf3055 100644
--- a/MdePkg/Library/BasePciExpressLib/PciLib.c
+++ b/MdePkg/Library/BasePciExpressLib/PciLib.c
@@ -1195,6 +1195,11 @@ PciExpressReadBuffer (
 {
   UINTN                             EndAddress;
 
+  ASSERT_INVALID_PCI_ADDRESS (StartAddress);
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);
+  ASSERT (Buffer != NULL);
+
   EndAddress = StartAddress + Size;
 
   if (StartAddress < EndAddress && (StartAddress & 1)) {
@@ -1278,6 +1283,11 @@ PciExpressWriteBuffer (
 {
   UINTN                             EndAddress;
 
+  ASSERT_INVALID_PCI_ADDRESS (StartAddress);
+  ASSERT (((StartAddress & 0xFFF) + Size) <= 0x1000);
+  ASSERT ((StartAddress + Size - 1) <= 0x0FFFFFFF);
+  ASSERT (Buffer != NULL);
+
   EndAddress = StartAddress + Size;
 
   if ((StartAddress < EndAddress) && ((StartAddress & 1)!= 0)) {
diff --git a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
index 088a10bb56..15a419bc56 100644
--- a/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/DxeMemoryAllocationLib/MemoryAllocationLib.c
@@ -474,6 +474,9 @@ InternalAllocateCopyPool (
 {
   VOID  *Memory;
 
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = InternalAllocatePool (PoolType, AllocationSize);
   if (Memory != NULL) {
      Memory = CopyMem (Memory, Buffer, AllocationSize);
@@ -793,6 +796,9 @@ InternalAllocateAlignedCopyPool (
 {
   VOID  *Memory;
   
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);
   if (Memory != NULL) {
     Memory = CopyMem (Memory, Buffer, AllocationSize);
diff --git a/MdePkg/Library/PeiIoLibCpuIo/IoLib.c b/MdePkg/Library/PeiIoLibCpuIo/IoLib.c
index 2156f6b480..1da0203b5c 100644
--- a/MdePkg/Library/PeiIoLibCpuIo/IoLib.c
+++ b/MdePkg/Library/PeiIoLibCpuIo/IoLib.c
@@ -39,7 +39,6 @@ IoRead8 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
 
   return CpuIo->IoRead8 (PeiServices, CpuIo, (UINT64) Port);
@@ -72,7 +71,6 @@ IoWrite8 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
 
   CpuIo->IoWrite8 (PeiServices, CpuIo, (UINT64) Port, Value);
@@ -104,9 +102,11 @@ IoRead16 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 16-bit boundary.
+  //
+  ASSERT ((Port & 1) == 0);
   return CpuIo->IoRead16 (PeiServices, CpuIo, (UINT64) Port);
 }
 
@@ -137,9 +137,11 @@ IoWrite16 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 16-bit boundary.
+  //
+  ASSERT ((Port & 1) == 0);
   CpuIo->IoWrite16 (PeiServices, CpuIo, (UINT64) Port, Value);
   return Value;
 }
@@ -169,9 +171,11 @@ IoRead32 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 32-bit boundary.
+  //
+  ASSERT ((Port & 3) == 0);
   return CpuIo->IoRead32 (PeiServices, CpuIo, (UINT64) Port);
 }
 
@@ -202,9 +206,11 @@ IoWrite32 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 32-bit boundary.
+  //
+  ASSERT ((Port & 3) == 0);
   CpuIo->IoWrite32 (PeiServices, CpuIo, (UINT64) Port, Value);
   return Value;
 }
@@ -234,9 +240,11 @@ IoRead64 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 64-bit boundary.
+  //
+  ASSERT ((Port & 7) == 0);
   return CpuIo->IoRead64 (PeiServices, CpuIo, (UINT64) Port);
 }
 
@@ -267,9 +275,11 @@ IoWrite64 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Port is aligned on a 64-bit boundary.
+  //
+  ASSERT ((Port & 7) == 0);
   CpuIo->IoWrite64 (PeiServices, CpuIo, (UINT64) Port, Value);
   return Value;;
 }
@@ -299,7 +309,6 @@ MmioRead8 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
 
   return CpuIo->MemRead8 (PeiServices, CpuIo, (UINT64) Address);
@@ -330,7 +339,6 @@ MmioWrite8 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
 
   CpuIo->MemWrite8 (PeiServices, CpuIo, (UINT64) Address, Value);
@@ -362,9 +370,11 @@ MmioRead16 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 16-bit boundary.
+  //
+  ASSERT ((Address & 1) == 0);
   return CpuIo->MemRead16 (PeiServices, CpuIo, (UINT64) Address);
 
 }
@@ -394,9 +404,11 @@ MmioWrite16 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 16-bit boundary.
+  //
+  ASSERT ((Address & 1) == 0);
   CpuIo->MemWrite16 (PeiServices, CpuIo, (UINT64) Address, Value);
   return Value;
 }
@@ -426,9 +438,11 @@ MmioRead32 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 32-bit boundary.
+  //
+  ASSERT ((Address & 3) == 0);
   return CpuIo->MemRead32 (PeiServices, CpuIo, (UINT64) Address);
 
 }
@@ -458,9 +472,11 @@ MmioWrite32 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 32-bit boundary.
+  //
+  ASSERT ((Address & 3) == 0);
   CpuIo->MemWrite32 (PeiServices, CpuIo, (UINT64) Address, Value);
   return Value;
 }
@@ -490,9 +506,11 @@ MmioRead64 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 64-bit boundary.
+  //
+  ASSERT ((Address & 7) == 0);
   return CpuIo->MemRead64 (PeiServices, CpuIo, (UINT64) Address);
 
 }
@@ -522,9 +540,11 @@ MmioWrite64 (
 
   PeiServices = GetPeiServicesTablePointer ();
   CpuIo       = (*PeiServices)->CpuIo;
-
   ASSERT (CpuIo != NULL);
-
+  //
+  // Make sure Address is aligned on a 64-bit boundary.
+  //
+  ASSERT ((Address & 7) == 0);
   CpuIo->MemWrite64 (PeiServices, CpuIo, (UINT64) Address, Value);
   return Value;
 }
diff --git a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
index 274287cf03..59e9a26238 100644
--- a/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
+++ b/MdePkg/Library/PeiMemoryAllocationLib/MemoryAllocationLib.c
@@ -451,6 +451,9 @@ InternalAllocateCopyPool (
 {
   VOID  *Memory;
 
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = InternalAllocatePool (PoolType, AllocationSize);
   if (Memory != NULL) {
      Memory = CopyMem (Memory, Buffer, AllocationSize);
@@ -477,6 +480,9 @@ AllocateCopyPool (
 {
   VOID  *Memory;
 
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = AllocatePool (AllocationSize);
   if (Memory != NULL) {
      Memory = CopyMem (Memory, Buffer, AllocationSize);
@@ -791,6 +797,9 @@ InternalAllocateAlignedCopyPool (
 {
   VOID  *Memory;
   
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = InternalAllocateAlignedPool (PoolType, AllocationSize, Alignment);
   if (Memory != NULL) {
     Memory = CopyMem (Memory, Buffer, AllocationSize);
@@ -820,6 +829,9 @@ AllocateAlignedCopyPool (
 {
   VOID  *Memory;
   
+  ASSERT (Buffer != NULL);
+  ASSERT (AllocationSize <= (MAX_ADDRESS - (UINTN) Buffer + 1));
+
   Memory = AllocateAlignedPool (AllocationSize, Alignment);
   if (Memory != NULL) {
     Memory = CopyMem (Memory, Buffer, AllocationSize);
diff --git a/MdePkg/Library/UefiLib/UefiNotTiano.c b/MdePkg/Library/UefiLib/UefiNotTiano.c
index f883c1d3c6..770d76df7e 100644
--- a/MdePkg/Library/UefiLib/UefiNotTiano.c
+++ b/MdePkg/Library/UefiLib/UefiNotTiano.c
@@ -16,7 +16,21 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 
 **/
 
-
+/**
+  An empty function to pass error checking of CreateEventEx (). 
+  
+  This empty function enusres that EFI_EVENT_NOTIFY_SIGNAL_ALL is error
+  checked correctly since it is now mapped into CreateEventEx() in UEFI 2.0.
+  
+**/
+VOID
+InternalEmptyFuntion (
+  IN EFI_EVENT                Event,
+  IN VOID                     *Context
+  )
+{
+  return;
+}
 
 /**
   Create a Legacy Boot Event.  
@@ -39,6 +53,42 @@ EFIAPI
 EfiCreateEventLegacyBoot (
   OUT EFI_EVENT  *LegacyBootEvent
   )
+{
+  return EfiCreateEventLegacyBootEx (
+           EFI_TPL_CALLBACK,
+           InternalEmptyFuntion,
+           NULL,
+           LegacyBootEvent
+           );
+}
+
+/**
+  Create an EFI event in the Legacy Boot Event Group and allows
+  the caller to specify a notification function.  
+  
+  This function abstracts the creation of the Legacy Boot Event.
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.
+  This library abstracts the caller from how this event is created to prevent
+  to code form having to change with the version of the specification supported.
+  If LegacyBootEvent is NULL, then ASSERT().
+
+  @param  NotifyTpl         The task priority level of the event.
+  @param  NotifyFunction    The notification function to call when the event is signaled.
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).
+
+  @retval EFI_SUCCESS       Event was created.
+  @retval Other             Event was not created.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiCreateEventLegacyBootEx (
+  IN  EFI_TPL           NotifyTpl,
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL
+  IN  VOID              *NotifyContext,  OPTIONAL
+  OUT EFI_EVENT         *LegacyBootEvent
+  )
 {
   EFI_STATUS    Status;
 
@@ -50,9 +100,9 @@ EfiCreateEventLegacyBoot (
   //
   Status = gBS->CreateEvent (
                   EFI_EVENT_SIGNAL_LEGACY_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
-                  EFI_TPL_CALLBACK,
-                  NULL,
-                  NULL,
+                  NotifyTpl,
+                  NotifyFunction,
+                  NotifyContext,
                   LegacyBootEvent
                   );
 #else
@@ -61,18 +111,17 @@ EfiCreateEventLegacyBoot (
   //
   Status = gBS->CreateEventEx (
                   EVENT_NOTIFY_SIGNAL,
-                  EFI_TPL_CALLBACK,
-                  NULL,
-                  NULL,
+                  NotifyTpl,
+                  NotifyFunction,
+                  NotifyContext,
                   &gEfiEventLegacyBootGuid,
                   LegacyBootEvent
                   );
 #endif
+
   return Status;
 }
 
-
-
 /**
   Create a Read to Boot Event.  
   
@@ -94,6 +143,42 @@ EFIAPI
 EfiCreateEventReadyToBoot (
   OUT EFI_EVENT  *ReadyToBootEvent
   )
+{
+  return EfiCreateEventReadyToBootEx (
+           EFI_TPL_CALLBACK,
+           InternalEmptyFuntion,
+           NULL,
+           ReadyToBootEvent
+           );
+}
+
+/**
+  Create an EFI event in the Ready To Boot Event Group and allows
+  the caller to specify a notification function.  
+  
+  This function abstracts the creation of the Ready to Boot Event.
+  The Framework moved from a proprietary to UEFI 2.0 based mechanism.
+  This library abstracts the caller from how this event is created to prevent
+  to code form having to change with the version of the specification supported.
+  If ReadyToBootEvent is NULL, then ASSERT().
+
+  @param  NotifyTpl         The task priority level of the event.
+  @param  NotifyFunction    The notification function to call when the event is signaled.
+  @param  NotifyContext     The content to pass to NotifyFunction when the event is signaled.
+  @param  LegacyBootEvent   Returns the EFI event returned from gBS->CreateEvent(Ex).
+
+  @retval EFI_SUCCESS       Event was created.
+  @retval Other             Event was not created.
+
+**/
+EFI_STATUS
+EFIAPI
+EfiCreateEventReadyToBootEx (
+  IN  EFI_TPL           NotifyTpl,
+  IN  EFI_EVENT_NOTIFY  NotifyFunction,  OPTIONAL
+  IN  VOID              *NotifyContext,  OPTIONAL
+  OUT EFI_EVENT         *ReadyToBootEvent
+  )
 {
   EFI_STATUS    Status;
 
@@ -105,9 +190,9 @@ EfiCreateEventReadyToBoot (
   //
   Status = gBS->CreateEvent (
                   EFI_EVENT_SIGNAL_READY_TO_BOOT | EFI_EVENT_NOTIFY_SIGNAL_ALL,
-                  EFI_TPL_CALLBACK,
-                  NULL,
-                  NULL,
+                  NotifyTpl,
+                  NotifyFunction,
+                  NotifyContext,
                   ReadyToBootEvent
                   );
 #else
@@ -116,9 +201,9 @@ EfiCreateEventReadyToBoot (
   //
   Status = gBS->CreateEventEx (
                   EVENT_NOTIFY_SIGNAL,
-                  EFI_TPL_CALLBACK,
-                  NULL,
-                  NULL,
+                  NotifyTpl,
+                  NotifyFunction,
+                  NotifyContext,
                   &gEfiEventReadyToBootGuid,
                   ReadyToBootEvent
                   );