diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-29 20:02:31 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2012-02-29 20:02:31 +0000 |
commit | 9e4aaf6e3f20974a57fbab91160ad023aaaa424b (patch) | |
tree | a76090660cf29338112a978aac141d863ef02a82 /libgo/go | |
parent | 6f9d8b766328b49f624395cabf9f3848899302a6 (diff) | |
download | gcc-9e4aaf6e3f20974a57fbab91160ad023aaaa424b.tar.gz |
syscall: Fill out GNU/Linux support.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184669 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libgo/go')
-rw-r--r-- | libgo/go/syscall/libcall_linux.go | 101 | ||||
-rw-r--r-- | libgo/go/syscall/libcall_posix.go | 32 | ||||
-rw-r--r-- | libgo/go/syscall/lsf_linux.go | 4 |
3 files changed, 94 insertions, 43 deletions
diff --git a/libgo/go/syscall/libcall_linux.go b/libgo/go/syscall/libcall_linux.go index 8a3d8c0e65e..cb04eac9036 100644 --- a/libgo/go/syscall/libcall_linux.go +++ b/libgo/go/syscall/libcall_linux.go @@ -160,20 +160,17 @@ func PtraceAttach(pid int) (err error) { return ptrace(PTRACE_ATTACH, pid, 0, 0) func PtraceDetach(pid int) (err error) { return ptrace(PTRACE_DETACH, pid, 0, 0) } -// FIXME: mksysinfo needs to produce LINUX_REBOOT_MAGIC[12]. - -// //sys reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error) -// //reboot(magic1 uint, magic2 uint, cmd int, arg *byte) int -// func Reboot(cmd int) (err error) { -// return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "") -// } +//sys reboot(magic1 uint, magic2 uint, cmd int, arg string) (err error) +//reboot(magic1 uint, magic2 uint, cmd int, arg *byte) int +func Reboot(cmd int) (err error) { + return reboot(LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, cmd, "") +} //sys Acct(path string) (err error) //acct(path *byte) int -// FIXME: mksysinfo Timex -// //sys Adjtimex(buf *Timex) (state int, err error) -// //adjtimex(buf *Timex) int +//sys Adjtimex(buf *Timex) (state int, err error) +//adjtimex(buf *Timex) int //sys Faccessat(dirfd int, path string, mode uint32, flags int) (err error) //faccessat(dirfd int, pathname *byte, mode int, flags int) int @@ -198,10 +195,56 @@ func Gettid() (tid int) { return int(r1) } -// FIXME: mksysinfo linux_dirent -// Or just abandon this function. -// //sys Getdents(fd int, buf []byte) (n int, err error) -// //getdents64(fd int, buf *byte, count uint) +func Getdents(fd int, buf []byte) (n int, err error) { + var p *byte + if len(buf) > 0 { + p = &buf[0] + } else { + p = (*byte)(unsafe.Pointer(&_zero)) + } + entersyscall() + r1, _, errno := Syscall(SYS_GETDENTS64, uintptr(fd), uintptr(unsafe.Pointer(p)), uintptr(len(buf))) + n = int(r1) + if n < 0 { + err = errno + } + exitsyscall() + return +} + +func clen(n []byte) int { + for i := 0; i < len(n); i++ { + if n[i] == 0 { + return i + } + } + return len(n) +} + +func ReadDirent(fd int, buf []byte) (n int, err error) { + return Getdents(fd, buf) +} + +func ParseDirent(buf []byte, max int, names []string) (consumed int, count int, newnames []string) { + origlen := len(buf) + count = 0 + for max != 0 && len(buf) > 0 { + dirent := (*Dirent)(unsafe.Pointer(&buf[0])) + buf = buf[dirent.Reclen:] + if dirent.Ino == 0 { // File absent in directory. + continue + } + bytes := (*[10000]byte)(unsafe.Pointer(&dirent.Name[0])) + var name = string(bytes[0:clen(bytes[:])]) + if name == "." || name == ".." { // Useless names + continue + } + max-- + count++ + names = append(names, name) + } + return origlen - len(buf), count, names +} //sys InotifyAddWatch(fd int, pathname string, mask uint32) (watchdesc int, err error) //inotify_add_watch(fd int, pathname *byte, mask uint32) int @@ -209,9 +252,8 @@ func Gettid() (tid int) { //sysnb InotifyInit() (fd int, err error) //inotify_init() int -// FIXME: Only in glibc 2.9 and later. -// //sysnb InotifyInit1(flags int) (fd int, err error) -// //inotify_init1(flags int) int +//sysnb InotifyInit1(flags int) (fd int, err error) +//inotify_init1(flags int) int //sysnb InotifyRmWatch(fd int, watchdesc uint32) (success int, err error) //inotify_rm_watch(fd int, wd uint32) int @@ -284,20 +326,22 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i //sys Statfs(path string, buf *Statfs_t) (err error) //statfs(path *byte, buf *Statfs_t) int -// FIXME: Only in glibc 2.6 and later. -// //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) -// //sync_file_range(fd int, off Offset_t, n Offset_t, flags uint) int +//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) +//sync_file_range(fd int, off Offset_t, n Offset_t, flags uint) int -// FIXME: mksysinfo Sysinfo_t -// //sysnb Sysinfo(info *Sysinfo_t) (err error) -// //sysinfo(info *Sysinfo_t) int +//sysnb Sysinfo(info *Sysinfo_t) (err error) +//sysinfo(info *Sysinfo_t) int //sys Tee(rfd int, wfd int, len int, flags int) (n int64, err error) //tee(rfd int, wfd int, len Size_t, flags uint) Ssize_t -// FIXME: Only available as a syscall. -// //sysnb Tgkill(tgid int, tid int, sig int) (err error) -// //tgkill(tgid int, tid int, sig int) int +func Tgkill(tgid, tid, sig int) error { + r1, _, errno := Syscall(SYS_TGKILL, uintptr(tgid), uintptr(tid), uintptr(sig)) + if r1 < 0 { + return errno + } + return nil +} //sys unlinkat(dirfd int, path string, flags int) (err error) //unlinkat(dirfd int, path *byte, flags int) int @@ -312,6 +356,5 @@ func Unlinkat(dirfd int, path string) (err error) { //sys Unshare(flags int) (err error) //unshare(flags int) int -// FIXME: mksysinfo Ustat_t -// //sys Ustat(dev int, ubuf *Ustat_t) (err error) -// //ustat(dev _dev_t, ubuf *Ustat_t) int +//sys Ustat(dev int, ubuf *Ustat_t) (err error) +//ustat(dev _dev_t, ubuf *Ustat_t) int diff --git a/libgo/go/syscall/libcall_posix.go b/libgo/go/syscall/libcall_posix.go index 1226c1cfbd4..3901fe094eb 100644 --- a/libgo/go/syscall/libcall_posix.go +++ b/libgo/go/syscall/libcall_posix.go @@ -61,6 +61,18 @@ func Getwd() (ret string, err error) { } } +func Getcwd(buf []byte) (n int, err error) { + err = getcwd(&buf[0], Size_t(len(buf))) + if err == nil { + i := 0 + for buf[i] != 0 { + i++ + } + n = i + 1 + } + return +} + //sysnb getgroups(size int, list *Gid_t) (nn int, err error) //getgroups(size int, list *Gid_t) int @@ -226,9 +238,8 @@ func FDZero(set *FdSet) { //sysnb Getppid() (ppid int) //getppid() Pid_t -// FIXME: mksysinfo Rlimit -// //sysnb Getrlimit(resource int, rlim *Rlimit) (err error) -// //getrlimit(resource int, rlim *Rlimit) int +//sysnb Getrlimit(resource int, rlim *Rlimit) (err error) +//getrlimit(resource int, rlim *Rlimit) int //sysnb Getrusage(who int, rusage *Rusage) (err error) //getrusage(who int, rusage *Rusage) int @@ -296,9 +307,8 @@ func Gettimeofday(tv *Timeval) (err error) { //sysnb Setreuid(ruid int, euid int) (err error) //setreuid(ruid Uid_t, euid Uid_t) int -// FIXME: mksysinfo Rlimit -// //sysnb Setrlimit(resource int, rlim *Rlimit) (err error) -// //setrlimit(resource int, rlim *Rlimit) int +//sysnb Setrlimit(resource int, rlim *Rlimit) (err error) +//setrlimit(resource int, rlim *Rlimit) int //sysnb Setsid() (pid int, err error) //setsid() Pid_t @@ -319,9 +329,8 @@ func Settimeofday(tv *Timeval) (err error) { //sys Sync() //sync() -// FIXME: mksysinfo Time_t -// //sysnb Time(t *Time_t) (tt Time_t, err error) -// //time(t *Time_t) Time_t +//sysnb Time(t *Time_t) (tt Time_t, err error) +//time(t *Time_t) Time_t //sysnb Times(tms *Tms) (ticks uintptr, err error) //times(tms *Tms) _clock_t @@ -332,9 +341,8 @@ func Settimeofday(tv *Timeval) (err error) { //sys Unlink(path string) (err error) //unlink(path *byte) int -// FIXME: mksysinfo Utimbuf -// //sys Utime(path string, buf *Utimbuf) (err error) -// //utime(path *byte, buf *Utimbuf) int +//sys Utime(path string, buf *Utimbuf) (err error) +//utime(path *byte, buf *Utimbuf) int //sys Write(fd int, p []byte) (n int, err error) //write(fd int, buf *byte, count Size_t) Ssize_t diff --git a/libgo/go/syscall/lsf_linux.go b/libgo/go/syscall/lsf_linux.go index 05d653b4aa0..5296cec9c6e 100644 --- a/libgo/go/syscall/lsf_linux.go +++ b/libgo/go/syscall/lsf_linux.go @@ -69,10 +69,10 @@ func AttachLsf(fd int, i []SockFilter) error { var p SockFprog p.Len = uint16(len(i)) p.Filter = (*SockFilter)(unsafe.Pointer(&i[0])) - return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, uintptr(unsafe.Pointer(&p)), unsafe.Sizeof(p)) + return setsockopt(fd, SOL_SOCKET, SO_ATTACH_FILTER, (*byte)(unsafe.Pointer(&p)), Socklen_t(unsafe.Sizeof(p))) } func DetachLsf(fd int) error { var dummy int - return setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, uintptr(unsafe.Pointer(&dummy)), unsafe.Sizeof(dummy)) + return setsockopt(fd, SOL_SOCKET, SO_DETACH_FILTER, (*byte)(unsafe.Pointer(&dummy)), Socklen_t(unsafe.Sizeof(dummy))) } |