![]() |
| | #1 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| Okay, weird. Code: if(read(mMemFd, buf, PageSize()) != 4096)
throw ProcException();
mMemFd is an open file descriptor on /proc/XXX/mem. Obviously, read() doesn't normally do this or the whole system would be breaking. Kernel is Linux 2.6.20
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #2 |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| Did you check what PageSize() returns?
__________________ jeff.bagu.org - Terrain rendering and other random stuff |
| Perspective is offline | |
| | #3 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| PageSize() returns 4096. I committed the sin of not posting the original code. It's actually: Code: if(read(mMemFd, buf, PageSize()) != PageSize())
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #4 |
| Crazy Fool Join Date: Jan 2003 Location: Canada
Posts: 2,596
| maybe check if errno is being set after the call? That's pretty odd though.
__________________ jeff.bagu.org - Terrain rendering and other random stuff |
| Perspective is offline | |
| | #5 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| errno is 0, as expected. My only theory at this point is kernel bug, so I'm compiling a newer kernel right now...
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
| | #6 |
| Senior software engineer Join Date: Mar 2007 Location: Portland, OR
Posts: 5,768
| Okay. So here's what was happening. I was calling read(), and if it failed, throwing an exception. Apparently, something during exception throw was resetting errno to 0. Silly mistake. Checking errno immediately after the call to read() shows EINVAL. The man page said that this could be due to unaligned access. But the access is aligned. So something else must be causing it. Turns out, I was able to read() from regions of memory less than 2 GB, but not > 2 GB (in this case, the stack of another process). That's because I was calling lseek(), which takes an off_t, which is a signed type. So my address was sign-extending and becoming negative. Oddly lseek() does not report it as an error if you seek before the beginning of the file. I don't know if that's always true. Solution? Switch over to lseek64() which has enough room in its off64_t for values larger than 2 GB. I still think there is a bug somewhere, either the kernel or the C library. If errno was being set (and I proved it by making sure it was 0 beforehand), then read() should be returning -1. But it's not, it's returning some value which seems to be "random" yet somehow related to the parameters passed. If I had been checking for error with: Code: if(read(...) < 0)
__________________ "Congratulations on your purchase. To begin using your quantum computer, set the power switch to both off and on simultaneously." -- raftpeople@slashdot |
| brewbuck is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| weird things with my linked list of queue | -EquinoX- | C Programming | 3 | 11-22-2008 11:23 PM |
| weird | kiz | C Programming | 8 | 09-24-2007 01:16 AM |
| Weird Characters With GetDlgItemText | execute | Windows Programming | 4 | 05-04-2006 04:53 PM |
| weird error | gandalf_bar | Linux Programming | 2 | 07-17-2005 07:32 AM |
| Getting weird characters in Strings | steve8820 | C Programming | 3 | 09-18-2001 02:49 AM |