LEFT | RIGHT |
1 // Copyright 2009,2010 The Go Authors. All rights reserved. | 1 // Copyright 2009,2010 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // Darwin system calls. | 5 // Darwin system calls. |
6 // This file is compiled as ordinary Go code, | 6 // This file is compiled as ordinary Go code, |
7 // but it is also input to mksyscall, | 7 // but it is also input to mksyscall, |
8 // which parses the //sys lines and generates system call stubs. | 8 // which parses the //sys lines and generates system call stubs. |
9 // Note that sometimes we use a lowercase //sys name and wrap | 9 // Note that sometimes we use a lowercase //sys name and wrap |
10 // it in our own nicer implementation, either here or in | 10 // it in our own nicer implementation, either here or in |
11 // syscall_bsd.go or syscall_unix.go. | 11 // syscall_bsd.go or syscall_unix.go. |
12 | 12 |
13 package syscall | 13 package syscall |
14 | 14 |
15 import ( | 15 import ( |
16 errorspkg "errors" | 16 errorspkg "errors" |
17 "unsafe" | 17 "unsafe" |
18 ) | 18 ) |
| 19 |
| 20 const ImplementsGetwd = true |
| 21 |
| 22 func Getwd() (string, error) { |
| 23 buf := make([]byte, 2048) |
| 24 attrs, err := getAttrList(".", attrList{CommonAttr: attrCmnFullpath}, bu
f, 0) |
| 25 if err == nil && len(attrs) == 1 && len(attrs[0]) >= 2 { |
| 26 wd := string(attrs[0]) |
| 27 // Sanity check that it's an absolute path and ends |
| 28 // in a null byte, which we then strip. |
| 29 if wd[0] == '/' && wd[len(wd)-1] == 0 { |
| 30 return wd[:len(wd)-1], nil |
| 31 } |
| 32 } |
| 33 // If pkg/os/getwd.go gets ENOTSUP, it will fall back to the |
| 34 // slow algorithm. |
| 35 return "", ENOTSUP |
| 36 } |
19 | 37 |
20 type SockaddrDatalink struct { | 38 type SockaddrDatalink struct { |
21 Len uint8 | 39 Len uint8 |
22 Family uint8 | 40 Family uint8 |
23 Index uint16 | 41 Index uint16 |
24 Type uint8 | 42 Type uint8 |
25 Nlen uint8 | 43 Nlen uint8 |
26 Alen uint8 | 44 Alen uint8 |
27 Slen uint8 | 45 Slen uint8 |
28 Data [12]int8 | 46 Data [12]int8 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 102 } |
85 return origlen - len(buf), count, names | 103 return origlen - len(buf), count, names |
86 } | 104 } |
87 | 105 |
88 //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error) | 106 //sys ptrace(request int, pid int, addr uintptr, data uintptr) (err error) |
89 func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) } | 107 func PtraceAttach(pid int) (err error) { return ptrace(PT_ATTACH, pid, 0, 0) } |
90 func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) } | 108 func PtraceDetach(pid int) (err error) { return ptrace(PT_DETACH, pid, 0, 0) } |
91 | 109 |
92 const ( | 110 const ( |
93 attrBitMapCount = 5 | 111 attrBitMapCount = 5 |
94 » AttrCmnFullpath = 0x08000000 | 112 » attrCmnFullpath = 0x08000000 |
95 ) | 113 ) |
96 | 114 |
97 type AttrList struct { | 115 type attrList struct { |
98 bitmapCount uint16 | 116 bitmapCount uint16 |
99 _ uint16 | 117 _ uint16 |
100 CommonAttr uint32 | 118 CommonAttr uint32 |
101 VolAttr uint32 | 119 VolAttr uint32 |
102 DirAttr uint32 | 120 DirAttr uint32 |
103 FileAttr uint32 | 121 FileAttr uint32 |
104 Forkattr uint32 | 122 Forkattr uint32 |
105 } | 123 } |
106 | 124 |
107 func GetAttrList(path string, attrList AttrList, attrBuf []byte, options uint) (
attrs [][]byte, err error) { | 125 func getAttrList(path string, attrList attrList, attrBuf []byte, options uint) (
attrs [][]byte, err error) { |
108 if len(attrBuf) < 4 { | 126 if len(attrBuf) < 4 { |
109 return nil, errorspkg.New("attrBuf too small") | 127 return nil, errorspkg.New("attrBuf too small") |
110 } | 128 } |
111 attrList.bitmapCount = attrBitMapCount | 129 attrList.bitmapCount = attrBitMapCount |
112 | 130 |
113 var _p0 *byte | 131 var _p0 *byte |
114 _p0, err = BytePtrFromString(path) | 132 _p0, err = BytePtrFromString(path) |
115 if err != nil { | 133 if err != nil { |
116 return nil, err | 134 return nil, err |
117 } | 135 } |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 // Poll_nocancel | 480 // Poll_nocancel |
463 // Msgsnd_nocancel | 481 // Msgsnd_nocancel |
464 // Msgrcv_nocancel | 482 // Msgrcv_nocancel |
465 // Sem_wait_nocancel | 483 // Sem_wait_nocancel |
466 // Aio_suspend_nocancel | 484 // Aio_suspend_nocancel |
467 // __sigwait_nocancel | 485 // __sigwait_nocancel |
468 // __semwait_signal_nocancel | 486 // __semwait_signal_nocancel |
469 // __mac_mount | 487 // __mac_mount |
470 // __mac_get_mount | 488 // __mac_get_mount |
471 // __mac_getfsstat | 489 // __mac_getfsstat |
LEFT | RIGHT |