描述:
最近正在看programming applications with microsoft windows这本书,以前对于这些知识所知太少!!
呵呵,汗!
问题如下:
主要是我对下面这一段话,不是很理解,原文贴上
Because the kernel object data structures are accessible only by the kernel, it is impossible for an application to locate these data structures in memory and directly alter their contents. Microsoft enforces this restriction deliberately to ensure that the kernel object structures maintain a consistent state. This restriction also allows Microsoft to add, remove, or change the members in these structures without breaking any applications.
If we cannot alter these structures directly, how do our applications manipulate these kernel objects? The answer is that Windows offers a set of functions that manipulate these structures in well-defined ways. These kernel objects are always accessible via these functions. When you call a function that creates a kernel object, the function returns a handle that identifies the object. Think of this handle as an opaque value that can be used by any thread in your process. You pass this handle to the various Windows functions so that the system knows which kernel object you want to manipulate. We'll talk a lot more about these handles later in this chapter.
To make the operating system robust, these handle values are process-relative. So if you were to pass this handle value to a thread in another process (using some form of interprocess communication), the calls that this other process would make using your process's handle value would fail.
-----------------------------------------------------------------------------------
1.既然核心对象只能由核心层进行管理,那么为什么句柄又和进程相关呢(To make the operating system robust, these handle values are process-relative.)为什么这样就具有鲁棒性啦?
2.还有核心对象和核心(kernel)究竟应当怎么理解呢?这本书还提到file也是核心对象,怎么我感觉我可以操作它啊,以该文的意思,我必须得通过句柄访问,不可以直接进行操作吗?
呵呵,谢谢。
解决方案1:
1.既然核心对象只能由核心层进行管理,那么为什么句柄又和进程相关呢(To make the operating system robust, these handle values are process-relative.)为什么这样就具有鲁棒性啦?
答案:内核对象(核心对象)是操作系统管理资源的一个数据结构,对用户(编程人员)是不可见的,即不能直接操作该数据结构,因为用户任意操作(通常是写操作)会给系统安全造成危害.但操作系统给用户提供了一系列封装好的API函数,用户可以调用这些函数对内核对象进行操作,进而保证了系统的安全性,这里的robust就是指的这一点.譬如这个问题,每个进程在系统看来都有一个数据结构来对其进行管理,用户需要对这个数据结构进行操作,这个句柄就相当于这个这个数据结构的地址(当然不是真实的地址).
2.还有核心对象和核心(kernel)究竟应当怎么理解呢?这本书还提到file也是核心对象,怎么我感觉我可以操作它啊,以该文的意思,我必须得通过句柄访问,不可以直接进行操作吗?
回答:核心是OS的程序,用来操作各种核心对象.核心对象上面已经说了,这里就不多啰嗦了.不错OS把任何资源都抽象为核心对象,这里你所谓的操作它,还是得调用OS的API函数对其操作!!!
因小丑回复次数到了
特此帮他回:
/////////////////////////////////////////////////////////
原文说句柄不是全局的而是和进城相关主要有两个原因一个是健壮性另外一个就是安全
原书说对象的创建者能够阻止未经授权的访问
---------------------------------
但是kernel对象的访问不是由kernel控制吗
怎么这里创建者,又有权利了。
它这个访问权限控制是不是和这个东西相关啊
typedef struct _SECURITY_ATTRIBUTES {
DWORD nLength;
LPVOID lpSecurityDescriptor;
BOOL bInheritHandle;
} SECURITY_ATTRIBUTES;
内核对象是由内核管理的,句柄只是提供给用户态来访问内核对象的一个东西。
这就像Linux中的文件和文件描述符的关系。文件只有一个,但是可以有多个进程同时打开它获得描述符。每个进程的文件描述符都是独立的,是进程的一种资源。描述符指向一个数据结构(进程独立的,也是在打开文件时生成的),里面记录了此进程读写文件的指针位置等进程相关的信息。
1。句柄是用来标识资源的,相信你是学过操作系统的,资源是以进程为单位分配的,当然要和进程相关。就好象图书馆一样,借出去的书是和学生的学号相关的——如果不存在这种关联,图书馆的书不都要被拿光了?!反正找不到和尚也找不到庙!
而所谓的robust是指用句柄的方式,application不能直接去操控kernel object。这个其实和C++的访问权限有点像,因为kernel object中某些域是不允许被application更改的。再次以图书馆为例,馆长肯定是什么书都可以借的,而你就不行,显然是在数据库中你的职称是学生他是馆长,难道你想把你的权限升级到馆长?那不乱套了!象你这样的行为如果被允许,那图书馆就叫做“in-robust”
2。关于kernel的定义,很多os书上讲的很清楚了,自己去翻书。至于file对象,那显然也是一种内核对象,你自己看看CreateFile的返回值是什么?当然是一个handle!
robust是健壮的意思吧,呵呵