aboutsummaryrefslogtreecommitdiffstats
path: root/mjit.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-08 01:50:39 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-12-08 01:50:39 +0000
commite15d9d86df98eb015a44b8d274c6a259e4e35f64 (patch)
tree8d992de78ffcc5f35c0b61565a560a66e1551e7b /mjit.c
parent2301054a99b85ad2ede6a53404268f25dc2d5fdc (diff)
downloadruby-e15d9d86df98eb015a44b8d274c6a259e4e35f64.tar.gz
Give the MJIT header path name
Give the whole MJIT header path name by preloaded shared library mjit_build_dir.so, than building the path from a given directory name and the embedded base name. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66280 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'mjit.c')
-rw-r--r--mjit.c64
1 files changed, 26 insertions, 38 deletions
diff --git a/mjit.c b/mjit.c
index e94f2d9443..da3558da54 100644
--- a/mjit.c
+++ b/mjit.c
@@ -365,10 +365,12 @@ static int
init_header_filename(void)
{
int fd;
+#ifdef LOAD_RELATIVE
/* Root path of the running ruby process. Equal to RbConfig::TOPDIR. */
VALUE basedir_val;
- const char *basedir;
- size_t baselen;
+#endif
+ const char *basedir = NULL;
+ size_t baselen = 0;
char *p;
#ifdef _WIN32
static const char libpathflag[] =
@@ -380,33 +382,32 @@ init_header_filename(void)
;
const size_t libpathflag_len = sizeof(libpathflag) - 1;
#endif
-#ifndef LOAD_RELATIVE
- const char *build_dir = 0;
- struct stat st;
-#endif
+#ifdef LOAD_RELATIVE
basedir_val = ruby_prefix_path;
basedir = StringValuePtr(basedir_val);
baselen = RSTRING_LEN(basedir_val);
-
-#ifndef LOAD_RELATIVE
+#else
if (getenv("MJIT_SEARCH_BUILD_DIR")) {
/* This path is not intended to be used on production, but using build directory's
header file here because people want to run `make test-all` without running
`make install`. Don't use $MJIT_SEARCH_BUILD_DIR except for test-all. */
- build_dir = dlsym(RTLD_DEFAULT, "MJIT_BUILD_DIR");
- if (!build_dir) {
- verbose(1, "No mjit_build_directory");
+ struct stat st;
+ const char *hdr = dlsym(RTLD_DEFAULT, "MJIT_HEADER");
+ if (!hdr) {
+ verbose(1, "No MJIT_HEADER");
}
- else if (build_dir[0] != '/') {
- verbose(1, "Non-absolute path MJIT_BUILD_DIR: %s", build_dir);
+ else if (hdr[0] != '/') {
+ verbose(1, "Non-absolute header file path: %s", hdr);
}
- else if (stat(build_dir, &st) || !S_ISDIR(st.st_mode)) {
- verbose(1, "Non-directory path MJIT_BUILD_DIR: %s", build_dir);
+ else if (stat(hdr, &st) || !S_ISREG(st.st_mode)) {
+ verbose(1, "Non-file header file path: %s", hdr);
}
- else if (!rb_path_check(build_dir)) {
- verbose(1, "Unsafe MJIT_BUILD_DIR: %s", build_dir);
+ else if ((st.st_uid != getuid()) || (st.st_mode & 022) ||
+ !rb_path_check(hdr)) {
+ verbose(1, "Unsafe header file: uid=%ld mode=%#o %s",
+ (long)st.st_uid, (unsigned)st.st_mode, hdr);
return FALSE;
}
else {
@@ -415,43 +416,30 @@ init_header_filename(void)
verbose(3, "PRELOADENV("PRELOADENV")=%s", getenv(PRELOADENV));
/* assume no other PRELOADENV in test-all */
unsetenv(PRELOADENV);
- verbose(3, "MJIT_BUILD_DIR: %s", build_dir);
- basedir = build_dir;
- baselen = strlen(build_dir);
}
+ verbose(3, "MJIT_HEADER: %s", hdr);
+ header_file = ruby_strdup(hdr);
+ if (!header_file) return FALSE;
}
+ else
#endif
-
-#ifndef _MSC_VER
{
/* A name of the header file included in any C file generated by MJIT for iseqs. */
- static const char header_name[] = MJIT_MIN_HEADER_NAME;
+ static const char header_name[] = MJIT_HEADER_INSTALL_DIR "/" MJIT_MIN_HEADER_NAME;
const size_t header_name_len = sizeof(header_name) - 1;
header_file = xmalloc(baselen + header_name_len + 1);
p = append_str2(header_file, basedir, baselen);
p = append_str2(p, header_name, header_name_len + 1);
+ }
+#ifndef _MSC_VER
+ {
if ((fd = rb_cloexec_open(header_file, O_RDONLY, 0)) < 0) {
verbose(1, "Cannot access header file: %s", header_file);
xfree(header_file);
header_file = NULL;
return FALSE;
}
-#ifndef LOAD_RELATIVE
- if (basedir == build_dir) {
- memset(&st, 0, sizeof(st));
- if (fstat(fd, &st) ||
- (st.st_uid != getuid()) ||
- (st.st_mode & 022)) {
- (void)close(fd);
- verbose(1, "Unsafe header file: uid=%ld mode=%#o %s",
- (long)st.st_uid, (unsigned)st.st_mode, header_file);
- xfree(header_file);
- header_file = NULL;
- return FALSE;
- }
- }
-#endif
(void)close(fd);
}