1 /** @file
2   SetMem() and SetMemN() implementation.
3 
4   The following BaseMemoryLib instances contain the same copy of this file:
5 
6     BaseMemoryLib
7     BaseMemoryLibMmx
8     BaseMemoryLibSse2
9     BaseMemoryLibRepStr
10     BaseMemoryLibOptDxe
11     BaseMemoryLibOptPei
12     PeiMemoryLib
13     UefiMemoryLib
14 
15   Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
16   This program and the accompanying materials
17   are licensed and made available under the terms and conditions of the BSD License
18   which accompanies this distribution.  The full text of the license may be found at
19   http://opensource.org/licenses/bsd-license.php.
20 
21   THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
22   WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
23 
24 **/
25 
26 #include "MemLibInternals.h"
27 
28 /**
29   Fills a target buffer with a byte value, and returns the target buffer.
30 
31   This function fills Length bytes of Buffer with Value, and returns Buffer.
32 
33   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
34 
35   @param  Buffer    The memory to set.
36   @param  Length    The number of bytes to set.
37   @param  Value     The value with which to fill Length bytes of Buffer.
38 
39   @return Buffer.
40 
41 **/
42 VOID *
43 EFIAPI
SetMem(OUT VOID * Buffer,IN UINTN Length,IN UINT8 Value)44 SetMem (
45   OUT VOID  *Buffer,
46   IN UINTN  Length,
47   IN UINT8  Value
48   )
49 {
50   if (Length == 0) {
51     return Buffer;
52   }
53 
54   ASSERT ((Length - 1) <= (MAX_ADDRESS - (UINTN)Buffer));
55 
56   return InternalMemSetMem (Buffer, Length, Value);
57 }
58 
59 /**
60   Fills a target buffer with a value that is size UINTN, and returns the target buffer.
61 
62   This function fills Length bytes of Buffer with the UINTN sized value specified by
63   Value, and returns Buffer. Value is repeated every sizeof(UINTN) bytes for Length
64   bytes of Buffer.
65 
66   If Length > 0 and Buffer is NULL, then ASSERT().
67   If Length is greater than (MAX_ADDRESS - Buffer + 1), then ASSERT().
68   If Buffer is not aligned on a UINTN boundary, then ASSERT().
69   If Length is not aligned on a UINTN boundary, then ASSERT().
70 
71   @param  Buffer  The pointer to the target buffer to fill.
72   @param  Length  The number of bytes in Buffer to fill.
73   @param  Value   The value with which to fill Length bytes of Buffer.
74 
75   @return Buffer.
76 
77 **/
78 VOID *
79 EFIAPI
SetMemN(OUT VOID * Buffer,IN UINTN Length,IN UINTN Value)80 SetMemN (
81   OUT VOID  *Buffer,
82   IN UINTN  Length,
83   IN UINTN  Value
84   )
85 {
86   if (sizeof (UINTN) == sizeof (UINT64)) {
87     return SetMem64 (Buffer, Length, (UINT64)Value);
88   } else {
89     return SetMem32 (Buffer, Length, (UINT32)Value);
90   }
91 }
92