| 1 | // ---------------------------------------------------------------------------- |
| 2 | // <auto-generated> |
| 3 | // This is autogenerated code by CppSharp with tweaks. |
| 4 | // Do not edit this file or all your changes will be lost after re-generation. |
| 5 | // </auto-generated> |
| 6 | // ---------------------------------------------------------------------------- |
| 7 | using System; |
| 8 | using System.Runtime.InteropServices; |
| 9 | using System.Security; |
| 10 | using WslSettings; |
| 11 | using __CallingConvention = global::System.Runtime.InteropServices.CallingConvention; |
| 12 | using __IntPtr = global::System.IntPtr; |
| 13 | |
| 14 | #pragma warning disable CS0109 // Member does not hide an inherited member; new keyword is not required |
| 15 | |
| 16 | namespace LibWsl |
| 17 | { |
| 18 | public enum WslConfigEntry |
| 19 | { |
| 20 | NoEntry = 0, |
| 21 | ProcessorCount = 1, |
| 22 | MemorySizeBytes = 2, |
| 23 | SwapSizeBytes = 3, |
| 24 | SwapFilePath = 4, |
| 25 | VhdSizeBytes = 5, |
| 26 | NetworkingMode = 6, |
| 27 | FirewallEnabled = 7, |
| 28 | IgnoredPorts = 8, |
| 29 | LocalhostForwardingEnabled = 9, |
| 30 | HostAddressLoopbackEnabled = 10, |
| 31 | AutoProxyEnabled = 11, |
| 32 | InitialAutoProxyTimeout = 12, |
| 33 | DNSProxyEnabled = 13, |
| 34 | DNSTunnelingEnabled = 14, |
| 35 | BestEffortDNSParsingEnabled = 15, |
| 36 | AutoMemoryReclaim = 16, |
| 37 | GUIApplicationsEnabled = 17, |
| 38 | NestedVirtualizationEnabled = 18, |
| 39 | SafeModeEnabled = 19, |
| 40 | SparseVHDEnabled = 20, |
| 41 | VMIdleTimeout = 21, |
| 42 | DebugConsoleEnabled = 22, |
| 43 | HardwarePerformanceCountersEnabled = 23, |
| 44 | KernelPath = 24, |
| 45 | SystemDistroPath = 25, |
| 46 | KernelModulesPath = 26, |
| 47 | InstanceIdleTimeout = 27 |
| 48 | } |
| 49 | |
| 50 | public enum NetworkingConfiguration |
| 51 | { |
| 52 | None = 0, |
| 53 | Nat = 1, |
| 54 | Bridged = 2, |
| 55 | Mirrored = 3, |
| 56 | Consomme = 4 |
| 57 | } |
| 58 | |
| 59 | public enum MemoryReclaimMode |
| 60 | { |
| 61 | Disabled = 0, |
| 62 | Gradual = 1, |
| 63 | DropCache = 2 |
| 64 | } |
| 65 | |
| 66 | public unsafe partial class WslConfig |
| 67 | { |
| 68 | public partial struct __Internal |
| 69 | { |
| 70 | } |
| 71 | |
| 72 | public __IntPtr __Instance { get; protected set; } |
| 73 | |
| 74 | internal static readonly new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::LibWsl.WslConfig> NativeToManagedMap = |
| 75 | new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::LibWsl.WslConfig>(); |
| 76 | |
| 77 | internal static void __RecordNativeToManagedMapping(IntPtr native, global::LibWsl.WslConfig managed) |
| 78 | { |
| 79 | NativeToManagedMap[native] = managed; |
| 80 | } |
| 81 | |
| 82 | internal static bool __TryGetNativeToManagedMapping(IntPtr native, out global::LibWsl.WslConfig managed) |
| 83 | { |
| 84 | |
| 85 | return NativeToManagedMap.TryGetValue(native, out managed); |
| 86 | } |
| 87 | |
| 88 | protected bool __ownsNativeInstance; |
| 89 | |
| 90 | internal static WslConfig __CreateInstance(__IntPtr native, bool skipVTables = false) |
| 91 | { |
| 92 | if (native == __IntPtr.Zero) |
| 93 | return null; |
| 94 | return new WslConfig(native.ToPointer(), skipVTables); |
| 95 | } |
| 96 | |
| 97 | internal static WslConfig __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false) |
| 98 | { |
| 99 | if (native == __IntPtr.Zero) |
| 100 | return null; |
| 101 | if (__TryGetNativeToManagedMapping(native, out var managed)) |
| 102 | return (WslConfig)managed; |
| 103 | var result = __CreateInstance(native, skipVTables); |
| 104 | if (saveInstance) |
| 105 | __RecordNativeToManagedMapping(native, result); |
| 106 | return result; |
| 107 | } |
| 108 | |
| 109 | internal static WslConfig __CreateInstance(__Internal native, bool skipVTables = false) |
| 110 | { |
| 111 | return new WslConfig(native, skipVTables); |
| 112 | } |
| 113 | |
| 114 | private static void* __CopyValue(__Internal native) |
| 115 | { |
| 116 | var ret = Marshal.AllocHGlobal(sizeof(__Internal)); |
| 117 | *(__Internal*) ret = native; |
| 118 | return ret.ToPointer(); |
| 119 | } |
| 120 | |
| 121 | private WslConfig(__Internal native, bool skipVTables = false) |
| 122 | : this(__CopyValue(native), skipVTables) |
| 123 | { |
| 124 | __ownsNativeInstance = true; |
| 125 | __RecordNativeToManagedMapping(__Instance, this); |
| 126 | } |
| 127 | |
| 128 | protected WslConfig(void* native, bool skipVTables = false) |
| 129 | { |
| 130 | if (native == null) |
| 131 | return; |
| 132 | __Instance = new __IntPtr(native); |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | public unsafe partial class WslConfigSetting : IDisposable |
| 137 | { |
| 138 | [StructLayout(LayoutKind.Explicit, Size = 16)] |
| 139 | public partial struct __Internal |
| 140 | { |
| 141 | [FieldOffset(0)] |
| 142 | internal global::LibWsl.WslConfigEntry ConfigEntry; |
| 143 | |
| 144 | [FieldOffset(8)] |
| 145 | internal __IntPtr StringValue; |
| 146 | |
| 147 | [FieldOffset(8)] |
| 148 | internal ulong UInt64Value; |
| 149 | |
| 150 | [FieldOffset(8)] |
| 151 | internal int Int32Value; |
| 152 | |
| 153 | [FieldOffset(8)] |
| 154 | internal byte BoolValue; |
| 155 | |
| 156 | [FieldOffset(8)] |
| 157 | internal global::LibWsl.NetworkingConfiguration NetworkingConfigurationValue; |
| 158 | |
| 159 | [FieldOffset(8)] |
| 160 | internal global::LibWsl.MemoryReclaimMode MemoryReclaimModeValue; |
| 161 | } |
| 162 | |
| 163 | public __IntPtr __Instance { get; protected set; } |
| 164 | |
| 165 | internal static readonly new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::LibWsl.WslConfigSetting> NativeToManagedMap = |
| 166 | new global::System.Collections.Concurrent.ConcurrentDictionary<IntPtr, global::LibWsl.WslConfigSetting>(); |
| 167 | |
| 168 | internal static void __RecordNativeToManagedMapping(IntPtr native, global::LibWsl.WslConfigSetting managed) |
| 169 | { |
| 170 | NativeToManagedMap[native] = managed; |
| 171 | } |
| 172 | |
| 173 | internal static bool __TryGetNativeToManagedMapping(IntPtr native, out global::LibWsl.WslConfigSetting managed) |
| 174 | { |
| 175 | |
| 176 | return NativeToManagedMap.TryGetValue(native, out managed); |
| 177 | } |
| 178 | |
| 179 | protected bool __ownsNativeInstance; |
| 180 | protected bool __ownsNativeStringValueInstance; |
| 181 | |
| 182 | internal static WslConfigSetting __CreateInstance(__IntPtr native, bool skipVTables = false) |
| 183 | { |
| 184 | if (native == __IntPtr.Zero) |
| 185 | return null; |
| 186 | return new WslConfigSetting(native.ToPointer(), skipVTables); |
| 187 | } |
| 188 | |
| 189 | internal static WslConfigSetting __GetOrCreateInstance(__IntPtr native, bool saveInstance = false, bool skipVTables = false) |
| 190 | { |
| 191 | if (native == __IntPtr.Zero) |
| 192 | return null; |
| 193 | if (__TryGetNativeToManagedMapping(native, out var managed)) |
| 194 | return (WslConfigSetting)managed; |
| 195 | var result = __CreateInstance(native, skipVTables); |
| 196 | if (saveInstance) |
| 197 | __RecordNativeToManagedMapping(native, result); |
| 198 | return result; |
| 199 | } |
| 200 | |
| 201 | internal static WslConfigSetting __CreateInstance(__Internal native, bool skipVTables = false) |
| 202 | { |
| 203 | return new WslConfigSetting(native, skipVTables); |
| 204 | } |
| 205 | |
| 206 | private static void* __CopyValue(__Internal native) |
| 207 | { |
| 208 | var ret = Marshal.AllocHGlobal(sizeof(__Internal)); |
| 209 | *(__Internal*) ret = native; |
| 210 | return ret.ToPointer(); |
| 211 | } |
| 212 | |
| 213 | private WslConfigSetting(__Internal native, bool skipVTables = false) |
| 214 | : this(__CopyValue(native), skipVTables) |
| 215 | { |
| 216 | __ownsNativeInstance = true; |
| 217 | __RecordNativeToManagedMapping(__Instance, this); |
| 218 | __ownsNativeStringValueInstance = false; |
| 219 | } |
| 220 | |
| 221 | protected WslConfigSetting(void* native, bool skipVTables = false) |
| 222 | { |
| 223 | if (native == null) |
| 224 | return; |
| 225 | __Instance = new __IntPtr(native); |
| 226 | } |
| 227 | |
| 228 | public void Dispose() |
| 229 | { |
| 230 | Dispose(disposing: true, callNativeDtor : __ownsNativeInstance ); |
| 231 | } |
| 232 | |
| 233 | partial void DisposePartial(bool disposing); |
| 234 | |
| 235 | internal protected virtual void Dispose(bool disposing, bool callNativeDtor ) |
| 236 | { |
| 237 | if (__Instance == IntPtr.Zero) |
| 238 | return; |
| 239 | NativeToManagedMap.TryRemove(__Instance, out _); |
| 240 | DisposePartial(disposing); |
| 241 | if (__ownsNativeInstance) |
| 242 | Marshal.FreeHGlobal(__Instance); |
| 243 | if (__ownsNativeStringValueInstance && ((__Internal*)__Instance)->StringValue != __IntPtr.Zero) |
| 244 | Marshal.FreeHGlobal(((__Internal*)__Instance)->StringValue); |
| 245 | __Instance = IntPtr.Zero; |
| 246 | } |
| 247 | |
| 248 | public global::LibWsl.WslConfigEntry ConfigEntry |
| 249 | { |
| 250 | get |
| 251 | { |
| 252 | return ((__Internal*)__Instance)->ConfigEntry; |
| 253 | } |
| 254 | |
| 255 | set |
| 256 | { |
| 257 | ((__Internal*)__Instance)->ConfigEntry = value; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | public string StringValue |
| 262 | { |
| 263 | get |
| 264 | { |
| 265 | return Marshal.PtrToStringAuto((IntPtr)((__Internal*)__Instance)->StringValue); |
| 266 | } |
| 267 | set |
| 268 | { |
| 269 | if (__ownsNativeStringValueInstance && ((__Internal*)__Instance)->StringValue != __IntPtr.Zero) |
| 270 | Marshal.FreeHGlobal(((__Internal*)__Instance)->StringValue); |
| 271 | ((__Internal*)__Instance)->StringValue = Marshal.StringToHGlobalAuto(value); |
| 272 | __ownsNativeStringValueInstance = true; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | public ulong UInt64Value |
| 277 | { |
| 278 | get |
| 279 | { |
| 280 | return ((__Internal*)__Instance)->UInt64Value; |
| 281 | } |
| 282 | |
| 283 | set |
| 284 | { |
| 285 | ((__Internal*)__Instance)->UInt64Value = value; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | public int Int32Value |
| 290 | { |
| 291 | get |
| 292 | { |
| 293 | return ((__Internal*)__Instance)->Int32Value; |
| 294 | } |
| 295 | |
| 296 | set |
| 297 | { |
| 298 | ((__Internal*)__Instance)->Int32Value = value; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | public bool BoolValue |
| 303 | { |
| 304 | get |
| 305 | { |
| 306 | return ((__Internal*)__Instance)->BoolValue != 0; |
| 307 | } |
| 308 | |
| 309 | set |
| 310 | { |
| 311 | ((__Internal*)__Instance)->BoolValue = (byte) (value ? 1 : 0); |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | public global::LibWsl.NetworkingConfiguration NetworkingConfigurationValue |
| 316 | { |
| 317 | get |
| 318 | { |
| 319 | return ((__Internal*)__Instance)->NetworkingConfigurationValue; |
| 320 | } |
| 321 | |
| 322 | set |
| 323 | { |
| 324 | ((__Internal*)__Instance)->NetworkingConfigurationValue = value; |
| 325 | } |
| 326 | } |
| 327 | |
| 328 | public global::LibWsl.MemoryReclaimMode MemoryReclaimModeValue |
| 329 | { |
| 330 | get |
| 331 | { |
| 332 | return ((__Internal*)__Instance)->MemoryReclaimModeValue; |
| 333 | } |
| 334 | |
| 335 | set |
| 336 | { |
| 337 | ((__Internal*)__Instance)->MemoryReclaimModeValue = value; |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | |
| 342 | public unsafe partial class WslCoreConfigInterface |
| 343 | { |
| 344 | public partial struct __Internal |
| 345 | { |
| 346 | [SuppressUnmanagedCodeSecurity, DllImport(@"..\libwsl.dll", EntryPoint = "GetWslConfigFilePath", CallingConvention = __CallingConvention.StdCall)] |
| 347 | internal static extern char* GetWslConfigFilePath(); |
| 348 | |
| 349 | [SuppressUnmanagedCodeSecurity, DllImport(@"..\libwsl.dll", EntryPoint = "CreateWslConfig", CallingConvention = __CallingConvention.StdCall)] |
| 350 | internal static extern __IntPtr CreateWslConfig(char* wslConfigFilePath); |
| 351 | |
| 352 | [SuppressUnmanagedCodeSecurity, DllImport(@"..\libwsl.dll", EntryPoint = "FreeWslConfig", CallingConvention = __CallingConvention.StdCall)] |
| 353 | internal static extern void FreeWslConfig(__IntPtr wslConfig); |
| 354 | |
| 355 | [SuppressUnmanagedCodeSecurity, DllImport(@"..\libwsl.dll", EntryPoint = "GetWslConfigSetting", CallingConvention = __CallingConvention.StdCall)] |
| 356 | internal static extern global::LibWsl.WslConfigSetting.__Internal GetWslConfigSetting(__IntPtr wslConfig, global::LibWsl.WslConfigEntry ConfigEntry); |
| 357 | |
| 358 | [SuppressUnmanagedCodeSecurity, DllImport(@"..\libwsl.dll", EntryPoint = "SetWslConfigSetting", CallingConvention = __CallingConvention.StdCall)] |
| 359 | internal static extern uint SetWslConfigSetting(__IntPtr wslConfig, global::LibWsl.WslConfigSetting.__Internal setting); |
| 360 | } |
| 361 | |
| 362 | public static string GetWslConfigFilePath() |
| 363 | { |
| 364 | var ___ret = __Internal.GetWslConfigFilePath(); |
| 365 | return Marshal.PtrToStringAuto((IntPtr)___ret); |
| 366 | } |
| 367 | |
| 368 | public static global::LibWsl.WslConfig CreateWslConfig(string wslConfigFilePath) |
| 369 | { |
| 370 | var __arg0 = (char*)Marshal.StringToHGlobalAuto(wslConfigFilePath); |
| 371 | var ___ret = __Internal.CreateWslConfig(__arg0); |
| 372 | var __result0 = global::LibWsl.WslConfig.__GetOrCreateInstance(___ret, false); |
| 373 | Marshal.FreeHGlobal((IntPtr)__arg0); |
| 374 | return __result0; |
| 375 | } |
| 376 | |
| 377 | public static void FreeWslConfig(global::LibWsl.WslConfig wslConfig) |
| 378 | { |
| 379 | var __arg0 = wslConfig is null ? __IntPtr.Zero : wslConfig.__Instance; |
| 380 | __Internal.FreeWslConfig(__arg0); |
| 381 | } |
| 382 | |
| 383 | public static global::LibWsl.WslConfigSetting GetWslConfigSetting(global::LibWsl.WslConfig wslConfig, global::LibWsl.WslConfigEntry ConfigEntry) |
| 384 | { |
| 385 | var __arg0 = wslConfig is null ? __IntPtr.Zero : wslConfig.__Instance; |
| 386 | var ___ret = __Internal.GetWslConfigSetting(__arg0, ConfigEntry); |
| 387 | return global::LibWsl.WslConfigSetting.__CreateInstance(___ret); |
| 388 | } |
| 389 | |
| 390 | public static uint SetWslConfigSetting(global::LibWsl.WslConfig wslConfig, global::LibWsl.WslConfigSetting setting) |
| 391 | { |
| 392 | var __arg0 = wslConfig is null ? __IntPtr.Zero : wslConfig.__Instance; |
| 393 | if (ReferenceEquals(setting, null)) |
| 394 | throw new global::System.ArgumentNullException("setting", "Cannot be null because it is passed by value."); |
| 395 | var __arg1 = setting.__Instance; |
| 396 | var ___ret = __Internal.SetWslConfigSetting(__arg0, *(global::LibWsl.WslConfigSetting.__Internal*) __arg1); |
| 397 | return ___ret; |
| 398 | } |
| 399 | } |
| 400 | } |