- Call create process notify routines from NtCreateProcess.

- Protect PiProcessNotifyRoutine by a spinlock.
- Started PsSetLoadImageNotifyRoutine implementation, it just registers the callback, but doesn't call it.

svn path=/trunk/; revision=8575
This commit is contained in:
Filip Navara 2004-03-07 20:31:53 +00:00
parent fa397a0e33
commit 877788b63b
4 changed files with 92 additions and 3 deletions

View file

@ -23,6 +23,22 @@ struct _KTHREAD;
typedef struct _KTHREAD *PKTHREAD, *PRKTHREAD;
typedef struct _IMAGE_INFO {
union {
ULONG Properties;
struct {
ULONG ImageAddressingMode : 8;
ULONG SystemModeImage : 1;
ULONG ImageMappedToAllPids : 1;
ULONG Reserved : 22;
};
};
PVOID ImageBase;
ULONG ImageSelector;
ULONG ImageSize;
ULONG ImageSectionNumber;
} IMAGE_INFO, *PIMAGE_INFO;
typedef VOID STDCALL_FUNC
(*PKSTART_ROUTINE)(PVOID StartContext);
@ -36,6 +52,11 @@ typedef VOID STDCALL_FUNC
HANDLE ThreadId,
BOOLEAN Create);
typedef VOID STDCALL_FUNC
(*PLOAD_IMAGE_NOTIFY_ROUTINE)(PUNICODE_STRING FullImageName,
HANDLE ProcessId,
PIMAGE_INFO ImageInfo);
typedef NTSTATUS STDCALL_FUNC
(*PW32_PROCESS_CALLBACK)(struct _EPROCESS *Process,
BOOLEAN Create);
@ -59,4 +80,6 @@ struct _KPROCESS;
#define HIGH_PRIORITY (31)
#define MAXIMUM_PRIORITY (32)
#define IMAGE_ADDRESSING_MODE_32BIT (3)
#endif /* __INCLUDE_DDK_PSTYPES_H */

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.def,v 1.176 2004/03/06 22:21:20 dwelch Exp $
; $Id: ntoskrnl.def,v 1.177 2004/03/07 20:31:53 navaraf Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -672,6 +672,7 @@ PsRevertToSelf@0
PsSetCreateProcessNotifyRoutine@8
PsSetCreateThreadNotifyRoutine@4
;PsSetLegoNotifyRoutine@4
PsSetLoadImageNotifyRoutine@4
;PsSetProcessPriorityByClass@8
PsTerminateSystemThread@4
PsThreadType DATA

View file

@ -1,4 +1,4 @@
; $Id: ntoskrnl.edf,v 1.162 2004/03/06 22:21:20 dwelch Exp $
; $Id: ntoskrnl.edf,v 1.163 2004/03/07 20:31:53 navaraf Exp $
;
; reactos/ntoskrnl/ntoskrnl.def
;
@ -673,6 +673,7 @@ PsRevertToSelf=PsRevertToSelf@0
PsSetCreateProcessNotifyRoutine=PsSetCreateProcessNotifyRoutine@8
PsSetCreateThreadNotifyRoutine=PsSetCreateThreadNotifyRoutine@4
;PsSetLegoNotifyRoutine
PsSetLoadImageNotifyRoutine=PsSetLoadImageNotifyRoutine@4
;PsSetProcessPriorityByClass
PsTerminateSystemThread=PsTerminateSystemThread@4
PsThreadType DATA

View file

