Skip to content
This repository was archived by the owner on Apr 25, 2021. It is now read-only.

Commit dc68d33

Browse files
committed
VFS_READ 고침 (기본 크기: 4096)
1 parent 627d58f commit dc68d33

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

src/main/java/kr/pe/ecmaxp/openpython/arch/OpenPythonInterruptHandler.kt

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -463,31 +463,41 @@ class OpenPythonInterruptHandler(val vm: OpenPythonVirtualMachine) {
463463
}
464464
}
465465
SYS_VFS_READ -> {
466-
val ret = fh("read", intr.r1)(machine)
467-
when {
468-
ret.error != null -> {
469-
ret.error.printStackTrace()
470-
return 1
471-
}
472-
ret.args != null -> {
473-
if (ret.args.size != 1) {
466+
var size = Math.min(intr.r1, 4096)
467+
var pos = 0
468+
val buffer = ByteArray(size)
469+
470+
while (pos < size) {
471+
val ret = fh("read", size - pos)(machine)
472+
when {
473+
ret.error != null -> {
474+
ret.error.printStackTrace()
474475
return MP_EPERM
475476
}
477+
ret.args != null -> {
478+
if (ret.args.size != 1) {
479+
return MP_EPERM
480+
}
476481

477-
val arg = ret.args[0]
478-
return when (arg) {
479-
is ByteArray -> {
480-
intr.memory.writeBuffer(intr.r2, arg)
481-
intr.memory.writeInt(intr.r3, arg.size)
482-
0
482+
val arg = ret.args[0]
483+
when (arg) {
484+
is ByteArray -> {
485+
if (arg.size == 0) {
486+
size = pos
487+
} else {
488+
System.arraycopy(arg, 0, buffer, pos, Math.min(arg.size, size - pos))
489+
pos += arg.size
490+
}
491+
}
492+
null -> size = pos
483493
}
484-
null -> // EOF
485-
0
486-
else -> MP_EPERM
487494
}
488495
}
489-
else -> return MP_EPERM
490496
}
497+
498+
intr.memory.writeBuffer(intr.r2, buffer)
499+
intr.memory.writeInt(intr.r3, pos)
500+
return MP_OK
491501
}
492502
SYS_VFS_WRITE -> {
493503
val buf = intr.readBuffer(intr.r1, intr.r2)

0 commit comments

Comments
 (0)