delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1992/02/10/07:29:53

Date: Mon, 10 Feb 92 22:42 +1100
From: Bill Metzenthen <APM233M AT vaxc DOT cc DOT monash DOT edu DOT au>
Subject: Suggested change to go32
To: djgpp AT sun DOT soe DOT clarkson DOT edu, dj AT ctron DOT com
Status: O

Here is another suggested modification to DJGPP.

MSDOS gives just 20 handles to a process (which may be subsequently
increased). Of these, five are already in use; being stdin, stdout,
stderr, stdaux, and stdprn. go32 (as of version 1.05) uses another
four handles, leaving just eleven spare handles for the program.

Three of the handles used by go32 are an inevitable consequence
of the way in which go32 works. However, the fourth one arises from
an apparent oversight! A file is opened, examined, and then the
handle is thrown away without closing the file. A simple change to
control.c allows this handle to be recovered for use by programs.

The following is a diff to add the close() function. It also includes
a suggested modification which would ensure that a program run under
go32 gets the same default number of free handles (23-5-3 = 15) as
ordinary DOS programs (assuming that files=xxx in config.sys is large
enough). Note that go32 chokes on DOS service 0x67, so a program running
under/on go32 probably has no means of increasing the number of file
handles for itself.


---------------------------- snip snip ---------------------------------
diff -c old/control.c ./control.c
*** old/control.c	Mon Aug 26 07:26:34 1991
--- ./control.c	Tue Feb 11 08:45:20 1992
***************
*** 13,18 ****
--- 13,20 ----
  */
  
  /* Modified for VCPI Implement by Y.Shibata Aug 5th 1991 */
+ /* Added file close(). W Metzenthen 9th Feb 1992 */
+ /* Added code to compensate for used handles. W Metzenthen 10th Feb 1992 */
  /* History:87,1 */
  #include <dos.h>
  #include <stdlib.h>
***************
*** 139,145 ****
--- 141,165 ----
    struct stat stbuf;
    char *cp, *path, *argv0, *emu_fn=0;
    unsigned short header[3];
+   unsigned DosVersion;
  
+   /* If the MSDOS version is >= 3.3 ... WM */
+   if ( ((DosVersion = bdos(0x30,0,0)) & 0xff > 3) ||
+       ((DosVersion & 0xff == 3) && (DosVersion & 0xff00 >= 0x300)) )
+ 	{
+ 	/* Compensate for the 3 handles used by go32 */
+ 	struct	REGPACK	regs;
+ 
+ 	regs.r_ax = 0x6700;
+ 	regs.r_bx = 23;
+ 	intr(0x21, &regs);
+ 	if ( regs.r_flags & CF )
+ 		{
+ 		fprintf(stderr, "DOS error %d for service 0x67\n", regs.r_ax);
+ 		exit(1);
+ 		}
+ 	}
+ 
    if (xms_installed())
      use_xms = 1;
    old_video_mode = peekb(0x40, 0x49);
***************
*** 350,355 ****
--- 370,376 ----
      if (header[0] == 0x010b)
        self_contained = 1;
    }
+   close(n);	/* Give the handle back to MS-DOS (precious resource). WM */
  
    if (self_contained)
    {
***************
*** 388,395 ****
      else /* found */
      {
        debug_mode = 0;
!       paging_set_file(argv0);
!       emu_installed = emu_install(emu_fn);
        set_command_line(argv, envp);
  #if DEBUGGER
        syms_init(argv0);
--- 409,419 ----
      else /* found */
      {
        debug_mode = 0;
! 
!       paging_set_file(argv0);	/* Open the file 'argv0' to be paged in/out. */
! 
!       emu_installed = emu_install(emu_fn);	/* Open the file 'emu_fn' to
! 						   be paged in/out. */
        set_command_line(argv, envp);
  #if DEBUGGER
        syms_init(argv0);
***************
*** 400,406 ****
    if (set_brk)
      paging_brk(0x8fffffffL);
  
!   dalloc_init();
    init_controllers();
    if (emu_installed)
    {
--- 424,430 ----
    if (set_brk)
      paging_brk(0x8fffffffL);
  
!   dalloc_init();	/* Opens the swap file. */
    init_controllers();
    if (emu_installed)
    {
---------------------------- snip snip ---------------------------------

Bill Metzenthen

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019