惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
MyScale Blog
MyScale Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
Y
Y Combinator Blog
月光博客
月光博客
IT之家
IT之家
T
Tailwind CSS Blog
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园_首页
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
博客园 - Franky
WordPress大学
WordPress大学
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
V
Visual Studio Blog
小众软件
小众软件
博客园 - 叶小钗
博客园 - 三生石上(FineUI控件)
N
Netflix TechBlog - Medium

博客园 - xwang

更好的执行 Better Communication – 你在听吗? 时间管理 or 能量管理 Stress Managment - 压力管理 Understanding WPF Template 调试Rotor: 启动过程 sscli google group launched Understanding Static Constructor, 理解静态构造函数 - xwang 自定义Rotor: 给Rotor添加一个CIL指令 Metadata Tables, 元数据表 [Coding For Fun] 您有运行许可证吗? How To: TeamBuild 编译之前的版本 How To: Team Build 自定义版本号 混淆的概念与实践 [Debugging Tool]Windbg调试托管代码 The Anatomy Of Basic Data Structure, 基本数据结构解析 Understanding GetHashCode, 理解GetHashCode 基本数据结构解析之List 试探讨泛型实现过程
PAL 阅读笔记
xwang · 2008-12-28 · via 博客园 - xwang

PAL = Platform Abstract Layer, 是.Net平台对于具体操作系统层次的依赖, 主要包括

  1. 启动和结束
  2. 文件系统
  3. 内存管理
  4. 同步 I/O
  5. 异步 I/O
  6. Threading
  7. Networking
  8. 异常处理
  9. 调试支持
  10. CRT (C Runtime Library)

1. PAL-specific Entry Points

所谓的PAL-specific Entry Points,指的是对于PAL层所自己定义的接口,例如启动,结束. 包含以下几个方法:

方法名称 解释
PAL_Initialize
  1. 成功时返回0, 失败时返回其他值, 最好提示错误信息
  2. PAL需要提供exit和ExitProcess方法
  3. CreateThread方法创建进程
PAL_Terminate
  1. 如果PAL_Initialize成功则执行PAL_Terminate
  2. 在PAL_Terminate调用完成之后,如果PAL客户端较少到0, 那则跳转到exit和ExitProcess
PAL_GetUserConfigurationDirectoryW 返回对应用户的设置数据
  • PAL_RegisterLibrary
  • PAL_UnregisterLibrary
  • 在DLLMain中注册 lib形式的dll 文件 (lpLibFileName)
    PAL_GetPALDirectoryW 得到PAL的dll运行所在目录,例如 c:\Rotor\v1.x86chk.rotor\rotor_pal.dll 返回的应该是 c:\Rotor\v1.x86chk.rotor
    PAL_Random 产生随机数. 1. lpBuffer: 用于得到随机产生的byte 2. bStrong: 用于标识是否额外强度的随机数, 例如用于Key
    PAL_get_stdout / PAL_get_stdin / PAL_get_stderr 对应系统的stdout, stdin, stderr方法
    PAL_errno 返回一个对应线程错误号的指针
    PAL_LocalHandleToRemote / PAL_RemoteHandleToLocal
  • 指向mutex(互斥体), 进程,事件的指针
  • 返回值: INVALID_HANDLE_VALUE / Handle值或者类型
  • 2. 文件系统

    以UNIX系统的PAL层为例, 大概对文件系统分为五种类型的操作

    1. 对文件的操作                             image
    2. 对目录的操作image
    3. 对于磁盘信息的读取
      PALIMPORT BOOL PALAPI GetDiskFreeSpaceW(
                LPCWSTR lpDirectoryName,
                LPDWORD lpSectorsPerCluster,
                LPDWORD lpBytesPerSector,
                LPDWORD lpNumberOfFreeClusters,  /* Caller will ignore output value */
                LPDWORD lpTotalNumberOfClusters) /* Caller will ignore output value */
    4. 查找文件image
    5. 对于路径的操作

      image

     3. 内存管理

    Local: 本地内存管理imageHeap: 基于堆的内存管理image共享内存: 所谓共享内存,是指不同进程使用同一份拷贝,例如 B程序 使用了 A.dll, 而C也是,这样B和C则有共享内存. 共享内存又包含写时拷贝,同步等部分image

    4. 同步/异步 IO

    Debug

    image

    Threading

    代码名称 作用
    Process.h 进程的操作
    Thread.h 线程的操作
    Localstorage.c string的一些基本操作,contact, copy 等等
    Seamphore.c 信号量
    mutex.c 互斥体
    event.h / event.c 事件
    critsect.c CRITICAL_SECTION
    wait.c  

    Networking

    Soket 通信机制

    image

    异步通信: Async.c

    Exception

    SEH – Structure Exceptuin Handler

    CRT (C Runtime)

    代码名称 作用
    file.c 对文件的操作, C语言中那些对文件的基本操作
    finite.h 对浮点数的支持, 无穷大,无穷小等等
    lstr string的一些基本操作,contact, copy 等等
    mbstring.c multi-bytes string
    misc.c 和运行环境之间进行交互,例如 char *MiscGetenv(const char *name)
    path.c 对路径的操作
    printf.c 对应操作系统的输出
    silent_printf.c 对应Trace输出 TODO:: Verify this
    string.c 对应string的常用操作,comare, _swab, PAL_strtoul, PAL_atol ...
    thread.c PAL_exit
    wchar.c 包含对char和string的一些操作

    后记:

    涉及到PAL层次的东西自然涉及到很多操作系统的知识,由于知识的专注性及个人精力的局限性,于是具体详细的解释暂不提供,如有兴趣和能力之同志,欢迎指教。谢谢