可执行映像
可执行文件使用内存映射图像文件加载到进程的地址空间中。 不需要打开文件本身,也不需要创建句柄,因为映射是通过 节完成的。 文件系统必须检查才能强制实施这些特殊语义,前提是它们支持内存映射文件。 例如,要为此情况检查的 FASTFAT 文件系统代码可以在 WDK 包含的 fastfat 示例中的 Create.c 源文件中的 FatOpenExistingFCB 函数中找到:
//
// If the user wants write access to the file, make sure there
// is not a process mapping this file as an image. Any attempt to
// delete the file will be stopped in fileinfo.c
//
// If the user wants to delete on close, check at this
// point though.
//
if (FlagOn(*DesiredAccess, FILE_WRITE_DATA) || DeleteOnClose) {
Fcb->OpenCount += 1;
DecrementFcbOpenCount = TRUE;
if (!MmFlushImageSection( &Fcb->NonPaged->SectionObjectPointers,
MmFlushForWrite )) {
Iosb.Status = DeleteOnClose ? STATUS_CANNOT_DELETE :STATUS_SHARING_VIOLATION;
try_return( Iosb );
}
}
因此,文件系统可确保即使文件未打开,也不能删除内存映射文件(包括可执行映像)。