0

I'm working on Kernel programming (Nachos), and having some trouble passing an array of arguments from a userprogram into kernel land. Similar to argc, argv in C, C++, the user program passes:

char *args

into a syscall. In the kernel, I only get an address of where args is located. Now, my thoughts here are that I can cast this int to a char*, and then access the array via subscript, as in the user program. But this gives me cannot access memory errors.

Any thoughts?

I've tried accessing args a few ways, they are shown here:

char *argv = (char *) ReadRegister() // ReadRegister returns an int, addr of args

in addition to

char **argv = (char **) ReadRegister()

I have then tried getting each argument via either

argv[i]

or

&argv[i]

Both give Memory access errors.

Jesavino
  • 149
  • 2
  • 11
  • Are you expecting simply an array of characters? Or are you expecting an array of strings? – Nard Nov 04 '14 at 04:24
  • Strings. Same as argv in c, c++ – Jesavino Nov 04 '14 at 04:26
  • What you have right there is a pointer to a char, therefore you will only get an array of chars not strings. I suppose you wanted char**? – Nard Nov 04 '14 at 04:27
  • Yeah, i thought that same thing. But I get that same Cannot access Memory at address... error either way I use it. – Jesavino Nov 04 '14 at 04:30
  • Could you show how you're accessing args? – Nard Nov 04 '14 at 04:32
  • Try `char **argv = (char **) ReadRegister()` – Nard Nov 04 '14 at 04:40
  • My fault, typo in what I added. I tried that one – Jesavino Nov 04 '14 at 04:41
  • how do you know that the address provided is a good address and within your address space? – Richard Chambers Nov 04 '14 at 04:43
  • 1
    This article provides [a note about using readVirtualMemory function](http://www.cs.berkeley.edu/~kubitron/courses/cs162-F05/Nachos/walk/x416.html) and others to transfer data from user space to kernel space. – Richard Chambers Nov 04 '14 at 04:57
  • If you are getting pointers from userland, and accessing in kernel, you should probably use `copyin()`, or `copyinstr()`, before you try to access the data. At least most Unix variants have memory boundary between user and kernel, memory space. But I don't know what Nachos is specifically. – lundman Nov 10 '14 at 06:13

0 Answers0