DOC PREVIEW
U of I CS 241 - Operating System Design

This preview shows page 1-2-15-16-31-32 out of 32 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 32 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

CS241 Overview Operating System Design University of Illinois at Urbana-ChampaignOverviewOperating System Structure (1)Operating System Structure (2)Operating System Structure (3)Operating System Structure (4)Operating System Structure (5)Metric UnitsPrograms R:p14-38Buffer OverflowSlide 11Password check susceptible to buffer overflowStack Layout for checkpassProgram LayoutR: Appendix ALibrary Function CallsError reportingMany Library Calls abort if process is interrupted by signalHandling ErrorsArgument ArraysArgument ArraysCreating Argument ArraysHow to write makeargvSlide 24Implementation of makeargv R:p37Making Functions SafeSlide 27Storage classes: static and automaticLinkage classesVariablesFunctionsSummary01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved1CS241CS241OverviewOverview Operating System Design Operating System DesignUniversity of Illinois at Urbana-ChampaignUniversity of Illinois at Urbana-Champaign Professor: Roy Campbell01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved2Overview•Operating System Design•Programs R:14-38•Buffer overflow•Arguments•Libraries01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved3Operating System Structure (1)Simple structuring model for a monolithic system01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved4Operating System Structure (2)Structure of the THE operating system01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved5Operating System Structure (3)Structure of VM/370 with CMS01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved6Operating System Structure (4)The client-server model01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved7Operating System Structure (5)The client-server model in a distributed system01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved8Metric UnitsThe metric prefixes01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved9Programs R:p14-38 The importance of writing correct programsBuffer overflowProgram LayoutStatic DataLibrary Function CallsFunction Return Values and ErrorsArgument Arrays01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved10Buffer Overflowchar buf[80];printf(“Enter your first name”);scanf(“%s,buf);Also note, strings end in a \0.01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved11#include <stdio.h> #include <string.h> int checkpass(void){ int x; char a[9]; x = 0; fprintf(stderr,"a at %p and\nx at %p\n", (void *)a, (void *)&x); printf("Enter a short word: "); scanf("%s", a); if (strcmp(a, "mypass") == 0) x = 1; return x; }01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved12Password check susceptible to buffer overflow#include <stdio.h> int checkpass(void); int main(void) { int x; x = checkpass(); fprintf(stderr, "x = %d\n", x); if (x) fprintf(stderr, "Password is correct!\n"); else fprintf(stderr, "Password is not correct!\n"); return 0; }01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved13Stack Layout for checkpassaunusedxSaved frame pointerReturn addresstopbase10001009101210161020102401/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved14Program Layout01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved15R: Appendix AMan PagesCompilationHeader FilesLinking and librariesMacros and conditional compilationMakefilesDebugging Aids – lint, debugger, trussIdentifiers, Storage Classes and Linkage Classes01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved16Library Function CallsUNIX – returns 0 successful, -1 unsuccessful, sets errnoPOSIX – all new functions return error code and do not use errnoGood coders handle ALL errors, not just mandatory (in the standard) ones.01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved17Error reporting#include <stdio.h>Void perror(const char * s);--------------------------#include <string.h>Char *strerror(int errnum);01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved18Many Library Calls abort if process is interrupted by signalint error;int fildes;while (((error = close(fildes))== -1) && (errno == EINTR));if (error == -1) perror(“Failed to close the file”);01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved19Handling ErrorsAlways handle all errorsEither:Print error message and exit program (only in main)Return -1 or NULL and set an error indicator such as errnoReturn and error codeAll functions should report errors to calling programUse conditional compilation to enclose debugging print statements01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved20Argument Arraysint main(int argc, char * argv[])Argc is number of arguments, argv is an array of pointers to the tokens01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved21Argument Arrays An argument array is an array of pointers terminated by a NULL pointer.Each element of the array is of type char * and represents a string.01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved22Creating Argument ArraysSometimes it is necessary to create a structure like this yourself from a string.The shell must do this when you execute a command. argv[] is an array of pointers to charsIn C, this is the same as a pointer to a pointer to a char. One way to write a function to do this is:char **makeargv(char *s)If you want to return the number of tokens, you can pass a pointer to the arg array as in:int makeargv(char *s, char ***argvp)The version we will use has an additional parameter that specifies a string of delimiters:int makeargv(const char *s, const char *delimiters, char ***argvp)The const for the first two parameters indicates that the strings should not be modified by the function.01/14/19 CS241 © 2005 Roy Campbell, All Rights Reserved23How to write makeargv Can use strtok: #include <string.h>char *strtok(char *restrict s1, const char *restrict s2); s1 is the string to parses2 is a string of delimitersreturns a pointer to the next token or NULL if none left.First call: s1 points to the string to parseAdditional calls: s1 is NULL.Note: the string s1 is modified. We do not want the string passed to makeargv to be modified so we allocate space for another copy of the string. Make a pass with strtok to count the tokens.Use the


View Full Document

U of I CS 241 - Operating System Design

Documents in this Course
Process

Process

28 pages

Files

Files

37 pages

File I/O

File I/O

52 pages

C Basics

C Basics

69 pages

Memory

Memory

23 pages

Threads

Threads

14 pages

Lecture

Lecture

55 pages

C Basics

C Basics

24 pages

Signals

Signals

27 pages

Memory

Memory

45 pages

Threads

Threads

47 pages

Threads

Threads

28 pages

LECTURE

LECTURE

45 pages

Threads

Threads

30 pages

Threads

Threads

55 pages

Files

Files

37 pages

SIGNALS

SIGNALS

22 pages

Files

Files

37 pages

Threads

Threads

14 pages

Threads

Threads

13 pages

Load more
Download Operating System Design
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Operating System Design and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Operating System Design 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?