Skip to content

Commit c59be28

Browse files
committed
update docker for x64
1 parent 8fa50a1 commit c59be28

File tree

7 files changed

+71
-60
lines changed

7 files changed

+71
-60
lines changed

Dockerfile

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
FROM ubuntu:jammy
1+
FROM ubuntu:24.04
22

3-
ENV QEMU_LD_PREFIX="/usr/arm-linux-gnueabihf"
43
ENV CC="clang"
5-
ENV CFLAGS="--target=arm-linux-gnueabihf"
6-
ENV OBJDUMP="/usr/arm-linux-gnueabihf/bin/objdump"
7-
ENV PRELOADER="qemu-arm"
4+
ENV OBJDUMP="objdump"
85

96
RUN apt-get update && apt-get -y install \
107
build-essential \
118
clang \
12-
gcc-arm-linux-gnueabihf \
13-
qemu-user
9+
binutils \
10+
less \
11+
bat \
12+
vim \
13+
neofetch
1414

1515
WORKDIR /root/tiny_wine

Makefile

-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# @todo: add fsanitize
2-
31
ifeq ($(CC),cc)
42
CC := clang
53
endif
@@ -25,18 +23,6 @@ all: \
2523
programs/linux/static_pie \
2624
programs/linux/dynamic
2725

28-
all_x64: \
29-
libtinyc.a \
30-
libtinyc.so \
31-
libstatic.a \
32-
loader \
33-
programs/linux/unit_test \
34-
programs/linux/env \
35-
programs/linux/string \
36-
programs/linux/tinyfetch \
37-
programs/linux/static_pie \
38-
programs/linux/dynamic
39-
4026
tinyc_start.o: src/tiny_c/tinyc_start.c
4127
@$(CC) $(CFLAGS) \
4228
-g \

arm32.Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ubuntu:jammy
2+
3+
ENV QEMU_LD_PREFIX="/usr/arm-linux-gnueabihf"
4+
ENV CC="clang"
5+
ENV CFLAGS="--target=arm-linux-gnueabihf"
6+
ENV OBJDUMP="/usr/arm-linux-gnueabihf/bin/objdump"
7+
ENV PRELOADER="qemu-arm"
8+
9+
RUN apt-get update && apt-get -y install \
10+
build-essential \
11+
clang \
12+
gcc-arm-linux-gnueabihf \
13+
qemu-user
14+
15+
WORKDIR /root/tiny_wine

readme.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ Very basic support for jumping to other static Linux ELF programs.
66

77
## Limitations
88

9-
- Arm32
109
- Linux
11-
- No standard libary
10+
- No standard library
11+
- More...
1212

1313
## Prerequisites
1414

15-
- docker (or an arm32 machine)
15+
- docker
1616

1717
```sh
1818
git clone https://github.com/Sharpiro/tiny-wine.git
@@ -29,7 +29,7 @@ docker run --rm -v $PWD:/root/tiny_wine tinywine make
2929
## Running
3030

3131
```sh
32-
docker run --rm -v $PWD:/root/tiny_wine tinywine qemu-arm ./loader ./tinyfetch
32+
docker run --rm -v $PWD:/root/tiny_wine tinywine ./loader ./tinyfetch
3333
```
3434

3535
### Example Output
@@ -39,8 +39,8 @@ root@3db29f0a588e
3939
--------------
4040
OS: Ubuntu 22.04.4 LTS armv7l
4141
Kernel: 6.10.5-100.fc39.x86_64
42-
Uptime: 0x00000024 days, 0x00000016 hours, 0x00000033 minutes
43-
Shell: (null)
42+
Uptime: Uptime: 32 days, 21 hours, 29 minutes
43+
Shell: /bin/bash
4444
```
4545

4646
## Tests

