I have did a self signed code codesign -- but not sure why vm\_write is failing.(I am using 10.6.6)

trying to figure out what is missing to make it work -- I appreciate some help of this issues.

```
#include <mach/vm_map.h>
#include <mach/mach_traps.h>
#include <mach/mach_error.h>

int main (int argc, const char * argv[])
{

    //get the task for PID
    kern_return_t err;
    int pid = 73002; // PID of process in the system
    mach_port_name_t t;

    err = task_for_pid(mach_task_self(), pid, &t);

    if(0 != err)
    {
        printf("task_for_pid : %s",mach_error_string(err));
    }

    vm_address_t address;
    vm_size_t size = 108;

    err =  vm_allocate(t,&address,size,TRUE);

    if(0 != err)
    {
        printf("vm_allocate : %s",mach_error_string(err));
    }

    vm_offset_t data = pid;
    mach_msg_type_number_t dataCnt = sizeof(pid);

    err = vm_write(t,address,data,dataCnt);

    if(0 != err)
    {
        printf("vm_write : %s",mach_error_string(err));
    }

    return 0;
}

```

Update:

1. self signed code codesign --- I have generated the certificate in the system and used for codesign.
2. vm\_write returns (os/kern) invalid address (return value is "1")