templeos-info/public/Wb/Home/Src/Adam/AMem.HC.HTML

211 lines
20 KiB
HTML
Executable File

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="generator" content="TempleOS V5.03">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="/style/templeos.css">
<script src="/script/templeos.js"></script>
<style type="text/css">
.cF0{color:#000000;background-color:#ffffff;}
.cF1{color:#0000aa;background-color:#ffffff;}
.cF2{color:#00aa00;background-color:#ffffff;}
.cF3{color:#00aaaa;background-color:#ffffff;}
.cF4{color:#aa0000;background-color:#ffffff;}
.cF5{color:#aa00aa;background-color:#ffffff;}
.cF6{color:#aa5500;background-color:#ffffff;}
.cF7{color:#aaaaaa;background-color:#ffffff;}
.cF8{color:#555555;background-color:#ffffff;}
.cF9{color:#5555ff;background-color:#ffffff;}
.cFA{color:#55ff55;background-color:#ffffff;}
.cFB{color:#55ffff;background-color:#ffffff;}
.cFC{color:#ff5555;background-color:#ffffff;}
.cFD{color:#ff55ff;background-color:#ffffff;}
.cFE{color:#ffff55;background-color:#ffffff;}
.cFF{color:#ffffff;background-color:#ffffff;}
</style>
</head>
<body>
<pre id="content">
<a name="l1"></a><span class=cF0>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Memory/Task&quot;</span><span class=cF0>
<a name="l2"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>TaskMemAlloced</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> override_validate=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l3"></a>{</span><span class=cF2>//Count of bytes alloced to a task, used+unused.</span><span class=cF0>
<a name="l4"></a> </span><span class=cF9>I64</span><span class=cF0> res;
<a name="l5"></a> </span><span class=cF1>if</span><span class=cF0> (!task) task=</span><span class=cF5>Fs</span><span class=cF0>;
<a name="l6"></a> </span><span class=cF1>if</span><span class=cF0> (override_validate || </span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l7"></a> res=task-&gt;code_heap-&gt;alloced_u8s;
<a name="l8"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;code_heap!=task-&gt;data_heap)
<a name="l9"></a> res+=task-&gt;data_heap-&gt;alloced_u8s;
<a name="l10"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l11"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l12"></a> </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l13"></a>}
<a name="l14"></a>
<a name="l15"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF9>I64</span><span class=cF0> </span><span class=cF5>TaskMemUsed</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> override_validate=</span><span class=cF3>FALSE</span><span class=cF0>)
<a name="l16"></a>{</span><span class=cF2>//Count of bytes alloced to a task and in use.</span><span class=cF0>
<a name="l17"></a> </span><span class=cF9>I64</span><span class=cF0> res;
<a name="l18"></a> </span><span class=cF1>if</span><span class=cF0> (!task) task=</span><span class=cF5>Fs</span><span class=cF0>;
<a name="l19"></a> </span><span class=cF1>if</span><span class=cF0> (override_validate || </span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l20"></a> res=task-&gt;code_heap-&gt;used_u8s;
<a name="l21"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;data_heap!=task-&gt;code_heap)
<a name="l22"></a> res+=task-&gt;data_heap-&gt;used_u8s;
<a name="l23"></a> </span><span class=cF1>return</span><span class=cF0> res;
<a name="l24"></a> </span><span class=cF7>}</span><span class=cF0> </span><span class=cF1>else</span><span class=cF0>
<a name="l25"></a> </span><span class=cF1>return</span><span class=cF0> 0;
<a name="l26"></a>}
<a name="l27"></a>
<a name="l28"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Memory/Task;Debugging/Heap;Memory/Debugging&quot;</span><span class=cF0>
<a name="l29"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>HeapRep</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task)
<a name="l30"></a>{</span><span class=cF2>//Report status of task's heap.</span><span class=cF0>
<a name="l31"></a> </span><span class=cF9>I64</span><span class=cF0> i,cnt;
<a name="l32"></a> </span><span class=cF9>CMemUnused</span><span class=cF0> *uum;
<a name="l33"></a>
<a name="l34"></a> </span><span class=cF1>if</span><span class=cF0> (!task || task==</span><span class=cF5>Fs</span><span class=cF0>) </span><span class=cF7>{</span><span class=cF0>
<a name="l35"></a> </span><span class=cF6>&quot;Task can't HeapRep on self.\n&quot;</span><span class=cF0>;
<a name="l36"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l37"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l38"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0>) </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l39"></a>
<a name="l40"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l41"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l42"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;task-&gt;code_heap-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l43"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l44"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;data_heap!=task-&gt;code_heap)
<a name="l45"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;task-&gt;data_heap-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l46"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l47"></a>
<a name="l48"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;</span><span class=cF3>MEM_HEAP_HASH_SIZE</span><span class=cF0>&gt;&gt;3;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l49"></a> cnt=0;
<a name="l50"></a> uum=task-&gt;code_heap-&gt;heap_hash[i];
<a name="l51"></a> </span><span class=cF1>while</span><span class=cF0> (uum) {
<a name="l52"></a> cnt+=uum-&gt;size;
<a name="l53"></a> uum=uum-&gt;next;
<a name="l54"></a> }
<a name="l55"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;data_heap!=task-&gt;code_heap) {
<a name="l56"></a> uum=task-&gt;data_heap-&gt;heap_hash[i];
<a name="l57"></a> </span><span class=cF1>while</span><span class=cF0> (uum) </span><span class=cF7>{</span><span class=cF0>
<a name="l58"></a> cnt+=uum-&gt;size;
<a name="l59"></a> uum=uum-&gt;next;
<a name="l60"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l61"></a> }
<a name="l62"></a> </span><span class=cF1>if</span><span class=cF0> (cnt)
<a name="l63"></a> </span><span class=cF6>&quot;%03X:%08X\n&quot;</span><span class=cF0>,i&lt;&lt;3,cnt;
<a name="l64"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l65"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l66"></a>
<a name="l67"></a> uum=task-&gt;code_heap-&gt;malloc_free_lst;
<a name="l68"></a> </span><span class=cF1>while</span><span class=cF0> (uum) </span><span class=cF7>{</span><span class=cF0>
<a name="l69"></a> </span><span class=cF6>&quot;%X, &quot;</span><span class=cF0>,uum-&gt;size;
<a name="l70"></a> uum=uum-&gt;next;
<a name="l71"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l72"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;data_heap!=task-&gt;code_heap) </span><span class=cF7>{</span><span class=cF0>
<a name="l73"></a> uum=task-&gt;data_heap-&gt;malloc_free_lst;
<a name="l74"></a> </span><span class=cF1>while</span><span class=cF0> (uum) {
<a name="l75"></a> </span><span class=cF6>&quot;%X, &quot;</span><span class=cF0>,uum-&gt;size;
<a name="l76"></a> uum=uum-&gt;next;
<a name="l77"></a> }
<a name="l78"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l79"></a>
<a name="l80"></a> </span><span class=cF1>if</span><span class=cF0> (task-&gt;data_heap!=task-&gt;code_heap)
<a name="l81"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;task-&gt;data_heap-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l82"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;task-&gt;code_heap-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l83"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l84"></a>
<a name="l85"></a> </span><span class=cF6>'\n'</span><span class=cF0>;
<a name="l86"></a>}
<a name="l87"></a>
<a name="l88"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Memory/HeapCtrl;Debugging/Heap;Memory/Debugging&quot;</span><span class=cF0>
<a name="l89"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsInHeapCtrl</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *a,</span><span class=cF9>CHeapCtrl</span><span class=cF0> *hc,</span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF1>lock</span><span class=cF0>=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l90"></a>{</span><span class=cF2>//Check addr if in HeapCtrl.</span><span class=cF0>
<a name="l91"></a> </span><span class=cF9>CMemBlk</span><span class=cF0> *m;
<a name="l92"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l93"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l94"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>lock</span><span class=cF0>)
<a name="l95"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l96"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l97"></a> m=hc-&gt;next_mem_blk;
<a name="l98"></a> </span><span class=cF1>while</span><span class=cF0> (m!=&amp;hc-&gt;next_mem_blk) </span><span class=cF7>{</span><span class=cF0>
<a name="l99"></a> </span><span class=cF1>if</span><span class=cF0> (a&gt;=m &amp;&amp; a&lt;m</span><span class=cF7>(</span><span class=cF1>U8</span><span class=cF0> *</span><span class=cF7>)</span><span class=cF0>+m-&gt;pags&lt;&lt;</span><span class=cF3>MEM_PAG_BITS</span><span class=cF0>) {
<a name="l100"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>lock</span><span class=cF0>)
<a name="l101"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l102"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l103"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l104"></a> }
<a name="l105"></a> m=m-&gt;next;
<a name="l106"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l107"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF1>lock</span><span class=cF0>)
<a name="l108"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l109"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l110"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l111"></a>}
<a name="l112"></a>
<a name="l113"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>HeapCtrlWalk</span><span class=cF0>(</span><span class=cF9>CHeapCtrl</span><span class=cF0> *hc)
<a name="l114"></a>{</span><span class=cF2>//Check integrity of HeapCtrl.</span><span class=cF0>
<a name="l115"></a> </span><span class=cF9>I64</span><span class=cF0> i;
<a name="l116"></a> </span><span class=cF9>CMemUnused</span><span class=cF0> *uum;
<a name="l117"></a>
<a name="l118"></a> </span><span class=cF1>PUSHFD</span><span class=cF0>
<a name="l119"></a> </span><span class=cF1>CLI</span><span class=cF0>
<a name="l120"></a> </span><span class=cF1>while</span><span class=cF0> (</span><span class=cF5>LBts</span><span class=cF7>(</span><span class=cF0>&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF7>)</span><span class=cF0>)
<a name="l121"></a> </span><span class=cF1>PAUSE</span><span class=cF0>
<a name="l122"></a>
<a name="l123"></a> </span><span class=cF1>for</span><span class=cF0> (i=0;i&lt;</span><span class=cF3>MEM_HEAP_HASH_SIZE</span><span class=cF0>&gt;&gt;3;i++) </span><span class=cF7>{</span><span class=cF0>
<a name="l124"></a> uum=hc-&gt;heap_hash[i];
<a name="l125"></a> </span><span class=cF1>while</span><span class=cF0> (uum) {
<a name="l126"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>IsInHeapCtrl</span><span class=cF7>(</span><span class=cF0>uum,hc,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l127"></a> </span><span class=cF1>goto</span><span class=cF0> hc_false;
<a name="l128"></a> uum=uum-&gt;next;
<a name="l129"></a> }
<a name="l130"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l131"></a> uum=hc-&gt;malloc_free_lst;
<a name="l132"></a> </span><span class=cF1>while</span><span class=cF0> (uum) </span><span class=cF7>{</span><span class=cF0>
<a name="l133"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>IsInHeapCtrl</span><span class=cF7>(</span><span class=cF0>uum,hc,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l134"></a> </span><span class=cF1>goto</span><span class=cF0> hc_false;
<a name="l135"></a> uum=uum-&gt;next;
<a name="l136"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l137"></a>
<a name="l138"></a> #</span><span class=cF1>if</span><span class=cF0> </span><span class=cF3>_CFG_HEAP_DBG</span><span class=cF0>
<a name="l139"></a> </span><span class=cF9>CMemUsed</span><span class=cF0> *um,*um1;
<a name="l140"></a> um1=(&amp;hc-&gt;next_um)(</span><span class=cF1>U8</span><span class=cF0> *)-</span><span class=cF1>offset</span><span class=cF0>(</span><span class=cF9>CMemUsed</span><span class=cF0>.next);
<a name="l141"></a> um=um1-&gt;next;
<a name="l142"></a> </span><span class=cF1>while</span><span class=cF0> (um!=um1) </span><span class=cF7>{</span><span class=cF0>
<a name="l143"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>IsInHeapCtrl</span><span class=cF7>(</span><span class=cF0>um,hc,</span><span class=cF3>FALSE</span><span class=cF7>)</span><span class=cF0>)
<a name="l144"></a> </span><span class=cF1>goto</span><span class=cF0> hc_false;
<a name="l145"></a> um=um-&gt;next;
<a name="l146"></a> </span><span class=cF7>}</span><span class=cF0>
<a name="l147"></a>#</span><span class=cF1>endif</span><span class=cF0>
<a name="l148"></a>
<a name="l149"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l150"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l151"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l152"></a>
<a name="l153"></a> hc_false:
<a name="l154"></a> </span><span class=cF5>LBtr</span><span class=cF0>(&amp;hc-&gt;locked_flags,</span><span class=cF3>HClf_LOCKED</span><span class=cF0>);
<a name="l155"></a> </span><span class=cF1>POPFD</span><span class=cF0>
<a name="l156"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l157"></a>}
<a name="l158"></a>
<a name="l159"></a>#</span><span class=cF1>help_index</span><span class=cF0> </span><span class=cF6>&quot;Memory/Task;Debugging/Heap;Memory/Debugging&quot;</span><span class=cF0>
<a name="l160"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>IsInHeap</span><span class=cF0>(</span><span class=cF1>U8</span><span class=cF0> *a,</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>,</span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF1>lock</span><span class=cF0>=</span><span class=cF3>TRUE</span><span class=cF0>)
<a name="l161"></a>{</span><span class=cF2>//Check addr if in task's heaps.</span><span class=cF0>
<a name="l162"></a> </span><span class=cF1>if</span><span class=cF0> (!task) task=</span><span class=cF5>Fs</span><span class=cF0>;
<a name="l163"></a> </span><span class=cF1>if</span><span class=cF0> (</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0> &amp;&amp; </span><span class=cF7>(</span><span class=cF5>IsInHeapCtrl</span><span class=cF0>(a,task-&gt;code_heap,</span><span class=cF1>lock</span><span class=cF0>)||
<a name="l164"></a> task-&gt;data_heap!=task-&gt;code_heap &amp;&amp;
<a name="l165"></a> </span><span class=cF5>IsInHeapCtrl</span><span class=cF0>(a,task-&gt;data_heap,</span><span class=cF1>lock</span><span class=cF0>)</span><span class=cF7>)</span><span class=cF0>)
<a name="l166"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l167"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l168"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l169"></a>}
<a name="l170"></a>
<a name="l171"></a></span><span class=cF1>public</span><span class=cF0> </span><span class=cF1>Bool</span><span class=cF0> </span><span class=cF5>HeapWalk</span><span class=cF0>(</span><span class=cF9>CTask</span><span class=cF0> *task=</span><span class=cF3>NULL</span><span class=cF0>)
<a name="l172"></a>{</span><span class=cF2>//Check integrity of task's heaps.</span><span class=cF0>
<a name="l173"></a> </span><span class=cF1>if</span><span class=cF0> (!task) task=</span><span class=cF5>Fs</span><span class=cF0>;
<a name="l174"></a> </span><span class=cF1>if</span><span class=cF0> (!</span><span class=cF5>TaskValidate</span><span class=cF7>(</span><span class=cF0>task</span><span class=cF7>)</span><span class=cF0> || !</span><span class=cF5>HeapCtrlWalk</span><span class=cF7>(</span><span class=cF0>task-&gt;code_heap</span><span class=cF7>)</span><span class=cF0> ||
<a name="l175"></a> task-&gt;data_heap!=task-&gt;code_heap &amp;&amp; !</span><span class=cF5>HeapCtrlWalk</span><span class=cF7>(</span><span class=cF0>task-&gt;data_heap</span><span class=cF7>)</span><span class=cF0>)
<a name="l176"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>FALSE</span><span class=cF0>;
<a name="l177"></a> </span><span class=cF1>else</span><span class=cF0>
<a name="l178"></a> </span><span class=cF1>return</span><span class=cF0> </span><span class=cF3>TRUE</span><span class=cF0>;
<a name="l179"></a>}
</span></pre></body>
</html>