Skip to content

Commit 5bbf214

Browse files
committed
mem: report DPMI memory
Show total, used and free DPMI memory and the largest free DPMI block (int 31h AX=0500h), as separate lines under EMS rather than as a row of the table: depending on the host, DPMI memory is either taken from XMS or is a pool of its own, so adding it to the totals could count it twice. Fields the host reports as -1 are skipped. This makes memory held by the shell itself visible: under dosemu2 the stub's DPMI loader keeps a 16Mb heap for the whole session, which shows up as ~19Mb used before any program is run. Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b1a78a7 commit 5bbf214

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

‎src/mem.c‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,25 @@ static void print_kb_and_bytes(const char *label, uint32_t kb, uint32_t bytes)
191191
print_line(buf);
192192
}
193193

194+
/* DPMI fn 0500h fills fields the host can't tell with -1 */
195+
#define DPMI_UNKNOWN 0xFFFFFFFFu
196+
#define DPMI_PAGE_KB 4
197+
198+
static void print_dpmi_pages(const char *label, uint32_t pages)
199+
{
200+
char kb_str[24], buf[160];
201+
202+
/* past 4GB the byte count no longer fits, so give KB alone */
203+
if (pages < 0x100000)
204+
{
205+
print_kb_and_bytes(label, pages * DPMI_PAGE_KB, pages * 4096);
206+
return;
207+
}
208+
format_kb(pages * DPMI_PAGE_KB, kb_str, sizeof(kb_str));
209+
snprintf(buf, sizeof(buf), "%-36s%8s", label, kb_str);
210+
print_line(buf);
211+
}
212+
194213
struct psp_name {
195214
uint16_t psp;
196215
char name[9];
@@ -951,6 +970,43 @@ void perform_mem(const char *arg)
951970
print_line("");
952971
}
953972

973+
/*
974+
* We are a DPMI client ourselves, so the host is always there. Its
975+
* memory is reported apart from the table above: under some hosts it
976+
* is carved out of XMS, under others (dosemu2) it is a separate pool,
977+
* so adding it to the totals would count the same memory twice.
978+
*/
979+
__dpmi_free_mem_info dpmi_info;
980+
if (__dpmi_get_free_memory_information(&dpmi_info) == 0)
981+
{
982+
uint32_t dpmi_total = dpmi_info.total_number_of_physical_pages;
983+
uint32_t dpmi_free = dpmi_info.total_number_of_free_pages;
984+
uint32_t dpmi_largest = dpmi_info.largest_available_free_block_in_bytes;
985+
int shown = 0;
986+
987+
if (dpmi_total != DPMI_UNKNOWN)
988+
{
989+
print_dpmi_pages("Total DPMI memory", dpmi_total);
990+
shown = 1;
991+
}
992+
if (dpmi_total != DPMI_UNKNOWN && dpmi_free != DPMI_UNKNOWN &&
993+
dpmi_free <= dpmi_total)
994+
print_dpmi_pages("Used DPMI memory", dpmi_total - dpmi_free);
995+
if (dpmi_free != DPMI_UNKNOWN)
996+
{
997+
print_dpmi_pages("Free DPMI memory", dpmi_free);
998+
shown = 1;
999+
}
1000+
if (dpmi_largest != DPMI_UNKNOWN)
1001+
{
1002+
print_kb_and_bytes("Largest free DPMI block",
1003+
dpmi_largest / 1024, dpmi_largest);
1004+
shown = 1;
1005+
}
1006+
if (shown)
1007+
print_line("");
1008+
}
1009+
9541010
print_kb_and_bytes("Largest executable program size",
9551011
paras_to_kb(conv_largest_paras), conv_largest_paras * 16);
9561012
print_kb_and_bytes("Largest available upper memory block",

0 commit comments

Comments
 (0)