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_ |
11 #define VBOOT_REFERENCE_UTILITY_H_ | 11 #define VBOOT_REFERENCE_UTILITY_H_ |
12 | 12 |
13 #include <inttypes.h> | 13 #include <inttypes.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
| 16 /* Combine [msw] and [lsw] uint16s to a uint32_t with its [msw] and |
| 17 * [lsw] forming the most and least signficant 16-bit words. |
| 18 */ |
| 19 #define CombineUint16Pair(msw,lsw) (((msw) << 16) | \ |
| 20 (((lsw)) & 0xFFFF)) |
| 21 /* Return the minimum of (a) or (b). */ |
| 22 #define Min(a, b) (((a) < (b)) ? (a) : (b)) |
| 23 |
16 /* Allocate [size] bytes and return a pointer to the allocated memory. Abort | 24 /* Allocate [size] bytes and return a pointer to the allocated memory. Abort |
17 * on error. | 25 * on error. |
18 */ | 26 */ |
19 void* Malloc(size_t size); | 27 void* Malloc(size_t size); |
20 | 28 |
21 /* Free memory pointed by [ptr] previously allocated by Malloc(). */ | 29 /* Free memory pointed by [ptr] previously allocated by Malloc(). */ |
22 void Free(void* ptr); | 30 void Free(void* ptr); |
23 | 31 |
24 /* Copy [n] bytes from [src] to [dest]. */ | 32 /* Copy [n] bytes from [src] to [dest]. */ |
25 void* Memcpy(void* dest, const void* src, size_t n); | 33 void* Memcpy(void* dest, const void* src, size_t n); |
(...skipping 27 matching lines...) Expand all Loading... |
53 * data from [src] into the buffer encapsulated in state [state]. | 61 * data from [src] into the buffer encapsulated in state [state]. |
54 * On success, return [src] and update [state]. | 62 * On success, return [src] and update [state]. |
55 * On failure, return NULL, set remaining_len in state to -1. | 63 * On failure, return NULL, set remaining_len in state to -1. |
56 * | 64 * |
57 * Useful for iterating through a structure to populate a binary blob. After the | 65 * Useful for iterating through a structure to populate a binary blob. After the |
58 * first failure (buffer overrun), successive calls will always fail. | 66 * first failure (buffer overrun), successive calls will always fail. |
59 */ | 67 */ |
60 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, int len); | 68 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, int len); |
61 | 69 |
62 #endif /* VBOOT_REFERENCE_UTILITY_H_ */ | 70 #endif /* VBOOT_REFERENCE_UTILITY_H_ */ |
OLD | NEW |