aboutsummaryrefslogtreecommitdiff
path: root/libgloss/arm/linux-syscalls1.c
blob: a196352b51d6b953c6ce9fb9f82dca39c13f4a48 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/** Linux system call interface.
 * Written by Shaun Jackman <sjackman@gmail.com>.
 * Copyright 2006 Pathway Connectivity
 *
 * Permission to use, copy, modify, and distribute this software
 * is freely granted, provided that this notice is preserved.
 */

#include <errno.h>
#include <stdint.h>

extern char _end[];
static void *curbrk = _end;

extern void *_brk(void *addr);

int brk(void *addr)
{
	void *newbrk;
	if (curbrk == addr)
		return 0;
	newbrk = _brk(addr);
	curbrk = newbrk;
	if (newbrk < addr) {
		errno = ENOMEM;
		return -1;
	}
	return 0;
}

void *_sbrk(intptr_t incr)
{
	void *oldbrk = curbrk;
	if (brk(oldbrk + incr) == -1)
		return (void *)-1;
	return oldbrk;
}

void *sbrk(intptr_t incr) __attribute__((alias("_sbrk")));

int _set_errno(int n)
{
	if (n < 0) {
		errno = -n;
		return -1;
	}
	return n;
}

#include <sys/wait.h>

struct rusage;

pid_t wait4(pid_t pid, int *status, int options, struct rusage *rusage);

pid_t _wait(int *status)
{
	return wait4(-1, status, 0, NULL);
}

pid_t waitpid(pid_t pid, int *status, int options)
{
	return wait4(pid, status, options, NULL);
}

extern int _reboot(int magic, int magic2, int flag, void *arg);

int reboot(int flag)
{
	return _reboot(0xfee1dead, 0x28121969, flag, NULL);
}