Browse Source

--- Merging r20111 into '.':
U packages/gdbint/src/gdbint.pp
--- Merging r20113 into '.':
U rtl/go32v2/v2prt0.as

# revisions: 20111,20113
------------------------------------------------------------------------
r20111 | pierre | 2012-01-19 15:01:47 +0100 (Thu, 19 Jan 2012) | 1 line
Changed paths:
M /trunk/packages/gdbint/src/gdbint.pp

* Try to fix go32v2 problems related to DJGPP code using C free on _environ ppchar by reallcating with malloc
------------------------------------------------------------------------
------------------------------------------------------------------------
r20113 | pierre | 2012-01-19 18:12:03 +0100 (Thu, 19 Jan 2012) | 1 line
Changed paths:
M /trunk/rtl/go32v2/v2prt0.as

* Try to fix go32v2 problems related to DJGPP 2.04 CVS code using __environ as alias of _environ
------------------------------------------------------------------------

git-svn-id: branches/fixes_2_6@20586 -

marco 13 years ago
parent
commit
cf50fa2a72
2 changed files with 40 additions and 5 deletions
  1. 32 1
      packages/gdbint/src/gdbint.pp
  2. 8 4
      rtl/go32v2/v2prt0.as

+ 32 - 1
packages/gdbint/src/gdbint.pp

@@ -815,8 +815,11 @@ type
   jmp_buf = dpmi_jmp_buf;
   pjmp_buf = pdpmi_jmp_buf;
 
+
   function setjmp(var rec : jmp_buf) : longint;cdecl;external;
 
+  function malloc(size : longint) : pointer;cdecl;external;
+
   procedure longjmp(var rec : jmp_buf;return_value : longint);cdecl;external;
 
   procedure reload_fs;assembler;
@@ -2980,6 +2983,32 @@ var
   c_environ : ppchar;external name '_environ';
   c_argc : longint;external name '___crt0_argc';
   c_argv : ppchar;external name '___crt0_argv';
+
+  procedure ReallocateEnvironUsingCMalloc;
+
+  var
+    neededsize , count : longint;
+    penv : pchar;
+    newenv : ppchar;
+  begin
+    if not assigned(c_environ) then
+      neededsize:=0
+    else
+      begin
+        count:=0;
+        penv:=c_environ^;
+        while assigned(penv) do
+          begin
+            inc(count);
+            inc(penv,sizeof(pchar));
+          end;
+        neededsize:=count*sizeof(pchar);
+      end;
+    newenv:=malloc(neededsize);
+    system.move(c_environ,newenv,neededsize);
+    c_environ:=newenv;
+  end;
+
 {$endif def go32v2}
 var
   current_directory : pchar; cvar; external;
@@ -2999,7 +3028,9 @@ var
 {$endif not GDB_INIT_HAS_ARGV0}
 begin
 {$ifdef go32v2}
-  c_environ:=system.envp;
+  { c_environ:=system.envp; }
+  { DJGPP libC presupposes the c_enivron was malloc'ated }
+  ReallocateEnvironUsingCMalloc;
   c_argc:=system.argc;
   c_argv:=system.argv;
 {$endif def go32v2}

+ 8 - 4
rtl/go32v2/v2prt0.as

@@ -852,7 +852,7 @@ _pascal_start:
         movl    %esp,%ebx
         movl    12(%ebx),%eax
         movl    %eax,U_SYSTEM_ENVP
-        movl    %eax,_environ
+        movl    %eax,__environ
         movl    8(%ebx),%eax
         movl    %eax,_args
         movl    4(%ebx),%eax
@@ -887,9 +887,13 @@ _core_selector:
         .globl ___v2prt0_start_fs
 ___v2prt0_start_fs:
         .word 0
-        .globl  _environ
-_environ:
-         .long 0
+         /* DJGPP CVS crt1.c code uses __environ symbol */
+         /* corresponding to _environ C variable */
+         /* instead of _environ symbol since commit rev 1.11 */
+         /* Thu Aug 19 9:11:52 2004 UTC by peuha */
+         /* _environ is provided by linker script at the same address */
+         /* as __environ if needed by linker. */
+        .comm  __environ,4
 
 /* Here Pierre Muller added all what was in crt1.c  */
 /* in assembler                              */