Skip to content

Commit acd30e9

Browse files
dwimmerianlancetaylor
authored andcommitted
runtime: fix syscall error returns on mips/mips64/ppc64
The linux syscall functions used in runtime are designed around the calling convention of returning errors as negative numbers. On some other systems (like mips and ppc) the actual syscalls signal errors in other ways. This means that the assembly implementations of the syscall functions on these platforms need to transform the return values in the error cases to match the expected negative errno values. This was addressed for certain syscalls in https://golang.org/cl/19455 and https://golang.org/cl/89235. This patch handles the rest of the syscall functions in sys_linux_*.s that return any value for mips/mips64/ppc64. Fixes #23446 Change-Id: I302100261231f76d5850ab2c2ea080170d7dba72 GitHub-Last-Rev: e358e2b GitHub-Pull-Request: #26606 Reviewed-on: https://go-review.googlesource.com/125895 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent b8669ef commit acd30e9

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

src/runtime/sys_linux_mips64x.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
218218
MOVV size+24(FP), R7
219219
MOVV $SYS_rt_sigaction, R2
220220
SYSCALL
221+
BEQ R7, 2(PC)
222+
SUBVU R2, R0, R2 // caller expects negative errno
221223
MOVW R2, ret+32(FP)
222224
RET
223225

@@ -299,6 +301,8 @@ TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
299301
MOVW val3+32(FP), R9
300302
MOVV $SYS_futex, R2
301303
SYSCALL
304+
BEQ R7, 2(PC)
305+
SUBVU R2, R0, R2 // caller expects negative errno
302306
MOVW R2, ret+40(FP)
303307
RET
304308

@@ -321,6 +325,8 @@ TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
321325

322326
MOVV $SYS_clone, R2
323327
SYSCALL
328+
BEQ R7, 2(PC)
329+
SUBVU R2, R0, R2 // caller expects negative errno
324330

325331
// In parent, return.
326332
BEQ R2, 3(PC)
@@ -383,6 +389,8 @@ TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
383389
MOVV buf+16(FP), R6
384390
MOVV $SYS_sched_getaffinity, R2
385391
SYSCALL
392+
BEQ R7, 2(PC)
393+
SUBVU R2, R0, R2 // caller expects negative errno
386394
MOVW R2, ret+24(FP)
387395
RET
388396

@@ -391,6 +399,8 @@ TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
391399
MOVW size+0(FP), R4
392400
MOVV $SYS_epoll_create, R2
393401
SYSCALL
402+
BEQ R7, 2(PC)
403+
SUBVU R2, R0, R2 // caller expects negative errno
394404
MOVW R2, ret+8(FP)
395405
RET
396406

@@ -399,6 +409,8 @@ TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
399409
MOVW flags+0(FP), R4
400410
MOVV $SYS_epoll_create1, R2
401411
SYSCALL
412+
BEQ R7, 2(PC)
413+
SUBVU R2, R0, R2 // caller expects negative errno
402414
MOVW R2, ret+8(FP)
403415
RET
404416

@@ -424,6 +436,8 @@ TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
424436
MOVV $0, R8
425437
MOVV $SYS_epoll_pwait, R2
426438
SYSCALL
439+
BEQ R7, 2(PC)
440+
SUBVU R2, R0, R2 // caller expects negative errno
427441
MOVW R2, ret+24(FP)
428442
RET
429443

src/runtime/sys_linux_mipsx.s

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT,$0-20
234234
MOVW size+12(FP), R7
235235
MOVW $SYS_rt_sigaction, R2
236236
SYSCALL
237+
BEQ R7, 2(PC)
238+
SUBU R2, R0, R2 // caller expects negative errno
237239
MOVW R2, ret+16(FP)
238240
RET
239241

@@ -320,6 +322,8 @@ TEXT runtime·futex(SB),NOSPLIT,$20-28
320322

321323
MOVW $SYS_futex, R2
322324
SYSCALL
325+
BEQ R7, 2(PC)
326+
SUBU R2, R0, R2 // caller expects negative errno
323327
MOVW R2, ret+24(FP)
324328
RET
325329

@@ -351,11 +355,11 @@ TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0-24
351355

352356
MOVW $SYS_clone, R2
353357
SYSCALL
358+
BEQ R7, 2(PC)
359+
SUBU R2, R0, R2 // caller expects negative errno
354360

355361
// In parent, return.
356-
BEQ R2, 5(PC)
357-
SUBU R2, R0, R3
358-
CMOVN R7, R3, R2
362+
BEQ R2, 3(PC)
359363
MOVW R2, ret+20(FP)
360364
RET
361365

