Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

palloc address error #4

Closed
yliam opened this issue Feb 2, 2016 · 15 comments
Closed

palloc address error #4

yliam opened this issue Feb 2, 2016 · 15 comments
Assignees

Comments

@yliam
Copy link

yliam commented Feb 2, 2016

Hello,

I get a palloc address error when attempting to execute selfie.m by mipster. See transcript below:

~/selfie
$ gcc selfie.c -o selfie

~/selfie
$ ./selfie -c selfie.c -o selfie.m
./selfie: this is selfie's cstarc compiling selfie.c
./selfie: writing code into output file selfie.m

~/selfie
$ ./selfie -l selfie.m -m 1
./selfie: loading code from input file selfie.m
./selfie: this is selfie's mipster executing selfie.m with 1MB of memory
./selfie: palloc address error

Please advise.

Thank you,
yliam

@ckirsch
Copy link
Member

ckirsch commented Feb 3, 2016

Hi yliam,

selfie needs to be compiled into a 32-bit executable. I suspect that you are on a 64-bit system and have therefore generated a 64-bit executable. Let me know if this is the case.

Please try instead:

gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

to compile selfie and then see if this solves the problem.

I just updated the README.md file with improved build instructions that should make this point easier to understand.

Best,
-ck

@ckirsch ckirsch self-assigned this Feb 3, 2016
@yliam
Copy link
Author

yliam commented Feb 4, 2016

Hello again Professor Kirsch,

I'm sorry to say I had the same results after compiling with:

gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

I am using Debian GNU/Linux 7 debian-i386 (wheezy) on a 32 bit system.

Incidentally, I am able to successfully execute selfie.m by mipster using the version released on November 16, 2015. The changes made during the implementation of hypster are somehow preventing successful emulation/virtualization for me now. See transcript below:

~/selfie
$ gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

~/selfie
$ ./selfie -c selfie.c -o selfie.m
./selfie: this is selfie's cstarc compiling selfie.c
./selfie: writing code into output file selfie.m

~/selfie
$ ./selfie -l selfie.m -m 1
./selfie: loading code from input file selfie.m
./selfie: this is selfie's mipster executing selfie.m with 1MB of memory
./selfie: palloc address error

You may also be surprised to hear that, in addition to standalone Debian GNU/Linux 7 debian-i386 (wheezy), the same release from November also works just fine for me under Cygwin32 on a 64-bit windows system using just:

gcc selfie.c -o selfie

for the initial build. I think there may be an issue somewhere in the hypster implementation.

Thank you,
yliam

@ckirsch
Copy link
Member

ckirsch commented Feb 4, 2016

Hi yliam,

no worries, I very much appreciate your feedback.

The problem is likely due to your system returning addresses through malloc that are negative numbers in 32-bit two's complement representation. Up until now, I had not implemented support of that in selfie. I have now taken the opportunity to do that but cannot test it. Would you be so kind, pull the new version, and try it?

Many thanks!

Best,
-ck

@yliam
Copy link
Author

yliam commented Feb 4, 2016

Hi again Professor Kirsch,

Per your request I just pulled cksystemsteaching-selfie-0b1a3a5 and tried it again on both Debian GNU/Linux 7 debian-i386 (wheezy) and Cygwin32, but I got a segmentation fault this time on both platforms. Please see transcript below:

~/selfie
$ gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

~/selfie
$ ./selfie -c selfie.c -o selfie.m
./selfie: this is selfie's cstarc compiling selfie.c
./selfie: writing code into output file selfie.m

~/selfie
$ ./selfie -l selfie.m -m 1
./selfie: loading code from input file selfie.m
./selfie: this is selfie's mipster executing selfie.m with 1MB of memory
Segmentation fault

The crash under Linux did not create a stackdump file, but the Cygwin crash did:

