Skip to content

Commit 58cbd1b

Browse files
committed
Remove the preview1 component adapter
1 parent cc314c3 commit 58cbd1b

File tree

8 files changed

+52
-44
lines changed

8 files changed

+52
-44
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ bindings: $(BINDING_WORK_DIR)/wasi-cli $(BINDING_WORK_DIR)/wit-bindgen
10581058
--autodrop-borrows yes \
10591059
--rename-world wasip2 \
10601060
--type-section-suffix __wasi_libc \
1061-
--world wasi:cli/imports@0.2.0 \
1061+
--world wasi:cli/command@0.2.0 \
10621062
--rename wasi:clocks/[email protected]=monotonic_clock \
10631063
--rename wasi:clocks/[email protected]=wall_clock \
10641064
--rename wasi:filesystem/[email protected]=filesystem_preopens \

expected/wasm32-wasip2/defined-symbols.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ __wasilibc_tell
392392
__wasilibc_unlinkat
393393
__wasilibc_utimens
394394
__wasm_call_dtors
395+
__wasm_export_exports_wasi_cli_run_run
395396
__wcscoll_l
396397
__wcsftime_l
397398
__wcsxfrm_l
@@ -612,6 +613,8 @@ explicit_bzero
612613
expm1
613614
expm1f
614615
expm1l
616+
exports_wasi_cli_run_result_void_void_free
617+
exports_wasi_cli_run_run
615618
fabs
616619
fabsf
617620
fabsl

expected/wasm32-wasip2/undefined-symbols.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ __subtf3
6565
__trunctfdf2
6666
__trunctfsf2
6767
__unordtf2
68-
__wasi_preview1_adapter_close_badfd
69-
__wasi_preview1_adapter_open_badfd
7068
__wasm_call_ctors
7169
__wasm_import_environment_get_arguments
7270
__wasm_import_environment_get_environment

libc-bottom-half/headers/public/wasi/wasip2.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,6 +1066,10 @@ typedef struct {
10661066
uint64_t f1;
10671067
} wasip2_tuple2_u64_u64_t;
10681068

1069+
typedef struct {
1070+
bool is_err;
1071+
} exports_wasi_cli_run_result_void_void_t;
1072+
10691073
// Imported Functions from `wasi:cli/[email protected]`
10701074
// Get the POSIX-style environment variables.
10711075
//
@@ -2251,6 +2255,9 @@ extern uint64_t random_insecure_get_insecure_random_u64(void);
22512255
// protection.
22522256
extern void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret);
22532257

2258+
// Exported Functions from `wasi:cli/[email protected]`
2259+
bool exports_wasi_cli_run_run(void);
2260+
22542261
// Helper Functions
22552262

22562263
void wasip2_tuple2_string_string_free(wasip2_tuple2_string_string_t *ptr);
@@ -2469,6 +2476,8 @@ void ip_name_lookup_option_ip_address_free(ip_name_lookup_option_ip_address_t *p
24692476

24702477
void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_result_option_ip_address_error_code_t *ptr);
24712478

2479+
void exports_wasi_cli_run_result_void_void_free(exports_wasi_cli_run_result_void_void_t *ptr);
2480+
24722481
// Transfers ownership of `s` into the string `ret`
24732482
void wasip2_string_set(wasip2_string_t *ret, char*s);
24742483

libc-bottom-half/sources/__main_void.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#ifdef __wasilibc_use_wasip2
22
#include <wasi/wasip2.h>
3+
#include <wasi/libc-environ.h>
34
#else
45
#include <wasi/api.h>
56
#endif
@@ -108,3 +109,11 @@ int __main_void(void) {
108109
return __main_argc_argv(argc, argv);
109110
#endif
110111
}
112+
113+
#ifdef __wasilibc_use_wasip2
114+
bool exports_wasi_cli_run_run(void) {
115+
// TODO: this is supposed to be unnecessary, but functional/env.c fails without it
116+
__wasilibc_initialize_environ();
117+
return __main_void() == 0;
118+
}
119+
#endif

libc-bottom-half/sources/descriptor_table.c

Lines changed: 10 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,6 @@
2424

2525
#include <wasi/descriptor_table.h>
2626