@@ -417,6 +421,8 @@ TEXT runtime·sched_getaffinity(SB),NOSPLIT,$0-16
417421
MOVW buf+8(FP), R6
418422
MOVW $SYS_sched_getaffinity, R2
419423
SYSCALL
424+
BEQ R7, 2(PC)
425+
SUBU R2, R0, R2 // caller expects negative errno
420426
MOVW R2, ret+12(FP)
421427
RET
422428

@@ -425,6 +431,8 @@ TEXT runtime·epollcreate(SB),NOSPLIT,$0-8
425431
MOVW size+0(FP), R4
426432
MOVW $SYS_epoll_create, R2
427433
SYSCALL
434+
BEQ R7, 2(PC)
435+
SUBU R2, R0, R2 // caller expects negative errno
428436
MOVW R2, ret+4(FP)
429437
RET
430438

@@ -433,6 +441,8 @@ TEXT runtime·epollcreate1(SB),NOSPLIT,$0-8
433441
MOVW flags+0(FP), R4
434442
MOVW $SYS_epoll_create1, R2
435443
SYSCALL
444+
BEQ R7, 2(PC)
445+
SUBU R2, R0, R2 // caller expects negative errno
436446
MOVW R2, ret+4(FP)
437447
RET
438448

@@ -456,6 +466,8 @@ TEXT runtime·epollwait(SB),NOSPLIT,$0-20
456466
MOVW timeout+12(FP), R7
457467
MOVW $SYS_epoll_wait, R2
458468
SYSCALL
469+
BEQ R7, 2(PC)
470+
SUBU R2, R0, R2 // caller expects negative errno
459471
MOVW R2, ret+16(FP)
460472
RET
461473

src/runtime/sys_linux_ppc64x.s

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ TEXT runtime·rt_sigaction(SB),NOSPLIT|NOFRAME,$0-36
193193
MOVD old+16(FP), R5
194194
MOVD size+24(FP), R6
195195
SYSCALL $SYS_rt_sigaction
196+
BVC 2(PC)
197+
NEG R3 // caller expects negative errno
196198
MOVW R3, ret+32(FP)
197199
RET
198200

@@ -388,6 +390,8 @@ TEXT runtime·futex(SB),NOSPLIT|NOFRAME,$0
388390
MOVD addr2+24(FP), R7
389391
MOVW val3+32(FP), R8
390392
SYSCALL $SYS_futex
393+
BVC 2(PC)
394+
NEG R3 // caller expects negative errno
391395
MOVW R3, ret+40(FP)
392396
RET
393397

@@ -409,6 +413,8 @@ TEXT runtime·clone(SB),NOSPLIT|NOFRAME,$0
409413
MOVD R7, -32(R4)
410414

411415
SYSCALL $SYS_clone
416+
BVC 2(PC)
417+
NEG R3 // caller expects negative errno
412418

413419
// In parent, return.
414420
CMP R3, $0
@@ -472,20 +478,26 @@ TEXT runtime·sched_getaffinity(SB),NOSPLIT|NOFRAME,$0
472478
MOVD len+8(FP), R4
473479
MOVD buf+16(FP), R5
474480
SYSCALL $SYS_sched_getaffinity
481+
BVC 2(PC)
482+
NEG R3 // caller expects negative errno
475483
MOVW R3, ret+24(FP)
476484
RET
477485

478486
// int32 runtime·epollcreate(int32 size);
479487
TEXT runtime·epollcreate(SB),NOSPLIT|NOFRAME,$0
480488
MOVW size+0(FP), R3
481489
SYSCALL $SYS_epoll_create
490+
BVC 2(PC)
491+
NEG R3 // caller expects negative errno
482492
MOVW R3, ret+8(FP)
483493
RET
484494

485495
// int32 runtime·epollcreate1(int32 flags);
486496
TEXT runtime·epollcreate1(SB),NOSPLIT|NOFRAME,$0
487497
MOVW flags+0(FP), R3
488498
SYSCALL $SYS_epoll_create1
499+
BVC 2(PC)
500+
NEG R3 // caller expects negative errno
489501
MOVW R3, ret+8(FP)
490502
RET
491503

@@ -507,6 +519,8 @@ TEXT runtime·epollwait(SB),NOSPLIT|NOFRAME,$0
507519
MOVW nev+16(FP), R5
508520
MOVW timeout+20(FP), R6
509521
SYSCALL $SYS_epoll_wait
522+
BVC 2(PC)
523+
NEG R3 // caller expects negative errno
510524
MOVW R3, ret+24(FP)
511525
RET
512526

0 commit comments

Comments
 (0)