[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Trouble executing example translator from Hurd Hacking Guide

From: Andrew Eggenberger
Subject: Trouble executing example translator from Hurd Hacking Guide
Date: Fri, 26 Jul 2019 20:36:20 -0500
User-agent: mu4e 1.2.0; emacs 26.2

I've been trying to compile and run the trivfs example [1] in the Hurd
Hacking Guide. It compiles with the slightly amended command:

        gcc -g -o one -ltrivfs -lports

But when I try to set it on a file using `settrans -ac foo one` and then
`cat foo`, the translator crashes. GDB finds an unknown rpc call. The
trouble appears to be in the following function.

     trivfs_S_io_read (struct trivfs_protid *cred,
                       mach_port_t reply, mach_msg_type_name_t reply_type,
                       vm_address_t *data, mach_msg_type_number_t *data_len,
                       off_t offs, mach_msg_type_number_t amount)
       /* Deny access if they have bad credentials.  */
       if (!cred)
         return EOPNOTSUPP;
       else if (!(cred->po->openmodes & O_READ))
         return EBADF;
       if (amount > 0)
           int i;
           /* Possibly allocate a new buffer.  */
           if (*data_len < amount)
             *data = (vm_address_t) mmap (0, amount, PROT_READ|PROT_WRITE,
                                          MAP_ANON, 0, 0);
           /* Copy the constant data into the buffer.  */
           for (i = 0; i < amount; i++)
             ((char *) *data)[i] = 1;
       *data_len = amount;
       return 0;

mmap fails to allocate memory. When I checked the errno string, it said
there was an invalid argument. The mmap manual says MAP_SHARED or
MAP_PRIVATE need to appear in the flags argument (the fourth one). I
tried adding each and the error persisted. Another possible reason for
the error according to the man page is an amount that is too high. I
checked the variable and it is a large number, but I don't know how to
check to see how much is too much. Anyway I'm stuck on this. Once I get
it working I hope to update the guide so that other interested newcomers
don't run into the same trouble.

By the way, that call to mmap is virtually identical to the one in the
translator hello.c that's part of the hurd source code. It's also
missing the MAP_SHARED or MAP_PRIVATE flag. The reason it doesn't crash
is I think because *data_len is always greater than the amount and never

Andrew Eggenberger

reply via email to

[Prev in Thread] Current Thread [Next in Thread]