⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 other calls2.txt

📁 Linux C 语言函数
💻 TXT
📖 第 1 页 / 共 2 页
字号:
ptrace

SYNOPSIS
int ptrace(int request, int pid, int addr, int data); 

PARAMETERS
request: [in] the kind of request. 

pid: [in] target task. 

addr: [in] the address where to perform peek and poke operations. 

data: [in] the data to write for poke operations and [out] the data read for peek operations
. 


DESCRIPTION
This call is used for debugging a child of the current task. The traced child will run until
a signal occurs. The parent is notified through the wait syscall. When the child is stoped 
the content of its address space may be read and written by the parent. The request 
parameter may be one of the following: 


PTRACE_TRACEME 
request tracing by the parent of the current task. 

PTRACE_PEEKTEXT, PTRACE_PEEKDATA 
request the reading of data from the address space of the child. 

PTRACE_PEEKUSR 
request the reading of data from the user area. 

PTRACE_POKETEXT, PTRACE_POKEDATA 
request the writing of data into the address space of the child. 

PTRACE_POKEUSR 
request the writing of data into the user area. 

PTRACE_SYSCALL, PTRACE_CONT 
request the continuation of the child after a signal. 

PTRACE_KILL 
send SIGKILL to the child. 

PTRACE_SINGLESTEP 
enable the single step mode. 

PTRACE_ATTACH 
attach to the process pid. 

PTRACE_DETACH 
detach from the process pid. 

RETURN VALUE
On success zero is returned. On error -1 is returned and errno is set to one of the 
following values: 


EPERM: the target taks cannot be traced or is already being traced. 
ESRCH, EIO. 

***************************************************************************************
reboot

SYNOPSIS
int reboot(int magic, int magic_too, int flag); 

PARAMETERS
magic: [in] 0xfee1dead. 

magic_too: [in] 672274793. 

flag: [in] see description. 

DESCRIPTION
Reboots the machine or enable the Ctrl-Alt-Del combinaison. magic must be 0xfee1dead and 
magic_too must be 672274793. If those two conditions are true, then the following values of
flag perform the specified operations: 


0x1234567 
preform a hard reset. 

0x89abcdef 
Ctrl-Alt-Del is enabled. 

0 
Ctrl-Atl-Del is disabled and a signal is send to init. 
Does not sync!!! The calling task must have superuser privileges. 


RETURN VALUE
On success zero is returned. On error -1 is returned and errno is set to one of the 
following values: 


EINVAL: the value of magic, magic_too or flag is invalid. 
EPERM: the calling task does not have superuser privileges. 


***************************************************************************************
setup
This call sets up the HDs and mounts the root partition. Only to be called once, by init. 
This call shouldn't be necessary for a server running on a mk.

***************************************************************************************
sigaction and signal

SYNOPSIS
int sigaction(int signum, const struct sigaction *new, struct sigaction *old); 

(void *) (int) signal(int signum, (void *handler)(int)); 


PARAMETERS
signum: [in] a signal number. 

new: [in] the action to take for this signal. 

old: [out] the previous action that was associated to the signal. 

handler: [in] points to the new signal handler. 


DESCRIPTION
sigaction is used to specify the action to take in case the signal signum is raised. 
signum can take one of the following values: 


SIGHUP 
(terminates) the controling terminal has been disconnected. 

SIGINT 
(terminates) the interrupt key has been pressed (Ctrl-C usually). 

SIGQUIT 
(terminates and dumps core) the quit key has been pressed (Ctrl-\ usually). 

SIGILL 
(terminates and dumps core) the task has executed an illegal instruction (or is ill?). 

SIGTRAP 
(terminates and dumps core) caught an hardware fault. 

SIGABRT 
(terminates and dumps core) usually generated by the abort function. 

SIGIOT 
(terminates and dumps core) caught an hardware fault. 

SIGUNUSED 
(terminates) unused. 

SIGFPE 
(terminates and dumps core) the task has generated a floating-point exception. 

