# HG changeset patch
# User moel.mich
# Date 1288907174 0
# Node ID 91800d0f54de4340dd527996bcd4ec22211dc1a5
# Parent  bddc6e01840aaf1be03034172c127364e424325c
Replaced the direct reference to the Mono.Posix assembly with reflection.

diff -r bddc6e01840a -r 91800d0f54de Hardware/Opcode.cs
--- a/Hardware/Opcode.cs	Wed Nov 03 22:07:46 2010 +0000
+++ b/Hardware/Opcode.cs	Thu Nov 04 21:46:14 2010 +0000
@@ -37,7 +37,7 @@
 
 using System;
 using System.Runtime.InteropServices;
-using Mono.Unix.Native;
+using System.Reflection;
 
 namespace OpenHardwareMonitor.Hardware {
   internal static class Opcode {
@@ -64,11 +64,28 @@
       }
       
       size = (ulong)(rdtscCode.Length + cpuidCode.Length);
-      
-      if ((p == 4) || (p == 128)) { // Unix
-        codeBuffer = Syscall.mmap(IntPtr.Zero, size, 
-          MmapProts.PROT_READ | MmapProts.PROT_WRITE | MmapProts.PROT_EXEC, 
-          MmapFlags.MAP_ANONYMOUS | MmapFlags.MAP_PRIVATE, -1, 0);
+
+      if ((p == 4) || (p == 128)) { // Unix   
+        Assembly assembly = 
+          Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " +
+          "PublicKeyToken=0738eb9f132ed756");
+
+        Type syscall = assembly.GetType("Mono.Unix.Native.Syscall");
+        MethodInfo mmap = syscall.GetMethod("mmap");
+
+        Type mmapProts = assembly.GetType("Mono.Unix.Native.MmapProts");
+        object mmapProtsParam = Enum.ToObject(mmapProts,
+          (int)mmapProts.GetField("PROT_READ").GetValue(null) |
+          (int)mmapProts.GetField("PROT_WRITE").GetValue(null) |
+          (int)mmapProts.GetField("PROT_EXEC").GetValue(null));
+
+        Type mmapFlags = assembly.GetType("Mono.Unix.Native.MmapFlags");
+        object mmapFlagsParam = Enum.ToObject(mmapFlags,
+          (int)mmapFlags.GetField("MAP_ANONYMOUS").GetValue(null) |
+          (int)mmapFlags.GetField("MAP_PRIVATE").GetValue(null));
+        
+        codeBuffer = (IntPtr)mmap.Invoke(null, new object[] { IntPtr.Zero, 
+          size, mmapProtsParam, mmapFlagsParam, -1, 0 });        
       } else { // Windows
         codeBuffer = NativeMethods.VirtualAlloc(IntPtr.Zero,
           (UIntPtr)size, AllocationType.COMMIT | AllocationType.RESERVE, 
@@ -93,7 +110,14 @@
       
       int p = (int)Environment.OSVersion.Platform;
       if ((p == 4) || (p == 128)) { // Unix
-        Syscall.munmap(codeBuffer, size);
+        Assembly assembly =
+          Assembly.Load("Mono.Posix, Version=2.0.0.0, Culture=neutral, " +
+          "PublicKeyToken=0738eb9f132ed756");
+
+        Type syscall = assembly.GetType("Mono.Unix.Native.Syscall");
+        MethodInfo munmap = syscall.GetMethod("munmap");
+        munmap.Invoke(null, new object[] { codeBuffer, size });
+
       } else { // Windows
         NativeMethods.VirtualFree(codeBuffer, UIntPtr.Zero, 
           FreeType.RELEASE);        
@@ -246,7 +270,7 @@
     }
 
     [Flags]
-    enum FreeType {
+    public enum FreeType {
       DECOMMIT = 0x4000,
       RELEASE = 0x8000
     }
diff -r bddc6e01840a -r 91800d0f54de OpenHardwareMonitorLib.csproj
--- a/OpenHardwareMonitorLib.csproj	Wed Nov 03 22:07:46 2010 +0000
+++ b/OpenHardwareMonitorLib.csproj	Thu Nov 04 21:46:14 2010 +0000
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
+<?xml version="1.0" encoding="utf-8"?>
 <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -54,7 +54,6 @@
   <ItemGroup>
     <Reference Include="System" />
     <Reference Include="System.Management" />
-    <Reference Include="Mono.Posix" />
   </ItemGroup>
   <ItemGroup>
     <Compile Include="Hardware\ATI\ADL.cs" />