Exception: STATUS_ACCESS_VIOLATION at eip=004090A0
eax=00000000 ebx=0000000C ecx=00001000 edx=800E86D0 esi=61306430 edi=611CCFAE
ebp=0028CB88 esp=0028CB70 program=C:\Users\yliam\Documents\programs\cygwin\home\yliam\selfie\selfie.exe, pid 2452, thread main
cs=0023 ds=002B es=002B fs=0053 gs=002B ss=002B
Stack trace:
Frame Function Args
0028CB88 004090A0 (00000000, 000FFEBD, 0028CBB8, 00409A26)
0028CBA8 004090E7 (00000000, 00000000, 0028CBE8, 0040D6C0)
0028CBE8 0040C7C0 (800F8770, 00000001, 0028CCB0, 0000000C)
0028CC08 0040D762 (00000001, 0028CCAC, 0000000A, 00000000)
0028CC38 0040D056 (00000001, 0028CCAC, 61007410, 0000001F)
0028CC58 0040D971 (00000001, 0028CCAC, 0028CD28, 0028CC9C)
0028CC78 0040DB7B (00000004, 0028CCA0, 80010100, 00000020)
0028CD28 6100839A (00000000, 0028CD84, 61007410, 00000000)
End of stack trace

I hope this helps in troubleshooting.

Thanks,
yliam

@ckirsch
Copy link
Member

ckirsch commented Feb 5, 2016

Hi yliam,

thank you for your feedback. I ran a few tests with negative addresses but cannot reproduce the problem.

Could you please set the flags:

debug_exception
debug_map

both to 1, then compile and run, and send me the output?

Thanks!

Best,
-ck

@yliam
Copy link
Author

yliam commented Feb 5, 2016

Hi again,

I'm happy to be of assistance in any way I can. Per your request, I set the debug_exception and debug_map flags, and this is what I got running the same commands:

~/selfie
$ gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie

~/selfie
$ ./selfie -c selfie.c -o selfie.m
./selfie: this is selfie's cstarc compiling selfie.c
./selfie: writing code into output file selfie.m

~/selfie
$ ./selfie -l selfie.m -m 1
./selfie: loading code from input file selfie.m
./selfie: this is selfie's mipster executing selfie.m with 1MB of memory
selfie.m: selfie_map page 0x0000 to frame 0xFFEA1 for context 0
selfie.m: selfie_map page 0x0001 to frame 0xFFEA2 for context 0
selfie.m: selfie_map page 0x0002 to frame 0xFFEA3 for context 0
selfie.m: selfie_map page 0x0003 to frame 0xFFEA4 for context 0
selfie.m: selfie_map page 0x0004 to frame 0xFFEA5 for context 0
selfie.m: selfie_map page 0x0005 to frame 0xFFEA6 for context 0
selfie.m: selfie_map page 0x0006 to frame 0xFFEA7 for context 0
selfie.m: selfie_map page 0x0007 to frame 0xFFEA8 for context 0
selfie.m: selfie_map page 0x0008 to frame 0xFFEA9 for context 0
selfie.m: selfie_map page 0x0009 to frame 0xFFEAA for context 0
selfie.m: selfie_map page 0x000A to frame 0xFFEAB for context 0
selfie.m: selfie_map page 0x000B to frame 0xFFEAC for context 0
selfie.m: selfie_map page 0x000C to frame 0xFFEAD for context 0
selfie.m: selfie_map page 0x000D to frame 0xFFEAE for context 0
selfie.m: selfie_map page 0x000E to frame 0xFFEAF for context 0
selfie.m: selfie_map page 0x000F to frame 0xFFEB0 for context 0
selfie.m: selfie_map page 0x0010 to frame 0xFFEB1 for context 0
selfie.m: selfie_map page 0x0011 to frame 0xFFEB2 for context 0
selfie.m: selfie_map page 0x0012 to frame 0xFFEB3 for context 0
selfie.m: selfie_map page 0x0013 to frame 0xFFEB4 for context 0
selfie.m: selfie_map page 0x0014 to frame 0xFFEB5 for context 0
selfie.m: selfie_map page 0x0015 to frame 0xFFEB6 for context 0
selfie.m: selfie_map page 0x0016 to frame 0xFFEB7 for context 0
selfie.m: selfie_map page 0x0017 to frame 0xFFEB8 for context 0
selfie.m: selfie_map page 0x0018 to frame 0xFFEB9 for context 0
selfie.m: selfie_map page 0x0019 to frame 0xFFEBA for context 0
selfie.m: selfie_map page 0x001A to frame 0xFFEBB for context 0
selfie.m: selfie_map page 0x001B to frame 0xFFEBC for context 0
selfie.m: selfie_map page 0x3FFF to frame 0xFFEBD for context 0
Segmentation fault