SIGKILL 
(terminates) kills the task. This signal can't be caught or ignored. 

SIGUSR1 
(terminates) user defined signal. 

SIGSEGV 
(terminates and dumps core) the task has made an invalid memory reference. 

SIGUSR2 
(terminates) user defined signal. 

SIGPIPE 
(terminates) the task tried to write to a pipe/socket but the reader is dead. 

SIGALRM 
(terminates) an alarm has expired. 

SIGTERM 
(terminates) termination signal. 

SIGSTKFLT 
?? 

SIGCHLD 
(ignore) a child has died. 

SIGCONT 
(ignored or resumes) send to a stopped task to make it resume its execution. 

SIGSTOP 
(stops) send to a task to make it stop its execution. This signal can't be caught or ignored
. 

SIGTSTP 
(stops) interactive stop signal generated by the terminal (usually Ctrl-Z). 

SIGTTIN 
(stops) the process is in background and tried to read from its controling terminal. 

SIGTTOU 
(stops) the process is in background and tried to write to its controling terminal. 

SIGIO 
(terminates) an asynchronous I/O event has occured. 

SIGPOLL 
(terminates) an event has occurend on a pooling device. 

SIGURG 
(terminates) an urgent condition has occured. (Usually the reception of out-of-band data on
 a network connection.) 

SIGXCPU 
(terminates) the task has exceeded its CPU time limit. 

SIGXFSZ 
(terminates) the taks exceeds its size limit. 

SIGVTALRM 
(terminates) a virtual interval timer has expired. 

SIGPROF 
(terminates) a profiling interval timer has expired. 

SIGWINCH 
(ignored) the controling terminal size has changed. 

SIGPWR 
(terminates) power failure: run for cover! 

SIGBUS 
(terminates) a hardware fault has occured. If we look in the kernel sources, we see: Arggh. 
Bad user source code wants this. 
There is also a signal SIGLOST in the sources, however it is commented out. 

The action to take is specified by a sigcaction structure that has the following layout: 


struct sigaction {
	__sighandler_t sa_handler;  /* the handler (or a special value) */
	sigset_t sa_mask;           /* signals to block on entry */
	int sa_flags;               /* some flags */
	void (*sa_restorer)(void);  /* not used */
};

sa_handler may be set to the address of the handler to start to handle the signal or it may
be set to one of the following special values: 


SIG_ING 
means to ignore the signal. 

SIG_DFL 
means to use the default handler. 
sa_mask specifies signals to be added to the signal mask of the process before calling the 
signal handler. The signal mask is restored to its initial value upon return from the 
handler. 

sa_flags specifies some options for the handling of the signal: 


SA_NOCLDSTOP 
disable the generation of the SIGCHLD signal when a child stops. signum must be SIGCHLD. 

SA_RESTART 
ask for automatic restart of system calls interrupted by this signal. 

SA_STACK 
not implemented. 

SA_INTERRUPT 
ignored. 

SA_NOMASK 
do not mask anything (not even the current signal). (Looks like SA_NODEFER in [Stevens].) 

SA_ONESHOT 
the handler will be used only once. (Looks like SA_RESETHAND in [Stevens].) 
The previous value of the sigaction structure for the signal is stored to the area pointed 
to by old. 

signal is some kind of proto-sigaction. It sets the handler of signum to handler. It is 
equivalent to 


struct sigaction new;
new.sa_handler=handler;
new.sa_mask=0;
new.sa_flags=SA_NOMASK | SA_ONESHOT;
new.sa_restorer=NULL;
sigaction(signum, &new, NULL);

It could be implemented as a sigaction wrapper. 


RETURN VALUE
On success, sigaction returns zero and signal returns the pointer to the signal handler. On
error, both return -1. The possible values of errno are: 


EINVAL: tried to set the handler of SIGKILL or SIGSTOP. 
EFAULT. 


***************************************************************************************
sgetmask and ssetmask

SYNOPSIS

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -