{"id":1371,"url":"https://patchwork.libcamera.org/api/1.1/patches/1371/?format=json","web_url":"https://patchwork.libcamera.org/patch/1371/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20190605221817.966-11-paul.elder@ideasonboard.com>","date":"2019-06-05T22:18:17","name":"[libcamera-devel,RFC,10/10] libcamera: ipa: shim: load IPA module into an IPAInterface","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"54e39d8f1b34cb16db524b8015d33f604ce747e8","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/1.1/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/1371/mbox/","series":[{"id":339,"url":"https://patchwork.libcamera.org/api/1.1/series/339/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=339","date":"2019-06-05T22:18:07","name":"Add IPA process isolation","version":1,"mbox":"https://patchwork.libcamera.org/series/339/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/1371/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/1371/checks/","tags":{},"headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 88C6164772\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  6 Jun 2019 00:18:35 +0200 (CEST)","from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id E343C84;\n\tThu,  6 Jun 2019 00:18:34 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1559773115;\n\tbh=EUm7WwfdOoEbXjefZzOV8nULKUqO1Bc4JJNcuQDD1Y8=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=YpQ1iX3gQoGxoHpNhjmpHj5HSySjF53Qw3eexdBAyD6C9SoxeOwDNHlgN7OhWEe5h\n\tK+XIFVcfOTTVvcJHNQ9DA6L1kw22IByuZoJRwjbVFVLyNcPPxilYlcW1tZVLo/SLty\n\t71kh/SILzkbvrTpC9BOHrdK8xHl81f2pPgeKDLH4=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed,  5 Jun 2019 18:18:17 -0400","Message-Id":"<20190605221817.966-11-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.20.1","In-Reply-To":"<20190605221817.966-1-paul.elder@ideasonboard.com>","References":"<20190605221817.966-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Subject":"[libcamera-devel] [RFC PATCH 10/10] libcamera: ipa: shim: load IPA\n\tmodule into an IPAInterface","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","X-List-Received-Date":"Wed, 05 Jun 2019 22:18:35 -0000"},"content":"Implement the dummy shim's init method that takes a path for the IPA\nmodule to be loaded. Set up IPC, then fork and load the IPAInterface\nimplementation from the IPA module shared object.\n\nImplement a cleanup method along with it.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\n---\nThis is the most draft-y patch of the whole series. I wasn't sure how to\nput what kind of IPC, so I kind of just did this very skeletal \"give you\nan idea\" type of IPC initialization. Privilege dropping will be looked\ninto for the next version.\n\n src/ipa/shim_dummy.cpp | 79 ++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 77 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/shim_dummy.cpp b/src/ipa/shim_dummy.cpp\nindex 4d28c2d..f2e6961 100644\n--- a/src/ipa/shim_dummy.cpp\n+++ b/src/ipa/shim_dummy.cpp\n@@ -6,6 +6,14 @@\n  */\n \n #include <iostream>\n+#include <memory>\n+\n+#include <dlfcn.h>\n+#include <string.h>\n+#include <stdlib.h>\n+#include <sys/socket.h>\n+#include <sys/types.h>\n+#include <unistd.h>\n \n #include <libcamera/ipa/ipa_interface.h>\n #include <libcamera/ipa/ipa_module_info.h>\n@@ -17,20 +25,87 @@ class ShimDummy : public IPAInterface\n public:\n \tint init();\n \tint init(const char *path);\n+\n+\tvoid cleanup();\n+\n+private:\n+\tstd::unique_ptr<IPAInterface> ipa_;\n+\n+\tint sockets_[2];\n+\tint childPid_;\n+\tvoid *dlHandle_;\n+\n+\ttypedef IPAInterface *(*IPAIntfFactory)(void);\n };\n \n int ShimDummy::init()\n {\n-\tstd::cout << \"okay shim init without path\" << std::endl;\n+\tstd::cout << \"initializing IPA via dummy shim!\" << std::endl;\n \treturn 0;\n }\n \n int ShimDummy::init(const char *path)\n {\n-\tstd::cout << \"initializing dummy shim!\" << std::endl;\n+\tstd::cout << \"initializing dummy shim! loading IPA from \" << path\n+\t\t  << std::endl;\n+\n+\t/* We know the IPA module is valid, otherwise IPAManager wouldn't\n+\t * even give its path to us. */\n+\n+\t// setup comm\n+\tif (socketpair(AF_UNIX, SOCK_STREAM, 0, sockets_)) {\n+\t\tint err = errno;\n+\t\tstd::cerr << \"Error opening sockets: \" << strerror(errno)\n+\t\t\t  << std::endl;\n+\t\treturn err;\n+\t}\n+\n+\t// fork\n+\tif ((childPid_ = fork()) == -1) {\n+\t\tint err = errno;\n+\t\tstd::cerr << \"Failed to fork: \" << strerror(errno) << std::endl;\n+\t\treturn err;\n+\t} else if (childPid_) {\n+\t\t// we are parent\n+\t\t// we can read/write sockets_[1]\n+\t\tclose(sockets_[0]);\n+\t} else {\n+\t\t// we are child\n+\t\t// we can read/write sockets_[0]\n+\t\tclose(sockets_[1]);\n+\n+\t\tdlHandle_ = dlopen(path, RTLD_LAZY);\n+\t\tif (!dlHandle_) {\n+\t\t\tstd::cerr << \"Failed to open IPA module: \"\n+\t\t\t\t  << dlerror() << std::endl;\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tvoid *symbol = dlsym(dlHandle_, \"ipaCreate\");\n+\t\tif (!symbol) {\n+\t\t\tstd::cerr\n+\t\t\t\t<< \"Failed to load ipaCreate() from IPA module shared object: \"\n+\t\t\t\t<< dlerror();\n+\t\t\tdlclose(dlHandle_);\n+\t\t\tdlHandle_ = nullptr;\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tIPAIntfFactory ipaCreate = reinterpret_cast<IPAIntfFactory>(symbol);\n+\t\tipa_ = std::unique_ptr<IPAInterface>(ipaCreate());\n+\t\texit(0);\n+\t}\n+\n \treturn 0;\n }\n \n+void ShimDummy::cleanup()\n+{\n+\tif (dlHandle_)\n+\t\tdlclose(dlHandle_);\n+\tdlHandle_ = nullptr;\n+}\n+\n /*\n  * External IPA module interface\n  */\n","prefixes":["libcamera-devel","RFC","10/10"]}