[ios] Remove code path using UseMachineKeyStore since it's not available (and bring...
[mono-project.git] / ikvm-native / os.c
blob9f2115f712ba6c2726969e963ebe4aa246048529
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 JNIEXPORT void* JNICALL ikvm_LoadLibrary(char* psz)
66 return g_module_open(psz, 0);
69 JNIEXPORT void JNICALL ikvm_FreeLibrary(GModule* handle)
71 g_module_close(handle);
74 JNIEXPORT void* JNICALL ikvm_GetProcAddress(GModule* handle, char* name, jint argc)
76 void *symbol;
78 gboolean res = g_module_symbol(handle, name, &symbol);
80 if (res)
81 return symbol;
82 else
83 return NULL;
86 JNIEXPORT void* JNICALL ikvm_mmap(int fd, jboolean writeable, jboolean copy_on_write, jlong position, jint size)
88 return mmap(0, size, writeable ? PROT_WRITE | PROT_READ : PROT_READ, copy_on_write ? MAP_PRIVATE : MAP_SHARED, fd, position);
91 JNIEXPORT int JNICALL ikvm_munmap(void* address, jint size)
93 return munmap(address, size);
96 JNIEXPORT int JNICALL ikvm_msync(void* address, jint size)
98 #if defined(__native_client__) && defined(USE_NEWLIB)
99 g_assert_not_reached ();
100 return -1;
101 #else
102 return msync(address, size, MS_SYNC);
103 #endif
105 #endif