Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using system calls in C language: Memcpy (memory copy) function Using Debian app on VM interface to compile. Adding a Memory Copy System Call The

Using system calls in C language:

Memcpy (memory copy) function

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Using Debian app on VM interface to compile.

Adding a Memory Copy System Call The memcpy() function In C, a commonly used function from the system's C library is the memcpy () function. This function takes in two pointers and a size and copies the given number of bytes from one to the other of the pointers. A very simple (albeit slow, performance-wise) version of this function might be implemented in the following manner: void *memopy (void *dest, const void *src, size t n) \{ unsigned char *d - (unsigned char *) dest; const unsigned char s= (unsigned char *)src; size t; unsigned char tmp; for (i=0;i header files at the top of copy.c to use any of these functions. If any checks fail (from access_ok, get_user, or put_user), you should stop trying to copy data and immediately return-EFAULT. If all data is copied correctly, return 0 at the end of the function (rather than the destination pointer as the userspace memopy does). Recall that in C, that a pointer to the i th element at a pointer ptr (or the ith element of an array, equivalently) can be obtained in the following two ways (use whichever you would like in your get_user and put_user calls: &ptr[i]/OR/ptr+i Testing Your System Call As with the hello world system call earlier, you should test your new memory copy system call to ensure that it works properly. You should test your function with a variety of pointers, both good and bad (for instance, try copying to or from a NULL pointer to see what happens. You should notice that when you copy to or from a bad pointer that the system call always returns 1. If you look at the errno variable in your program (\#include .h> in your test program to get access to it), you will find that it should be set to the constant EFAULT (also in errno.h) when an error occurs<>

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning C# 5.0 Databases

Authors: Vidya Vrat Agarwal

2nd Edition

1430242604, 978-1430242604

More Books

Students also viewed these Databases questions

Question

What are some limitations of internal controls?

Answered: 1 week ago

Question

6. Team members respect and trust each other.

Answered: 1 week ago

Question

Define Management by exception

Answered: 1 week ago

Question

Explain the importance of staffing in business organisations

Answered: 1 week ago

Question

What are the types of forms of communication ?

Answered: 1 week ago

Question

Explain the process of MBO

Answered: 1 week ago