Hafnium's coding style has been based on the Linux style with explicit modifications:
goto fail;, thanks.)
Following this, we generally fall back to the subset of the Google C++ style guide that is applicable to C.
We try to automate this where possible with clang-format and clang-tidy but that doesn‘t capture everything we’d like today. Where the style enforced by this tooling conflicts with what is in this document we accept what the tooling requires, and try to improve it if possible.
plat_prefix if appropriate), though there are quite a few exceptions to this rule.
These rules apply to comments and other natural language text.
Spell out Hafnium in full, not Hf.
Use single spaces.
Sentences end with full stops.
If the comment fits on one line use
/* */, otherwise space it out:
/* * Informative long comment * with extra information. */
Doc-ish comments start with
References to code symbols use backticks, e.g.
CHECK. Use it to assert pre-/post- conditions.
Hafnium uses the same log levels as Arm Trusted Firmware. There are 5 log levels, in order of severity:
Use this only for cases that there is an error in the hypervisor itself, perhaps caused by a coding error, bad configuration, unexpected hardware behaviour or a malformed manifest. Errors should not be logged during normal operation, even in case of a buggy or malicious VM.
Use this sparingly for important messages which should be logged even in production builds because they will be useful for debugging. This is a suitable level to use for events which may indicate a bug in a VM.
Use this for warnings which are important to developers but can generally be ignored in production.
Use this to provide extra information that is helpful for developers.
Use this to provide even more information which may be helpful when tracing through execution in detail, such as when debugging test failures. This is the only level which should include any sensitive data.
Logging is done with the
dlog_* macros, e.g.
dlog_info. These accept printf-style format strings and arguments.
The log level of a build is controlled by the
log_level argument defined in
BUILDCONFIG.gn. This defaults to
INFO for debug builds and tests, meaning that all levels except
VERBOSE will be logged. It is recommended to set the log level to
NOTICE for production builds, to reduce binary size and log spam.