-
Notifications
You must be signed in to change notification settings - Fork 1
/
c_hello.c
59 lines (51 loc) · 991 Bytes
/
c_hello.c
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
#define __NR_exit 60
#define __NR_write 1
typedef long ssize_t;
typedef unsigned long size_t;
int errno;
static unsigned long
errno_munge(unsigned long r)
{
if ((long)r < 0 && (long)r > -4096) {
errno = -r;
return (unsigned long)-1;
} else {
return r;
}
}
unsigned long
_syscall1(int sysnr, unsigned long arg)
{
unsigned long res;
asm ("syscall\n"
: "=a" (res)
: "0" (sysnr), "D" (arg)
: "memory");
return errno_munge(res);
}
unsigned long
_syscall3(int sysnr, unsigned long arg1, unsigned long arg2, unsigned long arg3)
{
unsigned long res;
asm ("syscall\n"
: "=a" (res)
: "0" (sysnr), "D" (arg1), "S" (arg2), "d" (arg3)
: "memory");
return errno_munge(res);
}
void
exit(int code)
{
_syscall1(__NR_exit, code);
}
ssize_t
write(int fd, const void *buf, size_t sz)
{
return _syscall3(__NR_write, fd, (unsigned long)buf, sz);
}
int
main(int argc, char *argv[])
{
write(1, "HELLO WORLD\n", sizeof("HELLO WORLD\n"));
return argc;
}