summaryrefslogtreecommitdiff
path: root/utils/ipc/generators
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2021-07-20 19:24:47 +0900
committerPaul Elder <paul.elder@ideasonboard.com>2021-08-19 16:54:02 +0900
commit31078711d6c3639073db97322c6f7d98dacbbefe (patch)
treecf684773f11124218cbdfb07337a24a92eb48fb9 /utils/ipc/generators
parente35cae067980a62b23d25792bc5176b4c554605f (diff)
ipa: Use FileDescriptor instead of int in layers above IPC payload
Regarding (de)serialization in isolated IPA calls, we have four layers: - struct - byte vector + fd vector - IPCMessage - IPC payload The proxy handles the upper three layers (with help from the IPADataSerializer), and passes an IPCMessage to the IPC mechanism (implemented as an IPCPipe), which sends an IPC payload to its worker counterpart. When a FileDescriptor is involved, previously it was only a FileDescriptor in the first layer; in the lower three it was an int. To reduce the risk of potential fd leaks in the future, keep the FileDescriptor as-is throughout the upper three layers. Only the IPC mechanism will deal with ints, if it so wishes, when it does the actual IPC. IPCPipeUnixSocket does deal with ints for sending fds, so the conversion between IPCMessage and IPCUnixSocket::Payload converts between FileDescriptor and int. Additionally, change the data portion of the serialized form of FileDescriptor to a 32-bit unsigned integer, for alightnment purposes and in preparation for conversion to an index into the fd array. Also update the deserializer of FrameBuffer::Plane accordingly. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Tested-by: Umang Jain <umang.jain@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Umang Jain <umang.jain@ideasonboard.com>
Diffstat (limited to 'utils/ipc/generators')
-rw-r--r--utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl2
-rw-r--r--utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl2
-rw-r--r--utils/ipc/generators/libcamera_templates/proxy_functions.tmpl2
-rw-r--r--utils/ipc/generators/libcamera_templates/serializer.tmpl26
4 files changed, 16 insertions, 16 deletions
diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl
index a4e008c7..aab1fffb 100644
--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl
+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.cpp.tmpl
@@ -236,7 +236,7 @@ void {{proxy_name}}::recvMessage(const IPCMessage &data)
void {{proxy_name}}::{{method.mojom_name}}IPC(
std::vector<uint8_t>::const_iterator data,
size_t dataSize,
- [[maybe_unused]] const std::vector<int32_t> &fds)
+ [[maybe_unused]] const std::vector<FileDescriptor> &fds)
{
{%- for param in method.parameters %}
{{param|name}} {{param.mojom_name}};
diff --git a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl
index c222f5f2..1979e68f 100644
--- a/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl
+++ b/utils/ipc/generators/libcamera_templates/module_ipa_proxy.h.tmpl
@@ -65,7 +65,7 @@ private:
void {{method.mojom_name}}IPC(
std::vector<uint8_t>::const_iterator data,
size_t dataSize,
- const std::vector<int32_t> &fds);
+ const std::vector<FileDescriptor> &fds);
{% endfor %}
/* Helper class to invoke async functions in another thread. */
diff --git a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl
index ea9cc86b..ebcd2aaa 100644
--- a/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl
+++ b/utils/ipc/generators/libcamera_templates/proxy_functions.tmpl
@@ -54,7 +54,7 @@
{%- for param in params %}
std::vector<uint8_t> {{param.mojom_name}}Buf;
{%- if param|has_fd %}
- std::vector<int32_t> {{param.mojom_name}}Fds;
+ std::vector<FileDescriptor> {{param.mojom_name}}Fds;
std::tie({{param.mojom_name}}Buf, {{param.mojom_name}}Fds) =
{%- else %}
std::tie({{param.mojom_name}}Buf, std::ignore) =
diff --git a/utils/ipc/generators/libcamera_templates/serializer.tmpl b/utils/ipc/generators/libcamera_templates/serializer.tmpl
index d8d55807..b8ef8e7b 100644
--- a/utils/ipc/generators/libcamera_templates/serializer.tmpl
+++ b/utils/ipc/generators/libcamera_templates/serializer.tmpl
@@ -40,7 +40,7 @@
retData.insert(retData.end(), {{field.mojom_name}}.begin(), {{field.mojom_name}}.end());
{%- elif field|is_fd %}
std::vector<uint8_t> {{field.mojom_name}};
- std::vector<int32_t> {{field.mojom_name}}Fds;
+ std::vector<FileDescriptor> {{field.mojom_name}}Fds;
std::tie({{field.mojom_name}}, {{field.mojom_name}}Fds) =
IPADataSerializer<{{field|name}}>::serialize(data.{{field.mojom_name}});
retData.insert(retData.end(), {{field.mojom_name}}.begin(), {{field.mojom_name}}.end());
@@ -58,7 +58,7 @@
{%- elif field|is_plain_struct or field|is_array or field|is_map or field|is_str %}
std::vector<uint8_t> {{field.mojom_name}};
{%- if field|has_fd %}
- std::vector<int32_t> {{field.mojom_name}}Fds;
+ std::vector<FileDescriptor> {{field.mojom_name}}Fds;
std::tie({{field.mojom_name}}, {{field.mojom_name}}Fds) =
{%- else %}
std::tie({{field.mojom_name}}, std::ignore) =
@@ -104,9 +104,9 @@
dataSize -= {{field_size}};
{%- endif %}
{% elif field|is_fd %}
- {%- set field_size = 1 %}
+ {%- set field_size = 4 %}
{{- check_data_size(field_size, 'dataSize', field.mojom_name, 'data')}}
- ret.{{field.mojom_name}} = IPADataSerializer<{{field|name}}>::deserialize(m, m + 1, n, n + 1, cs);
+ ret.{{field.mojom_name}} = IPADataSerializer<{{field|name}}>::deserialize(m, m + {{field_size}}, n, n + 1, cs);
{%- if not loop.last %}
m += {{field_size}};
dataSize -= {{field_size}};
@@ -177,7 +177,7 @@
# \a struct.
#}
{%- macro serializer(struct, namespace) %}
- static std::tuple<std::vector<uint8_t>, std::vector<int32_t>>
+ static std::tuple<std::vector<uint8_t>, std::vector<FileDescriptor>>
serialize(const {{struct|name_full}} &data,
{%- if struct|needs_control_serializer %}
ControlSerializer *cs)
@@ -187,7 +187,7 @@
{
std::vector<uint8_t> retData;
{%- if struct|has_fd %}
- std::vector<int32_t> retFds;
+ std::vector<FileDescriptor> retFds;
{%- endif %}
{%- for field in struct.fields %}
{{serializer_field(field, namespace, loop)}}
@@ -210,7 +210,7 @@
{%- macro deserializer_fd(struct, namespace) %}
static {{struct|name_full}}
deserialize(std::vector<uint8_t> &data,
- std::vector<int32_t> &fds,
+ std::vector<FileDescriptor> &fds,
{%- if struct|needs_control_serializer %}
ControlSerializer *cs)
{%- else %}
@@ -224,8 +224,8 @@
static {{struct|name_full}}
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
std::vector<uint8_t>::const_iterator dataEnd,
- std::vector<int32_t>::const_iterator fdsBegin,
- std::vector<int32_t>::const_iterator fdsEnd,
+ std::vector<FileDescriptor>::const_iterator fdsBegin,
+ std::vector<FileDescriptor>::const_iterator fdsEnd,
{%- if struct|needs_control_serializer %}
ControlSerializer *cs)
{%- else %}
@@ -234,7 +234,7 @@
{
{{struct|name_full}} ret;
std::vector<uint8_t>::const_iterator m = dataBegin;
- std::vector<int32_t>::const_iterator n = fdsBegin;
+ std::vector<FileDescriptor>::const_iterator n = fdsBegin;
size_t dataSize = std::distance(dataBegin, dataEnd);
[[maybe_unused]] size_t fdsSize = std::distance(fdsBegin, fdsEnd);
@@ -255,7 +255,7 @@
{%- macro deserializer_fd_simple(struct, namespace) %}
static {{struct|name_full}}
deserialize(std::vector<uint8_t> &data,
- [[maybe_unused]] std::vector<int32_t> &fds,
+ [[maybe_unused]] std::vector<FileDescriptor> &fds,
ControlSerializer *cs = nullptr)
{
return IPADataSerializer<{{struct|name_full}}>::deserialize(data.cbegin(), data.cend(), cs);
@@ -264,8 +264,8 @@
static {{struct|name_full}}
deserialize(std::vector<uint8_t>::const_iterator dataBegin,
std::vector<uint8_t>::const_iterator dataEnd,
- [[maybe_unused]] std::vector<int32_t>::const_iterator fdsBegin,
- [[maybe_unused]] std::vector<int32_t>::const_iterator fdsEnd,
+ [[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsBegin,
+ [[maybe_unused]] std::vector<FileDescriptor>::const_iterator fdsEnd,
ControlSerializer *cs = nullptr)
{
return IPADataSerializer<{{struct|name_full}}>::deserialize(dataBegin, dataEnd, cs);