]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/nt-base.c
(no commit message)
[imagemagick] / MagickCore / nt-base.c
index ec38b6493f24ef7f6efe0028b6e915449cc9a0bb..d9414bd7664979043df5921f2b98df012e03d8c2 100644 (file)
 #include "MagickCore/log.h"
 #include "MagickCore/magick.h"
 #include "MagickCore/memory_.h"
+#include "MagickCore/nt-base.h"
+#include "MagickCore/nt-base-private.h"
 #include "MagickCore/resource_.h"
+#include "MagickCore/resource-private.h"
 #include "MagickCore/timer.h"
 #include "MagickCore/string_.h"
 #include "MagickCore/utility.h"
@@ -54,7 +57,7 @@
 #if defined(MAGICKCORE_LTDL_DELEGATE)
 #  include "ltdl.h"
 #endif
-#include "MagickCore/nt-base.h"
+#include "MagickCore/nt-base-private.h"
 #if defined(MAGICKCORE_CIPHER_SUPPORT)
 #include <ntsecapi.h>
 #include <wincrypt.h>
@@ -230,7 +233,7 @@ BOOL WINAPI DllMain(HINSTANCE handle,DWORD reason,LPVOID lpvReserved)
 %      process.
 %
 */
-MagickExport int Exit(int status)
+MagickPrivate int Exit(int status)
 {
   if (IsWindows95())
     TerminateProcess(GetCurrentProcess(),(unsigned int) status);
@@ -263,7 +266,7 @@ MagickExport int Exit(int status)
 %    o time_zone: the time zone.
 %
 */
-MagickExport int gettimeofday (struct timeval *time_value,
+MagickPrivate int gettimeofday (struct timeval *time_value,
   struct timezone *time_zone)
 {
 #define EpochFiletime  MagickLLConstant(116444736000000000)
@@ -323,7 +326,7 @@ MagickExport int gettimeofday (struct timeval *time_value,
 %      int IsWindows95()
 %
 */
-MagickExport int IsWindows95()
+MagickPrivate int IsWindows95()
 {
   OSVERSIONINFO
     version_info;
@@ -360,7 +363,7 @@ MagickExport int IsWindows95()
 %    o argv:  the  wide-character command line arguments.
 %
 */
-MagickExport char **NTArgvToUTF8(const int argc,wchar_t **argv)
+MagickPrivate char **NTArgvToUTF8(const int argc,wchar_t **argv)
 {
   char
     **utf8;
@@ -417,7 +420,7 @@ MagickExport char **NTArgvToUTF8(const int argc,wchar_t **argv)
 %    o entry: Specifies a pointer to a DIR structure.
 %
 */
-MagickExport int NTCloseDirectory(DIR *entry)
+MagickPrivate int NTCloseDirectory(DIR *entry)
 {
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
   assert(entry != (DIR *) NULL);
@@ -448,7 +451,7 @@ MagickExport int NTCloseDirectory(DIR *entry)
 %    o handle: Specifies a handle to a previously loaded dynamic module.
 %
 */
-MagickExport int NTCloseLibrary(void *handle)
+MagickPrivate int NTCloseLibrary(void *handle)
 {
   if (IsWindows95())
     return(FreeLibrary((HINSTANCE) handle));
@@ -482,7 +485,7 @@ static BOOL ControlHandler(DWORD type)
   return(FALSE);
 }
 
-MagickExport int NTControlHandler(void)
+MagickPrivate int NTControlHandler(void)
 {
   return(SetConsoleCtrlHandler((PHANDLER_ROUTINE) ControlHandler,TRUE));
 }
@@ -506,7 +509,7 @@ MagickExport int NTControlHandler(void)
 %      double NTElapsedTime(void)
 %
 */
-MagickExport double NTElapsedTime(void)
+MagickPrivate double NTElapsedTime(void)
 {
   union
   {
@@ -553,7 +556,7 @@ MagickExport double NTElapsedTime(void)
 %    o description: Specifies any description to the reason.
 %
 */
-MagickExport void NTErrorHandler(const ExceptionType severity,
+MagickPrivate void NTErrorHandler(const ExceptionType severity,
   const char *reason,const char *description)
 {
   char
@@ -606,7 +609,7 @@ MagickExport void NTErrorHandler(const ExceptionType severity,
 %      int NTExitLibrary(void)
 %
 */
-MagickExport int NTExitLibrary(void)
+MagickPrivate int NTExitLibrary(void)
 {
   return(0);
 }
@@ -636,7 +639,7 @@ MagickExport int NTExitLibrary(void)
 %    random: the random data is returned here.
 %
 */
-MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
+MagickPrivate MagickBooleanType NTGatherRandomData(const size_t length,
   unsigned char *random)
 {
 #if defined(MAGICKCORE_CIPHER_SUPPORT) && defined(_MSC_VER) && (_MSC_VER > 1200)
@@ -694,7 +697,7 @@ MagickExport MagickBooleanType NTGatherRandomData(const size_t length,
 %    o extent: the maximum extent of the path.
 %
 */
-MagickExport MagickBooleanType NTGetExecutionPath(char *path,
+MagickPrivate MagickBooleanType NTGetExecutionPath(char *path,
   const size_t extent)
 {
   GetModuleFileName(0,path,(DWORD) extent);
@@ -763,7 +766,7 @@ char *NTGetLastError(void)
 %      const char *NTGetLibraryError(void)
 %
 */
-MagickExport const char *NTGetLibraryError(void)
+MagickPrivate const char *NTGetLibraryError(void)
 {
   static char
     last_error[MaxTextExtent];
@@ -839,7 +842,7 @@ void *NTGetLibrarySymbol(void *handle,const char *name)
 %    path: the module path is returned here.
 %
 */
-MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
+MagickPrivate MagickBooleanType NTGetModulePath(const char *module,char *path)
 {
   char
     module_path[MaxTextExtent];
@@ -886,7 +889,7 @@ MagickExport MagickBooleanType NTGetModulePath(const char *module,char *path)
 %
 */
 
-static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
+static int NTGetRegistryValue(HKEY root,const char *key,DWORD flags,const char *name,
   char *value,int *length)
 {
   BYTE
@@ -906,7 +909,7 @@ static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
   /*
     Get a registry value: key = root\\key, named value = name.
   */
-  if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
+  if (RegOpenKeyExA(root,key,0,KEY_READ | flags,&hkey) != ERROR_SUCCESS)
     return(1);  /* no match */
   p=(BYTE *) value;
   type=REG_SZ;
@@ -928,7 +931,7 @@ static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
   return(1);  /* not found */
 }
 
-static int NTLocateGhostscript(const char **product_family,int *major_version,
+static int NTLocateGhostscript(DWORD flags,const char **product_family,int *major_version,
   int *minor_version)
 {
   int
@@ -967,7 +970,7 @@ static int NTLocateGhostscript(const char **product_family,int *major_version,
 
     (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
     root=HKEY_LOCAL_MACHINE;
-    mode=KEY_READ;
+    mode=KEY_READ | flags;
     if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
       {
         DWORD
@@ -1012,7 +1015,17 @@ static int NTLocateGhostscript(const char **product_family,int *major_version,
   return(status);
 }
 
-static int NTGhostscriptGetString(const char *name,char *value,
+static BOOL NTIs64BitPlatform()
+{
+#if defined(_WIN64) || !defined(KEY_WOW64_32KEY)
+  return(TRUE);
+#else
+  BOOL is64=FALSE;
+  return(IsWow64Process(GetCurrentProcess(), &is64) && is64);
+#endif
+}
+
+static int NTGhostscriptGetString(const char *name,BOOL *is_64_bit,char *value,
   const size_t length)
 {
   char
@@ -1025,7 +1038,11 @@ static int NTGhostscriptGetString(const char *name,char *value,
   static const char
     *product_family = (const char *) NULL;
 
+  static BOOL
+    is_64_bit_version = FALSE;
+
   static int
+    flags=0,
     major_version=0,
     minor_version=0;
 
@@ -1046,9 +1063,37 @@ static int NTGhostscriptGetString(const char *name,char *value,
   /*
     Get a string from the installed Ghostscript.
   */
+  if (is_64_bit!=NULL)
+    *is_64_bit=FALSE;
   *value='\0';
   if (product_family == NULL)
-    (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
+  {
+    flags=0;
+#if defined(KEY_WOW64_32KEY)
+    flags=NTIs64BitPlatform() ? KEY_WOW64_64KEY : 0;
+#endif
+    (void) NTLocateGhostscript(flags,&product_family,&major_version,
+      &minor_version);
+    if (product_family == NULL)
+    {
+      if (flags!=0)
+      {
+        /*
+          We are running on a 64 bit platform - check for a 32 bit Ghostscript.
+        */
+        flags=0;
+#if defined(KEY_WOW64_32KEY)
+        flags=KEY_WOW64_32KEY;
+#endif
+        (void) NTLocateGhostscript(flags,&product_family,&major_version,
+          &minor_version);
+         }
+    }
+    else
+      is_64_bit_version=NTIs64BitPlatform();
+  }
+  if (is_64_bit!=NULL)
+    *is_64_bit=is_64_bit_version;
   if (product_family == NULL)
     return(FALSE);
   (void) FormatLocaleString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
@@ -1056,7 +1101,7 @@ static int NTGhostscriptGetString(const char *name,char *value,
   for (i=0; i < (ssize_t) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
   {
     extent=(int) length;
-    if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
+    if (NTGetRegistryValue(hkeys[i].hkey,key,flags,name,value,&extent) == 0)
       {
         (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
           "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
@@ -1068,15 +1113,26 @@ static int NTGhostscriptGetString(const char *name,char *value,
   return(FALSE);
 }
 
-MagickExport int NTGhostscriptDLL(char *path,int length)
+MagickPrivate int NTGhostscriptDLL(char *path,int length)
 {
   static char
     dll[MaxTextExtent] = { "" };
 
+  static BOOL
+    is_64_bit_version;
+
   *path='\0';
   if ((*dll == '\0') &&
-      (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
+      (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,dll,sizeof(dll)) == FALSE))
     return(FALSE);
+
+#if defined(_WIN64)
+  if (!is_64_bit_version)
+    return(FALSE);
+#else
+  if (is_64_bit_version)
+    return(FALSE);
+#endif
   (void) CopyMagickString(path,dll,length);
   return(TRUE);
 }
@@ -1102,7 +1158,7 @@ MagickExport int NTGhostscriptDLL(char *path,int length)
 %      const GhostInfo *NTGhostscriptDLLVectors(void)
 %
 */
-MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
+MagickPrivate const GhostInfo *NTGhostscriptDLLVectors(void)
 {
   if (NTGhostscriptLoadDLL() == FALSE)
     return((GhostInfo *) NULL);
@@ -1135,7 +1191,7 @@ MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
 %    o length: length of buffer.
 %
 */
-MagickExport int NTGhostscriptEXE(char *path,int length)
+MagickPrivate int NTGhostscriptEXE(char *path,int length)
 {
   register char
     *p;
@@ -1143,16 +1199,19 @@ MagickExport int NTGhostscriptEXE(char *path,int length)
   static char
     program[MaxTextExtent] = { "" };
 
+  static BOOL
+    is_64_bit_version = FALSE;
+
   (void) CopyMagickString(path,"gswin32c.exe",length);
   if ((*program == '\0') &&
-      (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
+      (NTGhostscriptGetString("GS_DLL",&is_64_bit_version,program,sizeof(program)) == FALSE))
     return(FALSE);
   p=strrchr(program,'\\');
   if (p != (char *) NULL)
     {
       p++;
       *p='\0';
-      (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
+      (void) ConcatenateMagickString(program,is_64_bit_version ? "gswin64c.exe" : "gswin32c.exe",sizeof(program));
     }
   (void) CopyMagickString(path,program,length);
   return(TRUE);
@@ -1183,7 +1242,7 @@ MagickExport int NTGhostscriptEXE(char *path,int length)
 %    o length: length of the path buffer.
 %
 */
-MagickExport int NTGhostscriptFonts(char *path,int length)
+MagickPrivate int NTGhostscriptFonts(char *path,int length)
 {
   char
     buffer[MaxTextExtent],
@@ -1194,7 +1253,7 @@ MagickExport int NTGhostscriptFonts(char *path,int length)
     *q;
 
   *path='\0';
-  if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
+  if (NTGhostscriptGetString("GS_LIB",NULL,buffer,MaxTextExtent) == FALSE)
     return(FALSE);
   for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
   {
@@ -1229,7 +1288,7 @@ MagickExport int NTGhostscriptFonts(char *path,int length)
 %      int NTGhostscriptLoadDLL(void)
 %
 */
-MagickExport int NTGhostscriptLoadDLL(void)
+MagickPrivate int NTGhostscriptLoadDLL(void)
 {
   char
     path[MaxTextExtent];
@@ -1278,7 +1337,7 @@ MagickExport int NTGhostscriptLoadDLL(void)
 %      int NTGhostscriptUnLoadDLL(void)
 %
 */
-MagickExport int NTGhostscriptUnLoadDLL(void)
+MagickPrivate int NTGhostscriptUnLoadDLL(void)
 {
   int
     status;
@@ -1309,7 +1368,7 @@ MagickExport int NTGhostscriptUnLoadDLL(void)
 %      int NTInitializeLibrary(void)
 %
 */
-MagickExport int NTInitializeLibrary(void)
+MagickPrivate int NTInitializeLibrary(void)
 {
   return(0);
 }
@@ -1329,11 +1388,11 @@ MagickExport int NTInitializeLibrary(void)
 %
 %  The format of the NTMapMemory method is:
 %
-%    MagickExport void *NTMapMemory(char *address,size_t length,int protection,
+%    MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
 %      int access,int file,MagickOffsetType offset)
 %
 */
-MagickExport void *NTMapMemory(char *address,size_t length,int protection,
+MagickPrivate void *NTMapMemory(char *address,size_t length,int protection,
   int flags,int file,MagickOffsetType offset)
 {
   DWORD
@@ -1418,7 +1477,7 @@ MagickExport void *NTMapMemory(char *address,size_t length,int protection,
 %    o entry: Specifies a pointer to a DIR structure.
 %
 */
-MagickExport DIR *NTOpenDirectory(const char *path)
+MagickPrivate DIR *NTOpenDirectory(const char *path)
 {
   char
     file_specification[MaxTextExtent];
@@ -1495,7 +1554,7 @@ static const char *GetSearchPath( void )
 #endif
 }
 
-MagickExport void *NTOpenLibrary(const char *filename)
+MagickPrivate void *NTOpenLibrary(const char *filename)
 {
 #define MaxPathElements  31
 
@@ -1576,7 +1635,7 @@ MagickExport void *NTOpenLibrary(const char *filename)
 %    o entry: Specifies a pointer to a DIR structure.
 %
 */
-MagickExport struct dirent *NTReadDirectory(DIR *entry)
+MagickPrivate struct dirent *NTReadDirectory(DIR *entry)
 {
   int
     status;
@@ -1633,7 +1692,7 @@ MagickExport struct dirent *NTReadDirectory(DIR *entry)
 %      "LibPath", "CoderModulesPath", "FilterModulesPath", "SharePath".
 %
 */
-MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
+MagickPrivate unsigned char *NTRegistryKeyLookup(const char *subkey)
 {
   char
     package_key[MaxTextExtent];
@@ -1720,7 +1779,7 @@ MagickExport unsigned char *NTRegistryKeyLookup(const char *subkey)
 %    o error: MagickTrue the event is an error.
 %
 */
-MagickExport MagickBooleanType NTReportEvent(const char *event,
+MagickPrivate MagickBooleanType NTReportEvent(const char *event,
   const MagickBooleanType error)
 {
   const char
@@ -1767,7 +1826,7 @@ MagickExport MagickBooleanType NTReportEvent(const char *event,
 %    o id: Specifies a string that identifies the resource.
 %
 */
-MagickExport unsigned char *NTResourceToBlob(const char *id)
+MagickPrivate unsigned char *NTResourceToBlob(const char *id)
 {
   char
     path[MaxTextExtent];
@@ -1849,7 +1908,7 @@ MagickExport unsigned char *NTResourceToBlob(const char *id)
 %      stream.
 %
 */
-MagickExport void NTSeekDirectory(DIR *entry,ssize_t position)
+MagickPrivate void NTSeekDirectory(DIR *entry,ssize_t position)
 {
   (void) position;
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
@@ -1880,7 +1939,7 @@ MagickExport void NTSeekDirectory(DIR *entry,ssize_t position)
 %      for DLL's that can be dynamically loaded.
 %
 */
-MagickExport int NTSetSearchPath(const char *path)
+MagickPrivate int NTSetSearchPath(const char *path)
 {
 #if defined(MAGICKCORE_LTDL_DELEGATE)
   lt_dlsetsearchpath(path);
@@ -1919,7 +1978,7 @@ MagickExport int NTSetSearchPath(const char *path)
 %    o flags: Option flags (ignored for Windows).
 %
 */
-MagickExport int NTSyncMemory(void *address,size_t length,int flags)
+MagickPrivate int NTSyncMemory(void *address,size_t length,int flags)
 {
   (void) flags;
   if (FlushViewOfFile(address,length) == MagickFalse)
@@ -1950,7 +2009,7 @@ MagickExport int NTSyncMemory(void *address,size_t length,int flags)
 %    o command: This string is the command to execute.
 %
 */
-MagickExport int NTSystemCommand(const char *command)
+MagickPrivate int NTSystemCommand(const char *command)
 {
   char
     local_command[MaxTextExtent];
@@ -1978,19 +2037,19 @@ MagickExport int NTSystemCommand(const char *command)
   (void) CopyMagickString(local_command,command,MaxTextExtent);
   background_process=command[strlen(command)-1] == '&' ? MagickTrue :
     MagickFalse;
-  if (background_process)
+  if (background_process != MagickFalse)
     local_command[strlen(command)-1]='\0';
   if (command[strlen(command)-1] == '|')
      local_command[strlen(command)-1]='\0';
    else
      startup_info.wShowWindow=SW_SHOWDEFAULT;
-  status=CreateProcess((LPCTSTR) NULL,local_command,
-    (LPSECURITY_ATTRIBUTES) NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,
-    (DWORD) NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
+  status=CreateProcess((LPCTSTR) NULL,local_command,(LPSECURITY_ATTRIBUTES)
+    NULL,(LPSECURITY_ATTRIBUTES) NULL,(BOOL) FALSE,(DWORD)
+    NORMAL_PRIORITY_CLASS,(LPVOID) NULL,(LPCSTR) NULL,&startup_info,
     &process_info);
   if (status == 0)
     return(-1);
-  if (background_process)
+  if (background_process != MagickFalse)
     return(status == 0);
   status=WaitForSingleObject(process_info.hProcess,INFINITE);
   if (status != WAIT_OBJECT_0)
@@ -2026,7 +2085,7 @@ MagickExport int NTSystemCommand(const char *command)
 %    o name: _SC_PAGE_SIZE or _SC_PHYS_PAGES.
 %
 */
-MagickExport ssize_t NTSystemConfiguration(int name)
+MagickPrivate ssize_t NTSystemConfiguration(int name)
 {
   switch (name)
   {
@@ -2101,7 +2160,7 @@ MagickExport ssize_t NTSystemConfiguration(int name)
 %    o entry: Specifies a pointer to a DIR structure.
 %
 */
-MagickExport ssize_t NTTellDirectory(DIR *entry)
+MagickPrivate ssize_t NTTellDirectory(DIR *entry)
 {
   assert(entry != (DIR *) NULL);
   return(0);
@@ -2131,7 +2190,7 @@ MagickExport ssize_t NTTellDirectory(DIR *entry)
 %    o length: the file length.
 %
 */
-MagickExport int NTTruncateFile(int file,off_t length)
+MagickPrivate int NTTruncateFile(int file,off_t length)
 {
   DWORD
     file_pointer;
@@ -2178,7 +2237,7 @@ MagickExport int NTTruncateFile(int file,off_t length)
 %    o length: the length of the binary large object.
 %
 */
-MagickExport int NTUnmapMemory(void *map,size_t length)
+MagickPrivate int NTUnmapMemory(void *map,size_t length)
 {
   (void) length;
   if (UnmapViewOfFile(map) == 0)
@@ -2205,7 +2264,7 @@ MagickExport int NTUnmapMemory(void *map,size_t length)
 %      double NTUserTime(void)
 %
 */
-MagickExport double NTUserTime(void)
+MagickPrivate double NTUserTime(void)
 {
   DWORD
     status;
@@ -2274,7 +2333,7 @@ MagickExport double NTUserTime(void)
 %    o description: Specifies any description to the reason.
 %
 */
-MagickExport void NTWarningHandler(const ExceptionType severity,
+MagickPrivate void NTWarningHandler(const ExceptionType severity,
   const char *reason,const char *description)
 {
   char