Skip to content

Commit 34c55f8

Browse files
committed
Fix platform specific code in libc_backing.c
1 parent 5fb554a commit 34c55f8

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

code_benches/run.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
IS_X86 = '86' in os.uname()[-1]
3030
IS_32_BIT_X86 = (not IS_64_BIT) and IS_X86
3131

32-
# TODO: Add an option to output a CSV instead of human readable output
33-
3432
# How many times should we run our benchmarks
3533
RUN_COUNT = 10
3634
ENABLE_DEBUG_SYMBOLS = True

runtime/libc/libc_backing.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ i32 wasm_stat(u32 path_str_offset, i32 stat_offset) {
226226
.st_blksize = stat.st_blksize,
227227
.st_blocks = stat.st_blocks,
228228
};
229-
229+
#ifdef __APPLE__
230230
stat_ptr->st_atim.tv_sec = stat.st_atimespec.tv_sec;
231231
stat_ptr->st_atim.tv_nsec = stat.st_atimespec.tv_nsec;
232232

@@ -235,6 +235,16 @@ i32 wasm_stat(u32 path_str_offset, i32 stat_offset) {
235235

236236
stat_ptr->st_ctim.tv_sec = stat.st_ctimespec.tv_sec;
237237
stat_ptr->st_ctim.tv_nsec = stat.st_ctimespec.tv_nsec;
238+
#else
239+
stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec;
240+
stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec;
241+
242+
stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec;
243+
stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec;
244+
245+
stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec;
246+
stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec;
247+
#endif
238248
} else if (res == -1) {
239249
return -errno;
240250
}
@@ -261,6 +271,7 @@ i32 wasm_fstat(i32 filedes, i32 stat_offset) {
261271
.st_blksize = stat.st_blksize,
262272
.st_blocks = stat.st_blocks,
263273
};
274+
#ifdef __APPLE__
264275
stat_ptr->st_atim.tv_sec = stat.st_atimespec.tv_sec;
265276
stat_ptr->st_atim.tv_nsec = stat.st_atimespec.tv_nsec;
266277

@@ -269,6 +280,16 @@ i32 wasm_fstat(i32 filedes, i32 stat_offset) {
269280

270281
stat_ptr->st_ctim.tv_sec = stat.st_ctimespec.tv_sec;
271282
stat_ptr->st_ctim.tv_nsec = stat.st_ctimespec.tv_nsec;
283+
#else
284+
stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec;
285+
stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec;
286+
287+
stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec;
288+
stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec;
289+
290+
stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec;
291+
stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec;
292+
#endif
272293
} else if (res == -1) {
273294
return -errno;
274295
}
@@ -296,6 +317,7 @@ i32 wasm_lstat(i32 path_str_offset, i32 stat_offset) {
296317
.st_blksize = stat.st_blksize,
297318
.st_blocks = stat.st_blocks,
298319
};
320+
#ifdef __APPLE__
299321
stat_ptr->st_atim.tv_sec = stat.st_atimespec.tv_sec;
300322
stat_ptr->st_atim.tv_nsec = stat.st_atimespec.tv_nsec;
301323

@@ -304,6 +326,16 @@ i32 wasm_lstat(i32 path_str_offset, i32 stat_offset) {
304326

305327
stat_ptr->st_ctim.tv_sec = stat.st_ctimespec.tv_sec;
306328
stat_ptr->st_ctim.tv_nsec = stat.st_ctimespec.tv_nsec;
329+
#else
330+
stat_ptr->st_atim.tv_sec = stat.st_atim.tv_sec;
331+
stat_ptr->st_atim.tv_nsec = stat.st_atim.tv_nsec;
332+
333+
stat_ptr->st_mtim.tv_sec = stat.st_mtim.tv_sec;
334+
stat_ptr->st_mtim.tv_nsec = stat.st_mtim.tv_nsec;
335+
336+
stat_ptr->st_ctim.tv_sec = stat.st_ctim.tv_sec;
337+
stat_ptr->st_ctim.tv_nsec = stat.st_ctim.tv_nsec;
338+
#endif
307339
} else if (res == -1) {
308340
return -errno;
309341
}

runtime/runtime.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,8 @@ int main(int argc, char* argv[]) {
193193
expand_memory();
194194
switch_into_runtime();
195195

196-
// FIXME: Should do a real bounds check here
197196
i32* array_ptr = get_memory_ptr_void(page_offset, argc * sizeof(i32));
198-
int string_offset = page_offset + argc * sizeof(i32);
197+
i32 string_offset = page_offset + argc * sizeof(i32);
199198
for (int i = 0; i < argc; i++) {
200199
size_t str_size = strlen(argv[i]) + 1;
201200

0 commit comments

Comments
 (0)