Questions on hw1.

9 views
Skip to first unread message

Truong

unread,
Feb 12, 2010, 5:57:59 PM2/12/10
to cs644s10_umb
Hi Professor.

I don't quite understand the 1.c. I can't find any syscall, when disas
the address as followed:
...
0x000000000040053d 4 write(1, "hi2\n", 4);
(gdb) si
0x0000000000400408 in write@plt ()
Current language: auto; currently asm
(gdb) disas 0x0000000000400408
Dump of assembler code for function write@plt:
0x0000000000400408 <write@plt+0>: jmpq *0x200bfa(%rip)
# 0x601008 <_GLOBAL_OFFSET_TABLE_+32>
0x000000000040040e <write@plt+6>: pushq $0x1
0x0000000000400413 <write@plt+11>: jmpq 0x4003e8 <_init+24>
End of assembler dump.
...

Not sure I got it right, but the instructions are confused. Can you
explain it in more detail? Thank you.

Truong.

Betty O'Neil

unread,
Feb 12, 2010, 7:11:38 PM2/12/10
to Truong, cs644s10_umb
That jmpq *... needs to be followed using si. Look at the transcript
handed out in class "Finding UNIX System Calls".

Weiwei

unread,
Feb 14, 2010, 2:08:08 PM2/14/10
to cs644s10_umb
Hi professor,

I also have the same problem, I could only see "syscall" symbols
when "disas ADDRESS" of write() function, but when I disas "syscall"
or later addresses, neither "int" instruction nor "_write" symbol
found, it directly output "hi2" after following 3 "si" operations.

(gdb) si
0x00007f49618efd80 in write () from /lib/libc.so.6
(gdb) disas 0x00007f49618efd80
Dump of assembler code for function write:
0x00007f49618efd80 <write+0>: cmpl $0x0,0x298301(%rip) #
0x7f4961b880
88
0x00007f49618efd87 <write+7>: jne 0x7f49618efd99 <write+25>
0x00007f49618efd89 <write+9>: mov $0x1,%eax
0x00007f49618efd8e <write+14>: syscall
0x00007f49618efd90 <write+16>: cmp $0xfffffffffffff001,%rax
0x00007f49618efd96 <write+22>: jae 0x7f49618efdeb <write+107>
0x00007f49618efd98 <write+24>: retq
0x00007f49618efd99 <write+25>: sub $0x28,%rsp
0x00007f49618efd9d <write+29>: mov %rdi,0x8(%rsp)
0x00007f49618efda2 <write+34>: mov %rsi,0x10(%rsp)
0x00007f49618efda7 <write+39>: mov %rdx,0x18(%rsp)
0x00007f49618efdac <write+44>: callq 0x7f496190bbf0
0x00007f49618efdb1 <write+49>: mov 0x8(%rsp),%rdi
0x00007f49618efdb6 <write+54>: mov 0x10(%rsp),%rsi
0x00007f49618efdbb <write+59>: mov 0x18(%rsp),%rdx
0x00007f49618efdc0 <write+64>: mov %rax,(%rsp)
0x00007f49618efdc4 <write+68>: mov $0x1,%eax
0x00007f49618efdc9 <write+73>: syscall
0x00007f49618efdcb <write+75>: mov (%rsp),%rdi
0x00007f49618efdcf <write+79>: mov %rax,0x8(%rsp)
0x00007f49618efdd4 <write+84>: callq 0x7f496190bbc0
---Type <return> to continue, or q <return> to quit---
0x00007f49618efdd9 <write+89>: mov 0x8(%rsp),%rax
0x00007f49618efdde <write+94>: add $0x28,%rsp
0x00007f49618efde2 <write+98>: cmp $0xfffffffffffff001,%rax
0x00007f49618efde8 <write+104>: jae 0x7f49618efdeb <write+107>
0x00007f49618efdea <write+106>: retq
0x00007f49618efdeb <write+107>: mov 0x2931ae(%rip),%rcx #
0x7f4961b82f
a0
0x00007f49618efdf2 <write+114>: xor %edx,%edx
0x00007f49618efdf4 <write+116>: sub %rax,%rdx
0x00007f49618efdf7 <write+119>: mov %edx,%fs:(%rcx)
0x00007f49618efdfa <write+122>: or $0xffffffffffffffff,%rax
0x00007f49618efdfe <write+126>: jmp 0x7f49618efdea <write+106>
End of assembler dump.
(gdb) si
0x00007f49618efd89 in write () from /lib/libc.so.6
(gdb) si
0x00007f49618efd8e in write () from /lib/libc.so.6
(gdb) si
hi2


By the way, I want to check whether we are supposed to use the
server sf06.cs.umb.edu or not. Thanks!

Weiwei

Betty O'Neil

unread,
Feb 14, 2010, 2:27:39 PM2/14/10
to cs644s10_umb

It's being disassembled as "syscall", that's all! You can see
it does the job.--Betty O.

On Sun, 14 Feb 2010, Weiwei wrote:

> Hi professor,
>
> I also have the same problem, I could only see "syscall" symbols
> when "disas ADDRESS" of write() function, but when I disas "syscall"
> or later addresses, neither "int" instruction nor "_write" symbol
> found, it directly output "hi2" after following 3 "si" operations.
>
> (gdb) si
> 0x00007f49618efd80 in write () from /lib/libc.so.6
> (gdb) disas 0x00007f49618efd80
> Dump of assembler code for function write:
> 0x00007f49618efd80 <write+0>: cmpl $0x0,0x298301(%rip) #
> 0x7f4961b880
> 88
> 0x00007f49618efd87 <write+7>: jne 0x7f49618efd99 <write+25>
> 0x00007f49618efd89 <write+9>: mov $0x1,%eax

> 0x00007f49618efd8e <write+14>: syscall <---Here it is!!

Weiwei Gong

unread,
Feb 14, 2010, 2:39:33 PM2/14/10
to cs644s...@googlegroups.com
But the description of this question is to "find the 'int' instruction used for system calls with the x86 processor", so I got a little confused.

For 1b, I think it uses registers instead of stack explained underneath the question, I enclosed the disassembled code of main(), it does use registers edx, esi... to store arguments, eg. it puts "hi\n" to esi in code below, doesn't it?

Dump of assembler code for function main:
0x000000000040050c <main+0>:    push   %rbp
0x000000000040050d <main+1>:    mov    %rsp,%rbp
0x0000000000400510 <main+4>:    mov    $0x3,%edx
0x0000000000400515 <main+9>:    mov    $0x40063c,%esi
0x000000000040051a <main+14>:   mov    $0x1,%edi
0x000000000040051f <main+19>:   mov    $0x0,%eax
0x0000000000400524 <main+24>:   callq  0x400408 <write@plt>
0x0000000000400529 <main+29>:   mov    $0x4,%edx
0x000000000040052e <main+34>:   mov    $0x400640,%esi
0x0000000000400533 <main+39>:   mov    $0x1,%edi
0x0000000000400538 <main+44>:   mov    $0x0,%eax
0x000000000040053d <main+49>:   callq  0x400408 <write@plt>
0x0000000000400542 <main+54>:   mov    $0x6,%eax
0x0000000000400547 <main+59>:   leaveq
0x0000000000400548 <main+60>:   retq
End of assembler dump.
Message has been deleted
Message has been deleted

Betty O'Neil

unread,
Feb 14, 2010, 5:59:17 PM2/14/10
to cs644s...@googlegroups.com
I see, the first ref to it is just "int", the classic x86 syscall
instruction, but later on--

d. Use si to proceed across the system call. Note how the whole
system call execution appears at user level to be due to this one
instruction. Is it int $0x80 or sysenter or what?

Sorry, I should have edited the first ref. --Betty O.

Truong

unread,
Feb 14, 2010, 6:03:24 PM2/14/10
to cs644s10_umb
So the answer to 1.d is "syscall" I guess.
Here is another strange thing happened when I compiled "hi.c" and ran
"hi" in sf06:

windy@sf06:~/cs644/hw1$ gcc -g hi.c -o hi
windy@sf06:~/cs644/hw1$ ls
hi hi.c linux_syscalls.script
windy@sf06:~/cs644/hw1$ hi
The program 'hi' is currently not installed. To run 'hi' please ask
your administrator to install the package 'hmake'
-bash: hi: command not found
windy@sf06:~/cs644/hw1$

I have no problem to do this in Unix on Sun Blades.
What is wrong here?

Truong.

Betty O'Neil

unread,
Feb 14, 2010, 6:07:10 PM2/14/10
to cs644s10_umb
This is a path problem. Use ./hi instead of hi to force the use
of the hi in your current directory.--Betty O.

Betty O'Neil

unread,
Apr 17, 2010, 2:16:22 PM4/17/10
to cs644s...@googlegroups.com
I've written up Thursday's class on user and kernel mutex and
hw4 implementation ideas.




--
Subscription settings: http://groups.google.com/group/cs644s10_umb/subscribe?hl=en

Betty O'Neil

unread,
Apr 18, 2010, 9:13:00 AM4/18/10
to cs644s...@googlegroups.com
For hw4, you can use the Makefile in $xuex for the user-level package,
but when you want to build with your own version of Xinu initialize.c
(original in $xuker/initialize.c) to finish the kernel kmessage.c,
you need to use some tricks in the Makefile.

I've put the needed Makefile hw4/Makefile from the web home
(/data/htdocs/cs644) and it is linked from the class web page.
To use it, copy $xuker/initialize.c to your hw4 directory as
well as Makefile, and the Makefile will build using the local
copy of initialize.c. Thus when you need to modify it, the build
will incorporate your changes.

To use the Makefile:
make U=mloop mloop.lnx
for example, to build mloop with umessage.c, kmessage.c and the
Xinu system. You can add another file such as cmessage.c easily
enough.
Reply all
Reply to author
Forward
0 new messages