Android 新增一个自定义分区

14 篇文章 0 订阅
2 篇文章 0 订阅

 在某个项目中,有一个需求,需要新增一个xxx分区,这个分区类似于vendor/oem分区,名字为指定的。此处有点好奇,为什么不直接使用oem分区,而是另外弄一个分区名出来。

功能实现点
在root目录下新增分区的挂载目录,将自定义分区的内容生成一个img。
配置方案,将需要拷进自动以分区的模块、文件等配置好。
在dts中加入xxx分区的支持。
增加init解析rc的路径,支持xxx/etc/init下的rc文件。
修改PackageManagerService,启动时包扫描增加xxx/app下的apk支持。
修改PATH环境变量,使xxx/bin在PATH环境路径下。
修改Android library路径,使JNI能找到xxx/lib中的so。
修改烧写分区,使xxx.img刷入到flash中。
Android custom images
        AndroidP提供了build_custom_images的task,Makefile的路径如下:

android/build/make/core/tasks/build_custom_images.mk
android/build/make/core/tasks/tools/build_custom_image.mk
        第一个Makefile定义了custom_images这个目标,已经声明了一些需要设置的参数:

custom_image_parameter_variables := \
  CUSTOM_IMAGE_MOUNT_POINT \
  CUSTOM_IMAGE_PARTITION_SIZE \
  CUSTOM_IMAGE_FILE_SYSTEM_TYPE \
  CUSTOM_IMAGE_DICT_FILE \
  CUSTOM_IMAGE_MODULES \
  CUSTOM_IMAGE_COPY_FILES \
  CUSTOM_IMAGE_SELINUX \
  CUSTOM_IMAGE_SUPPORT_VERITY \
  CUSTOM_IMAGE_SUPPORT_VERITY_FEC \
  CUSTOM_IMAGE_VERITY_BLOCK_DEVICE \
  CUSTOM_IMAGE_AVB_HASH_ENABLE \
  CUSTOM_IMAGE_AVB_ADD_HASH_FOOTER_ARGS \
  CUSTOM_IMAGE_AVB_HASHTREE_ENABLE \
  CUSTOM_IMAGE_AVB_ADD_HASHTREE_FOOTER_ARGS \
  CUSTOM_IMAGE_AVB_KEY_PATH \
  CUSTOM_IMAGE_AVB_ALGORITHM \
        这些变量的含义在代码的上方有注释,其中PRODUCT_CUSTOM_IMAGE_MAKEFILES这个变量是自定义的分区image的mk文件,image(分区)的名字就是mk的名字。然后调用第二个Makefile文件去编译生成img。

        在这里,原生的Makefile中没找到自动添加custom_images这个目标的方式,只能通过`make custom_images`的方式去生成。为了在make的时候自动生成custom_images,可做以下修改:

diff --git a/core/tasks/build_custom_images.mk b/core/tasks/build_custom_images.mk
index c9b07da57..93c06ab1d 100644
--- a/core/tasks/build_custom_images.mk
+++ b/core/tasks/build_custom_images.mk
@@ -50,7 +50,10 @@
 #
 # To build all those images, run "make custom_images".
 
-ifneq ($(filter $(MAKECMDGOALS),custom_images),)
+# ifneq ($(filter $(MAKECMDGOALS),custom_images),)
+ifneq ($(PRODUCT_CUSTOM_IMAGE_MAKEFILES),)
+
+$(DEFAULT_GOAL): custom_images
        在$(DEFAULT_GOAL)中添加custom_images这个目标,在core/tasks/build_custom_images.mk中修改判断条件,当PRODUCT_CUSTOM_IMAGE_MAKEFILES变量非空时即生成custom_images这个目标。

        core/tasks/tools/build_custom_image.mk中的my_staging_dir是指定生成custom_images中间文件目录的地方,默认是方案out目录下obj/PACKAGING/xxxx_intermediates/xxx下,我改到方案out目录下的xxx目录下。

custom_image mk配置
        在BoardConfig.mk中增加PRODUCT_CUSTOM_IMAGE_MAKEFILES的配置,如下:

PRODUCT_CUSTOM_IMAGE_MAKEFILES += device/xxx/xxx/xxx.mk
BOARD_ROOT_EXTRA_FOLDERS += xxx
        BOARD_ROOT_EXTRA_FOLDERS变量的值是指在root目录下创建一个目录,这个主要是为xxx分区提供好挂载点。

        然后就是我们需要根据自己的需求写xxx.mk,这里xxx就是我们的分区名:

CUSTOM_IMAGE_MOUNT_POINT := xxx
CUSTOM_IMAGE_PARTITION_SIZE := 11111111111
CUSTOM_IMAGE_FILE_SYSTEM_TYPE := ext4
CUSTOM_IMAGE_SELINUX := true         # 支持编译时指定好selinux权限
 
 
CUSTOM_IMAGE_MODULES += \
    aaaaa \
    bbbbb
 
CUSTOM_IMAGE_COPY_FILES += \
    aaaaaaaa/aaaaaaa.rc:etc/init/init.iptv.rc 
         这些配置变量可参考注释。注意,如果我们的分区是有一些服务的,那么此时最好配置好selinux,CUSTOM_IMAGE_SELINUX设置为true,然后在BoardConfig.mk中BOARD_SEPOLICY_DIRS加入自己的selinux配置,在file_contexts中将整个分区的所有内容默认设置为oemfs(方便使用,oemfs是已定义的selinux规则):

/xxx(/.*)?                     u:object_r:oemfs:s0
分区的挂载
        AndroidP比较特殊,使用了system as root,因此如果自定义分区中有一些rc文件,那么此时就需要在first state挂载上,如果没有rc文件, 无需在init解析rc前挂载,则只需在fstab上挂载即可。

        first state挂载是需要将分区信息写入到dts中,如下:

    firmware {
        android {
            fstab {
                compatible = "android,fstab";
                name = "fstab";
                vendor {
                    compatible = "android,vendor";
                    dev = "/dev/block/by-name/vendor";
                    fsmgr_flags = "wait,recoveryonly";
                    mnt_flags = "ro,barrier=1";
                    name = "vendor";
                    status = "ok";
                    type = "ext4";
                };
                xxx {
                    compatible = "android,xxx";
                    dev = "/dev/block/by-name/XXX";
                    fsmgr_flags = "wait,recoveryonly";
                    mnt_flags = "ro,barrier=1";
                    name = "xxx";
                    status = "ok";
                    type = "ext4";
                };
            };
        };
    };
增加rc文件扫描路径
        如果自定义分区中有需要增加的rc文件,可修改init的代码,如下:

diff --git a/init/init.cpp b/init/init.cpp
index e51a09301..69eb5c28c 100644
--- a/init/init.cpp
+++ b/init/init.cpp
@@ -125,6 +125,9 @@ static void LoadBootScripts(ActionManager& action_manager, ServiceList& service_
         if (!parser.ParseConfig("/vendor/etc/init")) {
             late_import_paths.emplace_back("/vendor/etc/init");
         }
+        if (!parser.ParseConfig("/xxx/etc/init")) {
+            late_import_paths.emplace_back("/xxx/etc/init");
+        }
     } else {
         parser.ParseConfig(bootscript);
     }
增加包扫描路径
        如果自定义分区中有放入预装的app,则可修改PackageManagerService的源码,增加包扫描的路径:

diff --git a/services/core/java/com/android/server/pm/PackageManagerService.java b/services/core/java/com/android/server/pm/PackageManagerService.java
index cf35d0a6d3c..f20873576ee 100644
--- a/services/core/java/com/android/server/pm/PackageManagerService.java
+++ b/services/core/java/com/android/server/pm/PackageManagerService.java
@@ -2660,6 +2660,15 @@ public class PackageManagerService extends IPackageManager.Stub
                     | SCAN_AS_SYSTEM,
                     0);
 
