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>
31 #include <sys/xattr.h>
43 #ifdef CVMFS_NAMESPACE_GUARD
44 namespace CVMFS_NAMESPACE_GUARD {
54 #define MSG_NOSIGNAL SO_NOSIGPIPE
60 #define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
62 #define platform_sighandler_t sig_t
65 std::vector<std::string> result;
66 struct statfs *mntbufp;
67 int num_elems = getmntinfo(&mntbufp, MNT_NOWAIT);
68 for (
int i = 0; i < num_elems; ++i) {
69 result.push_back(mntbufp[i].f_mntonname);
75 const int flags = lazy ? MNT_FORCE : 0;
76 int retval = unmount(mountpoint, flags);
82 int retval = unmount(mountpoint, MNT_FORCE);
89 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) \
90 && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
94 *lock = OS_UNFAIR_LOCK_INIT;
101 return os_unfair_lock_trylock(lock) ? 0 : -1;
105 os_unfair_lock_unlock(lock);
119 return OSSpinLockTry(lock) ? 0 : -1;
123 OSSpinLockUnlock(lock);
135 int retval = sigemptyset(&sigset);
137 retval = sigaddset(&sigset, signum);
140 retval = sigwait(&sigset, &result);
163 return stat(path, buf);
167 return lstat(path, buf);
171 return fstat(filedes, buf);
175 std::string *value) {
179 retval = getxattr(path.c_str(), name.c_str(), buffer,
size, 0, 0);
182 buffer = smalloc(size);
183 retval = getxattr(path.c_str(), name.c_str(), buffer,
size, 0, 0);
185 if ((retval < 0) || (retval >
size)) {
190 value->assign(static_cast<const char *>(buffer), size);
199 const std::string &value) {
200 int retval = setxattr(path.c_str(), name.c_str(), value.c_str(), value.size(),
206 const std::string &value) {
207 int retval = setxattr(path.c_str(),
217 void *value,
size_t size) {
218 return getxattr(path, name, value, size, 0 , XATTR_NOFOLLOW);
222 return listxattr(path, list, size, XATTR_NOFOLLOW);
226 fcntl(filedes, F_RDAHEAD, 0);
227 fcntl(filedes, F_NOCACHE, 1);
231 const off_t length) {
242 char *buffer_line = NULL;
243 size_t buffer_size = 0;
244 const int res = getline(&buffer_line, &buffer_size, f);
251 line->assign(buffer_line);
257 uint64_t val_abs = mach_absolute_time();
259 mach_timebase_info_data_t info;
260 mach_timebase_info(&info);
261 uint64_t val_ns = val_abs * (info.numer / info.denom);
262 return val_ns * 1e-9;
266 uint64_t val_abs = mach_absolute_time();
268 mach_timebase_info_data_t info;
269 mach_timebase_info(&info);
270 uint64_t val_ns = val_abs * (info.numer / info.denom);
276 int ret = gettimeofday(&tv, NULL);
278 uint64_t time = tv.tv_sec * 1e6 + tv.tv_usec * 1e3;
287 reinterpret_cast<char *>(alloca(strlen((s)) + 1)), (s))
290 return "lib" + base_name +
".dylib";
294 return std::string(_dyld_get_image_name(0));
301 int mib[] = {CTL_HW, HW_MEMSIZE};
306 len =
sizeof(ramsize);
307 rc = sysctl(mib, 2, &ramsize, &len, NULL, 0);
312 #ifdef CVMFS_NAMESPACE_GUARD
316 inline int prctl(
int, uint64_t, uint64_t, uint64_t, uint64_t) {
return 0; }
317 #define PR_SET_DUMPABLE 0
319 #endif // CVMFS_UTIL_PLATFORM_OSX_H_
assert((mem||(size==0))&&"Out Of Memory")