标题: linear address space最后一个页 [打印本页] 作者: kiongf 时间: 2013-07-27 18:22 标题: linear address space最后一个页 This is also a good place to recall from the introduction that Linux sometimes has to return a pointer if
an operation succeeds, and an error code if something fails. Unfortunately, the C language only allows
a single direct return value per function, so any information about possible errors has to be encoded
into the pointer. While pointers can in general point to arbitrary locations in memory, each architecture
supported by Linux has a region in virtual address space that starts from virtual address 0 and goes at
least 4 KiB far where no senseful information can live. The kernel can thus reuse this pointer range to
encode error codes: If the return value of fork points to an address within the aforementioned range,
then the call has failed, and the reason can be determined by the numerical value of the pointer. ERR_PTR
is a helper macro to perform the encoding of the numerical constant -EINVAL (invalid operation) into a
pointer.