int KernelStub_Open() { char *localCopy[MaxFileNameSize + 1]; // Check that the stack pointer is valid and that the arguments are stored at // valid addresses. if (!validUserAddressRange(userStackPointer, userStackPointer + size of arguments)) return error_code; // Fetch pointer to file name from user stack and convert it to a kernel pointer. filename = VirtualToKernel(userStackPointer); // Make a local copy of the filename. This prevents the application // from changing the name surreptitiously. // The string copy needs to check each address in the string before use to make sure // it is valid. // The string copy terminates after it copies MaxFileNameSize to ensure we // do not overwrite our internal buffer. if (!VirtualToKernelStringCopy(filename, localCopy, MaxFileNameSize)) return error_code; // Make sure the local copy of the file name is null terminated. localCopy[MaxFileNameSize] = 0; // Check if the user is permitted to access this file. if (!UserFileAccessPermitted(localCopy, current_process) return error_code; // Finally, call the actual routine to open the file. This returns a file // handle on success, or an error code on failure. return Kernel_Open(localCopy); }