Subversion Repositories HelenOS

Rev

Rev 3222 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3222 Rev 4471
Line 28... Line 28...
28
 
28
 
29
/** @addtogroup libc
29
/** @addtogroup libc
30
 * @{
30
 * @{
31
 */
31
 */
32
/** @file
32
/** @file
33
 */
33
 */
34
 
34
 
35
#include <as.h>
35
#include <as.h>
36
#include <libc.h>
36
#include <libc.h>
37
#include <unistd.h>
37
#include <unistd.h>
38
#include <align.h>
38
#include <align.h>
Line 100... Line 100...
100
}
100
}
101
 
101
 
102
static size_t heapsize = 0;
102
static size_t heapsize = 0;
103
static size_t maxheapsize = (size_t) (-1);
103
static size_t maxheapsize = (size_t) (-1);
104
 
104
 
105
static void * last_allocated = 0;
105
static void *last_allocated = 0;
106
 
106
 
107
/* Start of heap linker symbol */
107
/* Start of heap linker symbol */
108
extern char _heap;
108
extern char _heap;
109
 
109
 
110
/** Sbrk emulation
110
/** Sbrk emulation
Line 117... Line 117...
117
{
117
{
118
    int rc;
118
    int rc;
119
    void *res;
119
    void *res;
120
   
120
   
121
    /* Check for invalid values */
121
    /* Check for invalid values */
122
    if (incr < 0 && -incr > heapsize)
122
    if ((incr < 0) && (((size_t) -incr) > heapsize))
123
        return NULL;
123
        return NULL;
124
   
124
   
125
    /* Check for too large value */
125
    /* Check for too large value */
126
    if (incr > 0 && incr+heapsize < heapsize)
126
    if ((incr > 0) && (incr + heapsize < heapsize))
127
        return NULL;
127
        return NULL;
128
   
128
   
129
    /* Check for too small values */
129
    /* Check for too small values */
130
    if (incr < 0 && incr+heapsize > heapsize)
130
    if ((incr < 0) && (incr + heapsize > heapsize))
131
        return NULL;
131
        return NULL;
132
   
132
   
133
    /* Check for user limit */
133
    /* Check for user limit */
134
    if ((maxheapsize != (size_t) (-1)) && (heapsize + incr) > maxheapsize)
134
    if ((maxheapsize != (size_t) (-1)) && (heapsize + incr) > maxheapsize)
135
        return NULL;
135
        return NULL;
Line 173... Line 173...
173
        return NULL;   
173
        return NULL;   
174
 
174
 
175
    asz = 1 << (fnzb64(sz - 1) + 1);
175
    asz = 1 << (fnzb64(sz - 1) + 1);
176
 
176
 
177
    /* Set heapsize to some meaningful value */
177
    /* Set heapsize to some meaningful value */
178
    if (maxheapsize == -1)
178
    if (maxheapsize == (size_t) -1)
179
        set_maxheapsize(MAX_HEAP_SIZE);
179
        set_maxheapsize(MAX_HEAP_SIZE);
180
   
180
   
181
    /*
181
    /*
182
     * Make sure we allocate from naturally aligned address.
182
     * Make sure we allocate from naturally aligned address.
183
     */
183
     */