From 67442dc8f0bf56c88cf0826d6cfad874b19f8170 Mon Sep 17 00:00:00 2001 From: Sam Leffler Date: Thu, 23 Jun 2022 17:33:32 +0000 Subject: [PATCH] kata-os-camkes: export C bindings for better CAmkES integration In particular this exports the CAP_RELEASE flag so there is a single source for it's definition and KataOS-specific support in the CAmkES templates is enabled only for KataOS components. Specific changes: - adds cbindgen-generated CamkesBindings.h - adds include of CamkesBindings.h in component cbindgen files - add a dep on cbindgen.toml in all Makefiles - update generated interface files Change-Id: Ib6239d3ac0036b7a04bb36afccf25a05737b0e56 GitOrigin-RevId: af10117fa253f0c7c67969a5852ced9d992c6274 --- .../MemoryManager/kata-memory-interface/Makefile | 4 ++-- .../MemoryManager/kata-memory-interface/cbindgen.toml | 8 +++++++- .../components/MlCoordinator/kata-ml-interface/Makefile | 4 ++-- .../MlCoordinator/kata-ml-interface/cbindgen.toml | 5 ++++- .../ProcessManager/kata-proc-interface/Makefile | 4 ++-- .../ProcessManager/kata-proc-interface/cbindgen.toml | 6 +++++- .../SecurityCoordinator/kata-security-interface/Makefile | 4 ++-- .../kata-security-interface/cbindgen.toml | 8 +++++++- .../StorageManager/kata-storage-interface/Makefile | 4 ++-- .../StorageManager/kata-storage-interface/cbindgen.toml | 6 +++++- .../TimerService/kata-timer-interface/Makefile | 4 ++-- .../TimerService/kata-timer-interface/cbindgen.toml | 6 +++++- .../system/components/kata-os-common/src/camkes/Makefile | 4 ++++ .../components/kata-os-common/src/camkes/cbindgen.toml | 9 +++++++++ apps/system/interfaces/CamkesBindings.h | 8 ++++++++ apps/system/interfaces/MemoryManagerBindings.h | 3 +++ apps/system/interfaces/MlCoordBindings.h | 5 +++++ apps/system/interfaces/ProcessManagerBindings.h | 2 ++ apps/system/interfaces/SecurityCoordinatorBindings.h | 4 ++++ apps/system/interfaces/StorageManagerBindings.h | 2 ++ apps/system/interfaces/TimerServiceBindings.h | 4 +++- 21 files changed, 85 insertions(+), 19 deletions(-) create mode 100644 apps/system/components/kata-os-common/src/camkes/Makefile create mode 100644 apps/system/components/kata-os-common/src/camkes/cbindgen.toml create mode 100644 apps/system/interfaces/CamkesBindings.h diff --git a/apps/system/components/MemoryManager/kata-memory-interface/Makefile b/apps/system/components/MemoryManager/kata-memory-interface/Makefile index 0dd8134..649f102 100644 --- a/apps/system/components/MemoryManager/kata-memory-interface/Makefile +++ b/apps/system/components/MemoryManager/kata-memory-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/MemoryManagerBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/MemoryManagerBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/MemoryManager/kata-memory-interface/cbindgen.toml b/apps/system/components/MemoryManager/kata-memory-interface/cbindgen.toml index cec2834..dce74e8 100644 --- a/apps/system/components/MemoryManager/kata-memory-interface/cbindgen.toml +++ b/apps/system/components/MemoryManager/kata-memory-interface/cbindgen.toml @@ -2,6 +2,12 @@ language = "C" include_guard = "__MEMORY_MANAGER_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["RawPageDescData", "RawMemoryStatsData", "MemoryManagerStats", "MemoryManagerError"] +include = [ + "RawPageDescData", + "RawMemoryStatsData", + "MemoryManagerStats", + "MemoryManagerError", +] diff --git a/apps/system/components/MlCoordinator/kata-ml-interface/Makefile b/apps/system/components/MlCoordinator/kata-ml-interface/Makefile index 0de40c9..ec9f9ac 100644 --- a/apps/system/components/MlCoordinator/kata-ml-interface/Makefile +++ b/apps/system/components/MlCoordinator/kata-ml-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/MlCoordBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/MlCoordBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/MlCoordinator/kata-ml-interface/cbindgen.toml b/apps/system/components/MlCoordinator/kata-ml-interface/cbindgen.toml index 53c97e9..a5418b4 100644 --- a/apps/system/components/MlCoordinator/kata-ml-interface/cbindgen.toml +++ b/apps/system/components/MlCoordinator/kata-ml-interface/cbindgen.toml @@ -2,6 +2,9 @@ language = "C" include_guard = "__ML_COORDINATOR_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["MlCoordError"] +include = [ + "MlCoordError", +] diff --git a/apps/system/components/ProcessManager/kata-proc-interface/Makefile b/apps/system/components/ProcessManager/kata-proc-interface/Makefile index 90dfc66..c79e279 100644 --- a/apps/system/components/ProcessManager/kata-proc-interface/Makefile +++ b/apps/system/components/ProcessManager/kata-proc-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/ProcessManagerBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/ProcessManagerBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/ProcessManager/kata-proc-interface/cbindgen.toml b/apps/system/components/ProcessManager/kata-proc-interface/cbindgen.toml index 11079af..d80aa91 100644 --- a/apps/system/components/ProcessManager/kata-proc-interface/cbindgen.toml +++ b/apps/system/components/ProcessManager/kata-proc-interface/cbindgen.toml @@ -2,6 +2,10 @@ language = "C" include_guard = "__PROCESS_MANAGER_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["RawBundleIdData", "ProcessManagerError"] +include = [ + "RawBundleIdData", + "ProcessManagerError", +] diff --git a/apps/system/components/SecurityCoordinator/kata-security-interface/Makefile b/apps/system/components/SecurityCoordinator/kata-security-interface/Makefile index 6f2491b..1cd6049 100644 --- a/apps/system/components/SecurityCoordinator/kata-security-interface/Makefile +++ b/apps/system/components/SecurityCoordinator/kata-security-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/SecurityCoordinatorBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/SecurityCoordinatorBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/SecurityCoordinator/kata-security-interface/cbindgen.toml b/apps/system/components/SecurityCoordinator/kata-security-interface/cbindgen.toml index e7ab415..d61de29 100644 --- a/apps/system/components/SecurityCoordinator/kata-security-interface/cbindgen.toml +++ b/apps/system/components/SecurityCoordinator/kata-security-interface/cbindgen.toml @@ -2,6 +2,12 @@ language = "C" include_guard = "__SECURITY_COORDINATOR_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["SecurityRequestData", "SecurityReplyData", "SecurityRequest", "SecurityRequestError"] +include = [ + "SecurityRequestData", + "SecurityReplyData", + "SecurityRequest", + "SecurityRequestError", +] diff --git a/apps/system/components/StorageManager/kata-storage-interface/Makefile b/apps/system/components/StorageManager/kata-storage-interface/Makefile index 62a352f..858e4d8 100644 --- a/apps/system/components/StorageManager/kata-storage-interface/Makefile +++ b/apps/system/components/StorageManager/kata-storage-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/StorageManagerBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/StorageManagerBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/StorageManager/kata-storage-interface/cbindgen.toml b/apps/system/components/StorageManager/kata-storage-interface/cbindgen.toml index e9ce0fa..bc4409b 100644 --- a/apps/system/components/StorageManager/kata-storage-interface/cbindgen.toml +++ b/apps/system/components/StorageManager/kata-storage-interface/cbindgen.toml @@ -2,6 +2,10 @@ language = "C" include_guard = "__STORAGE_MANAGER_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["KeyValueData", "StorageManagerError"] +include = [ + "KeyValueData", + "StorageManagerError", +] diff --git a/apps/system/components/TimerService/kata-timer-interface/Makefile b/apps/system/components/TimerService/kata-timer-interface/Makefile index f682647..2cf3af5 100644 --- a/apps/system/components/TimerService/kata-timer-interface/Makefile +++ b/apps/system/components/TimerService/kata-timer-interface/Makefile @@ -1,4 +1,4 @@ INTERFACES=../../../interfaces -${INTERFACES}/TimerServiceBindings.h: src/lib.rs - cbindgen -c cbindgen.toml $? -o $@ +${INTERFACES}/TimerServiceBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/TimerService/kata-timer-interface/cbindgen.toml b/apps/system/components/TimerService/kata-timer-interface/cbindgen.toml index 7db195d..6b2871c 100644 --- a/apps/system/components/TimerService/kata-timer-interface/cbindgen.toml +++ b/apps/system/components/TimerService/kata-timer-interface/cbindgen.toml @@ -2,6 +2,10 @@ language = "C" include_guard = "__TIMER_SERVICE_BINDINGS_H__" autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" no_includes = true +includes = ["CamkesBindings.h"] [export] -include = ["TimerServiceError", "TimerId"] +include = [ + "TimerServiceError", + "TimerId", +] diff --git a/apps/system/components/kata-os-common/src/camkes/Makefile b/apps/system/components/kata-os-common/src/camkes/Makefile new file mode 100644 index 0000000..1d5b0a3 --- /dev/null +++ b/apps/system/components/kata-os-common/src/camkes/Makefile @@ -0,0 +1,4 @@ +INTERFACES=../../../../interfaces + +${INTERFACES}/CamkesBindings.h: src/lib.rs cbindgen.toml + cbindgen -c cbindgen.toml src/lib.rs -o $@ diff --git a/apps/system/components/kata-os-common/src/camkes/cbindgen.toml b/apps/system/components/kata-os-common/src/camkes/cbindgen.toml new file mode 100644 index 0000000..92259af --- /dev/null +++ b/apps/system/components/kata-os-common/src/camkes/cbindgen.toml @@ -0,0 +1,9 @@ +language = "C" +include_guard = "__CAMKES_BINDINGS_H__" +autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" +no_includes = true + +[export] +include = [ + "CAP_RELEASE", +] diff --git a/apps/system/interfaces/CamkesBindings.h b/apps/system/interfaces/CamkesBindings.h new file mode 100644 index 0000000..0f8c88e --- /dev/null +++ b/apps/system/interfaces/CamkesBindings.h @@ -0,0 +1,8 @@ +#ifndef __CAMKES_BINDINGS_H__ +#define __CAMKES_BINDINGS_H__ + +/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ + +#define CAP_RELEASE 2147483648 + +#endif /* __CAMKES_BINDINGS_H__ */ diff --git a/apps/system/interfaces/MemoryManagerBindings.h b/apps/system/interfaces/MemoryManagerBindings.h index 6289936..400a046 100644 --- a/apps/system/interfaces/MemoryManagerBindings.h +++ b/apps/system/interfaces/MemoryManagerBindings.h @@ -3,6 +3,8 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + #define RAW_OBJ_DESC_DATA_SIZE 2048 #define RAW_MEMORY_STATS_DATA_SIZE 100 @@ -12,6 +14,7 @@ typedef enum MemoryManagerError { MmeObjCountInvalid, MmeObjTypeInvalid, MmeObjCapInvalid, + MmeCapAllocFailed, MmeSerializeFailed, MmeDeserializeFailed, MmeUnknownError, diff --git a/apps/system/interfaces/MlCoordBindings.h b/apps/system/interfaces/MlCoordBindings.h index 63b020a..08be2f8 100644 --- a/apps/system/interfaces/MlCoordBindings.h +++ b/apps/system/interfaces/MlCoordBindings.h @@ -3,6 +3,11 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + +/** + * Errors that can occur when interacting with the MlCoordinator. + */ typedef enum MlCoordError { MlCoordOk, InvalidModelId, diff --git a/apps/system/interfaces/ProcessManagerBindings.h b/apps/system/interfaces/ProcessManagerBindings.h index 4ec6053..040f05a 100644 --- a/apps/system/interfaces/ProcessManagerBindings.h +++ b/apps/system/interfaces/ProcessManagerBindings.h @@ -3,6 +3,8 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + #define RAW_BUNDLE_ID_DATA_SIZE 100 #define DEFAULT_BUNDLE_ID_CAPACITY 64 diff --git a/apps/system/interfaces/SecurityCoordinatorBindings.h b/apps/system/interfaces/SecurityCoordinatorBindings.h index da7467a..9101f94 100644 --- a/apps/system/interfaces/SecurityCoordinatorBindings.h +++ b/apps/system/interfaces/SecurityCoordinatorBindings.h @@ -3,6 +3,8 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + #define SECURITY_REPLY_DATA_SIZE 2048 typedef enum SecurityRequest { @@ -16,6 +18,7 @@ typedef enum SecurityRequest { SrReadKey, SrWriteKey, SrDeleteKey, + SrTestMailbox, } SecurityRequest; typedef enum SecurityRequestError { @@ -43,6 +46,7 @@ typedef enum SecurityRequestError { SreReadFailed, SreWriteFailed, SreDeleteFailed, + SreTestFailed, } SecurityRequestError; typedef uint8_t SecurityReplyData[SECURITY_REPLY_DATA_SIZE]; diff --git a/apps/system/interfaces/StorageManagerBindings.h b/apps/system/interfaces/StorageManagerBindings.h index a3cd451..72a7190 100644 --- a/apps/system/interfaces/StorageManagerBindings.h +++ b/apps/system/interfaces/StorageManagerBindings.h @@ -3,6 +3,8 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + #define KEY_VALUE_DATA_SIZE 100 typedef enum StorageManagerError { diff --git a/apps/system/interfaces/TimerServiceBindings.h b/apps/system/interfaces/TimerServiceBindings.h index 24d016c..41e048e 100644 --- a/apps/system/interfaces/TimerServiceBindings.h +++ b/apps/system/interfaces/TimerServiceBindings.h @@ -3,12 +3,14 @@ /* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */ +#include "CamkesBindings.h" + typedef enum TimerServiceError { TimerOk = 0, NoSuchTimer, TimerAlreadyExists, } TimerServiceError; -typedef uintptr_t TimerId; +typedef uint32_t TimerId; #endif /* __TIMER_SERVICE_BINDINGS_H__ */