Commit 5f7c30e7 authored by Eli Zaretskii's avatar Eli Zaretskii

Implement memory-info for MS-DOS.

 src/dosfns.c (dos_memory_info): New function.
 src/dosfns.h (dos_memory_info): Add prototype.
 src/alloc.c (Fmemory_info) [MSDOS]: Call dos_memory_info.
 src/vm-limit.c (get_lim_data) [MSDOS]: Call dos_memory_info, instead
 of doing some of its job.
parent 8f4fc468
2014-07-11 Eli Zaretskii <eliz@gnu.org>
Implement memory-info for MS-DOS.
* dosfns.c (dos_memory_info): New function.
* dosfns.h (dos_memory_info): Add prototype.
* alloc.c (Fmemory_info) [MSDOS]: Call dos_memory_info.
* vm-limit.c (get_lim_data) [MSDOS]: Call dos_memory_info, instead
of doing some of its job.
* minibuf.c (read_minibuf_noninteractive) [WINDOWSNT]: Don't
reference termios structure members.
......
......@@ -53,6 +53,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/sysinfo.h>
#endif
#ifdef MSDOS
#include "dosfns.h" /* For dos_memory_info. */
#endif
#if (defined ENABLE_CHECKING \
&& defined HAVE_VALGRIND_VALGRIND_H \
&& !defined USE_VALGRIND)
......@@ -6900,10 +6904,21 @@ values are zero. If the system is not supported, return nil. */)
(uintmax_t) freeswap / 1024);
else
return Qnil;
#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT */
#elif defined MSDOS
unsigned long totalram, freeram, totalswap, freeswap;
if (dos_memory_info (&totalram, &freeram, &totalswap, &freeswap) == 0)
return list4i ((uintmax_t) totalram / 1024,
(uintmax_t) freeram / 1024,
(uintmax_t) totalswap / 1024,
(uintmax_t) freeswap / 1024);
else
return Qnil;
}
#else /* not HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
/* FIXME: add more systems. */
return Qnil;
#endif /* HAVE_LINUX_SYSINFO */
#endif /* HAVE_LINUX_SYSINFO, not WINDOWSNT, not MSDOS */
}
/* Debugging aids. */
......
......@@ -640,6 +640,48 @@ system_process_attributes (Lisp_Object pid)
return attrs;
}
/* Support for memory-info. */
int
dos_memory_info (unsigned long *totalram, unsigned long *freeram,
unsigned long *totalswap, unsigned long *freeswap)
{
_go32_dpmi_meminfo info;
unsigned long mem1, mem2, freemem;
_go32_dpmi_get_free_memory_information (&info);
/* DPMI server of Windows NT and its descendants reports in
info.available_memory a much lower amount that is really
available, which causes bogus "past 95% of memory limit"
warnings. Try to overcome that via circumstantial evidence. */
mem1 = info.available_memory;
mem2 = info.available_physical_pages;
/* DPMI Spec: "Fields that are unavailable will hold -1." */
if ((long)mem1 == -1L)
mem1 = 0;
if ((long)mem2 == -1L)
mem2 = 0;
else
mem2 *= 4096;
/* Surely, the available memory is at least what we have physically
available, right? */
if (mem1 >= mem2)
freemem = mem1;
else
freemem = mem2;
*freeram = freemem;
*totalswap =
((long)info.max_pages_in_paging_file == -1L)
? 0
: info.max_pages_in_paging_file * 4096;
*totalram =
((long)info.total_physical_pages == -1L)
? (freemem + (unsigned long)sbrk (0) + *totalswap)
: info.total_physical_pages * 4096;
*freeswap = 0;
return 0;
}
void
dos_cleanup (void)
......
......@@ -22,7 +22,8 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#define DOS_COUNTRY_INFO 34 /* no of bytes returned by dos int 38h */
extern unsigned char dos_country_info[DOS_COUNTRY_INFO];
extern int dos_memory_info (unsigned long *, unsigned long *,
unsigned long *, unsigned long *);
#ifndef HAVE_X_WINDOWS
extern int msdos_stdcolor_idx (const char *);
extern Lisp_Object msdos_stdcolor_name (int);
......
......@@ -21,7 +21,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
#include "lisp.h"
#ifdef MSDOS
#include <dpmi.h>
#include "dosfns.h"
extern int etext;
#endif
......@@ -106,29 +106,10 @@ get_lim_data (void)
void
get_lim_data (void)
{
_go32_dpmi_meminfo info;
unsigned long lim1, lim2;
_go32_dpmi_get_free_memory_information (&info);
/* DPMI server of Windows NT and its descendants reports in
info.available_memory a much lower amount that is really
available, which causes bogus "past 95% of memory limit"
warnings. Try to overcome that via circumstantial evidence. */
lim1 = info.available_memory;
lim2 = info.available_physical_pages;
/* DPMI Spec: "Fields that are unavailable will hold -1." */
if ((long)lim1 == -1L)
lim1 = 0;
if ((long)lim2 == -1L)
lim2 = 0;
else
lim2 *= 4096;
/* Surely, the available memory is at least what we have physically
available, right? */
if (lim1 >= lim2)
lim_data = lim1;
else
lim_data = lim2;
unsigned long totalram, freeram, totalswap, freeswap;
dos_memory_info (&totalram, &freeram, &totalswap, &freeswap);
lim_data = freeram;
/* Don't believe they will give us more that 0.5 GB. */
if (lim_data > 512U * 1024U * 1024U)
lim_data = 512U * 1024U * 1024U;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment