OLD | NEW |
1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 /* Helper functions/wrappers for memory allocations, manipulation and | 6 /* Helper functions/wrappers for memory allocations, manipulation and |
7 * comparison. | 7 * comparison. |
8 */ | 8 */ |
9 | 9 |
10 #ifndef VBOOT_REFERENCE_UTILITY_H_ | 10 #ifndef VBOOT_REFERENCE_UTILITY_H_ |
(...skipping 22 matching lines...) Expand all Loading... |
33 #define Min(a, b) (((a) < (b)) ? (a) : (b)) | 33 #define Min(a, b) (((a) < (b)) ? (a) : (b)) |
34 | 34 |
35 /* Allocate [size] bytes and return a pointer to the allocated memory. Abort | 35 /* Allocate [size] bytes and return a pointer to the allocated memory. Abort |
36 * on error. | 36 * on error. |
37 */ | 37 */ |
38 void* Malloc(size_t size); | 38 void* Malloc(size_t size); |
39 | 39 |
40 /* Free memory pointed by [ptr] previously allocated by Malloc(). */ | 40 /* Free memory pointed by [ptr] previously allocated by Malloc(). */ |
41 void Free(void* ptr); | 41 void Free(void* ptr); |
42 | 42 |
| 43 /* Compare [n] bytes in [src1] and [src2] |
| 44 * Returns an integer less than, equal to, or greater than zero if the first [n] |
| 45 * bytes of [src1] is found, respectively, to be less than, to match, or be |
| 46 * greater than the first n bytes of [src2]. */ |
| 47 int Memcmp(const void* src1, const void* src2, size_t n); |
| 48 |
43 /* Copy [n] bytes from [src] to [dest]. */ | 49 /* Copy [n] bytes from [src] to [dest]. */ |
44 void* Memcpy(void* dest, const void* src, size_t n); | 50 void* Memcpy(void* dest, const void* src, size_t n); |
45 | 51 |
46 /* Set [n] bytes starting at [s] to [c]. */ | 52 /* Set [n] bytes starting at [s] to [c]. */ |
47 void* Memset(void *dest, const uint8_t c, size_t n); | 53 void* Memset(void *dest, const uint8_t c, size_t n); |
48 | 54 |
49 /* Compare [n] bytes starting at [s1] with [s2] and return 0 if they match, | 55 /* Compare [n] bytes starting at [s1] with [s2] and return 0 if they match, |
50 * 1 if they don't. Time taken to perform the comparison is only dependent on | 56 * 1 if they don't. Time taken to perform the comparison is only dependent on |
51 * [n] and not on the relationship of the match between [s1] and [s2]. | 57 * [n] and not on the relationship of the match between [s1] and [s2]. |
52 */ | 58 */ |
(...skipping 20 matching lines...) Expand all Loading... |
73 * data from [src] into the buffer encapsulated in state [state]. | 79 * data from [src] into the buffer encapsulated in state [state]. |
74 * On success, return [src] and update [state]. | 80 * On success, return [src] and update [state]. |
75 * On failure, return NULL, set remaining_len in state to -1. | 81 * On failure, return NULL, set remaining_len in state to -1. |
76 * | 82 * |
77 * Useful for iterating through a structure to populate a binary blob. After the | 83 * Useful for iterating through a structure to populate a binary blob. After the |
78 * first failure (buffer overrun), successive calls will always fail. | 84 * first failure (buffer overrun), successive calls will always fail. |
79 */ | 85 */ |
80 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, uint64_t len); | 86 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, uint64_t len); |
81 | 87 |
82 #endif /* VBOOT_REFERENCE_UTILITY_H_ */ | 88 #endif /* VBOOT_REFERENCE_UTILITY_H_ */ |
OLD | NEW |