Bug 254164 - OS X task_info: UNKNOWN task message [id 3405, to mach_task_self(), reply 0x........]
Summary: OS X task_info: UNKNOWN task message [id 3405, to mach_task_self(), reply 0x....
Status: RESOLVED FIXED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (show other bugs)
Version: 3.6 SVN
Platform: Unlisted Binaries macOS
: NOR normal
Target Milestone: ---
Assignee: Rhys Kidd
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-14 15:54 UTC by Alexander Potapenko
Modified: 2015-05-11 13:20 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Proposed patch (1.81 KB, patch)
2015-05-11 13:16 UTC, Rhys Kidd
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander Potapenko 2010-10-14 15:54:15 UTC
Valgrind prints the following message for the code below taken from http://miknight.blogspot.com/2005/11/resident-set-size-in-mac-os-x.html :

  UNKNOWN task message [id 3405, to mach_task_self(), reply 0xf03]

Looks like the wrapper for mach_msg_task (see m_syswrap/syswrap_darwin.c) doesn't handle neither id 3405 (which is task_info), nor 3406 (task_set_info).

================================================

#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;
}

void memcheck()
{
    unsigned int rss, vs, psize;
    task_t task = MACH_PORT_NULL;

    if (task_for_pid(current_task(), getpid(), &task) != KERN_SUCCESS)
        abort();
    getres(task, &rss, &vs);
    psize = getpagesize();
    fprintf(stderr, "RSS: %u KiB, VS: %u KiB.\n", rss, vs);
}

int main() {
  memcheck();
  return 0;
}
Comment 1 Rhys Kidd 2015-05-10 13:38:20 UTC
This can be reliably reproduced with the newly added (r15205) regression test case as follows:

$ cd none/tests/darwin/
$ make bug254164
$ cd ../../../
$ perl tests/vg_regtest none/tests/darwin/bug254164
bug254164:       valgrind   -q ./bug254164 
*** bug254164 failed (stderr) ***

== 1 test, 1 stderr failure, 0 stdout failures, 0 stderrB failures, 0 stdoutB failures, 0 post failures ==
none/tests/darwin/bug254164              (stderr)

Also worth noting that current Darwin kernel code indicates that task_set_info() is currently deprecated. Can you advise of a program which uses the task_set_info() interface?
Comment 2 Rhys Kidd 2015-05-11 13:16:27 UTC
Created attachment 92542 [details]
Proposed patch
Comment 3 Rhys Kidd 2015-05-11 13:20:11 UTC
Resolved in r15209.