aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / boot / slot_control.c
| 1 | /* SPDX-License-Identifier: Apache-2.0 |
| 2 | * Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | /* slot_control.c -- see slot_control.h. */ |
| 18 | #include "slot_control.h" |
| 19 | |
| 20 | static struct ck_slot_control g_back; |
| 21 | |
| 22 | int ck_slot_control_commit(ts_region *r, const struct ck_slot_control *c, uint64_t *seq_out) |
| 23 | { |
| 24 | uint64_t seq = 0; |
| 25 | int rc = ts_commit(r, (const uint8_t *)c); |
| 26 | if (rc == TS_OK) |
| 27 | rc = ts_recover(r, (uint8_t *)&g_back, &seq, 0); |
| 28 | if (rc == TS_OK) { |
| 29 | const uint8_t *a = (const uint8_t *)&g_back, *b = (const uint8_t *)c; |
| 30 | uint8_t d = 0; |
| 31 | for (unsigned i = 0; i < sizeof g_back; i++) |
| 32 | d |= (uint8_t)(a[i] ^ b[i]); |
| 33 | if (d) |
| 34 | rc = TS_CORRUPT; |
| 35 | } |
| 36 | if (seq_out) |
| 37 | *seq_out = rc == TS_OK ? seq : 0; |
| 38 | return rc; |
| 39 | } |