1
0
mirror of https://github.com/golang/go synced 2024-11-18 12:14:42 -07:00

mksyscall was treating 64-bit systems as 32-bit,

so 64-bit args like the offset in Seek were being
mishandled.  fix.

R=dsymonds
DELTA=1269  (645 added, 611 deleted, 13 changed)
OCL=30082
CL=30082
This commit is contained in:
Russ Cox 2009-06-08 22:10:48 -07:00
parent 83632c7359
commit 01b695dbff
4 changed files with 106 additions and 72 deletions

View File

@ -515,3 +515,35 @@ func TestTime(t *testing.T) {
}
}
func TestSeek(t *testing.T) {
f, err := Open("_obj/seektest", O_CREAT|O_RDWR|O_TRUNC, 0666);
if err != nil {
t.Fatalf("open _obj/seektest: %s", err);
}
const data = "hello, world\n";
io.WriteString(f, data);
type test struct {
in int64;
whence int;
out int64;
}
var tests = []test {
test{ 0, 1, int64(len(data)) },
test{ 0, 0, 0 },
test{ 5, 0, 5 },
test{ 0, 2, int64(len(data)) },
test{ 0, 0, 0 },
test{ -1, 2, int64(len(data)) - 1 },
test{ 1<<40, 0, 1<<40 },
test{ 1<<40, 2, 1<<40 + int64(len(data)) }
};
for i, tt := range tests {
off, err := f.Seek(tt.in, tt.whence);
if off != tt.out || err != nil {
t.Errorf("#%d: Seek(%v, %v) = %v, %v want %v, nil", i, tt.in, tt.whence, off, err, tt.out);
}
}
f.Close();
}

View File

@ -15,7 +15,7 @@
$cmdline = "mksyscall " . join(' ', @ARGV);
$errors = 0;
$_32bit = 0;
$_32bit = "";
if($ARGV[0] eq "-b32") {
$_32bit = "big-endian";

View File

@ -8,13 +8,6 @@ import (
"unsafe";
)
func getfsstat64(buf *Statfs_t, nbuf int, flags int) (n int, errno int) {
r0, r1, e1 := Syscall(SYS_GETFSSTAT64, uintptr(unsafe.Pointer(buf)), uintptr(nbuf), uintptr(flags));
n = int(r0);
errno = int(e1);
return;
}
func getgroups(ngid int, gid *_Gid_t) (n int, errno int) {
r0, r1, e1 := Syscall(SYS_GETGROUPS, uintptr(ngid), uintptr(unsafe.Pointer(gid)), 0);
n = int(r0);
@ -44,20 +37,12 @@ func pipe() (r int, w int, errno int) {
}
func lseek(fd int, offset int64, whence int) (newoffset uintptr, errno int) {
r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(offset >> 32), uintptr(whence), 0, 0);
r0, r1, e1 := Syscall(SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence));
newoffset = uintptr(r0);
errno = int(e1);
return;
}
func gettimeofday(tp *Timeval) (sec int64, usec int32, errno int) {
r0, r1, e1 := Syscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0);
sec = int64(r0);
usec = int32(r1);
errno = int(e1);
return;
}
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int) {
r0, r1, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)));
fd = int(r0);
@ -232,7 +217,7 @@ func Fsync(fd int) (errno int) {
}
func Ftruncate(fd int, length int64) (errno int) {
r0, r1, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), uintptr(length), uintptr(length >> 32));
r0, r1, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0);
errno = int(e1);
return;
}
@ -264,6 +249,15 @@ func Geteuid() (uid int) {
return;
}
func Getfsstat(buf []Statfs_t, flags int) (n int, errno int) {
var _p0 *Statfs_t;
if len(buf) > 0 { _p0 = &buf[0]; }
r0, r1, e1 := Syscall(SYS_GETFSSTAT64, uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(flags));
n = int(r0);
errno = int(e1);
return;
}
func Getgid() (gid int) {
r0, r1, e1 := Syscall(SYS_GETGID, 0, 0, 0);
gid = int(r0);
@ -405,7 +399,7 @@ func Pathconf(path string, name int) (val int, errno int) {
func Pread(fd int, p []byte, offset int64) (n int, errno int) {
var _p0 *byte;
if len(p) > 0 { _p0 = &p[0]; }
r0, r1, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), uintptr(offset >> 32), 0);
r0, r1, e1 := Syscall6(SYS_PREAD, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0);
n = int(r0);
errno = int(e1);
return;
@ -414,7 +408,7 @@ func Pread(fd int, p []byte, offset int64) (n int, errno int) {
func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
var _p0 *byte;
if len(p) > 0 { _p0 = &p[0]; }
r0, r1, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), uintptr(offset >> 32), 0);
r0, r1, e1 := Syscall6(SYS_PWRITE, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0);
n = int(r0);
errno = int(e1);
return;
@ -566,7 +560,7 @@ func Sync() (errno int) {
}
func Truncate(path string, length int64) (errno int) {
r0, r1, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length), uintptr(length >> 32));
r0, r1, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length), 0);
errno = int(e1);
return;
}
@ -618,5 +612,13 @@ func write(fd int, buf *byte, nbuf int) (n int, errno int) {
return;
}
func gettimeofday(tp *Timeval) (sec int64, usec int32, errno int) {
r0, r1, e1 := Syscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tp)), 0, 0);
sec = int64(r0);
usec = int32(r1);
errno = int(e1);
return;
}

