1 // Copyright 2021 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14
15 // This is a basic, standalone implementation of DiceClearMemory that aims to
16 // write zeros to the memory without the compiler optimizing it away by using a
17 // volatile data pointer. Attention has not been given to performance, clearing
18 // caches or other potential side channels.
19
20 #include "dice/ops/clear_memory.h"
21
22 #include <stdint.h>
23
DiceClearMemory(void * context,size_t size,void * address)24 void DiceClearMemory(void* context, size_t size, void* address) {
25 (void)context;
26 volatile uint8_t* p = address;
27 for (size_t i = 0; i < size; i++) {
28 p[i] = 0;
29 }
30 }
31