lecture20 - CIS 450 Computer Architecture and Organization...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
CIS 450 – Computer Architecture and Organization Lecture 20: Control Flow Mitch Neilsen ([email protected] ) 219D Nichols Hall
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Topics ± Linking Example z Library Interpositioning ± Control Flow z Exceptions z Process context switches z Creating and destroying processes
Background image of page 2
Case Study: Library Interpositioning Library interpositioning is a powerful linking technique that allows programmers to intercept calls to arbitrary functions Interpositioning can occur at: ± compile time z When the source code is compiled ± link time z When the relocatable object files are linked to form an executable object file ± load/run time z When an executable object file is loaded into memory, dynamically linked, and then executed.
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Some Interpositioning Applications Security ± Confinement (sandboxing) z Interpose calls to libc functions. ± Behind the scenes encryption z Automatically encrypt otherwise unencrypted network connections. Monitoring and Profiling ± Count number of calls to functions ± Characterize call sites and arguments to functions ± Malloc tracing z Detecting memory leaks z Generating malloc traces
Background image of page 4
Example: malloc() Statistics Count how much memory is allocated by a function void *malloc(size_t size){ static void *(*fp)(size_t) = 0; void *mp; char *errorstr; /* Get a pointer to the real malloc() */ if (!fp) { fp = dlsym(RTLD_NEXT, "malloc"); if ((errorstr = dlerror()) != NULL) { fprintf(stderr, "%s(): %s\n", fname, errorstr); exit(1); } } /* Call the real malloc function */ mp = fp(size); mem_used += size; return mp; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Example: /pub/cis450/programs/malloc $ make $ make runc Æ ./helloc – compile-time version $ make runl Æ ./hellol – link-time version $ make runr Æ (LD_PRELOAD="/usr/lib/libdl.so ./mymalloc.so" ./hellor) – run-time version
Background image of page 6
Computers do Only One Thing ± From startup to shutdown, a CPU simply reads and executes (interprets) a sequence of instructions, one at a time. ± This sequence is the system’s physical control flow (or flow of control ). Control Flow <startup> inst 1 inst 2 inst 3 inst n <shutdown> Physical control flow Time
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Altering the Control Flow Up to Now: two mechanisms for changing control flow: ± Jumps and branches ± Call and return using the stack discipline. Both react to changes in program state. Insufficient for a useful system ± Difficult for the CPU to react to changes in system state. z Data arrives from a disk or a network adapter z Instruction divides by zero z User hits Ctrl-c at the keyboard z System timer expires The system needs some additional mechanisms for exceptional control flow
Background image of page 8
Exceptional Control Flow ± Mechanisms for exceptional control flow exists at all levels of a computer system. Low-level Mechanism
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 43

lecture20 - CIS 450 Computer Architecture and Organization...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online