11#[=============================================================================[
2- Check for ptrace() .
2+ Check FPM trace implementation .
33
44## Cache variables:
55
@@ -26,6 +26,8 @@ include(CheckSourceRuns)
2626include (CheckSymbolExists)
2727include (CMakePushCheckState)
2828
29+ message (CHECK_START "Checking FPM trace implementation" )
30+
2931message (CHECK_START "Checking whether ptrace works" )
3032
3133cmake_push_check_state(RESET)
@@ -118,70 +120,77 @@ endif()
118120
119121if (HAVE_PTRACE)
120122 message (CHECK_PASS "yes" )
121- return ()
123+ else ()
124+ message (CHECK_FAIL "no" )
122125endif ()
123- message (CHECK_FAIL "no" )
124-
125- check_symbol_exists(mach_vm_read "mach/mach.h;mach/mach_vm.h" HAVE_MACH_VM_READ)
126126
127- if (HAVE_MACH_VM_READ )
128- return ( )
127+ if (NOT HAVE_PTRACE )
128+ check_symbol_exists(mach_vm_read "mach/mach.h;mach/mach_vm.h" HAVE_MACH_VM_READ )
129129endif ()
130130
131- message (CHECK_START "Checking for process memory access file" )
131+ if (NOT HAVE_PTRACE AND NOT HAVE_MACH_VM_READ)
132+ message (CHECK_START "Checking for process memory access file" )
132133
133- if (NOT CMAKE_CROSSCOMPILING )
134- set (PROC_MEM_FILE)
135- if (EXISTS /proc/self/mem)
136- set (PROC_MEM_FILE "mem" )
137- elseif (EXISTS /proc/self/as)
138- set (PROC_MEM_FILE "as" )
139- endif ()
134+ if (NOT CMAKE_CROSSCOMPILING )
135+ set (PROC_MEM_FILE)
136+ if (EXISTS /proc/self/mem)
137+ set (PROC_MEM_FILE "mem" )
138+ elseif (EXISTS /proc/self/as)
139+ set (PROC_MEM_FILE "as" )
140+ endif ()
140141
141- if (PROC_MEM_FILE)
142- cmake_push_check_state(RESET)
143- set (CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
144- set (CMAKE_REQUIRED_QUIET TRUE )
145- check_source_runs(C "
146- #define _FILE_OFFSET_BITS 64
147- #include <stdint.h>
148- #include <unistd.h>
149- #include <sys/types.h>
150- #include <sys/stat.h>
151- #include <fcntl.h>
152- #include <stdio.h>
153-
154- int main(void)
155- {
156- long v1 = (unsigned int) -1, v2 = 0;
157- char buf[128];
158- int fd;
159- sprintf(buf, \" /proc/%d/${PROC_MEM_FILE} \" , getpid());
160- fd = open(buf, O_RDONLY);
161- if (0 > fd) {
162- return 1;
163- }
164- if (sizeof(long) != pread(fd, &v2, sizeof(long), (uintptr_t) &v1)) {
142+ if (PROC_MEM_FILE)
143+ cmake_push_check_state(RESET)
144+ set (CMAKE_REQUIRED_DEFINITIONS -D_GNU_SOURCE)
145+ set (CMAKE_REQUIRED_QUIET TRUE )
146+ check_source_runs(C "
147+ #define _FILE_OFFSET_BITS 64
148+ #include <stdint.h>
149+ #include <unistd.h>
150+ #include <sys/types.h>
151+ #include <sys/stat.h>
152+ #include <fcntl.h>
153+ #include <stdio.h>
154+
155+ int main(void)
156+ {
157+ long v1 = (unsigned int) -1, v2 = 0;
158+ char buf[128];
159+ int fd;
160+ sprintf(buf, \" /proc/%d/${PROC_MEM_FILE} \" , getpid());
161+ fd = open(buf, O_RDONLY);
162+ if (0 > fd) {
163+ return 1;
164+ }
165+ if (sizeof(long) != pread(fd, &v2, sizeof(long), (uintptr_t) &v1)) {
166+ close(fd);
167+ return 1;
168+ }
165169 close(fd);
166- return 1 ;
170+ return v1 != v2 ;
167171 }
168- close(fd);
169- return v1 != v2;
170- }
171- " _HAVE_PROC_MEM_FILE)
172- cmake_pop_check_state()
172+ " _HAVE_PROC_MEM_FILE)
173+ cmake_pop_check_state()
173174
174- if (NOT _HAVE_PROC_MEM_FILE)
175- unset (PROC_MEM_FILE)
175+ if (NOT _HAVE_PROC_MEM_FILE)
176+ unset (PROC_MEM_FILE)
177+ endif ()
176178 endif ()
177179 endif ()
178- endif ()
179180
180- if (PROC_MEM_FILE)
181- message (CHECK_PASS "yes (${PROC_MEM_FILE} )" )
182- return ()
181+ if (PROC_MEM_FILE)
182+ message (CHECK_PASS "yes (${PROC_MEM_FILE} )" )
183+ else ()
184+ message (CHECK_FAIL "no" )
185+ endif ()
183186endif ()
184187
185- message (CHECK_FAIL "no" )
186-
187- message (WARNING "FPM trace - ptrace, pread, or mach: could not be found" )
188+ if (HAVE_PTRACE)
189+ message (CHECK_PASS "found (ptrace)" )
190+ elseif (HAVE_MACH_VM_READ)
191+ message (CHECK_PASS "found (mach)" )
192+ elseif (PROC_MEM_FILE)
193+ message (CHECK_PASS "found (pread)" )
194+ else ()
195+ message (CHECK_FAIL "not found, FPM trace implementation is disabled" )
196+ endif ()
0 commit comments