From: Eli Zaretskii Date: Fri, 11 Jul 2014 10:09:51 +0000 (+0300) Subject: Implement memory-info for MS-DOS. X-Git-Tag: emacs-25.0.90~2636^2~38 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=5f7c30e757680f66be9ef4c399fd1d7ce5b66203;p=emacs.git 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. --- diff --git a/src/ChangeLog b/src/ChangeLog index 1e0a3a92f5d..e469880a4ce 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,12 @@ 2014-07-11 Eli Zaretskii + 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. diff --git a/src/alloc.c b/src/alloc.c index 4a912703c39..77be94d73d1 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -53,6 +53,10 @@ along with GNU Emacs. If not, see . */ #include #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. */ diff --git a/src/dosfns.c b/src/dosfns.c index baa0358d725..e557dcba022 100644 --- a/src/dosfns.c +++ b/src/dosfns.c @@ -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) diff --git a/src/dosfns.h b/src/dosfns.h index 3409b2247b7..f32e6342fc9 100644 --- a/src/dosfns.h +++ b/src/dosfns.h @@ -22,7 +22,8 @@ along with GNU Emacs. If not, see . */ #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); diff --git a/src/vm-limit.c b/src/vm-limit.c index f138dc28b2e..308613f7eb4 100644 --- a/src/vm-limit.c +++ b/src/vm-limit.c @@ -21,7 +21,7 @@ along with GNU Emacs. If not, see . */ #include "lisp.h" #ifdef MSDOS -#include +#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;