Skip to content

Commit 2634164

Browse files
atrosinenkokripken
authored andcommitted
Fix the pwrite64 system call. (emscripten-core#4838)
There was an implementation of the `pwrite64` syscall in Emscripten, but when invoked it crashed because of ReferenceError. This commit replaces the `nbyte` variable with the `count` one and adds some tests for this syscall.
1 parent a66b3fb commit 2634164

File tree

4 files changed

+22
-6
lines changed

4 files changed

+22
-6
lines changed

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,4 @@ a license to everyone to use it as detailed in LICENSE.)
271271
* Vladimir Davidovich <[email protected]>
272272
* Christophe Gragnic <[email protected]>
273273
* Murphy McCauley <[email protected]>
274+
* Anatoly Trosinenko <[email protected]>

src/library_syscall.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,11 +838,8 @@ var SyscallsLibrary = {
838838
return FS.read(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, count, offset);
839839
},
840840
__syscall181: function(which, varargs) { // pwrite64
841-
#if SYSCALL_DEBUG
842-
Module.printErr('warning: untested syscall');
843-
#endif
844841
var stream = SYSCALLS.getStreamFromFD(), buf = SYSCALLS.get(), count = SYSCALLS.get(), zero = SYSCALLS.getZero(), offset = SYSCALLS.get64();
845-
return FS.write(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, nbyte, offset);
842+
return FS.write(stream, {{{ heapAndOffset('HEAP8', 'buf') }}}, count, offset);
846843
},
847844
__syscall183: function(which, varargs) { // getcwd
848845
var buf = SYSCALLS.get(), size = SYSCALLS.get();

tests/unistd/io.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ int main() {
156156
printf("errno: %d\n\n", errno);
157157
errno = 0;
158158

159+
printf("pwrite to the middle of file: %d\n", pwrite(f, writeBuffer + 2, 3, 17));
160+
printf("errno: %d\n", errno);
161+
printf("seek: %d\n\n", lseek(f, 0, SEEK_CUR));
162+
errno = 0;
163+
164+
printf("pwrite past end of file: %d\n", pwrite(f, writeBuffer, 5, 32));
165+
printf("errno: %d\n", errno);
166+
printf("seek: %d\n\n", lseek(f, 0, SEEK_CUR));
167+
errno = 0;
168+
159169
int bytesRead;
160170
printf("seek: %d\n", lseek(f, 0, SEEK_SET));
161171
printf("read after write: %d\n", bytesRead = read(f, readBuffer, sizeof readBuffer));

tests/unistd/io.out

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,15 @@ seek: 23
6666
write after end of file: 8
6767
errno: 0
6868

69+
pwrite to the middle of file: 3
70+
errno: 0
71+
seek: 31
72+
73+
pwrite past end of file: 5
74+
errno: 0
75+
seek: 31
76+
6977
seek: 0
70-
read after write: 31
78+
read after write: 37
7179
errno: 0
72-
final: wri4567890wri\0\0\0\0\0\0\0\0\0\0writeme\0
80+
final: wri4567890wri\0\0\0\0ite\0\0\0writeme\0\0write

0 commit comments

Comments
 (0)