src/loader/loader_main.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void dynamic_linker_callback(void) {
8181

8282
size_t *lib_dyn_offset = (size_t *)(*(rbp + 1));
8383
size_t relocation_index = *(rbp + 2);
84-
if (lib_dyn_offset == nullptr) {
84+
if (lib_dyn_offset == NULL) {
8585
tiny_c_fprintf(STDERR, "lib_dyn_offset was null\n");
8686
tiny_c_exit(-1);
8787
}

src/programs/linux/dynamic/dynamic_lib.c

+41-30
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ bool read_to_string(const char *path, char **content) {
141141
}
142142

143143
struct Split {
144-
size_t start;
145-
size_t end;
144+
const char *split;
145+
size_t split_len;
146146
};
147147

148148
bool string_split(
@@ -160,10 +160,14 @@ bool string_split(
160160
size_t split_start = 0;
161161
for (size_t i = 0; i < str_len; i++) {
162162
const char curr_char = str[i];
163-
if (curr_char == split_char || i + 1 == str_len) {
163+
bool is_last_char = i + 1 == str_len;
164+
if (curr_char == split_char || is_last_char) {
165+
const char *split = str + split_start;
166+
size_t split_len =
167+
is_last_char ? i - split_start + 1 : i - split_start;
164168
(*split_entries)[split_index++] = (struct Split){
165-
.start = split_start,
166-
.end = i,
169+
.split = split,
170+
.split_len = split_len,
167171
};
168172
if (split_index == MAX_SPLIT_ENTRIES) {
169173
BAIL("max split entries exceeded\n");
@@ -184,47 +188,54 @@ struct passwd *getpwuid(uid_t uid) {
184188
}
185189

186190
size_t passwd_file_len = strlen(passwd_file);
187-
struct Split *lines;
188-
size_t lines_len;
189-
if (!string_split(passwd_file, passwd_file_len, '\n', &lines, &lines_len)) {
191+
struct Split *user_lines;
192+
size_t user_lines_len;
193+
if (!string_split(
194+
passwd_file, passwd_file_len, '\n', &user_lines, &user_lines_len
195+
)) {
190196
tinyc_errno = ENOENT;
191197
return NULL;
192198
}
193199

194-
for (size_t i = 0; i < lines_len; i++) {
195-
struct Split *curr_line = &lines[i];
196-
char *line_ptr = passwd_file + curr_line->start;
197-
size_t line_len = curr_line->end - curr_line->start;
198-
struct Split *split_entries;
199-
size_t split_entries_len;
200+
for (size_t i = 0; i < user_lines_len; i++) {
201+
struct Split *user_line = &user_lines[i];
202+
struct Split *user_details_split;
203+
size_t user_details_split_len;
200204
if (!string_split(
201-
line_ptr, line_len, ':', &split_entries, &split_entries_len
205+
user_line->split,
206+
user_line->split_len,
207+
':',
208+
&user_details_split,
209+
&user_details_split_len
202210
)) {
203211
tinyc_errno = ENOENT;
204212
return NULL;
205213
}
206-
if (split_entries_len < 7) {
214+
if (user_details_split_len < 7) {
207215
tinyc_errno = ENOENT;
208216
return NULL;
209217
}
210218

211-
struct Split *uid_split = &split_entries[2];
212-
size_t uid_str_len = uid_split->end - uid_split->start;
213-
char *uid_str = passwd_file + curr_line->start + uid_split->start;
214-
size_t parsed_uid = (size_t)atol_len(uid_str, uid_str_len);
219+
struct Split *uid_split = &user_details_split[2];
220+
size_t parsed_uid =
221+
(size_t)atol_len(uid_split->split, uid_split->split_len);
215222
if (parsed_uid == uid) {
216-
struct Split *username_split = &split_entries[0];
217-
size_t username_len = username_split->end - username_split->start;
218-
char *username_file_ptr = passwd_file + curr_line->start;
219-
char *username = tinyc_malloc_arena(username_len + 1);
220-
// @todo: could create 'alloc' func to avoid this line
221-
username[username_len] = 0;
222-
memcpy(username, username_file_ptr, username_len);
223-
struct passwd *passwdx = tinyc_malloc_arena(READ_SIZE);
224-
*passwdx = (struct passwd){
223+
struct Split *username_split = &user_details_split[0];
224+
char *username = tinyc_malloc_arena(username_split->split_len + 1);
225+
memcpy(username, username_split->split, username_split->split_len);
226+
memset(username + user_line->split_len, 0, 1);
227+
228+
struct Split *shell_split = &user_details_split[6];
229+
char *shell = tinyc_malloc_arena(shell_split->split_len + 1);
230+
memcpy(shell, shell_split->split, shell_split->split_len);
231+
memset(shell + shell_split->split_len, 0, 1);
232+
233+
struct passwd *passwd = tinyc_malloc_arena(sizeof(struct passwd));
234+
*passwd = (struct passwd){
225235
.pw_name = username,
236+
.pw_shell = shell,
226237
};
227-
return passwdx;
238+
return passwd;
228239
}
229240
}
230241

src/programs/linux/tinyfetch/tinyfetch_main.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ int main(int argc, char **argv) {
9393
);
9494

9595
/* Shell */
96-
const char *shell = getenv("SHELL");
97-
tiny_c_printf("Shell: %s\n", shell);
96+
tiny_c_printf("Shell: %s\n", user_info->pw_shell);
9897

9998
tinyc_free_arena();
10099
}

0 commit comments

Comments
 (0)