static char* g_argv_end = nullptr;
static char* g_envp_end = nullptr;
+#if BUILDFLAG(IS_EFL)
+static char** g_main_argv = nullptr;
+static size_t g_main_argv_size = 0;
+#endif
+
void setproctitle(const char* fmt, ...) {
va_list ap;
return;
// The title can be up to the end of envp.
- const size_t avail_size =
+ size_t avail_size =
base::checked_cast<size_t>(g_envp_end - g_argv_start - 1);
// Linux 4.18--5.2 have a bug where we can never set a process title
return cmdline.size() >= 2;
}();
+#if BUILDFLAG(IS_EFL) && !BUILDFLAG(IS_TIZEN_TV)
+ // Put all arguments into argv[1], not argv[0]
+ if (g_main_argv[0])
+ snprintf(g_main_argv[0], strlen(g_orig_argv0) + 1, "%s", g_orig_argv0);
+ if (g_main_argv[1]) {
+ // argv[0] can be replaced by exceeding the original argument length within
+ // the free memory of the page, but argv[1] cannot exceed the the original
+ // length.
+ // Adjusts the available size to the length of the original arguments.
+ avail_size = g_main_argv_size;
+ avail_size -= (strlen(g_main_argv[0]) + 1);
+
+ memset(g_main_argv[1], 0, avail_size);
+ va_start(ap, fmt);
+ vsnprintf(g_main_argv[1], avail_size, fmt, ap);
+ va_end(ap);
+ g_main_argv[2] = nullptr;
+ return;
+ }
+#endif
+
memset(g_argv_start, 0, avail_size + 1);
size_t size;
char* argv_end = p;
size_t environ_size = 0;
for (size_t i = 0; environ[i]; ++i, ++environ_size) {
+#if !BUILDFLAG(IS_EFL)
+ // Chromium-efl uses setenv at few places, setenv updates the address value
+ // of the particular env. variable, so the below check would fail when we
+ // compare it with default glibc's |environ|
if (p != environ[i])
return;
+#endif
p += strlen(p) + 1;
}
char* envp_end = p;
g_argv_start = argv_start;
g_argv_end = argv_end;
g_envp_end = envp_end;
+#if BUILDFLAG(IS_EFL)
+ g_main_argv = const_cast<char**>(main_argv);
+ if (argv) {
+ for (int i = 0; argv[i]; ++i)
+ g_main_argv_size += strlen(argv[i]) + 1;
+ }
+#endif
}