write() and __libc_write()?

sean yang seanatpurdue@hotmail.com
Sat Mar 11 04:10:00 GMT 2006


this is the code from  ./ sysdeps/generic/write.c, and I believe it's the 
code corresponding to write(2) exported by #include <unistd.h>
By why can't I find "int $0x80" inside the function body? And I did an 
objdump -d libc.so.6(see below), and found the object code for __libc_write 
is totoal different from the source code here. Why? Thanks.

>cat write.c
...//some header files
/* Write NBYTES of BUF to FD.  Return the number written, or -1.  */
ssize_t
__libc_write (int fd, const void *buf, size_t nbytes)
{
  if (nbytes == 0)
    return 0;
  if (fd < 0)
    {
      __set_errno (EBADF);
      return -1;
    }
  if (buf == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  __set_errno (ENOSYS);
  return -1;
}
libc_hidden_def (__libc_write)
stub_warning (write)

weak_alias (__libc_write, __write)
libc_hidden_weak (__write)
weak_alias (__libc_write, write)
#include <stub-tag.h>


==========================
>objdump -d libc.so.6
228426 000d2780 <__libc_write>:
228427    d2780:   e8 be 5e 04 00          call   118643 
<__i686.get_pc_thunk.cx>
228428    d2785:   81 c1 bb 73 06 00       add    $0x673bb,%ecx
228429    d278b:   83 b9 04 1a 00 00 00    cmpl   $0x0,0x1a04(%ecx)
228430    d2792:   75 1d                   jne    d27b1 <__libc_write+0x31>
228431    d2794:   53                      push   %ebx
228432    d2795:   8b 54 24 10             mov    0x10(%esp,1),%edx
228433    d2799:   8b 4c 24 0c             mov    0xc(%esp,1),%ecx
228434    d279d:   8b 5c 24 08             mov    0x8(%esp,1),%ebx
228435    d27a1:   b8 04 00 00 00          mov    $0x4,%eax
228436    d27a6:   cd 80                   int    $0x80
228437    d27a8:   5b                      pop    %ebx
228438    d27a9:   3d 01 f0 ff ff          cmp    $0xfffff001,%eax
228439    d27ae:   73 2d                   jae    d27dd <__libc_write+0x5d>
228440    d27b0:   c3                      ret
228441    d27b1:   e8 0a c2 01 00          call   ee9c0 
<__librt_enable_asynccancel>
228442    d27b6:   50                      push   %eax
228443    d27b7:   53                      push   %ebx
228444    d27b8:   8b 54 24 14             mov    0x14(%esp,1),%edx
228445    d27bc:   8b 4c 24 10             mov    0x10(%esp,1),%ecx
228446    d27c0:   8b 5c 24 0c             mov    0xc(%esp,1),%ebx
228447    d27c4:   b8 04 00 00 00          mov    $0x4,%eax
228448    d27c9:   cd 80                   int    $0x80
228449    d27cb:   5b                      pop    %ebx
228450    d27cc:   87 04 24                xchg   %eax,(%esp,1)
228451    d27cf:   e8 5c c2 01 00          call   eea30 
<__librt_disable_asynccancel>
228452    d27d4:   58                      pop    %eax
228453    d27d5:   3d 01 f0 ff ff          cmp    $0xfffff001,%eax
228454    d27da:   73 01                   jae    d27dd <__libc_write+0x5d>
228455    d27dc:   c3                      ret
228456    d27dd:   53                      push   %ebx
228457    d27de:   e8 9a 32 f4 ff          call   15a7d 
<__i686.get_pc_thunk.bx>
228458    d27e3:   81 c3 5d 73 06 00       add    $0x6735d,%ebx
228459    d27e9:   31 d2                   xor    %edx,%edx
228460    d27eb:   29 c2                   sub    %eax,%edx
228461    d27ed:   52                      push   %edx
228462    d27ee:   e8 dd 31 f4 ff          call   159d0 <GCC_3.0+0x159d0>
228463    d27f3:   59                      pop    %ecx
228464    d27f4:   5b                      pop    %ebx
228465    d27f5:   89 08                   mov    %ecx,(%eax)
228466    d27f7:   83 c8 ff                or     $0xffffffff,%eax
228467    d27fa:   eb e0                   jmp    d27dc <__libc_write+0x5c>
228468    d27fc:   90                      nop
228469    d27fd:   90                      nop
228470    d27fe:   90                      nop
228471    d27ff:   90                      nop

_________________________________________________________________
Is your PC infected? Get a FREE online computer virus scan from McAfee® 
Security. http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963



More information about the Libc-alpha mailing list