1

I have async io code in OSX that basically does the following:

aiocb request;
memset(&request, 0 sizeof(request));

char buffer[64 * 1024];
int filedes = open(path, O_RDONLY);

request->aio_offset = offset;
request->aio_fildes = filedes;
request->aio_buf = buffer;
request->aio_nbytes = 64 * 1024;
request->aio_lio_opcode = LIO_READ;

int result = aio_read(&request);
result = aio_suspend(&request, 1, Riot::INFINITE_WAIT);
int error = aio_error(&request);

Offset is non-aligned and the buffer has no alignment restrictions. (I know this is a "pointless" way of using async io for synchronous reads, but that is irrelevant for my question).

Under certain conditions when I run this code I get error code 14 (Bad Address). I think the problem is that the maybe read goes off the end of the buffer and writes over the filedes.

Has anyone experienced something similar?

The OSX documentation mentions no requirements for alignment just the desire to not have the buffer on the stack since it is async (which doesn't apply if we block until the read is finished). But I did find some documentation on aio_read that says the buffer and size need to be 512 byte aligned. Does anyone know if this restriction (or any other alignment restrictions) apply to OSX aio_read?

Any other ideas about what might be going on here?

RunHolt
  • 1,892
  • 2
  • 19
  • 26
  • Without knowing the "certain conditions" the error attributed is tantamount to almost anything. – l'L'l Feb 16 '15 at 23:59
  • It seems that most of the relevant conditions should be contained in the sample. I think the conditions might be the alignment of the offset, but I'm hoping someone else has seen something like this. – RunHolt Feb 17 '15 at 02:08

0 Answers0