Thanks,
yliam

@ghost
Copy link

ghost commented Feb 5, 2016

Hi,

I have tried the same way of executing selfie, but on a 32 bit Peppermint Six (Ubuntu 14.04) system, and I got the exact same error (segmentation fault) and debugging output as described above with the latest version. I also tried to use different execution sizes for selfie, not just 1 MB, but it didn't make any difference.

I have also checked out the version of Feb 3, which led to the palloc address error @yliam described. The version of Dec 17 seemed to work for me, though.

@ghost
Copy link

ghost commented Feb 5, 2016

Hello everybody!
I tested it on Debian 8/i386 with gcc 4.9 and had the same issues.
It seems to work on OS X El Capitan with the clang compiler. It also
works on Debian 8/i386 with the clang compiler (for me). As far as I
know, cygwin is using a gcc version. So, there may be some differences
between gcc and clang but I am not sure.

Tests:
FreeBSD 10.2 x86 / clang: works.
OpenBSD 5.7 i386 / gcc42: doesn't work.
OpenBSD 5.7 i386 / clang: works.
Debian 8 i386 / gcc49: doesn't work.
Debian 8 i386 / clang: works.
Mac OSX El Cap. / clang: works.

On Debian 8 / gcc49, the program received SIGSEGV signal at line 4641:

Program received signal SIGSEGV, Segmentation fault.
0x0804fc3a in mipster_switch (toID=0) at selfie.c:4641
4641 *(registers+REG_V1) = doSwitch(toID);
(gdb) print registers
$1 = (int *) 0x8079420
(gdb) print REG_V1
$2 = 3
(gdb) print *(registers+REG_V1)
$3 = 0

Greetings,
Christian Barthel.

@ckirsch
Copy link
Member

ckirsch commented Feb 5, 2016

Thanks a lot, everyone, for your help!

I suspect this is a silent integer overflow problem but I am not sure. One candidate is the address computation in tlb(). I have added additional parentheses to enforce the right order of evaluation and instrumented that with debugging code. Please pull the new version, enable debug_exception, debug_map, and debug_tlb, and rerun. There may be a lot of output now. Please attach that here as text file, if necessary.

Many thanks!

-ck

@yliam
Copy link
Author

yliam commented Feb 5, 2016

Greetings Professor Kirsch,

Here's my output from b977211 with debug_exception, debug_map, and debug_tlb enabled.

Same three commands:
gcc -w -m32 -D'main(a, b)=main(int argc, char **argv)' selfie.c -o selfie
./selfie -c selfie.c -o selfie.m
./selfie -l selfie.m -m 1

Thanks,
yliam

yliam_dbg.txt

@ckirsch
Copy link
Member

ckirsch commented Feb 5, 2016

Thanks, yliam.

I just pushed another version with simplified page frame handling.

Can anyone try please?

-ck

@yliam
Copy link
Author

yliam commented Feb 6, 2016

You're welcome.

I just re-ran using release 4d73ecf with debug_exception, debug_map, and debug_tlb enabled and got the exact same output as I did using b977211. Since the two log files were identical, I'm not re-attaching the file again.

-yliam

@ckirsch
Copy link
Member

ckirsch commented Feb 6, 2016

Everyone,

I finally installed my own copy of a 32-bit Ubuntu Linux system and fixed the bug.

In hindsight, Christian's gdb message had all the information needed. In particular, the bug had nothing to do with my new memory management. It is rather due to differences in how compilers treat assignments. Some seem to evaluate lvalues before rvalues which in our case here lead to dereferencing a null pointer, see my comment in the newest version of the code.

Please pull and test.

Thanks a lot again for your help. From now on I can even do this myself (I will keep the 32-bit system).

-ck

@yliam
Copy link
Author

yliam commented Feb 7, 2016

Excellent!

Now it works again for me with GCC under both Linux and Cygwin.

Thanks for your help Professor Kirsch.

yliam

@ckirsch
Copy link
Member

ckirsch commented Feb 7, 2016

I am glad to hear that.

Thanks a lot for your help!

-ck

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants