Hi,
I wanted to relay a few issues found in 'command.com' , FreeDos version 1.2.
(1) After a successful build (using Turbo C 2.01), the system would hang after 
entering a command ... I tracked the hangup to "realloc()" call in static void 
docommand(char *line)
#ifdef FEATURE_INSTALLABLE_COMMANDS
    cp = realloc(buf, ARGS_BUFFER_SIZE);
#ifndef NDEBUG
    if(cp != buf) {
        dprintf( ("[INTERNAL error: realloc() returned wrong result]") );
        buf = cp;
    }
#endif
#else
    free(buf);  buf = 0;    /* no further useage of this buffer */
#endif
The only way to resolve this problem without changing code in 'docommand()'  
was to replace realloc() with my own -- (see below) -- once done, the command 
processor accepted commands. This may be a compiler related problem -- I 
empirically determined the size of the heap block since I didn't have the Turbo 
C source code of malloc() and related functions.
#define USE_MY_REALLOC
#ifdef USE_MY_REALLOC
/*
 *----------------------------------------------------------------------
 *
 * realloc --
 *
 *    Change the size of the block referenced by ptr to "size",
 *    possibly moving the block to a larger storage area.
 *
 * Results:
 *    The return value is a pointer to the new area of memory.
 *    The contents of this block will be unchanged up to the
 *    lesser of the new and old sizes.
 *
 * Side effects:
 *    The old block of memory may be released.
 *
 *----------------------------------------------------------------------
 */

static int malloc_size(char *ptr)
{
    unsigned short size;

    /* empirically determined size of memory block */

    ptr -= 4;
    size = *(unsigned short*)ptr;
    size -= 9;
    return (size);
}
void * _Cdecl realloc(void *ptr, size_t newSize)
                            /* Ptr to currently allocated block.  If
                            * it's 0, then this procedure behaves
                            * identically to malloc. */
                            /* Size of block after it is extended */
{
    char *newPtr;
    unsigned int curSize;

    if (ptr == 0)
    {
        return malloc(newSize);
    }
    curSize = malloc_size(ptr);
    if (newSize <= curSize)
    {
        return ptr;
    }
    newPtr = malloc(newSize);
    memcpy(newPtr, ptr, curSize);
    free(ptr);
    return(newPtr);
}
#endif /* USE_MY_REALLOC */


(2) Copying a file (via DOS 'copy' command) failed. I tracked this issue down 
to code in farread.c. The Int21 DOS call (via DOSreadwrite()) for WRITE and 
READ used the same command parameter (0x3F). I changed this to 0x40 for WRITE 
which resolved the problem.

size_t farread(int fd, void far*buf, size_t length)
{
    /* Use DOS API in order to read the strings directly to the far address */  
  return( DOSreadwrite( fd, buf, length, 0x3F00 ) );
}

size_t farwrite(int fd, void far*buf, size_t length)
{
/*    
    Originally ..
        return( DOSreadwrite( fd, buf, length, 0x3F00 ) );
    Change 0x3F00 to 0x4000 for WRITE
*/
    return( DOSreadwrite( fd, buf, length, 0x4000 ) );
}




------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Freedos-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freedos-devel

Reply via email to