• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 **
3 ** Copyright 2008, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 **     http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17 
18 #include <fcntl.h>
19 #include <sys/prctl.h>
20 #include <sys/wait.h>
21 #include <binder/IPCThreadState.h>
22 #include <binder/ProcessState.h>
23 #include <binder/IServiceManager.h>
24 #include <mediautils/LimitProcessMemory.h>
25 #include <string>
26 
27 #include <android-base/logging.h>
28 #include <android-base/properties.h>
29 #include <utils/misc.h>
30 
31 #include <bionic/reserved_signals.h>
32 
33 // from LOCAL_C_INCLUDES
34 #include "MediaExtractorService.h"
35 #include "minijail.h"
36 
37 using namespace android;
38 
39 static const char kSystemSeccompPolicyPath[] =
40         "/apex/com.android.media/etc/seccomp_policy/mediaextractor.policy";
41 static const char kVendorSeccompPolicyPath[] =
42         "/vendor/etc/seccomp_policy/mediaextractor.policy";
43 
main(int argc __unused,char ** argv)44 int main(int argc __unused, char** argv)
45 {
46     limitProcessMemory(
47         "ro.media.maxmem", /* property that defines limit */
48         SIZE_MAX, /* upper limit in bytes */
49         20 /* upper limit as percentage of physical RAM */);
50 
51     signal(SIGPIPE, SIG_IGN);
52 
53     // Do not assist platform profilers (relevant only on debug builds).
54     // Otherwise, the signal handler can violate the seccomp policy.
55     signal(BIONIC_SIGNAL_PROFILER, SIG_IGN);
56 
57     //b/62255959: this forces libutis.so to dlopen vendor version of libutils.so
58     //before minijail is on. This is dirty but required since some syscalls such
59     //as pread64 are used by linker but aren't allowed in the minijail. By
60     //calling the function before entering minijail, we can force dlopen.
61     android::report_sysprop_change();
62 
63     SetUpMinijail(kSystemSeccompPolicyPath, kVendorSeccompPolicyPath);
64 
65     strcpy(argv[0], "media.extractor");
66     sp<ProcessState> proc(ProcessState::self());
67     sp<IServiceManager> sm = defaultServiceManager();
68     MediaExtractorService::instantiate();
69 
70     ProcessState::self()->startThreadPool();
71     IPCThreadState::self()->joinThreadPool();
72 }
73