From 750b45e5a3ca70282e839002b8d834fc84573800 Mon Sep 17 00:00:00 2001 From: David Welch Date: Sun, 2 Sep 2001 17:31:00 +0000 Subject: [PATCH] Added generic capture functions. svn path=/trunk/; revision=2224 --- reactos/ntoskrnl/Makefile | 5 +- reactos/ntoskrnl/rtl/capture.c | 119 +++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 reactos/ntoskrnl/rtl/capture.c diff --git a/reactos/ntoskrnl/Makefile b/reactos/ntoskrnl/Makefile index 640baf5bd15..815ef0234cd 100644 --- a/reactos/ntoskrnl/Makefile +++ b/reactos/ntoskrnl/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.51 2001/08/29 05:06:31 rex Exp $ +# $Id: Makefile,v 1.52 2001/09/02 17:31:00 dwelch Exp $ # # ReactOS Operating System # @@ -99,7 +99,8 @@ OBJECTS_RTL = \ rtl/unicode.o \ rtl/wstring.o \ rtl/bitops.o \ - rtl/memcmp.o + rtl/memcmp.o \ + rtl/capture.o # Kernel (Ke) OBJECTS_KE = \ diff --git a/reactos/ntoskrnl/rtl/capture.c b/reactos/ntoskrnl/rtl/capture.c new file mode 100644 index 00000000000..5379c59121a --- /dev/null +++ b/reactos/ntoskrnl/rtl/capture.c @@ -0,0 +1,119 @@ +/* + * ReactOS kernel + * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ +/* $Id: capture.c,v 1.1 2001/09/02 17:31:00 dwelch Exp $ + * + * PROJECT: ReactOS kernel + * FILE: ntoskrnl/rtl/capture.c + * PURPOSE: Helper routines for system calls. + * PROGRAMMER: David Welch (welch@cwcom.net) + * UPDATE HISTORY: + * 02/09/01: Created + */ + +/* INCLUDES ******************************************************************/ + +#include + +#define NDEBUG +#include + +/* FUNCTIONS *****************************************************************/ + +NTSTATUS +RtlCaptureUnicodeString(PUNICODE_STRING Dest, + PUNICODE_STRING UnsafeSrc) +{ + PUNICODE_STRING Src; + NTSTATUS Status; + + /* + * Copy the source string structure to kernel space. + */ + Status = MmCopyFromCaller(&Src, UnsafeSrc, sizeof(UNICODE_STRING)); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + /* + * Initialize the destination string. + */ + Dest->Length = Src->Length; + Dest->MaximumLength = Src->MaximumLength; + Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength); + if (Dest->Buffer == NULL) + { + return(Status); + } + + /* + * Copy the source string to kernel space. + */ + Status = MmCopyFromCaller(Dest->Buffer, Src->Buffer, Dest->Length); + if (!NT_SUCCESS(Status)) + { + ExFreePool(Dest->Buffer); + return(Status); + } + + return(STATUS_SUCCESS); +} + +NTSTATUS +RtlCaptureAnsiString(PANSI_STRING Dest, + PANSI_STRING UnsafeSrc) +{ + PANSI_STRING Src; + NTSTATUS Status; + + /* + * Copy the source string structure to kernel space. + */ + Status = MmCopyFromCaller(&Src, UnsafeSrc, sizeof(ANSI_STRING)); + if (!NT_SUCCESS(Status)) + { + return(Status); + } + + /* + * Initialize the destination string. + */ + Dest->Length = Src->Length; + Dest->MaximumLength = Src->MaximumLength; + Dest->Buffer = ExAllocatePool(NonPagedPool, Dest->MaximumLength); + if (Dest->Buffer == NULL) + { + return(Status); + } + + /* + * Copy the source string to kernel space. + */ + Status = MmCopyFromCaller(Dest->Buffer, Src->Buffer, Dest->Length); + if (!NT_SUCCESS(Status)) + { + ExFreePool(Dest->Buffer); + return(Status); + } + + return(STATUS_SUCCESS); +} + +/* EOF */ +