CS 3320 Operating Systems

1y ago
9 Views
3 Downloads
2.84 MB
29 Pages
Last View : 1m ago
Last Download : 2m ago
Upload by : Oscar Steel
Transcription

CS 3320Operating SystemsSystem CallsJia RaoDepartment of Computer Science and Engineeringhttp://ranger.uta.edu/ jrao1

Outline What is a system call?oKernel space vs user spaceoSystem call vs library calloWhat service can system calls provide?oSystem call naming, input, output How to add a new system calloExampleoProject 1CS 3320Operating Systems

User space vs. Kernel space Kernel space is strictly reserved for running a privileged operatingsystem kernel, kernel extensions, and most device drivers. User space is the area where application software and some driversexecute.CS 3320Operating Systems

User mode vs. Kernel mode The difference between kernel and user mode?ooThe CPU can execute any instruction in its instruction set and useany feature of the hardware when executing in kernel mode.However, it can execute only a subset of instructions and use onlysubset of features when executing in the user mode. The purpose of having these two modesoPurpose: protection – to protect critical resources (e.g., privilegedinstructions, memory, I/O devices) from being misused by userprograms.CS 3320Operating Systems

Interactions between user and kernel spaces For applications, in order to perform privileged operations, itmust transit into OS through well defined interfacesoSystem callprintf(“%d”, helloworld);write(buffer, count) ;os- write(buf, count, pos);CS 3320Operating Systems

System calls A type of special “protected procedure calls” allowinguser-level processes request services from the kernel. System calls provide:oooAn abstraction layer betweenprocesses and hardware, allowingthe kernel to provide access controlA virtualization of the underlyingsystemA well-defined interface for systemservicesCS 3320Operating Systems

System calls vs. Library functions What are the similarities and differencesbetween system calls and library functions(e.g., libc functions)?libc html node/Function-Index.htmlsystem callshttps://filippo.io/linux-syscall-table/CS 3320Operating Systems

System calls vs. Library functions SimilarityoBoth appear to be APIs that can be called by programs toobtain a service}E.g., ce/tools/include/nolibc/nolibc.h#L2038}E.g., ml node/StringLength.html#index-strlenCS 3320Operating Systems

System calls vs. Library functionslibc functions: string.h - - - strlen() : all in user spaceCS 3320Operating Systems

System calls vs. Library ource/fs/open.c#L1074System calls: fcntl.h - - - open()- - - do sys open() // wrapper system callCS 3320Operating Systems

System calls vs. Library functions DifferenceoLibrary functions execute in the user spaceoSystem calls execute in the kernel spacestrlen() ( string.h ) ? all in user spaceopen() ( fcntl.h )? do sys open()CS 3320Operating Systems

System calls vs. Library functions DifferenceoFast, no context switchoSlow, high cost, kernel/user context switchstrlen() ( string.h ) ? all in user spaceopen() ( fcntl.h )? do sys open()CS 3320Operating Systems

Services Provided by System Calls Process creation and management Main memory management File Access, Directory and File systemmanagement Device handling(I/O) Protection, e.g., encrypt Networking, etc.CS 3320Operating Systems

ExamplesCS 3320Operating Systems

System call table There are approximately 350system calls in Linux. An array of function-pointers(identified by the IDnumber) This array is named‘sys call table[]’ in arch/x86/entry/syscall 64.cCS 3320The ‘jump-table’ ideaOperating Systems

System call table Any specific systemcall is selected by itsID-number (i.e., thesystem call number,which is placed intoregister %eax)CS 3320Operating Systems

