OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [libgloss/] [mep/] [sbrk.c] - Diff between revs 158 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 158 Rev 816
/*
/*
 * Copyright (c) 2003  Red Hat, Inc. All rights reserved.
 * Copyright (c) 2003  Red Hat, Inc. All rights reserved.
 *
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the BSD
 * copy, or redistribute it subject to the terms and conditions of the BSD
 * License.  This program is distributed in the hope that it will be useful,
 * License.  This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY expressed or implied, including the implied
 * but WITHOUT ANY WARRANTY expressed or implied, including the implied
 * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy
 * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  A copy
 * of this license is available at http://www.opensource.org/licenses. Any
 * of this license is available at http://www.opensource.org/licenses. Any
 * Red Hat trademarks that are incorporated in the source code or documentation
 * Red Hat trademarks that are incorporated in the source code or documentation
 * are not subject to the BSD License and may only be used or replicated with
 * are not subject to the BSD License and may only be used or replicated with
 * the express permission of Red Hat, Inc.
 * the express permission of Red Hat, Inc.
 */
 */
 
 
#include <errno.h>
#include <errno.h>
 
 
extern int __heap __far;      /* beginning of heap */
extern int __heap __far;      /* beginning of heap */
extern int __heap_end __far;  /* if at address 0, use stack pointer as limit */
extern int __heap_end __far;  /* if at address 0, use stack pointer as limit */
 
 
static char *the_break = (char *)(& __heap);
static char *the_break = (char *)(& __heap);
 
 
int
int
is_addr_0 (int address)
is_addr_0 (int address)
{
{
  return address ? 0 : 1;
  return address ? 0 : 1;
}
}
 
 
void *
void *
sbrk(int inc)
sbrk(int inc)
{
{
  char *current_heap_limit = (char *) (& __heap_end);
  char *current_heap_limit = (char *) (& __heap_end);
 
 
  /* is_addr_0 avoids optimizing out this block.  */
  /* is_addr_0 avoids optimizing out this block.  */
  if (is_addr_0 ((int) current_heap_limit))
  if (is_addr_0 ((int) current_heap_limit))
    {
    {
      int something;
      int something;
      int margin = 4096;
      int margin = 4096;
      current_heap_limit = (char *) (& something) - margin;
      current_heap_limit = (char *) (& something) - margin;
    }
    }
 
 
  if ((the_break + inc) < current_heap_limit)
  if ((the_break + inc) < current_heap_limit)
    {
    {
      void *rv = (void *) the_break;
      void *rv = (void *) the_break;
      the_break += inc;
      the_break += inc;
      return rv;
      return rv;
    }
    }
  else
  else
    {
    {
      errno = ENOMEM;
      errno = ENOMEM;
      return (void *) -1;
      return (void *) -1;
    }
    }
}
}
 
 
int
int
brk (void *ptr)
brk (void *ptr)
{
{
  the_break = ptr;
  the_break = ptr;
  return 0;
  return 0;
}
}
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.