Skip to content

Commit 98425e6

Browse files
committed
wip
1 parent 13ed03b commit 98425e6

File tree

12 files changed

+316
-274
lines changed

12 files changed

+316
-274
lines changed

packages/std/packages/std/manifest.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,7 @@ impl Manifest {
340340
}
341341

342342
let bytes = std::fs::read(output).map_err(|source| tg::error!(!source, "failed to read the output"))?;
343+
std::fs::remove_file(output).map_err(|source| tg::error!(!source, "failed to remove output file"))?;
343344
let cursor = std::io::Cursor::new(bytes);
344345
let blob = tg::Blob::with_reader(tg, cursor).await.map_err(|source| tg::error!(!source, "failed to create blob"))?;
345346

Lines changed: 88 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,209 +1,126 @@
1-
// Minimal syscall interface required by the stub.
2-
#pragma once
3-
#include <linux/unistd.h>
4-
#include <stddef.h>
5-
#include <stdint.h>
6-
7-
8-
#define PROT_READ 0x1
9-
#define PROT_WRITE 0x2
10-
#define PROT_EXEC 0x4
11-
#define MAP_PRIVATE 0x02
12-
#define MAP_ANONYMOUS 0x20
13-
#define MAP_FIXED 0x10
14-
#define MAP_FIXED_NOREPLACE 0x100000
15-
#define MAP_FAILED (void*)-1
16-
17-
#define RLIMIT_STACK 3
18-
19-
#define O_RDONLY 0
20-
#define SEEK_SET 0
21-
#define SEEK_CUR 1
22-
#define SEEK_END 2
23-
24-
#define STDOUT_FILENO 1
25-
#define STDERR_FILENO 2
26-
27-
typedef long off_t;
28-
typedef unsigned long __rlim_t;
29-
typedef struct {
30-
__rlim_t soft;
31-
__rlim_t hard;
32-
} rlimit_t;
33-
34-
typedef struct {
35-
uint8_t buf[256];
36-
} stat_t;
37-
38-
__attribute__((naked))
39-
static long write (int fd, const void *buf, size_t count) {
40-
register long x8 asm("x8") = __NR_write;
41-
register long x0 asm("x0") = (long)fd;
42-
register long x1 asm("x1") = (long)buf;
43-
register long x2 asm("x2") = (long)count;
44-
asm volatile(
45-
"svc 0\n\t"
46-
"ret\n\t"
47-
:
48-
: "r"(x8), "0"(x0), "r"(x1), "r"(x2)
49-
: "rcx", "r11", "memory"
50-
);
51-
}
52-
53-
__attribute__((naked))
54-
static int open (const char* path, int mode) {
55-
register long x8 asm("x8") = __NR_open;
56-
register long x0 asm("x0") = (long)path;
57-
register long x1 asm("x1") = (long)mode;
58-
asm volatile(
59-
"svc 0\n\t"
60-
"ret\n\t"
61-
:
62-
: "r"(x8), "0"(x0), "r"(x1)
63-
: "memory", "cc"
64-
);
65-
}
66-
67-
__attribute__((naked))
68-
static int close(int fd) {
69-
register long x8 asm("x8") = __NR_close;
70-
register long x0 asm("x0") = (long)fd;
71-
asm volatile(
72-
"svc 0\n\t"
73-
"ret\n\t"
74-
:
75-
: "r"(x8), "0"(x0)
76-
: "memory", "cc"
77-
);
78-
79-
}
80-
81-
__attribute__((naked))
82-
static long lseek (int fd, off_t offset, int whence) {
83-
register long x8 asm("x8") = __NR_lseek;
84-
register long x0 asm("x0") = (long)fd;
85-
register long x1 asm("x1") = (long)offset;
86-
register long x2 asm("x2") = (long)whence;
87-
asm volatile(
88-
"svc 0\n\t"
89-
"ret\n\t"
90-
:
91-
: "r"(x8), "0"(x0), "r"(x1), "r"(x2)
92-
: "memory", "cc"
93-
);
94-
}
95-
96-
__attribute__((naked))
97-
static int getrlimit (int resource, rlimit_t* rlim) {
98-
register long x8 asm("x8") = __NR_getrlimit;
99-
register long x0 asm("x0") = (long)resource;
100-
register long x1 asm("x1") = (long)rlim;
101-
asm volatile(
102-
"svc 0\n\t"
103-
"ret\n\t"
104-
:
105-
: "r"(x8), "0"(x0), "r"(x1)
106-
: "memory", "cc"
107-
);
108-
}
1091

