NoPie.c (933B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 #include <errno.h> 7 #include <limits.h> 8 #include <stdio.h> 9 #include <string.h> 10 #include <unistd.h> 11 12 int main(int argc, char* argv[]) { 13 // Ideally, we'd use mozilla::BinaryPath, but that pulls in stdc++compat, 14 // and further causes trouble linking with LTO. 15 char path[PATH_MAX + 4]; 16 ssize_t len = readlink("/proc/self/exe", path, PATH_MAX - 1); 17 if (len < 0) { 18 fprintf(stderr, "Couldn't find the application directory.\n"); 19 return 255; 20 } 21 strcpy(path + len, "-bin"); 22 execv(path, argv); 23 // execv never returns. If it did, there was an error. 24 fprintf(stderr, "Exec failed with error: %s\n", strerror(errno)); 25 return 255; 26 }