Fix the long-standing mkhive bug on 64-bit systems

This is now done by adding a "typedefs64.h" header file, which uses int's instead of long's for 32-bit values. As far as I know, this is the only way to avoid the problem that a long has a size of 64-bit on 64-bit systems.
This header file is now used in the host makefiles of cmlib, inflib and mkhive. It is also suitable for the other host tools, which need 32-bit values (will do some changes there in the next few days).

Unfortunately, Live-CDs still do not work because of another bug (see bug #2290).
But I compared the hives created by 32-bit Debian Linux and 64-bit Debian Linux and after these changes, they are exactly the same.
See issue #2272 for more details.

svn path=/trunk/; revision=28389
This commit is contained in:
Colin Finck 2007-08-17 22:17:13 +00:00
parent c4bb3a9eb4
commit fe41b9be51
14 changed files with 145 additions and 87 deletions

View file

@ -107,11 +107,21 @@ inline void* ULongToPtr( const unsigned long ul )
#else /* !_WIN64 */ #else /* !_WIN64 */
typedef _W64 int INT_PTR, *PINT_PTR; typedef _W64 int INT_PTR, *PINT_PTR;
typedef _W64 unsigned int UINT_PTR, *PUINT_PTR; typedef _W64 unsigned int UINT_PTR, *PUINT_PTR;
typedef _W64 long LONG_PTR, *PLONG_PTR;
typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR; #ifndef LONG_PTR_DEFINED
#define LONG_PTR_DEFINED
typedef _W64 long LONG_PTR, *PLONG_PTR;
typedef _W64 unsigned long ULONG_PTR, *PULONG_PTR;
#endif
typedef unsigned short UHALF_PTR, *PUHALF_PTR; typedef unsigned short UHALF_PTR, *PUHALF_PTR;
typedef short HALF_PTR, *PHALF_PTR; typedef short HALF_PTR, *PHALF_PTR;
typedef _W64 unsigned long HANDLE_PTR;
#ifndef HANDLE_PTR_DEFINED
#define HANDLE_PTR_DEFINED
typedef _W64 unsigned long HANDLE_PTR;
#endif
#endif /* !_WIN64 */ #endif /* !_WIN64 */
typedef _W64 ULONG_PTR SIZE_T, *PSIZE_T; typedef _W64 ULONG_PTR SIZE_T, *PSIZE_T;

View file

@ -77,8 +77,8 @@
#include <guiddef.h> #include <guiddef.h>
#ifndef _ERROR_STATUS_T_DEFINED #ifndef _ERROR_STATUS_T_DEFINED
typedef unsigned long error_status_t;
#define _ERROR_STATUS_T_DEFINED #define _ERROR_STATUS_T_DEFINED
typedef unsigned long error_status_t;
#endif #endif
#ifndef _WCHAR_T_DEFINED #ifndef _WCHAR_T_DEFINED

View file

@ -102,8 +102,8 @@ typedef char CHAR;
typedef short SHORT; typedef short SHORT;
#ifndef LONG_DEFINED #ifndef LONG_DEFINED
#define LONG_DEFINED #define LONG_DEFINED
typedef long LONG; typedef long LONG;
typedef unsigned long ULONG,*PULONG; typedef unsigned long ULONG,*PULONG;
#endif//LONG_DEFINED #endif//LONG_DEFINED
typedef char CCHAR, *PCCHAR; typedef char CCHAR, *PCCHAR;
typedef unsigned char UCHAR,*PUCHAR; typedef unsigned char UCHAR,*PUCHAR;

View file

@ -0,0 +1,39 @@
/*
PROJECT: ReactOS
LICENSE: GPL v2 or any later version
FILE: include/reactos/typedefs64.h
PURPOSE: Type definitions for host tools, which are built on 64-bit systems
COPYRIGHT: Copyright 2007 Colin Finck <mail@colinfinck.de>
*/
#ifndef _TYPEDEFS64_H
#define _TYPEDEFS64_H
#ifndef DWORD_DEFINED
#define DWORD_DEFINED
typedef unsigned int DWORD;
#endif
#ifndef LONG_DEFINED
#define LONG_DEFINED
typedef int LONG;
typedef unsigned int ULONG,*PULONG;
#endif
#ifndef LONG_PTR_DEFINED
#define LONG_PTR_DEFINED
typedef int LONG_PTR, *PLONG_PTR;
typedef unsigned int ULONG_PTR, *PULONG_PTR;
#endif
#ifndef HANDLE_PTR_DEFINED
#define HANDLE_PTR_DEFINED
typedef unsigned int HANDLE_PTR;
#endif
#ifndef _ERROR_STATUS_T_DEFINED
#define _ERROR_STATUS_T_DEFINED
typedef unsigned int error_status_t;
#endif
#endif

View file

@ -9,6 +9,10 @@
#define CMLIB_H #define CMLIB_H
//#define WIN32_NO_STATUS //#define WIN32_NO_STATUS
#ifdef CMLIB_HOST
#include <typedefs64.h>
#endif
#include <ntddk.h> #include <ntddk.h>
#include "hivedata.h" #include "hivedata.h"
#include "cmdata.h" #include "cmdata.h"

View file

@ -33,7 +33,7 @@ CMLIB_HOST_OBJECTS = \
CMLIB_HOST_CFLAGS = -O3 -Wall -Wwrite-strings -Wpointer-arith \ CMLIB_HOST_CFLAGS = -O3 -Wall -Wwrite-strings -Wpointer-arith \
-D_X86_ -D__i386__ -D_REACTOS_ -D_NTOSKRNL_ -D_NTSYSTEM_ \ -D_X86_ -D__i386__ -D_REACTOS_ -D_NTOSKRNL_ -D_NTSYSTEM_ \
-DCMLIB_HOST -D_M_IX86 -I$(CMLIB_BASE) -Iinclude/reactos -Iinclude/psdk -Iinclude/ddk -Iinclude/crt \ -DCMLIB_HOST -D_M_IX86 -I$(CMLIB_BASE) -Iinclude/reactos -Iinclude/psdk -Iinclude/ddk -Iinclude/crt \
-D__NO_CTYPE_INLINES -D__NO_CTYPE_INLINES -DCMLIB_HOST
$(CMLIB_HOST_TARGET): $(CMLIB_HOST_OBJECTS) | $(CMLIB_OUT) $(CMLIB_HOST_TARGET): $(CMLIB_HOST_OBJECTS) | $(CMLIB_OUT)
$(ECHO_AR) $(ECHO_AR)

View file

@ -30,10 +30,10 @@
typedef char CHAR, *PCHAR; typedef char CHAR, *PCHAR;
typedef unsigned char UCHAR, *PUCHAR; typedef unsigned char UCHAR, *PUCHAR;
typedef long LONG, *PLONG;
typedef unsigned long ULONG, *PULONG;
typedef void VOID, *PVOID; typedef void VOID, *PVOID;
typedef UCHAR BOOLEAN, *PBOOLEAN; typedef UCHAR BOOLEAN, *PBOOLEAN;
#include <typedefs64.h>
typedef LONG *PLONG;
typedef char TCHAR, *PTCHAR, *PTSTR; typedef char TCHAR, *PTCHAR, *PTSTR;
#define _T(x) x #define _T(x) x
@ -48,7 +48,7 @@ typedef char TCHAR, *PTCHAR, *PTSTR;
#define strcasecmp stricmp #define strcasecmp stricmp
#endif #endif
extern unsigned long DbgPrint(char *Fmt, ...); extern ULONG DbgPrint(char *Fmt, ...);
#else /* ! defined(INFLIB_HOST) */ #else /* ! defined(INFLIB_HOST) */

View file

@ -17,59 +17,59 @@ extern "C" {
extern int InfHostOpenBufferedFile(PHINF InfHandle, extern int InfHostOpenBufferedFile(PHINF InfHandle,
void *Buffer, void *Buffer,
unsigned long BufferSize, ULONG BufferSize,
unsigned long *ErrorLine); ULONG *ErrorLine);
extern int InfHostOpenFile(PHINF InfHandle, extern int InfHostOpenFile(PHINF InfHandle,
const char *FileName, const CHAR *FileName,
unsigned long *ErrorLine); ULONG *ErrorLine);
extern int InfHostWriteFile(HINF InfHandle, extern int InfHostWriteFile(HINF InfHandle,
const char *FileName, const CHAR *FileName,
const char *HeaderComment); const CHAR *HeaderComment);
extern void InfHostCloseFile(HINF InfHandle); extern void InfHostCloseFile(HINF InfHandle);
extern int InfHostFindFirstLine(HINF InfHandle, extern int InfHostFindFirstLine(HINF InfHandle,
const char *Section, const CHAR *Section,
const char *Key, const CHAR *Key,
PINFCONTEXT *Context); PINFCONTEXT *Context);
extern int InfHostFindNextLine(PINFCONTEXT ContextIn, extern int InfHostFindNextLine(PINFCONTEXT ContextIn,
PINFCONTEXT ContextOut); PINFCONTEXT ContextOut);
extern int InfHostFindFirstMatchLine(PINFCONTEXT ContextIn, extern int InfHostFindFirstMatchLine(PINFCONTEXT ContextIn,
const char *Key, const CHAR *Key,
PINFCONTEXT ContextOut); PINFCONTEXT ContextOut);
extern int InfHostFindNextMatchLine(PINFCONTEXT ContextIn, extern int InfHostFindNextMatchLine(PINFCONTEXT ContextIn,
const char *Key, const CHAR *Key,
PINFCONTEXT ContextOut); PINFCONTEXT ContextOut);
extern long InfHostGetLineCount(HINF InfHandle, extern LONG InfHostGetLineCount(HINF InfHandle,
const char *Section); const CHAR *Section);
extern long InfHostGetFieldCount(PINFCONTEXT Context); extern LONG InfHostGetFieldCount(PINFCONTEXT Context);
extern int InfHostGetBinaryField(PINFCONTEXT Context, extern int InfHostGetBinaryField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
unsigned char *ReturnBuffer, UCHAR *ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize); ULONG *RequiredSize);
extern int InfHostGetIntField(PINFCONTEXT Context, extern int InfHostGetIntField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
unsigned long *IntegerValue); ULONG *IntegerValue);
extern int InfHostGetMultiSzField(PINFCONTEXT Context, extern int InfHostGetMultiSzField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char *ReturnBuffer, CHAR *ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize); ULONG *RequiredSize);
extern int InfHostGetStringField(PINFCONTEXT Context, extern int InfHostGetStringField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char *ReturnBuffer, CHAR *ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize); ULONG *RequiredSize);
extern int InfHostGetData(PINFCONTEXT Context, extern int InfHostGetData(PINFCONTEXT Context,
char **Key, CHAR **Key,
char **Data); CHAR **Data);
extern int InfHostGetDataField(PINFCONTEXT Context, extern int InfHostGetDataField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char **Data); CHAR **Data);
extern int InfHostFindOrAddSection(HINF InfHandle, extern int InfHostFindOrAddSection(HINF InfHandle,
const char *Section, const CHAR *Section,
PINFCONTEXT *Context); PINFCONTEXT *Context);
extern int InfHostAddLine(PINFCONTEXT Context, const char *Key); extern int InfHostAddLine(PINFCONTEXT Context, const CHAR *Key);
extern int InfHostAddField(PINFCONTEXT Context, const char *Data); extern int InfHostAddField(PINFCONTEXT Context, const CHAR *Data);
extern void InfHostFreeContext(PINFCONTEXT Context); extern void InfHostFreeContext(PINFCONTEXT Context);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -19,15 +19,15 @@
int int
InfHostOpenBufferedFile(PHINF InfHandle, InfHostOpenBufferedFile(PHINF InfHandle,
void *Buffer, void *Buffer,
unsigned long BufferSize, ULONG BufferSize,
unsigned long *ErrorLine) ULONG *ErrorLine)
{ {
INFSTATUS Status; INFSTATUS Status;
PINFCACHE Cache; PINFCACHE Cache;
char *FileBuffer; CHAR *FileBuffer;
*InfHandle = NULL; *InfHandle = NULL;
*ErrorLine = (unsigned long)-1; *ErrorLine = (ULONG)-1;
/* Allocate file buffer */ /* Allocate file buffer */
FileBuffer = MALLOC(BufferSize + 1); FileBuffer = MALLOC(BufferSize + 1);
@ -77,17 +77,17 @@ InfHostOpenBufferedFile(PHINF InfHandle,
int int
InfHostOpenFile(PHINF InfHandle, InfHostOpenFile(PHINF InfHandle,
const char *FileName, const CHAR *FileName,
unsigned long *ErrorLine) ULONG *ErrorLine)
{ {
FILE *File; FILE *File;
char *FileBuffer; CHAR *FileBuffer;
unsigned long FileLength; ULONG FileLength;
PINFCACHE Cache; PINFCACHE Cache;
INFSTATUS Status; INFSTATUS Status;
*InfHandle = NULL; *InfHandle = NULL;
*ErrorLine = (unsigned long)-1; *ErrorLine = (ULONG)-1;
/* Open the inf file */ /* Open the inf file */
File = fopen(FileName, "rb"); File = fopen(FileName, "rb");
@ -108,7 +108,7 @@ InfHostOpenFile(PHINF InfHandle,
} }
FileLength = ftell(File); FileLength = ftell(File);
if ((unsigned long) -1 == FileLength) if ((ULONG) -1 == FileLength)
{ {
DPRINT1("ftell() failed (errno %d)\n", errno); DPRINT1("ftell() failed (errno %d)\n", errno);
fclose(File); fclose(File);

View file

@ -16,8 +16,8 @@
int int
InfHostFindFirstLine(HINF InfHandle, InfHostFindFirstLine(HINF InfHandle,
const char *Section, const CHAR *Section,
const char *Key, const CHAR *Key,
PINFCONTEXT *Context) PINFCONTEXT *Context)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -56,7 +56,7 @@ InfHostFindNextLine(PINFCONTEXT ContextIn,
int int
InfHostFindFirstMatchLine(PINFCONTEXT ContextIn, InfHostFindFirstMatchLine(PINFCONTEXT ContextIn,
const char *Key, const CHAR *Key,
PINFCONTEXT ContextOut) PINFCONTEXT ContextOut)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -76,7 +76,7 @@ InfHostFindFirstMatchLine(PINFCONTEXT ContextIn,
int int
InfHostFindNextMatchLine(PINFCONTEXT ContextIn, InfHostFindNextMatchLine(PINFCONTEXT ContextIn,
const char *Key, const CHAR *Key,
PINFCONTEXT ContextOut) PINFCONTEXT ContextOut)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -94,7 +94,7 @@ InfHostFindNextMatchLine(PINFCONTEXT ContextIn,
} }
long LONG
InfHostGetLineCount(HINF InfHandle, InfHostGetLineCount(HINF InfHandle,
PCTSTR Section) PCTSTR Section)
{ {
@ -105,7 +105,7 @@ InfHostGetLineCount(HINF InfHandle,
/* InfGetLineText */ /* InfGetLineText */
long LONG
InfHostGetFieldCount(PINFCONTEXT Context) InfHostGetFieldCount(PINFCONTEXT Context)
{ {
return InfpGetFieldCount(Context); return InfpGetFieldCount(Context);
@ -114,10 +114,10 @@ InfHostGetFieldCount(PINFCONTEXT Context)
int int
InfHostGetBinaryField(PINFCONTEXT Context, InfHostGetBinaryField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
unsigned char *ReturnBuffer, UCHAR *ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize) ULONG *RequiredSize)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -137,8 +137,8 @@ InfHostGetBinaryField(PINFCONTEXT Context,
int int
InfHostGetIntField(PINFCONTEXT Context, InfHostGetIntField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
unsigned long *IntegerValue) ULONG *IntegerValue)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -157,10 +157,10 @@ InfHostGetIntField(PINFCONTEXT Context,
int int
InfHostGetMultiSzField(PINFCONTEXT Context, InfHostGetMultiSzField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char * ReturnBuffer, CHAR * ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize) ULONG *RequiredSize)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -180,10 +180,10 @@ InfHostGetMultiSzField(PINFCONTEXT Context,
int int
InfHostGetStringField(PINFCONTEXT Context, InfHostGetStringField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char *ReturnBuffer, CHAR *ReturnBuffer,
unsigned long ReturnBufferSize, ULONG ReturnBufferSize,
unsigned long *RequiredSize) ULONG *RequiredSize)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -203,8 +203,8 @@ InfHostGetStringField(PINFCONTEXT Context,
int int
InfHostGetData(PINFCONTEXT Context, InfHostGetData(PINFCONTEXT Context,
char **Key, CHAR **Key,
char **Data) CHAR **Data)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -223,8 +223,8 @@ InfHostGetData(PINFCONTEXT Context,
int int
InfHostGetDataField(PINFCONTEXT Context, InfHostGetDataField(PINFCONTEXT Context,
unsigned long FieldIndex, ULONG FieldIndex,
char **Data) CHAR **Data)
{ {
INFSTATUS Status; INFSTATUS Status;

View file

@ -11,7 +11,7 @@
#define NDEBUG #define NDEBUG
#include <debug.h> #include <debug.h>
unsigned long ULONG
DbgPrint(char *Fmt, ...) DbgPrint(char *Fmt, ...)
{ {
va_list Args; va_list Args;

View file

@ -13,11 +13,11 @@
#include <debug.h> #include <debug.h>
int int
InfHostWriteFile(HINF InfHandle, const char *FileName, InfHostWriteFile(HINF InfHandle, const CHAR *FileName,
const char *HeaderComment) const CHAR *HeaderComment)
{ {
char *Buffer; CHAR *Buffer;
unsigned long BufferSize; ULONG BufferSize;
INFSTATUS Status; INFSTATUS Status;
FILE *File; FILE *File;
@ -60,7 +60,7 @@ InfHostWriteFile(HINF InfHandle, const char *FileName,
int int
InfHostFindOrAddSection(HINF InfHandle, InfHostFindOrAddSection(HINF InfHandle,
const char *Section, const CHAR *Section,
PINFCONTEXT *Context) PINFCONTEXT *Context)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -78,7 +78,7 @@ InfHostFindOrAddSection(HINF InfHandle,
} }
int int
InfHostAddLine(PINFCONTEXT Context, const char *Key) InfHostAddLine(PINFCONTEXT Context, const CHAR *Key)
{ {
INFSTATUS Status; INFSTATUS Status;
@ -95,7 +95,7 @@ InfHostAddLine(PINFCONTEXT Context, const char *Key)
} }
int int
InfHostAddField(PINFCONTEXT Context, const char *Data) InfHostAddField(PINFCONTEXT Context, const CHAR *Data)
{ {
INFSTATUS Status; INFSTATUS Status;

View file

@ -37,6 +37,11 @@
#define NTOS_MODE_USER #define NTOS_MODE_USER
#define WIN32_NO_STATUS #define WIN32_NO_STATUS
#ifdef MKHIVE_HOST
#include <typedefs64.h>
#endif
#include <ntddk.h> #include <ntddk.h>
#include <cmlib.h> #include <cmlib.h>
#include <infhost.h> #include <infhost.h>

View file

@ -31,7 +31,7 @@ MKHIVE_OBJECTS = \
$(addprefix $(INTERMEDIATE_), $(MKHIVE_SOURCES:.c=.o)) $(addprefix $(INTERMEDIATE_), $(MKHIVE_SOURCES:.c=.o))
MKHIVE_HOST_CFLAGS = -fshort-wchar $(xTOOLS_CFLAGS) -I$(INFLIB_BASE) -I$(CMLIB_BASE) \ MKHIVE_HOST_CFLAGS = -fshort-wchar $(xTOOLS_CFLAGS) -I$(INFLIB_BASE) -I$(CMLIB_BASE) \
-D_NTOSKRNL_ -D_NTSYSTEM_ \ -D_NTOSKRNL_ -D_NTSYSTEM_ -DMKHIVE_HOST \
-Iinclude/reactos -Iinclude/ddk -Iinclude/ndk -Iinclude/psdk -Iinclude -Iinclude/crt -g3 -Iinclude/reactos -Iinclude/ddk -Iinclude/ndk -Iinclude/psdk -Iinclude -Iinclude/crt -g3
MKHIVE_HOST_LFLAGS = $(xTOOLS_LFLAGS) -g3 MKHIVE_HOST_LFLAGS = $(xTOOLS_LFLAGS) -g3