MentOS  0.8.0
The Mentoring Operating System
Functions
syscall.h File Reference

System Call handler definition. More...

Go to the source code of this file.

Functions

void syscall_init (void)
 Initialize the system calls.
 
void syscall_handler (pt_regs *f)
 Handler for the system calls. More...
 
pt_regsget_current_interrupt_stack_frame (void)
 Returns the current interrupt stack frame. More...
 
void sys_exit (int exit_code)
 
ssize_t sys_read (int fd, void *buf, size_t nbytes)
 Read data from a file descriptor. More...
 
ssize_t sys_write (int fd, const void *buf, size_t nbytes)
 Write data into a file descriptor. More...
 
off_t sys_lseek (int fd, off_t offset, int whence)
 Repositions the file offset inside a file. More...
 
int sys_open (const char *pathname, int flags, mode_t mode)
 Given a pathname for a file, open() returns a file descriptor, a small, nonnegative integer for use in subsequent system calls. More...
 
int sys_close (int fd)
 
int sys_unlink (const char *path)
 Delete a name and possibly the file it refers to. More...
 
pid_t sys_waitpid (pid_t pid, int *status, int options)
 Suspends execution of the calling thread until a child specified by pid argument has changed state. More...
 
int sys_execve (pt_regs *f)
 Replaces the current process image with a new process image. More...
 
int sys_chdir (char const *path)
 Changes the working directory. More...
 
int sys_fchdir (int fd)
 Changes the working directory. More...
 
pid_t sys_getpid (void)
 Returns the process ID (PID) of the calling process. More...
 
pid_t sys_getsid (pid_t pid)
 Return session id of the given process. If pid == 0 return the SID of the calling process If pid != 0 return the SID corresponding to the process having identifier == pid. More...
 
pid_t sys_setsid (void)
 creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID). The calling process also becomes the process group leader of a new process group in the session (i.e., its process group ID is made the same as its process ID). More...
 
pid_t sys_getpgid (pid_t pid)
 returns the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used. More...
 
int sys_setpgid (pid_t pid, pid_t pgid)
 Sets the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used. More...
 
gid_t sys_getgid (void)
 returns the real group ID of the calling process. More...
 
int sys_setgid (gid_t gid)
 sets the group ID of the calling process. More...
 
gid_t sys_getegid (void)
 returns the effective group ID of the calling process. More...
 
int sys_setregid (gid_t rgid, gid_t egid)
 sets the real and effective group ID of the calling process. More...
 
pid_t sys_getppid (void)
 Returns the parent process ID (PPID) of the calling process. More...
 
uid_t sys_getuid (void)
 Returns the real User ID (UID) of the calling process. More...
 
int sys_setuid (uid_t uid)
 Tries to set the User ID (UID) of the calling process. More...
 
uid_t sys_geteuid (void)
 Returns the effective User ID (UID) of the calling process. More...
 
int sys_setreuid (uid_t ruid, uid_t euid)
 Set the real and effective User ID (UID) of the calling process. More...
 
int sys_nice (int increment)
 Adds the increment to the priority value of the task. More...
 
int sys_reboot (int magic1, int magic2, unsigned int cmd, void *arg)
 Reboots the system, or enables/disables the reboot keystroke. More...
 
char * sys_getcwd (char *buf, size_t size)
 Get current working directory. More...
 
pid_t sys_fork (pt_regs *f)
 Clone the calling process, but without copying the whole address space. The calling process is suspended until the new process exits or is replaced by a call to ‘execve’. More...
 
int sys_stat (const char *path, stat_t *buf)
 Stat the file at the given path. More...
 
int sys_fstat (int fd, stat_t *buf)
 Retrieves information about the file at the given location. More...
 
int sys_mkdir (const char *path, mode_t mode)
 Creates a new directory at the given path. More...
 
int sys_rmdir (const char *path)
 Removes the given directory. More...
 
int sys_creat (const char *path, mode_t mode)
 Creates a new file or rewrite an existing one. More...
 
int sys_readlink (const char *path, char *buffer, size_t bufsize)
 Read the symbolic link, if present. More...
 
int sys_symlink (const char *linkname, const char *path)
 Creates a symbolic link. More...
 
ssize_t sys_getdents (int fd, dirent_t *dirp, unsigned int count)
 
time_t sys_time (time_t *time)
 Returns the current time. More...
 

Detailed Description

System Call handler definition.

Function Documentation

◆ get_current_interrupt_stack_frame()

pt_regs* get_current_interrupt_stack_frame ( void  )

Returns the current interrupt stack frame.

Returns
Pointer to the stack frame.

◆ sys_chdir()

int sys_chdir ( char const *  path)

Changes the working directory.

Parameters
pathThe new working directory.
Returns
On success 0. On error -1, and errno indicates the error.

◆ sys_close()

int sys_close ( int  fd)
Parameters
fd
Returns

◆ sys_creat()

int sys_creat ( const char *  path,
mode_t  mode 
)

