Kernel Objects 内核对象

Kernel Objects

13 out of 13 rated this helpful - Rate this topic

Kernel object handles are process specific. That is, a process must either create the object or open an existing object to obtain a kernel object handle. The per-process limit on kernel handles is 2^24. However, handles are stored in the paged pool, so the actual number of handles you can create is based on available memory. The number of handles that you can create on 32-bit Windows is significantly lower than 2^24.

Any process can create a new handle to an existing kernel object (even one created by another process), provided that the process knows the name of the object and has security access to the object. Kernel object handles include access rights that indicate the actions that can be granted or denied to a process. An application specifies access rights when it creates an object or obtains an existing object handle. Each type of kernel object supports its own set of access rights. For example, event handles can have set or wait access (or both), file handles can have read or write access (or both), and so on. For more information, see Securable Objects.

In the following illustration, an application creates an event object. The CreateEvent function creates the event object and returns an object handle.

Application creating an event object

After the event object has been created, the application can use the event handle to set or wait on the event. The handle remains valid until the application closes the handle or terminates.

Most kernel objects support multiple handles to a single object. For example, the application in the preceding illustration could obtain additional event object handles by using the OpenEvent function, as shown in the following illustration.

Application creating an event object with multiple handles

This method enables an application to have handles with different access rights. For example, Handle 1 might have set and wait access to the event, and Handle 2 might have only wait access.

If another process knows the event name and has security access to the object, it can create its own event object handle by using OpenEvent. The creating application could also duplicate one of its handles into the same process or into another process by using the DuplicateHandle function.

An object remains in memory as long as at least one object handle exists. In the following illustration, the applications use the CloseHandle function to close their event object handles. When there are no event handles, the system removes the object from memory, as shown in the following illustration.

Application closing event object handles to remove object from memory

The system manages file objects somewhat differently from other kernel objects. File objects contain the file pointer — the pointer to the next byte to be read or written in a file. Whenever an application creates a new file handle, the system creates a new file object. Therefore, more than one file object can refer to a single file on disk, as shown in the next illustration.

Multiple file objects referring to a file on disk

Only through duplication or inheritance can more than one file handle refer to the same file object, as shown in the following illustration.

Two file handles refer to same file object

The following table lists each of the kernel objects, along with each object's creator and destroyer functions. The creator functions either create the object and an object handle or create a new existing object handle. The destroyer functions close the object handle. When an application closes the last handle to a kernel object, the system removes the object from memory.

Kernel objectCreator functionDestroyer function
Access tokenCreateRestrictedToken, DuplicateToken, DuplicateTokenEx, OpenProcessToken, OpenThreadTokenCloseHandle
Change notificationFindFirstChangeNotificationFindCloseChangeNotification
Communications deviceCreateFileCloseHandle
Console inputCreateFile, with CONIN$CloseHandle
Console screen bufferCreateFile, with CONOUT$CloseHandle
DesktopGetThreadDesktopApplications cannot delete this object.
EventCreateEvent, CreateEventEx, OpenEventCloseHandle
Event logOpenEventLog, RegisterEventSource, OpenBackupEventLogCloseEventLog
FileCreateFileCloseHandle, DeleteFile
File mappingCreateFileMapping, OpenFileMappingCloseHandle
Find fileFindFirstFileFindClose
HeapHeapCreateHeapDestroy
I/O completion portCreateIoCompletionPortCloseHandle
JobCreateJobObjectCloseHandle
MailslotCreateMailslotCloseHandle
Memory resource notificationCreateMemoryResourceNotificationCloseHandle
ModuleLoadLibrary, GetModuleHandleFreeLibrary
MutexCreateMutex, CreateMutexEx, OpenMutexCloseHandle
PipeCreateNamedPipe, CreatePipeCloseHandle, DisconnectNamedPipe
ProcessCreateProcess, OpenProcess, GetCurrentProcessCloseHandle, TerminateProcess
SemaphoreCreateSemaphore, CreateSemaphoreEx, OpenSemaphoreCloseHandle
Socketsocket, acceptclosesocket
ThreadCreateThread, CreateRemoteThread, GetCurrentThreadCloseHandle, TerminateThread
TimerCreateWaitableTimer, CreateWaitableTimerEx, OpenWaitableTimerCloseHandle
Update resourceBeginUpdateResourceEndUpdateResource
Window stationGetProcessWindowStationApplications cannot delete this object.

 

Related topics

Kernel Object Namespaces

 

 

Send comments about this topic to Microsoft

Build date: 7/26/2013

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值