@ -1,4 +1,4 @@
/* $Id: process.c,v 1.124 2004/01/05 14:28:21 weiden Exp $
/* $Id: process.c,v 1.125 2004/03/07 20:31:53 navaraf Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -53,9 +53,15 @@ static GENERIC_MAPPING PiProcessMapping = {PROCESS_READ,
PROCESS_ALL_ACCESS};
#define MAX_PROCESS_NOTIFY_ROUTINE_COUNT 8
#define MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT 8
static KSPIN_LOCK PsNotifyListLock;
static PCREATE_PROCESS_NOTIFY_ROUTINE
PiProcessNotifyRoutine[MAX_PROCESS_NOTIFY_ROUTINE_COUNT];
static PLOAD_IMAGE_NOTIFY_ROUTINE
PiLoadImageNotifyRoutine[MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT];
typedef struct
{
@ -268,6 +274,10 @@ PsInitProcessManagment(VOID)
InitializeListHead(&PsProcessListHead);
KeInitializeSpinLock(&PsProcessListLock);
KeInitializeSpinLock(&PsNotifyListLock);
RtlZeroMemory(PiProcessNotifyRoutine, sizeof(PiProcessNotifyRoutine));
RtlZeroMemory(PiLoadImageNotifyRoutine, sizeof(PiLoadImageNotifyRoutine));
/*
* Initialize the system process
@ -913,6 +923,8 @@ NtCreateProcess(OUT PHANDLE ProcessHandle,
&Message);
}
#endif
PspRunCreateProcessNotifyRoutines(Process, TRUE);
ObDereferenceObject(Process);
ObDereferenceObject(ParentProcess);
@ -1572,10 +1584,13 @@ PspRunCreateProcessNotifyRoutines
ULONG i;
HANDLE ProcessId = (HANDLE)CurrentProcess->UniqueProcessId;
HANDLE ParentId = CurrentProcess->InheritedFromUniqueProcessId;
KIRQL oldIrql;
KeAcquireSpinLock(&PsNotifyListLock, &oldIrql);
for(i = 0; i < MAX_PROCESS_NOTIFY_ROUTINE_COUNT; ++ i)
if(PiProcessNotifyRoutine[i])
PiProcessNotifyRoutine[i](ParentId, ProcessId, Create);
KeReleaseSpinLock(&PsNotifyListLock, oldIrql);
}
/*
@ -1586,7 +1601,9 @@ PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
IN BOOLEAN Remove)
{
ULONG i;
KIRQL oldIrql;
KeAcquireSpinLock(&PsNotifyListLock, &oldIrql);
if (Remove)
{
for(i=0;i<MAX_PROCESS_NOTIFY_ROUTINE_COUNT;i++)
@ -1598,6 +1615,7 @@ PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
}
}
KeReleaseSpinLock(&PsNotifyListLock, oldIrql);
return(STATUS_SUCCESS);
}
@ -1611,6 +1629,8 @@ PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
}
}
KeReleaseSpinLock(&PsNotifyListLock, oldIrql);
if (i == MAX_PROCESS_NOTIFY_ROUTINE_COUNT)
{
return STATUS_INSUFFICIENT_RESOURCES;
@ -1619,4 +1639,48 @@ PsSetCreateProcessNotifyRoutine(IN PCREATE_PROCESS_NOTIFY_ROUTINE NotifyRoutine,
return STATUS_SUCCESS;
}
VOID STDCALL
PspRunLoadImageNotifyRoutines(
PUNICODE_STRING FullImageName,
HANDLE ProcessId,
PIMAGE_INFO ImageInfo)
{
ULONG i;
KIRQL oldIrql;
KeAcquireSpinLock(&PsNotifyListLock, &oldIrql);
for (i = 0; i < MAX_PROCESS_NOTIFY_ROUTINE_COUNT; ++ i)
if (PiLoadImageNotifyRoutine[i])
PiLoadImageNotifyRoutine[i](FullImageName, ProcessId, ImageInfo);
KeReleaseSpinLock(&PsNotifyListLock, oldIrql);
}
/*
* @implemented
*/
NTSTATUS STDCALL
PsSetLoadImageNotifyRoutine(IN PLOAD_IMAGE_NOTIFY_ROUTINE NotifyRoutine)
{
ULONG i;
KIRQL oldIrql;
KeAcquireSpinLock(&PsNotifyListLock, &oldIrql);
for (i = 0; i < MAX_LOAD_IMAGE_NOTIFY_ROUTINE_COUNT; i++)
{
if (PiLoadImageNotifyRoutine[i] == NULL)
{
PiLoadImageNotifyRoutine[i] = NotifyRoutine;
break;
}
}
KeReleaseSpinLock(&PsNotifyListLock, oldIrql);
if (i == MAX_PROCESS_NOTIFY_ROUTINE_COUNT)
{
return STATUS_INSUFFICIENT_RESOURCES;
}
return STATUS_SUCCESS;
}
/* EOF */