Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(816)

Side by Side Diff: src/platform/vboot_reference/include/utility.h

Issue 1519008: VBoot Reference: 18 Exabytes ought to be enough for everybody (Closed)
Patch Set: Use symbolic constants. Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 26 matching lines...) Expand all
37 37
38 /* Compare [n] bytes starting at [s1] with [s2] and return 0 if they match, 38 /* Compare [n] bytes starting at [s1] with [s2] and return 0 if they match,
39 * 1 if they don't. Time taken to perform the comparison is only dependent on 39 * 1 if they don't. Time taken to perform the comparison is only dependent on
40 * [n] and not on the relationship of the match between [s1] and [s2]. 40 * [n] and not on the relationship of the match between [s1] and [s2].
41 */ 41 */
42 int SafeMemcmp(const void* s1, const void* s2, size_t n); 42 int SafeMemcmp(const void* s1, const void* s2, size_t n);
43 43
44 /* Track remaining data to be read in a buffer. */ 44 /* Track remaining data to be read in a buffer. */
45 typedef struct MemcpyState { 45 typedef struct MemcpyState {
46 void* remaining_buf; 46 void* remaining_buf;
47 uint64_t remaining_len; 47 uint64_t remaining_len; /* Remaining length of the buffer. */
48 uint8_t overrun; /* Flag set to 1 when an overrun occurs. */
48 } MemcpyState; 49 } MemcpyState;
49 50
50 /* Copy [len] bytes into [dst] only if there's enough data to read according 51 /* Copy [len] bytes into [dst] only if there's enough data to read according
51 * to [state]. 52 * to [state].
52 * On success, return [dst] and update [state]. 53 * On success, return [dst] and update [state].
53 * On failure, return NULL, set remaining len in state to -1. 54 * On failure, return NULL, set remaining len in state to -1.
54 * 55 *
55 * Useful for iterating through a binary blob to populate a struct. After the 56 * Useful for iterating through a binary blob to populate a struct. After the
56 * first failure (buffer overrun), successive calls will always fail. 57 * first failure (buffer overrun), successive calls will always fail.
57 */ 58 */
58 void* StatefulMemcpy(MemcpyState* state, void* dst, int len); 59 void* StatefulMemcpy(MemcpyState* state, void* dst, uint64_t len);
59 60
60 /* Like StatefulMemcpy() but copies in the opposite direction, populating 61 /* Like StatefulMemcpy() but copies in the opposite direction, populating
61 * data from [src] into the buffer encapsulated in state [state]. 62 * data from [src] into the buffer encapsulated in state [state].
62 * On success, return [src] and update [state]. 63 * On success, return [src] and update [state].
63 * On failure, return NULL, set remaining_len in state to -1. 64 * On failure, return NULL, set remaining_len in state to -1.
64 * 65 *
65 * Useful for iterating through a structure to populate a binary blob. After the 66 * Useful for iterating through a structure to populate a binary blob. After the
66 * first failure (buffer overrun), successive calls will always fail. 67 * first failure (buffer overrun), successive calls will always fail.
67 */ 68 */
68 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, int len); 69 const void* StatefulMemcpy_r(MemcpyState* state, const void* src, uint64_t len);
69 70
70 #endif /* VBOOT_REFERENCE_UTILITY_H_ */ 71 #endif /* VBOOT_REFERENCE_UTILITY_H_ */
OLDNEW
« no previous file with comments | « src/platform/vboot_reference/include/rsa_utility.h ('k') | src/platform/vboot_reference/tests/Makefile » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698