1 |
/* hello-mt.c - A trivial single-file translator, multithreaded version |
/* hello-mt.c - A trivial single-file translator, multithreaded version |
2 |
Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc. |
Copyright (C) 1998,99,2001,02 Free Software Foundation, Inc. |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
5 |
modify it under the terms of the GNU General Public License as |
modify it under the terms of the GNU General Public License as |
123 |
error_t |
error_t |
124 |
trivfs_S_io_read (struct trivfs_protid *cred, |
trivfs_S_io_read (struct trivfs_protid *cred, |
125 |
mach_port_t reply, mach_msg_type_name_t reply_type, |
mach_port_t reply, mach_msg_type_name_t reply_type, |
126 |
vm_address_t *data, mach_msg_type_number_t *data_len, |
char **data, mach_msg_type_number_t *data_len, |
127 |
off_t offs, mach_msg_type_number_t amount) |
loff_t offs, mach_msg_type_number_t amount) |
128 |
{ |
{ |
129 |
struct open *op; |
struct open *op; |
130 |
|
|
154 |
{ |
{ |
155 |
/* Possibly allocate a new buffer. */ |
/* Possibly allocate a new buffer. */ |
156 |
if (*data_len < amount) |
if (*data_len < amount) |
157 |
*data = (vm_address_t) mmap (0, amount, PROT_READ|PROT_WRITE, |
*data = mmap (0, amount, PROT_READ|PROT_WRITE, MAP_ANON, 0, 0); |
158 |
MAP_ANON, 0, 0); |
if (*data == MAP_FAILED) |
159 |
|
{ |
160 |
|
mutex_unlock (&op->lock); |
161 |
|
rwlock_reader_unlock (&contents_lock); |
162 |
|
return ENOMEM; |
163 |
|
} |
164 |
|
|
165 |
/* Copy the constant data into the buffer. */ |
/* Copy the constant data into the buffer. */ |
166 |
memcpy ((char *) *data, contents + offs, amount); |
memcpy ((char *) *data, contents + offs, amount); |