Files
OpenCellular/firmware/lib/stateful_util.c
Randall Spangler 664096bd1a vboot: use standard memcmp, memcpy, memset
Originally, we didn't trust the firmware to provide these functions from
a standard library.  Now, with coreboot, we do.

BUG=chromium:611535
BRANCH=none
TEST=make runtests; emerge-kevin coreboot depthcharge

Change-Id: I4e624c40085f2b665275a38624340b2f6aabcf11
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/399120
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
2016-10-23 13:33:38 -07:00

75 lines
1.7 KiB
C

/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* Implementations of stateful memory operations.
*/
#include "sysincludes.h"
#include "stateful_util.h"
#include "utility.h"
void StatefulInit(MemcpyState *state, void *buf, uint64_t len)
{
state->remaining_buf = buf;
state->remaining_len = len;
state->overrun = 0;
}
void *StatefulSkip(MemcpyState *state, uint64_t len)
{
if (state->overrun)
return NULL;
if (len > state->remaining_len) {
state->overrun = 1;
return NULL;
}
state->remaining_buf += len;
state->remaining_len -= len;
return state; /* Must return something non-NULL. */
}
void *StatefulMemcpy(MemcpyState *state, void *dst, uint64_t len)
{
if (state->overrun)
return NULL;
if (len > state->remaining_len) {
state->overrun = 1;
return NULL;
}
memcpy(dst, state->remaining_buf, len);
state->remaining_buf += len;
state->remaining_len -= len;
return dst;
}
const void *StatefulMemcpy_r(MemcpyState *state, const void *src, uint64_t len)
{
if (state->overrun)
return NULL;
if (len > state->remaining_len) {
state->overrun = 1;
return NULL;
}
memcpy(state->remaining_buf, src, len);
state->remaining_buf += len;
state->remaining_len -= len;
return src;
}
const void *StatefulMemset_r(MemcpyState *state, const uint8_t val,
uint64_t len)
{
if (state->overrun)
return NULL;
if (len > state->remaining_len) {
state->overrun = 1;
return NULL;
}
memset(state->remaining_buf, val, len);
state->remaining_buf += len;
state->remaining_len -= len;
return state; /* Must return something non-NULL. */
}