System.Data.SQLite

Login
This project makes use of Eagle, provided by Mistachkin Systems.
Eagle: Secure Software Automation

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Changes In Branch preLoad Excluding Merge-Ins

This is equivalent to a diff from 377c46ce48 to 77969440cd

2012-04-03
03:58
Simplify the native library pre-loading code. Also, allow the selected processor architecture to be overridden via the environment variable 'PreLoadSQLite_ProcessorArchitecture'. check-in: 48466de4f9 user: mistachkin tags: trunk
03:18
Clarify comments and semantics of the process 'bitness' checking in the native library pre-loading code. Closed-Leaf check-in: 77969440cd user: mistachkin tags: preLoad
2012-04-02
17:58
Start of work on improving the platform detection in the native library pre-loading code. check-in: 621d22239e user: mistachkin tags: preLoad
2012-03-31
22:23
Minor enhancements to release archive verification tool. check-in: 377c46ce48 user: mistachkin tags: trunk
21:56
Document usage of the release archive verification tool in the release process. check-in: 679091c7c5 user: mistachkin tags: trunk

Changes to System.Data.SQLite/UnsafeNativeMethods.cs.

82
83
84
85
86
87
88


















































89
90
91
92
93
94
95
96
97
98
99
      /// This lock is used to protect the static _SQLiteModule and
      /// processorArchitecturePlatforms fields, below.
      /// </summary>
      private static readonly object staticSyncRoot = new object();

      /////////////////////////////////////////////////////////////////////////
      /// <summary>


















































      /// Stores the mappings between processor architecture names and platform
      /// names.
      /// </summary>
      private static Dictionary<string, string> processorArchitecturePlatforms;

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// The native module handle for the native SQLite library or the value
      /// IntPtr.Zero.
      /// </summary>
      private static IntPtr _SQLiteModule = IntPtr.Zero;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

|

