File size: 4,232 Bytes
806d4b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

I64 HashEntrySize(CHashSrcSym *tmph)
{//Logical size of a std system hash entry.
  CDbgInfo *dbg_info;
  CBinFile *bfh;
  switch (HashTypeNum(tmph)) {
    case HTt_DEFINE_STR:
      return MSize(tmph(CHashDefineStr *)->data);
    case HTt_GLBL_VAR:
    case HTt_CLASS:
    case HTt_INTERNAL_TYPE:
      return tmph(CHashClass *)->size;
    case HTt_FUN:
      if (dbg_info=tmph->dbg_info)
        return dbg_info->body[dbg_info->max_line+1-dbg_info->min_line]
              -dbg_info->body[0];
      else
        return -1;
    case HTt_FILE:
      return MSize(tmph(CHashGeneric *)->user_data0);
    case HTt_MODULE:
      if (StrCmp(tmph->str,KERNEL_MODULE_NAME))
        return MSize(tmph(CHashGeneric *)->user_data0);
      else {
        bfh=mem_boot_base-sizeof(CBinFile);
        return bfh->file_size;
      }
    case HTt_WORD:
      return StrLen(tmph->str);
  }
  return -1;
}

I64 HashEntrySize2(CHashSrcSym *tmph)
{//Memory size of a std system hash entry.
  CDbgInfo *dbg_info;
  I64 res=MSize2(tmph);
  if (!(tmph->type&HTT_DICT_WORD))
    res+=MSize2(tmph->str);
  if (tmph->type & HTG_SRC_SYM) {
    res+=MSize2(tmph->src_link);
    res+=MSize2(tmph->idx);
    res+=MSize2(tmph->import_name);
    res+=LinkedLstSize(tmph->ie_lst);
    if (tmph->type & (HTT_FUN | HTT_EXPORT_SYS_SYM))
      res+=MSize2(tmph->dbg_info);
    if (tmph->type & HTT_CLASS)
      res+=MemberLstSize(tmph);
    else if (tmph->type & HTT_FUN) {
      res+=MemberLstSize(tmph);
      if (dbg_info=tmph->dbg_info)
//This should be MSize() but it would crash on AOT .BIN.Z file funs.
        res+=dbg_info->body[dbg_info->max_line+1-dbg_info->min_line]
              -dbg_info->body[0];
    } else if (tmph->type&HTT_DEFINE_STR)
      res+=MSize2(tmph(CHashDefineStr *)->data);
    else if (tmph->type & HTT_GLBL_VAR) {
      res+=LinkedLstSize(tmph(CHashGlblVar *)->dim.next);
      if (!(tmph(CHashGlblVar *)->flags&GVF_ALIAS))
        res+=MSize2(tmph(CHashGlblVar *)->data_addr);
      if (tmph(CHashGlblVar *)->fun_ptr)
        res+=HashEntrySize2(tmph(CHashGlblVar *)->fun_ptr
              -tmph(CHashGlblVar *)->fun_ptr->ptr_stars_cnt);
    }
  } else if (tmph->type & HTT_FILE)
    res+=MSize2(tmph(CHashGeneric *)->user_data0);
  else if (tmph->type & HTT_MODULE &&
        StrCmp(tmph->str,KERNEL_MODULE_NAME))
    res+=MSize2(tmph(CHashGeneric *)->user_data0);
  return res;
}

I64 HashTableSize2(CHashTable *table)
{//Memory size of std system hash table and all entries.
  I64 i,res=0;
  CHashSrcSym *tmph;
  if (!table)
    return 0;
  for (i=0;i<=table->mask;i++) {
    tmph=table->body[i];
    while (tmph) {
      res+=HashEntrySize2(tmph);
      tmph=tmph->next;
    }
  }
  res+=MSize2(table->body);
  res+=MSize2(table);
  return res;
}

U0 MapFileWrite(CHashTable *h,U8 *map_name,U8 drv_let)
{
  CHashSrcSym *tmph;
  I64 i,size;
  U8 *src_link;
  CDoc *doc;
  CDocBin *tmpb;
  CDbgInfo *dbg_info;

  doc=DocNew(map_name);
  doc->flags|=DOCF_NO_CURSOR;
  for (i=0;i<=h->mask;i++) {
    tmph=h->body[i];
    while (tmph) {
      if (tmph->src_link && !(tmph->type & (HTF_IMPORT | HTF_PRIVATE))) {
        src_link=StrNew(tmph->src_link);
        if (drv_let && StrLen(src_link)>=4)
          src_link[3]=drv_let;
        if (dbg_info=tmph->dbg_info) {
          size=offset(CDbgInfo.body)+
                sizeof(U32)*(dbg_info->max_line+2-dbg_info->min_line);
          if (size>MSize(dbg_info)) {
            "Corrupt Map Entry\n";
            dbg_info=NULL;
          } else {
            if (dbg_info->min_line<=dbg_info->max_line) {
              tmpb=CAlloc(sizeof(CDocBin));
              tmpb->size=size;
              tmpb->data=MAlloc(size);
              MemCpy(tmpb->data,dbg_info,size);
              tmpb->num=doc->cur_bin_num++;
              tmpb->use_cnt=1;
              QueIns(tmpb,doc->bin_head.last);
            } else
              dbg_info=NULL;
          }
        }
        if (dbg_info)
          DocPrint(doc,"$LK,\"%s\",A=\"%s\",BI=%d$\n",
                tmph->str,src_link,tmpb->num);
        else
          DocPrint(doc,"$LK,\"%s\",A=\"%s\"$\n",tmph->str,src_link);

        Free(src_link);
      }
      tmph=tmph->next;
    }
  }
  DocBinsValidate(doc);
  DocWrite(doc);
  DocDel(doc);
}