summaryrefslogtreecommitdiff
path: root/tests/syscalls.c
blob: 285e5395fc6246c68fc45063123c7fc7a128e4d5 (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
int strlen(char *s) {
    int n = 0;
    while (s[n] != 0) { n = n + 1; }
    return n;
}

int puts_fd(int fd, char *s) {
    return syscall(1, fd, s, strlen(s));
}

int main() {
    puts_fd(1, "Hello from JIT syscall!\n");

    int pid = syscall(39);
    int pid_ok = pid > 0;

    char msg[32];
    msg[0] = 'P'; msg[1] = 'I'; msg[2] = 'D'; msg[3] = ' ';
    msg[4] = 'o'; msg[5] = 'k'; msg[6] = ':'; msg[7] = ' ';
    msg[8] = '0' + pid_ok;
    msg[9] = '\n';
    syscall(1, 1, msg, 10);

    int n1 = syscall(1, 1, "write test 1\n", 13);
    int n2 = syscall(1, 1, "write test 2\n", 13);

    int result = pid_ok + (n1 == 13) + (n2 == 13);

    return result;
}