|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
      /// This lock is used to protect the static _SQLiteModule and
      /// processorArchitecturePlatforms fields, below.
      /// </summary>
      private static readonly object staticSyncRoot = new object();

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// This class represents the concept of a platform as understood by the
      /// native library pre-loading code.
      /// </summary>
      private sealed class Platform
      {
          #region Private Data
          private string name;
          private int bits;
          #endregion

          /////////////////////////////////////////////////////////////////////

          #region Public Constructors
          public Platform(
              string name,
              int bits
              )
          {
              this.name = name;
              this.bits = bits;
          }
          #endregion

          /////////////////////////////////////////////////////////////////////

          #region Public Properties
          /// <summary>
          /// The name of the platform.  This is used to help locate the
          /// native library to pre-load.
          /// </summary>
          public string Name
          {
              get { return name; }
          }

          /////////////////////////////////////////////////////////////////////

          /// <summary>
          /// The number of bits needed to represent memory addresses on this
          /// platform.
          /// </summary>
          public int Bits
          {
              get { return bits; }
          }
          #endregion
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Stores the mappings between processor architecture names and platform
      /// names (and bits).
      /// </summary>
      private static Dictionary<string, Platform> processorArchitecturePlatforms;

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// The native module handle for the native SQLite library or the value
      /// IntPtr.Zero.
      /// </summary>
      private static IntPtr _SQLiteModule = IntPtr.Zero;
128
129
130
131
132
133
134





135
136

137




138


139


140

141
142
143
144
145
146
147
              //
              // TODO: Make sure this list is updated if the supported
              //       processor architecture names and/or platform names
              //       changes.
              //
              if (processorArchitecturePlatforms == null)
              {





                  processorArchitecturePlatforms =
                      new Dictionary<string, string>();






                  processorArchitecturePlatforms.Add("X86", "Win32");


                  processorArchitecturePlatforms.Add("AMD64", "x64");


                  processorArchitecturePlatforms.Add("IA64", "Itanium");

              }

              //
              // BUGBUG: What about other application domains?
              //
              if (_SQLiteModule == IntPtr.Zero)
                  _SQLiteModule = PreLoadSQLiteDll(null, null);







>
>
>
>
>

|
>

>
>
>
>
|
>
>
|
>
>
|
>







178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
              //
              // TODO: Make sure this list is updated if the supported
              //       processor architecture names and/or platform names
              //       changes.
              //
              if (processorArchitecturePlatforms == null)
              {
                  //
                  // NOTE: Create the map of processor architecture names
                  //       to platform names using a case-insensitive string
                  //       comparer.
                  //
                  processorArchitecturePlatforms =
                      new Dictionary<string, Platform>(
                          StringComparer.OrdinalIgnoreCase);

                  //
                  // NOTE: Setup the list of platform names associated with
                  //       the supported processor architectures.
                  //
                  processorArchitecturePlatforms.Add("x86",
                      new Platform("Win32", 32));

                  processorArchitecturePlatforms.Add("AMD64",
                      new Platform("x64", 64));

                  processorArchitecturePlatforms.Add("IA64",
                      new Platform("Itanium", 64));
              }

              //
              // BUGBUG: What about other application domains?
              //
              if (_SQLiteModule == IntPtr.Zero)
                  _SQLiteModule = PreLoadSQLiteDll(null, null);
233
234
235
236
237
238
239



















240
241
242
243
244
245
246
247
248
249
250
251


















252
253
254

















255
256
257
258
259
260
261
          }

          return fileName;
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>



















      /// Queries and returns the processor architecture of the current
      /// process.
      /// </summary>
      /// <returns>
      /// The processor architecture of the current process -OR- null if it
      /// cannot be determined.  Always returns an empty string when running on
      /// the .NET Compact Framework.
      /// </returns>
      private static string GetProcessorArchitecture()
      {
#if !PLATFORM_COMPACTFRAMEWORK
          //


















          // BUGBUG: Will this always be reliable?
          //
          return Environment.GetEnvironmentVariable(PROCESSOR_ARCHITECTURE);

















#else
          //
          // BUGBUG: No way to determine this value on the .NET Compact
          //         Framework (running on Windows CE, etc).
          //
          return String.Empty;
#endif







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>












>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
          }

          return fileName;
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Determines and then returns the number of bits used to represent
      /// memory addresses for the current process.
      /// </summary>
      /// <returns>
      /// The number of bits used to represent memory addresses for the
      /// current process or zero if this value cannot be determined.
      /// </returns>
      private static int GetProcessBits()
      {
          //
          // NOTE: The number of bits used to represent memory addresses for
          //       the current process is the size of an IntPtr (in bytes),
          //       multiplied by the number of bits per byte (8).
          //
          return IntPtr.Size * 8;
      }

      /////////////////////////////////////////////////////////////////////////
      /// <summary>
      /// Queries and returns the processor architecture of the current
      /// process.
      /// </summary>
      /// <returns>
      /// The processor architecture of the current process -OR- null if it
      /// cannot be determined.  Always returns an empty string when running on
      /// the .NET Compact Framework.
      /// </returns>
      private static string GetProcessorArchitecture()
      {
#if !PLATFORM_COMPACTFRAMEWORK
          //
          // NOTE: If the "PreLoadSQLite_ProcessorArchitecture" environment
          //       variable is set, use it verbatim for the current processor
          //       architecture.
          //
          string processorArchitecture = Environment.GetEnvironmentVariable(
              "PreLoadSQLite_ProcessorArchitecture");

          if (processorArchitecture != null)
              return processorArchitecture;

          //
          // NOTE: We cannot sanity check the processor architecture value
          //       without the mappings between processor architecture names
          //       and platform bits; therefore, return null in that case.
          //
          if (processorArchitecturePlatforms != null)
          {
              //
              // BUGBUG: Will this always be reliable?
              //
              processorArchitecture = Environment.GetEnvironmentVariable(
                  PROCESSOR_ARCHITECTURE);

              if (processorArchitecture != null)
              {
                  Platform platform;

                  if (processorArchitecturePlatforms.TryGetValue(
                          processorArchitecture, out platform) &&
                      (platform != null) &&
                      (platform.Bits == GetProcessBits()))
                  {
                      return processorArchitecture;
                  }
              }
          }

          return null;
#else
          //
          // BUGBUG: No way to determine this value on the .NET Compact
          //         Framework (running on Windows CE, etc).
          //
          return String.Empty;
#endif
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
              return null;

          lock (staticSyncRoot)
          {
              if (processorArchitecturePlatforms == null)
                  return null;

              string platformName;

              if (processorArchitecturePlatforms.TryGetValue(
                      processorArchitecture, out platformName))
              {
                  return platformName;
              }

              if (processorArchitecturePlatforms.TryGetValue(
#if !PLATFORM_COMPACTFRAMEWORK
                      processorArchitecture.ToUpperInvariant(),
#else
                      processorArchitecture.ToUpper(),
#endif
                      out platformName))
              {
                  return platformName;
              }
          }

          return null;
      }

      /////////////////////////////////////////////////////////////////////////







|


|
<
<
<
<
<
<
<
<
<
<
|

|







399
400
401
402
403
404
405
406
407
408
409










410
411
412
413
414
415
416
417
418
419
              return null;

          lock (staticSyncRoot)
          {
              if (processorArchitecturePlatforms == null)
                  return null;

              Platform platform;

              if (processorArchitecturePlatforms.TryGetValue(
                      processorArchitecture, out platform) &&










                  (platform != null))
              {
                  return platform.Name;
              }
          }

          return null;
      }

      /////////////////////////////////////////////////////////////////////////