File: bug254164.c

package info (click to toggle)
valgrind 1%3A3.24.0-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 176,332 kB
  • sloc: ansic: 795,029; exp: 26,134; xml: 23,472; asm: 14,393; cpp: 9,397; makefile: 7,464; sh: 6,122; perl: 5,446; python: 1,498; javascript: 981; awk: 166; csh: 1
file content (61 lines) | stat: -rw-r--r-- 1,588 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Small test program to demonstrate Valgrind bug.
// https://bugs.kde.org/show_bug.cgi?id=254164


#include <stdio.h>
#include <sys/resource.h>

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <mach/task.h>
#include <mach/mach_init.h>

void getres(task_t task, unsigned int *rss, unsigned int *vs)
{
    struct task_basic_info t_info;
    mach_msg_type_number_t t_info_count = TASK_BASIC_INFO_COUNT;
    
    task_info(task, TASK_BASIC_INFO, (task_info_t)&t_info, &t_info_count);
    *rss = t_info.resident_size;
    *vs = t_info.virtual_size;
}

/** It appears task_set_info() is a deprecated interface on modern Darwin
  * Per comments in osfmk/kern/task.c:
  *
  *   This routine was added, pretty much exclusively, for registering the
  *   RPC glue vector for in-kernel short circuited tasks. Rather than
  *   removing it completely, I have only disabled that feature (which was
  *   the only feature at the time).
  */
/**
void setres(task_t task)
{
    struct task_trace_memory_info t_info;
    mach_msg_type_number_t t_info_count = TASK_TRACE_MEMORY_INFO_COUNT;
 
    t_info.user_memory_address = NULL;
    t_info.buffer_size = 0;
    t_info.mailbox_array_size = 0;
    
    task_set_info(task, TASK_TRACE_MEMORY_INFO, (task_info_t)&t_info, &t_info_count);
}
 */

int main(void)
{
    unsigned int rss, vs;
    task_t task = MACH_PORT_NULL;
    
    if (task_for_pid(current_task(), getpid(), &task) != KERN_SUCCESS)
        abort();
    
    getres(task, &rss, &vs);
    //setres(task);
    
    return 0;
}