用户进程的有效地址空间是多少? (OS X和Linux) [英] What is the valid address space for a user process? (OS X and Linux)

查看:238
本文介绍了用户进程的有效地址空间是多少? (OS X和Linux)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

mmap系统调用文档说,如果出现以下情况,该功能将失败:

The mmap system call documentation says that the function will fail if:

已指定MAP_FIXED和地址 参数未对齐页面或部分 所需的地址空间驻留 超出有效地址空间 用户进程.

MAP_FIXED was specified and the addr argument was not page aligned, or part of the desired address space resides out of the valid address space for a user process.

我找不到任何地方的文档说明什么是要映射的有效地址. (我对在OS X和linux上执行此操作很感兴趣,理想情况下,相同的地址对两者都有效...).

I can't find documentation anywhere saying what would be a valid address to map. (I'm interested in doing this on OS X and linux, ideally the same address would be valid for both...).

推荐答案

Linux内核为其自身保留了部分虚拟地址空间,用户空间几乎(几乎)无法访问并且无法映射任何内容.您正在寻找所谓的用户空间/内核空间拆分".

Linux kernel reserves part of virtual address space for itself to where userspace have (almost) no access and can't map anything. You're looking for what's called "userspace/kernelspace split".

在i386上,默认为3G/1G-用户空间获得3GB的虚拟地址空间,内核获得1GB的虚拟地址空间,此外还有2G/2G和1G/3G分割:

On i386 arch default is 3G/1G one -- userspace gets lower 3 GB of virtual address space, kernel gets upper 1 GB, additionally there are 2G/2G and 1G/3G splits:

config PAGE_OFFSET
        hex
        default 0xB0000000 if VMSPLIT_3G_OPT
        default 0x80000000 if VMSPLIT_2G
        default 0x78000000 if VMSPLIT_2G_OPT
        default 0x40000000 if VMSPLIT_1G
        default 0xC0000000
        depends on X86_32

在x86_64上,用户空间位于(当前)48位虚拟地址空间的下半部分:

On x86_64, userspace lives in lower half of (currently) 48-bit of virtual address space:

/*
 * User space process size. 47bits minus one guard page.
 */
#define TASK_SIZE_MAX   ((1UL << 47) - PAGE_SIZE)

这篇关于用户进程的有效地址空间是多少? (OS X和Linux)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