Linux Kernel Architecture

(Jacob Rumans) #1
Mauerer runapp01.tex V1 - 09/04/2008 6:08pm Page 1120

Appendix A: Architecture Specifics


of the entire address space into a kernel address space and a user address space. However, this does
not apply on all architectures. (Sparc is one such exception, because it has two separate address spaces
for the kernel and userspace. AMD64 is another exception, because its virtual address space has a non-
addressable hole in the middle.) As a result, theTASK_SIZEconstant defined inasm-arch/process.h
must be used instead ofPAGE_OFFSETto determine the size of userspace.

A.5 System Calls


The mechanism for issuing system calls to perform a controlled switch from userspace to kernel space
differs on all supported platforms. However, a standard file named<asm-arch/unistd.h>is responsible
for the following two aspects relevant to system calls:

❑ It defines pre-processor constants to link the descriptors of all system calls with symbolic
constants. The constants have names such as__NR_chdirand__NR_send. Because the individual
architectures do their best to remain compatible with the descriptors of the specific native
operating system (for example, OSF/1 on Alpha, or Solaris on Sparc), the numeric values differ
from architecture to architecture.
❑ It defines functions to invoke system callsfrom within the kernel itself. Generally, a
pre-processor mechanism is used for this purpose together with an inline assembler for
automatic generation.

A.6 String Processing


Operations on strings are performed at various points in the kernel and are therefore particularly time-
critical. Because many architectures provide special assembler commands to carry out the requisite tasks,
or because manually optimized assembler code executes faster than compiler-generated code, all archi-
tectures may define various string operations of their own in<asm-arch/string.h>:

❑ int strcmp(const char * cs,const char * ct)compares two strings, character by character.
❑ int strncmp(const char * cs,const char * ct,size_t count)is similar tostrcmpbut compares
amaximumofcountcharacters.
❑ int strnicmp(const char *s1, const char *s2, size_t len)is similar tostrncmpbut compares
the individual characters regardless of case.
❑ char * strcpy(char * dest,const char *src)copies a null-terminated string fromsrctodest.
❑ char * strncpy(char * dest,const char *src,size_t count)is similar tostrcpybut restricts
the maximum copy length tocountbytes or characters.
❑ size_t strlcpy(char *dest, const char *src, size_t size)is similar tostrncpy,butthedes-
tination string is also null-terminated if the source string has more thansizecharacters.
❑ char * strcat(char * dest, const char * src)addssrctodest.
❑ char * strncat(char *dest, const char *src, size_t count)is similar tostrcat, but restricts
the operation to a maximum ofcountcopied bytes.
❑ size_t strlcat(char *dest, const char *src, size_t count)is similar tostrncat,but
restricts the length of the result (and not the number of copy operations) tocountbytes.
Free download pdf