4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jayoun Lee <airjany@samsung.com>, Sewook Park <sewook7.park@samsung.com>, Jaeho Lee <jaeho81.lee@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
23 #ifdef PRELOAD_ACTIVATE
26 #define PRELOAD_FILE SHARE_PREFIX"/preload_list.txt"
28 #define EFL_PREINIT_FUNC "elm_quicklaunch_init"
29 #define EFL_SHUTDOWN_FUNC "elm_quicklaunch_shutdown"
31 static int preload_initialized = 0;
34 static int max_cmdline_size = 0;
36 static int (*dl_einit) () = NULL;
37 static int (*dl_efini) () = NULL;
39 static inline void __preload_init(int argc, char **argv)
42 char soname[MAX_LOCAL_BUFSZ];
49 for (i = 0; i < argc; i++) {
50 max_cmdline_size += (strlen(argv[i]) + 1);
52 _D("max_cmdline_size = %d", max_cmdline_size);
54 preload_list = fopen(PRELOAD_FILE, "rt");
55 if (preload_list == NULL) {
60 while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > 0) {
61 soname[strlen(soname) - 1] = 0;
62 handle = dlopen((const char *) soname, RTLD_NOW);
65 _D("preload %s# - handle : %x\n", soname, handle);
67 func = dlsym(handle, EFL_PREINIT_FUNC);
69 _D("get pre-initialization function\n");
71 func = dlsym(handle, EFL_SHUTDOWN_FUNC);
73 _D("get shutdown function\n");
80 preload_initialized = 1;
83 static inline int preinit_init()
87 _D("pre-initialzation on");
91 static inline int preinit_fini()
95 _D("pre-initialization off");
99 /* TODO : how to set cmdline gracefully ?? */
100 static inline int __change_cmdline(char *cmdline)
102 if (strlen(cmdline) > max_cmdline_size + 1) {
103 _E("cmdline exceed max size : %d", max_cmdline_size);
107 memset(g_argv[0], '\0', max_cmdline_size);
108 snprintf(g_argv[0], max_cmdline_size, "%s", cmdline);
113 static inline void __preload_exec(int argc, char **argv)
116 int (*dl_main) (int, char **);
119 if (!preload_initialized)
122 handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL);
123 if (handle == NULL) {
124 _E("dlopen(\"%s\") failed", argv[0]);
125 if ((error = dlerror()) != NULL) {
126 _E("dlopen error: %s", error);
133 dl_main = dlsym(handle, "main");
134 if (dl_main != NULL) {
135 if (__change_cmdline(argv[0]) < 0) {
136 _E("change cmdline fail");
141 #ifdef _APPFW_FEATURE_PRIORITY_CHANGE
142 int res = setpriority(PRIO_PROCESS, 0, 0);
145 SECURE_LOGE("Setting process (%d) priority to 0 failed, errno: %d (%s)",
146 getpid(), errno, strerror(errno));
151 _E("dlsym not founded. bad preloaded app - check fpie pie");
152 if ((error = dlerror()) != NULL) {
153 _E("dlsym error: %s", error);
164 static inline void __preload_init();
165 static inline void __preload_exec(int argc, char **argv);