Commit | Line | Data |
---|---|---|
b728d87e MD |
1 | #ifndef _UST_COMPAT_H |
2 | #define _UST_COMPAT_H | |
3 | ||
4 | /* | |
e92f3e28 | 5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
b728d87e | 6 | * |
e92f3e28 MD |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; only | |
10 | * version 2.1 of the License. | |
b728d87e | 11 | * |
e92f3e28 MD |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
b728d87e MD |
20 | */ |
21 | ||
69df1193 MD |
22 | /* |
23 | * sched_getcpu. | |
24 | */ | |
25 | #ifdef __linux__ | |
e4486ebc MD |
26 | |
27 | #ifdef __UCLIBC__ | |
69df1193 | 28 | #include <sys/syscall.h> |
e4486ebc MD |
29 | #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache) |
30 | static inline | |
31 | int sched_getcpu(void) | |
32 | { | |
33 | int c, s; | |
34 | ||
35 | s = __getcpu(&c, NULL, NULL); | |
36 | return (s == -1) ? s : c; | |
37 | } | |
38 | #endif /* __UCLIBC__ */ | |
69df1193 MD |
39 | |
40 | #else | |
41 | #error "Please add support for your OS into liblttng-ust/compat.h." | |
42 | #endif | |
43 | ||
44 | /* | |
45 | * lttng_ust_getprocname. | |
46 | */ | |
47 | #ifdef __linux__ | |
48 | ||
49 | #include <sys/prctl.h> | |
50 | ||
51 | #define LTTNG_UST_PROCNAME_LEN 17 | |
52 | ||
53 | static inline | |
54 | void lttng_ust_getprocname(char *name) | |
55 | { | |
56 | (void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0); | |
57 | } | |
58 | ||
59 | #elif defined(__FreeBSD__) | |
60 | #include <stdlib.h> | |
61 | #include <string.h> | |
62 | ||
63 | /* | |
64 | * Limit imposed by Linux UST-sessiond ABI. | |
65 | */ | |
66 | #define LTTNG_UST_PROCNAME_LEN 17 | |
67 | ||
68 | /* | |
69 | * Acts like linux prctl, the string is not necessarily 0-terminated if | |
70 | * 16-byte long. | |
71 | */ | |
72 | static inline | |
73 | void lttng_ust_getprocname(char *name) | |
74 | { | |
75 | const char *bsd_name; | |
76 | ||
77 | bsd_name = getprogname(); | |
78 | if (!bsd_name) | |
79 | name[0] = '\0'; | |
80 | memcpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1); | |
81 | } | |
82 | ||
83 | #endif | |
84 | ||
b728d87e | 85 | #endif /* _UST_COMPAT_H */ |