Creates a new file or rewrite an existing one.

Parameters
pathpath to the file.
modemode for file creation.
Returns
file descriptor number, -1 otherwise and errno is set to indicate the error.

It is equivalent to: open(path, O_WRONLY|O_CREAT|O_TRUNC, mode)

◆ sys_execve()

int sys_execve ( pt_regs f)

Replaces the current process image with a new process image.

Parameters
fCPU registers whe calling this function.
Returns
0 on success, -1 on error.

◆ sys_exit()

void sys_exit ( int  exit_code)

The exit() function causes normal process termination.

Parameters
exit_codeThe exit code.

◆ sys_fchdir()

int sys_fchdir ( int  fd)

Changes the working directory.

Parameters
fdFile descriptor of the new working directory.
Returns
On success 0. On error -1, and errno indicates the error.

◆ sys_fork()

pid_t sys_fork ( pt_regs f)

Clone the calling process, but without copying the whole address space. The calling process is suspended until the new process exits or is replaced by a call to ‘execve’.

Parameters
fCPU registers whe calling this function.
Returns
Return -1 for errors, 0 to the new process, and the process ID of the new process to the old process.

◆ sys_fstat()

int sys_fstat ( int  fd,
stat_t buf 
)

Retrieves information about the file at the given location.

Parameters
fdThe file descriptor of the file that is being inquired.
bufA structure where data about the file will be stored.
Returns
Returns a negative value on failure.

◆ sys_getcwd()

char* sys_getcwd ( char *  buf,
size_t  size 
)

Get current working directory.

Parameters
bufThe array where the CWD will be copied.
sizeThe size of the array.
Returns
On success, returns the same pointer to buf. On failure, returnr NULL, and errno is set to indicate the error.

◆ sys_getdents()

ssize_t sys_getdents ( int  fd,
dirent_t dirp,
unsigned int  count 
)

Provide access to the directory entries.

Parameters
fdThe file descriptor of the directory for which we accessing the entries.
dirpThe buffer where de data should be placed.
countThe size of the buffer.
Returns
On success, the number of bytes read is returned. On end of directory, 0 is returned. On error, -1 is returned, and errno is set appropriately.

◆ sys_getegid()

gid_t sys_getegid ( void  )

returns the effective group ID of the calling process.

Returns
GID of the current process

◆ sys_geteuid()

uid_t sys_geteuid ( void  )

Returns the effective User ID (UID) of the calling process.

Returns
The User ID.

◆ sys_getgid()

gid_t sys_getgid ( void  )

returns the real group ID of the calling process.

Returns
GID of the current process

◆ sys_getpgid()

pid_t sys_getpgid ( pid_t  pid)

returns the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used.

Parameters
pidprocess of which we want to know the PGID.
Returns
the PGID of the specified process.

◆ sys_getpid()

pid_t sys_getpid ( void  )

Returns the process ID (PID) of the calling process.

Returns
The process ID.

◆ sys_getppid()

pid_t sys_getppid ( void  )

Returns the parent process ID (PPID) of the calling process.

Returns
The parent process ID.

◆ sys_getsid()

pid_t sys_getsid ( pid_t  pid)

Return session id of the given process. If pid == 0 return the SID of the calling process If pid != 0 return the SID corresponding to the process having identifier == pid.

Parameters
pidprocess identifier from wich we want the SID
Returns
On success return SID of the session Otherwise return -1 with errno set on: EPERM or ESRCH

◆ sys_getuid()

uid_t sys_getuid ( void  )

Returns the real User ID (UID) of the calling process.

Returns
The User ID.

◆ sys_lseek()

off_t sys_lseek ( int  fd,
off_t  offset,
int  whence 
)

Repositions the file offset inside a file.

Parameters
fdThe file descriptor of the file.
offsetThe offest to use for the operation.
whenceThe type of operation.
Returns
Upon successful completion, returns the resulting offset location as measured in bytes from the beginning of the file. On error, the value (off_t) -1 is returned and errno is set to indicate the error.

◆ sys_mkdir()

int sys_mkdir ( const char *  path,
mode_t  mode 
)

Creates a new directory at the given path.

Parameters
pathThe path of the new directory.
modeThe permission of the new directory.
Returns
Returns a negative value on failure.

◆ sys_nice()

int sys_nice ( int  increment)

Adds the increment to the priority value of the task.

Parameters
incrementThe modifier to apply to the nice value.
Returns
The new nice value.

◆ sys_open()

int sys_open ( const char *  pathname,
int  flags,
mode_t  mode 
)

Given a pathname for a file, open() returns a file descriptor, a small, nonnegative integer for use in subsequent system calls.

Parameters
pathnameA pathname for a file.
flagsUsed to set the file status flags and file access modes of the open file description.
modeSpecifies the file mode bits be applied when a new file is created.
Returns
Returns a file descriptor, a small, nonnegative integer for use in subsequent system calls.

◆ sys_read()

