7 #ifndef CVMFS_UTIL_PLATFORM_OSX_H_
8 #define CVMFS_UTIL_PLATFORM_OSX_H_
13 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
14 __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
17 #include <libkern/OSAtomic.h>
18 #endif // defined(__MAC_OS_X_VERSION_MIN_REQUIRED) &&
20 #include <mach-o/dyld.h>
21 #include <mach/mach.h>
22 #include <mach/mach_time.h>
24 #include <sys/mount.h>
25 #include <sys/param.h>
27 #include <sys/sysctl.h>
28 #include <sys/types.h>
29 #include <sys/ucred.h>
30 #include <sys/xattr.h>
42 #ifdef CVMFS_NAMESPACE_GUARD
43 namespace CVMFS_NAMESPACE_GUARD {
53 #define MSG_NOSIGNAL SO_NOSIGPIPE
59 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
61 #define platform_sighandler_t sig_t
64 std::vector<std::string> result;
65 struct statfs *mntbufp;
66 int num_elems = getmntinfo(&mntbufp, MNT_NOWAIT);
67 for (
int i = 0; i < num_elems; ++i) {
68 result.push_back(mntbufp[i].f_mntonname);
74 const int flags = lazy ? MNT_FORCE : 0;
75 int retval = unmount(mountpoint, flags);
81 int retval = unmount(mountpoint, MNT_FORCE);
88 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
89 __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
93 *lock = OS_UNFAIR_LOCK_INIT;
100 return os_unfair_lock_trylock(lock) ? 0 : -1;
104 os_unfair_lock_unlock(lock);
118 return OSSpinLockTry(lock) ? 0 : -1;
122 OSSpinLockUnlock(lock);
134 int retval = sigemptyset(&sigset);
136 retval = sigaddset(&sigset, signum);
139 retval = sigwait(&sigset, &result);
162 return stat(path, buf);
166 return lstat(path, buf);
170 return fstat(filedes, buf);
174 std::string *value) {
178 retval = getxattr(path.c_str(), name.c_str(), buffer,
size, 0, 0);
181 buffer = smalloc(size);
182 retval = getxattr(path.c_str(), name.c_str(), buffer,
size, 0, 0);
184 if ((retval < 0) || (retval >
size)) {
189 value->assign(static_cast<const char *>(buffer), size);
198 const std::string &value) {
200 setxattr(path.c_str(), name.c_str(), value.c_str(), value.size(), 0, 0);
205 const std::string &value) {
218 void *value,
size_t size) {
219 return getxattr(path, name, value, size, 0 , XATTR_NOFOLLOW);
223 return listxattr(path, list, size, XATTR_NOFOLLOW);
227 fcntl(filedes, F_RDAHEAD, 0);
228 fcntl(filedes, F_NOCACHE, 1);
232 const off_t length) {
243 char *buffer_line = NULL;
244 size_t buffer_size = 0;
245 const int res = getline(&buffer_line, &buffer_size, f);
252 line->assign(buffer_line);
258 uint64_t val_abs = mach_absolute_time();
260 mach_timebase_info_data_t info;
261 mach_timebase_info(&info);
262 uint64_t val_ns = val_abs * (info.numer / info.denom);
263 return val_ns * 1e-9;
267 uint64_t val_abs = mach_absolute_time();
269 mach_timebase_info_data_t info;
270 mach_timebase_info(&info);
271 uint64_t val_ns = val_abs * (info.numer / info.denom);
277 int ret = gettimeofday(&tv, NULL);
279 uint64_t time = tv.tv_sec * 1e6 + tv.tv_usec * 1e3;
288 reinterpret_cast<char *>(alloca(strlen((s)) + 1)), (s))
291 return "lib" + base_name +
".dylib";
295 return std::string(_dyld_get_image_name(0));
302 int mib[] = {CTL_HW, HW_MEMSIZE};
307 len =
sizeof(ramsize);
308 rc = sysctl(mib, 2, &ramsize, &len, NULL, 0);
313 #ifdef CVMFS_NAMESPACE_GUARD
317 inline int prctl(
int, uint64_t, uint64_t, uint64_t, uint64_t) {
return 0; }
318 #define PR_SET_DUMPABLE 0
320 #endif // CVMFS_UTIL_PLATFORM_OSX_H_
assert((mem||(size==0))&&"Out Of Memory")