1102
__attribute__((naked))
111-
static int pread64 (int fd, void* buf, size_t count, off_t offset) {
112-
register long x8 asm("x8") = __NR_pread64;
113-
register long x0 asm("x0") = (long)fd;
114-
register long x1 asm("x1") = (long)buf;
115-
register long x2 asm("x2") = (long)count;
116-
register long x1 asm("x1") = (long)offset;
117-
asm volatile(
118-
"svc 0\n\t"
3+
static long syscall1 (
4+
long nr,
5+
long arg1
6+
) {
7+
register long rax asm("rax") = nr;
8+
register long rdi asm("rdi") = arg1;
9+
asm volatile (
10+
"syscall\n\t"
11911
"ret\n\t"
12012
:
121-
: "r"(x8)
122-
: "memory", "cc"
13+
: "a"(rax), "D"(rdi)
14+
: "rcx", "r11", "memory"
12315
);
12416
}
12517

12618
__attribute__((naked))
127-
static void exit (int status)
128-
{
129-
register long x8 asm("x8") = __NR_exit;
130-
register long x0 asm("x0") = (long)status;
131-
asm volatile(
132-
"svc 0\n\t"
19+
static long syscall2 (
20+
long nr,
21+
long arg1,
22+
long arg2
23+
) {
24+
register long rax asm("rax") = nr;
25+
register long rdi asm("rdi") = arg1;
26+
register long rsi asm("rsi") = arg2;
27+
asm volatile (
28+
"syscall\n\t"
13329
"ret\n\t"
13430
:
135-
: "r"(x8), "0"(x0)
136-
: "memory", "cc"
31+
: "a"(rax), "D"(rdi), "S"(rsi)
32+
: "rcx", "r11", "memory"
13733
);
138-
__builtin_unreachable();
13934
}
14035

14136
__attribute__((naked))
142-
static void* mmap(
143-
void* addr,
144-
uint64_t length,
145-
uint64_t prot,
146-
uint64_t flags,
147-
int64_t fd,
148-
uint64_t offset
37+
static long syscall3 (
38+
long nr,
39+
long arg1,
40+
long arg2,
41+
long arg3
14942
) {
150-
register long x8 asm("x8") = __NR_mmap;
151-
register long x0 asm("x0") = (long)addr;
152-
register long x1 asm("x1") = (long)length;
153-
register long x2 asm("x2") = (long)prot;
154-
register long x3 asm("x3") = (long)flags;
155-
register long x4 asm("x4") = (long)fd;
156-
register long x5 asm("x5") = (long)offset;
157-
asm volatile(
158-
"svc 0\n\t"
43+
register long rax asm("rax") = nr;
44+
register long rdi asm("rdi") = arg1;
45+
register long rsi asm("rsi") = arg2;
46+
register long rdx asm("rdx") = arg3;
47+
asm volatile (
48+
"syscall\n\t"
15949
"ret\n\t"
16050
:
161-
: "r"(x8), "0"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x4), "r"(x5)
162-
: "memory", "cc"
51+
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx)
52+
: "rcx", "r11", "memory"
16353
);
16454
}
16555

16656
__attribute__((naked))
167-
static int munmap(
168-
void* addr,
169-
uint64_t len
57+
static long syscall4 (
58+
long nr,
59+
long arg1,
60+
long arg2,
61+
long arg3,
62+
long arg4
17063
) {
171-
register long x8 asm("x8") = __NR_munmap;
172-
register long x0 asm("x0") = (long)addr;
173-
register long x1 asm("x1") = (long)len;
174-
asm volatile(
175-
"svc 0\n\t"
64+
register long rax asm("rax") = nr;
65+
register long rdi asm("rdi") = arg1;
66+
register long rsi asm("rsi") = arg2;
67+
register long rdx asm("rdx") = arg3;
68+
register long r10 asm("r10") = arg4;
69+
asm volatile (
70+
"syscall\n\t"
17671
"ret\n\t"
17772
:
178-
: "r"(x8), "0"(x0), "r"(x1)
179-
: "memory", "cc"
73+
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10)
74+
: "rcx", "r11", "memory"
18075
);
18176
}
18277

18378
__attribute__((naked))
184-
static char* getcwd(char* buf, size_t size) {
185-
register long x8 asm("x8") = __NR_getcwd;
186-
register long x0 asm("x0") = (long)buf;
187-
register long x1 asm("x1") = (long)size;
188-
asm volatile(
189-
"svc 0\n\t"
79+
static long syscall5 (
80+
long nr,
81+
long arg1,
82+
long arg2,
83+
long arg3,
84+
long arg4,
85+
long arg5
86+
) {
87+
register long rax asm("rax") = nr;
88+
register long rdi asm("rdi") = arg1;
89+
register long rsi asm("rsi") = arg2;
90+
register long rdx asm("rdx") = arg3;
91+
register long r10 asm("r10") = arg4;
92+
register long r8 asm("r8") = arg5;
93+
asm volatile (
94+
"syscall\n\t"
19095
"ret\n\t"
19196
:
192-
: "r"(x8), "0"(x0), "r"(x1)
193-
: "memory", "cc"
97+
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10), "r"(r8)
98+
: "rcx", "r11", "memory"
19499
);
195100
}
196101

197102
__attribute__((naked))
198-
int stat (const char* pathname, stat_t* statbuf) {
199-
register long x8 asm("x8") = __NR_stat;
200-
register long x0 asm("x0") = (long)pathname;
201-
register long x1 asm("x1") = (long)statbuf;
202-
asm volatile(
203-
"svc 0\n\t"
103+
static long syscall6 (
104+
long nr,
105+
long arg1,
106+
long arg2,
107+
long arg3,
108+
long arg4,
109+
long arg5,
110+
long arg6
111+
) {
112+
register long rax asm("rax") = nr;
113+
register long rdi asm("rdi") = arg1;
114+
register long rsi asm("rsi") = arg2;
115+
register long rdx asm("rdx") = arg3;
116+
register long r10 asm("r10") = arg4;
117+
register long r8 asm("r8") = arg5;
118+
register long r9 asm("r9") = arg6;
119+
asm volatile (
120+
"syscall\n\t"
204121
"ret\n\t"
205122
:
206-
: "r"(x8), "0"(x0), "r"(x1)
207-
: "memory", "cc"
123+
: "a"(rax), "D"(rdi), "S"(rsi), "d"(rdx), "r"(r10), "r"(r8), "r"(r9)
124+
: "rcx", "r11", "memory"
208125
);
209126
}

0 commit comments

Comments
 (0)