ssize_t sys_read ( int  fd,
void *  buf,
size_t  nbytes 
)

Read data from a file descriptor.

Parameters
fdThe file descriptor.
bufThe buffer.
nbytesThe number of bytes to read.
Returns
The number of read characters.

◆ sys_readlink()

int sys_readlink ( const char *  path,
char *  buffer,
size_t  bufsize 
)

Read the symbolic link, if present.

Parameters
paththe file for which we want to read the symbolic link information.
bufferthe buffer where we will store the symbolic link path.
bufsizethe size of the buffer.
Returns
The number of read characters on success, -1 otherwise and errno is set to indicate the error.

◆ sys_reboot()

int sys_reboot ( int  magic1,
int  magic2,
unsigned int  cmd,
void *  arg 
)

Reboots the system, or enables/disables the reboot keystroke.

Parameters
magic1fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC1.
magic2fails (with the error EINVAL) unless equals LINUX_REBOOT_MAGIC2.
cmdThe command to send to the reboot.
argArgument passed with some specific commands.
Returns
For the values of cmd that stop or restart the system, a successful call to reboot() does not return. For the other cmd values, zero is returned on success. In all cases, -1 is returned on failure, and errno is set appropriately.

◆ sys_rmdir()

int sys_rmdir ( const char *  path)

Removes the given directory.

Parameters
pathThe path to the directory to remove.
Returns
Returns a negative value on failure.

◆ sys_setgid()

int sys_setgid ( gid_t  gid)

sets the group ID of the calling process.

Parameters
gidgroup id
Returns
On success, zero is returned. Otherwise returns -1 with errno set to :EINVAL or EPERM.

◆ sys_setpgid()

int sys_setpgid ( pid_t  pid,
pid_t  pgid 
)

Sets the Process Group ID (PGID) of the process specified by pid. If pid is zero, the process ID of the calling process is used.

Parameters
pidprocess of which we want to set the PGID.
pgidthe PGID we want to set.
Returns
returns zero. On error, -1 is returned, and errno is set appropriately.

◆ sys_setregid()

int sys_setregid ( gid_t  rgid,
gid_t  egid 
)

sets the real and effective group ID of the calling process.

Parameters
rgidreal group id
egideffective group id
Returns
On success, zero is returned. Otherwise returns -1 with errno set to EPERM.

◆ sys_setreuid()

int sys_setreuid ( uid_t  ruid,
uid_t  euid 
)

Set the real and effective User ID (UID) of the calling process.

Parameters
ruidthe new real User ID.
euidthe new effective User ID.
Returns
On success, zero is returned. Otherwise returns -1 with errno set to EPERM.

◆ sys_setsid()

pid_t sys_setsid ( void  )

creates a new session if the calling process is not a process group leader. The calling process is the leader of the new session (i.e., its session ID is made the same as its process ID). The calling process also becomes the process group leader of a new process group in the session (i.e., its process group ID is made the same as its process ID).

Returns
On success return SID of the session just created Otherwise return -1 with errno : EPERM

◆ sys_setuid()

int sys_setuid ( uid_t  uid)

Tries to set the User ID (UID) of the calling process.

Parameters
uidthe new User ID.
Returns
On success, zero is returned. Otherwise returns -1 with errno set to :EINVAL or EPERM.

◆ sys_stat()

int sys_stat ( const char *  path,
stat_t buf 
)

Stat the file at the given path.

Parameters
pathPath to the file for which we are retrieving the statistics.
bufBuffer where we are storing the statistics.
Returns
0 on success, a negative number if fails and errno is set.

◆ sys_symlink()

int sys_symlink ( const char *  linkname,
const char *  path 
)

Creates a symbolic link.

Parameters
linknamethe name of the link.
paththe entity it is linking to.
Returns
0 on success, a negative number if fails and errno is set.

◆ sys_time()

time_t sys_time ( time_t time)

Returns the current time.

Parameters
timeWhere the time should be stored.
Returns
The current time.

◆ sys_unlink()

int sys_unlink ( const char *  path)

Delete a name and possibly the file it refers to.

Parameters
pathA pathname for a file.
Returns
On success, zero is returned. On error, -1 is returned, and errno is set appropriately.

◆ sys_waitpid()

pid_t sys_waitpid ( pid_t  pid,
int *  status,
int  options 
)

Suspends execution of the calling thread until a child specified by pid argument has changed state.

Parameters
pidThe pid to wait.
statusIf not NULL, store status information here.
optionsDetermines the wait behaviour.
Returns
on success, returns the process ID of the terminated child; on error, -1 is returned.

◆ sys_write()

ssize_t sys_write ( int  fd,
const void *  buf,
size_t  nbytes 
)

Write data into a file descriptor.

Parameters
fdThe file descriptor.
bufThe buffer collecting data to written.
nbytesThe number of bytes to write.
Returns
The number of written bytes.

◆ syscall_handler()

void syscall_handler ( pt_regs f)

Handler for the system calls.

Parameters
fThe interrupt stack frame.