• address_space 从哪里来


    address_space 从哪里来

    这两天想弄清楚linux的内存分配,忽然看到了address_space,就想弄明白。
    整个内核就见到 address_space(1)和address_space(2)在这个文件里出现。
    include/linux/compiler.h:
    # define __user __attribute__((noderef, address_space(1)))
    # define __iomem __attribute__((noderef, address_space(2)))
    不过在新内核2.6.36中出现新的了
    2.6.36.3/include/linux/compiler.h
    # define __user         __attribute__((noderef, address_space(1)))
    # define __kernel       __attribute__((address_space(0)))
    # define __iomem        __attribute__((noderef, address_space(2)))
    # define __percpu       __attribute__((noderef, address_space(3)))
     
    探索
    -------------------------------------
    在参考1中说,addres_space(v) 
    v:1 gcc中的定义是用户空间;
    v:2  gcc中的定义是io存储空间(或许io寄存器空间更合适吧)。
    作者还猜测了 v为0时内核空间。在2.6.36.3 中验证了作者的猜测。 作为发挥,就把后来的添加注释
    address_space(v)
    -------------------------------------
    v: 0 内核空间
    v: 1 用户空间
    v: 2 io存储空间
    v: 3 cpu空间(我感到这有点生搬硬套)
    是这样吗?从哪里可以验证?
     
    文章中还提到是gcc调用sparse分析的。应该看看sparse中的定义。
    sparse 源码(http://codemonkey.org.uk/projects/git-snapshots/sparse/)
     
    搜索代码
    一处:
    1. address_space
    2.     -------------------------------------
    3.     ->ident-list.h
    4.     IDENT(address_space);
    5.     
    6.     -->
    7.     #define IDENT(n) __IDENT(n## _ident, #n, 0)
    8.     =====================================
     
    在这个文件的上下文中可以确定address_space是关键字
     
    另一处
    1. address_space
    2.     -------------------------------------
    3.     ->parse.c
    4.     static struct init_keyword {
    5.         const char *name;
    6.         enum namespace ns;
    7.         unsigned long modifiers;
    8.         struct symbol_op *op;
    9.         struct symbol *type;
    10.     } keyword_table[] = {
    11.     /* .... */
    12.     { "address_space",NS_KEYWORD, .op = &address_space_op },
    13.     /* ... */
    14.     };
    15.     这是关键字,有什么操作呢?关注symbol_op结构的address_space_op:
    16.     =====================================
    17.     
    18.     address_space_op
    19.     -------------------------------------
    20.     -->parse.c
    21.     static struct symbol_op address_space_op = {
    22.             .attribute = attribute_address_space,
    23.     };
    24.     =====================================
    25.     
    26.     attribute_address_space
    27.     -------------------------------------
    28.     --->parse.c
    29.      static attr_t attribute_address_space ;
    30.     
    31.     struct symbol_op
    32.     -------------------------------------
    33.     --->symbol.h
    34.     struct symbol_op {
    35.         /* ..... */
    36.         /* keywords */
    37.         struct token *(*attribute)(struct token *token,
    38.                 struct symbol *attr, struct decl_state *ctx);
    39.         /* ..... */
    40.         };
    41.     =====================================
    42.     
    43.     attr_t
    44.     -------------------------------------
    45.     ---->parse.c
    46.     typedef struct token *attr_t(struct token *,
    47.                 struct symbol *, struct decl_state *);
    48.     
    49.     attribute_address_space
    50.     -------------------------------------
    51.     ---->parse.c
    52.     static struct token *
    53.     attribute_address_space(struct token *token,
    54.             struct symbol *attr, struct decl_state *ctx)
    55.     {
    56.         struct expression *expr = NULL;
    57.         int as;
    58.         token = expect(token, '(', "after address_space attribute");
    59.         token = conditional_expression(token, &expr);
    60.         if (expr) {
    61.                 as = const_expression_value(expr);
    62.                 if (Waddress_space && as)
    63.                         ctx->ctype.as = as;
    64.         }
    65.         token = expect(token, ')', "after address_space attribute");
    66.         return token;
    67.     }
    68.     =====================================
     
    疑问
    -------------------------------------
    再往下追踪,也没有结果,希望得到高人指点。疑问是:
    * 怎么和内核空间(3G-4G)、用户空间(低于3G)相联系起来?
    * 里面的address_space(v) (v=0,1,2,3,...)怎么起作用的?
  • 相关阅读:
    谁是你随时可以说话的人
    我们在帝都这么拼,为的是什么?
    CVE-2016-4758: UXSS in Safari's showModalDialog
    JSON-SCHEMA
    JS城市data
    linux(centos )mongodb install
    python pip install
    基于chrome内核的UXSS
    Trying to hack Redis via HTTP requests
    Apache Solr 访问权限控制
  • 原文地址:https://www.cnblogs.com/timssd/p/4781095.html
Copyright © 2020-2023  润新知