Merge pull request #2802 from BrzVlad/feature-evacuation-opt2
[mono.git] / mono / utils / mono-dl-posix.c
1 /*
2  * mono-dl.c: Interface to the dynamic linker
3  *
4  * Author:
5  *    Mono Team (http://www.mono-project.com)
6  *
7  * Copyright 2001-2004 Ximian, Inc.
8  * Copyright 2004-2009 Novell, Inc.
9  * Licensed under the MIT license. See LICENSE file in the project root for full license information.
10  */
11 #include <config.h>
12
13 #ifdef HAVE_UNISTD_H
14 #include <unistd.h>
15 #endif
16
17 #if defined(_POSIX_VERSION)
18
19 #include "mono/utils/mono-dl.h"
20 #include "mono/utils/mono-embed.h"
21 #include "mono/utils/mono-path.h"
22
23 #include <stdlib.h>
24 #include <stdio.h>
25 #include <ctype.h>
26 #include <string.h>
27 #include <glib.h>
28 #include <dlfcn.h>
29
30 #if !defined (TARGET_MACH)
31 const char *
32 mono_dl_get_so_prefix (void)
33 {
34         return "lib";
35 }
36 const char **
37 mono_dl_get_so_suffixes (void)
38 {
39         static const char *suffixes[] = {
40                 ".so",
41                 "",
42         };
43         return suffixes;
44 }
45
46 int
47 mono_dl_get_executable_path (char *buf, int buflen)
48 {
49         return readlink ("/proc/self/exe", buf, buflen - 1);
50 }
51
52 const char*
53 mono_dl_get_system_dir (void)
54 {
55         return NULL;
56 }
57
58 #endif
59
60 void *
61 mono_dl_open_file (const char *file, int flags)
62 {
63 #ifdef PLATFORM_ANDROID
64         /* Bionic doesn't support NULL filenames */
65         if (!file)
66                 return NULL;
67 #endif
68         return dlopen (file, flags);
69 }
70
71 void
72 mono_dl_close_handle (MonoDl *module)
73 {
74         dlclose (module->handle);
75 }
76
77 void*
78 mono_dl_lookup_symbol (MonoDl *module, const char *name)
79 {
80         return dlsym (module->handle, name);
81 }
82
83 int
84 mono_dl_convert_flags (int flags)
85 {
86         int lflags = flags & MONO_DL_LOCAL? 0: RTLD_GLOBAL;
87
88         if (flags & MONO_DL_LAZY)
89                 lflags |= RTLD_LAZY;
90         else
91                 lflags |= RTLD_NOW;
92         return lflags;
93 }
94
95 char*
96 mono_dl_current_error_string (void)
97 {
98         return g_strdup (dlerror ());
99 }
100
101 #endif