1 // Small test program to demonstrate Valgrind bug.
2 // https://bugs.kde.org/show_bug.cgi?id=254164
3
4
5 #include <stdio.h>
6 #include <sys/resource.h>
7
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <sys/types.h>
12 #include <sys/sysctl.h>
13 #include <mach/task.h>
14 #include <mach/mach_init.h>
15
getres(task_t task,unsigned int * rss,unsigned int * vs)16 void getres(task_t task, unsigned int *rss, unsigned int *vs)
17 {
18 struct task_basic_info t_info;
19 mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
20
21 task_info(task, TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
22 *rss = t_info.resident_size;
23 *vs = t_info.virtual_size;
24 }
25
26 /** It appears task_set_info() is a deprecated interface on modern Darwin
27 * Per comments in osfmk/kern/task.c:
28 *
29 * This routine was added, pretty much exclusively, for registering the
30 * RPC glue vector for in-kernel short circuited tasks. Rather than
31 * removing it completely, I have only disabled that feature (which was
32 * the only feature at the time).
33 */
34 /**
35 void setres(task_t task)
36 {
37 struct task_trace_memory_info t_info;
38 mach_msg_type_number_t t_info_count = TASK_TRACE_MEMORY_INFO_COUNT;
39
40 t_info.user_memory_address = NULL;
41 t_info.buffer_size = 0;
42 t_info.mailbox_array_size = 0;
43
44 task_set_info(task, TASK_TRACE_MEMORY_INFO, (task_info_t)&t_info, &t_info_count);
45 }
46 */
47
main(void)48 int main(void)
49 {
50 unsigned int rss, vs;
51 task_t task = MACH_PORT_NULL;
52
53 if (task_for_pid(current_task(), getpid(), &task) != KERN_SUCCESS)
54 abort();
55
56 getres(task, &rss, &vs);
57 //setres(task);
58
59 return 0;
60 }
61
62