Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 The Hafnium Authors. |
| 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 | * https://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 | #include "hf/panic.h" |
| 18 | |
| 19 | #include <stdarg.h> |
| 20 | |
Andrew Scull | a59f9bc | 2019-04-03 15:24:35 +0100 | [diff] [blame] | 21 | #include "hf/abort.h" |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 22 | #include "hf/dlog.h" |
| 23 | |
| 24 | /** |
Andrew Scull | a59f9bc | 2019-04-03 15:24:35 +0100 | [diff] [blame] | 25 | * Logs a reason before calling abort. |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 26 | * |
| 27 | * TODO: Determine if we want to omit strings on non-debug builds. |
| 28 | */ |
| 29 | noreturn void panic(const char *fmt, ...) |
| 30 | { |
| 31 | va_list args; |
| 32 | |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 33 | dlog("Panic: "); |
| 34 | |
| 35 | va_start(args, fmt); |
| 36 | vdlog(fmt, args); |
| 37 | va_end(args); |
| 38 | |
| 39 | dlog("\n"); |
| 40 | |
Andrew Scull | a59f9bc | 2019-04-03 15:24:35 +0100 | [diff] [blame] | 41 | abort(); |
Andrew Scull | a9c172d | 2019-04-03 14:10:00 +0100 | [diff] [blame] | 42 | } |