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"
27 #define PRELOAD_FILE_WRT SHARE_PREFIX"/preload_list_wrt.txt"
29 #define EFL_PREINIT_FUNC "elm_quicklaunch_init"
30 #define EFL_SHUTDOWN_FUNC "elm_quicklaunch_shutdown"
32 static int preload_initialized = 0;
35 static size_t max_cmdline_size = 0;
37 static int (*dl_einit) () = NULL;
38 static int (*dl_efini) () = NULL;
40 static inline void __preload_init(int argc, char **argv)
43 char soname[MAX_LOCAL_BUFSZ];
50 for (i = 0; i < argc; i++) {
51 max_cmdline_size += (strlen(argv[i]) + 1);
53 _D("max_cmdline_size = %d", max_cmdline_size);
55 preload_list = fopen(PRELOAD_FILE, "rt");
56 if (preload_list == NULL) {
61 while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > (char*)0) {
62 soname[strlen(soname) - 1] = 0;
63 handle = dlopen(soname, RTLD_NOW);
66 _D("preload %s# - handle : %x\n", soname, handle);
68 func = dlsym(handle, EFL_PREINIT_FUNC);
70 _D("get pre-initialization function\n");
72 func = dlsym(handle, EFL_SHUTDOWN_FUNC);
74 _D("get shutdown function\n");
81 preload_initialized = 1;
84 static inline int preinit_init()
88 _D("pre-initialzation on");
92 static inline int preinit_fini()
96 _D("pre-initialization off");
100 /* TODO : how to set cmdline gracefully ?? */
101 static inline int __change_cmdline(char *cmdline)
103 if (strlen(cmdline) > max_cmdline_size + 1) {
104 _E("cmdline exceed max size : %d", max_cmdline_size);
108 memset(g_argv[0], '\0', max_cmdline_size);
109 snprintf(g_argv[0], max_cmdline_size, "%s", cmdline);
114 static inline void __preload_exec(int argc, char **argv)
117 int (*dl_main) (int, char **);
119 if (!preload_initialized)
122 handle = dlopen(argv[0], RTLD_LAZY | RTLD_GLOBAL);
123 if (handle == NULL) {
127 dl_main = dlsym(handle, "main");
128 if (dl_main != NULL) {
129 if (__change_cmdline(argv[0]) < 0) {
130 _E("change cmdline fail");
135 _E("dlsym not founded. bad preloaded app - check fpie pie");
141 static inline void __preload_init_for_wrt()
144 char soname[MAX_LOCAL_BUFSZ];
147 preload_list = fopen(PRELOAD_FILE_WRT, "rt");
148 if (preload_list == NULL) {
149 _E("no wrt preload\n");
153 while (fgets(soname, MAX_LOCAL_BUFSZ, preload_list) > (char*)0) {
154 soname[strlen(soname) - 1] = 0;
155 handle = dlopen(soname, RTLD_NOW|RTLD_GLOBAL);
158 _D("preload %s# - handle : %x\n", soname, handle);
161 fclose(preload_list);
166 static inline void __preload_init(int argc, char **argv);
167 static inline void __preload_exec(int argc, char **argv);
168 static inline void __preload_init_for_wrt();