From 6d64efee466fd76b55a0a8cfbedd4ffdcd9b7d1a Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Thu, 12 Jul 2001 17:23:42 +0000 Subject: [PATCH] Moved interlocked and locale functions. Implemented basic locale support. Added some missing interlocked functions. svn path=/trunk/; revision=2056 --- reactos/include/ddk/exfuncs.h | 46 ++++ reactos/ntoskrnl/Makefile | 7 +- reactos/ntoskrnl/Makefile.i386 | 7 +- reactos/ntoskrnl/ex/i386/.cvsignore | 1 + reactos/ntoskrnl/{rtl => ex/i386}/interlck.c | 81 +++++- reactos/ntoskrnl/ex/interlck.c | 34 ++- reactos/ntoskrnl/ex/locale.c | 58 ---- reactos/ntoskrnl/include/internal/ps.h | 11 +- reactos/ntoskrnl/ke/main.c | 4 +- reactos/ntoskrnl/ntoskrnl.def | 16 +- reactos/ntoskrnl/ntoskrnl.edf | 16 +- reactos/ntoskrnl/ps/create.c | 12 +- reactos/ntoskrnl/ps/locale.c | 272 +++++++++++++++++++ reactos/ntoskrnl/ps/psmgr.c | 4 +- 14 files changed, 470 insertions(+), 99 deletions(-) create mode 100644 reactos/ntoskrnl/ex/i386/.cvsignore rename reactos/ntoskrnl/{rtl => ex/i386}/interlck.c (54%) delete mode 100644 reactos/ntoskrnl/ex/locale.c create mode 100644 reactos/ntoskrnl/ps/locale.c diff --git a/reactos/include/ddk/exfuncs.h b/reactos/include/ddk/exfuncs.h index 18d50fc5ef4..00ab81b2a40 100644 --- a/reactos/include/ddk/exfuncs.h +++ b/reactos/include/ddk/exfuncs.h @@ -713,6 +713,52 @@ ExInitializePagedLookasideList ( ); +ULONG +FASTCALL +ExfInterlockedAddUlong ( + IN PULONG Addend, + IN ULONG Increment, + IN PKSPIN_LOCK Lock + ); + +INTERLOCKED_RESULT +FASTCALL +Exfi386InterlockedIncrementLong ( + IN PLONG Addend + ); + +INTERLOCKED_RESULT +FASTCALL +Exfi386InterlockedDecrementLong ( + IN PLONG Addend + ); + +ULONG +FASTCALL +Exfi386InterlockedExchangeUlong ( + IN PULONG Target, + IN ULONG Value + ); + +INTERLOCKED_RESULT +STDCALL +Exi386InterlockedIncrementLong ( + IN PLONG Addend + ); + +INTERLOCKED_RESULT +STDCALL +Exi386InterlockedDecrementLong ( + IN PLONG Addend + ); + +ULONG +STDCALL +Exi386InterlockedExchangeUlong ( + IN PULONG Target, + IN ULONG Value + ); + /* LONG FASTCALL diff --git a/reactos/ntoskrnl/Makefile b/reactos/ntoskrnl/Makefile index 0d36a649c51..f7892750bb2 100644 --- a/reactos/ntoskrnl/Makefile +++ b/reactos/ntoskrnl/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.45 2001/07/04 20:40:20 chorns Exp $ +# $Id: Makefile,v 1.46 2001/07/12 17:17:06 ekohl Exp $ # # ReactOS Operating System # @@ -55,7 +55,7 @@ TARGETNAME := ntoskrnl OBJECTS_PATH = objects ASFLAGS = -Iinclude -CFLAGS = -Iinclude -D__NTOSKRNL__ $(CFLAGS_DBG) -Wall -Werror +CFLAGS = -Iinclude -D__NTOSKRNL__ $(CFLAGS_DBG) -Wall -Werror include $(PATH_TO_TOP)/rules.mak @@ -96,7 +96,6 @@ OBJECTS_RTL = \ rtl/ctype.o \ rtl/error.o \ rtl/handle.o \ - rtl/interlck.o \ rtl/largeint.o \ rtl/mem.o \ rtl/memchr.o \ @@ -216,6 +215,7 @@ OBJECTS_PS = \ ps/create.o \ ps/idle.o \ ps/kill.o \ + ps/locale.o \ ps/process.o \ ps/psmgr.o \ ps/thread.o \ @@ -230,7 +230,6 @@ OBJECTS_EX = \ ex/init.o \ ex/interlck.o \ ex/list.o \ - ex/locale.o \ ex/lookas.o \ ex/napi.o \ ex/power.o \ diff --git a/reactos/ntoskrnl/Makefile.i386 b/reactos/ntoskrnl/Makefile.i386 index ff7457e1915..be07f02a81a 100644 --- a/reactos/ntoskrnl/Makefile.i386 +++ b/reactos/ntoskrnl/Makefile.i386 @@ -7,6 +7,9 @@ include hal/x86/sources OBJECTS_BOOT := ke/i386/multiboot.o +OBJECTS_EX_I386 := \ + ex/i386/interlck.o + OBJECTS_KE_I386 := \ ke/i386/exp.o \ ke/i386/irq.o \ @@ -20,7 +23,7 @@ OBJECTS_KE_I386 := \ ke/i386/v86m.o \ ke/i386/v86m_sup.o \ ke/i386/bios.o \ - ke/i386/i386-mcount.o \ + ke/i386/i386-mcount.o \ ke/i386/gdt.o \ ke/i386/idt.o \ ke/i386/ldt.o \ @@ -34,4 +37,4 @@ OBJECTS_MM_I386 := \ mm/i386/page.o \ mm/i386/pfault.o -OBJECTS_ARCH = $(OBJECTS_BOOT) $(OBJECTS_KE_I386) $(OBJECTS_MM_I386) \ No newline at end of file +OBJECTS_ARCH = $(OBJECTS_BOOT) $(OBJECTS_EX_I386) $(OBJECTS_KE_I386) $(OBJECTS_MM_I386) diff --git a/reactos/ntoskrnl/ex/i386/.cvsignore b/reactos/ntoskrnl/ex/i386/.cvsignore new file mode 100644 index 00000000000..36de49a073e --- /dev/null +++ b/reactos/ntoskrnl/ex/i386/.cvsignore @@ -0,0 +1 @@ +*.d \ No newline at end of file diff --git a/reactos/ntoskrnl/rtl/interlck.c b/reactos/ntoskrnl/ex/i386/interlck.c similarity index 54% rename from reactos/ntoskrnl/rtl/interlck.c rename to reactos/ntoskrnl/ex/i386/interlck.c index 36f244b5855..969b5b80989 100644 --- a/reactos/ntoskrnl/rtl/interlck.c +++ b/reactos/ntoskrnl/ex/i386/interlck.c @@ -1,13 +1,80 @@ -/* $Id: interlck.c,v 1.9 2001/07/06 21:30:33 ekohl Exp $ +/* $Id: interlck.c,v 1.1 2001/07/12 17:17:56 ekohl Exp $ * - * reactos/ntoskrnl/rtl/interlck.c + * reactos/ntoskrnl/ex/i386/interlck.c * */ -#include -#include -#include +#include + + +INTERLOCKED_RESULT FASTCALL +Exfi386InterlockedIncrementLong(IN PLONG Addend); + +__asm__("\n\t.global @Exfi386InterlockedIncrementLong@4\n\t" + "@Exfi386InterlockedIncrementLong@4:\n\t" + "addl $1,(%ecx)\n\t" + "lahf\n\t" + "andl $0xC000, %eax\n\t" + "ret\n\t"); + + +INTERLOCKED_RESULT FASTCALL +Exfi386InterlockedDecrementLong(IN PLONG Addend); + +__asm__("\n\t.global @Exfi386InterlockedDecrementLong@4\n\t" + "@Exfi386InterlockedDecrementLong@4:\n\t" + "subl $1,(%ecx)\n\t" + "lahf\n\t" + "andl $0xC000, %eax\n\t" + "ret\n\t"); + + +ULONG FASTCALL +Exfi386InterlockedExchangeUlong(IN PULONG Target, + IN ULONG Value); + +__asm__("\n\t.global @Exfi386InterlockedExchangeUlong@8\n\t" + "@Exfi386InterlockedExchangeUlong@8:\n\t" + "movl (%ecx),%eax\n" + "xchgl %edx,(%ecx)\n\t" + "ret\n\t"); + + + +INTERLOCKED_RESULT STDCALL +Exi386InterlockedIncrementLong(IN PLONG Addend); + +__asm__("\n\t.global _Exi386InterlockedIncrementLong@4\n\t" + "_Exi386InterlockedIncrementLong@4:\n\t" + "movl 4(%esp),%eax\n\t" + "addl $1,(%eax)\n\t" + "lahf\n\t" + "andl $0xC000, %eax\n\t" + "ret $4\n\t"); + + +INTERLOCKED_RESULT STDCALL +Exi386InterlockedDecrementLong(IN PLONG Addend); + +__asm__("\n\t.global _Exi386InterlockedDecrementLong@4\n\t" + "_Exi386InterlockedDecrementLong@4:\n\t" + "movl 4(%esp),%eax\n\t" + "subl $1,(%eax)\n\t" + "lahf\n\t" + "andl $0xC000, %eax\n\t" + "ret $4\n\t"); + + +ULONG STDCALL +Exi386InterlockedExchangeUlong(IN PULONG Target, + IN ULONG Value); + +__asm__("\n\t.global _Exi386InterlockedExchangeUlong@8\n\t" + "_Exi386InterlockedExchangeUlong@8:\n\t" + "movl 4(%esp),%edx\n\t" + "movl 8(%esp),%eax\n\t" + "xchgl %eax,(%edx)\n\t" + "ret $8\n\t"); -#define USE_FASTCALL /********************************************************************** * FASTCALL: @InterlockedIncrement@4 @@ -18,7 +85,7 @@ InterlockedIncrement(PLONG Addend); /* * FUNCTION: Increments a caller supplied variable of type LONG as an * atomic operation - * ARGUMENTS; + * ARGUMENTS: * Addend = Points to a variable whose value is to be increment * RETURNS: The incremented value */ diff --git a/reactos/ntoskrnl/ex/interlck.c b/reactos/ntoskrnl/ex/interlck.c index c5136563951..c45fc5604b1 100644 --- a/reactos/ntoskrnl/ex/interlck.c +++ b/reactos/ntoskrnl/ex/interlck.c @@ -1,4 +1,4 @@ -/* $Id: interlck.c,v 1.6 2000/12/23 02:37:39 dwelch Exp $ +/* $Id: interlck.c,v 1.7 2001/07/12 17:18:49 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -180,5 +180,37 @@ ExInterlockedCompareExchange64 (IN OUT PLONGLONG Destination, return oldval; } +ULONG FASTCALL +ExfInterlockedAddUlong(PULONG Addend, + ULONG Increment, + PKSPIN_LOCK Lock) +/* + * ExInterlockedAddUlong adds an unsigned long value to a given unsigned + * integer as an atomic operation. + * + * ADDEND = Points to an unsigned long integer whose value is to be adjusted + * by the Increment value. + * + * INCREMENT = Is an unsigned long integer to be added. + * + * LOCK = Points to a spinlock to be used to synchronize access to ADDEND. + * + * Returns: + * + * The original value of the unsigned integer pointed to by ADDEND. + */ +{ + KIRQL oldlvl; + ULONG oldval; + + KeAcquireSpinLock (Lock, &oldlvl); + + oldval = *Addend; + *Addend += Increment; + + KeReleaseSpinLock (Lock, oldlvl); + + return oldval; +} /* EOF */ diff --git a/reactos/ntoskrnl/ex/locale.c b/reactos/ntoskrnl/ex/locale.c deleted file mode 100644 index de76f41e171..00000000000 --- a/reactos/ntoskrnl/ex/locale.c +++ /dev/null @@ -1,58 +0,0 @@ -/* $Id: locale.c,v 1.4 2000/12/23 02:37:39 dwelch Exp $ - * - * COPYRIGHT: See COPYING in the top level directory - * PROJECT: ReactOS kernel - * FILE: ntoskrnl/ex/locale.c - * PURPOSE: Locale support - * PROGRAMMER: David Welch (welch@cwcom.net) - * UPDATE HISTORY: - * Created 22/05/98 - */ - -/* INCLUDES *****************************************************************/ - -#include - -#include - -/* FUNCTIONS *****************************************************************/ - -NTSTATUS STDCALL -NtQueryDefaultLocale(IN BOOLEAN ThreadOrSystem, - OUT PLCID DefaultLocaleId) -/* - * Returns the default locale. - * - * THREADORSYSTEM = If TRUE then the locale for this thread is returned, - * otherwise the locale for the system is returned. - * - * DEFAUTLOCALEID = Points to a variable that receives the locale id. - * - * Returns: - * - * Status. - */ -{ - UNIMPLEMENTED; -} - -NTSTATUS STDCALL -NtSetDefaultLocale(IN BOOLEAN ThreadOrSystem, - IN LCID DefaultLocaleId) -/* - * Sets the default locale. - * - * THREADORSYSTEM = If TRUE then the thread's locale is set, otherwise the - * sytem locale is set. - * - * DEFAUTLOCALEID = The locale id to be set - * - * Returns: - * - * Status - */ -{ - UNIMPLEMENTED; -} - -/* EOF */ diff --git a/reactos/ntoskrnl/include/internal/ps.h b/reactos/ntoskrnl/include/internal/ps.h index a4c208228d5..41dc1629198 100644 --- a/reactos/ntoskrnl/include/internal/ps.h +++ b/reactos/ntoskrnl/include/internal/ps.h @@ -95,6 +95,10 @@ static inline PKPCR KeGetCurrentKPCR(VOID) extern HANDLE SystemProcessHandle; +extern LCID PsDefaultThreadLocaleId; +extern LCID PsDefaultSystemLocaleId; + + typedef struct _KAPC_STATE { LIST_ENTRY ApcListHead[2]; @@ -118,7 +122,7 @@ typedef struct _KTHREAD NT_TEB* Teb; /* 20 */ /* Pointer to the thread's TLS array */ - PVOID TlsArray; /* 24 */ + PVOID TlsArray; /* 24 */ PVOID KernelStack; /* 28 */ UCHAR DebugActive; /* 2C */ @@ -443,7 +447,7 @@ struct _EPROCESS PVOID SectionBaseAddress; PVOID QuotaBlock; NTSTATUS LastThreadExitStatus; - PVOID WorkingSetWatch; + PVOID WorkingSetWatch; HANDLE InheritedFromUniqueProcessId; ACCESS_MASK GrantedAccess; ULONG DefaultHardErrorProcessing; @@ -471,12 +475,13 @@ struct _EPROCESS /* * Added by Philip Susi for list of threads in process */ - LIST_ENTRY ThreadListHead; + LIST_ENTRY ThreadListHead; }; #define PROCESS_STATE_TERMINATED (1) #define PROCESS_STATE_ACTIVE (2) +VOID PiInitDefaultLocale(VOID); VOID PiInitProcessManager(VOID); VOID PiShutdownProcessManager(VOID); VOID PsInitThreadManagment(VOID); diff --git a/reactos/ntoskrnl/ke/main.c b/reactos/ntoskrnl/ke/main.c index f5b1230379f..5b5e5f94eb3 100644 --- a/reactos/ntoskrnl/ke/main.c +++ b/reactos/ntoskrnl/ke/main.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: main.c,v 1.99 2001/06/29 21:08:50 ea Exp $ +/* $Id: main.c,v 1.100 2001/07/12 17:23:42 ekohl Exp $ * * PROJECT: ReactOS kernel * FILE: ntoskrnl/ke/main.c @@ -646,6 +646,8 @@ ExpInitializeExecutive(VOID) CmInitializeRegistry2(); + PiInitDefaultLocale(); + /* * Start the motherboard enumerator (the HAL) */ diff --git a/reactos/ntoskrnl/ntoskrnl.def b/reactos/ntoskrnl/ntoskrnl.def index c4c0d89d247..6c26ce9062c 100644 --- a/reactos/ntoskrnl/ntoskrnl.def +++ b/reactos/ntoskrnl/ntoskrnl.def @@ -1,4 +1,4 @@ -; $Id: ntoskrnl.def,v 1.110 2001/07/06 21:30:59 ekohl Exp $ +; $Id: ntoskrnl.def,v 1.111 2001/07/12 17:17:07 ekohl Exp $ ; ; reactos/ntoskrnl/ntoskrnl.def ; @@ -86,18 +86,18 @@ ExSystemTimeToLocalTime@8 ExTryToAcquireResourceExclusiveLite@4 ExUnregisterCallback@4 ExWindowStationObjectType DATA -;@ExfInterlockedAddUlong +@ExfInterlockedAddUlong@12 ;@ExfInterlockedInsertHeadList ;@ExfInterlockedInsertTailList ;@ExfInterlockedPopEntryList ;@ExfInterlockedPushEntryList ;@ExfInterlockedRemoveHeadList -;@Exfi386InterlockedDecrementLong -;@Exfi386InterlockedExchangeUlong -;@Exfi386InterlockedIncrementLong -;Exi386InterlockedDecrementLong -;Exi386InterlockedExchangeUlong -;Exi386InterlockedIncrementLong +@Exfi386InterlockedDecrementLong@4 +@Exfi386InterlockedExchangeUlong@8 +@Exfi386InterlockedIncrementLong@4 +Exi386InterlockedDecrementLong@4 +Exi386InterlockedExchangeUlong@8 +Exi386InterlockedIncrementLong@4 FsRtlAddLargeMcbEntry@28 FsRtlAddMcbEntry@16 FsRtlAddToTunnelCache@32 diff --git a/reactos/ntoskrnl/ntoskrnl.edf b/reactos/ntoskrnl/ntoskrnl.edf index 16f87e67f8c..7d8e33cd454 100644 --- a/reactos/ntoskrnl/ntoskrnl.edf +++ b/reactos/ntoskrnl/ntoskrnl.edf @@ -1,4 +1,4 @@ -; $Id: ntoskrnl.edf,v 1.96 2001/07/06 21:30:59 ekohl Exp $ +; $Id: ntoskrnl.edf,v 1.97 2001/07/12 17:17:07 ekohl Exp $ ; ; reactos/ntoskrnl/ntoskrnl.def ; @@ -86,18 +86,18 @@ ExSystemTimeToLocalTime=ExSystemTimeToLocalTime@8 ExTryToAcquireResourceExclusiveLite=ExTryToAcquireResourceExclusiveLite@4 ExUnregisterCallback=ExUnregisterCallback@4 ExWindowStationObjectType DATA -;ExfInterlockedAddUlong +ExfInterlockedAddUlong=@ExfInterlockedAddUlong@12 ;ExfInterlockedInsertHeadList ;ExfInterlockedInsertTailList ;ExfInterlockedPopEntryList ;ExfInterlockedPushEntryList ;ExfInterlockedRemoveHeadList -;Exfi386InterlockedDecrementLong -;Exfi386InterlockedExchangeUlong -;Exfi386InterlockedIncrementLong -;Exi386InterlockedDecrementLong -;Exi386InterlockedExchangeUlong -;Exi386InterlockedIncrementLong +Exfi386InterlockedDecrementLong=@Exfi386InterlockedDecrementLong@4 +Exfi386InterlockedExchangeUlong=@Exfi386InterlockedExchangeUlong@8 +Exfi386InterlockedIncrementLong=@Exfi386InterlockedIncrementLong@4 +Exi386InterlockedDecrementLong=Exi386InterlockedDecrementLong@4 +Exi386InterlockedExchangeUlong=Exi386InterlockedExchangeUlong@8 +Exi386InterlockedIncrementLong=Exi386InterlockedIncrementLong@4 FsRtlAddLargeMcbEntry=FsRtlAddLargeMcbEntry@28 FsRtlAddMcbEntry=FsRtlAddMcbEntry@16 FsRtlAddToTunnelCache=FsRtlAddToTunnelCache@32 diff --git a/reactos/ntoskrnl/ps/create.c b/reactos/ntoskrnl/ps/create.c index b211bb8dfa5..6bcb784071d 100644 --- a/reactos/ntoskrnl/ps/create.c +++ b/reactos/ntoskrnl/ps/create.c @@ -1,4 +1,4 @@ -/* $Id: create.c,v 1.34 2001/07/04 20:40:21 chorns Exp $ +/* $Id: create.c,v 1.35 2001/07/12 17:21:05 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel @@ -406,10 +406,11 @@ PsInitializeThread(HANDLE ProcessHandle, } -static NTSTATUS PsCreateTeb (HANDLE ProcessHandle, - PNT_TEB *TebPtr, - PETHREAD Thread, - PINITIAL_TEB InitialTeb) +static NTSTATUS +PsCreateTeb(HANDLE ProcessHandle, + PNT_TEB *TebPtr, + PETHREAD Thread, + PINITIAL_TEB InitialTeb) { MEMORY_BASIC_INFORMATION Info; NTSTATUS Status; @@ -484,6 +485,7 @@ static NTSTATUS PsCreateTeb (HANDLE ProcessHandle, /* more initialization */ Teb.Cid.UniqueThread = Thread->Cid.UniqueThread; Teb.Cid.UniqueProcess = Thread->Cid.UniqueProcess; + Teb.CurrentLocale = PsDefaultThreadLocaleId; DPRINT("sizeof(NT_TEB) %x\n", sizeof(NT_TEB)); diff --git a/reactos/ntoskrnl/ps/locale.c b/reactos/ntoskrnl/ps/locale.c new file mode 100644 index 00000000000..d98dc0d7a26 --- /dev/null +++ b/reactos/ntoskrnl/ps/locale.c @@ -0,0 +1,272 @@ +/* $Id: locale.c,v 1.1 2001/07/12 17:21:06 ekohl Exp $ + * + * COPYRIGHT: See COPYING in the top level directory + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/ps/locale.c + * PURPOSE: Locale support + * PROGRAMMER: David Welch (welch@cwcom.net) + * UPDATE HISTORY: + * Created 22/05/98 + */ + +/* INCLUDES *****************************************************************/ + +#include +#include + +#define NDEBUG +#include + + +/* GLOBALS *******************************************************************/ + +/* + * Default setting: LANG_NEUTRAL, SUBLANG_NEUTRAL, SORT_DEFAULT + */ +LCID PsDefaultThreadLocaleId = 0; +LCID PsDefaultSystemLocaleId = 0; + + +#define VALUE_BUFFER_SIZE 256 + +/* FUNCTIONS *****************************************************************/ + +VOID +PiInitDefaultLocale(VOID) +/* + * FUNCTION: + * Initializes the default locale. + * Reads default locale from registry, if available + * ARGUMENTS: + * None. + * Returns: + * None. + */ +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING KeyName; + UNICODE_STRING ValueName; + HANDLE KeyHandle; + ULONG ValueLength; + UCHAR ValueBuffer[VALUE_BUFFER_SIZE]; + PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; + UNICODE_STRING ValueString; + ULONG LocaleValue; + NTSTATUS Status; + + ValueInfo = (PKEY_VALUE_PARTIAL_INFORMATION)ValueBuffer; + + /* read system locale */ + RtlInitUnicodeString(&KeyName, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\Language"); + RtlInitUnicodeString(&ValueName, + L"Default"); + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtOpenKey(&KeyHandle, + KEY_QUERY_VALUE, + &ObjectAttributes); + if (NT_SUCCESS(Status)) + { + Status = NtQueryValueKey(KeyHandle, + &ValueName, + KeyValuePartialInformation, + ValueBuffer, + VALUE_BUFFER_SIZE, + &ValueLength); + if ((NT_SUCCESS(Status)) && (ValueInfo->Type == REG_SZ)) + { + ValueString.Length = ValueInfo->DataLength; + ValueString.MaximumLength = ValueInfo->DataLength; + ValueString.Buffer = (PWSTR)ValueInfo->Data; + + Status = RtlUnicodeStringToInteger(&ValueString, + 10, + &LocaleValue); + if (NT_SUCCESS(Status)) + { + DPRINT("System locale: %08lu\n", LocaleValue); + PsDefaultSystemLocaleId = (LCID)LocaleValue; + } + } + NtClose(KeyHandle); + } + + /* read default thread locale */ + RtlInitUnicodeString(&KeyName, + L"\\Registry\\User\\.Default\\Control Panel\\International"); + RtlInitUnicodeString(&ValueName, + L"Locale"); + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + NULL, + NULL); + Status = NtOpenKey(&KeyHandle, + KEY_QUERY_VALUE, + &ObjectAttributes); + if (NT_SUCCESS(Status)) + { + Status = NtQueryValueKey(KeyHandle, + &ValueName, + KeyValuePartialInformation, + ValueBuffer, + VALUE_BUFFER_SIZE, + &ValueLength); + if ((NT_SUCCESS(Status)) && (ValueInfo->Type == REG_SZ)) + { + ValueString.Length = ValueInfo->DataLength; + ValueString.MaximumLength = ValueInfo->DataLength; + ValueString.Buffer = (PWSTR)ValueInfo->Data; + + Status = RtlUnicodeStringToInteger(&ValueString, + 10, + &LocaleValue); + if (NT_SUCCESS(Status)) + { + DPRINT("Thread locale: %08lu\n", LocaleValue); + PsDefaultThreadLocaleId = (LCID)LocaleValue; + } + } + NtClose(KeyHandle); + } +} + + +NTSTATUS STDCALL +NtQueryDefaultLocale(IN BOOLEAN ThreadOrSystem, + OUT PLCID DefaultLocaleId) +/* + * FUNCTION: + * Returns the default locale. + * ARGUMENTS: + * ThreadOrSystem = If TRUE then the locale for this thread is returned, + * otherwise the locale for the system is returned. + * DefaultLocaleId = Points to a variable that receives the locale id. + * Returns: + * Status. + */ +{ + if (DefaultLocaleId == NULL) + return STATUS_UNSUCCESSFUL; + + if (ThreadOrSystem == TRUE) + { + /* set thread locale */ + *DefaultLocaleId = PsDefaultThreadLocaleId; + } + else + { + /* set system locale */ + *DefaultLocaleId = PsDefaultSystemLocaleId; + } + return(STATUS_SUCCESS); +} + + +NTSTATUS STDCALL +NtSetDefaultLocale(IN BOOLEAN ThreadOrSystem, + IN LCID DefaultLocaleId) +/* + * FUNCTION: + * Sets the default locale. + * ARGUMENTS: + * ThreadOrSystem = If TRUE then the locale for this thread is set, + * otherwise the locale for the system is set. + * DefaultLocaleId = The locale id to be set. + * Returns: + * Status. + */ +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING KeyName; + UNICODE_STRING ValueName; + HANDLE KeyHandle; + ULONG ValueLength; + WCHAR ValueBuffer[20]; + HANDLE UserKey = NULL; + NTSTATUS Status; + + if (ThreadOrSystem == TRUE) + { + /* thread locale */ + Status = RtlOpenCurrentUser(KEY_WRITE, + &UserKey); + if (!NT_SUCCESS(Status)) + return(Status); + RtlInitUnicodeString(&KeyName, + L"Control Panel\\International"); + RtlInitUnicodeString(&ValueName, + L"Locale"); + } + else + { + /* system locale */ + RtlInitUnicodeString(&KeyName, + L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Nls\\Language"); + RtlInitUnicodeString(&ValueName, + L"Default"); + } + + InitializeObjectAttributes(&ObjectAttributes, + &KeyName, + OBJ_CASE_INSENSITIVE, + UserKey, + NULL); + Status = NtOpenKey(&KeyHandle, + KEY_SET_VALUE, + &ObjectAttributes); + if (!NT_SUCCESS(Status)) + { + if (UserKey != NULL) + { + NtClose(UserKey); + } + return(Status); + } + + ValueLength = swprintf(ValueBuffer, + L"%08lu", + (ULONG)DefaultLocaleId); + ValueLength = (ValueLength + 1) * sizeof(WCHAR); + + Status = NtSetValueKey(KeyHandle, + &ValueName, + 0, + REG_SZ, + ValueBuffer, + ValueLength); + + NtClose(KeyHandle); + if (UserKey != NULL) + { + NtClose(UserKey); + } + + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + if (ThreadOrSystem == TRUE) + { + /* set thread locale */ + DPRINT("Thread locale: %08lu\n", DefaultLocaleId); + PsDefaultThreadLocaleId = DefaultLocaleId; + } + else + { + /* set system locale */ + DPRINT("System locale: %08lu\n", DefaultLocaleId); + PsDefaultSystemLocaleId = DefaultLocaleId; + } + + return(STATUS_SUCCESS); +} + +/* EOF */ diff --git a/reactos/ntoskrnl/ps/psmgr.c b/reactos/ntoskrnl/ps/psmgr.c index c23b9fcd8cd..9189c774ff3 100644 --- a/reactos/ntoskrnl/ps/psmgr.c +++ b/reactos/ntoskrnl/ps/psmgr.c @@ -1,9 +1,9 @@ -/* $Id: psmgr.c,v 1.10 2001/05/01 23:08:20 chorns Exp $ +/* $Id: psmgr.c,v 1.11 2001/07/12 17:21:06 ekohl Exp $ * * COPYRIGHT: See COPYING in the top level directory * PROJECT: ReactOS kernel * FILE: ntoskrnl/ps/psmgr.c - * PURPOSE: Process managment + * PURPOSE: Process management * PROGRAMMER: David Welch (welch@mcmail.com) */