Remove .csproj files from mcs/ build, they were never used (#20883)
[mono-project.git] / ikvm-native / os.c
blob43531ae0ea5b5d7666759ac7dd98d5505e4f4067
1 /*
2 Copyright (C) 2004, 2005 Jeroen Frijters
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
20 Jeroen Frijters
21 jeroen@frijters.net
24 #ifdef _WIN32
25 #include <windows.h>
26 #include "jni.h"
28 JNIEXPORT void* JNICALL ikvm_LoadLibrary(char* psz)
30 return LoadLibrary(psz);
33 JNIEXPORT void JNICALL ikvm_FreeLibrary(HMODULE handle)
35 FreeLibrary(handle);
38 JNIEXPORT void* JNICALL ikvm_GetProcAddress(HMODULE handle, char* name, jint argc)
40 #ifdef _WIN64
41 return GetProcAddress(handle, name);
42 #else
43 void* pfunc;
44 char buf[512];
45 if(strlen(name) > sizeof(buf) - 11)
47 return 0;
49 wsprintf(buf, "_%s@%d", name, argc);
50 pfunc = GetProcAddress(handle, buf);
51 if (pfunc)
52 return pfunc;
53 // If we didn't find the mangled name, try the unmangled name (this happens if you have an
54 // explicit EXPORT in the linker def).
55 return GetProcAddress(handle, name);
56 #endif
58 #else
59 #include <gmodule.h>
60 #include <sys/types.h>
61 #include <sys/mman.h>
62 #include "jni.h"
64 void* JNICALL ikvm_LoadLibrary(char* psz);
66 JNIEXPORT void* JNICALL ikvm_LoadLibrary(char* psz)
68 return g_module_open(psz, 0);
71 void JNICALL ikvm_FreeLibrary(GModule* handle);
73 JNIEXPORT void JNICALL ikvm_FreeLibrary(GModule* handle)
75 g_module_close(handle);
78 void* JNICALL ikvm_GetProcAddress(GModule* handle, char* name, jint argc);
80 JNIEXPORT void* JNICALL ikvm_GetProcAddress(GModule* handle, char* name, jint argc)
82 void *symbol;
84 gboolean res = g_module_symbol(handle, name, &symbol);
86 if (res)
87 return symbol;
88 else
89 return NULL;
92 void* JNICALL ikvm_mmap(int fd, jboolean writeable, jboolean copy_on_write, jlong position, jint size);
94 JNIEXPORT void* JNICALL ikvm_mmap(int fd, jboolean writeable, jboolean copy_on_write, jlong position, jint size)
96 return mmap(0, size, writeable ? PROT_WRITE | PROT_READ : PROT_READ, copy_on_write ? MAP_PRIVATE : MAP_SHARED, fd, position);
99 int JNICALL ikvm_munmap(void* address, jint size);
101 JNIEXPORT int JNICALL ikvm_munmap(void* address, jint size)
103 return munmap(address, size);
106 int JNICALL ikvm_msync(void* address, jint size);
108 JNIEXPORT int JNICALL ikvm_msync(void* address, jint size)
110 #if defined(__native_client__) && defined(USE_NEWLIB)
111 g_assert_not_reached ();
112 return -1;
113 #else
114 return msync(address, size, MS_SYNC);
115 #endif
117 #endif