[sgen] Evacuate from emptier blocks to fuller ones
[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  */
10 #include <config.h>
11
12 #ifdef HAVE_UNISTD_H
13 #include <unistd.h>
14 #endif
15
16 #if defined(_POSIX_VERSION)
17
18 #include "mono/utils/mono-dl.h"
19 #include "mono/utils/mono-embed.h"
20 #include "mono/utils/mono-path.h"
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <ctype.h>
25 #include <string.h>
26 #include <glib.h>
27 #include <dlfcn.h>
28
29 #if !defined (TARGET_MACH)
30 const char *
31 mono_dl_get_so_prefix (void)
32 {
33         return "lib";
34 }
35 const char **
36 mono_dl_get_so_suffixes (void)
37 {
38         static const char *suffixes[] = {
39                 ".so",
40                 "",
41         };
42         return suffixes;
43 }
44
45 int
46 mono_dl_get_executable_path (char *buf, int buflen)
47 {
48         return readlink ("/proc/self/exe", buf, buflen - 1);
49 }
50
51 const char*
52 mono_dl_get_system_dir (void)
53 {
54         return NULL;
55 }
56
57 #endif
58
59 void *
60 mono_dl_open_file (const char *file, int flags)
61 {
62 #ifdef PLATFORM_ANDROID
63         /* Bionic doesn't support NULL filenames */
64         if (!file)
65                 return NULL;
66 #endif
67         return dlopen (file, flags);
68 }
69
70 void
71 mono_dl_close_handle (MonoDl *module)
72 {
73         dlclose (module->handle);
74 }
75
76 void*
77 mono_dl_lookup_symbol (MonoDl *module, const char *name)
78 {
79         return dlsym (module->handle, name);
80 }
81
82 int
83 mono_dl_convert_flags (int flags)
84 {
85         int lflags = flags & MONO_DL_LOCAL? 0: RTLD_GLOBAL;
86
87         if (flags & MONO_DL_LAZY)
88                 lflags |= RTLD_LAZY;
89         else
90                 lflags |= RTLD_NOW;
91         return lflags;
92 }
93
94 char*
95 mono_dl_current_error_string (void)
96 {
97         return g_strdup (dlerror ());
98 }
99
100 #endif