CS350 COS
COS
Loading...
Searching...
No Matches
stdlib.h File Reference
#include <sys/types.h>
Include dependency graph for stdlib.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NULL   ((void *)0)
 

Functions

int atexit (void(*function)(void))
 
void exit (int status)
 
_Noreturn void abort (void)
 
void * calloc (size_t num, size_t sz)
 
void * malloc (size_t sz)
 
void free (void *buf)
 
int atoi (const char *nptr)
 

Macro Definition Documentation

◆ NULL

#define NULL   ((void *)0)

Definition at line 8 of file stdlib.h.

Function Documentation

◆ abort()

_Noreturn void abort ( void  )

Definition at line 9 of file abort.c.

10{
11 OSExit(-1);
12
14}
#define UNREACHABLE
Definition: cdefs.h:14
void OSExit(int status)
Definition: syscall.c:17
Here is the call graph for this function:
Here is the caller graph for this function:

◆ atexit()

int atexit ( void(*)(void)  function)

Definition at line 17 of file exit.c.

18{
19 if (_atexit_count < 32) {
20 struct atexit_cb *prev = _atexit_last;
21
22 _atexits[_atexit_count].cb = function;
24
27 } else {
28 // XXX: Support malloc
29 return -1;
30 }
31
32 return 0;
33}
static uint64_t _atexit_count
Definition: exit.c:12
static struct atexit_cb _atexits[32]
Definition: exit.c:13
static struct atexit_cb * _atexit_last
Definition: exit.c:14
Definition: exit.c:7
void(* cb)(void)
Definition: exit.c:9
struct atexit_cb * next
Definition: exit.c:8
Here is the caller graph for this function:

◆ atoi()

int atoi ( const char *  nptr)

Definition at line 3 of file stdlib.c.

4{
5 int i = 0;
6 int val = 0;
7
8 while (nptr[i] != '\0') {
9 if (nptr[i] >= '0' && nptr[i] <= '9') {
10 val = val * 10 + (int)(nptr[i] - '0');
11 } else {
12 return 0;
13 }
14 i++;
15 }
16
17 return val;
18}
Here is the caller graph for this function:

◆ calloc()

void * calloc ( size_t  num,
size_t  sz 
)

Definition at line 154 of file malloc.c.

155{
156 return malloc(num*sz);
157}
void * malloc(size_t sz)
Definition: malloc.c:160
Here is the call graph for this function:

◆ exit()

void exit ( int  status)

Definition at line 36 of file exit.c.

37{
38 while (_atexit_last != NULL) {
39 (_atexit_last->cb)();
41 }
42
43 OSExit(status & 0x00ff);
44
45 __builtin_unreachable();
46}
#define NULL
Definition: stddef.h:6
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free()

void free ( void *  buf)

Definition at line 169 of file malloc.c.

170{
171 Header *hdr = (Header *)mem;
172 hdr--;
173
174 if (mem == NULL)
175 return;
176
177 assert(hdr->magic == HEAP_MAGIC);
178
179 if (hdr->size > HEAP_MAX_POOLSIZE)
180 free_large(hdr);
181 else
182 free_small(hdr);
183}
#define assert(_expr)
Definition: assert.h:7
#define HEAP_MAGIC
Definition: malloc.c:15
#define HEAP_MAX_POOLSIZE
Definition: malloc.c:18
uint32_t size
Definition: malloc.c:11
uint16_t magic
Definition: malloc.c:9
static void free_small(Header *mem)
Definition: malloc.c:115
static void free_large(Header *mem)
Definition: malloc.c:148
Definition: malloc.c:8
Here is the call graph for this function:
Here is the caller graph for this function:

◆ malloc()

void * malloc ( size_t  sz)

Definition at line 160 of file malloc.c.

161{
162 if (sz > HEAP_MAX_POOLSIZE)
163 return malloc_large(sz);
164 else
165 return malloc_small(sz);
166}
static void * malloc_large(size_t sz)
Definition: malloc.c:124
static void * malloc_small(size_t sz)
Definition: malloc.c:95
Here is the call graph for this function:
Here is the caller graph for this function: