-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
unix: match ioctl req argument type to libc type
On Solaris, AIX, and zOS, the req argument of ioctl() is a signed int, not an unsigned long like on other platforms, which means many constants are negative, causing friction when passing them to a uint argument. Correct the signature of these functions to pass the req argument as signed, just like libc. Fixes golang/go#59030. Change-Id: Ia14e92a150f4b5fb9488c5032ca296cb786e9811 Reviewed-on: https://go-review.googlesource.com/c/sys/+/476515 Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan Mills <[email protected]> Run-TryBot: Jason Donenfeld <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Nahum Shalman <[email protected]>
- Loading branch information
Showing
11 changed files
with
103 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright 2018 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
//go:build aix || solaris | ||
// +build aix solaris | ||
|
||
package unix | ||
|
||
import ( | ||
"unsafe" | ||
) | ||
|
||
// ioctl itself should not be exposed directly, but additional get/set | ||
// functions for specific types are permissible. | ||
|
||
// IoctlSetInt performs an ioctl operation which sets an integer value | ||
// on fd, using the specified request number. | ||
func IoctlSetInt(fd int, req int, value int) error { | ||
return ioctl(fd, req, uintptr(value)) | ||
} | ||
|
||
// IoctlSetPointerInt performs an ioctl operation which sets an | ||
// integer value on fd, using the specified request number. The ioctl | ||
// argument is called with a pointer to the integer value, rather than | ||
// passing the integer value directly. | ||
func IoctlSetPointerInt(fd int, req int, value int) error { | ||
v := int32(value) | ||
return ioctlPtr(fd, req, unsafe.Pointer(&v)) | ||
} | ||
|
||
// IoctlSetWinsize performs an ioctl on fd with a *Winsize argument. | ||
// | ||
// To change fd's window size, the req argument should be TIOCSWINSZ. | ||
func IoctlSetWinsize(fd int, req int, value *Winsize) error { | ||
// TODO: if we get the chance, remove the req parameter and | ||
// hardcode TIOCSWINSZ. | ||
return ioctlPtr(fd, req, unsafe.Pointer(value)) | ||
} | ||
|
||
// IoctlSetTermios performs an ioctl on fd with a *Termios. | ||
// | ||
// The req value will usually be TCSETA or TIOCSETA. | ||
func IoctlSetTermios(fd int, req int, value *Termios) error { | ||
// TODO: if we get the chance, remove the req parameter. | ||
return ioctlPtr(fd, req, unsafe.Pointer(value)) | ||
} | ||
|
||
// IoctlGetInt performs an ioctl operation which gets an integer value | ||
// from fd, using the specified request number. | ||
// | ||
// A few ioctl requests use the return value as an output parameter; | ||
// for those, IoctlRetInt should be used instead of this function. | ||
func IoctlGetInt(fd int, req int) (int, error) { | ||
var value int | ||
err := ioctlPtr(fd, req, unsafe.Pointer(&value)) | ||
return value, err | ||
} | ||
|
||
func IoctlGetWinsize(fd int, req int) (*Winsize, error) { | ||
var value Winsize | ||
err := ioctlPtr(fd, req, unsafe.Pointer(&value)) | ||
return &value, err | ||
} | ||
|
||
func IoctlGetTermios(fd int, req int) (*Termios, error) { | ||
var value Termios | ||
err := ioctlPtr(fd, req, unsafe.Pointer(&value)) | ||
return &value, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.