AT/t compilation of Use documents for study notes

Source: Internet
Author: User

Working with files:
System calls
Open 5 Open the file you want to access and create a handle to the file.
Read 3 Open file with file handle
Write 4 write with file handle
Close 6 Close file and delete file handle

Open it:
int open (const char* pathname, int flags, mode_t mode);
EAX 5
EBX A memory address that contains the starting position of the file name string that ends with a null character.
ECX requires access to the file; The true value of the type's flag
edx If you create a new file, it represents an integer value that contains UNIX permissions



C Constants: Numeric value Descriptions
o_rdonly 00 Open file, read only
O_wronly 01 Write only
O_rdwr 02 Open File, read/write access
O_creat 0100 file does not exist then create
O_excl 0200 when used with O_creat
O_trunc 01000 truncates the file length to 0 if the file exists and is opened as write-only mode.
O_append 02000 appends data to the end of the file.
O_nonblock 04000 opens in non-block mode.
O_sync 010000 open files in synchronous mode (only one write is allowed)
O_async 020000 opens in asynchronous mode (multiple write operations allowed)

Open File Code:
. Section. Data
FileName
. Asciz "Output.txt"
..
..
. section. Text
..
..
MOVL $filename,%EBX

MOVL%esp,%EBP
..
MOVL 8 (%EBP),%EBX


MOVL,%eax
MOVL $filename,%EBX
MOVL $0102,%ECX
MOVL $0644,%edx
int $0x80
Test%eax,%eax
JS Badfile

Error code: error value: Description
Eperm 1 operation is not allowed
ENOENT 2 does not have this file
EBADF 9 Bad file handle numbers
Eacces 13 Permission Denied
Efault 14 Bad file address
Ebusy 16 device or resource busy
Eexist 17 File exists
Eisdir 21 is the directory
Emfile 24 Too many open files
Efbig 27 File too large
Erofs 30 Read-only file system
Enametoolong 36 filename Too long

Close File
MOVL FileHandle,%EBX
MOVL $6,%eax
int $0x80

Read call ssize_t read (int fd, void* buf, size_t count);
Handle buffer number of bytes

EAX 3 System Call value
EBX Handle to open file
ECX the memory location of the buffer
EdX to read the integer value of the number of bytes

The operating system cannot write files while reading files.
void *mmap (void* start,size_t length,int port,int flags,int fd,off_t offset);
In-memory start location number of bytes memory protection sets the starting point of the data to be copied to memory in the handle file of the mapped object to be created to be mapped to the memory file

Protection Name:
Port_none 0 does not allow data access
Port_read 1 allows read access
Port_write 2 Allow Write access
Port_exec 4 allows execution of access

Flags
Map_share 1 and other processes shared memory-mapped file changes
Map_private 2 Keeping all the changes is private to this process

Msync original files and memory files for synchronous mapping
Munmap Delete the memory-mapped file from memory and write all changes to the original file

int Msync (const void* start,size_t length, int flags);
int Munmap (void* start,size_t length);

The Ms_async schedules the update the next time the file is written, and the system returns the call
Ms_sync system calls wait until an update is made and then returns to the calling program

System Call values
MMAP 90
Munmap 91
Msync 144


Mmap templates
Pushl
Puhl FileHandle
PUSHL $
Pushl
PUSHL size
Pushl
MOVL%esp,%EBP
MOVL,%eax
int $0x80
Addl $24,%esp
MOVL%eax, Mappedfile


Unmap
MOVL $91,%eax
MOVL Mappedfile,%EBX
MOVL size,%ECX
int $0x80

int llseek (unsigned int fd,unsigned long offset_high,unsigned long offset_low, loff_t *result,unsigned int whence);

Stack
Offset
Fd
Flags
Port
Length
Start EBX

AT/t compilation of Use documents for study notes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.