Syscall Naming Convention Usually a library function “foo()”will do some work and then call asystem call (“sys urce/arch/x86/entry/syscalls/syscall 64.tbl In Linux, all system calls begin with“sys ”open: Often “sys abc()” just does somesimple error checking and thencalls a worker function named“do abc()”CS fs/open.c#L1072do sys /fs/open.c#L1044Operating Systems

Define your system call Step 1: register your system call Step 2: declare your system call in the header file Step 3: implement your system call Step 4: write user level app to call itCS 3320Operating Systems

Step 1: register your system callarch/x86/entry/syscalls/syscall /arch/x86/entry/syscalls/syscall 64.tbl#L346CSE 3320Operating Systems

Step 2: declare your system call in the header .com/linux/v5.0/source/include/linux/syscalls.hCSE 3320Operating Systems

Step 3: implement your system 5.0/source/kernel/sys.c#L402CSE 3320Operating Systems

Step 4: write user level app to call ittest ****#include linux/unistd .h #include sys/syscall .h #include sys/types .h #include stdio .h #define NR helloworld 335int main(int argc, char *argv[]){syscall ( NR helloworld) ;return 0 e and execute: gcc test syscall.c -o test syscall ./test syscallThe test program will call the newsystem call and output a helloworldmessage at the tail of the output ofdmesg (system log).//If syscall needs parameter, then://syscall ( NR helloworld,a,b,c) ;CSE 3320Operating Systems

Project 1: menuconfigCS 3502Kennesaw State Universityhttps://youtu.be/UyOGF4UOoR0Operating Systems

Compile the kernelCommands: sudo make; sudo make modules; sudo make modules install; sudo makeinstallCSE 3320Operating Systems

Where is the new kernel? ls /boot/Initial ramdisk: loading atemporary root file system intomemory. Used for startup.CSE 3320Linux executable kernel imageOperating Systems

How to boot to the new kernel ?If you are using Ubuntu: change the grub configuration file: sudo vim /etc/default/grubThe OS boots by using the first kernel bydefault. You have 10 seconds to choose.Make the following changes:GRUB DEFAULT 0GRUB TIMEOUT 10Then, update the grub entry: sudo update-grub2CSE 3320Operating Systems

What if my kernel crashed? Your kernel could crash because you mightbring in some kernel bugs In the menu, choosethe old kernel toboot the system Fix your bug in thesource code Compile and rebootCS 3502Kennesaw State UniversityOperating Systems

Edit a file with vim step 1: vim file step 2: press i, enter insert mode; move thecursor to position and edit the context step 3: after editing, press ESC to exit theinsert mode to normal mode step 4: press :wq to save what you edited andquit. If you do not want to save, press :q!CSE 3320Operating Systems

More about vim A quick start guide for beginners to the Vim text guide-for-beginners-to-thevim-text-editor Vim basics:ohttps://www.howtoforge.com/vim-basics Learn the Basic Vim Commands [Beginners Guide]ohttps://www.youtube.com/watch?time continue 265&v ZEGqkam-3IcCSE 3320Operating Systems

CS 3320 Operating Systems The difference between kernel and user mode? oThe CPU can execute anyinstruction in its instruction set and use anyfeature of the hardware when executing in kernel mode. oHowever, it can execute only a subset of instructions and use only subset of featureswhen executing in the user mode.

Related Documents:

Spring 2012 GEA 3320: GEOGRAPHY OF THE CARIBBEAN M/W/F 9:00-9:50 AM, College of Business Com

Mar 17, 2021 · The STEM Designated Degree Program list is a complete list of fields of study that VA considers to be science, technology, engineering or mathematics (STEM) fields of study for purposes of the Edith Nourse Rogers STEM Scholarship described at 38 CFR 3320. Under 38 CFR 3320(b)(4)(A)(i), a STE

4RTG112100 Toro 2100 32,50, 3300, 3320, 3400, 3420 319.40 4RTG142100 Toro 2100 32,50, 3300, 3320, 3400, 3420 380.39 4RTG113250 Toro 3250 (2011 & older) 330.07 4RTF075510 Toro 5510D, 5610D, 6500D, 6700D 348.29 4RTF085510 Toro 5510D, 5610D, 6500D, 6700D 361.38 4RTF115510 Toro 5510D, 5610D, 6500D, 6700D

Tech 3320 v4.1 User requirements for Video Monitors in Television Production 3 Conformance Notation This document contains both normative text and informative text.

motor switch, or other operating control, a safety device or the power cord cease operating immediately until the particular part is properly repaired or replaced. b. Never place your fingers in a position where they could contact the drill bit or other cutting tool if the workpiece should unexpectedly shift or your hand should slip .

Operating Systems, Embedded Systems, and Real-Time Systems Janez Puhan Ljubljana, 2015. CIP-CatalogingInPublication NationalandUniversityLibrary,Ljubljana 004.451(078.5)(0.034.2) PUHAN,Janez,1969-Operating Systems, Embedded Systems, and Real-Time Systems [Electronic

Operating Systems: Design and Implementation, 3rd edition This popular text on operating systems is the only book covering both the princi ples of operating systems and their application to a real system. All the traditional operating systems topics are covered in detail. In addition, the principles are care

Auf deiner Beste-Freunde-Skala sehe ich mich auf Platz Eigentlich würde ich gerade lieber Mein Serientipp für dich: In 20 Jahren bin ich Weißt du noch, als Wir haben uns zum ersten Mal so richtig zusammen betrunken, als des Titels Beste Freunde (978-3-86883-890-9) 2015 by riva erlag, Münchner erlagsgruppe GmbH, München