View File

@ -55,44 +55,6 @@ func wait4(pid int, wstatus *_C_int, options int, rusage *Rusage) (wpid int, err
return;
}
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int) {
r0, r1, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)));
fd = int(r0);
errno = int(e1);
return;
}
func bind(s int, addr uintptr, addrlen _Socklen) (errno int) {
r0, r1, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen));
errno = int(e1);
return;
}
func connect(s int, addr uintptr, addrlen _Socklen) (errno int) {
r0, r1, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen));
errno = int(e1);
return;
}
func socket(domain int, typ int, proto int) (fd int, errno int) {
r0, r1, e1 := Syscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto));
fd = int(r0);
errno = int(e1);
return;
}
func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
r0, r1, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0);
errno = int(e1);
return;
}
func Listen(s int, n int) (errno int) {
r0, r1, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(n), 0);
errno = int(e1);
return;
}
func Access(path string, mode int) (errno int) {
r0, r1, e1 := Syscall(SYS_ACCESS, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(mode), 0);
errno = int(e1);
@ -197,7 +159,7 @@ func Faccessat(dirfd int, path string, mode int, flags int) (errno int) {
}
func Fallocate(fd int, mode int, off int64, len int64) (errno int) {
r0, r1, e1 := Syscall6(SYS_FALLOCATE, uintptr(fd), uintptr(mode), uintptr(off), uintptr(off >> 32), uintptr(len), uintptr(len >> 32));
r0, r1, e1 := Syscall6(SYS_FALLOCATE, uintptr(fd), uintptr(mode), uintptr(off), uintptr(len), 0, 0);
errno = int(e1);
return;
}
@ -264,7 +226,7 @@ func Fsync(fd int) (errno int) {
}
func Ftruncate(fd int, length int64) (errno int) {
r0, r1, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), uintptr(length), uintptr(length >> 32));
r0, r1, e1 := Syscall(SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0);
errno = int(e1);
return;
}
@ -455,7 +417,7 @@ func PivotRoot(newroot string, putold string) (errno int) {
func Pread(fd int, p []byte, offset int64) (n int, errno int) {
var _p0 *byte;
if len(p) > 0 { _p0 = &p[0]; }
r0, r1, e1 := Syscall6(SYS_PREAD64, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), uintptr(offset >> 32), 0);
r0, r1, e1 := Syscall6(SYS_PREAD64, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0);
n = int(r0);
errno = int(e1);
return;
@ -464,7 +426,7 @@ func Pread(fd int, p []byte, offset int64) (n int, errno int) {
func Pwrite(fd int, p []byte, offset int64) (n int, errno int) {
var _p0 *byte;
if len(p) > 0 { _p0 = &p[0]; }
r0, r1, e1 := Syscall6(SYS_PWRITE64, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), uintptr(offset >> 32), 0);
r0, r1, e1 := Syscall6(SYS_PWRITE64, uintptr(fd), uintptr(unsafe.Pointer(_p0)), uintptr(len(p)), uintptr(offset), 0, 0);
n = int(r0);
errno = int(e1);
return;
@ -507,7 +469,7 @@ func Rmdir(path string) (errno int) {
}
func Seek(fd int, offset int64, whence int) (off int64, errno int) {
r0, r1, e1 := Syscall6(SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(offset >> 32), uintptr(whence), 0, 0);
r0, r1, e1 := Syscall(SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence));
off = int64(r0);
errno = int(e1);
return;
@ -608,12 +570,6 @@ func Setuid(uid int) (errno int) {
return;
}
func Shutdown(fd int, how int) (errno int) {
r0, r1, e1 := Syscall(SYS_SHUTDOWN, uintptr(fd), uintptr(how), 0);
errno = int(e1);
return;
}
func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, errno int) {
r0, r1, e1 := Syscall6(SYS_SPLICE, uintptr(rfd), uintptr(unsafe.Pointer(roff)), uintptr(wfd), uintptr(unsafe.Pointer(woff)), uintptr(len), uintptr(flags));
n = int64(r0);
@ -645,7 +601,7 @@ func Sync() () {
}
func SyncFileRange(fd int, off int64, n int64, flags int) (errno int) {
r0, r1, e1 := Syscall6(SYS_SYNC_FILE_RANGE, uintptr(fd), uintptr(off), uintptr(off >> 32), uintptr(n), uintptr(n >> 32), uintptr(flags));
r0, r1, e1 := Syscall6(SYS_SYNC_FILE_RANGE, uintptr(fd), uintptr(off), uintptr(n), uintptr(flags), 0, 0);
errno = int(e1);
return;
}
@ -684,7 +640,7 @@ func Times(tms *Tms) (ticks uintptr, errno int) {
}
func Truncate(path string, length int64) (errno int) {
r0, r1, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length), uintptr(length >> 32));
r0, r1, e1 := Syscall(SYS_TRUNCATE, uintptr(unsafe.Pointer(StringBytePtr(path))), uintptr(length), 0);
errno = int(e1);
return;
}
@ -760,5 +716,49 @@ func write(fd int, p *byte, np int) (n int, errno int) {
return;
}
func accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, errno int) {
r0, r1, e1 := Syscall(SYS_ACCEPT, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen)));
fd = int(r0);
errno = int(e1);
return;
}
func bind(s int, addr uintptr, addrlen _Socklen) (errno int) {
r0, r1, e1 := Syscall(SYS_BIND, uintptr(s), uintptr(addr), uintptr(addrlen));
errno = int(e1);
return;
}
func connect(s int, addr uintptr, addrlen _Socklen) (errno int) {
r0, r1, e1 := Syscall(SYS_CONNECT, uintptr(s), uintptr(addr), uintptr(addrlen));
errno = int(e1);
return;
}
func socket(domain int, typ int, proto int) (fd int, errno int) {
r0, r1, e1 := Syscall(SYS_SOCKET, uintptr(domain), uintptr(typ), uintptr(proto));
fd = int(r0);
errno = int(e1);
return;
}
func setsockopt(s int, level int, name int, val uintptr, vallen int) (errno int) {
r0, r1, e1 := Syscall6(SYS_SETSOCKOPT, uintptr(s), uintptr(level), uintptr(name), uintptr(val), uintptr(vallen), 0);
errno = int(e1);
return;
}
func Listen(s int, n int) (errno int) {
r0, r1, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(n), 0);
errno = int(e1);
return;
}
func Shutdown(fd int, how int) (errno int) {
r0, r1, e1 := Syscall(SYS_SHUTDOWN, uintptr(fd), uintptr(how), 0);
errno = int(e1);
return;
}