27-
__attribute__((__import_module__("wasi_snapshot_preview1"),
28-
__import_name__("adapter_open_badfd"))) extern int32_t
29-
__wasi_preview1_adapter_open_badfd(int32_t);
30-
31-
static bool wasi_preview1_adapter_open_badfd(int *fd)
32-
{
33-
return __wasi_preview1_adapter_open_badfd((int32_t)fd) == 0;
34-
}
35-
36-
__attribute__((__import_module__("wasi_snapshot_preview1"),
37-
__import_name__("adapter_close_badfd"))) extern int32_t
38-
__wasi_preview1_adapter_close_badfd(int32_t);
39-
40-
static bool wasi_preview1_adapter_close_badfd(int fd)
41-
{
42-
return __wasi_preview1_adapter_close_badfd(fd) == 0;
43-
}
44-
4527
/*
4628
* This hash table is based on the one in musl/src/search/hsearch.c, but uses
4729
* integer keys and supports a `remove` operation. Note that I've switched from
@@ -69,6 +51,8 @@ static descriptor_table_t global_table = { .entries = NULL,
6951
.mask = 0,
7052
.used = 0 };
7153

54+
static int next_fd = 3;
55+
7256
static size_t keyhash(int key)
7357
{
7458
// TODO: use a hash function here
@@ -223,19 +207,13 @@ static bool remove(int fd, descriptor_table_entry_t *entry,
223207

224208
bool descriptor_table_insert(descriptor_table_entry_t entry, int *fd)
225209
{
226-
if (wasi_preview1_adapter_open_badfd(fd)) {
227-
if (insert(entry, *fd, &global_table, false)) {
228-
return true;
229-
} else {
230-
if (!wasi_preview1_adapter_close_badfd(*fd)) {
231-
abort();
232-
}
233-
*fd = -1;
234-
return false;
235-
}
236-
} else {
237-
return false;
238-
}
210+
*fd = ++next_fd;
211+
if (insert(entry, *fd, &global_table, false)) {
212+
return true;
213+
} else {
214+
*fd = -1;
215+
return false;
216+
}
239217
}
240218

241219
bool descriptor_table_get_ref(int fd, descriptor_table_entry_t **entry)
@@ -260,12 +238,5 @@ bool descriptor_table_update(int fd, descriptor_table_entry_t entry) {
260238

261239
bool descriptor_table_remove(int fd, descriptor_table_entry_t *entry)
262240
{
263-
if (remove(fd, entry, &global_table)) {
264-
if (!wasi_preview1_adapter_close_badfd(fd)) {
265-
abort();
266-
}
267-
return true;
268-
} else {
269-
return false;
270-
}
241+
return remove(fd, entry, &global_table);
271242
}

libc-bottom-half/sources/wasip2.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,11 @@ void ip_name_lookup_result_option_ip_address_error_code_free(ip_name_lookup_resu
10101010
}
10111011
}
10121012

1013+
void exports_wasi_cli_run_result_void_void_free(exports_wasi_cli_run_result_void_void_t *ptr) {
1014+
if (!ptr->is_err) {
1015+
}
1016+
}
1017+
10131018
void wasip2_string_set(wasip2_string_t *ret, char*s) {
10141019
ret->ptr = (uint8_t*) s;
10151020
ret->len = strlen(s);
@@ -1068,7 +1073,7 @@ bool environment_initial_cwd(wasip2_string_t *ret) {
10681073
return option.is_some;
10691074
}
10701075

1071-
_Noreturn void exit_exit(exit_result_void_void_t *status) {
1076+
void exit_exit(exit_result_void_void_t *status) {
10721077
int32_t result;
10731078
if ((*status).is_err) {
10741079
result = 1;
@@ -4320,6 +4325,19 @@ void random_insecure_seed_insecure_seed(wasip2_tuple2_u64_u64_t *ret) {
43204325
};
43214326
}
43224327

4328+
__attribute__((__export_name__("wasi:cli/[email protected]#run")))
4329+
int32_t __wasm_export_exports_wasi_cli_run_run(void) {
4330+
exports_wasi_cli_run_result_void_void_t ret;
4331+
ret.is_err = !exports_wasi_cli_run_run();
4332+
int32_t result;
4333+
if ((ret).is_err) {
4334+
result = 1;
4335+
} else {
4336+
result = 0;
4337+
}
4338+
return result;
4339+
}
4340+
43234341
extern void __component_type_object_force_link_wasip2(void);
43244342
void __component_type_object_force_link_wasip2_public_use_in_this_compilation_unit(void) {
43254343
__component_type_object_force_link_wasip2();

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ $(OBJDIR)/%.core.wasm: $(OBJDIR)/%.wasm.o $(INFRA_WASM_OBJS) | $(BUILTINS_STAMP)
171171
# For wasip2, we include an additional step to wrap up the core module into
172172
# a component.
173173
$(OBJDIR)/%.component.wasm: $(OBJDIR)/%.core.wasm
174-
$(WASM_TOOLS) component new --adapt $(ADAPTER) $< -o $@
174+
$(WASM_TOOLS) component new $< -o $@
175175

176176
# Compile each selected test using Clang. Note that failures here are likely
177177
# due to a missing `libclang_rt.builtins-wasm32.a` in the Clang lib directory.

0 commit comments

Comments
 (0)