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