Commit | Line | Data |
---|---|---|
b728d87e MD |
1 | #ifndef _UST_COMPAT_H |
2 | #define _UST_COMPAT_H | |
3 | ||
4 | /* | |
5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6 | * | |
7 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED | |
8 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. | |
9 | * | |
10 | * Permission is hereby granted to use or copy this program | |
11 | * for any purpose, provided the above notices are retained on all copies. | |
12 | * Permission to modify the code and to distribute modified code is granted, | |
13 | * provided the above notices are retained, and a notice that the code was | |
14 | * modified is included with the above copyright notice. | |
15 | */ | |
16 | ||
e4486ebc MD |
17 | /* |
18 | * sched_getcpu. | |
19 | */ | |
20 | #ifdef __linux__ | |
21 | ||
22 | #ifdef __UCLIBC__ | |
23 | #include <sys/syscall.h> | |
24 | #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache) | |
25 | static inline | |
26 | int sched_getcpu(void) | |
27 | { | |
28 | int c, s; | |
29 | ||
30 | s = __getcpu(&c, NULL, NULL); | |
31 | return (s == -1) ? s : c; | |
32 | } | |
33 | #endif /* __UCLIBC__ */ | |
34 | ||
35 | #else | |
36 | #error "Please add support for your OS into liblttng-ust/compat.h." | |
37 | #endif | |
38 | ||
48621a42 MD |
39 | /* |
40 | * lttng_ust_getprocname. | |
41 | */ | |
42 | #ifdef __linux__ | |
43 | ||
44 | #include <sys/prctl.h> | |
45 | ||
46 | #define LTTNG_UST_PROCNAME_LEN 17 | |
47 | ||
48 | static inline | |
49 | void lttng_ust_getprocname(char *name) | |
50 | { | |
51 | (void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0); | |
52 | } | |
53 | ||
54 | #elif defined(__FreeBSD__) | |
55 | #include <stdlib.h> | |
56 | #include <string.h> | |
57 | ||
58 | /* | |
59 | * Limit imposed by Linux UST-sessiond ABI. | |
60 | */ | |
61 | #define LTTNG_UST_PROCNAME_LEN 17 | |
62 | ||
63 | /* | |
64 | * Acts like linux prctl, the string is not necessarily 0-terminated if | |
65 | * 16-byte long. | |
66 | */ | |
67 | static inline | |
68 | void lttng_ust_getprocname(char *name) | |
69 | { | |
70 | const char *bsd_name; | |
71 | ||
72 | bsd_name = getprogname(); | |
73 | if (!bsd_name) | |
74 | name[0] = '\0'; | |
75 | memcpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1); | |
76 | } | |
77 | ||
78 | #endif | |
79 | ||
b728d87e | 80 | #endif /* _UST_COMPAT_H */ |