+            // Collect ordinary ctc packages.
+            final File ctcAppDir = new File("/xxx", "app");
+            scanDirTracedLI(ctcAppDir,
+                    mDefParseFlags
+                    | PackageParser.PARSE_IS_SYSTEM_DIR,
+                    scanFlags
+                    | SCAN_AS_SYSTEM,
+                    0);
+
             // Collect privileged vendor packages.
             File privilegedVendorAppDir = new File(Environment.getVendorDirectory(), "priv-app");
             try {
        在这里,由于我自定义分区的app需要具有与system同等的权限,因此参数与扫描system下的APP一样。

新增PATH路径
        如果自定义分区中有一些可执行文件可被其他人执行,可将该路径添加到PATH变量下:

diff --git a/libc/include/paths.h b/libc/include/paths.h
index 922d1ceeb..e5fbcc99c 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -38,7 +38,7 @@
 #define        _PATH_BSHELL    "/system/bin/sh"
 #endif
 #define        _PATH_CONSOLE   "/dev/console"
-#define        _PATH_DEFPATH   "/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin"
+#define        _PATH_DEFPATH   "/sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin:/xxx/bin"
 #define        _PATH_DEV       "/dev/"
 #define        _PATH_DEVNULL   "/dev/null"
 #define        _PATH_KLOG      "/proc/kmsg"
       这个宏在init启动的时候使用到了。

       或者在rc文件中使用export的方式修改:

on init
    export PATH /sbin:/system/sbin:/system/bin:/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin:/xxx/bin
        ext4的分区,在打包成img时,部分文件目录的权限会被修改,如bin这种需要可执行的权限,还需修改打包时权限的设置:

diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 5b79b1d7d..8f3fe41dc 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -203,6 +203,7 @@ static const struct fs_path_config android_files[] = {
     { 00755, AID_ROOT,      AID_ROOT,      0, "system/lib64/valgrind/*" },
     { 00755, AID_ROOT,      AID_SHELL,     0, "system/xbin/*" },
     { 00755, AID_ROOT,      AID_SHELL,     0, "vendor/bin/*" },
+    { 00755, AID_ROOT,      AID_SHELL,     0, "ctc/bin/*" },
     { 00755, AID_ROOT,      AID_SHELL,     0, "vendor/xbin/*" },
     { 00644, AID_ROOT,      AID_ROOT,      0, 0 },
     // clang-format on
新增Android libraries路径
        如果自定义分区支持App,则还需考虑apk加载jni库的路径。Android的jni库加载的路径,是在android/bionic/linker/linker.cpp中加载的,同时还会去读取ld.config.txt中的配置,具体的过程可以去分析linker.cpp中的源码。

        因此我们需要做以下的修改:

        android/bionic仓库下:

diff --git a/linker/linker.cpp b/linker/linker.cpp
index c78b9aba6..750ab39a3 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -96,6 +96,7 @@ static const char* const kLdConfigVndkLiteFilePath = "/system/etc/ld.config.vndk
 static const char* const kSystemLibDir     = "/system/lib64";
 static const char* const kOdmLibDir        = "/odm/lib64";
 static const char* const kVendorLibDir     = "/vendor/lib64";
+static const char* const kCtcLibDir        = "/ctc/lib64";
 static const char* const kAsanSystemLibDir = "/data/asan/system/lib64";
 static const char* const kAsanOdmLibDir    = "/data/asan/odm/lib64";
 static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
@@ -103,6 +104,7 @@ static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib64";
 static const char* const kSystemLibDir     = "/system/lib";
 static const char* const kOdmLibDir        = "/odm/lib";
 static const char* const kVendorLibDir     = "/vendor/lib";
+static const char* const kCtcLibDir        = "/ctc/lib";
 static const char* const kAsanSystemLibDir = "/data/asan/system/lib";
 static const char* const kAsanOdmLibDir    = "/data/asan/odm/lib";
 static const char* const kAsanVendorLibDir = "/data/asan/vendor/lib";
@@ -114,6 +116,7 @@ static const char* const kDefaultLdPaths[] = {
   kSystemLibDir,
   kOdmLibDir,
   kVendorLibDir,
+  kCtcLibDir,
   nullptr
 };
        android/system/core仓库下:

diff --git a/rootdir/etc/ld.config.txt b/rootdir/etc/ld.config.txt
index 42dc7abe7..936757b08 100644
--- a/rootdir/etc/ld.config.txt
+++ b/rootdir/etc/ld.config.txt
@@ -39,6 +39,7 @@ additional.namespaces = sphal,vndk,rs
 namespace.default.isolated = true
 
 namespace.default.search.paths  = /system/${LIB}
+namespace.default.search.paths += /ctc/${LIB}
 namespace.default.search.paths += /%PRODUCT%/${LIB}
        库的路径已经增加上,还有prebuilt的jni库需要拷贝到自定义分区下的模块目录下,修改build下的Makefile:

diff --git a/core/dex_preopt_odex_install.mk b/core/dex_preopt_odex_install.mk
index ce917590b..6638b1d5b 100644
--- a/core/dex_preopt_odex_install.mk
+++ b/core/dex_preopt_odex_install.mk
@@ -369,7 +369,7 @@ ifneq (true,$(my_generate_dm))
   $(my_all_targets): $(installed_odex) $(installed_vdex) $(installed_art)
 else
   ALL_MODULES.$(my_register_name).INSTALLED += $(my_installed_dm)
-  ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_dm) $(my_installed_dm)
+  ALL_MODULES.$(my_register_name).BUILT_INSTALLED += $(my_built_dm):$(my_installed_dm)
 
   # Make sure to install the .dm when you run "make <module_name>"
   $(my_all_targets): $(installed_dm)
diff --git a/core/install_jni_libs_internal.mk b/core/install_jni_libs_internal.mk
index a99d88ad7..5b1bbaf6b 100644
--- a/core/install_jni_libs_internal.mk
+++ b/core/install_jni_libs_internal.mk
@@ -95,7 +95,8 @@ my_jni_shared_libraries += $(my_prebuilt_jni_libs)
 else # not my_embed_jni
 # Install my_prebuilt_jni_libs as separate files.
 $(foreach lib, $(my_prebuilt_jni_libs), \
-    $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib)))))
+    $(eval $(call copy-one-file, $(lib), $(my_app_lib_path)/$(notdir $(lib))))\
+       $(eval ALL_MODULES.$(my_register_name).PREBUILT_INSTALLED += $(lib):$(my_app_lib_path)/$(notdir $(lib))))
 
 $(LOCAL_INSTALLED_MODULE) : $(addprefix $(my_app_lib_path)/, $(notdir $(my_prebuilt_jni_libs)))
 endif  # my_embed_jni
diff --git a/core/tasks/tools/build_custom_image.mk b/core/tasks/tools/build_custom_image.mk
index a1151e908..49033b74f 100644
--- a/core/tasks/tools/build_custom_image.mk
+++ b/core/tasks/tools/build_custom_image.mk
@@ -26,7 +26,7 @@ my_custom_image_name := $(basename $(notdir $(my_custom_imag_makefile)))
 
 intermediates := $(call intermediates-dir-for,PACKAGING,$(my_custom_image_name))
 my_built_custom_image := $(intermediates)/$(my_custom_image_name).img
-my_staging_dir := $(intermediates)/$(CUSTOM_IMAGE_MOUNT_POINT)
+my_staging_dir := $(PRODUCT_OUT)/$(CUSTOM_IMAGE_MOUNT_POINT)
 
 # Collect CUSTOM_IMAGE_MODULES's installd files and their PICKUP_FILES.
 my_built_modules :=
@@ -38,6 +38,8 @@ $(foreach m,$(CUSTOM_IMAGE_MODULES),\
     $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PICKUP_FILES)))\
   $(eval _built_files := $(strip $(ALL_MODULES.$(m).BUILT_INSTALLED)\
     $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).BUILT_INSTALLED)))\
+  $(eval _prebuilt_files := $(strip $(ALL_MODULES.$(m).PREBUILT_INSTALLED)\
+    $(ALL_MODULES.$(m)$(TARGET_2ND_ARCH_MODULE_SUFFIX).PREBUILT_INSTALLED)))\
   $(if $(_pickup_files)$(_built_files),,\
     $(warning Unknown installed file for module '$(m)'))\
   $(eval my_pickup_files += $(_pickup_files))\
@@ -52,6 +54,17 @@ $(foreach m,$(CUSTOM_IMAGE_MODULES),\
       $(eval my_copy_dest := $(wordlist 2,999,$(my_copy_dest)))\
       $(eval my_copy_dest := $(subst $(space),/,$(my_copy_dest)))\
       $(eval my_copy_pairs += $(bui):$(my_staging_dir)/$(my_copy_dest)))\
+  )\
+  $(foreach i, $(_prebuilt_files),\
+    $(eval prebui_ins := $(subst :,$(space),$(i)))\
+    $(eval ins := $(word 2,$(prebui_ins)))\
+    $(if $(filter $(TARGET_OUT_ROOT)/%,$(ins)),\
+      $(eval prebui := $(word 1,$(prebui_ins)))\
+      $(eval my_copy_dest := $(patsubst $(PRODUCT_OUT)/%,%,$(ins)))\
+      $(eval my_copy_dest := $(subst /,$(space),$(my_copy_dest)))\
+      $(eval my_copy_dest := $(wordlist 2,999,$(my_copy_dest)))\
+      $(eval my_copy_dest := $(subst $(space),/,$(my_copy_dest)))\
+      $(eval my_copy_pairs += $(prebui):$(my_staging_dir)/$(my_copy_dest)))\
   ))
刷写分区
        各个厂商的实现不一样,这里不展开。

总结
        经过上面的修改后,一个自定义的分区基本可以完成我们需要的功能,后续有遇到问题再进行修正。
