Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > gnu.hurd.help > #393

Trouble executing example translator from Hurd Hacking Guide

From Andrew Eggenberger <andrew.eggenberger@gmail.com>
Newsgroups gnu.hurd.help
Subject Trouble executing example translator from Hurd Hacking Guide
Date 2019-07-26 20:36 -0500
Message-ID <mailman.2342.1564191391.2688.help-hurd@gnu.org> (permalink)
References <877e84gsx7.fsf@gmail.com>

Show all headers | View raw


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.


     error_t
     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
runs.

[1]: https://www.gnu.org/software/hurd/hacking-guide/hhg.html#An-Example-using-trivfs
-- 
Andrew Eggenberger

Back to gnu.hurd.help | Previous | Next | Find similar


Thread

Trouble executing example translator from Hurd Hacking Guide Andrew Eggenberger <andrew.eggenberger@gmail.com> - 2019-07-26 20:36 -0500

csiph-web