————————————————
版权声明:本文为CSDN博主「chongyuzhao」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/zcyxiaxi/article/details/119113593

  • 1
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PE iDentifier v0.95 (2008.10.21) by snaker, Qwerton, Jibz & xineohP ------------------------------------------------------ PEiD detects most common packers, cryptors and compilers for PE files. I t can currently detect more than 600 different signatures in PE files. PEiD is special in some aspects when compared to other identifiers already out there! 1. It has a superb GUI and the interface is really intuitive and simple. 2. Detection rates are amongst the best given by any other identifier. 3. Special scanning modes for *advanced* detections of modified and unknown files. 4. Shell integration, Command line support, Always on top and Drag'n'Drop capabilities. 5. Multiple file and directory scanning with recursion. 6. Task viewer and controller. 7. Plugin Interface with plugins like Generic OEP Finder and Krypto ANALyzer. 8. Extra scanning techniques used for even better detections. 9. Heuristic Scanning options. 10. New PE details, Imports, Exports and TLS viewers 11. New built in quick disassembler. 12. New built in hex viewer. 13. External signature interface which can be updated by the user. There are 3 different and unique scanning modes in PEiD. The *Normal Mode* scans the PE files at their Entry Point for all documented signatures. This is what all other identifiers also do. The *Deep Mode* scans the PE file's Entry Point containing section for all the documented signatures. This ensures detection of around 80% of modified and scrambled files. The *Hardcore Mode* does a complete scan of the entire PE file for the documented signatures. You should use this mode as a last option as the small signatures often tend to occur a lot in many files and so erroneous outputs may result. The scanner's inbuilt scanning techniques have error control methods which generally ensure correct outputs even if the last mode is chosen. The first two methods produce almost instantaneous outputs but the last method is a bit slow due to obvious reasons! Command line Options -------------------- PEiD now fully supports commandline parameters. peid -time // Show statistics before quitting peid -r // Recurse through subdirectories peid -nr // Don't scan subdirectories even if its set peid -hard // Scan files in Hardcore Mode peid -deep // Scan files in Deep Mode peid -norm // Scan files in Normal Mode peid <file1> <file2> <dir1> <dir2> You can combine one or more of the parameters. For example. peid -hard -time -r c:\windows\system32 peid -time -deep c:\windows\system32\*.dll Task Viewing / Control Module ----------------------------- You can scan currently running tasks with PEiD. The files are scanned from memory. Processes can also be terminated. You can also optionally dump a module and scan the dumped image. You can also view all dependant modules of the processes. Multiple File Scan Module ------------------------- You can scan multiple files at one go with PEiD. Just drag and drop the files on the PEiD main dialog and the Multiple File Scan Dialog will popup displaying the results. You can keep dragging and dropping files onto this dialog as well. It also offers you to choose from the different scanning modes and optionally load a single file in PEiD. It allows you to skip the non PE files so that the list looks clean. You can also scan the contents of a directory choosing files of custom extension if required. MFS v0.02 now supports recursive directory scanning. Disassembler Module ------------------- You can have a quick disassembly of the file loaded in PEiD. Double click to follow JMPs and CALLs and use the Back button to trace back to the original positions. You can copy disassembled output to the clipboard. A new CADT core with custom String Reference Finder has been cooked up. CADT is coded by Ms-Rem. Hex Viewer Module ------------------- You can have a quick hex view of the file loaded in PEiD. A modified version of 16Edit by y0da is used for this purpose. We intend to update the signatures quite often to keep pace with this ever evolving scene :) Please report bugs, ideas, new signatures or packer info to: pusher -> sir.pusher(at)gmail(dot)com ( Administration / Coder ) snaker -> snaker(at)myrealbox(dot)com Jibz -> peid(at)ibsensoftware(dot)com Qwerton -> qwaci(at)gmx(dot)net ALL SUGGESTIONS, IDEAS, BUG REPORTS AND CRITICS ARE WELCOME. History ------- 0.7 Beta -> First public release. 0.8 Public -> Added support for 40 more packers. OEP finding module. Task viewing/control module. GUI changes. General signature bug fixes. Multiple File and Directory Scanning module. 0.9 Recode -> Completely recoded from scratch. New Plugin Interface which lets you use extra features. Added more than 130 new signatures. Fixed many detections and general bugs. 0.91 Reborn -> Recoded everything again. New faster and better scanning engine. New internal signature system. MFS v0.02 now supports Recursive Scanning. Commandline Parser now updated and more powerful. Detections fine tuned and newer detections added. Very basic Heuristic scanning. 0.92 Classic -> Added support for external database, independent of internal signatures. Added PE details lister. Added Import, Export, TLS and Section viewers. Added Disassembler. Added Hex Viewer. Added ability to use plugins from Multiscan window. Added exporting of Multiscan results. Added ability to abort MultiScan without loosing results. Added ability to show process icons in Task Viewer. Added ability to show modules under a process in Task Viewer. Added some more detections. 0.93 Elixir -> Added sorting of Plugin menu items. Submenus are created based on subfolders in the directory. Added Brizo disassembler core. Added some more detections. Fixed documented and undocumented vulnerability issues. Fixed some general bugs. Removed mismatch mode scanner which needs further improvements. 0.94 Flux -> Too much is new to remember. MFS, Task Viewer and Disassembler windows maximizable. New smaller and lighter disassembler core CADT. New KANAL 2.90 with much more detections and export features. Added loads of new signatures. Thanks to all the external signature collections online. String References integrated into disassembler. Fixed documented and undocumented crashes. Fixed some general bugs. 0.95 Phoenix -> Fixed some crashing bugs. Minor Core update. Greets ------ Qwerton, Jibz, CHRiST0PH, uno, DAEMON, MackT, VAG, SAC, Gamumba, SnowP and all the rest at uG, Michael Hering, tE!, pusher, {igNo}, Maxx, CoDE, BaND, Snacker, skamer, HypnZ, ParaBytes, Clansman, BuLLeT, Devine9, innuendo, Corby, cokine, AiRW0lF, fxfighter, GodsJiva, Carpathia, _death, artik, r!sc, NoodleSPA, SiR_dReaM, CHoRDLeSS, NeOXQuiCk, un4Giv3n, RZX, 7xS, LibX and all who helped with PEiD :) snaker, Jibz, cokine, Iczelion, Clansman, Z-Wing, Unknown One/TMG, PeeWee, DnNuke, sinny/BAFH, all the other nice people in CiA, uG and all of you who helped us develope PEiD. Thanks. snaker, Qwerton, DAEMON, VaG, Parabytes, bse, f0dder, Stone, Michael Hering, Iczelion, Steve Hutchesson, Eugene Suslikov, and everybody in #unpacking and #compression. Qwerton - Hope you get time someday again, was nice working with you :) Jibz - You rock evil friend. Thanks for all your help. It's a pleasure working with you. Hope things work out! Michael Hering - FILE INFO is still the absolute best. Your suggestions rock :) uG2oo6 - Delicious Slumber! MackT - Thanks for all your help and for ImpREC of course ;) Unknown One - Spend more time with us :) BaND - Thanks for all your testing and help. pusher - Thanks for your help and all the testing and the constant encouragment ;) Maxx - Thanks for the encouragment, your code and suggestions should be added next time :) Kaparo & Aaron - Thanks for your sites :) BoB - Thanks for taking over the PEiD project, and the contribution. We would also like to thank the *few* people who sent us their comments and feedback about PEiD. Also greetings to everyone who has supported PEiD till date. Without you this new release would never be possible. You can check out the PEiD homepage at http://www.peid.info and the PEiD Forums at http://www.peid.info/forum snaker, Qwerton, Jibz & xineohP Productions
PART I: CORE TECHNOLOGIES 1 Overview ...................................................................................................... 3 1.1 Introduction ...................................................................................................................... 3 1.2 Kernel Architecture ......................................................................................................... 3 1.3 Related Documentation Resources .............................................................................. 4 1.4 VxWorks Configuration and Build .............................................................................. 5 2 VxWorks Configuration ............................................................................. 7 2.1 Introduction ...................................................................................................................... 7 2.2 About VxWorks Configuration ................................................................................... 7 2.2.1 Default Configuration and Images ................................................................. 8 2.2.2 Configuration With VxWorks Image Projects ............................................... 8 2.2.3 Configuration With VxWorks Source Build Projects ................................... 8 2.2.4 Configuration and Customization .................................................................. 8 2.2.5 Configuration Tools: Workbench and vxprj .................................................. 9 2.3 VxWorks Image Projects: VIPs .................................................................................... 9 2.3.1 VxWorks Components ...................................................................................... 10 Component Names .......................................................................................... 10 Basic VxWorks Components ............................................................................ 11 2.3.2 Device Driver Selection ................................................................................... 13 2.3.3 Component Bundles and Configuration Profiles ........................................ 14 2.3.4 VxWorks Component Reference .................................................................... 14 2.4 VxWorks Source Build Projects: VSBs ....................................................................... 14 2.4.1 Basic Operating System VSB Options ........................................................... 16 BSP-Specific Optimizations ............................................................................. 16 VxWorks Kernel Programmer's Guide, 6.9 iv Inconsistent Cache Mode Support .................................................................. 17 System Viewer Instrumentation Support ...................................................... 17 Real-Time Process Support .............................................................................. 17 Object Management Support ........................................................................... 17 Error Detection and Reporting Policy Hooks ............................................... 18 Task Switch Hook Support .............................................................................. 18 Task Create Hook Support ............................................................................... 18 CPU Power Management Support ................................................................. 19 Advanced Options ............................................................................................ 19 VxWorks BSP Validation Test Suite Support ................................................. 19 Symmetric Multiprocessor (SMP) Support ................................................... 19 SMP Determinism ............................................................................................. 19 MIPC Support .................................................................................................... 20 WRLOAD Support ............................................................................................ 20 Task-Specific Current Working Directory ...................................................... 20 Device Name Length ........................................................................................ 20 NFS V3 Server Optimization ........................................................................... 20 DOSFS Name Length Compatible .................................................................. 21 2.4.2 VSB Profiles ........................................................................................................ 21 2.4.3 Using VSB Projects to Create VxWorks Systems: Basic Steps .................... 21 2.4.4 Developing Kernel Applications for VSB Systems ..................................... 21 2.5 VxWorks Without Networking ..................................................................................... 22 2.6 Small-Footprint VxWorks Configuration ................................................................... 22 2.6.1 About Small-Footprint VxWorks .................................................................... 22 Kernel Facilities ................................................................................................. 22 Unsupported Facilities ..................................................................................... 23 BSPs ..................................................................................................................... 23 2.6.2 Configuring Small Footprint VxWorks .......................................................... 23 Small-Footprint VSB Profile and Options ...................................................... 24 VSB Options Specific to the Small-Footprint Profile .................................... 24 Small-Footprint VIP Profile and Components .............................................. 25 Optional Components for a Small Footprint VIP Project ............................ 25 2.6.3 Configuration and Build Steps for Small-Footprint VxWorks ................... 25 2.6.4 Writing Applications for Small-Footprint VxWorks .................................... 26 2.6.5 Example Application ........................................................................................ 26 2.6.6 Debugging Small-Footprint VxWorks ............................................................ 28 2.7 VxWorks Image Types ................................................................................................... 28 2.7.1 Default VxWorks Images ................................................................................ 29 2.7.2 VxWorks Images for Development and Production Systems ..................... 29 2.7.3 Boot Parameter Configuration for Standalone VxWorks Images .............. 30 2.8 Image Size Considerations ............................................................................................ 30 2.8.1 Boot Loader and Downloadable Image ......................................................... 30 2.8.2 Self-Booting Image ............................................................................................ 31 Contents v 3 Boot Loader ................................................................................................. 33 3.1 Introduction ...................................................................................................................... 33 3.2 Using a Default Boot Loader ......................................................................................... 34 3.3 Boot Loader Image Types ............................................................................................... 35 3.4 Boot Loader Shell ............................................................................................................ 35 3.4.1 Boot Loader Shell Commands ......................................................................... 36 3.5 Boot Parameters ............................................................................................................... 39 3.5.1 Displaying Current Boot Parameters ............................................................. 40 3.5.2 Description of Boot Parameters ...................................................................... 41 3.5.3 Changing Boot Parameters Interactively ....................................................... 44 3.6 Rebooting VxWorks ........................................................................................................ 45 3.7 Configuring and Building Boot Loaders .................................................................... 46 3.7.1 Boot Loader Profiles .......................................................................................... 46 3.7.2 Boot Loader Components ................................................................................ 47 3.7.3 Configuring Boot Parameters Statically ......................................................... 47 3.7.4 Enabling Networking for Non-Boot Interfaces ............................................. 48 3.7.5 Selecting a Boot Device ..................................................................................... 48 3.7.6 Reconfiguring Boot Loader Memory Layout for 32-Bit VxWorks ............. 50 Redefining the Boot Loader Link Address for Custom Boot Loaders ....... 50 Reconfiguring Memory Layout for a Persistent Memory Region ............. 51 3.7.7 Reconfiguring Boot Loader Memory Layout for 64-Bit VxWorks ............. 53 3.7.8 Building Boot Loaders ...................................................................................... 53 3.8 Installing Boot Loaders .................................................................................................. 53 3.9 Booting From a Network ............................................................................................... 53 3.10 Booting From a Target File System ............................................................................. 55 3.11 Booting From the Host File System Using TSFS ..................................................... 55 4 Kernel Applications .................................................................................... 57 4.1 Introduction ...................................................................................................................... 57 4.2 About Kernel Applications ........................................................................................... 58 4.3 Comparing Kernel Applications with RTP Applications ....................................... 59 4.4 C and C++ Libraries ........................................................................................................ 60 VxWorks Kernel Programmer's Guide, 6.9 vi 4.5 Kernel Application Structure ........................................................................................ 60 4.6 VxWorks Header Files .................................................................................................... 61 4.6.1 VxWorks Header File: vxWorks.h ................................................................... 61 4.6.2 Other VxWorks Header Files ........................................................................... 62 4.6.3 ANSI Header Files ............................................................................................ 62 4.6.4 ANSI C++ Header Files .................................................................................... 62 4.6.5 The -I Compiler Flag ......................................................................................... 62 4.6.6 VxWorks Nested Header Files ........................................................................ 62 4.6.7 VxWorks Private Header Files ........................................................................ 63 4.7 Custom Header Files ....................................................................................................... 63 4.8 Static Instantiation of Kernel Objects ......................................................................... 64 4.8.1 About Static Instantiation of Kernel Objects ................................................. 64 Kernel Objects That can be Instantiated Statically ....................................... 65 Static Instantiation and Code Size .................................................................. 65 Advantages of Static Instantiation .................................................................. 65 Applications and Static Instantiation ............................................................. 66 4.8.2 Scope Of Static Declarations ............................................................................ 66 4.8.3 Caveat With Regard to Macro Use .................................................................. 66 4.8.4 Static Instantiation of Tasks ............................................................................. 66 4.8.5 Static Instantiation Of Semaphores ................................................................ 67 4.8.6 Static Instantiation of Message Queues ......................................................... 68 4.8.7 Static Instantiation of Watchdog Timers ........................................................ 68 4.9 Boot-Time Hook Routine Facility ............................................................................... 69 Boot-Time Hook Routine Stubs and Components ....................................... 69 Using Boot-Time Hook Routine Stubs ........................................................... 70 4.10 Kernel Applications and Kernel Component Requirements ................................. 71 4.11 Building Kernel Application Modules ....................................................................... 71 4.12 Downloading Kernel Application Object Modules to a Target ............................. 72 4.13 Linking Kernel Application Object Modules with VxWorks ................................ 72 4.14 Configuring VxWorks to Run Applications Automatically ................................... 72 5 C++ Development ....................................................................................... 75 5.1 Introduction ...................................................................................................................... 75 5.2 Configuring VxWorks for C++ ..................................................................................... 76 5.3 C++ Header Files ............................................................................................................. 76 Contents vii 5.4 Spawning Tasks That Use C++ ..................................................................................... 76 5.5 Calls Between C and C++ Code .................................................................................... 77 5.6 C++ Compiler Caveats .................................................................................................... 77 5.7 Using C++ in Signal Handlers and ISRs ................................................................... 78 5.8 Downloadable Kernel Modules in C++ ..................................................................... 78 5.9 C++ Compiler Differences ............................................................................................ 78 5.9.1 Template Instantiation ...................................................................................... 78 5.9.2 Run-Time Type Information ............................................................................ 80 5.10 Namespaces ...................................................................................................................... 80 5.11 C++ Exception Handling ................................................................................................ 81 5.12 Standard Template Library (STL) ................................................................................ 81 5.13 C++ Demo Example ........................................................................................................ 81 6 Multitasking ................................................................................................. 83 6.1 Introduction ...................................................................................................................... 83 6.2 About Tasks and Multitasking ..................................................................................... 84 6.2.1 Task States and Transitions .............................................................................. 85 Tasks States and State Symbols ....................................................................... 85 Illustration of Basic Task State Transitions .................................................... 86 6.3 VxWorks System Tasks .................................................................................................. 87 Basic VxWorks Tasks ......................................................................................... 88 Tasks for Optional Components ..................................................................... 91 6.4 Task Scheduling .............................................................................................................. 93 6.4.1 Task Priorities .................................................................................................... 93 6.4.2 VxWorks Traditional Scheduler ...................................................................... 93 Priority-Based Preemptive Scheduling .......................................................... 94 Scheduling and the Ready Queue ................................................................. 94 Round-Robin Scheduling ................................................................................. 95 6.5 Task Creation and Management ................................................................................... 97 6.5.1 Task Creation and Activation .......................................................................... 97 Static instantiation of Tasks ............................................................................. 98 6.5.2 Task Names and IDs ......................................................................................... 98 Task Naming Rules ........................................................................................... 99 Task Name and ID Routines ............................................................................ 99 VxWorks Kernel Programmer's Guide, 6.9 viii 6.5.3 Inter-Process Communication With Public Tasks ......................................... 99 6.5.4 Task Creation Options ...................................................................................... 100 6.5.5 Task Stack ........................................................................................................... 102 Task Stack Protection ........................................................................................ 102 6.5.6 Task Information ............................................................................................... 103 6.5.7 Task Deletion and Deletion Safety .................................................................. 104 6.5.8 Task Execution Control ..................................................................................... 105 6.5.9 Task Scheduling Control .................................................................................. 106 6.5.10 Tasking Extensions: Using Hook Routines .................................................... 107 6.6 Task Error Status: errno .................................................................................................. 108 6.6.1 Layered Definitions of errno ........................................................................... 109 6.6.2 A Separate errno Value for Each Task ............................................................ 109 6.6.3 Error Return Convention ................................................................................. 109 6.6.4 Assignment of Error Status Values ................................................................. 110 6.7 Task Exception Handling ............................................................................................... 110 6.8 Shared Code and Reentrancy ........................................................................................ 111 6.8.1 Dynamic Stack Variables .................................................................................. 112 6.8.2 Guarded Global and Static Variables ............................................................. 112 6.8.3 Task-Specific Variables .................................................................................... 113 Thread-Local Variables: __thread Storage Class ........................................... 113 taskVarLib and Task Variables ........................................................................ 114 6.8.4 Multiple Tasks with the Same Main Routine ................................................ 114 7 Intertask and Interprocess Communication ............................................. 117 7.1 Introduction ...................................................................................................................... 117 7.2 About Intertask and Interprocess Communication .................................................. 118 7.3 Shared Data Structures ................................................................................................... 119 7.4 Interrupt Locks ............................................................................................................... 120 7.5 Task Locks ........................................................................................................................ 121 7.6 Semaphores ...................................................................................................................... 122 7.6.1 Inter-Process Communication With Public Semaphores ............................. 123 7.6.2 Semaphore Creation and Use .......................................................................... 123 Options for Scalable and Inline Semaphore Routines ................................ 125 Static Instantiation of Semaphores ................................................................. 125 Scalable and Inline Semaphore Take and Give Routines ........................... 126 Contents ix 7.6.3 Binary Semaphores ........................................................................................... 126 Mutual Exclusion .............................................................................................. 127 Synchronization ................................................................................................. 128 7.6.4 Mutual-Exclusion Semaphores ....................................................................... 129 Priority Inversion and Priority Inheritance ................................................... 129 Deletion Safety ................................................................................................... 132 Recursive Resource Access .............................................................................. 133 7.6.5 Counting Semaphores ...................................................................................... 134 7.6.6 Read/Write Semaphores ................................................................................. 134 Specification of Read or Write Mode .............................................................. 135 Precedence for Write Access Operations ....................................................... 136 Read/Write Semaphores and System Performance ..................................... 136 7.6.7 Special Semaphore Options ............................................................................. 136 Semaphore Timeout .......................................................................................... 136 Semaphores and Queueing .............................................................................. 137 Semaphores and VxWorks Events .................................................................. 137 7.7 Message Queues .............................................................................................................. 137 7.7.1 Inter-Process Communication With Public Message Queues ..................... 138 7.7.2 Message Creation and Use ............................................................................... 138 Static Instantiation of Message Queues ......................................................... 139 Message Queue Timeout .................................................................................. 139 Message Queue Urgent Messages .................................................................. 140 Message Queues and Queuing Options ........................................................ 140 7.7.3 Displaying Message Queue Attributes .......................................................... 141 7.7.4 Servers and Clients with Message Queues .................................................... 141 7.7.5 Message Queues and VxWorks Events .......................................................... 142 7.8 Pipes ................................................................................................................................... 142 7.8.1 Creating Pipes ................................................................................................... 142 7.8.2 Writing to Pipes from ISRs ............................................................................... 142 7.8.3 I/O Control Functions ...................................................................................... 143 7.9 VxWorks Events ............................................................................................................... 143 7.9.1 Configuring VxWorks for Events .................................................................... 144 7.9.2 About Event Flags and the Task Events Register ......................................... 144 7.9.3 Receiving Events ............................................................................................... 145 7.9.4 Sending Events .................................................................................................. 146 7.9.5 Inter-Process Communication With Events .................................................. 148 7.9.6 Events Routines ................................................................................................. 148 7.9.7 Code Example ................................................................................................... 149 7.9.8 Show Routines and Events .............................................................................. 149 VxWorks Kernel Programmer's Guide, 6.9 x 7.10 Inter-Process Communication With Public Objects ................................................. 149 Creating and Naming Public and Private Objects ....................................... 150 Example of Inter-process Communication With a Public Semaphore ...... 150 7.11 About VxWorks API Timeout Parameters .................................................................. 152 7.12 About Object Ownership and Resource Reclamation ............................................. 152 8 Signals, ISRs, and Watchdog Timers ........................................................ 155 8.1 Introduction ...................................................................................................................... 155 8.2 Signals .............................................................................................................................. 156 8.2.1 Configuring VxWorks for Signals .................................................................. 157 8.2.2 Basic Signal Routines ........................................................................................ 158 8.2.3 Queued Signal Routines .................................................................................. 159 8.2.4 Signal Events ...................................................................................................... 162 8.2.5 Signal Handlers ................................................................................................. 163 8.3 Interrupt Service Routines: ISRs ................................................................................. 166 8.3.1 Configuring VxWorks for ISRs ........................................................................ 166 Configuring the Interrupt Stack ...................................................................... 166 Adding Show Routine Support ....................................................................... 167 8.3.2 Writing ISRs ....................................................................................................... 167 Restrictions on ISRs ........................................................................................... 167 Facilities Available for ISRs .............................................................................. 169 Reserving High Interrupt Levels .................................................................... 170 8.3.3 System Clock ISR Modification ....................................................................... 171 8.3.4 Connecting ISRs to Interrupts ......................................................................... 171 8.3.5 Getting Information About ISRs ..................................................................... 172 8.3.6 Debugging ISRs ................................................................................................. 173 8.4 Watchdog Timers ............................................................................................................. 174 Static Instantiation of Watchdog Timers ........................................................ 175 8.4.1 Inter-Process Communication With Public Watchdog Timers ................... 176 9 POSIX Facilities .......................................................................................... 177 9.1 Introduction ...................................................................................................................... 178 9.2 Configuring VxWorks with POSIX Facilities ............................................................ 179 9.2.1 VxWorks Components for POSIX Facilities .................................................. 179 9.3 General POSIX Support ................................................................................................. 180 9.4 POSIX Header Files ........................................................................................................ 181 Contents xi 9.5 POSIX Namespace .......................................................................................................... 183 9.6 POSIX Clocks and Timers ............................................................................................. 183 9.7 POSIX Asynchronous I/O .............................................................................................. 186 9.8 POSIX Advisory File Locking ....................................................................................... 186 9.9 POSIX Page-Locking Interface ..................................................................................... 186 9.10 POSIX Threads ................................................................................................................ 187 9.10.1 POSIX Thread Attributes ................................................................................. 188 9.10.2 VxWorks-Specific Pthread Attributes ............................................................ 188 9.10.3 Specifying Attributes when Creating Pthreads ........................................... 189 9.10.4 POSIX Thread Creation and Management .................................................... 190 9.10.5 POSIX Thread Attribute Access ...................................................................... 190 9.10.6 POSIX Thread Private Data ............................................................................. 191 9.10.7 POSIX Thread Cancellation ............................................................................. 192 9.11 POSIX Thread Mutexes and Condition Variables .................................................... 193 9.11.1 Thread Mutexes ................................................................................................. 193 Protocol Mutex Attribute ................................................................................ 194 Priority Ceiling Mutex Attribute .................................................................... 195 9.11.2 Condition Variables .......................................................................................... 195 9.12 POSIX and VxWorks Scheduling ................................................................................. 196 9.12.1 Differences in POSIX and VxWorks Scheduling ........................................... 197 9.12.2 POSIX and VxWorks Priority Numbering ..................................................... 198 9.12.3 Default Scheduling Policy ................................................................................ 198 9.12.4 VxWorks Traditional Scheduler ...................................................................... 198 9.12.5 POSIX Threads Scheduler ................................................................................ 199 9.12.6 POSIX Scheduling Routines ............................................................................ 203 9.12.7 Getting Scheduling Parameters: Priority Limits and Time Slice ................ 204 9.13 POSIX Semaphores ......................................................................................................... 204 9.13.1 Comparison of POSIX and VxWorks Semaphores ....................................... 205 9.13.2 Using Unnamed Semaphores .......................................................................... 206 9.13.3 Using Named Semaphores .............................................................................. 208 9.14 POSIX Message Queues ................................................................................................. 211 9.14.1 Comparison of POSIX and VxWorks Message Queues ............................... 212 9.14.2 POSIX Message Queue Attributes .................................................................. 213 9.14.3 Displaying Message Queue Attributes .......................................................... 214 VxWorks Kernel Programmer's Guide, 6.9 xii 9.14.4 Communicating Through a Message Queue ................................................ 215 9.14.5 Notification of Message Arrival ..................................................................... 218 9.15 POSIX Signals .................................................................................................................. 222 9.16 POSIX Memory Management ....................................................................................... 222 10 Memory Management ................................................................................. 223 10.1 Introduction ...................................................................................................................... 223 10.2 32-Bit VxWorks Memory Layout ................................................................................. 224 10.2.1 Displaying Information About Memory Layout .......................................... 224 10.2.2 System Memory Map Without RTP Support ................................................ 224 10.2.3 System Memory Map with RTP Support ....................................................... 226 10.2.4 System RAM Autosizing .................................................................................. 228 10.2.5 Reserved Memory: User-Reserved Memory and Persistent Memory ...... 228 10.3 64-Bit VxWorks Memory Layout ................................................................................. 229 10.3.1 Displaying Information About Memory Layout .......................................... 230 10.3.2 Virtual Memory Regions .................................................................................. 230 Kernel System Virtual Memory Region ......................................................... 231 Kernel Virtual Memory Pool Region .............................................................. 232 Kernel Reserved Memory Region ................................................................... 232 Shared User Virtual Memory Region ............................................................. 232 RTP Private Virtual Memory Region .............................................................. 232 10.3.3 Global RAM Pool .............................................................................................. 233 10.3.4 Kernel Memory Map ........................................................................................ 233 Kernel System Memory .................................................................................... 235 Kernel Common Heap ...................................................................................... 235 DMA32 Heap ..................................................................................................... 235 User-Reserved Memory ................................................................................... 235 Persistent Memory ............................................................................................ 235 10.3.5 Reserved Memory Configuration: User-Reserved Memory and Persistent Memory .............................................................................................................. 236 10.3.6 System RAM Autosizing .................................................................................. 236 10.4 About VxWorks Memory Allocation Facilities ......................................................... 236 10.5 32-Bit VxWorks Heap and Memory Partition Management .................................. 237 10.5.1 Configuring the Kernel Heap and the Memory Partition Manager .......... 238 10.5.2 Basic Heap and Memory Partition Manager ................................................. 238 10.5.3 Full Heap and Memory Partition Manager ................................................... 238 10.6 64-Bit VxWorks Heap and Memory Partition Management .................................. 239 10.6.1 Kernel Common Heap ...................................................................................... 239 Contents xiii 10.6.2 Kernel Proximity Heap ..................................................................................... 240 10.6.3 DMA32 Heap ..................................................................................................... 240 10.7 SMP-Optimized Memory Allocation .......................................................................... 241 10.7.1 Configuration ..................................................................................................... 241 10.7.2 Usage scenarios ................................................................................................. 241 10.8 Memory Pools .................................................................................................................. 242 10.9 POSIX Memory Management ....................................................................................... 242 10.9.1 POSIX Memory Management APIs ................................................................ 243 10.9.2 POSIX Memory Mapping ................................................................................ 244 10.9.3 POSIX Memory Protection ............................................................................... 244 10.9.4 POSIX Memory Locking .................................................................................. 244 10.10 Memory Mapping Facilities .......................................................................................... 245 10.10.1 POSIX Memory-Mapped Files ........................................................................ 247 10.10.2 POSIX Shared Memory Objects ...................................................................... 247 10.10.3 Anonymous Memory Mapping ...................................................................... 247 10.10.4 Device Memory Objects ................................................................................... 248 10.10.5 Shared Data Regions ......................................................................................... 249 10.11 Virtual Memory Management ..................................................................................... 249 10.11.1 Configuring Virtual Memory Management .................................................. 250 10.11.2 Managing Virtual Memory Programmatically ............................................. 251 Modifying Page States ...................................................................................... 252 Making Memory Non-Writable ...................................................................... 253 Invalidating Memory Pages ............................................................................ 255 Locking TLB Entries .......................................................................................... 255 Page Size Optimization .................................................................................... 255 Setting Page States in ISRs ............................................................................... 256 10.11.3 Troubleshooting ................................................................................................. 256 10.12 Additional Memory Protection Features ................................................................... 257 10.12.1 Configuring VxWorks for Additional Memory Protection ......................... 257 10.12.2 Stack Overrun and Underrun Detection ........................................................ 258 10.12.3 Non-Executable Task Stack .............................................................................. 258 10.12.4 Text Segment Write Protection ........................................................................ 258 10.12.5 Exception Vector Table Write Protection ........................................................ 259 10.13 Memory Error Detection ................................................................................................ 259 10.13.1 Heap and Partition Memory Instrumentation .............................................. 259 10.13.2 Compiler Instrumentation: 32-Bit VxWorks .................................................. 264 VxWorks Kernel Programmer's Guide, 6.9 xiv 11 I/O System ................................................................................................... 269 11.1 Introduction ...................................................................................................................... 269 11.2 About the VxWorks I/O System ................................................................................... 270 Differences Between VxWorks and Host System I/O ................................. 270 11.3 Configuring VxWorks With I/O Facilities .................................................................. 271 11.4 I/O Devices, Named Files, and File Systems ............................................................ 272 11.5 Remote File System Access From VxWorks ............................................................... 273 NFS File System Access from VxWorks ......................................................... 273 Non-NFS Network File System Access from VxWorks WIth FTP or RSH 273 11.6 Basic I/O ............................................................................................................................ 275 11.6.1 File Descriptors .................................................................................................. 275 File Descriptor Table ......................................................................................... 276 11.6.2 Standard Input, Standard Output, and Standard Error .............................. 276 11.6.3 Standard I/O Redirection ................................................................................ 276 Issues with Standard I/O Redirection ........................................................... 277 11.6.4 Open and Close ................................................................................................. 278 11.6.5 Create and Remove ........................................................................................... 280 11.6.6 Read and Write .................................................................................................. 281 11.6.7 File Truncation ................................................................................................... 281 11.6.8 I/O Control ........................................................................................................ 282 11.6.9 Pending on Multiple File Descriptors with select( ) ..................................... 282 11.6.10 POSIX File System Routines ............................................................................ 284 11.7 Standard I/O ..................................................................................................................... 285 11.7.1 Configuring VxWorks With Standard I/O .................................................... 285 11.7.2 About printf( ), sprintf( ), and scanf( ) ............................................................ 286 11.7.3 About Standard I/O and Buffering ................................................................ 286 11.7.4 About Standard Input, Standard Output, and Standard Error .................. 287 11.8 Other Formatted I/O ....................................................................................................... 287 11.8.1 Output in Serial I/O Polled Mode: kprintf( ) ................................................ 287 Writing to User-Defined Storage Media With kprintf( ) and kputs( ) ....... 288 11.8.2 Additional Formatted I/O Routines ............................................................. 289 11.8.3 Message Logging ............................................................................................... 289 11.9 Asynchronous Input/Output ......................................................................................... 289 11.9.1 The POSIX AIO Routines ................................................................................. 290 Contents xv 11.9.2 AIO Control Block ............................................................................................. 291 11.9.3 Using AIO ........................................................................................................... 292 AIO with Periodic Checks for Completion ................................................... 292 Alternatives for Testing AIO Completion ..................................................... 294 12 Devices ........................................................................................................ 297 12.1 Introduction ...................................................................................................................... 297 12.2 About Devices in VxWorks ........................................................................................... 298 12.3 Serial I/O Devices: Terminal and Pseudo-Terminal Devices .................................. 299 tty Options .......................................................................................................... 299 12.3.1 Raw Mode and Line Mode .............................................................................. 300 12.3.2 tty Special Characters ....................................................................................... 300 12.3.3 I/O Control Functions ...................................................................................... 301 12.4 Pipe Devices ..................................................................................................................... 302 12.5 Pseudo I/O Device ........................................................................................................... 302 12.5.1 I/O Control Functions ...................................................................................... 303 12.6 Null Devices .................................................................................................................... 303 12.7 Block Devices ................................................................................................................... 303 12.7.1 XBD RAM Disk .................................................................................................. 305 12.7.2 SCSI Drivers ....................................................................................................... 306 Configuring SCSI Drivers ................................................................................ 306 Structure of the SCSI Subsystem ..................................................................... 307 Booting and Initialization ................................................................................ 308 Device-Specific Configuration Options ......................................................... 308 SCSI Configuration Examples ......................................................................... 310 Troubleshooting ................................................................................................. 312 12.8 Extended Block Device Facility: XBD ......................................................................... 313 12.8.1 XBD Disk Partition Manager ........................................................................... 313 12.8.2 XBD Block Device Wrapper ............................................................................. 314 12.8.3 XBD TRFS Component ..................................................................................... 314 12.9 PCMCIA ............................................................................................................................ 315 12.10 Peripheral Component Interconnect: PCI .................................................................. 315 12.11 Network File System (NFS) Devices ........................................................................... 315 12.11.1 I/O Control Functions for NFS Clients .......................................................... 316 12.12 Non-NFS Network Devices ........................................................................................... 317 VxWorks Kernel Programmer's Guide, 6.9 xvi 12.12.1 Creating Network Devices ............................................................................... 318 12.12.2 I/O Control Functions ...................................................................................... 318 12.13 Sockets ............................................................................................................................... 318 12.14 Internal I/O System Structure ....................................................................................... 319 12.14.1 Drivers ................................................................................................................ 321 The Driver Table and Installing Drivers ........................................................ 322 Example of Installing a Driver ........................................................................ 322 12.14.2 Devices ................................................................................................................ 323 The Device List and Adding Devices ............................................................. 323 Example of Adding Devices ............................................................................ 324 Deleting Devices ................................................................................................ 324 12.14.3 File Descriptors .................................................................................................. 327 File Descriptor Table ......................................................................................... 327 Example of Opening a File ............................................................................... 327 Example of Reading Data from the File ......................................................... 330 Example of Closing a File ................................................................................. 331 Implementing select( ) ...................................................................................... 331 Cache Coherency ............................................................................................... 334 13 Local File Systems ..................................................................................... 339 13.1 Introduction ...................................................................................................................... 339 13.2 File System Monitor ...................................................................................................... 341 Device Insertion Events .................................................................................... 342 XBD Name Mapping Facility .......................................................................... 343 13.3 Virtual Root File System: VRFS ................................................................................... 343 13.4 Highly Reliable File System: HRFS ............................................................................ 345 13.4.1 Configuring VxWorks for HRFS ..................................................................... 345 13.4.2 Configuring HRFS ............................................................................................ 346 13.4.3 Creating an HRFS File System ....................................................................... 347 Overview of HRFS File System Creation ....................................................... 347 HRFS File System Creation Steps ................................................................... 347 13.4.4 HRFS, ATA, and RAM Disk Examples .......................................................... 348 13.4.5 Optimizing HRFS Performance ...................................................................... 353 13.4.6 Transactional Operations and Commit Policies ......................................... 353 Automatic Commit Policy ............................................................................... 353 High-Speed Commit Policy ............................................................................. 354 Mandatory Commits ......................................................................................... 354 Rollbacks ............................................................................................................. 354 Programmatically Initiating Commits ........................................................... 354 13.4.7 File Access Time Stamps .................................................................................. 355 Contents xvii 13.4.8 Maximum Number of Files and Directories ................................................. 355 13.4.9 Working with Directories ................................................................................. 355 Creating Subdirectories .................................................................................... 355 Removing Subdirectories ................................................................................. 356 Reading Directory Entries ................................................................................ 356 13.4.10 Working with Files ............................................................................................ 356 File I/O Routines ............................................................................................... 356 File Linking and Unlinking ............................................................................. 356 File Permissions ................................................................................................. 357 13.4.11 I/O Control Functions Supported by HRFS ................................................. 357 13.4.12 Crash Recovery and Volume Consistency ..................................................... 358 Crash Recovery .................................................................................................. 358 Consistency Checking ...................................................................................... 358 13.4.13 File Management and Full Devices ................................................................ 358 13.5 MS-DOS-Compatible File System: dosFs .................................................................. 359 13.5.1 Configuring VxWorks for dosFs ..................................................................... 360 13.5.2 Configuring dosFs ............................................................................................ 361 13.5.3 Creating a dosFs File System ........................................................................... 362 Overview of dosFs File System Creation ....................................................... 362 dosFs File System Creation Steps ................................................................... 363 13.5.4 dosFs, ATA Disk, and RAM Disk Examples ................................................. 365 13.5.5 Optimizing dosFs Performance ...................................................................... 369 13.5.6 Working with Volumes and Disks .................................................................. 370 Accessing Volume Configuration Information ............................................. 370 Synchronizing Volumes .................................................................................... 370 13.5.7 Working with Directories ................................................................................. 370 Creating Subdirectories .................................................................................... 370 Removing Subdirectories ................................................................................. 371 Reading Directory Entries ................................................................................ 371 13.5.8 Working with Files ............................................................................................ 371 File I/O Routines ............................................................................................... 371 File Attributes .................................................................................................... 371 13.5.9 Disk Space Allocation Options ........................................................................ 373 Choosing an Allocation Method ..................................................................... 374 Using Cluster Group Allocation ..................................................................... 374 Using Absolutely Contiguous Allocation ...................................................... 374 13.5.10 Crash Recovery and Volume Consistency ..................................................... 376 13.5.11 I/O Control Functions Supported by dosFsLib ............................................ 376 13.5.12 Booting from a Local dosFs File System Using SCSI ................................... 378 13.6 Transaction-Based Reliable File System Support for dosFs: TRFS ....................... 380 VxWorks Kernel Programmer's Guide, 6.9 xviii 13.6.1 Configuring VxWorks With TRFS ................................................................... 380 13.6.2 Automatic Instantiation of TRFS .................................................................... 380 13.6.3 Formatting a Device for TRFS ......................................................................... 381 13.6.4 Using TRFS in Applications ............................................................................ 382 TRFS Code Examples ....................................................................................... 382 13.7 Raw File System: rawFs ................................................................................................. 383 13.7.1 Configuring VxWorks for rawFs ..................................................................... 383 13.7.2 Creating a rawFs File System .......................................................................... 383 13.7.3 Mounting rawFs Volumes ................................................................................ 384 13.7.4 rawFs File I/O ................................................................................................... 385 13.7.5 I/O Control Functions Supported by rawFsLib ........................................... 385 13.8 CD-ROM File System: cdromFs ................................................................................... 386 13.8.1 Configuring VxWorks for cdromFs ................................................................ 387 13.8.2 Creating and Using cdromFs ........................................................................... 387 13.8.3 I/O Control Functions Supported by cdromFsLib ...................................... 389 13.8.4 Version Numbers ............................................................................................... 390 13.9 Read-Only Memory File System: ROMFS ................................................................. 390 13.9.1 Configuring VxWorks with ROMFS ............................................................... 391 13.9.2 Adding a ROMFS Directory and File Content to VxWorks ........................ 391 13.9.3 Accessing Files in ROMFS ............................................................................... 392 13.9.4 Using ROMFS to Start Applications Automatically .................................... 392 13.10 Target Server File System: TSFS ................................................................................... 392 Socket Support ................................................................................................... 393 Error Handling .................................................................................................. 394 Configuring VxWorks for TSFS Use ............................................................... 394 Security Considerations ................................................................................... 394 Using the TSFS to Boot a Target ...................................................................... 395 14 Flash File System Support: TrueFFS ........................................................ 397 14.1 Introduction ...................................................................................................................... 397 14.2 Overview of Implementation Steps ............................................................................ 398 14.3 Creating a VxWorks System with TrueFFS ................................................................ 400 14.3.1 Selecting an MTD .............................................................................................. 400 14.3.2 Identifying the Socket Driver .......................................................................... 400 14.3.3 Configuring VxWorks with TrueFFS and File System ................................. 401 Including the Core TrueFFS Component ....................................................... 401 Including the MTD Component ...................................................................... 402 Contents xix Including the Translation Layer Component ................................................ 402 Including the Socket Driver ............................................................................. 403 Including the XBD Wrapper Component ...................................................... 403 Including File System Components ............................................................... 403 Including Utility Components ........................................................................ 403 14.3.4 Building the System .......................................................................................... 404 14.3.5 Formatting the Flash ......................................................................................... 404 Formatting With sysTffsFormat( ) .................................................................. 404 Formatting With tffsDevFormat( ) .................................................................. 405 14.3.6 Reserving a Region in Flash for a Boot Image .............................................. 406 Reserving a Fallow Region .............................................................................. 407 Writing the Boot Image to Flash ...................................................................... 408 14.3.7 Mounting the Drive .......................................................................................... 409 14.3.8 Creating a File System ...................................................................................... 409 14.3.9 Testing the Drive ............................................................................................... 410 14.4 Using TrueFFS Shell Commands ................................................................................. 410 14.5 Using TrueFFS With HRFS ............................................................................................
Version 1.7 ----------- - ADD: Delphi/CBuilder 10.2 Tokyo now supported. - ADD: Delphi/CBuilder 10.1 Berlin now supported. - ADD: Delphi/CBuilder 10 Seattle now supported. - ADD: Delphi/CBuilder XE8 now supported. - ADD: Delphi/CBuilder XE7 now supported. - ADD: Delphi/CBuilder XE6 now supported. - ADD: Delphi/CBuilder XE5 now supported. - ADD: Delphi/CBuilder XE4 now supported. - ADD: Delphi/CBuilder XE3 now supported. - ADD: Delphi/CBuilder XE2 now supported. - ADD: Delphi/CBuilder XE now supported. - ADD: Delphi/CBuilder 2010 now supported. - ADD: Delphi/CBuilder 2009 now supported. - ADD: New demo project FlexCADImport. - FIX: The height of the TFlexRegularPolygon object incorrectly changes with its rotation. - FIX: Added division by zero protect in method TFlexControl.MovePathSegment. - FIX: The background beyond docuemnt wasn't filled when TFlexPanel.DocClipping=True. - FIX: In "Windows ClearType" font rendering mode (OS Windows mode) the "garbage" pixels can appear from the right and from the bottom sides of the painted rectangle of the TFlexText object. - FIX: The result rectangle incorrectly calculated in the TFlexText.GetRefreshRect method. - FIX: Added FPaintCache.rcPaint cleanup in the TFlexPanel.WMPaint method. Now it is possible to define is the drawing take place via WMPaint or via the PaintTo direct call (if rcPaint contain non-empty rectangle then WMPaint in progress). - FIX: The TFlexPanel.FPaintCache field moved in the protected class section. Added rcPaint field in FPaintCache that represents drawing rectangle. - ADD: In the text prcise mode (TFlexText.Precise=True) takes into account the rotation angle (TFlexText.Angle). - FIX: Removed FG_NEWTEXTROTATE directive (the TFlexText Precise mode should be used instead). - FIX: The TFlexRegularPolygon object clones incorrectly drawed in case when TFlexRegularPolygon have alternative brush (gradient, texture). - ADD: Add TFlexPanel.InvalidateControl virtual method which calls from TFle
Contents About the Author...............................................................................................xix About the Technical Reviewer and Contributing Author.................xxi Chapter1 Apache and the Internet..............................................1 Apache: The Anatomy of a Web Server.........................................................1 The Apache Source .............................................................................................1 The Apache License............................................................................................1 Support for Apache.............................................................................................2 How Apache Works..............................................................................................3 The Hypertext Transfer Protocol..................................................................7 HTTP Requests and Responses..........................................................................7 HTTP Headers...................................................................................................12 Networking and TCP/IP......................................................................................13 Definitions.........................................................................................................13 Packets and Encapsulation...............................................................................14 ACKs, NAKs, and Other Messages....................................................................15 The TCP/IP Network Model.............................................................................16 Non-IP Protocols...............................................................................................19 IP Addresses and Network Classes...................................................................19 Special IP Addresses..........................................................................................20 Netmasks and Routing......................................................................................21 Web Services: Well-Known Ports......................................................................23 Internet Daemon: The Networking Super Server...........................................24 The Future: IPv6................................................................................................25 Networking Tools...............................................................................................26 Server Hardware...................................................................................................29 Supported Platforms.........................................................................................29 Basic Server Requirements...............................................................................30 Memory..............................................................................................................31 Network Interface..............................................................................................32 Internet Connection.........................................................................................32 Hard Disk and Controller.................................................................................33 Operating System Checklist.............................................................................33 Redundancy and Backup..................................................................................34 Specific Hardware Solutions............................................................................35 Get Someone Else to Do It.............................................................................36 Summary....................................................................................................................36 v 3006_Ch00_CMP2 12/14/03 8:56 AM Page v Chapter 2 Getting Started with Apache.................................37 Installing Apache..............................................................................................38 Getting Apache..................................................................................................38 Installing Apache from Binary Distribution....................................................39 Installing Apache from Source.........................................................................41 Installing Apache from Prebuilt Packages.......................................................41 Installing Apache by Hand...............................................................................45 Upgrading Apache.............................................................................................47 Other Issues.......................................................................................................49 Basic Configuration..........................................................................................50 Decisions............................................................................................................50 Introducing the Master Configuration File.....................................................55 Other Basic Configuration Directives..............................................................56 Starting, Stopping, and Restarting the Server.................................57 Starting Apache on Unix...................................................................................58 Starting Apache on Windows...........................................................................59 Invocation Options...........................................................................................60 Restarting the Server.........................................................................................73 Stopping the Server...........................................................................................75 Starting the Server Automatically....................................................................76 Testing the Server............................................................................................81 Testing with a Browser......................................................................................82 Testing from the Command Line or a Terminal Program..............................82 Testing the Server Configuration Without Starting It.....................................85 Getting the Server Status from the Command Line.......................................86 Using Graphical Configuration Tools.......................................................86 Comanche..........................................................................................................87 TkApache...........................................................................................................91 LinuxConf..........................................................................................................91 Webmin..............................................................................................................91 ApacheConf.......................................................................................................97 Other Configuration Tools................................................................................99 Summary..................................................................................................................100 Chapter 3 Building Apache the Way You Want It...........101 Why Build Apache Yourself?.........................................................................101 Verifying the Apache Source Archive.............................................................103 Building Apache from Source......................................................................105 Configuring and Building Apache.................................................................106 Determining Which Modules to Include.......................................................111 Building Apache As a Dynamic Server..........................................................116 Contents vi 3006_Ch00_CMP2 12/14/03 8:56 AM Page vi Changing the Module Order (Apache 1.3)....................................................118 Checking the Generated Configuration........................................................120 Building Apache from Source As an RPM (Apache 2)..................................122 Advanced Configuration.................................................................................124 Configuring Apache’s Layout..........................................................................124 Choosing a Layout Scheme............................................................................124 Choosing a Multiprocessing Module (Apache 2)..........................................132 Rules (Apache 1.3)...........................................................................................135 Building Apache with suExec support...........................................................137 Configuring Apache’s Supporting Files and Scripts.....................................139 Configuring Apache 2 for Cross-Platform Builds.........................................140 Configuring Apache for Production or Debug Builds..................................142 Configuring Apache for Binary Distribution.................................................143 Configuring Apache’s Library and Include Paths..........................................143 Configuring the Build Environment.........................................................144 Building Modules with configure and apxs..........................................146 Adding Third-Party Modules with configure................................................146 Building Modules with apxs...........................................................................148 Installing Modules with apxs..........................................................................150 Generating Module Templates with apxs......................................................151 Overriding apxs Defaults and Using apxs in makefiles................................152 Summary..................................................................................................................153 Chapter 4 Configuring Apache the Way You Want It...155 Where Apache Looks for Its Configuration..........................................155 Configuration File Syntax...............................................................................156 Configuration for Virtual Hosts......................................................................156 Including Multiple Configuration Files.........................................................157 Per-Directory Configuration..........................................................................159 Conditional Configuration.............................................................................160 How Apache Structures Its Configuration............................................163 Apache’s Container Directives........................................................................164 Directive Types and Locations.......................................................................168 Where Directives Can Go................................................................................171 Container Scope and Nesting.........................................................................172 How Apache Combines Containers and Their Contents.............................174 Legality of Directives in Containers...............................................................175 Options and Overrides....................................................................................176 Enabling and Disabling Features with Options............................................176 Overriding Directives with Per-Directory Configuration.............................179 Contents vii 3006_Ch00_CMP2 12/14/03 8:56 AM Page vii Restricting Access with allow and deny..............................................182 Controlling Access by Name...........................................................................183 Controlling Access by IP Address...................................................................184 Controlling Subnet Access by Network and Netmask..................................185 Controlling Access by HTTP Header.............................................................186 Combining Host-Based Access with User Authentication...........................187 Overriding Host-Based Access.......................................................................188 Directory Listings..........................................................................................188 Enabling and Disabling Directory Indices....................................................189 How mod_autoindex Generates the HTML Page.........................................190 Controlling Which Files Are Seen with IndexIgnore.....................................196 Controlling the Sort Order..............................................................................197 Assigning Icons................................................................................................199 Assigning Descriptions...................................................................................202 Apache’s Environment......................................................................................203 Setting, Unsetting, and Passing Variables from the Shell.............................204 Setting Variables Conditionally......................................................................205 Special Browser Variables...............................................................................207 Detecting Robots with BrowserMatch...........................................................209 Passing Variables to CGI.................................................................................209 Conditional Access Control............................................................................210 Caveats with SetEnvIf vs. SetEnv....................................................................210 Setting Variables with mod_rewrite...............................................................211 Controlling Request and Response Headers..........................................211 Setting Custom Response Headers................................................................213 Setting Custom Request Headers...................................................................215 Inserting Dynamic Values into Headers........................................................216 Setting Custom Headers Conditionally.........................................................217 Retrieving Response Headers from Metadata Files......................................217 Setting Expiry Times.......................................................................................219 Sending Content As-Is....................................................................................222 Controlling the Server Identification Header.................................223 Sending a Content Digest.............................................................................224 Handling the Neighbors.................................................................................225 Controlling Robots with robots.txt................................................................226 Controlling Robots in HTML..........................................................................227 Controlling Robots with Access Control........................................................227 Attracting Robots.............................................................................................228 Making Sure Robots Index the Right Information........................................228 Known Robots, Bad Robots, and Further Reading.......................................229 Summary..................................................................................................................229 Contents viii 3006_Ch00_CMP2 12/14/03 8:56 AM Page viii Chapter 5 Deciding What the Client Needs........................231 Content Handling and Negotiation...........................................................231 File Types.........................................................................................................232 File Encoding...................................................................................................236 File Languages.................................................................................................243 File Character Sets...........................................................................................245 Handling URLs with Extra Path Information................................................247 Content Negotiation.......................................................................................248 Content Negotiation with MultiViews...........................................................250 File Permutations and Valid URLs with MultiViews.....................................256 Magic MIME Types..........................................................................................260 Error and Response Handling......................................................................264 How Apache Handles Errors...........................................................................265 Error and Response Codes.............................................................................265 The ErrorDocument Directive.......................................................................266 Limitations of ErrorDocument......................................................................270 Aliases and Redirection...............................................................................271 Aliases and Script Aliases................................................................................271 Redirections.....................................................................................................273 Rewriting URLs with mod_rewrite.................................................................277 Server-Side Image Maps.................................................................................300 Matching Misspelled URLS............................................................................305 Summary..................................................................................................................306 Chapter 6 Delivering Dynamic Content..................................307 Server-Side Includes......................................................................................308 Enabling SSI.....................................................................................................309 Format of SSI Commands...............................................................................311 The SSI Command Set....................................................................................312 SSI Variables.....................................................................................................312 Passing Trailing Path Information to SSIs (and Other Dynamic Documents).................................................................315 Setting the Date and Error Format.................................................................316 Templating with SSIs.......................................................................................317 Caching Server-Parsed Documents...............................................................319 Identifying Server-Parsed Documents by Execute Permission...................320 CGI: The Common Gateway Interface.........................................................321 CGI and the Environment..............................................................................321 Configuring Apache to Recognize CGI Scripts.............................................323 Setting Up a CGI Directory with ExecCGI: A Simple Way............................327 Triggering CGI Scripts on Events...................................................................330 Contents ix 3006_Ch00_CMP2 12/14/03 8:56 AM Page ix ISINDEX-Style CGI Scripts and Command Line Arguments................332 Writing and Debugging CGI Scripts.........................................................333 A Minimal CGI Script......................................................................................333 Interactive Scripts: A Simple Form................................................................337 Adding Headers...............................................................................................338 Debugging CGI Scripts....................................................................................339 Setting the CGI Daemon Socket.....................................................................345 Limiting CGI Resource Usage.........................................................................346 Actions, Handlers, and Filters................................................................347 Handlers...........................................................................................................348 Filters................................................................................................................354 Dynamic Content and Security....................................................................363 CGI Security Issues..........................................................................................363 Security Advice on the Web............................................................................364 Security Issues with Apache CGI Configuration...........................................364 An Example of an Insecure CGI Script..........................................................365 Known Insecure CGI Scripts...........................................................................370 CGI Wrappers...................................................................................................370 Security Checklist............................................................................................380 Inventing a Better CGI Script with FastCGI......................................381 Summary..................................................................................................................403 Chapter 7 Hosting More Than One Web Site........................405 Implementing User Directories with UserDir......................................406 Enabling and Disabling Specific Users..........................................................407 Redirecting Users to Other Servers................................................................408 Alternative Ways to Implement User Directories.........................................409 Separate Servers..............................................................................................410 Restricting Apache’s Field of View..................................................................411 Specifying Different Configurations and Server Roots................................412 Starting Separate Servers from the Same Configuration.............................412 Sharing External Configuration Files.............................................................413 IP-Based Virtual Hosting.............................................................................414 Multiple IPs, Separate Networks, and Virtual Interfaces..............................415 Configuring What Apache Listens To.............................................................416 Defining IP-Based Virtual Hosts.....................................................................418 Virtual Hosts and the Server-Level Configuration........................................421 Specifying Virtual Host User Privileges..........................................................422 Excluded Directives.........................................................................................426 Default Virtual Hosts....................................................................................427 Contents x 3006_Ch00_CMP2 12/14/03 8:56 AM Page x Name-Based Virtual Hosting.........................................................................428 Defining Named Virtual Hosts.......................................................................428 Server Names and Aliases...............................................................................430 Defining a Default Host for Name-Based Virtual Hosting...........................430 Mixing IP-Based and Name-Based Hosting..................................................431 Issues Affecting Virtual Hosting...........................................................434 Log Files and File Handles..............................................................................434 Virtual Hosts and Server Security..................................................................436 Secure HTTP and Virtual Hosts......................................................................437 Handling HTTP/1.0 Clients with Name-Based Virtual Hosts......................439 Dynamic Virtual Hosting...............................................................................441 Mass Hosting with Virtual-Host Aliases........................................................441 Mapping Hostnames Dynamically with mod_rewrite.................................448 Generating On the Fly and Included Configuration Files with mod_perl..449 Summary..................................................................................................................455 Chapter 8 Improving Apache’s Performance........................457 Apache’s Performance Directives..............................................................458 Configuring MPMs: Processes and Threads..................................................459 Network and IP-Related Performance Directives.........................................470 HTTP-Related Performance Directives.........................................................472 HTTP Limit Directives....................................................................................475 Configuring Apache for Better Performance........................................477 Directives That Affect Performance...............................................................477 Additional Directives for Tuning Performance.............................................482 Benchmarking Apache’s Performance.........................................................490 Benchmarking Apache with ab......................................................................490 Benchmarking Apache with gprof.................................................................495 External Benchmarking Tools........................................................................496 Benchmarking Strategy and Pitfalls...............................................................496 A Performance Checklist...............................................................................497 Proxying................................................................................................................498 Installing and Enabling Proxy Services..........................................................498 Normal Proxy Operation.................................................................................499 Configuring Apache As a Proxy......................................................................500 URL Matching with Directory Containers....................................................502 Blocking Sites via the Proxy............................................................................504 Localizing Remote URLs and Hiding Servers from View.............................504 Relaying Requests to Remote Proxies............................................................508 Proxy Chains and the Via Header...................................................................509 Proxies and Intranets......................................................................................512 Handling Errors...............................................................................................512 Contents xi 3006_Ch00_CMP2 12/14/03 8:56 AM Page xi Timing Out Proxy Requests............................................................................514 Tunneling Other Protocols.............................................................................514 Tuning Proxy Operations................................................................................515 Squid: A High-Performance Proxy Alternative.............................................516 Caching..................................................................................................................516 Enabling Caching............................................................................................516 File-Based Caching.........................................................................................517 In-Memory Caching (Apache 2 Only)............................................................520 Coordinating Memory-Based and Disk-Based Caches................................522 General Cache Configuration.........................................................................522 Maintaining Good Relations with External Caches......................................527 Fault Tolerance and Clustering................................................................529 Backup Server via Redirected Secondary DNS.............................................530 Load Sharing with Round-Robin DNS...........................................................531 Backup Server via Floating IP Address..........................................................531 Hardware Load Balancing..............................................................................532 Clustering with Apache...................................................................................533 Other Clustering Solutions.............................................................................536 Summary..................................................................................................................537 Chapter 9 Monitoring Apache.........................................................539 Logs and Logging..............................................................................................539 Log Files and Security.....................................................................................540 The Error Log...................................................................................................540 Setting the Log Level.......................................................................................541 Logging Errors to the System Log..................................................................542 Transfer Logs...................................................................................................544 Driving Applications Through Logs...............................................................554 Log Rotation....................................................................................................556 Lies, Logs, and Statistics.........................................................................560 What You Can’t Find Out from Logs...............................................................560 Analog: A Log Analyzer...................................................................................561 Server Information..........................................................................................577 Server Status....................................................................................................578 Server Info........................................................................................................581 Securing Access to Server Information.........................................................582 User Tracking.....................................................................................................583 Alternatives to User Tracking.........................................................................584 Cookie Tracking with mod_usertrack............................................................584 URL Tracking with mod_session....................................................................589 Other Session Tracking Options.....................................................................594 Summary..................................................................................................................595 Contents xii 3006_Ch00_CMP2 12/14/03 8:56 AM Page xii Chapter 10Securing Apache..............................................................597 User Authentication........................................................................................597 Apache Authentication Modules...................................................................598 Authentication Configuration Requirements...............................................599 Using Authentication Directives in .htaccess...............................................601 Basic Authentication.......................................................................................601 Digest Authentication.....................................................................................603 Anonymous Authentication...........................................................................606 Setting Up User Information..........................................................................606 Specifying User Requirements.......................................................................614 LDAP Authentication......................................................................................617 Using Multiple Authentication Schemes.......................................................624 Combining User- and Host-Based Authentication......................................626 Securing Basic Authentication with SSL.......................................................627 SSL and Apache...................................................................................................627 Downloading OpenSSL and ModSSL............................................................628 Building and Installing the OpenSSL Library...............................................629 Building and Installing mod_ssl for Apache 2..............................................633 Building and Installing mod_ssl for Apache 1.3...........................................633 Basic SSL Configuration.................................................................................637 Installing a Private Key....................................................................................639 Creating a Certificate Signing Request and Temporary Certificate.............640 Getting a Signed Certificate............................................................................642 Advanced SSL Configuration.........................................................................644 Server-Level Configuration............................................................................644 Client Certification..........................................................................................657 Using Client Certification with User Authentication..................659 SSL and Logging..............................................................................................660 SSL Environment Variables and CGI.............................................................662 SSL and Virtual Hosts......................................................................................666 Advanced Features..........................................................................................668 Summary..................................................................................................................671 Chapter 11Improving Web Server Security..........................673 Apache Features.................................................................................................673 Unwanted Files................................................................................................674 Automatic Directory Indices..........................................................................674 Symbolic Links................................................................................................675 Server-Side Includes.......................................................................................676 ISINDEX-Style CGI Scripts.............................................................................677 Server Tokens...................................................................................................677 Contents xiii 3006_Ch00_CMP2 12/14/03 8:56 AM Page xiii File Permissions..............................................................................................678 Viewing Server Information with mod_info..........................................679 Restricting Server Privileges..................................................................679 Restricting Access by Hostname and IP Address...............................680 Other Server Security Measures................................................................682 Dedicated Server..............................................................................................682 File Integrity...................................................................................................683 md5sum...........................................................................................................684 Tripwire............................................................................................................685 Hardening the Server......................................................................................686 Minimizing Services........................................................................................686 Port Scanning with nmap ..............................................................................688 Probing with Nessus.......................................................................................689 Hardening Windows 2000 and XP..................................................................689 Disabling Network Services.........................................................................690 File Transfer Protocol (FTP)............................................................................690 telnet................................................................................................................690 rlogin, rsh, rexec, rcp.......................................................................................690 Network Filesystem (NFS)..............................................................................690 sendmail/Other Mail Transport Agents (MTAs)...........................................691 Restricting Services with TCP Wrappers........................................................691 Security Fixes, Alerts, and Online Resources.................................693 The WWW Security FAQ..................................................................................693 The BugTraQ Mailing List and Archive..........................................................693 Operating System Newsletters.......................................................................693 Package and Module Notification..................................................................694 Removing Important Data from the Server............................................694 Enabling Secure Logins with SSH..............................................................694 Building and Installing OpenSSH..................................................................695 Authentication Strategies...............................................................................698 Configuring SSH..............................................................................................699 Testing SSH......................................................................................................702 Expanding SSH to Authenticate Users..........................................................703 Secure Server Backups with Rsync and SSH.................................................704 Forwarding Client Connections to Server Applications...............................705 Firewalls and Multifacing Servers.........................................................706 Types of Firewall..............................................................................................706 Designing the Network Topology...................................................................707 Running Apache Under a Virtual chroot Root Directory................709 What chroot Is.................................................................................................709 What chroot Isn’t.............................................................................................710 Setting Up Apache for chroot Operation.......................................................711 Contents xiv 3006_Ch00_CMP2 12/14/03 8:56 AM Page xiv Server Security Checklist...........................................................................723 Avoid Root Services.........................................................................................723 Maintain Logs Properly..................................................................................723 Keep It Simple..................................................................................................724 Block Abusive Clients......................................................................................724 Have an Effective Backup and Restore Process............................................725 Plan for High Availability, Capacity, and Disaster Recovery........................725 Monitor the Server..........................................................................................725 Take Care with Information Flow...................................................................726 Choose an Effective robots.txt Policy............................................................726 Summary..................................................................................................................726 Chapter 12Extending Apache............................................................727 WebDAV....................................................................................................................727 Adding WebDAV to Apache.............................................................................728 The WebDAV Protocol.....................................................................................729 Configuring Apache for WebDAV...................................................................731 Restricting Options and Disabling Overrides...............................................734 WebDAV and Virtual Hosts.............................................................................735 Configuring the DAV Lock Time.....................................................................735 Limitations of File-Based Repositories..........................................................736 Protecting WebDAV Servers............................................................................737 More Advanced Configurations.....................................................................737 Cooperating with CGI and Other Content Handlers....................................740 ISAPI......................................................................................................................741 Supported ISAPI Support Functions.............................................................742 Configuring ISAPI Extensions........................................................................743 Setting the Maximum Initial Request Data Size...........................................744 Logging ISAPI Extensions...............................................................................745 Preloading and Caching ISAPI Extensions....................................................746 Handling Asynchronous ISAPI Extensions...................................................746 Perl.........................................................................................................................746 Building and Installing mod_perl..................................................................748 Migrating mod_perl from Apache 1.3 to Apache 2.......................................755 Configuring and Implementing Perl Handlers.............................................758 Configuring and Implementing Perl Filters..................................................771 Warnings, Taint Mode, and Debugging.........................................................772 Managing Perl Threads in mod_perl 2...........................................................774 Initializing Modules at Startup.......................................................................779 Restarting mod_perl and Auto-Reloading Modules.....................................780 Creating a mod_perl Status Page...................................................................782 Running CGI Scripts Under mod_perl..........................................................782 Contents xv 3006_Ch00_CMP2 12/14/03 8:56 AM Page xv CGI Caveats......................................................................................................785 Passing Variables to Perl Handlers.................................................................787 Using mod_perl with Server-Side Includes...................................................788 Embedding Perl in HTML...............................................................................789 Embedding Perl in Apache’s Configuration..................................................794 PHP...........................................................................................................................795 Installing PHP..................................................................................................796 Getting the PHP source...................................................................................796 Configuring Apache to Work with PHP..........................................................802 Configuring PHP.............................................................................................803 Testing PHP with Apache................................................................................807 Tomcat/Java.........................................................................................................807 So What Is Tomcat?..........................................................................................807 Installation.......................................................................................................808 Tomcat Configuration.....................................................................................813 mod_jk.............................................................................................................818 Mod_python....................................................................................................829 mod_ruby.........................................................................................................835 Summary..................................................................................................................839 Index....................................................................................................................843

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值